Chromium Code Reviews| 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 "base/compiler_specific.h" | 16 #include "ash/wm/common/wm_activation_observer.h" |
| 17 #include "ash/wm/common/wm_window_observer.h" | |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
|
James Cook
2016/05/27 00:02:51
Still needed?
sky
2016/05/27 03:18:04
Removed from here, but I had to add to WindowGrid.
| |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "ui/aura/window_observer.h" | |
| 21 #include "ui/aura/window_tracker.h" | |
| 22 #include "ui/display/display_observer.h" | 21 #include "ui/display/display_observer.h" |
| 23 #include "ui/events/event_handler.h" | |
| 24 #include "ui/views/controls/textfield/textfield_controller.h" | 22 #include "ui/views/controls/textfield/textfield_controller.h" |
| 25 #include "ui/wm/public/activation_change_observer.h" | |
| 26 | |
| 27 namespace aura { | |
| 28 class RootWindow; | |
| 29 class Window; | |
| 30 } | |
| 31 | |
| 32 namespace gfx { | |
| 33 class Rect; | |
| 34 } | |
| 35 | |
| 36 namespace ui { | |
| 37 class LocatedEvent; | |
| 38 } | |
| 39 | 23 |
| 40 namespace views { | 24 namespace views { |
| 41 class Textfield; | 25 class Textfield; |
| 42 class Widget; | 26 class Widget; |
| 43 } | 27 } |
| 44 | 28 |
| 45 namespace ash { | 29 namespace ash { |
| 46 class WindowSelectorDelegate; | 30 class WindowSelectorDelegate; |
| 47 class WindowSelectorItem; | 31 class WindowSelectorItem; |
| 48 class WindowSelectorTest; | 32 class WindowSelectorTest; |
| 49 class WindowGrid; | 33 class WindowGrid; |
| 50 | 34 |
| 51 // The WindowSelector shows a grid of all of your windows, allowing to select | 35 // The WindowSelector shows a grid of all of your windows, allowing to select |
| 52 // one by clicking or tapping on it. | 36 // one by clicking or tapping on it. |
| 53 class ASH_EXPORT WindowSelector : public display::DisplayObserver, | 37 class ASH_EXPORT WindowSelector : public display::DisplayObserver, |
| 54 public aura::WindowObserver, | 38 public wm::WmWindowObserver, |
| 55 public aura::client::ActivationChangeObserver, | 39 public wm::WmActivationObserver, |
| 56 public views::TextfieldController { | 40 public views::TextfieldController { |
| 57 public: | 41 public: |
| 58 // The distance between the top edge of the screen and the bottom edge of | 42 // The distance between the top edge of the screen and the bottom edge of |
| 59 // the text filtering textfield. | 43 // the text filtering textfield. |
| 60 static const int kTextFilterBottomEdge; | 44 static const int kTextFilterBottomEdge; |
| 61 | 45 |
| 62 // Returns true if the window can be selected in overview mode. | 46 // Returns true if the window can be selected in overview mode. |
| 63 static bool IsSelectable(aura::Window* window); | 47 static bool IsSelectable(wm::WmWindow* window); |
| 64 | 48 |
| 65 enum Direction { | 49 enum Direction { |
| 66 LEFT, | 50 LEFT, |
| 67 UP, | 51 UP, |
| 68 RIGHT, | 52 RIGHT, |
| 69 DOWN | 53 DOWN |
| 70 }; | 54 }; |
| 71 | 55 |
| 72 typedef std::vector<aura::Window*> WindowList; | 56 using WindowList = std::vector<wm::WmWindow*>; |
| 73 typedef ScopedVector<WindowSelectorItem> WindowSelectorItemList; | |
| 74 | 57 |
| 75 explicit WindowSelector(WindowSelectorDelegate* delegate); | 58 explicit WindowSelector(WindowSelectorDelegate* delegate); |
| 76 ~WindowSelector() override; | 59 ~WindowSelector() override; |
| 77 | 60 |
| 78 // Initialize with the windows that can be selected. | 61 // Initialize with the windows that can be selected. |
| 79 void Init(const WindowList& windows); | 62 void Init(const WindowList& windows); |
| 80 | 63 |
| 81 // Perform cleanup that cannot be done in the destructor. | 64 // Perform cleanup that cannot be done in the destructor. |
| 82 void Shutdown(); | 65 void Shutdown(); |
| 83 | 66 |
| 84 // Cancels window selection. | 67 // Cancels window selection. |
| 85 void CancelSelection(); | 68 void CancelSelection(); |
| 86 | 69 |
| 87 // Called when the last window selector item from a grid is deleted. | 70 // Called when the last window selector item from a grid is deleted. |
| 88 void OnGridEmpty(WindowGrid* grid); | 71 void OnGridEmpty(WindowGrid* grid); |
| 89 | 72 |
| 90 // Activates |window|. | 73 // Activates |window|. |
| 91 void SelectWindow(aura::Window* window); | 74 void SelectWindow(wm::WmWindow* window); |
| 92 | 75 |
| 93 bool restoring_minimized_windows() const { | 76 bool restoring_minimized_windows() const { |
| 94 return restoring_minimized_windows_; | 77 return restoring_minimized_windows_; |
| 95 } | 78 } |
| 96 | 79 |
| 97 // display::DisplayObserver: | 80 // display::DisplayObserver: |
| 98 void OnDisplayAdded(const display::Display& display) override; | 81 void OnDisplayAdded(const display::Display& display) override; |
| 99 void OnDisplayRemoved(const display::Display& display) override; | 82 void OnDisplayRemoved(const display::Display& display) override; |
| 100 void OnDisplayMetricsChanged(const display::Display& display, | 83 void OnDisplayMetricsChanged(const display::Display& display, |
| 101 uint32_t metrics) override; | 84 uint32_t metrics) override; |
| 102 | 85 |
| 103 // aura::WindowObserver: | 86 // wm::WmWindowObserver: |
| 104 void OnWindowAdded(aura::Window* new_window) override; | 87 void OnWindowTreeChanged(wm::WmWindow* window, |
| 105 void OnWindowDestroying(aura::Window* window) override; | 88 const TreeChangeParams& params) override; |
| 89 void OnWindowDestroying(wm::WmWindow* window) override; | |
| 106 | 90 |
| 107 // aura::client::ActivationChangeObserver: | 91 // wm::WmActivationObserver |
| 108 void OnWindowActivated( | 92 void OnWindowActivated(wm::WmWindow* gained_active, |
| 109 aura::client::ActivationChangeObserver::ActivationReason reason, | 93 wm::WmWindow* lost_active) override; |
| 110 aura::Window* gained_active, | 94 void OnAttemptToReactivateWindow(wm::WmWindow* request_active, |
| 111 aura::Window* lost_active) override; | 95 wm::WmWindow* actual_active) override; |
| 112 void OnAttemptToReactivateWindow(aura::Window* request_active, | |
| 113 aura::Window* actual_active) override; | |
| 114 | 96 |
| 115 // views::TextfieldController: | 97 // views::TextfieldController: |
| 116 void ContentsChanged(views::Textfield* sender, | 98 void ContentsChanged(views::Textfield* sender, |
| 117 const base::string16& new_contents) override; | 99 const base::string16& new_contents) override; |
| 118 bool HandleKeyEvent(views::Textfield* sender, | 100 bool HandleKeyEvent(views::Textfield* sender, |
| 119 const ui::KeyEvent& key_event) override; | 101 const ui::KeyEvent& key_event) override; |
| 120 | 102 |
| 121 private: | 103 private: |
| 122 friend class WindowSelectorTest; | 104 friend class WindowSelectorTest; |
| 123 | 105 |
| 124 // Begins positioning windows such that all windows are visible on the screen. | 106 // Returns the WmWindow for |text_filter_widget_|. |
| 125 void StartOverview(); | 107 wm::WmWindow* GetTextFilterWidgetWindow(); |
| 126 | 108 |
| 127 // Position all of the windows in the overview. | 109 // Position all of the windows in the overview. |
| 128 void PositionWindows(bool animate); | 110 void PositionWindows(bool animate); |
| 129 | 111 |
| 130 // Repositions and resizes |text_filter_widget_| on | 112 // Repositions and resizes |text_filter_widget_| on |
| 131 // DisplayMetricsChanged event. | 113 // DisplayMetricsChanged event. |
| 132 void RepositionTextFilterOnDisplayMetricsChange(); | 114 void RepositionTextFilterOnDisplayMetricsChange(); |
| 133 | 115 |
| 134 // |focus|, restores focus to the stored window. | 116 // |focus|, restores focus to the stored window. |
| 135 void ResetFocusRestoreWindow(bool focus); | 117 void ResetFocusRestoreWindow(bool focus); |
| 136 | 118 |
| 137 // Helper function that moves the selection widget to |direction| on the | 119 // Helper function that moves the selection widget to |direction| on the |
| 138 // corresponding window grid. | 120 // corresponding window grid. |
| 139 void Move(Direction direction, bool animate); | 121 void Move(Direction direction, bool animate); |
| 140 | 122 |
| 141 // Removes all observers that were registered during construction and/or | 123 // Removes all observers that were registered during construction and/or |
| 142 // initialization. | 124 // initialization. |
| 143 void RemoveAllObservers(); | 125 void RemoveAllObservers(); |
| 144 | 126 |
| 145 // Tracks observed windows. | 127 // Tracks observed windows. |
| 146 std::set<aura::Window*> observed_windows_; | 128 std::set<wm::WmWindow*> observed_windows_; |
| 147 | 129 |
| 148 // Weak pointer to the selector delegate which will be called when a | 130 // Weak pointer to the selector delegate which will be called when a |
| 149 // selection is made. | 131 // selection is made. |
| 150 WindowSelectorDelegate* delegate_; | 132 WindowSelectorDelegate* delegate_; |
| 151 | 133 |
| 152 // A weak pointer to the window which was focused on beginning window | 134 // A weak pointer to the window which was focused on beginning window |
| 153 // selection. If window selection is canceled the focus should be restored to | 135 // selection. If window selection is canceled the focus should be restored to |
| 154 // this window. | 136 // this window. |
| 155 aura::Window* restore_focus_window_; | 137 wm::WmWindow* restore_focus_window_; |
| 156 | 138 |
| 157 // True when performing operations that may cause window activations. This is | 139 // True when performing operations that may cause window activations. This is |
| 158 // used to prevent handling the resulting expected activation. | 140 // used to prevent handling the resulting expected activation. |
| 159 bool ignore_activations_; | 141 bool ignore_activations_; |
| 160 | 142 |
| 161 // List of all the window overview grids, one for each root window. | 143 // List of all the window overview grids, one for each root window. |
| 162 ScopedVector<WindowGrid> grid_list_; | 144 std::vector<std::unique_ptr<WindowGrid>> grid_list_; |
| 163 | 145 |
| 164 // Tracks the index of the root window the selection widget is in. | 146 // Tracks the index of the root window the selection widget is in. |
| 165 size_t selected_grid_index_; | 147 size_t selected_grid_index_; |
| 166 | 148 |
| 167 // The following variables are used for metric collection purposes. All of | 149 // The following variables are used for metric collection purposes. All of |
| 168 // them refer to this particular overview session and are not cumulative: | 150 // them refer to this particular overview session and are not cumulative: |
| 169 // The time when overview was started. | 151 // The time when overview was started. |
| 170 base::Time overview_start_time_; | 152 base::Time overview_start_time_; |
| 171 | 153 |
| 172 // The number of arrow key presses. | 154 // The number of arrow key presses. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 193 // Tracks whether minimized windows are currently being restored for overview | 175 // Tracks whether minimized windows are currently being restored for overview |
| 194 // mode. | 176 // mode. |
| 195 bool restoring_minimized_windows_; | 177 bool restoring_minimized_windows_; |
| 196 | 178 |
| 197 DISALLOW_COPY_AND_ASSIGN(WindowSelector); | 179 DISALLOW_COPY_AND_ASSIGN(WindowSelector); |
| 198 }; | 180 }; |
| 199 | 181 |
| 200 } // namespace ash | 182 } // namespace ash |
| 201 | 183 |
| 202 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ | 184 #endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_H_ |
| OLD | NEW |