activation_tracker_win.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_
6#define CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_
7
8#include "base/callback.h"
9#include "base/timer/timer.h"
10#include "ui/app_list/views/app_list_view.h"
11#include "ui/views/widget/widget.h"
12
13// Periodically checks to see if an AppListView has lost focus using a timer.
14class ActivationTrackerWin : public app_list::AppListView::Observer {
15 public:
16  ActivationTrackerWin(app_list::AppListView* view,
17                       const base::Closure& on_should_dismiss);
18  ~ActivationTrackerWin();
19
20  void RegainNextLostFocus() {
21    regain_next_lost_focus_ = true;
22  }
23
24  // app_list::AppListView::Observer overrides.
25  virtual void OnActivationChanged(views::Widget* widget, bool active) OVERRIDE;
26
27  void OnViewHidden();
28
29 private:
30  void CheckTaskbarOrViewHasFocus();
31
32  // The window to track the active state of.
33  app_list::AppListView* view_;
34
35  // Called to request |view_| be closed.
36  base::Closure on_should_dismiss_;
37
38  // True if we are anticipating that the app list will lose focus, and we want
39  // to take it back. This is used when switching out of Metro mode, and the
40  // browser regains focus after showing the app list.
41  bool regain_next_lost_focus_;
42
43  // When the context menu on the app list's taskbar icon is brought up the
44  // app list should not be hidden, but it should be if the taskbar is clicked
45  // on. There can be a period of time when the taskbar gets focus between a
46  // right mouse click and the menu showing; to prevent hiding the app launcher
47  // when this happens it is kept visible if the taskbar is seen briefly without
48  // the right mouse button down, but not if this happens twice in a row.
49  bool preserving_focus_for_taskbar_menu_;
50
51  // Timer used to check if the taskbar or app list is active. Using a timer
52  // means we don't need to hook Windows, which is apparently not possible
53  // since Vista (and is not nice at any time).
54  base::RepeatingTimer<ActivationTrackerWin> timer_;
55};
56
57#endif  // CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_
58