OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_WM_WINDOW_SELECTOR_H_ | 5 #ifndef ASH_WM_WINDOW_SELECTOR_H_ |
6 #define ASH_WM_WINDOW_SELECTOR_H_ | 6 #define ASH_WM_WINDOW_SELECTOR_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/scoped_vector.h" | |
11 #include "ui/aura/window_observer.h" | 13 #include "ui/aura/window_observer.h" |
12 #include "ui/base/events/event_handler.h" | 14 #include "ui/base/events/event_handler.h" |
13 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
14 | 16 |
15 namespace aura { | 17 namespace aura { |
16 class RootWindow; | 18 class RootWindow; |
17 } | 19 } |
18 | 20 |
21 namespace ui { | |
22 class LocatedEvent; | |
23 } | |
24 | |
25 namespace views { | |
26 class Widget; | |
27 } | |
28 | |
19 namespace ash { | 29 namespace ash { |
20 | 30 |
21 class WindowSelectorDelegate; | 31 class WindowSelectorDelegate; |
32 class WindowSelectorWindow; | |
22 | 33 |
23 // The WindowSelector shows a grid of all of your windows and allows selecting | 34 // The WindowSelector shows a grid of all of your windows and allows selecting |
24 // a window by clicking or tapping on it. | 35 // a window by clicking or tapping on it (OVERVIEW mode) or by alt-tabbing to |
36 // it (CYCLE mode). | |
25 class WindowSelector : public ui::EventHandler, | 37 class WindowSelector : public ui::EventHandler, |
26 public aura::WindowObserver { | 38 public aura::WindowObserver { |
27 public: | 39 public: |
40 enum Direction { | |
41 FORWARD, | |
42 BACKWARD | |
43 }; | |
44 enum Mode { | |
45 CYCLE, | |
46 OVERVIEW | |
47 }; | |
48 | |
28 typedef std::vector<aura::Window*> WindowList; | 49 typedef std::vector<aura::Window*> WindowList; |
29 | 50 |
30 WindowSelector(const WindowList& windows, | 51 WindowSelector(const WindowList& windows, |
52 Mode mode, | |
31 WindowSelectorDelegate* delegate); | 53 WindowSelectorDelegate* delegate); |
32 virtual ~WindowSelector(); | 54 virtual ~WindowSelector(); |
33 | 55 |
56 // Step to the next window in |direction|. | |
57 void Step(Direction direction); | |
58 | |
59 // Select the current window. | |
60 void SelectWindow(); | |
61 | |
62 Mode mode() { return mode_; } | |
63 | |
34 // ui::EventHandler: | 64 // ui::EventHandler: |
35 virtual void OnEvent(ui::Event* event) OVERRIDE; | 65 virtual void OnEvent(ui::Event* event) OVERRIDE; |
36 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 66 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
37 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 67 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
38 | 68 |
39 // aura::WindowObserver: | 69 // aura::WindowObserver: |
40 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; | 70 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; |
41 | 71 |
42 private: | 72 private: |
43 struct WindowDetails { | 73 // Returns the target of |event| or NULL if the event is not targeted at |
44 WindowDetails() : window(NULL), minimized(false) {} | 74 // any of the windows in the selector. |
75 WindowSelectorWindow* GetEventTarget(ui::LocatedEvent* event); | |
45 | 76 |
46 bool operator==(const aura::Window* other_window) const { | 77 // Handles a selection event for |target|. |
47 return window == other_window; | 78 void HandleSelectionEvent(WindowSelectorWindow* target); |
48 } | |
49 | 79 |
50 // A weak pointer to the window. | 80 // Position all of the windows based on the current selection mode. |
51 aura::Window* window; | 81 void PositionWindows(); |
82 // Position all of the windows from |root_window| on |root_window|. | |
83 void PositionWindowsFromRoot(aura::RootWindow* root_window); | |
84 // Position all of the |windows| to fit on the |root_window|. | |
85 void PositionWindowsOnRoot(aura::RootWindow* root_window, | |
86 const std::vector<WindowSelectorWindow*>& windows); | |
52 | 87 |
53 // If true, the window was minimized and this should be restored if the | 88 void InitializeSelectionWidget(); |
Daniel Erat
2013/08/09 20:54:35
nit: add a blank line after this line
flackr
2013/08/09 22:15:36
Done.
| |
54 // window was not selected. | 89 // Updates the selection widget's location to the currently selected window. |
55 bool minimized; | 90 // If |animate| the transition to the new location is animated. |
91 void UpdateSelectionLocation(bool animate); | |
56 | 92 |
57 // The original transform of the window before entering overview mode. | 93 // The collection of windows in the overview wrapped by a helper class which |
58 gfx::Transform original_transform; | 94 // restores their state and helps transform them to other root windows. |
59 }; | 95 ScopedVector<WindowSelectorWindow> windows_; |
60 | 96 |
61 void HandleSelectionEvent(ui::Event* event); | 97 // The window selection mode. |
62 void PositionWindows(); | 98 Mode mode_; |
63 void PositionWindowsOnRoot(aura::RootWindow* root_window); | |
64 | |
65 void SelectWindow(aura::Window*); | |
66 | |
67 // List of weak pointers of windows to select from. | |
68 std::vector<WindowDetails> windows_; | |
69 | 99 |
70 // Weak pointer to the selector delegate which will be called when a | 100 // Weak pointer to the selector delegate which will be called when a |
71 // selection is made. | 101 // selection is made. |
72 WindowSelectorDelegate* delegate_; | 102 WindowSelectorDelegate* delegate_; |
73 | 103 |
104 // Index of the currently selected window if the mode is CYCLE. | |
105 size_t selected_window_; | |
106 | |
107 // Widget indicating which window is currently selected. | |
108 scoped_ptr<views::Widget> selection_widget_; | |
109 | |
110 // If not NULL, this is the root window selection is taking place in used | |
Daniel Erat
2013/08/09 20:54:35
nit: i found this a bit hard to parse. how about t
flackr
2013/08/09 22:15:36
Done.
| |
111 // for CYCLE mode. | |
112 aura::RootWindow* selection_root_; | |
113 | |
74 DISALLOW_COPY_AND_ASSIGN(WindowSelector); | 114 DISALLOW_COPY_AND_ASSIGN(WindowSelector); |
75 }; | 115 }; |
76 | 116 |
77 } // namespace ash | 117 } // namespace ash |
78 | 118 |
79 #endif // ASH_WM_WINDOW_SELECTOR_H_ | 119 #endif // ASH_WM_WINDOW_SELECTOR_H_ |
OLD | NEW |