| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "ui/events/event.h" | 6 #include "ui/events/event.h" |
| 7 #include "ui/events/event_targeter.h" | 7 #include "ui/events/event_targeter.h" |
| 8 #include "ui/events/test/test_event_processor.h" | 8 #include "ui/events/test/test_event_processor.h" |
| 9 #include "ui/events/test/test_event_target.h" | 9 #include "ui/events/test/test_event_target.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 TestEventProcessor processor_; | 34 TestEventProcessor processor_; |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); | 36 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 TEST_F(EventProcessorTest, Basic) { | 39 TEST_F(EventProcessorTest, Basic) { |
| 40 scoped_ptr<TestEventTarget> child(new TestEventTarget()); | 40 scoped_ptr<TestEventTarget> child(new TestEventTarget()); |
| 41 root()->AddChild(child.Pass()); | 41 root()->AddChild(child.Pass()); |
| 42 | 42 |
| 43 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 43 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 44 EF_NONE); | 44 EF_NONE, EF_NONE); |
| 45 DispatchEvent(&mouse); | 45 DispatchEvent(&mouse); |
| 46 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 46 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 47 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 47 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 48 | 48 |
| 49 root()->RemoveChild(root()->child_at(0)); | 49 root()->RemoveChild(root()->child_at(0)); |
| 50 DispatchEvent(&mouse); | 50 DispatchEvent(&mouse); |
| 51 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 51 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 template<typename T> | 54 template<typename T> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ASSERT_EQ(1u, root()->child_at(0)->child_count()); | 123 ASSERT_EQ(1u, root()->child_at(0)->child_count()); |
| 124 ASSERT_EQ(1u, root()->child_at(0)->child_at(0)->child_count()); | 124 ASSERT_EQ(1u, root()->child_at(0)->child_at(0)->child_count()); |
| 125 | 125 |
| 126 TestEventTarget* parent_r = root()->child_at(0); | 126 TestEventTarget* parent_r = root()->child_at(0); |
| 127 TestEventTarget* child_r = parent_r->child_at(0); | 127 TestEventTarget* child_r = parent_r->child_at(0); |
| 128 TestEventTarget* grandchild_r = child_r->child_at(0); | 128 TestEventTarget* grandchild_r = child_r->child_at(0); |
| 129 | 129 |
| 130 // Dispatch a mouse event that falls on the parent, but not on the child. When | 130 // Dispatch a mouse event that falls on the parent, but not on the child. When |
| 131 // the default event-targeter used, the event will still reach |grandchild|, | 131 // the default event-targeter used, the event will still reach |grandchild|, |
| 132 // because the default targeter does not look at the bounds. | 132 // because the default targeter does not look at the bounds. |
| 133 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1), EF_NONE); | 133 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1), EF_NONE, |
| 134 EF_NONE); |
| 134 DispatchEvent(&mouse); | 135 DispatchEvent(&mouse); |
| 135 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 136 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 136 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 137 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 137 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 138 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 138 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 139 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 139 grandchild_r->ResetReceivedEvents(); | 140 grandchild_r->ResetReceivedEvents(); |
| 140 | 141 |
| 141 // Now install a targeter on the parent that looks at the bounds and makes | 142 // Now install a targeter on the parent that looks at the bounds and makes |
| 142 // sure the event reaches the target only if the location of the event within | 143 // sure the event reaches the target only if the location of the event within |
| 143 // the bounds of the target. | 144 // the bounds of the target. |
| 144 parent_r->SetEventTargeter(scoped_ptr<EventTargeter>( | 145 parent_r->SetEventTargeter(scoped_ptr<EventTargeter>( |
| 145 new BoundsEventTargeter<BoundsTestTarget>())); | 146 new BoundsEventTargeter<BoundsTestTarget>())); |
| 146 DispatchEvent(&mouse); | 147 DispatchEvent(&mouse); |
| 147 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 148 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 148 EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 149 EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 149 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 150 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 150 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 151 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 151 parent_r->ResetReceivedEvents(); | 152 parent_r->ResetReceivedEvents(); |
| 152 | 153 |
| 153 MouseEvent second(ET_MOUSE_MOVED, gfx::Point(12, 12), gfx::Point(12, 12), | 154 MouseEvent second(ET_MOUSE_MOVED, gfx::Point(12, 12), gfx::Point(12, 12), |
| 154 EF_NONE); | 155 EF_NONE, EF_NONE); |
| 155 DispatchEvent(&second); | 156 DispatchEvent(&second); |
| 156 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 157 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 157 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 158 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 158 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 159 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 159 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 160 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 160 } | 161 } |
| 161 | 162 |
| 162 } // namespace test | 163 } // namespace test |
| 163 } // namespace ui | 164 } // namespace ui |
| OLD | NEW |