| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GRID_H_ | 5 #ifndef ASH_WM_OVERVIEW_WINDOW_GRID_H_ |
| 6 #define ASH_WM_OVERVIEW_WINDOW_GRID_H_ | 6 #define ASH_WM_OVERVIEW_WINDOW_GRID_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "ash/wm/common/wm_window_observer.h" |
| 14 #include "ash/wm/overview/window_selector.h" | 15 #include "ash/wm/overview/window_selector.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "ui/aura/window_observer.h" | |
| 17 | |
| 18 namespace aura { | |
| 19 class Window; | |
| 20 } | |
| 21 | 17 |
| 22 namespace views { | 18 namespace views { |
| 23 class Widget; | 19 class Widget; |
| 24 } | 20 } |
| 25 | 21 |
| 26 namespace ash { | 22 namespace ash { |
| 27 | 23 |
| 28 class WindowSelectorItem; | 24 class WindowSelectorItem; |
| 29 | 25 |
| 30 // Represents a grid of windows in the Overview Mode in a particular root | 26 // Represents a grid of windows in the Overview Mode in a particular root |
| 31 // window, and manages a selection widget that can be moved with the arrow keys. | 27 // window, and manages a selection widget that can be moved with the arrow keys. |
| 32 // The idea behind the movement strategy is that it should be possible to access | 28 // The idea behind the movement strategy is that it should be possible to access |
| 33 // any window pressing a given arrow key repeatedly. | 29 // any window pressing a given arrow key repeatedly. |
| 34 // +-------+ +-------+ +-------+ | 30 // +-------+ +-------+ +-------+ |
| 35 // | 0 | | 1 | | 2 | | 31 // | 0 | | 1 | | 2 | |
| 36 // +-------+ +-------+ +-------+ | 32 // +-------+ +-------+ +-------+ |
| 37 // +-------+ +-------+ +-------+ | 33 // +-------+ +-------+ +-------+ |
| 38 // | 3 | | 4 | | 5 | | 34 // | 3 | | 4 | | 5 | |
| 39 // +-------+ +-------+ +-------+ | 35 // +-------+ +-------+ +-------+ |
| 40 // +-------+ | 36 // +-------+ |
| 41 // | 6 | | 37 // | 6 | |
| 42 // +-------+ | 38 // +-------+ |
| 43 // Example sequences: | 39 // Example sequences: |
| 44 // - Going right to left | 40 // - Going right to left |
| 45 // 0, 1, 2, 3, 4, 5, 6 | 41 // 0, 1, 2, 3, 4, 5, 6 |
| 46 // - Going "top" to "bottom" | 42 // - Going "top" to "bottom" |
| 47 // 0, 3, 6, 1, 4, 2, 5 | 43 // 0, 3, 6, 1, 4, 2, 5 |
| 48 // The selector is switched to the next window grid (if available) or wrapped if | 44 // The selector is switched to the next window grid (if available) or wrapped if |
| 49 // it reaches the end of its movement sequence. | 45 // it reaches the end of its movement sequence. |
| 50 class ASH_EXPORT WindowGrid : public aura::WindowObserver { | 46 class ASH_EXPORT WindowGrid : public wm::WmWindowObserver { |
| 51 public: | 47 public: |
| 52 WindowGrid(aura::Window* root_window, | 48 WindowGrid(wm::WmWindow* root_window, |
| 53 const std::vector<aura::Window*>& window_list, | 49 const std::vector<wm::WmWindow*>& window_list, |
| 54 WindowSelector* window_selector); | 50 WindowSelector* window_selector); |
| 55 ~WindowGrid() override; | 51 ~WindowGrid() override; |
| 56 | 52 |
| 57 // Prepares the windows in this grid for overview. This will restore all | 53 // Prepares the windows in this grid for overview. This will restore all |
| 58 // minimized windows and ensure they are visible. | 54 // minimized windows and ensure they are visible. |
| 59 void PrepareForOverview(); | 55 void PrepareForOverview(); |
| 60 | 56 |
| 61 // Positions all the windows in the grid. | 57 // Positions all the windows in the grid. |
| 62 void PositionWindows(bool animate); | 58 void PositionWindows(bool animate); |
| 63 | 59 |
| 64 // Updates |selected_index_| according to the specified |direction| and calls | 60 // Updates |selected_index_| according to the specified |direction| and calls |
| 65 // MoveSelectionWidget(). Returns |true| if the new selection index is out of | 61 // MoveSelectionWidget(). Returns |true| if the new selection index is out of |
| 66 // this window grid bounds. | 62 // this window grid bounds. |
| 67 bool Move(WindowSelector::Direction direction, bool animate); | 63 bool Move(WindowSelector::Direction direction, bool animate); |
| 68 | 64 |
| 69 // Returns the target selected window, or NULL if there is none selected. | 65 // Returns the target selected window, or NULL if there is none selected. |
| 70 WindowSelectorItem* SelectedWindow() const; | 66 WindowSelectorItem* SelectedWindow() const; |
| 71 | 67 |
| 72 // Returns true if a window is contained in any of the WindowSelectorItems | 68 // Returns true if a window is contained in any of the WindowSelectorItems |
| 73 // this grid owns. | 69 // this grid owns. |
| 74 bool Contains(const aura::Window* window) const; | 70 bool Contains(const wm::WmWindow* window) const; |
| 75 | 71 |
| 76 // Dims the items whose titles do not contain |pattern| and prevents their | 72 // Dims the items whose titles do not contain |pattern| and prevents their |
| 77 // selection. The pattern has its accents removed and is converted to | 73 // selection. The pattern has its accents removed and is converted to |
| 78 // lowercase in a l10n sensitive context. | 74 // lowercase in a l10n sensitive context. |
| 79 // If |pattern| is empty, no item is dimmed. | 75 // If |pattern| is empty, no item is dimmed. |
| 80 void FilterItems(const base::string16& pattern); | 76 void FilterItems(const base::string16& pattern); |
| 81 | 77 |
| 82 // Returns true if the grid has no more windows. | 78 // Returns true if the grid has no more windows. |
| 83 bool empty() const { return window_list_.empty(); } | 79 bool empty() const { return window_list_.empty(); } |
| 84 | 80 |
| 85 // Returns how many window selector items are in the grid. | 81 // Returns how many window selector items are in the grid. |
| 86 size_t size() const { return window_list_.size(); } | 82 size_t size() const { return window_list_.size(); } |
| 87 | 83 |
| 88 // Returns true if the selection widget is active. | 84 // Returns true if the selection widget is active. |
| 89 bool is_selecting() const { return selection_widget_ != nullptr; } | 85 bool is_selecting() const { return selection_widget_ != nullptr; } |
| 90 | 86 |
| 91 // Returns the root window in which the grid displays the windows. | 87 // Returns the root window in which the grid displays the windows. |
| 92 const aura::Window* root_window() const { return root_window_; } | 88 const wm::WmWindow* root_window() const { return root_window_; } |
| 93 | 89 |
| 94 const std::vector<WindowSelectorItem*>& window_list() const { | 90 const std::vector<WindowSelectorItem*>& window_list() const { |
| 95 return window_list_.get(); | 91 return window_list_.get(); |
| 96 } | 92 } |
| 97 | 93 |
| 98 // aura::WindowObserver: | 94 // wm::WmWindowObserver: |
| 99 void OnWindowDestroying(aura::Window* window) override; | 95 void OnWindowDestroying(wm::WmWindow* window) override; |
| 100 // TODO(flackr): Handle window bounds changed in WindowSelectorItem. | 96 // TODO(flackr): Handle window bounds changed in WindowSelectorItem. |
| 101 void OnWindowBoundsChanged(aura::Window* window, | 97 void OnWindowBoundsChanged(wm::WmWindow* window, |
| 102 const gfx::Rect& old_bounds, | 98 const gfx::Rect& old_bounds, |
| 103 const gfx::Rect& new_bounds) override; | 99 const gfx::Rect& new_bounds) override; |
| 104 | 100 |
| 105 private: | 101 private: |
| 106 friend class WindowSelectorTest; | 102 friend class WindowSelectorTest; |
| 107 | 103 |
| 108 // Internal function to initialize the selection widget. | 104 // Internal function to initialize the selection widget. |
| 109 void InitSelectionWidget(WindowSelector::Direction direction); | 105 void InitSelectionWidget(WindowSelector::Direction direction); |
| 110 | 106 |
| 111 // Moves the selection widget to the specified |direction|. | 107 // Moves the selection widget to the specified |direction|. |
| 112 void MoveSelectionWidget(WindowSelector::Direction direction, | 108 void MoveSelectionWidget(WindowSelector::Direction direction, |
| 113 bool recreate_selection_widget, | 109 bool recreate_selection_widget, |
| 114 bool out_of_bounds, | 110 bool out_of_bounds, |
| 115 bool animate); | 111 bool animate); |
| 116 | 112 |
| 117 // Moves the selection widget to the targeted window. | 113 // Moves the selection widget to the targeted window. |
| 118 void MoveSelectionWidgetToTarget(bool animate); | 114 void MoveSelectionWidgetToTarget(bool animate); |
| 119 | 115 |
| 120 // Returns the target bounds of the currently selected item. | 116 // Returns the target bounds of the currently selected item. |
| 121 const gfx::Rect GetSelectionBounds() const; | 117 const gfx::Rect GetSelectionBounds() const; |
| 122 | 118 |
| 123 // Root window the grid is in. | 119 // Root window the grid is in. |
| 124 aura::Window* root_window_; | 120 wm::WmWindow* root_window_; |
| 125 | 121 |
| 126 // Pointer to the window selector that spawned this grid. | 122 // Pointer to the window selector that spawned this grid. |
| 127 WindowSelector* window_selector_; | 123 WindowSelector* window_selector_; |
| 128 | 124 |
| 129 // Vector containing all the windows in this grid. | 125 // Vector containing all the windows in this grid. |
| 130 ScopedVector<WindowSelectorItem> window_list_; | 126 ScopedVector<WindowSelectorItem> window_list_; |
| 131 | 127 |
| 132 // Vector containing the observed windows. | 128 // Vector containing the observed windows. |
| 133 std::set<aura::Window*> observed_windows_; | 129 std::set<wm::WmWindow*> observed_windows_; |
| 134 | 130 |
| 135 // Widget that indicates to the user which is the selected window. | 131 // Widget that indicates to the user which is the selected window. |
| 136 std::unique_ptr<views::Widget> selection_widget_; | 132 std::unique_ptr<views::Widget> selection_widget_; |
| 137 | 133 |
| 138 // Current selected window position. | 134 // Current selected window position. |
| 139 size_t selected_index_; | 135 size_t selected_index_; |
| 140 | 136 |
| 141 // Number of columns in the grid. | 137 // Number of columns in the grid. |
| 142 size_t num_columns_; | 138 size_t num_columns_; |
| 143 | 139 |
| 144 DISALLOW_COPY_AND_ASSIGN(WindowGrid); | 140 DISALLOW_COPY_AND_ASSIGN(WindowGrid); |
| 145 }; | 141 }; |
| 146 | 142 |
| 147 } // namespace ash | 143 } // namespace ash |
| 148 | 144 |
| 149 #endif // ASH_WM_OVERVIEW_WINDOW_GRID_H_ | 145 #endif // ASH_WM_OVERVIEW_WINDOW_GRID_H_ |
| OLD | NEW |