| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_WM_OVERVIEW_WINDOW_GRID_H_ | |
| 6 #define ASH_WM_OVERVIEW_WINDOW_GRID_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <set> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "ash/common/wm_window_observer.h" | |
| 15 #include "ash/wm/overview/window_selector.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/scoped_vector.h" | |
| 18 | |
| 19 namespace views { | |
| 20 class Widget; | |
| 21 } | |
| 22 | |
| 23 namespace ash { | |
| 24 | |
| 25 class WindowSelectorItem; | |
| 26 | |
| 27 // Represents a grid of windows in the Overview Mode in a particular root | |
| 28 // window, and manages a selection widget that can be moved with the arrow keys. | |
| 29 // The idea behind the movement strategy is that it should be possible to access | |
| 30 // any window pressing a given arrow key repeatedly. | |
| 31 // +-------+ +-------+ +-------+ | |
| 32 // | 0 | | 1 | | 2 | | |
| 33 // +-------+ +-------+ +-------+ | |
| 34 // +-------+ +-------+ +-------+ | |
| 35 // | 3 | | 4 | | 5 | | |
| 36 // +-------+ +-------+ +-------+ | |
| 37 // +-------+ | |
| 38 // | 6 | | |
| 39 // +-------+ | |
| 40 // Example sequences: | |
| 41 // - Going right to left | |
| 42 // 0, 1, 2, 3, 4, 5, 6 | |
| 43 // - Going "top" to "bottom" | |
| 44 // 0, 3, 6, 1, 4, 2, 5 | |
| 45 // The selector is switched to the next window grid (if available) or wrapped if | |
| 46 // it reaches the end of its movement sequence. | |
| 47 class ASH_EXPORT WindowGrid : public WmWindowObserver { | |
| 48 public: | |
| 49 WindowGrid(WmWindow* root_window, | |
| 50 const std::vector<WmWindow*>& window_list, | |
| 51 WindowSelector* window_selector); | |
| 52 ~WindowGrid() override; | |
| 53 | |
| 54 // Prepares the windows in this grid for overview. This will restore all | |
| 55 // minimized windows and ensure they are visible. | |
| 56 void PrepareForOverview(); | |
| 57 | |
| 58 // Positions all the windows in rows of equal height scaling each window to | |
| 59 // fit that height. | |
| 60 // Layout is done in 2 stages maintaining fixed MRU ordering. | |
| 61 // 1. Optimal height is determined. In this stage |height| is bisected to find | |
| 62 // maximum height which still allows all the windows to fit. | |
| 63 // 2. Row widths are balanced. In this stage the available width is reduced | |
| 64 // until some windows are no longer fitting or until the difference between | |
| 65 // the narrowest and the widest rows starts growing. | |
| 66 // Overall this achieves the goals of maximum size for previews (or maximum | |
| 67 // row height which is equivalent assuming fixed height), balanced rows and | |
| 68 // minimal wasted space. | |
| 69 // Optionally animates the windows to their targets when |animate| is true. | |
| 70 void PositionWindowsMD(bool animate); | |
| 71 | |
| 72 // Positions all the windows in the grid. | |
| 73 // Optionally animates the windows to their targets when |animate| is true. | |
| 74 void PositionWindows(bool animate); | |
| 75 | |
| 76 // Updates |selected_index_| according to the specified |direction| and calls | |
| 77 // MoveSelectionWidget(). Returns |true| if the new selection index is out of | |
| 78 // this window grid bounds. | |
| 79 bool Move(WindowSelector::Direction direction, bool animate); | |
| 80 | |
| 81 // Returns the target selected window, or NULL if there is none selected. | |
| 82 WindowSelectorItem* SelectedWindow() const; | |
| 83 | |
| 84 // Returns true if a window is contained in any of the WindowSelectorItems | |
| 85 // this grid owns. | |
| 86 bool Contains(const WmWindow* window) const; | |
| 87 | |
| 88 // Dims the items whose titles do not contain |pattern| and prevents their | |
| 89 // selection. The pattern has its accents removed and is converted to | |
| 90 // lowercase in a l10n sensitive context. | |
| 91 // If |pattern| is empty, no item is dimmed. | |
| 92 void FilterItems(const base::string16& pattern); | |
| 93 | |
| 94 // Returns true if the grid has no more windows. | |
| 95 bool empty() const { return window_list_.empty(); } | |
| 96 | |
| 97 // Returns how many window selector items are in the grid. | |
| 98 size_t size() const { return window_list_.size(); } | |
| 99 | |
| 100 // Returns true if the selection widget is active. | |
| 101 bool is_selecting() const { return selection_widget_ != nullptr; } | |
| 102 | |
| 103 // Returns the root window in which the grid displays the windows. | |
| 104 const WmWindow* root_window() const { return root_window_; } | |
| 105 | |
| 106 const std::vector<WindowSelectorItem*>& window_list() const { | |
| 107 return window_list_.get(); | |
| 108 } | |
| 109 | |
| 110 // WmWindowObserver: | |
| 111 void OnWindowDestroying(WmWindow* window) override; | |
| 112 // TODO(flackr): Handle window bounds changed in WindowSelectorItem. | |
| 113 void OnWindowBoundsChanged(WmWindow* window, | |
| 114 const gfx::Rect& old_bounds, | |
| 115 const gfx::Rect& new_bounds) override; | |
| 116 | |
| 117 private: | |
| 118 friend class WindowSelectorTest; | |
| 119 | |
| 120 // Initializes the screen shield widget. | |
| 121 void InitShieldWidget(); | |
| 122 | |
| 123 // Internal function to initialize the selection widget. | |
| 124 void InitSelectionWidget(WindowSelector::Direction direction); | |
| 125 | |
| 126 // Moves the selection widget to the specified |direction|. | |
| 127 void MoveSelectionWidget(WindowSelector::Direction direction, | |
| 128 bool recreate_selection_widget, | |
| 129 bool out_of_bounds, | |
| 130 bool animate); | |
| 131 | |
| 132 // Moves the selection widget to the targeted window. | |
| 133 void MoveSelectionWidgetToTarget(bool animate); | |
| 134 | |
| 135 // Attempts to fit all |rects| inside |bounds|. The method ensures that | |
| 136 // the |rects| vector has appropriate size and populates it with the values | |
| 137 // placing Rects next to each other left-to-right in rows of equal |height|. | |
| 138 // While fitting |rects| several metrics are collected that can be used by the | |
| 139 // caller. |max_bottom| specifies the bottom that the rects are extending to. | |
| 140 // |min_right| and |max_right| report the right bound of the narrowest and the | |
| 141 // widest rows respectively. In-values of the |max_bottom|, |min_right| and | |
| 142 // |max_right| parameters are ignored and their values are always initialized | |
| 143 // inside this method. Returns true on success and false otherwise. | |
| 144 bool FitWindowRectsInBounds(const gfx::Rect& bounds, | |
| 145 int height, | |
| 146 std::vector<gfx::Rect>* rects, | |
| 147 int* max_bottom, | |
| 148 int* min_right, | |
| 149 int* max_right); | |
| 150 | |
| 151 // Returns the target bounds of the currently selected item. | |
| 152 const gfx::Rect GetSelectionBounds() const; | |
| 153 | |
| 154 // Root window the grid is in. | |
| 155 WmWindow* root_window_; | |
| 156 | |
| 157 // Pointer to the window selector that spawned this grid. | |
| 158 WindowSelector* window_selector_; | |
| 159 | |
| 160 // Vector containing all the windows in this grid. | |
| 161 ScopedVector<WindowSelectorItem> window_list_; | |
| 162 | |
| 163 // Vector containing the observed windows. | |
| 164 std::set<WmWindow*> observed_windows_; | |
| 165 | |
| 166 // Widget that darkens the screen background. | |
| 167 std::unique_ptr<views::Widget> shield_widget_; | |
| 168 | |
| 169 // Widget that indicates to the user which is the selected window. | |
| 170 std::unique_ptr<views::Widget> selection_widget_; | |
| 171 | |
| 172 // Current selected window position. | |
| 173 size_t selected_index_; | |
| 174 | |
| 175 // Number of columns in the grid. | |
| 176 size_t num_columns_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(WindowGrid); | |
| 179 }; | |
| 180 | |
| 181 } // namespace ash | |
| 182 | |
| 183 #endif // ASH_WM_OVERVIEW_WINDOW_GRID_H_ | |
| OLD | NEW |