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