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/timer/timer.h" 16 #include "ui/aura/client/activation_change_observer.h" 17 #include "ui/aura/window_observer.h" 18 19 namespace aura { 20 class RootWindow; 21 } 22 23 namespace ui { 24 class EventHandler; 25 } 26 27 namespace ash { 28 29 namespace internal { 30 class WindowSelectorTest; 31 } 32 33 class ScopedShowWindow; 34 class WindowOverview; 35 class WindowSelectorDelegate; 36 class WindowSelectorItem; 37 38 // The WindowSelector allows selecting a window by alt-tabbing (CYCLE mode) or 39 // by clicking or tapping on it (OVERVIEW mode). A WindowOverview will be shown 40 // in OVERVIEW mode or if the user lingers on a window while alt tabbing. 41 class ASH_EXPORT WindowSelector 42 : public aura::WindowObserver, 43 public aura::client::ActivationChangeObserver { 44 public: 45 enum Direction { 46 FORWARD, 47 BACKWARD 48 }; 49 enum Mode { 50 CYCLE, 51 OVERVIEW 52 }; 53 54 typedef std::vector<aura::Window*> WindowList; 55 56 WindowSelector(const WindowList& windows, 57 Mode mode, 58 WindowSelectorDelegate* delegate); 59 virtual ~WindowSelector(); 60 61 // Step to the next window in |direction|. 62 void Step(Direction direction); 63 64 // Choose the currently selected window. 65 void SelectWindow(); 66 67 // Choose |window| from the available windows to select. 68 void SelectWindow(aura::Window* window); 69 70 // Cancels window selection. 71 void CancelSelection(); 72 73 Mode mode() { return mode_; } 74 75 // aura::WindowObserver: 76 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE; 77 virtual void OnWindowBoundsChanged(aura::Window* window, 78 const gfx::Rect& old_bounds, 79 const gfx::Rect& new_bounds) OVERRIDE; 80 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 81 82 // Overridden from 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 internal::WindowSelectorTest; 91 92 // Begins positioning windows such that all windows are visible on the screen. 93 void StartOverview(); 94 95 // Resets the stored window from RemoveFocusAndSetRestoreWindow to NULL. If 96 // |focus|, restores focus to the stored window. 97 void ResetFocusRestoreWindow(bool focus); 98 99 // The collection of items in the overview wrapped by a helper class which 100 // restores their state and helps transform them to other root windows. 101 ScopedVector<WindowSelectorItem> windows_; 102 103 // Tracks observed windows. 104 std::set<aura::Window*> observed_windows_; 105 106 // The window selection mode. 107 Mode mode_; 108 109 // An event handler listening for the release of the alt key during alt-tab 110 // cycling. 111 scoped_ptr<ui::EventHandler> event_handler_; 112 113 // The currently selected window being shown (temporarily brought to the front 114 // of the stacking order and made visible). 115 scoped_ptr<ScopedShowWindow> showing_window_; 116 117 bool timer_enabled_; 118 base::DelayTimer<WindowSelector> start_overview_timer_; 119 scoped_ptr<WindowOverview> window_overview_; 120 121 // The time when window cycling was started. 122 base::Time cycle_start_time_; 123 124 // Weak pointer to the selector delegate which will be called when a 125 // selection is made. 126 WindowSelectorDelegate* delegate_; 127 128 // Index of the currently selected window if the mode is CYCLE. 129 size_t selected_window_; 130 131 // A weak pointer to the window which was focused on beginning window 132 // selection. If window selection is canceled the focus should be restored to 133 // this window. 134 aura::Window* restore_focus_window_; 135 136 // True when performing operations that may cause window activations. This is 137 // used to prevent handling the resulting expected activation. 138 bool ignore_activations_; 139 140 DISALLOW_COPY_AND_ASSIGN(WindowSelector); 141 }; 142 143 } // namespace ash 144 145 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ 146