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 "ash/common/shell_window_ids.h" | 5 #include "ash/common/shell_window_ids.h" |
6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
8 #include "ash/test/test_activation_delegate.h" | 8 #include "ash/test/test_activation_delegate.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "ui/aura/client/cursor_client_observer.h" | 10 #include "ui/aura/client/cursor_client_observer.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/events/test/test_event_handler.h" | 23 #include "ui/events/test/test_event_handler.h" |
24 #include "ui/wm/core/compound_event_filter.h" | 24 #include "ui/wm/core/compound_event_filter.h" |
25 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
26 #include "ui/wm/public/activation_delegate.h" | 26 #include "ui/wm/public/activation_delegate.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 class TestingCursorClientObserver : public aura::client::CursorClientObserver { | 30 class TestingCursorClientObserver : public aura::client::CursorClientObserver { |
31 public: | 31 public: |
32 TestingCursorClientObserver() | 32 TestingCursorClientObserver() |
33 : cursor_visibility_(false), | 33 : cursor_visibility_(false), did_visibility_change_(false) {} |
34 did_visibility_change_(false) {} | |
35 void reset() { cursor_visibility_ = did_visibility_change_ = false; } | 34 void reset() { cursor_visibility_ = did_visibility_change_ = false; } |
36 bool is_cursor_visible() const { return cursor_visibility_; } | 35 bool is_cursor_visible() const { return cursor_visibility_; } |
37 bool did_visibility_change() const { return did_visibility_change_; } | 36 bool did_visibility_change() const { return did_visibility_change_; } |
38 | 37 |
39 // Overridden from aura::client::CursorClientObserver: | 38 // Overridden from aura::client::CursorClientObserver: |
40 void OnCursorVisibilityChanged(bool is_visible) override { | 39 void OnCursorVisibilityChanged(bool is_visible) override { |
41 cursor_visibility_ = is_visible; | 40 cursor_visibility_ = is_visible; |
42 did_visibility_change_ = true; | 41 did_visibility_change_ = true; |
43 } | 42 } |
44 | 43 |
45 private: | 44 private: |
46 bool cursor_visibility_; | 45 bool cursor_visibility_; |
47 bool did_visibility_change_; | 46 bool did_visibility_change_; |
48 | 47 |
49 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); | 48 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); |
50 }; | 49 }; |
51 | 50 |
52 base::TimeTicks getTime() { | 51 base::TimeTicks getTime() { |
53 return ui::EventTimeForNow(); | 52 return ui::EventTimeForNow(); |
54 } | 53 } |
55 | 54 |
56 // A slightly changed TestEventHandler which can be configured to return a | 55 // A slightly changed TestEventHandler which can be configured to return a |
57 // specified value for key/mouse event handling. | 56 // specified value for key/mouse event handling. |
58 class CustomEventHandler : public ui::test::TestEventHandler { | 57 class CustomEventHandler : public ui::test::TestEventHandler { |
59 public: | 58 public: |
60 CustomEventHandler() | 59 CustomEventHandler() |
61 : key_result_(ui::ER_UNHANDLED), | 60 : key_result_(ui::ER_UNHANDLED), mouse_result_(ui::ER_UNHANDLED) {} |
62 mouse_result_(ui::ER_UNHANDLED) { | |
63 } | |
64 | 61 |
65 ~CustomEventHandler() override {} | 62 ~CustomEventHandler() override {} |
66 | 63 |
67 void set_key_event_handling_result(ui::EventResult result) { | 64 void set_key_event_handling_result(ui::EventResult result) { |
68 key_result_ = result; | 65 key_result_ = result; |
69 } | 66 } |
70 | 67 |
71 void set_mouse_event_handling_result(ui::EventResult result) { | 68 void set_mouse_event_handling_result(ui::EventResult result) { |
72 mouse_result_ = result; | 69 mouse_result_ = result; |
73 } | 70 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 NonFocusableDelegate() {} | 104 NonFocusableDelegate() {} |
108 | 105 |
109 private: | 106 private: |
110 bool CanFocus() override { return false; } | 107 bool CanFocus() override { return false; } |
111 | 108 |
112 DISALLOW_COPY_AND_ASSIGN(NonFocusableDelegate); | 109 DISALLOW_COPY_AND_ASSIGN(NonFocusableDelegate); |
113 }; | 110 }; |
114 | 111 |
115 class HitTestWindowDelegate : public aura::test::TestWindowDelegate { | 112 class HitTestWindowDelegate : public aura::test::TestWindowDelegate { |
116 public: | 113 public: |
117 HitTestWindowDelegate() | 114 HitTestWindowDelegate() : hittest_code_(HTNOWHERE) {} |
118 : hittest_code_(HTNOWHERE) { | |
119 } | |
120 ~HitTestWindowDelegate() override {} | 115 ~HitTestWindowDelegate() override {} |
121 void set_hittest_code(int hittest_code) { hittest_code_ = hittest_code; } | 116 void set_hittest_code(int hittest_code) { hittest_code_ = hittest_code; } |
122 | 117 |
123 private: | 118 private: |
124 // Overridden from TestWindowDelegate: | 119 // Overridden from TestWindowDelegate: |
125 int GetNonClientComponent(const gfx::Point& point) const override { | 120 int GetNonClientComponent(const gfx::Point& point) const override { |
126 return hittest_code_; | 121 return hittest_code_; |
127 } | 122 } |
128 | 123 |
129 int hittest_code_; | 124 int hittest_code_; |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // Creates a window and make it active | 650 // Creates a window and make it active |
656 std::unique_ptr<aura::Window> w1( | 651 std::unique_ptr<aura::Window> w1( |
657 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); | 652 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
658 wm::ActivateWindow(w1.get()); | 653 wm::ActivateWindow(w1.get()); |
659 | 654 |
660 // Creates two addition filters | 655 // Creates two addition filters |
661 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler); | 656 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler); |
662 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler); | 657 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler); |
663 | 658 |
664 // Adds them to root window event filter. | 659 // Adds them to root window event filter. |
665 ::wm::CompoundEventFilter* env_filter = | 660 ::wm::CompoundEventFilter* env_filter = Shell::GetInstance()->env_filter(); |
666 Shell::GetInstance()->env_filter(); | |
667 env_filter->AddHandler(f1.get()); | 661 env_filter->AddHandler(f1.get()); |
668 env_filter->AddHandler(f2.get()); | 662 env_filter->AddHandler(f2.get()); |
669 | 663 |
670 // Dispatches mouse and keyboard events. | 664 // Dispatches mouse and keyboard events. |
671 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 665 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
672 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); | 666 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
673 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); | 667 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); |
674 ASSERT_FALSE(details.dispatcher_destroyed); | 668 ASSERT_FALSE(details.dispatcher_destroyed); |
675 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 669 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), |
676 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); | 670 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 generator.MoveMouseTo(50, 50); | 844 generator.MoveMouseTo(50, 50); |
851 EXPECT_TRUE(observer_a.did_visibility_change()); | 845 EXPECT_TRUE(observer_a.did_visibility_change()); |
852 EXPECT_FALSE(observer_b.did_visibility_change()); | 846 EXPECT_FALSE(observer_b.did_visibility_change()); |
853 EXPECT_TRUE(observer_a.is_cursor_visible()); | 847 EXPECT_TRUE(observer_a.is_cursor_visible()); |
854 | 848 |
855 cursor_manager->RemoveObserver(&observer_a); | 849 cursor_manager->RemoveObserver(&observer_a); |
856 } | 850 } |
857 #endif // defined(OS_CHROMEOS) | 851 #endif // defined(OS_CHROMEOS) |
858 | 852 |
859 } // namespace ash | 853 } // namespace ash |
OLD | NEW |