| 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" |
| 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/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/test/aura_test_base.h" | 15 #include "ui/aura/test/aura_test_base.h" |
| 16 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 17 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
| 18 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_tracker.h" | 20 #include "ui/aura/window_tracker.h" |
| 21 #include "ui/events/event_handler.h" | 21 #include "ui/events/event_handler.h" |
| 22 #include "ui/views/corewm/base_focus_rules.h" | 22 #include "ui/views/corewm/base_focus_rules.h" |
| 23 #include "ui/views/corewm/wm_state.h" |
| 23 | 24 |
| 24 namespace views { | 25 namespace views { |
| 25 namespace corewm { | 26 namespace corewm { |
| 26 | 27 |
| 27 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 28 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
| 28 public aura::client::FocusChangeObserver { | 29 public aura::client::FocusChangeObserver { |
| 29 public: | 30 public: |
| 30 FocusNotificationObserver() | 31 FocusNotificationObserver() |
| 31 : activation_changed_count_(0), | 32 : activation_changed_count_(0), |
| 32 focus_changed_count_(0), | 33 focus_changed_count_(0), |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 268 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
| 268 }; | 269 }; |
| 269 | 270 |
| 270 // Common infrastructure shared by all FocusController test types. | 271 // Common infrastructure shared by all FocusController test types. |
| 271 class FocusControllerTestBase : public aura::test::AuraTestBase { | 272 class FocusControllerTestBase : public aura::test::AuraTestBase { |
| 272 protected: | 273 protected: |
| 273 FocusControllerTestBase() {} | 274 FocusControllerTestBase() {} |
| 274 | 275 |
| 275 // Overridden from aura::test::AuraTestBase: | 276 // Overridden from aura::test::AuraTestBase: |
| 276 virtual void SetUp() OVERRIDE { | 277 virtual void SetUp() OVERRIDE { |
| 278 wm_state_.reset(new views::corewm::WMState); |
| 277 // FocusController registers itself as an Env observer so it can catch all | 279 // FocusController registers itself as an Env observer so it can catch all |
| 278 // window initializations, including the root_window()'s, so we create it | 280 // window initializations, including the root_window()'s, so we create it |
| 279 // before allowing the base setup. | 281 // before allowing the base setup. |
| 280 test_focus_rules_ = new TestFocusRules; | 282 test_focus_rules_ = new TestFocusRules; |
| 281 focus_controller_.reset(new FocusController(test_focus_rules_)); | 283 focus_controller_.reset(new FocusController(test_focus_rules_)); |
| 282 aura::test::AuraTestBase::SetUp(); | 284 aura::test::AuraTestBase::SetUp(); |
| 283 root_window()->AddPreTargetHandler(focus_controller_.get()); | 285 root_window()->AddPreTargetHandler(focus_controller_.get()); |
| 284 aura::client::SetFocusClient(root_window(), focus_controller_.get()); | 286 aura::client::SetFocusClient(root_window(), focus_controller_.get()); |
| 285 aura::client::SetActivationClient(root_window(), focus_controller_.get()); | 287 aura::client::SetActivationClient(root_window(), focus_controller_.get()); |
| 286 | 288 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 313 gfx::Rect(1, 1, 5, 5), w21); | 315 gfx::Rect(1, 1, 5, 5), w21); |
| 314 aura::test::CreateTestWindowWithDelegate( | 316 aura::test::CreateTestWindowWithDelegate( |
| 315 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, | 317 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, |
| 316 gfx::Rect(125, 125, 50, 50), root_window()); | 318 gfx::Rect(125, 125, 50, 50), root_window()); |
| 317 } | 319 } |
| 318 virtual void TearDown() OVERRIDE { | 320 virtual void TearDown() OVERRIDE { |
| 319 root_window()->RemovePreTargetHandler(focus_controller_.get()); | 321 root_window()->RemovePreTargetHandler(focus_controller_.get()); |
| 320 aura::test::AuraTestBase::TearDown(); | 322 aura::test::AuraTestBase::TearDown(); |
| 321 test_focus_rules_ = NULL; // Owned by FocusController. | 323 test_focus_rules_ = NULL; // Owned by FocusController. |
| 322 focus_controller_.reset(); | 324 focus_controller_.reset(); |
| 325 wm_state_.reset(); |
| 323 } | 326 } |
| 324 | 327 |
| 325 void FocusWindow(aura::Window* window) { | 328 void FocusWindow(aura::Window* window) { |
| 326 aura::client::GetFocusClient(root_window())->FocusWindow(window); | 329 aura::client::GetFocusClient(root_window())->FocusWindow(window); |
| 327 } | 330 } |
| 328 aura::Window* GetFocusedWindow() { | 331 aura::Window* GetFocusedWindow() { |
| 329 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); | 332 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); |
| 330 } | 333 } |
| 331 int GetFocusedWindowId() { | 334 int GetFocusedWindowId() { |
| 332 aura::Window* focused_window = GetFocusedWindow(); | 335 aura::Window* focused_window = GetFocusedWindow(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 virtual void ShiftFocusOnActivation() {} | 367 virtual void ShiftFocusOnActivation() {} |
| 365 virtual void ShiftFocusOnActivationDueToHide() {} | 368 virtual void ShiftFocusOnActivationDueToHide() {} |
| 366 virtual void NoShiftActiveOnActivation() {} | 369 virtual void NoShiftActiveOnActivation() {} |
| 367 virtual void NoFocusChangeOnClickOnCaptureWindow() {} | 370 virtual void NoFocusChangeOnClickOnCaptureWindow() {} |
| 368 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 371 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 369 virtual void DontPassDeletedWindow() {} | 372 virtual void DontPassDeletedWindow() {} |
| 370 | 373 |
| 371 private: | 374 private: |
| 372 scoped_ptr<FocusController> focus_controller_; | 375 scoped_ptr<FocusController> focus_controller_; |
| 373 TestFocusRules* test_focus_rules_; | 376 TestFocusRules* test_focus_rules_; |
| 377 scoped_ptr<views::corewm::WMState> wm_state_; |
| 374 | 378 |
| 375 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 379 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
| 376 }; | 380 }; |
| 377 | 381 |
| 378 // Test base for tests where focus is directly set to a target window. | 382 // Test base for tests where focus is directly set to a target window. |
| 379 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 383 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
| 380 protected: | 384 protected: |
| 381 FocusControllerDirectTestBase() {} | 385 FocusControllerDirectTestBase() {} |
| 382 | 386 |
| 383 // Different test types shift focus in different ways. | 387 // Different test types shift focus in different ways. |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1105 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
| 1102 | 1106 |
| 1103 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1107 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1104 ChangeFocusWhenNothingFocusedAndCaptured); | 1108 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1105 | 1109 |
| 1106 // See description above DontPassDeletedWindow() for details. | 1110 // See description above DontPassDeletedWindow() for details. |
| 1107 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1111 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
| 1108 | 1112 |
| 1109 } // namespace corewm | 1113 } // namespace corewm |
| 1110 } // namespace views | 1114 } // namespace views |
| OLD | NEW |