OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/wm/core/focus_controller.h" | 5 #include "ui/wm/core/focus_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
10 #include "ui/aura/client/default_capture_client.h" | 10 #include "ui/aura/client/default_capture_client.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
32 public aura::client::FocusChangeObserver { | 32 public aura::client::FocusChangeObserver { |
33 public: | 33 public: |
34 FocusNotificationObserver() | 34 FocusNotificationObserver() |
35 : activation_changed_count_(0), | 35 : activation_changed_count_(0), |
36 focus_changed_count_(0), | 36 focus_changed_count_(0), |
37 reactivation_count_(0), | 37 reactivation_count_(0), |
38 reactivation_requested_window_(NULL), | 38 reactivation_requested_window_(NULL), |
39 reactivation_actual_window_(NULL) {} | 39 reactivation_actual_window_(NULL) {} |
40 virtual ~FocusNotificationObserver() {} | 40 ~FocusNotificationObserver() override {} |
41 | 41 |
42 void ExpectCounts(int activation_changed_count, int focus_changed_count) { | 42 void ExpectCounts(int activation_changed_count, int focus_changed_count) { |
43 EXPECT_EQ(activation_changed_count, activation_changed_count_); | 43 EXPECT_EQ(activation_changed_count, activation_changed_count_); |
44 EXPECT_EQ(focus_changed_count, focus_changed_count_); | 44 EXPECT_EQ(focus_changed_count, focus_changed_count_); |
45 } | 45 } |
46 int reactivation_count() const { | 46 int reactivation_count() const { |
47 return reactivation_count_; | 47 return reactivation_count_; |
48 } | 48 } |
49 aura::Window* reactivation_requested_window() const { | 49 aura::Window* reactivation_requested_window() const { |
50 return reactivation_requested_window_; | 50 return reactivation_requested_window_; |
51 } | 51 } |
52 aura::Window* reactivation_actual_window() const { | 52 aura::Window* reactivation_actual_window() const { |
53 return reactivation_actual_window_; | 53 return reactivation_actual_window_; |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 // Overridden from aura::client::ActivationChangeObserver: | 57 // Overridden from aura::client::ActivationChangeObserver: |
58 virtual void OnWindowActivated(aura::Window* gained_active, | 58 void OnWindowActivated(aura::Window* gained_active, |
59 aura::Window* lost_active) override { | 59 aura::Window* lost_active) override { |
60 ++activation_changed_count_; | 60 ++activation_changed_count_; |
61 } | 61 } |
62 virtual void OnAttemptToReactivateWindow( | 62 void OnAttemptToReactivateWindow(aura::Window* request_active, |
63 aura::Window* request_active, | 63 aura::Window* actual_active) override { |
64 aura::Window* actual_active) override { | |
65 ++reactivation_count_; | 64 ++reactivation_count_; |
66 reactivation_requested_window_ = request_active; | 65 reactivation_requested_window_ = request_active; |
67 reactivation_actual_window_ = actual_active; | 66 reactivation_actual_window_ = actual_active; |
68 } | 67 } |
69 | 68 |
70 // Overridden from aura::client::FocusChangeObserver: | 69 // Overridden from aura::client::FocusChangeObserver: |
71 virtual void OnWindowFocused(aura::Window* gained_focus, | 70 void OnWindowFocused(aura::Window* gained_focus, |
72 aura::Window* lost_focus) override { | 71 aura::Window* lost_focus) override { |
73 ++focus_changed_count_; | 72 ++focus_changed_count_; |
74 } | 73 } |
75 | 74 |
76 int activation_changed_count_; | 75 int activation_changed_count_; |
77 int focus_changed_count_; | 76 int focus_changed_count_; |
78 int reactivation_count_; | 77 int reactivation_count_; |
79 aura::Window* reactivation_requested_window_; | 78 aura::Window* reactivation_requested_window_; |
80 aura::Window* reactivation_actual_window_; | 79 aura::Window* reactivation_actual_window_; |
81 | 80 |
82 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver); | 81 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver); |
(...skipping 15 matching lines...) Expand all Loading... |
98 public aura::client::FocusChangeObserver { | 97 public aura::client::FocusChangeObserver { |
99 public: | 98 public: |
100 RecordingActivationAndFocusChangeObserver(aura::Window* root, | 99 RecordingActivationAndFocusChangeObserver(aura::Window* root, |
101 WindowDeleter* deleter) | 100 WindowDeleter* deleter) |
102 : root_(root), | 101 : root_(root), |
103 deleter_(deleter), | 102 deleter_(deleter), |
104 was_notified_with_deleted_window_(false) { | 103 was_notified_with_deleted_window_(false) { |
105 aura::client::GetActivationClient(root_)->AddObserver(this); | 104 aura::client::GetActivationClient(root_)->AddObserver(this); |
106 aura::client::GetFocusClient(root_)->AddObserver(this); | 105 aura::client::GetFocusClient(root_)->AddObserver(this); |
107 } | 106 } |
108 virtual ~RecordingActivationAndFocusChangeObserver() { | 107 ~RecordingActivationAndFocusChangeObserver() override { |
109 aura::client::GetActivationClient(root_)->RemoveObserver(this); | 108 aura::client::GetActivationClient(root_)->RemoveObserver(this); |
110 aura::client::GetFocusClient(root_)->RemoveObserver(this); | 109 aura::client::GetFocusClient(root_)->RemoveObserver(this); |
111 } | 110 } |
112 | 111 |
113 bool was_notified_with_deleted_window() const { | 112 bool was_notified_with_deleted_window() const { |
114 return was_notified_with_deleted_window_; | 113 return was_notified_with_deleted_window_; |
115 } | 114 } |
116 | 115 |
117 // Overridden from aura::client::ActivationChangeObserver: | 116 // Overridden from aura::client::ActivationChangeObserver: |
118 virtual void OnWindowActivated(aura::Window* gained_active, | 117 void OnWindowActivated(aura::Window* gained_active, |
119 aura::Window* lost_active) override { | 118 aura::Window* lost_active) override { |
120 if (lost_active && lost_active == deleter_->GetDeletedWindow()) | 119 if (lost_active && lost_active == deleter_->GetDeletedWindow()) |
121 was_notified_with_deleted_window_ = true; | 120 was_notified_with_deleted_window_ = true; |
122 } | 121 } |
123 | 122 |
124 // Overridden from aura::client::FocusChangeObserver: | 123 // Overridden from aura::client::FocusChangeObserver: |
125 virtual void OnWindowFocused(aura::Window* gained_focus, | 124 void OnWindowFocused(aura::Window* gained_focus, |
126 aura::Window* lost_focus) override { | 125 aura::Window* lost_focus) override { |
127 if (lost_focus && lost_focus == deleter_->GetDeletedWindow()) | 126 if (lost_focus && lost_focus == deleter_->GetDeletedWindow()) |
128 was_notified_with_deleted_window_ = true; | 127 was_notified_with_deleted_window_ = true; |
129 } | 128 } |
130 | 129 |
131 private: | 130 private: |
132 aura::Window* root_; | 131 aura::Window* root_; |
133 | 132 |
134 // Not owned. | 133 // Not owned. |
135 WindowDeleter* deleter_; | 134 WindowDeleter* deleter_; |
136 | 135 |
137 // Whether the observer was notified about the loss of activation or the | 136 // Whether the observer was notified about the loss of activation or the |
138 // loss of focus with a window already deleted by |deleter_| as the | 137 // loss of focus with a window already deleted by |deleter_| as the |
139 // |lost_active| or |lost_focus| parameter. | 138 // |lost_active| or |lost_focus| parameter. |
140 bool was_notified_with_deleted_window_; | 139 bool was_notified_with_deleted_window_; |
141 | 140 |
142 DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver); | 141 DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver); |
143 }; | 142 }; |
144 | 143 |
145 // ActivationChangeObserver that deletes the window losing activation. | 144 // ActivationChangeObserver that deletes the window losing activation. |
146 class DeleteOnLoseActivationChangeObserver : | 145 class DeleteOnLoseActivationChangeObserver : |
147 public aura::client::ActivationChangeObserver, | 146 public aura::client::ActivationChangeObserver, |
148 public WindowDeleter { | 147 public WindowDeleter { |
149 public: | 148 public: |
150 explicit DeleteOnLoseActivationChangeObserver(aura::Window* window) | 149 explicit DeleteOnLoseActivationChangeObserver(aura::Window* window) |
151 : root_(window->GetRootWindow()), | 150 : root_(window->GetRootWindow()), |
152 window_(window), | 151 window_(window), |
153 did_delete_(false) { | 152 did_delete_(false) { |
154 aura::client::GetActivationClient(root_)->AddObserver(this); | 153 aura::client::GetActivationClient(root_)->AddObserver(this); |
155 } | 154 } |
156 virtual ~DeleteOnLoseActivationChangeObserver() { | 155 ~DeleteOnLoseActivationChangeObserver() override { |
157 aura::client::GetActivationClient(root_)->RemoveObserver(this); | 156 aura::client::GetActivationClient(root_)->RemoveObserver(this); |
158 } | 157 } |
159 | 158 |
160 // Overridden from aura::client::ActivationChangeObserver: | 159 // Overridden from aura::client::ActivationChangeObserver: |
161 virtual void OnWindowActivated(aura::Window* gained_active, | 160 void OnWindowActivated(aura::Window* gained_active, |
162 aura::Window* lost_active) override { | 161 aura::Window* lost_active) override { |
163 if (window_ && lost_active == window_) { | 162 if (window_ && lost_active == window_) { |
164 delete lost_active; | 163 delete lost_active; |
165 did_delete_ = true; | 164 did_delete_ = true; |
166 } | 165 } |
167 } | 166 } |
168 | 167 |
169 // Overridden from WindowDeleter: | 168 // Overridden from WindowDeleter: |
170 virtual aura::Window* GetDeletedWindow() override { | 169 aura::Window* GetDeletedWindow() override { |
171 return did_delete_ ? window_ : NULL; | 170 return did_delete_ ? window_ : NULL; |
172 } | 171 } |
173 | 172 |
174 private: | 173 private: |
175 aura::Window* root_; | 174 aura::Window* root_; |
176 aura::Window* window_; | 175 aura::Window* window_; |
177 bool did_delete_; | 176 bool did_delete_; |
178 | 177 |
179 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseActivationChangeObserver); | 178 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseActivationChangeObserver); |
180 }; | 179 }; |
181 | 180 |
182 // FocusChangeObserver that deletes the window losing focus. | 181 // FocusChangeObserver that deletes the window losing focus. |
183 class DeleteOnLoseFocusChangeObserver | 182 class DeleteOnLoseFocusChangeObserver |
184 : public aura::client::FocusChangeObserver, | 183 : public aura::client::FocusChangeObserver, |
185 public WindowDeleter { | 184 public WindowDeleter { |
186 public: | 185 public: |
187 explicit DeleteOnLoseFocusChangeObserver(aura::Window* window) | 186 explicit DeleteOnLoseFocusChangeObserver(aura::Window* window) |
188 : root_(window->GetRootWindow()), | 187 : root_(window->GetRootWindow()), |
189 window_(window), | 188 window_(window), |
190 did_delete_(false) { | 189 did_delete_(false) { |
191 aura::client::GetFocusClient(root_)->AddObserver(this); | 190 aura::client::GetFocusClient(root_)->AddObserver(this); |
192 } | 191 } |
193 virtual ~DeleteOnLoseFocusChangeObserver() { | 192 ~DeleteOnLoseFocusChangeObserver() override { |
194 aura::client::GetFocusClient(root_)->RemoveObserver(this); | 193 aura::client::GetFocusClient(root_)->RemoveObserver(this); |
195 } | 194 } |
196 | 195 |
197 // Overridden from aura::client::FocusChangeObserver: | 196 // Overridden from aura::client::FocusChangeObserver: |
198 virtual void OnWindowFocused(aura::Window* gained_focus, | 197 void OnWindowFocused(aura::Window* gained_focus, |
199 aura::Window* lost_focus) override { | 198 aura::Window* lost_focus) override { |
200 if (window_ && lost_focus == window_) { | 199 if (window_ && lost_focus == window_) { |
201 delete lost_focus; | 200 delete lost_focus; |
202 did_delete_ = true; | 201 did_delete_ = true; |
203 } | 202 } |
204 } | 203 } |
205 | 204 |
206 // Overridden from WindowDeleter: | 205 // Overridden from WindowDeleter: |
207 virtual aura::Window* GetDeletedWindow() override { | 206 aura::Window* GetDeletedWindow() override { |
208 return did_delete_ ? window_ : NULL; | 207 return did_delete_ ? window_ : NULL; |
209 } | 208 } |
210 | 209 |
211 private: | 210 private: |
212 aura::Window* root_; | 211 aura::Window* root_; |
213 aura::Window* window_; | 212 aura::Window* window_; |
214 bool did_delete_; | 213 bool did_delete_; |
215 | 214 |
216 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver); | 215 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver); |
217 }; | 216 }; |
218 | 217 |
219 class ScopedFocusNotificationObserver : public FocusNotificationObserver { | 218 class ScopedFocusNotificationObserver : public FocusNotificationObserver { |
220 public: | 219 public: |
221 ScopedFocusNotificationObserver(aura::Window* root_window) | 220 ScopedFocusNotificationObserver(aura::Window* root_window) |
222 : root_window_(root_window) { | 221 : root_window_(root_window) { |
223 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 222 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
224 aura::client::GetFocusClient(root_window_)->AddObserver(this); | 223 aura::client::GetFocusClient(root_window_)->AddObserver(this); |
225 } | 224 } |
226 virtual ~ScopedFocusNotificationObserver() { | 225 ~ScopedFocusNotificationObserver() override { |
227 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); | 226 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
228 aura::client::GetFocusClient(root_window_)->RemoveObserver(this); | 227 aura::client::GetFocusClient(root_window_)->RemoveObserver(this); |
229 } | 228 } |
230 | 229 |
231 private: | 230 private: |
232 aura::Window* root_window_; | 231 aura::Window* root_window_; |
233 | 232 |
234 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver); | 233 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver); |
235 }; | 234 }; |
236 | 235 |
237 class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver { | 236 class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver { |
238 public: | 237 public: |
239 ScopedTargetFocusNotificationObserver(aura::Window* root_window, int id) | 238 ScopedTargetFocusNotificationObserver(aura::Window* root_window, int id) |
240 : target_(root_window->GetChildById(id)) { | 239 : target_(root_window->GetChildById(id)) { |
241 aura::client::SetActivationChangeObserver(target_, this); | 240 aura::client::SetActivationChangeObserver(target_, this); |
242 aura::client::SetFocusChangeObserver(target_, this); | 241 aura::client::SetFocusChangeObserver(target_, this); |
243 tracker_.Add(target_); | 242 tracker_.Add(target_); |
244 } | 243 } |
245 virtual ~ScopedTargetFocusNotificationObserver() { | 244 ~ScopedTargetFocusNotificationObserver() override { |
246 if (tracker_.Contains(target_)) { | 245 if (tracker_.Contains(target_)) { |
247 aura::client::SetActivationChangeObserver(target_, NULL); | 246 aura::client::SetActivationChangeObserver(target_, NULL); |
248 aura::client::SetFocusChangeObserver(target_, NULL); | 247 aura::client::SetFocusChangeObserver(target_, NULL); |
249 } | 248 } |
250 } | 249 } |
251 | 250 |
252 private: | 251 private: |
253 aura::Window* target_; | 252 aura::Window* target_; |
254 aura::WindowTracker tracker_; | 253 aura::WindowTracker tracker_; |
255 | 254 |
256 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); | 255 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); |
257 }; | 256 }; |
258 | 257 |
259 class ScopedFocusedTextInputClientChanger | 258 class ScopedFocusedTextInputClientChanger |
260 : public ScopedFocusNotificationObserver { | 259 : public ScopedFocusNotificationObserver { |
261 public: | 260 public: |
262 ScopedFocusedTextInputClientChanger(aura::Window* root_window, | 261 ScopedFocusedTextInputClientChanger(aura::Window* root_window, |
263 ui::TextInputClient* text_input_client) | 262 ui::TextInputClient* text_input_client) |
264 : ScopedFocusNotificationObserver(root_window), | 263 : ScopedFocusNotificationObserver(root_window), |
265 text_input_client_(text_input_client) {} | 264 text_input_client_(text_input_client) {} |
266 | 265 |
267 private: | 266 private: |
268 // Overridden from aura::client::FocusChangeObserver: | 267 // Overridden from aura::client::FocusChangeObserver: |
269 virtual void OnWindowFocused(aura::Window* gained_focus, | 268 void OnWindowFocused(aura::Window* gained_focus, |
270 aura::Window* lost_focus) override { | 269 aura::Window* lost_focus) override { |
271 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient( | 270 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient( |
272 text_input_client_); | 271 text_input_client_); |
273 } | 272 } |
274 | 273 |
275 ui::TextInputClient* text_input_client_; | 274 ui::TextInputClient* text_input_client_; |
276 }; | 275 }; |
277 | 276 |
278 // Used to fake the handling of events in the pre-target phase. | 277 // Used to fake the handling of events in the pre-target phase. |
279 class SimpleEventHandler : public ui::EventHandler { | 278 class SimpleEventHandler : public ui::EventHandler { |
280 public: | 279 public: |
281 SimpleEventHandler() {} | 280 SimpleEventHandler() {} |
282 virtual ~SimpleEventHandler() {} | 281 ~SimpleEventHandler() override {} |
283 | 282 |
284 // Overridden from ui::EventHandler: | 283 // Overridden from ui::EventHandler: |
285 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 284 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); } |
286 event->SetHandled(); | 285 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); } |
287 } | |
288 virtual void OnGestureEvent(ui::GestureEvent* event) override { | |
289 event->SetHandled(); | |
290 } | |
291 | 286 |
292 private: | 287 private: |
293 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler); | 288 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler); |
294 }; | 289 }; |
295 | 290 |
296 class FocusShiftingActivationObserver | 291 class FocusShiftingActivationObserver |
297 : public aura::client::ActivationChangeObserver { | 292 : public aura::client::ActivationChangeObserver { |
298 public: | 293 public: |
299 explicit FocusShiftingActivationObserver(aura::Window* activated_window) | 294 explicit FocusShiftingActivationObserver(aura::Window* activated_window) |
300 : activated_window_(activated_window), | 295 : activated_window_(activated_window), |
301 shift_focus_to_(NULL) {} | 296 shift_focus_to_(NULL) {} |
302 virtual ~FocusShiftingActivationObserver() {} | 297 ~FocusShiftingActivationObserver() override {} |
303 | 298 |
304 void set_shift_focus_to(aura::Window* shift_focus_to) { | 299 void set_shift_focus_to(aura::Window* shift_focus_to) { |
305 shift_focus_to_ = shift_focus_to; | 300 shift_focus_to_ = shift_focus_to; |
306 } | 301 } |
307 | 302 |
308 private: | 303 private: |
309 // Overridden from aura::client::ActivationChangeObserver: | 304 // Overridden from aura::client::ActivationChangeObserver: |
310 virtual void OnWindowActivated(aura::Window* gained_active, | 305 void OnWindowActivated(aura::Window* gained_active, |
311 aura::Window* lost_active) override { | 306 aura::Window* lost_active) override { |
312 // Shift focus to a child. This should prevent the default focusing from | 307 // Shift focus to a child. This should prevent the default focusing from |
313 // occurring in FocusController::FocusWindow(). | 308 // occurring in FocusController::FocusWindow(). |
314 if (gained_active == activated_window_) { | 309 if (gained_active == activated_window_) { |
315 aura::client::FocusClient* client = | 310 aura::client::FocusClient* client = |
316 aura::client::GetFocusClient(gained_active); | 311 aura::client::GetFocusClient(gained_active); |
317 client->FocusWindow(shift_focus_to_); | 312 client->FocusWindow(shift_focus_to_); |
318 } | 313 } |
319 } | 314 } |
320 | 315 |
321 aura::Window* activated_window_; | 316 aura::Window* activated_window_; |
322 aura::Window* shift_focus_to_; | 317 aura::Window* shift_focus_to_; |
323 | 318 |
324 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver); | 319 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver); |
325 }; | 320 }; |
326 | 321 |
327 // BaseFocusRules subclass that allows basic overrides of focus/activation to | 322 // BaseFocusRules subclass that allows basic overrides of focus/activation to |
328 // be tested. This is intended more as a test that the override system works at | 323 // be tested. This is intended more as a test that the override system works at |
329 // all, rather than as an exhaustive set of use cases, those should be covered | 324 // all, rather than as an exhaustive set of use cases, those should be covered |
330 // in tests for those FocusRules implementations. | 325 // in tests for those FocusRules implementations. |
331 class TestFocusRules : public BaseFocusRules { | 326 class TestFocusRules : public BaseFocusRules { |
332 public: | 327 public: |
333 TestFocusRules() : focus_restriction_(NULL) {} | 328 TestFocusRules() : focus_restriction_(NULL) {} |
334 | 329 |
335 // Restricts focus and activation to this window and its child hierarchy. | 330 // Restricts focus and activation to this window and its child hierarchy. |
336 void set_focus_restriction(aura::Window* focus_restriction) { | 331 void set_focus_restriction(aura::Window* focus_restriction) { |
337 focus_restriction_ = focus_restriction; | 332 focus_restriction_ = focus_restriction; |
338 } | 333 } |
339 | 334 |
340 // Overridden from BaseFocusRules: | 335 // Overridden from BaseFocusRules: |
341 virtual bool SupportsChildActivation(aura::Window* window) const override { | 336 bool SupportsChildActivation(aura::Window* window) const override { |
342 // In FocusControllerTests, only the RootWindow has activatable children. | 337 // In FocusControllerTests, only the RootWindow has activatable children. |
343 return window->GetRootWindow() == window; | 338 return window->GetRootWindow() == window; |
344 } | 339 } |
345 virtual bool CanActivateWindow(aura::Window* window) const override { | 340 bool CanActivateWindow(aura::Window* window) const override { |
346 // Restricting focus to a non-activatable child window means the activatable | 341 // Restricting focus to a non-activatable child window means the activatable |
347 // parent outside the focus restriction is activatable. | 342 // parent outside the focus restriction is activatable. |
348 bool can_activate = | 343 bool can_activate = |
349 CanFocusOrActivate(window) || window->Contains(focus_restriction_); | 344 CanFocusOrActivate(window) || window->Contains(focus_restriction_); |
350 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false; | 345 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false; |
351 } | 346 } |
352 virtual bool CanFocusWindow(aura::Window* window) const override { | 347 bool CanFocusWindow(aura::Window* window) const override { |
353 return CanFocusOrActivate(window) ? | 348 return CanFocusOrActivate(window) ? |
354 BaseFocusRules::CanFocusWindow(window) : false; | 349 BaseFocusRules::CanFocusWindow(window) : false; |
355 } | 350 } |
356 virtual aura::Window* GetActivatableWindow( | 351 aura::Window* GetActivatableWindow(aura::Window* window) const override { |
357 aura::Window* window) const override { | |
358 return BaseFocusRules::GetActivatableWindow( | 352 return BaseFocusRules::GetActivatableWindow( |
359 CanFocusOrActivate(window) ? window : focus_restriction_); | 353 CanFocusOrActivate(window) ? window : focus_restriction_); |
360 } | 354 } |
361 virtual aura::Window* GetFocusableWindow( | 355 aura::Window* GetFocusableWindow(aura::Window* window) const override { |
362 aura::Window* window) const override { | |
363 return BaseFocusRules::GetFocusableWindow( | 356 return BaseFocusRules::GetFocusableWindow( |
364 CanFocusOrActivate(window) ? window : focus_restriction_); | 357 CanFocusOrActivate(window) ? window : focus_restriction_); |
365 } | 358 } |
366 virtual aura::Window* GetNextActivatableWindow( | 359 aura::Window* GetNextActivatableWindow(aura::Window* ignore) const override { |
367 aura::Window* ignore) const override { | |
368 aura::Window* next_activatable = | 360 aura::Window* next_activatable = |
369 BaseFocusRules::GetNextActivatableWindow(ignore); | 361 BaseFocusRules::GetNextActivatableWindow(ignore); |
370 return CanFocusOrActivate(next_activatable) ? | 362 return CanFocusOrActivate(next_activatable) ? |
371 next_activatable : GetActivatableWindow(focus_restriction_); | 363 next_activatable : GetActivatableWindow(focus_restriction_); |
372 } | 364 } |
373 | 365 |
374 private: | 366 private: |
375 bool CanFocusOrActivate(aura::Window* window) const { | 367 bool CanFocusOrActivate(aura::Window* window) const { |
376 return !focus_restriction_ || focus_restriction_->Contains(window); | 368 return !focus_restriction_ || focus_restriction_->Contains(window); |
377 } | 369 } |
378 | 370 |
379 aura::Window* focus_restriction_; | 371 aura::Window* focus_restriction_; |
380 | 372 |
381 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 373 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
382 }; | 374 }; |
383 | 375 |
384 // Common infrastructure shared by all FocusController test types. | 376 // Common infrastructure shared by all FocusController test types. |
385 class FocusControllerTestBase : public aura::test::AuraTestBase { | 377 class FocusControllerTestBase : public aura::test::AuraTestBase { |
386 protected: | 378 protected: |
387 FocusControllerTestBase() {} | 379 FocusControllerTestBase() {} |
388 | 380 |
389 // Overridden from aura::test::AuraTestBase: | 381 // Overridden from aura::test::AuraTestBase: |
390 virtual void SetUp() override { | 382 void SetUp() override { |
391 wm_state_.reset(new wm::WMState); | 383 wm_state_.reset(new wm::WMState); |
392 // FocusController registers itself as an Env observer so it can catch all | 384 // FocusController registers itself as an Env observer so it can catch all |
393 // window initializations, including the root_window()'s, so we create it | 385 // window initializations, including the root_window()'s, so we create it |
394 // before allowing the base setup. | 386 // before allowing the base setup. |
395 test_focus_rules_ = new TestFocusRules; | 387 test_focus_rules_ = new TestFocusRules; |
396 focus_controller_.reset(new FocusController(test_focus_rules_)); | 388 focus_controller_.reset(new FocusController(test_focus_rules_)); |
397 aura::test::AuraTestBase::SetUp(); | 389 aura::test::AuraTestBase::SetUp(); |
398 root_window()->AddPreTargetHandler(focus_controller_.get()); | 390 root_window()->AddPreTargetHandler(focus_controller_.get()); |
399 aura::client::SetFocusClient(root_window(), focus_controller_.get()); | 391 aura::client::SetFocusClient(root_window(), focus_controller_.get()); |
400 aura::client::SetActivationClient(root_window(), focus_controller_.get()); | 392 aura::client::SetActivationClient(root_window(), focus_controller_.get()); |
(...skipping 22 matching lines...) Expand all Loading... |
423 aura::Window* w21 = aura::test::CreateTestWindowWithDelegate( | 415 aura::Window* w21 = aura::test::CreateTestWindowWithDelegate( |
424 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21, | 416 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21, |
425 gfx::Rect(5, 5, 10, 10), w2); | 417 gfx::Rect(5, 5, 10, 10), w2); |
426 aura::test::CreateTestWindowWithDelegate( | 418 aura::test::CreateTestWindowWithDelegate( |
427 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211, | 419 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211, |
428 gfx::Rect(1, 1, 5, 5), w21); | 420 gfx::Rect(1, 1, 5, 5), w21); |
429 aura::test::CreateTestWindowWithDelegate( | 421 aura::test::CreateTestWindowWithDelegate( |
430 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, | 422 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, |
431 gfx::Rect(125, 125, 50, 50), root_window()); | 423 gfx::Rect(125, 125, 50, 50), root_window()); |
432 } | 424 } |
433 virtual void TearDown() override { | 425 void TearDown() override { |
434 root_window()->RemovePreTargetHandler(focus_controller_.get()); | 426 root_window()->RemovePreTargetHandler(focus_controller_.get()); |
435 aura::test::AuraTestBase::TearDown(); | 427 aura::test::AuraTestBase::TearDown(); |
436 test_focus_rules_ = NULL; // Owned by FocusController. | 428 test_focus_rules_ = NULL; // Owned by FocusController. |
437 focus_controller_.reset(); | 429 focus_controller_.reset(); |
438 wm_state_.reset(); | 430 wm_state_.reset(); |
439 } | 431 } |
440 | 432 |
441 void FocusWindow(aura::Window* window) { | 433 void FocusWindow(aura::Window* window) { |
442 aura::client::GetFocusClient(root_window())->FocusWindow(window); | 434 aura::client::GetFocusClient(root_window())->FocusWindow(window); |
443 } | 435 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 DCHECK(window); | 503 DCHECK(window); |
512 FocusWindowDirect(window); | 504 FocusWindowDirect(window); |
513 } | 505 } |
514 void ActivateWindowById(int id) { | 506 void ActivateWindowById(int id) { |
515 aura::Window* window = root_window()->GetChildById(id); | 507 aura::Window* window = root_window()->GetChildById(id); |
516 DCHECK(window); | 508 DCHECK(window); |
517 ActivateWindowDirect(window); | 509 ActivateWindowDirect(window); |
518 } | 510 } |
519 | 511 |
520 // Overridden from FocusControllerTestBase: | 512 // Overridden from FocusControllerTestBase: |
521 virtual void BasicFocus() override { | 513 void BasicFocus() override { |
522 EXPECT_EQ(NULL, GetFocusedWindow()); | 514 EXPECT_EQ(NULL, GetFocusedWindow()); |
523 FocusWindowById(1); | 515 FocusWindowById(1); |
524 EXPECT_EQ(1, GetFocusedWindowId()); | 516 EXPECT_EQ(1, GetFocusedWindowId()); |
525 FocusWindowById(2); | 517 FocusWindowById(2); |
526 EXPECT_EQ(2, GetFocusedWindowId()); | 518 EXPECT_EQ(2, GetFocusedWindowId()); |
527 } | 519 } |
528 virtual void BasicActivation() override { | 520 void BasicActivation() override { |
529 EXPECT_EQ(NULL, GetActiveWindow()); | 521 EXPECT_EQ(NULL, GetActiveWindow()); |
530 ActivateWindowById(1); | 522 ActivateWindowById(1); |
531 EXPECT_EQ(1, GetActiveWindowId()); | 523 EXPECT_EQ(1, GetActiveWindowId()); |
532 ActivateWindowById(2); | 524 ActivateWindowById(2); |
533 EXPECT_EQ(2, GetActiveWindowId()); | 525 EXPECT_EQ(2, GetActiveWindowId()); |
534 // Verify that attempting to deactivate NULL does not crash and does not | 526 // Verify that attempting to deactivate NULL does not crash and does not |
535 // change activation. | 527 // change activation. |
536 DeactivateWindow(NULL); | 528 DeactivateWindow(NULL); |
537 EXPECT_EQ(2, GetActiveWindowId()); | 529 EXPECT_EQ(2, GetActiveWindowId()); |
538 DeactivateWindow(GetActiveWindow()); | 530 DeactivateWindow(GetActiveWindow()); |
539 EXPECT_EQ(1, GetActiveWindowId()); | 531 EXPECT_EQ(1, GetActiveWindowId()); |
540 } | 532 } |
541 virtual void FocusEvents() override { | 533 void FocusEvents() override { |
542 ScopedFocusNotificationObserver root_observer(root_window()); | 534 ScopedFocusNotificationObserver root_observer(root_window()); |
543 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); | 535 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); |
544 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); | 536 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); |
545 | 537 |
546 root_observer.ExpectCounts(0, 0); | 538 root_observer.ExpectCounts(0, 0); |
547 observer1.ExpectCounts(0, 0); | 539 observer1.ExpectCounts(0, 0); |
548 observer2.ExpectCounts(0, 0); | 540 observer2.ExpectCounts(0, 0); |
549 | 541 |
550 FocusWindowById(1); | 542 FocusWindowById(1); |
551 root_observer.ExpectCounts(1, 1); | 543 root_observer.ExpectCounts(1, 1); |
552 observer1.ExpectCounts(1, 1); | 544 observer1.ExpectCounts(1, 1); |
553 observer2.ExpectCounts(0, 0); | 545 observer2.ExpectCounts(0, 0); |
554 | 546 |
555 FocusWindowById(2); | 547 FocusWindowById(2); |
556 root_observer.ExpectCounts(2, 2); | 548 root_observer.ExpectCounts(2, 2); |
557 observer1.ExpectCounts(2, 2); | 549 observer1.ExpectCounts(2, 2); |
558 observer2.ExpectCounts(1, 1); | 550 observer2.ExpectCounts(1, 1); |
559 } | 551 } |
560 virtual void DuplicateFocusEvents() override { | 552 void DuplicateFocusEvents() override { |
561 // Focusing an existing focused window should not resend focus events. | 553 // Focusing an existing focused window should not resend focus events. |
562 ScopedFocusNotificationObserver root_observer(root_window()); | 554 ScopedFocusNotificationObserver root_observer(root_window()); |
563 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); | 555 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); |
564 | 556 |
565 root_observer.ExpectCounts(0, 0); | 557 root_observer.ExpectCounts(0, 0); |
566 observer1.ExpectCounts(0, 0); | 558 observer1.ExpectCounts(0, 0); |
567 | 559 |
568 FocusWindowById(1); | 560 FocusWindowById(1); |
569 root_observer.ExpectCounts(1, 1); | 561 root_observer.ExpectCounts(1, 1); |
570 observer1.ExpectCounts(1, 1); | 562 observer1.ExpectCounts(1, 1); |
571 | 563 |
572 FocusWindowById(1); | 564 FocusWindowById(1); |
573 root_observer.ExpectCounts(1, 1); | 565 root_observer.ExpectCounts(1, 1); |
574 observer1.ExpectCounts(1, 1); | 566 observer1.ExpectCounts(1, 1); |
575 } | 567 } |
576 virtual void ActivationEvents() override { | 568 void ActivationEvents() override { |
577 ActivateWindowById(1); | 569 ActivateWindowById(1); |
578 | 570 |
579 ScopedFocusNotificationObserver root_observer(root_window()); | 571 ScopedFocusNotificationObserver root_observer(root_window()); |
580 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); | 572 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); |
581 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); | 573 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); |
582 | 574 |
583 root_observer.ExpectCounts(0, 0); | 575 root_observer.ExpectCounts(0, 0); |
584 observer1.ExpectCounts(0, 0); | 576 observer1.ExpectCounts(0, 0); |
585 observer2.ExpectCounts(0, 0); | 577 observer2.ExpectCounts(0, 0); |
586 | 578 |
587 ActivateWindowById(2); | 579 ActivateWindowById(2); |
588 root_observer.ExpectCounts(1, 1); | 580 root_observer.ExpectCounts(1, 1); |
589 observer1.ExpectCounts(1, 1); | 581 observer1.ExpectCounts(1, 1); |
590 observer2.ExpectCounts(1, 1); | 582 observer2.ExpectCounts(1, 1); |
591 } | 583 } |
592 virtual void ReactivationEvents() override { | 584 void ReactivationEvents() override { |
593 ActivateWindowById(1); | 585 ActivateWindowById(1); |
594 ScopedFocusNotificationObserver root_observer(root_window()); | 586 ScopedFocusNotificationObserver root_observer(root_window()); |
595 EXPECT_EQ(0, root_observer.reactivation_count()); | 587 EXPECT_EQ(0, root_observer.reactivation_count()); |
596 root_window()->GetChildById(2)->Hide(); | 588 root_window()->GetChildById(2)->Hide(); |
597 // When we attempt to activate "2", which cannot be activated because it | 589 // When we attempt to activate "2", which cannot be activated because it |
598 // is not visible, "1" will be reactivated. | 590 // is not visible, "1" will be reactivated. |
599 ActivateWindowById(2); | 591 ActivateWindowById(2); |
600 EXPECT_EQ(1, root_observer.reactivation_count()); | 592 EXPECT_EQ(1, root_observer.reactivation_count()); |
601 EXPECT_EQ(root_window()->GetChildById(2), | 593 EXPECT_EQ(root_window()->GetChildById(2), |
602 root_observer.reactivation_requested_window()); | 594 root_observer.reactivation_requested_window()); |
603 EXPECT_EQ(root_window()->GetChildById(1), | 595 EXPECT_EQ(root_window()->GetChildById(1), |
604 root_observer.reactivation_actual_window()); | 596 root_observer.reactivation_actual_window()); |
605 } | 597 } |
606 virtual void DuplicateActivationEvents() override { | 598 void DuplicateActivationEvents() override { |
607 // Activating an existing active window should not resend activation events. | 599 // Activating an existing active window should not resend activation events. |
608 ActivateWindowById(1); | 600 ActivateWindowById(1); |
609 | 601 |
610 ScopedFocusNotificationObserver root_observer(root_window()); | 602 ScopedFocusNotificationObserver root_observer(root_window()); |
611 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); | 603 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); |
612 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); | 604 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); |
613 | 605 |
614 root_observer.ExpectCounts(0, 0); | 606 root_observer.ExpectCounts(0, 0); |
615 observer1.ExpectCounts(0, 0); | 607 observer1.ExpectCounts(0, 0); |
616 observer2.ExpectCounts(0, 0); | 608 observer2.ExpectCounts(0, 0); |
617 | 609 |
618 ActivateWindowById(2); | 610 ActivateWindowById(2); |
619 root_observer.ExpectCounts(1, 1); | 611 root_observer.ExpectCounts(1, 1); |
620 observer1.ExpectCounts(1, 1); | 612 observer1.ExpectCounts(1, 1); |
621 observer2.ExpectCounts(1, 1); | 613 observer2.ExpectCounts(1, 1); |
622 | 614 |
623 ActivateWindowById(2); | 615 ActivateWindowById(2); |
624 root_observer.ExpectCounts(1, 1); | 616 root_observer.ExpectCounts(1, 1); |
625 observer1.ExpectCounts(1, 1); | 617 observer1.ExpectCounts(1, 1); |
626 observer2.ExpectCounts(1, 1); | 618 observer2.ExpectCounts(1, 1); |
627 } | 619 } |
628 virtual void ShiftFocusWithinActiveWindow() override { | 620 void ShiftFocusWithinActiveWindow() override { |
629 ActivateWindowById(1); | 621 ActivateWindowById(1); |
630 EXPECT_EQ(1, GetActiveWindowId()); | 622 EXPECT_EQ(1, GetActiveWindowId()); |
631 EXPECT_EQ(1, GetFocusedWindowId()); | 623 EXPECT_EQ(1, GetFocusedWindowId()); |
632 FocusWindowById(11); | 624 FocusWindowById(11); |
633 EXPECT_EQ(11, GetFocusedWindowId()); | 625 EXPECT_EQ(11, GetFocusedWindowId()); |
634 FocusWindowById(12); | 626 FocusWindowById(12); |
635 EXPECT_EQ(12, GetFocusedWindowId()); | 627 EXPECT_EQ(12, GetFocusedWindowId()); |
636 } | 628 } |
637 virtual void ShiftFocusToChildOfInactiveWindow() override { | 629 void ShiftFocusToChildOfInactiveWindow() override { |
638 ActivateWindowById(2); | 630 ActivateWindowById(2); |
639 EXPECT_EQ(2, GetActiveWindowId()); | 631 EXPECT_EQ(2, GetActiveWindowId()); |
640 EXPECT_EQ(2, GetFocusedWindowId()); | 632 EXPECT_EQ(2, GetFocusedWindowId()); |
641 FocusWindowById(11); | 633 FocusWindowById(11); |
642 EXPECT_EQ(1, GetActiveWindowId()); | 634 EXPECT_EQ(1, GetActiveWindowId()); |
643 EXPECT_EQ(11, GetFocusedWindowId()); | 635 EXPECT_EQ(11, GetFocusedWindowId()); |
644 } | 636 } |
645 virtual void ShiftFocusToParentOfFocusedWindow() override { | 637 void ShiftFocusToParentOfFocusedWindow() override { |
646 ActivateWindowById(1); | 638 ActivateWindowById(1); |
647 EXPECT_EQ(1, GetFocusedWindowId()); | 639 EXPECT_EQ(1, GetFocusedWindowId()); |
648 FocusWindowById(11); | 640 FocusWindowById(11); |
649 EXPECT_EQ(11, GetFocusedWindowId()); | 641 EXPECT_EQ(11, GetFocusedWindowId()); |
650 FocusWindowById(1); | 642 FocusWindowById(1); |
651 // Focus should _not_ shift to the parent of the already-focused window. | 643 // Focus should _not_ shift to the parent of the already-focused window. |
652 EXPECT_EQ(11, GetFocusedWindowId()); | 644 EXPECT_EQ(11, GetFocusedWindowId()); |
653 } | 645 } |
654 virtual void FocusRulesOverride() override { | 646 void FocusRulesOverride() override { |
655 EXPECT_EQ(NULL, GetFocusedWindow()); | 647 EXPECT_EQ(NULL, GetFocusedWindow()); |
656 FocusWindowById(11); | 648 FocusWindowById(11); |
657 EXPECT_EQ(11, GetFocusedWindowId()); | 649 EXPECT_EQ(11, GetFocusedWindowId()); |
658 | 650 |
659 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211)); | 651 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211)); |
660 FocusWindowById(12); | 652 FocusWindowById(12); |
661 // Input events leave focus unchanged; direct API calls will change focus | 653 // Input events leave focus unchanged; direct API calls will change focus |
662 // to the restricted window. | 654 // to the restricted window. |
663 int focused_window = IsInputEvent() ? 11 : 211; | 655 int focused_window = IsInputEvent() ? 11 : 211; |
664 EXPECT_EQ(focused_window, GetFocusedWindowId()); | 656 EXPECT_EQ(focused_window, GetFocusedWindowId()); |
665 | 657 |
666 test_focus_rules()->set_focus_restriction(NULL); | 658 test_focus_rules()->set_focus_restriction(NULL); |
667 FocusWindowById(12); | 659 FocusWindowById(12); |
668 EXPECT_EQ(12, GetFocusedWindowId()); | 660 EXPECT_EQ(12, GetFocusedWindowId()); |
669 } | 661 } |
670 virtual void ActivationRulesOverride() override { | 662 void ActivationRulesOverride() override { |
671 ActivateWindowById(1); | 663 ActivateWindowById(1); |
672 EXPECT_EQ(1, GetActiveWindowId()); | 664 EXPECT_EQ(1, GetActiveWindowId()); |
673 EXPECT_EQ(1, GetFocusedWindowId()); | 665 EXPECT_EQ(1, GetFocusedWindowId()); |
674 | 666 |
675 aura::Window* w3 = root_window()->GetChildById(3); | 667 aura::Window* w3 = root_window()->GetChildById(3); |
676 test_focus_rules()->set_focus_restriction(w3); | 668 test_focus_rules()->set_focus_restriction(w3); |
677 | 669 |
678 ActivateWindowById(2); | 670 ActivateWindowById(2); |
679 // Input events leave activation unchanged; direct API calls will activate | 671 // Input events leave activation unchanged; direct API calls will activate |
680 // the restricted window. | 672 // the restricted window. |
681 int active_window = IsInputEvent() ? 1 : 3; | 673 int active_window = IsInputEvent() ? 1 : 3; |
682 EXPECT_EQ(active_window, GetActiveWindowId()); | 674 EXPECT_EQ(active_window, GetActiveWindowId()); |
683 EXPECT_EQ(active_window, GetFocusedWindowId()); | 675 EXPECT_EQ(active_window, GetFocusedWindowId()); |
684 | 676 |
685 test_focus_rules()->set_focus_restriction(NULL); | 677 test_focus_rules()->set_focus_restriction(NULL); |
686 ActivateWindowById(2); | 678 ActivateWindowById(2); |
687 EXPECT_EQ(2, GetActiveWindowId()); | 679 EXPECT_EQ(2, GetActiveWindowId()); |
688 EXPECT_EQ(2, GetFocusedWindowId()); | 680 EXPECT_EQ(2, GetFocusedWindowId()); |
689 } | 681 } |
690 virtual void ShiftFocusOnActivation() override { | 682 void ShiftFocusOnActivation() override { |
691 // When a window is activated, by default that window is also focused. | 683 // When a window is activated, by default that window is also focused. |
692 // An ActivationChangeObserver may shift focus to another window within the | 684 // An ActivationChangeObserver may shift focus to another window within the |
693 // same activatable window. | 685 // same activatable window. |
694 ActivateWindowById(2); | 686 ActivateWindowById(2); |
695 EXPECT_EQ(2, GetFocusedWindowId()); | 687 EXPECT_EQ(2, GetFocusedWindowId()); |
696 ActivateWindowById(1); | 688 ActivateWindowById(1); |
697 EXPECT_EQ(1, GetFocusedWindowId()); | 689 EXPECT_EQ(1, GetFocusedWindowId()); |
698 | 690 |
699 ActivateWindowById(2); | 691 ActivateWindowById(2); |
700 | 692 |
(...skipping 21 matching lines...) Expand all Loading... |
722 ActivateWindowById(1); | 714 ActivateWindowById(1); |
723 EXPECT_EQ(1, GetFocusedWindowId()); | 715 EXPECT_EQ(1, GetFocusedWindowId()); |
724 | 716 |
725 client->RemoveObserver(observer.get()); | 717 client->RemoveObserver(observer.get()); |
726 | 718 |
727 ActivateWindowById(2); | 719 ActivateWindowById(2); |
728 EXPECT_EQ(2, GetFocusedWindowId()); | 720 EXPECT_EQ(2, GetFocusedWindowId()); |
729 ActivateWindowById(1); | 721 ActivateWindowById(1); |
730 EXPECT_EQ(1, GetFocusedWindowId()); | 722 EXPECT_EQ(1, GetFocusedWindowId()); |
731 } | 723 } |
732 virtual void ShiftFocusOnActivationDueToHide() override { | 724 void ShiftFocusOnActivationDueToHide() override { |
733 // Similar to ShiftFocusOnActivation except the activation change is | 725 // Similar to ShiftFocusOnActivation except the activation change is |
734 // triggered by hiding the active window. | 726 // triggered by hiding the active window. |
735 ActivateWindowById(1); | 727 ActivateWindowById(1); |
736 EXPECT_EQ(1, GetFocusedWindowId()); | 728 EXPECT_EQ(1, GetFocusedWindowId()); |
737 | 729 |
738 // Removes window 3 as candidate for next activatable window. | 730 // Removes window 3 as candidate for next activatable window. |
739 root_window()->GetChildById(3)->Hide(); | 731 root_window()->GetChildById(3)->Hide(); |
740 EXPECT_EQ(1, GetFocusedWindowId()); | 732 EXPECT_EQ(1, GetFocusedWindowId()); |
741 | 733 |
742 aura::Window* target = root_window()->GetChildById(2); | 734 aura::Window* target = root_window()->GetChildById(2); |
743 aura::client::ActivationClient* client = | 735 aura::client::ActivationClient* client = |
744 aura::client::GetActivationClient(root_window()); | 736 aura::client::GetActivationClient(root_window()); |
745 | 737 |
746 scoped_ptr<FocusShiftingActivationObserver> observer( | 738 scoped_ptr<FocusShiftingActivationObserver> observer( |
747 new FocusShiftingActivationObserver(target)); | 739 new FocusShiftingActivationObserver(target)); |
748 observer->set_shift_focus_to(target->GetChildById(21)); | 740 observer->set_shift_focus_to(target->GetChildById(21)); |
749 client->AddObserver(observer.get()); | 741 client->AddObserver(observer.get()); |
750 | 742 |
751 // Hide the active window. | 743 // Hide the active window. |
752 root_window()->GetChildById(1)->Hide(); | 744 root_window()->GetChildById(1)->Hide(); |
753 | 745 |
754 EXPECT_EQ(21, GetFocusedWindowId()); | 746 EXPECT_EQ(21, GetFocusedWindowId()); |
755 | 747 |
756 client->RemoveObserver(observer.get()); | 748 client->RemoveObserver(observer.get()); |
757 } | 749 } |
758 virtual void NoShiftActiveOnActivation() override { | 750 void NoShiftActiveOnActivation() override { |
759 // When a window is activated, we need to prevent any change to activation | 751 // When a window is activated, we need to prevent any change to activation |
760 // from being made in response to an activation change notification. | 752 // from being made in response to an activation change notification. |
761 } | 753 } |
762 | 754 |
763 virtual void NoFocusChangeOnClickOnCaptureWindow() override { | 755 void NoFocusChangeOnClickOnCaptureWindow() override { |
764 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( | 756 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( |
765 new aura::client::DefaultCaptureClient(root_window())); | 757 new aura::client::DefaultCaptureClient(root_window())); |
766 // Clicking on a window which has capture should not cause a focus change | 758 // Clicking on a window which has capture should not cause a focus change |
767 // to the window. This test verifies whether that is indeed the case. | 759 // to the window. This test verifies whether that is indeed the case. |
768 ActivateWindowById(1); | 760 ActivateWindowById(1); |
769 | 761 |
770 EXPECT_EQ(1, GetActiveWindowId()); | 762 EXPECT_EQ(1, GetActiveWindowId()); |
771 EXPECT_EQ(1, GetFocusedWindowId()); | 763 EXPECT_EQ(1, GetFocusedWindowId()); |
772 | 764 |
773 aura::Window* w2 = root_window()->GetChildById(2); | 765 aura::Window* w2 = root_window()->GetChildById(2); |
774 aura::client::GetCaptureClient(root_window())->SetCapture(w2); | 766 aura::client::GetCaptureClient(root_window())->SetCapture(w2); |
775 ui::test::EventGenerator generator(root_window(), w2); | 767 ui::test::EventGenerator generator(root_window(), w2); |
776 generator.ClickLeftButton(); | 768 generator.ClickLeftButton(); |
777 | 769 |
778 EXPECT_EQ(1, GetActiveWindowId()); | 770 EXPECT_EQ(1, GetActiveWindowId()); |
779 EXPECT_EQ(1, GetFocusedWindowId()); | 771 EXPECT_EQ(1, GetFocusedWindowId()); |
780 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); | 772 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); |
781 } | 773 } |
782 | 774 |
783 // Verifies focus change is honored while capture held. | 775 // Verifies focus change is honored while capture held. |
784 virtual void ChangeFocusWhenNothingFocusedAndCaptured() override { | 776 void ChangeFocusWhenNothingFocusedAndCaptured() override { |
785 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( | 777 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( |
786 new aura::client::DefaultCaptureClient(root_window())); | 778 new aura::client::DefaultCaptureClient(root_window())); |
787 aura::Window* w1 = root_window()->GetChildById(1); | 779 aura::Window* w1 = root_window()->GetChildById(1); |
788 aura::client::GetCaptureClient(root_window())->SetCapture(w1); | 780 aura::client::GetCaptureClient(root_window())->SetCapture(w1); |
789 | 781 |
790 EXPECT_EQ(-1, GetActiveWindowId()); | 782 EXPECT_EQ(-1, GetActiveWindowId()); |
791 EXPECT_EQ(-1, GetFocusedWindowId()); | 783 EXPECT_EQ(-1, GetFocusedWindowId()); |
792 | 784 |
793 FocusWindowById(1); | 785 FocusWindowById(1); |
794 | 786 |
795 EXPECT_EQ(1, GetActiveWindowId()); | 787 EXPECT_EQ(1, GetActiveWindowId()); |
796 EXPECT_EQ(1, GetFocusedWindowId()); | 788 EXPECT_EQ(1, GetFocusedWindowId()); |
797 | 789 |
798 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); | 790 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); |
799 } | 791 } |
800 | 792 |
801 // Verifies if a window that loses activation or focus is deleted during | 793 // Verifies if a window that loses activation or focus is deleted during |
802 // observer notification we don't pass the deleted window to other observers. | 794 // observer notification we don't pass the deleted window to other observers. |
803 virtual void DontPassDeletedWindow() override { | 795 void DontPassDeletedWindow() override { |
804 FocusWindowById(1); | 796 FocusWindowById(1); |
805 | 797 |
806 EXPECT_EQ(1, GetActiveWindowId()); | 798 EXPECT_EQ(1, GetActiveWindowId()); |
807 EXPECT_EQ(1, GetFocusedWindowId()); | 799 EXPECT_EQ(1, GetFocusedWindowId()); |
808 | 800 |
809 { | 801 { |
810 aura::Window* to_delete = root_window()->GetChildById(1); | 802 aura::Window* to_delete = root_window()->GetChildById(1); |
811 DeleteOnLoseActivationChangeObserver observer1(to_delete); | 803 DeleteOnLoseActivationChangeObserver observer1(to_delete); |
812 RecordingActivationAndFocusChangeObserver observer2(root_window(), | 804 RecordingActivationAndFocusChangeObserver observer2(root_window(), |
813 &observer1); | 805 &observer1); |
(...skipping 18 matching lines...) Expand all Loading... |
832 EXPECT_EQ(3, GetActiveWindowId()); | 824 EXPECT_EQ(3, GetActiveWindowId()); |
833 EXPECT_EQ(3, GetFocusedWindowId()); | 825 EXPECT_EQ(3, GetFocusedWindowId()); |
834 | 826 |
835 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); | 827 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); |
836 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); | 828 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); |
837 } | 829 } |
838 } | 830 } |
839 | 831 |
840 // Verifies if the focused text input client is cleared when a window gains | 832 // Verifies if the focused text input client is cleared when a window gains |
841 // or loses the focus. | 833 // or loses the focus. |
842 virtual void FocusedTextInputClient() override { | 834 void FocusedTextInputClient() override { |
843 ui::TextInputFocusManager* text_input_focus_manager = | 835 ui::TextInputFocusManager* text_input_focus_manager = |
844 ui::TextInputFocusManager::GetInstance(); | 836 ui::TextInputFocusManager::GetInstance(); |
845 ui::DummyTextInputClient text_input_client; | 837 ui::DummyTextInputClient text_input_client; |
846 ui::TextInputClient* null_text_input_client = NULL; | 838 ui::TextInputClient* null_text_input_client = NULL; |
847 | 839 |
848 EXPECT_EQ(null_text_input_client, | 840 EXPECT_EQ(null_text_input_client, |
849 text_input_focus_manager->GetFocusedTextInputClient()); | 841 text_input_focus_manager->GetFocusedTextInputClient()); |
850 | 842 |
851 text_input_focus_manager->FocusTextInputClient(&text_input_client); | 843 text_input_focus_manager->FocusTextInputClient(&text_input_client); |
852 EXPECT_EQ(&text_input_client, | 844 EXPECT_EQ(&text_input_client, |
(...skipping 23 matching lines...) Expand all Loading... |
876 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 868 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
877 }; | 869 }; |
878 | 870 |
879 // Focus and Activation changes via aura::client::ActivationClient API. | 871 // Focus and Activation changes via aura::client::ActivationClient API. |
880 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 872 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
881 public: | 873 public: |
882 FocusControllerApiTest() {} | 874 FocusControllerApiTest() {} |
883 | 875 |
884 private: | 876 private: |
885 // Overridden from FocusControllerTestBase: | 877 // Overridden from FocusControllerTestBase: |
886 virtual void FocusWindowDirect(aura::Window* window) override { | 878 void FocusWindowDirect(aura::Window* window) override { FocusWindow(window); } |
887 FocusWindow(window); | 879 void ActivateWindowDirect(aura::Window* window) override { |
888 } | |
889 virtual void ActivateWindowDirect(aura::Window* window) override { | |
890 ActivateWindow(window); | 880 ActivateWindow(window); |
891 } | 881 } |
892 virtual void DeactivateWindowDirect(aura::Window* window) override { | 882 void DeactivateWindowDirect(aura::Window* window) override { |
893 DeactivateWindow(window); | 883 DeactivateWindow(window); |
894 } | 884 } |
895 virtual bool IsInputEvent() override { return false; } | 885 bool IsInputEvent() override { return false; } |
896 | 886 |
897 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest); | 887 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest); |
898 }; | 888 }; |
899 | 889 |
900 // Focus and Activation changes via input events. | 890 // Focus and Activation changes via input events. |
901 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase { | 891 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase { |
902 public: | 892 public: |
903 FocusControllerMouseEventTest() {} | 893 FocusControllerMouseEventTest() {} |
904 | 894 |
905 // Tests that a handled mouse or gesture event does not trigger a window | 895 // Tests that a handled mouse or gesture event does not trigger a window |
906 // activation. | 896 // activation. |
907 void IgnoreHandledEvent() { | 897 void IgnoreHandledEvent() { |
908 EXPECT_EQ(NULL, GetActiveWindow()); | 898 EXPECT_EQ(NULL, GetActiveWindow()); |
909 aura::Window* w1 = root_window()->GetChildById(1); | 899 aura::Window* w1 = root_window()->GetChildById(1); |
910 SimpleEventHandler handler; | 900 SimpleEventHandler handler; |
911 root_window()->PrependPreTargetHandler(&handler); | 901 root_window()->PrependPreTargetHandler(&handler); |
912 ui::test::EventGenerator generator(root_window(), w1); | 902 ui::test::EventGenerator generator(root_window(), w1); |
913 generator.ClickLeftButton(); | 903 generator.ClickLeftButton(); |
914 EXPECT_EQ(NULL, GetActiveWindow()); | 904 EXPECT_EQ(NULL, GetActiveWindow()); |
915 generator.GestureTapAt(w1->bounds().CenterPoint()); | 905 generator.GestureTapAt(w1->bounds().CenterPoint()); |
916 EXPECT_EQ(NULL, GetActiveWindow()); | 906 EXPECT_EQ(NULL, GetActiveWindow()); |
917 root_window()->RemovePreTargetHandler(&handler); | 907 root_window()->RemovePreTargetHandler(&handler); |
918 generator.ClickLeftButton(); | 908 generator.ClickLeftButton(); |
919 EXPECT_EQ(1, GetActiveWindowId()); | 909 EXPECT_EQ(1, GetActiveWindowId()); |
920 } | 910 } |
921 | 911 |
922 private: | 912 private: |
923 // Overridden from FocusControllerTestBase: | 913 // Overridden from FocusControllerTestBase: |
924 virtual void FocusWindowDirect(aura::Window* window) override { | 914 void FocusWindowDirect(aura::Window* window) override { |
925 ui::test::EventGenerator generator(root_window(), window); | 915 ui::test::EventGenerator generator(root_window(), window); |
926 generator.ClickLeftButton(); | 916 generator.ClickLeftButton(); |
927 } | 917 } |
928 virtual void ActivateWindowDirect(aura::Window* window) override { | 918 void ActivateWindowDirect(aura::Window* window) override { |
929 ui::test::EventGenerator generator(root_window(), window); | 919 ui::test::EventGenerator generator(root_window(), window); |
930 generator.ClickLeftButton(); | 920 generator.ClickLeftButton(); |
931 } | 921 } |
932 virtual void DeactivateWindowDirect(aura::Window* window) override { | 922 void DeactivateWindowDirect(aura::Window* window) override { |
933 aura::Window* next_activatable = | 923 aura::Window* next_activatable = |
934 test_focus_rules()->GetNextActivatableWindow(window); | 924 test_focus_rules()->GetNextActivatableWindow(window); |
935 ui::test::EventGenerator generator(root_window(), next_activatable); | 925 ui::test::EventGenerator generator(root_window(), next_activatable); |
936 generator.ClickLeftButton(); | 926 generator.ClickLeftButton(); |
937 } | 927 } |
938 virtual bool IsInputEvent() override { return true; } | 928 bool IsInputEvent() override { return true; } |
939 | 929 |
940 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); | 930 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); |
941 }; | 931 }; |
942 | 932 |
943 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { | 933 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { |
944 public: | 934 public: |
945 FocusControllerGestureEventTest() {} | 935 FocusControllerGestureEventTest() {} |
946 | 936 |
947 private: | 937 private: |
948 // Overridden from FocusControllerTestBase: | 938 // Overridden from FocusControllerTestBase: |
949 virtual void FocusWindowDirect(aura::Window* window) override { | 939 void FocusWindowDirect(aura::Window* window) override { |
950 ui::test::EventGenerator generator(root_window(), window); | 940 ui::test::EventGenerator generator(root_window(), window); |
951 generator.GestureTapAt(window->bounds().CenterPoint()); | 941 generator.GestureTapAt(window->bounds().CenterPoint()); |
952 } | 942 } |
953 virtual void ActivateWindowDirect(aura::Window* window) override { | 943 void ActivateWindowDirect(aura::Window* window) override { |
954 ui::test::EventGenerator generator(root_window(), window); | 944 ui::test::EventGenerator generator(root_window(), window); |
955 generator.GestureTapAt(window->bounds().CenterPoint()); | 945 generator.GestureTapAt(window->bounds().CenterPoint()); |
956 } | 946 } |
957 virtual void DeactivateWindowDirect(aura::Window* window) override { | 947 void DeactivateWindowDirect(aura::Window* window) override { |
958 aura::Window* next_activatable = | 948 aura::Window* next_activatable = |
959 test_focus_rules()->GetNextActivatableWindow(window); | 949 test_focus_rules()->GetNextActivatableWindow(window); |
960 ui::test::EventGenerator generator(root_window(), next_activatable); | 950 ui::test::EventGenerator generator(root_window(), next_activatable); |
961 generator.GestureTapAt(window->bounds().CenterPoint()); | 951 generator.GestureTapAt(window->bounds().CenterPoint()); |
962 } | 952 } |
963 virtual bool IsInputEvent() override { return true; } | 953 bool IsInputEvent() override { return true; } |
964 | 954 |
965 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); | 955 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); |
966 }; | 956 }; |
967 | 957 |
968 // Test base for tests where focus is implicitly set to a window as the result | 958 // Test base for tests where focus is implicitly set to a window as the result |
969 // of a disposition change to the focused window or the hierarchy that contains | 959 // of a disposition change to the focused window or the hierarchy that contains |
970 // it. | 960 // it. |
971 class FocusControllerImplicitTestBase : public FocusControllerTestBase { | 961 class FocusControllerImplicitTestBase : public FocusControllerTestBase { |
972 protected: | 962 protected: |
973 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {} | 963 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {} |
974 | 964 |
975 aura::Window* GetDispositionWindow(aura::Window* window) { | 965 aura::Window* GetDispositionWindow(aura::Window* window) { |
976 return parent_ ? window->parent() : window; | 966 return parent_ ? window->parent() : window; |
977 } | 967 } |
978 | 968 |
979 // Change the disposition of |window| in such a way as it will lose focus. | 969 // Change the disposition of |window| in such a way as it will lose focus. |
980 virtual void ChangeWindowDisposition(aura::Window* window) = 0; | 970 virtual void ChangeWindowDisposition(aura::Window* window) = 0; |
981 | 971 |
982 // Allow each disposition change test to add additional post-disposition | 972 // Allow each disposition change test to add additional post-disposition |
983 // change expectations. | 973 // change expectations. |
984 virtual void PostDispostionChangeExpectations() {} | 974 virtual void PostDispostionChangeExpectations() {} |
985 | 975 |
986 // Overridden from FocusControllerTestBase: | 976 // Overridden from FocusControllerTestBase: |
987 virtual void BasicFocus() override { | 977 void BasicFocus() override { |
988 EXPECT_EQ(NULL, GetFocusedWindow()); | 978 EXPECT_EQ(NULL, GetFocusedWindow()); |
989 | 979 |
990 aura::Window* w211 = root_window()->GetChildById(211); | 980 aura::Window* w211 = root_window()->GetChildById(211); |
991 FocusWindow(w211); | 981 FocusWindow(w211); |
992 EXPECT_EQ(211, GetFocusedWindowId()); | 982 EXPECT_EQ(211, GetFocusedWindowId()); |
993 | 983 |
994 ChangeWindowDisposition(w211); | 984 ChangeWindowDisposition(w211); |
995 // BasicFocusRules passes focus to the parent. | 985 // BasicFocusRules passes focus to the parent. |
996 EXPECT_EQ(parent_ ? 2 : 21, GetFocusedWindowId()); | 986 EXPECT_EQ(parent_ ? 2 : 21, GetFocusedWindowId()); |
997 } | 987 } |
998 virtual void BasicActivation() override { | 988 void BasicActivation() override { |
999 DCHECK(!parent_) << "Activation tests don't support parent changes."; | 989 DCHECK(!parent_) << "Activation tests don't support parent changes."; |
1000 | 990 |
1001 EXPECT_EQ(NULL, GetActiveWindow()); | 991 EXPECT_EQ(NULL, GetActiveWindow()); |
1002 | 992 |
1003 aura::Window* w2 = root_window()->GetChildById(2); | 993 aura::Window* w2 = root_window()->GetChildById(2); |
1004 ActivateWindow(w2); | 994 ActivateWindow(w2); |
1005 EXPECT_EQ(2, GetActiveWindowId()); | 995 EXPECT_EQ(2, GetActiveWindowId()); |
1006 | 996 |
1007 ChangeWindowDisposition(w2); | 997 ChangeWindowDisposition(w2); |
1008 EXPECT_EQ(3, GetActiveWindowId()); | 998 EXPECT_EQ(3, GetActiveWindowId()); |
1009 PostDispostionChangeExpectations(); | 999 PostDispostionChangeExpectations(); |
1010 } | 1000 } |
1011 virtual void FocusEvents() override { | 1001 void FocusEvents() override { |
1012 aura::Window* w211 = root_window()->GetChildById(211); | 1002 aura::Window* w211 = root_window()->GetChildById(211); |
1013 FocusWindow(w211); | 1003 FocusWindow(w211); |
1014 | 1004 |
1015 ScopedFocusNotificationObserver root_observer(root_window()); | 1005 ScopedFocusNotificationObserver root_observer(root_window()); |
1016 ScopedTargetFocusNotificationObserver observer211(root_window(), 211); | 1006 ScopedTargetFocusNotificationObserver observer211(root_window(), 211); |
1017 root_observer.ExpectCounts(0, 0); | 1007 root_observer.ExpectCounts(0, 0); |
1018 observer211.ExpectCounts(0, 0); | 1008 observer211.ExpectCounts(0, 0); |
1019 | 1009 |
1020 ChangeWindowDisposition(w211); | 1010 ChangeWindowDisposition(w211); |
1021 root_observer.ExpectCounts(0, 1); | 1011 root_observer.ExpectCounts(0, 1); |
1022 observer211.ExpectCounts(0, 1); | 1012 observer211.ExpectCounts(0, 1); |
1023 } | 1013 } |
1024 virtual void ActivationEvents() override { | 1014 void ActivationEvents() override { |
1025 DCHECK(!parent_) << "Activation tests don't support parent changes."; | 1015 DCHECK(!parent_) << "Activation tests don't support parent changes."; |
1026 | 1016 |
1027 aura::Window* w2 = root_window()->GetChildById(2); | 1017 aura::Window* w2 = root_window()->GetChildById(2); |
1028 ActivateWindow(w2); | 1018 ActivateWindow(w2); |
1029 | 1019 |
1030 ScopedFocusNotificationObserver root_observer(root_window()); | 1020 ScopedFocusNotificationObserver root_observer(root_window()); |
1031 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); | 1021 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); |
1032 ScopedTargetFocusNotificationObserver observer3(root_window(), 3); | 1022 ScopedTargetFocusNotificationObserver observer3(root_window(), 3); |
1033 root_observer.ExpectCounts(0, 0); | 1023 root_observer.ExpectCounts(0, 0); |
1034 observer2.ExpectCounts(0, 0); | 1024 observer2.ExpectCounts(0, 0); |
1035 observer3.ExpectCounts(0, 0); | 1025 observer3.ExpectCounts(0, 0); |
1036 | 1026 |
1037 ChangeWindowDisposition(w2); | 1027 ChangeWindowDisposition(w2); |
1038 root_observer.ExpectCounts(1, 1); | 1028 root_observer.ExpectCounts(1, 1); |
1039 observer2.ExpectCounts(1, 1); | 1029 observer2.ExpectCounts(1, 1); |
1040 observer3.ExpectCounts(1, 1); | 1030 observer3.ExpectCounts(1, 1); |
1041 } | 1031 } |
1042 virtual void FocusRulesOverride() override { | 1032 void FocusRulesOverride() override { |
1043 EXPECT_EQ(NULL, GetFocusedWindow()); | 1033 EXPECT_EQ(NULL, GetFocusedWindow()); |
1044 aura::Window* w211 = root_window()->GetChildById(211); | 1034 aura::Window* w211 = root_window()->GetChildById(211); |
1045 FocusWindow(w211); | 1035 FocusWindow(w211); |
1046 EXPECT_EQ(211, GetFocusedWindowId()); | 1036 EXPECT_EQ(211, GetFocusedWindowId()); |
1047 | 1037 |
1048 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11)); | 1038 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11)); |
1049 ChangeWindowDisposition(w211); | 1039 ChangeWindowDisposition(w211); |
1050 // Normally, focus would shift to the parent (w21) but the override shifts | 1040 // Normally, focus would shift to the parent (w21) but the override shifts |
1051 // it to 11. | 1041 // it to 11. |
1052 EXPECT_EQ(11, GetFocusedWindowId()); | 1042 EXPECT_EQ(11, GetFocusedWindowId()); |
1053 | 1043 |
1054 test_focus_rules()->set_focus_restriction(NULL); | 1044 test_focus_rules()->set_focus_restriction(NULL); |
1055 } | 1045 } |
1056 virtual void ActivationRulesOverride() override { | 1046 void ActivationRulesOverride() override { |
1057 DCHECK(!parent_) << "Activation tests don't support parent changes."; | 1047 DCHECK(!parent_) << "Activation tests don't support parent changes."; |
1058 | 1048 |
1059 aura::Window* w1 = root_window()->GetChildById(1); | 1049 aura::Window* w1 = root_window()->GetChildById(1); |
1060 ActivateWindow(w1); | 1050 ActivateWindow(w1); |
1061 | 1051 |
1062 EXPECT_EQ(1, GetActiveWindowId()); | 1052 EXPECT_EQ(1, GetActiveWindowId()); |
1063 EXPECT_EQ(1, GetFocusedWindowId()); | 1053 EXPECT_EQ(1, GetFocusedWindowId()); |
1064 | 1054 |
1065 aura::Window* w3 = root_window()->GetChildById(3); | 1055 aura::Window* w3 = root_window()->GetChildById(3); |
1066 test_focus_rules()->set_focus_restriction(w3); | 1056 test_focus_rules()->set_focus_restriction(w3); |
(...skipping 22 matching lines...) Expand all Loading... |
1089 // Focus and Activation changes in response to window visibility changes. | 1079 // Focus and Activation changes in response to window visibility changes. |
1090 class FocusControllerHideTest : public FocusControllerImplicitTestBase { | 1080 class FocusControllerHideTest : public FocusControllerImplicitTestBase { |
1091 public: | 1081 public: |
1092 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {} | 1082 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {} |
1093 | 1083 |
1094 protected: | 1084 protected: |
1095 FocusControllerHideTest(bool parent) | 1085 FocusControllerHideTest(bool parent) |
1096 : FocusControllerImplicitTestBase(parent) {} | 1086 : FocusControllerImplicitTestBase(parent) {} |
1097 | 1087 |
1098 // Overridden from FocusControllerImplicitTestBase: | 1088 // Overridden from FocusControllerImplicitTestBase: |
1099 virtual void ChangeWindowDisposition(aura::Window* window) override { | 1089 void ChangeWindowDisposition(aura::Window* window) override { |
1100 GetDispositionWindow(window)->Hide(); | 1090 GetDispositionWindow(window)->Hide(); |
1101 } | 1091 } |
1102 | 1092 |
1103 private: | 1093 private: |
1104 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest); | 1094 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest); |
1105 }; | 1095 }; |
1106 | 1096 |
1107 // Focus and Activation changes in response to window parent visibility | 1097 // Focus and Activation changes in response to window parent visibility |
1108 // changes. | 1098 // changes. |
1109 class FocusControllerParentHideTest : public FocusControllerHideTest { | 1099 class FocusControllerParentHideTest : public FocusControllerHideTest { |
1110 public: | 1100 public: |
1111 FocusControllerParentHideTest() : FocusControllerHideTest(true) {} | 1101 FocusControllerParentHideTest() : FocusControllerHideTest(true) {} |
1112 | 1102 |
1113 private: | 1103 private: |
1114 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest); | 1104 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest); |
1115 }; | 1105 }; |
1116 | 1106 |
1117 // Focus and Activation changes in response to window destruction. | 1107 // Focus and Activation changes in response to window destruction. |
1118 class FocusControllerDestructionTest : public FocusControllerImplicitTestBase { | 1108 class FocusControllerDestructionTest : public FocusControllerImplicitTestBase { |
1119 public: | 1109 public: |
1120 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {} | 1110 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {} |
1121 | 1111 |
1122 protected: | 1112 protected: |
1123 FocusControllerDestructionTest(bool parent) | 1113 FocusControllerDestructionTest(bool parent) |
1124 : FocusControllerImplicitTestBase(parent) {} | 1114 : FocusControllerImplicitTestBase(parent) {} |
1125 | 1115 |
1126 // Overridden from FocusControllerImplicitTestBase: | 1116 // Overridden from FocusControllerImplicitTestBase: |
1127 virtual void ChangeWindowDisposition(aura::Window* window) override { | 1117 void ChangeWindowDisposition(aura::Window* window) override { |
1128 delete GetDispositionWindow(window); | 1118 delete GetDispositionWindow(window); |
1129 } | 1119 } |
1130 | 1120 |
1131 private: | 1121 private: |
1132 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest); | 1122 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest); |
1133 }; | 1123 }; |
1134 | 1124 |
1135 // Focus and Activation changes in response to window parent destruction. | 1125 // Focus and Activation changes in response to window parent destruction. |
1136 class FocusControllerParentDestructionTest | 1126 class FocusControllerParentDestructionTest |
1137 : public FocusControllerDestructionTest { | 1127 : public FocusControllerDestructionTest { |
1138 public: | 1128 public: |
1139 FocusControllerParentDestructionTest() | 1129 FocusControllerParentDestructionTest() |
1140 : FocusControllerDestructionTest(true) {} | 1130 : FocusControllerDestructionTest(true) {} |
1141 | 1131 |
1142 private: | 1132 private: |
1143 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest); | 1133 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest); |
1144 }; | 1134 }; |
1145 | 1135 |
1146 // Focus and Activation changes in response to window removal. | 1136 // Focus and Activation changes in response to window removal. |
1147 class FocusControllerRemovalTest : public FocusControllerImplicitTestBase { | 1137 class FocusControllerRemovalTest : public FocusControllerImplicitTestBase { |
1148 public: | 1138 public: |
1149 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {} | 1139 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {} |
1150 | 1140 |
1151 protected: | 1141 protected: |
1152 FocusControllerRemovalTest(bool parent) | 1142 FocusControllerRemovalTest(bool parent) |
1153 : FocusControllerImplicitTestBase(parent) {} | 1143 : FocusControllerImplicitTestBase(parent) {} |
1154 | 1144 |
1155 // Overridden from FocusControllerImplicitTestBase: | 1145 // Overridden from FocusControllerImplicitTestBase: |
1156 virtual void ChangeWindowDisposition(aura::Window* window) override { | 1146 void ChangeWindowDisposition(aura::Window* window) override { |
1157 aura::Window* disposition_window = GetDispositionWindow(window); | 1147 aura::Window* disposition_window = GetDispositionWindow(window); |
1158 disposition_window->parent()->RemoveChild(disposition_window); | 1148 disposition_window->parent()->RemoveChild(disposition_window); |
1159 window_owner_.reset(disposition_window); | 1149 window_owner_.reset(disposition_window); |
1160 } | 1150 } |
1161 virtual void TearDown() override { | 1151 void TearDown() override { |
1162 window_owner_.reset(); | 1152 window_owner_.reset(); |
1163 FocusControllerImplicitTestBase::TearDown(); | 1153 FocusControllerImplicitTestBase::TearDown(); |
1164 } | 1154 } |
1165 | 1155 |
1166 private: | 1156 private: |
1167 scoped_ptr<aura::Window> window_owner_; | 1157 scoped_ptr<aura::Window> window_owner_; |
1168 | 1158 |
1169 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest); | 1159 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest); |
1170 }; | 1160 }; |
1171 | 1161 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1266 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
1277 | 1267 |
1278 // - Verifies that the focused text input client is cleard when the window focus | 1268 // - Verifies that the focused text input client is cleard when the window focus |
1279 // changes. | 1269 // changes. |
1280 ALL_FOCUS_TESTS(FocusedTextInputClient); | 1270 ALL_FOCUS_TESTS(FocusedTextInputClient); |
1281 | 1271 |
1282 // If a mouse event was handled, it should not activate a window. | 1272 // If a mouse event was handled, it should not activate a window. |
1283 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1273 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
1284 | 1274 |
1285 } // namespace wm | 1275 } // namespace wm |
OLD | NEW |