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/basictypes.h" 9 #include "base/callback.h" 10 #include "base/timer/timer.h" 11 #include "ui/app_list/views/app_list_view_observer.h" 12 13 namespace app_list { 14 class AppListView; 15 } 16 17 // Periodically checks to see if an AppListView has lost focus using a timer. 18 class ActivationTrackerWin : public app_list::AppListViewObserver { 19 public: 20 ActivationTrackerWin(app_list::AppListView* view, 21 const base::Closure& on_should_dismiss); 22 ~ActivationTrackerWin(); 23 24 void ReactivateOnNextFocusLoss() { 25 reactivate_on_next_focus_loss_ = true; 26 } 27 28 // app_list::AppListViewObserver: 29 virtual void OnActivationChanged(views::Widget* widget, bool active) OVERRIDE; 30 31 void OnViewHidden(); 32 33 private: 34 // Dismisses the app launcher if it has lost focus and the user is not trying 35 // to pin it. If it is time to dismiss the app launcher, but 36 // ReactivateOnNextFocusLoss has been called, reactivates the app launcher 37 // instead of dismissing it. 38 void MaybeDismissAppList(); 39 40 // Determines whether the app launcher should be dismissed. This should be 41 // called at most once per timer tick, as it is not idempotent (if the taskbar 42 // is focused, it waits until it has been called twice before dismissing the 43 // app list). 44 bool ShouldDismissAppList(); 45 46 // The window to track the active state of. 47 app_list::AppListView* view_; 48 49 // Called to request |view_| be closed. 50 base::Closure on_should_dismiss_; 51 52 // True if we are anticipating that the app list will lose focus, and we want 53 // to take it back. This is used when switching out of Metro mode, and the 54 // browser regains focus after showing the app list. 55 bool reactivate_on_next_focus_loss_; 56 57 // Records whether, on the previous timer tick, the taskbar had focus without 58 // the right mouse button being down. We allow the taskbar to have focus for 59 // one tick before dismissing the app list. This allows the app list to be 60 // kept visible if the taskbar is seen briefly without the right mouse button 61 // down, but not if this happens for two consecutive ticks. 62 bool taskbar_has_focus_; 63 64 // Timer used to check if the taskbar or app list is active. Using a timer 65 // means we don't need to hook Windows, which is apparently not possible 66 // since Vista (and is not nice at any time). 67 base::RepeatingTimer<ActivationTrackerWin> timer_; 68 69 DISALLOW_COPY_AND_ASSIGN(ActivationTrackerWin); 70 }; 71 72 #endif // CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_ 73