| 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 "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/client/default_capture_client.h" | 12 #include "ui/aura/client/default_capture_client.h" |
| 13 #include "ui/aura/client/focus_change_observer.h" | 13 #include "ui/aura/client/focus_change_observer.h" |
| 14 #include "ui/aura/test/aura_test_base.h" | 14 #include "ui/aura/test/aura_test_base.h" |
| 15 #include "ui/aura/test/test_window_delegate.h" | 15 #include "ui/aura/test/test_window_delegate.h" |
| 16 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
| 19 #include "ui/aura/window_tracker.h" | 19 #include "ui/aura/window_tracker.h" |
| 20 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 21 #include "ui/events/event_constants.h" | 21 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/event_handler.h" | 22 #include "ui/events/event_handler.h" |
| 23 #include "ui/events/test/event_generator.h" | 23 #include "ui/events/test/event_generator.h" |
| 24 #include "ui/wm/core/base_focus_rules.h" | 24 #include "ui/wm/core/base_focus_rules.h" |
| 25 #include "ui/wm/core/window_util.h" | 25 #include "ui/wm/core/window_util.h" |
| 26 #include "ui/wm/core/wm_state.h" | |
| 27 #include "ui/wm/public/activation_change_observer.h" | 26 #include "ui/wm/public/activation_change_observer.h" |
| 28 #include "ui/wm/public/activation_client.h" | 27 #include "ui/wm/public/activation_client.h" |
| 29 | 28 |
| 30 namespace wm { | 29 namespace wm { |
| 31 | 30 |
| 32 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
| 33 public aura::client::FocusChangeObserver { | 32 public aura::client::FocusChangeObserver { |
| 34 public: | 33 public: |
| 35 FocusNotificationObserver() | 34 FocusNotificationObserver() |
| 36 : last_activation_reason_(ActivationReason::ACTIVATION_CLIENT), | 35 : last_activation_reason_(ActivationReason::ACTIVATION_CLIENT), |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 364 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
| 366 }; | 365 }; |
| 367 | 366 |
| 368 // Common infrastructure shared by all FocusController test types. | 367 // Common infrastructure shared by all FocusController test types. |
| 369 class FocusControllerTestBase : public aura::test::AuraTestBase { | 368 class FocusControllerTestBase : public aura::test::AuraTestBase { |
| 370 protected: | 369 protected: |
| 371 FocusControllerTestBase() {} | 370 FocusControllerTestBase() {} |
| 372 | 371 |
| 373 // Overridden from aura::test::AuraTestBase: | 372 // Overridden from aura::test::AuraTestBase: |
| 374 void SetUp() override { | 373 void SetUp() override { |
| 375 wm_state_.reset(new wm::WMState); | |
| 376 // FocusController registers itself as an Env observer so it can catch all | 374 // FocusController registers itself as an Env observer so it can catch all |
| 377 // window initializations, including the root_window()'s, so we create it | 375 // window initializations, including the root_window()'s, so we create it |
| 378 // before allowing the base setup. | 376 // before allowing the base setup. |
| 379 test_focus_rules_ = new TestFocusRules; | 377 test_focus_rules_ = new TestFocusRules; |
| 380 focus_controller_.reset(new FocusController(test_focus_rules_)); | 378 focus_controller_.reset(new FocusController(test_focus_rules_)); |
| 381 aura::test::AuraTestBase::SetUp(); | 379 aura::test::AuraTestBase::SetUp(); |
| 382 root_window()->AddPreTargetHandler(focus_controller_.get()); | 380 root_window()->AddPreTargetHandler(focus_controller_.get()); |
| 383 aura::client::SetFocusClient(root_window(), focus_controller_.get()); | 381 aura::client::SetFocusClient(root_window(), focus_controller_.get()); |
| 384 aura::client::SetActivationClient(root_window(), focus_controller_.get()); | 382 aura::client::SetActivationClient(root_window(), focus_controller_.get()); |
| 385 | 383 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 412 gfx::Rect(1, 1, 5, 5), w21); | 410 gfx::Rect(1, 1, 5, 5), w21); |
| 413 aura::test::CreateTestWindowWithDelegate( | 411 aura::test::CreateTestWindowWithDelegate( |
| 414 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, | 412 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, |
| 415 gfx::Rect(125, 125, 50, 50), root_window()); | 413 gfx::Rect(125, 125, 50, 50), root_window()); |
| 416 } | 414 } |
| 417 void TearDown() override { | 415 void TearDown() override { |
| 418 root_window()->RemovePreTargetHandler(focus_controller_.get()); | 416 root_window()->RemovePreTargetHandler(focus_controller_.get()); |
| 419 aura::test::AuraTestBase::TearDown(); | 417 aura::test::AuraTestBase::TearDown(); |
| 420 test_focus_rules_ = NULL; // Owned by FocusController. | 418 test_focus_rules_ = NULL; // Owned by FocusController. |
| 421 focus_controller_.reset(); | 419 focus_controller_.reset(); |
| 422 wm_state_.reset(); | |
| 423 } | 420 } |
| 424 | 421 |
| 425 void FocusWindow(aura::Window* window) { | 422 void FocusWindow(aura::Window* window) { |
| 426 aura::client::GetFocusClient(root_window())->FocusWindow(window); | 423 aura::client::GetFocusClient(root_window())->FocusWindow(window); |
| 427 } | 424 } |
| 428 aura::Window* GetFocusedWindow() { | 425 aura::Window* GetFocusedWindow() { |
| 429 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); | 426 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); |
| 430 } | 427 } |
| 431 int GetFocusedWindowId() { | 428 int GetFocusedWindowId() { |
| 432 aura::Window* focused_window = GetFocusedWindow(); | 429 aura::Window* focused_window = GetFocusedWindow(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 virtual void ShiftFocusOnActivationDueToHide() {} | 462 virtual void ShiftFocusOnActivationDueToHide() {} |
| 466 virtual void NoShiftActiveOnActivation() {} | 463 virtual void NoShiftActiveOnActivation() {} |
| 467 virtual void FocusChangeDuringDrag() {} | 464 virtual void FocusChangeDuringDrag() {} |
| 468 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 465 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 469 virtual void DontPassDeletedWindow() {} | 466 virtual void DontPassDeletedWindow() {} |
| 470 virtual void StackWindowAtTopOnActivation() {} | 467 virtual void StackWindowAtTopOnActivation() {} |
| 471 | 468 |
| 472 private: | 469 private: |
| 473 std::unique_ptr<FocusController> focus_controller_; | 470 std::unique_ptr<FocusController> focus_controller_; |
| 474 TestFocusRules* test_focus_rules_; | 471 TestFocusRules* test_focus_rules_; |
| 475 std::unique_ptr<wm::WMState> wm_state_; | |
| 476 | 472 |
| 477 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 473 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
| 478 }; | 474 }; |
| 479 | 475 |
| 480 // Test base for tests where focus is directly set to a target window. | 476 // Test base for tests where focus is directly set to a target window. |
| 481 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 477 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
| 482 protected: | 478 protected: |
| 483 FocusControllerDirectTestBase() {} | 479 FocusControllerDirectTestBase() {} |
| 484 | 480 |
| 485 // Different test types shift focus in different ways. | 481 // Different test types shift focus in different ways. |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation); | 1317 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation); |
| 1322 | 1318 |
| 1323 // See description above TransientChildWindowActivationTest() for details. | 1319 // See description above TransientChildWindowActivationTest() for details. |
| 1324 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, | 1320 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, |
| 1325 TransientChildWindowActivationTest); | 1321 TransientChildWindowActivationTest); |
| 1326 | 1322 |
| 1327 // If a mouse event was handled, it should not activate a window. | 1323 // If a mouse event was handled, it should not activate a window. |
| 1328 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1324 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1329 | 1325 |
| 1330 } // namespace wm | 1326 } // namespace wm |
| OLD | NEW |