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_OVERVIEW_WINDOW_SELECTOR_H_ | 5 #ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ |
6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ | 6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "ash/ash_export.h" | 15 #include "ash/ash_export.h" |
16 #include "ash/common/wm/wm_activation_observer.h" | 16 #include "ash/common/wm_activation_observer.h" |
17 #include "ash/common/wm/wm_window_observer.h" | 17 #include "ash/common/wm_window_observer.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "ui/display/display_observer.h" | 20 #include "ui/display/display_observer.h" |
21 #include "ui/views/controls/textfield/textfield_controller.h" | 21 #include "ui/views/controls/textfield/textfield_controller.h" |
22 | 22 |
23 namespace views { | 23 namespace views { |
24 class Textfield; | 24 class Textfield; |
25 class Widget; | 25 class Widget; |
26 } | 26 } |
27 | 27 |
28 namespace ash { | 28 namespace ash { |
29 class WindowSelectorDelegate; | 29 class WindowSelectorDelegate; |
30 class WindowSelectorItem; | 30 class WindowSelectorItem; |
31 class WindowSelectorTest; | 31 class WindowSelectorTest; |
32 class WindowGrid; | 32 class WindowGrid; |
33 | 33 |
34 // The WindowSelector shows a grid of all of your windows, allowing to select | 34 // The WindowSelector shows a grid of all of your windows, allowing to select |
35 // one by clicking or tapping on it. | 35 // one by clicking or tapping on it. |
36 class ASH_EXPORT WindowSelector : public display::DisplayObserver, | 36 class ASH_EXPORT WindowSelector : public display::DisplayObserver, |
37 public wm::WmWindowObserver, | 37 public WmWindowObserver, |
38 public wm::WmActivationObserver, | 38 public WmActivationObserver, |
39 public views::TextfieldController { | 39 public views::TextfieldController { |
40 public: | 40 public: |
41 // The distance between the top edge of the screen and the bottom edge of | 41 // The distance between the top edge of the screen and the bottom edge of |
42 // the text filtering textfield. | 42 // the text filtering textfield. |
43 static const int kTextFilterBottomEdge; | 43 static const int kTextFilterBottomEdge; |
44 | 44 |
45 // Returns true if the window can be selected in overview mode. | 45 // Returns true if the window can be selected in overview mode. |
46 static bool IsSelectable(wm::WmWindow* window); | 46 static bool IsSelectable(WmWindow* window); |
47 | 47 |
48 enum Direction { | 48 enum Direction { |
49 LEFT, | 49 LEFT, |
50 UP, | 50 UP, |
51 RIGHT, | 51 RIGHT, |
52 DOWN | 52 DOWN |
53 }; | 53 }; |
54 | 54 |
55 using WindowList = std::vector<wm::WmWindow*>; | 55 using WindowList = std::vector<WmWindow*>; |
56 | 56 |
57 explicit WindowSelector(WindowSelectorDelegate* delegate); | 57 explicit WindowSelector(WindowSelectorDelegate* delegate); |
58 ~WindowSelector() override; | 58 ~WindowSelector() override; |
59 | 59 |
60 // Initialize with the windows that can be selected. | 60 // Initialize with the windows that can be selected. |
61 void Init(const WindowList& windows); | 61 void Init(const WindowList& windows); |
62 | 62 |
63 // Perform cleanup that cannot be done in the destructor. | 63 // Perform cleanup that cannot be done in the destructor. |
64 void Shutdown(); | 64 void Shutdown(); |
65 | 65 |
66 // Cancels window selection. | 66 // Cancels window selection. |
67 void CancelSelection(); | 67 void CancelSelection(); |
68 | 68 |
69 // Called when the last window selector item from a grid is deleted. | 69 // Called when the last window selector item from a grid is deleted. |
70 void OnGridEmpty(WindowGrid* grid); | 70 void OnGridEmpty(WindowGrid* grid); |
71 | 71 |
72 // Activates |window|. | 72 // Activates |window|. |
73 void SelectWindow(wm::WmWindow* window); | 73 void SelectWindow(WmWindow* window); |
74 | 74 |
75 bool restoring_minimized_windows() const { | 75 bool restoring_minimized_windows() const { |
76 return restoring_minimized_windows_; | 76 return restoring_minimized_windows_; |
77 } | 77 } |
78 | 78 |
79 // display::DisplayObserver: | 79 // display::DisplayObserver: |
80 void OnDisplayAdded(const display::Display& display) override; | 80 void OnDisplayAdded(const display::Display& display) override; |
81 void OnDisplayRemoved(const display::Display& display) override; | 81 void OnDisplayRemoved(const display::Display& display) override; |
82 void OnDisplayMetricsChanged(const display::Display& display, | 82 void OnDisplayMetricsChanged(const display::Display& display, |
83 uint32_t metrics) override; | 83 uint32_t metrics) override; |
84 | 84 |
85 // wm::WmWindowObserver: | 85 // WmWindowObserver: |
86 void OnWindowTreeChanged(wm::WmWindow* window, | 86 void OnWindowTreeChanged(WmWindow* window, |
87 const TreeChangeParams& params) override; | 87 const TreeChangeParams& params) override; |
88 void OnWindowDestroying(wm::WmWindow* window) override; | 88 void OnWindowDestroying(WmWindow* window) override; |
89 | 89 |
90 // wm::WmActivationObserver | 90 // WmActivationObserver |
91 void OnWindowActivated(wm::WmWindow* gained_active, | 91 void OnWindowActivated(WmWindow* gained_active, |
92 wm::WmWindow* lost_active) override; | 92 WmWindow* lost_active) override; |
93 void OnAttemptToReactivateWindow(wm::WmWindow* request_active, | 93 void OnAttemptToReactivateWindow(WmWindow* request_active, |
94 wm::WmWindow* actual_active) override; | 94 WmWindow* actual_active) override; |
95 | 95 |
96 // views::TextfieldController: | 96 // views::TextfieldController: |
97 void ContentsChanged(views::Textfield* sender, | 97 void ContentsChanged(views::Textfield* sender, |
98 const base::string16& new_contents) override; | 98 const base::string16& new_contents) override; |
99 bool HandleKeyEvent(views::Textfield* sender, | 99 bool HandleKeyEvent(views::Textfield* sender, |
100 const ui::KeyEvent& key_event) override; | 100 const ui::KeyEvent& key_event) override; |
101 | 101 |
102 private: | 102 private: |
103 friend class WindowSelectorTest; | 103 friend class WindowSelectorTest; |
104 | 104 |
105 // Returns the WmWindow for |text_filter_widget_|. | 105 // Returns the WmWindow for |text_filter_widget_|. |
106 wm::WmWindow* GetTextFilterWidgetWindow(); | 106 WmWindow* GetTextFilterWidgetWindow(); |
107 | 107 |
108 // Position all of the windows in the overview. | 108 // Position all of the windows in the overview. |
109 void PositionWindows(bool animate); | 109 void PositionWindows(bool animate); |
110 | 110 |
111 // Repositions and resizes |text_filter_widget_| on | 111 // Repositions and resizes |text_filter_widget_| on |
112 // DisplayMetricsChanged event. | 112 // DisplayMetricsChanged event. |
113 void RepositionTextFilterOnDisplayMetricsChange(); | 113 void RepositionTextFilterOnDisplayMetricsChange(); |
114 | 114 |
115 // |focus|, restores focus to the stored window. | 115 // |focus|, restores focus to the stored window. |
116 void ResetFocusRestoreWindow(bool focus); | 116 void ResetFocusRestoreWindow(bool focus); |
117 | 117 |
118 // Helper function that moves the selection widget to |direction| on the | 118 // Helper function that moves the selection widget to |direction| on the |
119 // corresponding window grid. | 119 // corresponding window grid. |
120 void Move(Direction direction, bool animate); | 120 void Move(Direction direction, bool animate); |
121 | 121 |
122 // Removes all observers that were registered during construction and/or | 122 // Removes all observers that were registered during construction and/or |
123 // initialization. | 123 // initialization. |
124 void RemoveAllObservers(); | 124 void RemoveAllObservers(); |
125 | 125 |
126 // Tracks observed windows. | 126 // Tracks observed windows. |
127 std::set<wm::WmWindow*> observed_windows_; | 127 std::set<WmWindow*> observed_windows_; |
128 | 128 |
129 // Weak pointer to the selector delegate which will be called when a | 129 // Weak pointer to the selector delegate which will be called when a |
130 // selection is made. | 130 // selection is made. |
131 WindowSelectorDelegate* delegate_; | 131 WindowSelectorDelegate* delegate_; |
132 | 132 |
133 // A weak pointer to the window which was focused on beginning window | 133 // A weak pointer to the window which was focused on beginning window |
134 // selection. If window selection is canceled the focus should be restored to | 134 // selection. If window selection is canceled the focus should be restored to |
135 // this window. | 135 // this window. |
136 wm::WmWindow* restore_focus_window_; | 136 WmWindow* restore_focus_window_; |
137 | 137 |
138 // True when performing operations that may cause window activations. This is | 138 // True when performing operations that may cause window activations. This is |
139 // used to prevent handling the resulting expected activation. | 139 // used to prevent handling the resulting expected activation. |
140 bool ignore_activations_; | 140 bool ignore_activations_; |
141 | 141 |
142 // List of all the window overview grids, one for each root window. | 142 // List of all the window overview grids, one for each root window. |
143 std::vector<std::unique_ptr<WindowGrid>> grid_list_; | 143 std::vector<std::unique_ptr<WindowGrid>> grid_list_; |
144 | 144 |
145 // Tracks the index of the root window the selection widget is in. | 145 // Tracks the index of the root window the selection widget is in. |
146 size_t selected_grid_index_; | 146 size_t selected_grid_index_; |
(...skipping 27 matching lines...) Expand all Loading... |
174 // Tracks whether minimized windows are currently being restored for overview | 174 // Tracks whether minimized windows are currently being restored for overview |
175 // mode. | 175 // mode. |
176 bool restoring_minimized_windows_; | 176 bool restoring_minimized_windows_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(WindowSelector); | 178 DISALLOW_COPY_AND_ASSIGN(WindowSelector); |
179 }; | 179 }; |
180 | 180 |
181 } // namespace ash | 181 } // namespace ash |
182 | 182 |
183 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ | 183 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ |
OLD | NEW |