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/transient_window_stacking_client.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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 207 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
207 }; | 208 }; |
208 | 209 |
209 // Common infrastructure shared by all FocusController test types. | 210 // Common infrastructure shared by all FocusController test types. |
210 class FocusControllerTestBase : public aura::test::AuraTestBase { | 211 class FocusControllerTestBase : public aura::test::AuraTestBase { |
211 protected: | 212 protected: |
212 FocusControllerTestBase() {} | 213 FocusControllerTestBase() {} |
213 | 214 |
214 // Overridden from aura::test::AuraTestBase: | 215 // Overridden from aura::test::AuraTestBase: |
215 virtual void SetUp() OVERRIDE { | 216 virtual void SetUp() OVERRIDE { |
| 217 // SetWindowStackingClient() takes ownership of |
| 218 // TransientWindowStackingClient. |
| 219 aura::client::SetWindowStackingClient( |
| 220 new corewm::TransientWindowStackingClient); |
216 // FocusController registers itself as an Env observer so it can catch all | 221 // FocusController registers itself as an Env observer so it can catch all |
217 // window initializations, including the root_window()'s, so we create it | 222 // window initializations, including the root_window()'s, so we create it |
218 // before allowing the base setup. | 223 // before allowing the base setup. |
219 test_focus_rules_ = new TestFocusRules; | 224 test_focus_rules_ = new TestFocusRules; |
220 focus_controller_.reset(new FocusController(test_focus_rules_)); | 225 focus_controller_.reset(new FocusController(test_focus_rules_)); |
221 aura::test::AuraTestBase::SetUp(); | 226 aura::test::AuraTestBase::SetUp(); |
222 root_window()->AddPreTargetHandler(focus_controller_.get()); | 227 root_window()->AddPreTargetHandler(focus_controller_.get()); |
223 aura::client::SetFocusClient(root_window(), focus_controller_.get()); | 228 aura::client::SetFocusClient(root_window(), focus_controller_.get()); |
224 aura::client::SetActivationClient(root_window(), focus_controller_.get()); | 229 aura::client::SetActivationClient(root_window(), focus_controller_.get()); |
225 | 230 |
(...skipping 26 matching lines...) Expand all Loading... |
252 gfx::Rect(1, 1, 5, 5), w21); | 257 gfx::Rect(1, 1, 5, 5), w21); |
253 aura::test::CreateTestWindowWithDelegate( | 258 aura::test::CreateTestWindowWithDelegate( |
254 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, | 259 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3, |
255 gfx::Rect(125, 125, 50, 50), root_window()); | 260 gfx::Rect(125, 125, 50, 50), root_window()); |
256 } | 261 } |
257 virtual void TearDown() OVERRIDE { | 262 virtual void TearDown() OVERRIDE { |
258 root_window()->RemovePreTargetHandler(focus_controller_.get()); | 263 root_window()->RemovePreTargetHandler(focus_controller_.get()); |
259 aura::test::AuraTestBase::TearDown(); | 264 aura::test::AuraTestBase::TearDown(); |
260 test_focus_rules_ = NULL; // Owned by FocusController. | 265 test_focus_rules_ = NULL; // Owned by FocusController. |
261 focus_controller_.reset(); | 266 focus_controller_.reset(); |
| 267 aura::client::SetWindowStackingClient(NULL); |
262 } | 268 } |
263 | 269 |
264 void FocusWindow(aura::Window* window) { | 270 void FocusWindow(aura::Window* window) { |
265 aura::client::GetFocusClient(root_window())->FocusWindow(window); | 271 aura::client::GetFocusClient(root_window())->FocusWindow(window); |
266 } | 272 } |
267 aura::Window* GetFocusedWindow() { | 273 aura::Window* GetFocusedWindow() { |
268 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); | 274 return aura::client::GetFocusClient(root_window())->GetFocusedWindow(); |
269 } | 275 } |
270 int GetFocusedWindowId() { | 276 int GetFocusedWindowId() { |
271 aura::Window* focused_window = GetFocusedWindow(); | 277 aura::Window* focused_window = GetFocusedWindow(); |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 1020 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
1015 | 1021 |
1016 // Clicking on a window which has capture should not result in a focus change. | 1022 // Clicking on a window which has capture should not result in a focus change. |
1017 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1023 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
1018 | 1024 |
1019 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1025 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
1020 ChangeFocusWhenNothingFocusedAndCaptured); | 1026 ChangeFocusWhenNothingFocusedAndCaptured); |
1021 | 1027 |
1022 } // namespace corewm | 1028 } // namespace corewm |
1023 } // namespace views | 1029 } // namespace views |
OLD | NEW |