activation_tracker_win.h revision f2477e01787aa58f445919b809d89e252beef54f
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 ReactivateOnNextFocusLoss() { 21 reactivate_on_next_focus_loss_ = 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 // Dismisses the app launcher if it has lost focus and the user is not trying 31 // to pin it. If it is time to dismiss the app launcher, but 32 // ReactivateOnNextFocusLoss has been called, reactivates the app launcher 33 // instead of dismissing it. 34 void MaybeDismissAppList(); 35 36 // Determines whether the app launcher should be dismissed. This should be 37 // called at most once per timer tick, as it is not idempotent (if the taskbar 38 // is focused, it waits until it has been called twice before dismissing the 39 // app list). 40 bool ShouldDismissAppList(); 41 42 // The window to track the active state of. 43 app_list::AppListView* view_; 44 45 // Called to request |view_| be closed. 46 base::Closure on_should_dismiss_; 47 48 // True if we are anticipating that the app list will lose focus, and we want 49 // to take it back. This is used when switching out of Metro mode, and the 50 // browser regains focus after showing the app list. 51 bool reactivate_on_next_focus_loss_; 52 53 // Records whether, on the previous timer tick, the taskbar had focus without 54 // the right mouse button being down. We allow the taskbar to have focus for 55 // one tick before dismissing the app list. This allows the app list to be 56 // kept visible if the taskbar is seen briefly without the right mouse button 57 // down, but not if this happens for two consecutive ticks. 58 bool taskbar_has_focus_; 59 60 // Timer used to check if the taskbar or app list is active. Using a timer 61 // means we don't need to hook Windows, which is apparently not possible 62 // since Vista (and is not nice at any time). 63 base::RepeatingTimer<ActivationTrackerWin> timer_; 64}; 65 66#endif // CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_ 67