activation_tracker_win.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 13namespace app_list { 14class AppListView; 15} 16 17// Periodically checks to see if an AppListView has lost focus using a timer. 18class ActivationTrackerWin : public app_list::AppListViewObserver { 19 public: 20 ActivationTrackerWin(app_list::AppListView* view, 21 const base::Closure& on_should_dismiss); 22 ~ActivationTrackerWin(); 23 24 // app_list::AppListViewObserver: 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. 32 void MaybeDismissAppList(); 33 34 // Determines whether the app launcher should be dismissed. This should be 35 // called at most once per timer tick, as it is not idempotent (if the taskbar 36 // is focused, it waits until it has been called twice before dismissing the 37 // app list). 38 bool ShouldDismissAppList(); 39 40 // The window to track the active state of. 41 app_list::AppListView* view_; 42 43 // Called to request |view_| be closed. 44 base::Closure on_should_dismiss_; 45 46 // Records whether, on the previous timer tick, the taskbar had focus without 47 // the right mouse button being down. We allow the taskbar to have focus for 48 // one tick before dismissing the app list. This allows the app list to be 49 // kept visible if the taskbar is seen briefly without the right mouse button 50 // down, but not if this happens for two consecutive ticks. 51 bool taskbar_has_focus_; 52 53 // Timer used to check if the taskbar or app list is active. Using a timer 54 // means we don't need to hook Windows, which is apparently not possible 55 // since Vista (and is not nice at any time). 56 base::RepeatingTimer<ActivationTrackerWin> timer_; 57 58 DISALLOW_COPY_AND_ASSIGN(ActivationTrackerWin); 59}; 60 61#endif // CHROME_BROWSER_UI_VIEWS_APP_LIST_WIN_ACTIVATION_TRACKER_WIN_H_ 62