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 ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ 6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ 7 8 #include <set> 9 #include <vector> 10 11 #include "ash/ash_export.h" 12 #include "base/compiler_specific.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_vector.h" 15 #include "base/time/time.h" 16 #include "ui/aura/window_observer.h" 17 #include "ui/aura/window_tracker.h" 18 #include "ui/events/event_handler.h" 19 #include "ui/gfx/display_observer.h" 20 #include "ui/wm/public/activation_change_observer.h" 21 22 namespace aura { 23 class RootWindow; 24 class Window; 25 } 26 27 namespace gfx { 28 class Rect; 29 } 30 31 namespace ui { 32 class LocatedEvent; 33 } 34 35 namespace ash { 36 class WindowSelectorDelegate; 37 class WindowSelectorItem; 38 class WindowSelectorTest; 39 class WindowGrid; 40 41 // The WindowSelector shows a grid of all of your windows, allowing to select 42 // one by clicking or tapping on it. 43 class ASH_EXPORT WindowSelector 44 : public ui::EventHandler, 45 public gfx::DisplayObserver, 46 public aura::WindowObserver, 47 public aura::client::ActivationChangeObserver { 48 public: 49 enum Direction { 50 LEFT, 51 UP, 52 RIGHT, 53 DOWN 54 }; 55 56 typedef std::vector<aura::Window*> WindowList; 57 typedef ScopedVector<WindowSelectorItem> WindowSelectorItemList; 58 59 WindowSelector(const WindowList& windows, 60 WindowSelectorDelegate* delegate); 61 virtual ~WindowSelector(); 62 63 // Cancels window selection. 64 void CancelSelection(); 65 66 // Called when the last window selector item from a grid is deleted. 67 void OnGridEmpty(WindowGrid* grid); 68 69 // ui::EventHandler: 70 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 71 72 // gfx::DisplayObserver: 73 virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE; 74 virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE; 75 virtual void OnDisplayMetricsChanged(const gfx::Display& display, 76 uint32_t metrics) OVERRIDE; 77 78 // aura::WindowObserver: 79 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE; 80 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 81 82 // aura::client::ActivationChangeObserver: 83 virtual void OnWindowActivated(aura::Window* gained_active, 84 aura::Window* lost_active) OVERRIDE; 85 virtual void OnAttemptToReactivateWindow( 86 aura::Window* request_active, 87 aura::Window* actual_active) OVERRIDE; 88 89 private: 90 friend class WindowSelectorTest; 91 92 // Begins positioning windows such that all windows are visible on the screen. 93 void StartOverview(); 94 95 // Position all of the windows in the overview. 96 void PositionWindows(bool animate); 97 98 // Hide and track all hidden windows not in the overview item list. 99 void HideAndTrackNonOverviewWindows(); 100 101 // |focus|, restores focus to the stored window. 102 void ResetFocusRestoreWindow(bool focus); 103 104 // Helper function that moves the selection widget to |direction| on the 105 // corresponding window grid. 106 void Move(Direction direction); 107 108 // Tracks observed windows. 109 std::set<aura::Window*> observed_windows_; 110 111 // Weak pointer to the selector delegate which will be called when a 112 // selection is made. 113 WindowSelectorDelegate* delegate_; 114 115 // A weak pointer to the window which was focused on beginning window 116 // selection. If window selection is canceled the focus should be restored to 117 // this window. 118 aura::Window* restore_focus_window_; 119 120 // True when performing operations that may cause window activations. This is 121 // used to prevent handling the resulting expected activation. 122 bool ignore_activations_; 123 124 // List of all the window overview grids, one for each root window. 125 ScopedVector<WindowGrid> grid_list_; 126 127 // Tracks windows which were hidden because they were not part of the 128 // overview. 129 aura::WindowTracker hidden_windows_; 130 131 // Tracks the index of the root window the selection widget is in. 132 size_t selected_grid_index_; 133 134 // The following variables are used for metric collection purposes. All of 135 // them refer to this particular overview session and are not cumulative: 136 // The time when overview was started. 137 base::Time overview_start_time_; 138 139 // The number of arrow key presses. 140 size_t num_key_presses_; 141 142 // The number of items in the overview. 143 size_t num_items_; 144 145 DISALLOW_COPY_AND_ASSIGN(WindowSelector); 146 }; 147 148 } // namespace ash 149 150 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ 151