Morph the selector widget to a constant padding on the window shapes in overview.
[chromium-blink-merge.git] / ash / wm / overview / window_selector.h
blobb962ff33d6783549d8993b272e987433bbea7249
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_
8 #include <set>
9 #include <vector>
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"
19 namespace aura {
20 class RootWindow;
23 namespace ui {
24 class EventHandler;
27 namespace ash {
29 namespace internal {
30 class WindowSelectorTest;
33 class WindowOverview;
34 class WindowSelectorDelegate;
35 class WindowSelectorItem;
37 // The WindowSelector allows selecting a window by alt-tabbing (CYCLE mode) or
38 // by clicking or tapping on it (OVERVIEW mode). A WindowOverview will be shown
39 // in OVERVIEW mode or if the user lingers on a window while alt tabbing.
40 class ASH_EXPORT WindowSelector
41 : public aura::WindowObserver,
42 public aura::client::ActivationChangeObserver {
43 public:
44 enum Direction {
45 FORWARD,
46 BACKWARD
48 enum Mode {
49 CYCLE,
50 OVERVIEW
53 typedef std::vector<aura::Window*> WindowList;
55 WindowSelector(const WindowList& windows,
56 Mode mode,
57 WindowSelectorDelegate* delegate);
58 virtual ~WindowSelector();
60 // Step to the next window in |direction|.
61 void Step(Direction direction);
63 // Choose the currently selected window.
64 void SelectWindow();
66 // Choose |window| from the available windows to select.
67 void SelectWindow(aura::Window* window);
69 // Cancels window selection.
70 void CancelSelection();
72 Mode mode() { return mode_; }
74 // aura::WindowObserver:
75 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE;
76 virtual void OnWindowBoundsChanged(aura::Window* window,
77 const gfx::Rect& old_bounds,
78 const gfx::Rect& new_bounds) OVERRIDE;
79 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
81 // Overridden from aura::client::ActivationChangeObserver:
82 virtual void OnWindowActivated(aura::Window* gained_active,
83 aura::Window* lost_active) OVERRIDE;
84 virtual void OnAttemptToReactivateWindow(
85 aura::Window* request_active,
86 aura::Window* actual_active) OVERRIDE;
88 private:
89 friend class internal::WindowSelectorTest;
91 // Begins positioning windows such that all windows are visible on the screen.
92 void StartOverview();
94 // Stores the currently focused window and removes focus from it.
95 void RemoveFocusAndSetRestoreWindow();
97 // Resets the stored window from RemoveFocusAndSetRestoreWindow to NULL. If
98 // |focus|, restores focus to the stored window.
99 void ResetFocusRestoreWindow(bool focus);
101 // The collection of items in the overview wrapped by a helper class which
102 // restores their state and helps transform them to other root windows.
103 ScopedVector<WindowSelectorItem> windows_;
105 // Tracks observed windows.
106 std::set<aura::Window*> observed_windows_;
108 // The window selection mode.
109 Mode mode_;
111 // An event handler listening for the release of the alt key during alt-tab
112 // cycling.
113 scoped_ptr<ui::EventHandler> event_handler_;
115 base::DelayTimer<WindowSelector> start_overview_timer_;
116 scoped_ptr<WindowOverview> window_overview_;
118 // Weak pointer to the selector delegate which will be called when a
119 // selection is made.
120 WindowSelectorDelegate* delegate_;
122 // Index of the currently selected window if the mode is CYCLE.
123 size_t selected_window_;
125 // A weak pointer to the window which was focused on entering overview mode.
126 // If overview mode is canceled the focus should be restored to this window.
127 aura::Window* restore_focus_window_;
129 // True when restoring focus to the window. This is used to prevent handling
130 // the resulting activation.
131 bool restoring_focus_;
133 DISALLOW_COPY_AND_ASSIGN(WindowSelector);
136 } // namespace ash
138 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_