Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: ash/common/wm/overview/window_selector.h

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/wm/overview/window_grid.cc ('k') | ash/common/wm/overview/window_selector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ASH_COMMON_WM_OVERVIEW_WINDOW_SELECTOR_H_
6 #define ASH_COMMON_WM_OVERVIEW_WINDOW_SELECTOR_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12 #include <set>
13 #include <vector>
14
15 #include "ash/ash_export.h"
16 #include "ash/common/wm_activation_observer.h"
17 #include "base/macros.h"
18 #include "base/time/time.h"
19 #include "ui/aura/window_observer.h"
20 #include "ui/display/display_observer.h"
21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/views/controls/textfield/textfield_controller.h"
23
24 namespace views {
25 class Textfield;
26 class Widget;
27 }
28
29 namespace ash {
30 class WindowSelectorDelegate;
31 class WindowSelectorItem;
32 class WindowSelectorTest;
33 class WindowGrid;
34
35 // The WindowSelector shows a grid of all of your windows, allowing to select
36 // one by clicking or tapping on it.
37 class ASH_EXPORT WindowSelector : public display::DisplayObserver,
38 public aura::WindowObserver,
39 public WmActivationObserver,
40 public views::TextfieldController {
41 public:
42 // Returns true if the window can be selected in overview mode.
43 static bool IsSelectable(WmWindow* window);
44
45 enum Direction { LEFT, UP, RIGHT, DOWN };
46
47 using WindowList = std::vector<WmWindow*>;
48
49 explicit WindowSelector(WindowSelectorDelegate* delegate);
50 ~WindowSelector() override;
51
52 // Initialize with the windows that can be selected.
53 void Init(const WindowList& windows);
54
55 // Perform cleanup that cannot be done in the destructor.
56 void Shutdown();
57
58 // Cancels window selection.
59 void CancelSelection();
60
61 // Called when the last window selector item from a grid is deleted.
62 void OnGridEmpty(WindowGrid* grid);
63
64 // Moves the current selection by |increment| items. Positive values of
65 // |increment| move the selection forward, negative values move it backward.
66 void IncrementSelection(int increment);
67
68 // Accepts current selection if any. Returns true if a selection was made,
69 // false otherwise.
70 bool AcceptSelection();
71
72 // Activates |item's| window.
73 void SelectWindow(WindowSelectorItem* item);
74
75 // Called when |window| is about to get closed.
76 void WindowClosing(WindowSelectorItem* window);
77
78 WindowSelectorDelegate* delegate() { return delegate_; }
79
80 bool restoring_minimized_windows() const {
81 return restoring_minimized_windows_;
82 }
83
84 int text_filter_bottom() const { return text_filter_bottom_; }
85
86 bool is_shut_down() const { return is_shut_down_; }
87
88 // display::DisplayObserver:
89 void OnDisplayAdded(const display::Display& display) override;
90 void OnDisplayRemoved(const display::Display& display) override;
91 void OnDisplayMetricsChanged(const display::Display& display,
92 uint32_t metrics) override;
93
94 // aura::WindowObserver:
95 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
96 void OnWindowDestroying(aura::Window* window) override;
97
98 // WmActivationObserver
99 void OnWindowActivated(WmWindow* gained_active,
100 WmWindow* lost_active) override;
101 void OnAttemptToReactivateWindow(WmWindow* request_active,
102 WmWindow* actual_active) override;
103
104 // views::TextfieldController:
105 void ContentsChanged(views::Textfield* sender,
106 const base::string16& new_contents) override;
107 bool HandleKeyEvent(views::Textfield* sender,
108 const ui::KeyEvent& key_event) override;
109
110 private:
111 friend class WindowSelectorTest;
112
113 // Returns the WmWindow for |text_filter_widget_|.
114 WmWindow* GetTextFilterWidgetWindow();
115
116 // Position all of the windows in the overview.
117 void PositionWindows(bool animate);
118
119 // Repositions and resizes |text_filter_widget_| on
120 // DisplayMetricsChanged event.
121 void RepositionTextFilterOnDisplayMetricsChange();
122
123 // |focus|, restores focus to the stored window.
124 void ResetFocusRestoreWindow(bool focus);
125
126 // Helper function that moves the selection widget to |direction| on the
127 // corresponding window grid.
128 void Move(Direction direction, bool animate);
129
130 // Removes all observers that were registered during construction and/or
131 // initialization.
132 void RemoveAllObservers();
133
134 // Tracks observed windows.
135 std::set<WmWindow*> observed_windows_;
136
137 // Weak pointer to the selector delegate which will be called when a
138 // selection is made.
139 WindowSelectorDelegate* delegate_;
140
141 // A weak pointer to the window which was focused on beginning window
142 // selection. If window selection is canceled the focus should be restored to
143 // this window.
144 WmWindow* restore_focus_window_;
145
146 // True when performing operations that may cause window activations. This is
147 // used to prevent handling the resulting expected activation.
148 bool ignore_activations_;
149
150 // List of all the window overview grids, one for each root window.
151 std::vector<std::unique_ptr<WindowGrid>> grid_list_;
152
153 // Tracks the index of the root window the selection widget is in.
154 size_t selected_grid_index_;
155
156 // The following variables are used for metric collection purposes. All of
157 // them refer to this particular overview session and are not cumulative:
158 // The time when overview was started.
159 base::Time overview_start_time_;
160
161 // The number of arrow key presses.
162 size_t num_key_presses_;
163
164 // The number of items in the overview.
165 size_t num_items_;
166
167 // Indicates if the text filter is shown on screen (rather than above it).
168 bool showing_text_filter_;
169
170 // Window text filter widget. As the user writes on it, we filter the items
171 // in the overview. It is also responsible for handling overview key events,
172 // such as enter key to select.
173 std::unique_ptr<views::Widget> text_filter_widget_;
174
175 // Image used for text filter textfield.
176 gfx::ImageSkia search_image_;
177
178 // The current length of the string entered into the text filtering textfield.
179 size_t text_filter_string_length_;
180
181 // The number of times the text filtering textfield has been cleared of text
182 // during this overview mode session.
183 size_t num_times_textfield_cleared_;
184
185 // Tracks whether minimized windows are currently being restored for overview
186 // mode.
187 bool restoring_minimized_windows_;
188
189 // The distance between the top edge of the screen and the bottom edge of
190 // the text filtering textfield.
191 int text_filter_bottom_;
192
193 bool is_shut_down_ = false;
194
195 DISALLOW_COPY_AND_ASSIGN(WindowSelector);
196 };
197
198 } // namespace ash
199
200 #endif // ASH_COMMON_WM_OVERVIEW_WINDOW_SELECTOR_H_
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_grid.cc ('k') | ash/common/wm/overview/window_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698