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.
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_
8 #include "base/macros.h"
9 #include "base/timer/timer.h"
10 #include "ui/app_list/views/app_list_view_observer.h"
12 class AppListServiceWin;
14 // Periodically checks to see if an AppListView has lost focus using a timer.
15 class ActivationTrackerWin : public app_list::AppListViewObserver {
17 explicit ActivationTrackerWin(AppListServiceWin* service);
18 ~ActivationTrackerWin();
20 // app_list::AppListViewObserver:
21 virtual void OnActivationChanged(views::Widget* widget, bool active) OVERRIDE;
26 // Dismisses the app launcher if it has lost focus and the user is not trying
28 void MaybeDismissAppList();
30 // Determines whether the app launcher should be dismissed. This should be
31 // called at most once per timer tick, as it is not idempotent (if the taskbar
32 // is focused, it waits until it has been called twice before dismissing the
34 bool ShouldDismissAppList();
36 AppListServiceWin* service_; // Weak. Owns this.
38 // Records whether, on the previous timer tick, the taskbar had focus without
39 // the right mouse button being down. We allow the taskbar to have focus for
40 // one tick before dismissing the app list. This allows the app list to be
41 // kept visible if the taskbar is seen briefly without the right mouse button
42 // down, but not if this happens for two consecutive ticks.
43 bool taskbar_has_focus_;
45 // Timer used to check if the taskbar or app list is active. Using a timer
46 // means we don't need to hook Windows, which is apparently not possible
47 // since Vista (and is not nice at any time).
48 base::RepeatingTimer<ActivationTrackerWin> timer_;
50 DISALLOW_COPY_AND_ASSIGN(ActivationTrackerWin);
53 #endif // CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_