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.
5 #ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_
6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_
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/wm/public/activation_change_observer.h"
30 class WindowSelectorTest;
33 class ScopedShowWindow;
35 class WindowSelectorDelegate;
36 class WindowSelectorItem;
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 {
54 typedef std::vector<aura::Window*> WindowList;
56 WindowSelector(const WindowList& windows,
58 WindowSelectorDelegate* delegate);
59 virtual ~WindowSelector();
61 // Step to the next window in |direction|.
62 void Step(Direction direction);
64 // Choose the currently selected window.
67 // Choose |window| from the available windows to select.
68 void SelectWindow(aura::Window* window);
70 // Cancels window selection.
71 void CancelSelection();
73 Mode mode() { return mode_; }
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;
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;
90 friend class internal::WindowSelectorTest;
92 // Begins positioning windows such that all windows are visible on the screen.
95 // Resets the stored window from RemoveFocusAndSetRestoreWindow to NULL. If
96 // |focus|, restores focus to the stored window.
97 void ResetFocusRestoreWindow(bool focus);
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_;
103 // Tracks observed windows.
104 std::set<aura::Window*> observed_windows_;
106 // The window selection mode.
109 // An event handler listening for the release of the alt key during alt-tab
111 scoped_ptr<ui::EventHandler> event_handler_;
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_;
117 scoped_ptr<WindowOverview> window_overview_;
119 // The time when window cycling was started.
120 base::Time cycle_start_time_;
122 // Weak pointer to the selector delegate which will be called when a
123 // selection is made.
124 WindowSelectorDelegate* delegate_;
126 // Index of the currently selected window if the mode is CYCLE.
127 size_t selected_window_;
129 // A weak pointer to the window which was focused on beginning window
130 // selection. If window selection is canceled the focus should be restored to
132 aura::Window* restore_focus_window_;
134 // True when performing operations that may cause window activations. This is
135 // used to prevent handling the resulting expected activation.
136 bool ignore_activations_;
138 DISALLOW_COPY_AND_ASSIGN(WindowSelector);
143 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_