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/views/corewm/focus_controller.h" | 5 #include "ui/views/corewm/focus_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ui/aura/client/activation_change_observer.h" | 9 #include "ui/aura/client/activation_change_observer.h" |
10 #include "ui/aura/client/activation_client.h" | 10 #include "ui/aura/client/activation_client.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 focus_controller_.reset(); | 261 focus_controller_.reset(); |
262 } | 262 } |
263 | 263 |
264 void FocusWindow(aura::Window* window) { | 264 void FocusWindow(aura::Window* window) { |
265 aura::client::GetFocusClient(root_window())->FocusWindow(window); | 265 aura::client::GetFocusClient(root_window())->FocusWindow(window); |
266 } | 266 } |
267 aura::Window* GetFocusedWindow() { | 267 aura::Window* GetFocusedWindow() { |
268 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); | 268 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); |
269 } | 269 } |
270 int GetFocusedWindowId() { | 270 int GetFocusedWindowId() { |
271 return GetFocusedWindow()->id(); | 271 aura::Window* focused_window = GetFocusedWindow(); |
| 272 return focused_window ? focused_window->id() : -1; |
272 } | 273 } |
273 void ActivateWindow(aura::Window* window) { | 274 void ActivateWindow(aura::Window* window) { |
274 aura::client::GetActivationClient(root_window())->ActivateWindow(window); | 275 aura::client::GetActivationClient(root_window())->ActivateWindow(window); |
275 } | 276 } |
276 void DeactivateWindow(aura::Window* window) { | 277 void DeactivateWindow(aura::Window* window) { |
277 aura::client::GetActivationClient(root_window())->DeactivateWindow(window); | 278 aura::client::GetActivationClient(root_window())->DeactivateWindow(window); |
278 } | 279 } |
279 aura::Window* GetActiveWindow() { | 280 aura::Window* GetActiveWindow() { |
280 return aura::client::GetActivationClient(root_window())->GetActiveWindow(); | 281 return aura::client::GetActivationClient(root_window())->GetActiveWindow(); |
281 } | 282 } |
(...skipping 14 matching lines...) Expand all Loading... |
296 virtual void DuplicateActivationEvents() {} | 297 virtual void DuplicateActivationEvents() {} |
297 virtual void ShiftFocusWithinActiveWindow() {} | 298 virtual void ShiftFocusWithinActiveWindow() {} |
298 virtual void ShiftFocusToChildOfInactiveWindow() {} | 299 virtual void ShiftFocusToChildOfInactiveWindow() {} |
299 virtual void ShiftFocusToParentOfFocusedWindow() {} | 300 virtual void ShiftFocusToParentOfFocusedWindow() {} |
300 virtual void FocusRulesOverride() = 0; | 301 virtual void FocusRulesOverride() = 0; |
301 virtual void ActivationRulesOverride() = 0; | 302 virtual void ActivationRulesOverride() = 0; |
302 virtual void ShiftFocusOnActivation() {} | 303 virtual void ShiftFocusOnActivation() {} |
303 virtual void ShiftFocusOnActivationDueToHide() {} | 304 virtual void ShiftFocusOnActivationDueToHide() {} |
304 virtual void NoShiftActiveOnActivation() {} | 305 virtual void NoShiftActiveOnActivation() {} |
305 virtual void NoFocusChangeOnClickOnCaptureWindow() {} | 306 virtual void NoFocusChangeOnClickOnCaptureWindow() {} |
| 307 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
306 | 308 |
307 private: | 309 private: |
308 scoped_ptr<FocusController> focus_controller_; | 310 scoped_ptr<FocusController> focus_controller_; |
309 TestFocusRules* test_focus_rules_; | 311 TestFocusRules* test_focus_rules_; |
310 | 312 |
311 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 313 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
312 }; | 314 }; |
313 | 315 |
314 // Test base for tests where focus is directly set to a target window. | 316 // Test base for tests where focus is directly set to a target window. |
315 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 317 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 aura::Window* w2 = root_window()->GetChildById(2); | 593 aura::Window* w2 = root_window()->GetChildById(2); |
592 aura::client::GetCaptureClient(root_window())->SetCapture(w2); | 594 aura::client::GetCaptureClient(root_window())->SetCapture(w2); |
593 aura::test::EventGenerator generator(root_window(), w2); | 595 aura::test::EventGenerator generator(root_window(), w2); |
594 generator.ClickLeftButton(); | 596 generator.ClickLeftButton(); |
595 | 597 |
596 EXPECT_EQ(1, GetActiveWindowId()); | 598 EXPECT_EQ(1, GetActiveWindowId()); |
597 EXPECT_EQ(1, GetFocusedWindowId()); | 599 EXPECT_EQ(1, GetFocusedWindowId()); |
598 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); | 600 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); |
599 } | 601 } |
600 | 602 |
| 603 // Verifies focus change is honored while capture held. |
| 604 virtual void ChangeFocusWhenNothingFocusedAndCaptured() OVERRIDE { |
| 605 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( |
| 606 new aura::client::DefaultCaptureClient(root_window())); |
| 607 aura::Window* w1 = root_window()->GetChildById(1); |
| 608 aura::client::GetCaptureClient(root_window())->SetCapture(w1); |
| 609 |
| 610 EXPECT_EQ(-1, GetActiveWindowId()); |
| 611 EXPECT_EQ(-1, GetFocusedWindowId()); |
| 612 |
| 613 FocusWindowById(1); |
| 614 |
| 615 EXPECT_EQ(1, GetActiveWindowId()); |
| 616 EXPECT_EQ(1, GetFocusedWindowId()); |
| 617 |
| 618 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); |
| 619 } |
| 620 |
601 private: | 621 private: |
602 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 622 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
603 }; | 623 }; |
604 | 624 |
605 // Focus and Activation changes via aura::client::ActivationClient API. | 625 // Focus and Activation changes via aura::client::ActivationClient API. |
606 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 626 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
607 public: | 627 public: |
608 FocusControllerApiTest() {} | 628 FocusControllerApiTest() {} |
609 | 629 |
610 private: | 630 private: |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 | 1009 |
990 // - Verifies that attempts to change focus or activation from a focus or | 1010 // - Verifies that attempts to change focus or activation from a focus or |
991 // activation change observer are ignored. | 1011 // activation change observer are ignored. |
992 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); | 1012 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); |
993 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); | 1013 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); |
994 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 1014 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
995 | 1015 |
996 // Clicking on a window which has capture should not result in a focus change. | 1016 // Clicking on a window which has capture should not result in a focus change. |
997 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1017 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
998 | 1018 |
| 1019 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1020 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1021 |
999 } // namespace corewm | 1022 } // namespace corewm |
1000 } // namespace views | 1023 } // namespace views |
OLD | NEW |