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