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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 DispatchEvent(&mouse); | 135 DispatchEvent(&mouse); |
136 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 136 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
137 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 137 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
138 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 138 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
139 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 139 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
140 grandchild_r->ResetReceivedEvents(); | 140 grandchild_r->ResetReceivedEvents(); |
141 | 141 |
142 // 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 |
143 // 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 |
144 // the bounds of the target. | 144 // the bounds of the target. |
| 145 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1), EF_NONE, |
| 146 EF_NONE); |
145 parent_r->SetEventTargeter(scoped_ptr<EventTargeter>( | 147 parent_r->SetEventTargeter(scoped_ptr<EventTargeter>( |
146 new BoundsEventTargeter<BoundsTestTarget>())); | 148 new BoundsEventTargeter<BoundsTestTarget>())); |
147 DispatchEvent(&mouse); | 149 DispatchEvent(&mouse2); |
148 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 150 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
149 EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 151 EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
150 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 152 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
151 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 153 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
152 parent_r->ResetReceivedEvents(); | 154 parent_r->ResetReceivedEvents(); |
153 | 155 |
154 MouseEvent second(ET_MOUSE_MOVED, gfx::Point(12, 12), gfx::Point(12, 12), | 156 MouseEvent second(ET_MOUSE_MOVED, gfx::Point(12, 12), gfx::Point(12, 12), |
155 EF_NONE, EF_NONE); | 157 EF_NONE, EF_NONE); |
156 DispatchEvent(&second); | 158 DispatchEvent(&second); |
157 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 159 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
158 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 160 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
159 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 161 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
160 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 162 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
161 } | 163 } |
162 | 164 |
| 165 class IgnoreEventTargeter : public EventTargeter { |
| 166 public: |
| 167 IgnoreEventTargeter() {} |
| 168 virtual ~IgnoreEventTargeter() {} |
| 169 |
| 170 private: |
| 171 // EventTargeter: |
| 172 virtual bool SubtreeShouldBeExploredForEvent( |
| 173 EventTarget* target, const LocatedEvent& event) OVERRIDE { |
| 174 return false; |
| 175 } |
| 176 }; |
| 177 |
| 178 // Verifies that the EventTargeter installed on an EventTarget can dictate |
| 179 // whether the target itself can process an event. |
| 180 TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) { |
| 181 scoped_ptr<TestEventTarget> child(new TestEventTarget()); |
| 182 root()->AddChild(child.Pass()); |
| 183 |
| 184 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 185 EF_NONE, EF_NONE); |
| 186 DispatchEvent(&mouse); |
| 187 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 188 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 189 root()->child_at(0)->ResetReceivedEvents(); |
| 190 |
| 191 // Install an even handler on |child| which always prevents the target from |
| 192 // receiving event. |
| 193 root()->child_at(0)->SetEventTargeter( |
| 194 scoped_ptr<EventTargeter>(new IgnoreEventTargeter())); |
| 195 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 196 EF_NONE, EF_NONE); |
| 197 DispatchEvent(&mouse2); |
| 198 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 199 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 200 } |
| 201 |
163 } // namespace test | 202 } // namespace test |
164 } // namespace ui | 203 } // namespace ui |
OLD | NEW |