Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: ui/aura/window_targeter_unittest.cc

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/aura/window_targeter.h" 5 #include "ui/aura/window_targeter.h"
6 6
7 #include "ui/aura/scoped_window_targeter.h" 7 #include "ui/aura/scoped_window_targeter.h"
8 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_window_delegate.h" 9 #include "ui/aura/test/test_window_delegate.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 61 window->SetBounds(gfx::Rect(0, 0, 100, 100));
62 one->SetBounds(gfx::Rect(0, 0, 500, 100)); 62 one->SetBounds(gfx::Rect(0, 0, 500, 100));
63 two->SetBounds(gfx::Rect(501, 0, 500, 1000)); 63 two->SetBounds(gfx::Rect(501, 0, 500, 1000));
64 64
65 root_window()->Show(); 65 root_window()->Show();
66 66
67 ui::test::TestEventHandler handler; 67 ui::test::TestEventHandler handler;
68 one->AddPreTargetHandler(&handler); 68 one->AddPreTargetHandler(&handler);
69 69
70 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::Point(20, 20), 70 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::PointF(20.f, 20.f),
71 gfx::Point(20, 20), ui::EventTimeForNow(), ui::EF_NONE, 71 gfx::PointF(20.f, 20.f), ui::EventTimeForNow(),
72 ui::EF_NONE); 72 ui::EF_NONE, ui::EF_NONE);
73 DispatchEventUsingWindowDispatcher(&press); 73 DispatchEventUsingWindowDispatcher(&press);
74 EXPECT_EQ(1, handler.num_mouse_events()); 74 EXPECT_EQ(1, handler.num_mouse_events());
75 75
76 handler.Reset(); 76 handler.Reset();
77 DispatchEventUsingWindowDispatcher(&press); 77 DispatchEventUsingWindowDispatcher(&press);
78 EXPECT_EQ(1, handler.num_mouse_events()); 78 EXPECT_EQ(1, handler.num_mouse_events());
79 79
80 one->RemovePreTargetHandler(&handler); 80 one->RemovePreTargetHandler(&handler);
81 } 81 }
82 82
83 TEST_F(WindowTargeterTest, ScopedWindowTargeter) { 83 TEST_F(WindowTargeterTest, ScopedWindowTargeter) {
84 test::TestWindowDelegate delegate; 84 test::TestWindowDelegate delegate;
85 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate)); 85 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate));
86 Window* child = CreateNormalWindow(2, window.get(), &delegate); 86 Window* child = CreateNormalWindow(2, window.get(), &delegate);
87 87
88 window->SetBounds(gfx::Rect(30, 30, 100, 100)); 88 window->SetBounds(gfx::Rect(30, 30, 100, 100));
89 child->SetBounds(gfx::Rect(20, 20, 50, 50)); 89 child->SetBounds(gfx::Rect(20, 20, 50, 50));
90 root_window()->Show(); 90 root_window()->Show();
91 91
92 ui::EventTarget* root = root_window(); 92 ui::EventTarget* root = root_window();
93 ui::EventTargeter* targeter = root->GetEventTargeter(); 93 ui::EventTargeter* targeter = root->GetEventTargeter();
94 94
95 gfx::Point event_location(60, 60); 95 gfx::PointF event_location(60.f, 60.f);
96 { 96 {
97 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, 97 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
98 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 98 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
99 EXPECT_EQ(child, targeter->FindTargetForEvent(root, &mouse)); 99 EXPECT_EQ(child, targeter->FindTargetForEvent(root, &mouse));
100 } 100 }
101 101
102 // Install a targeter on |window| so that the events never reach the child. 102 // Install a targeter on |window| so that the events never reach the child.
103 scoped_ptr<ScopedWindowTargeter> scoped_targeter( 103 scoped_ptr<ScopedWindowTargeter> scoped_targeter(
104 new ScopedWindowTargeter(window.get(), scoped_ptr<ui::EventTargeter>( 104 new ScopedWindowTargeter(window.get(), scoped_ptr<ui::EventTargeter>(
105 new StaticWindowTargeter(window.get())))); 105 new StaticWindowTargeter(window.get()))));
(...skipping 29 matching lines...) Expand all
135 root_window()->Show(); 135 root_window()->Show();
136 136
137 test::TestWindowDelegate delegate; 137 test::TestWindowDelegate delegate;
138 scoped_ptr<Window> window(CreateNormalWindow(2, root_window(), &delegate)); 138 scoped_ptr<Window> window(CreateNormalWindow(2, root_window(), &delegate));
139 139
140 const gfx::Rect window_bounds(100, 20, 400, 80); 140 const gfx::Rect window_bounds(100, 20, 400, 80);
141 window->SetBounds(window_bounds); 141 window->SetBounds(window_bounds);
142 142
143 ui::EventTarget* root_target = root_window(); 143 ui::EventTarget* root_target = root_window();
144 ui::EventTargeter* targeter = root_target->GetEventTargeter(); 144 ui::EventTargeter* targeter = root_target->GetEventTargeter();
145 gfx::Point event_location(490, 50); 145 gfx::PointF event_location(490.f, 50.f);
146 { 146 {
147 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, 147 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
148 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 148 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
149 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); 149 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse));
150 } 150 }
151 151
152 // Scale |window| by 50%. This should move it away from underneath 152 // Scale |window| by 50%. This should move it away from underneath
153 // |event_location|, so an event in that location will not be targeted to it. 153 // |event_location|, so an event in that location will not be targeted to it.
154 gfx::Transform transform; 154 gfx::Transform transform;
155 transform.Scale(0.5, 0.5); 155 transform.Scale(0.5, 0.5);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 Window* parent_r = root_window()->children()[0]; 209 Window* parent_r = root_window()->children()[0];
210 Window* child_r = parent_r->children()[0]; 210 Window* child_r = parent_r->children()[0];
211 Window* grandchild_r = child_r->children()[0]; 211 Window* grandchild_r = child_r->children()[0];
212 212
213 ui::EventTarget* root_target = root_window(); 213 ui::EventTarget* root_target = root_window();
214 ui::EventTargeter* targeter = root_target->GetEventTargeter(); 214 ui::EventTargeter* targeter = root_target->GetEventTargeter();
215 215
216 // Dispatch a mouse event that falls on the parent, but not on the child. When 216 // Dispatch a mouse event that falls on the parent, but not on the child. When
217 // the default event-targeter used, the event will still reach |grandchild|, 217 // the default event-targeter used, the event will still reach |grandchild|,
218 // because the default targeter does not look at the bounds. 218 // because the default targeter does not look at the bounds.
219 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1), 219 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::PointF(1.f, 1.f),
220 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 220 gfx::PointF(1.f, 1.f), ui::EventTimeForNow(),
221 ui::EF_NONE, ui::EF_NONE);
221 EXPECT_EQ(parent_r, targeter->FindTargetForEvent(root_target, &mouse)); 222 EXPECT_EQ(parent_r, targeter->FindTargetForEvent(root_target, &mouse));
222 223
223 // Install a targeter on the |child| that looks at the window id as well 224 // Install a targeter on the |child| that looks at the window id as well
224 // as the bounds and makes sure the event reaches the target only if the id of 225 // as the bounds and makes sure the event reaches the target only if the id of
225 // the window is equal to 2 (incorrect). This causes the event to get handled 226 // the window is equal to 2 (incorrect). This causes the event to get handled
226 // by |parent|. 227 // by |parent|.
227 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(8, 8), gfx::Point(8, 8), 228 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::PointF(8.f, 8.f),
228 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 229 gfx::PointF(8.f, 8.f), ui::EventTimeForNow(),
230 ui::EF_NONE, ui::EF_NONE);
229 scoped_ptr<ui::EventTargeter> original_targeter = child_r->SetEventTargeter( 231 scoped_ptr<ui::EventTargeter> original_targeter = child_r->SetEventTargeter(
230 scoped_ptr<ui::EventTargeter>(new IdCheckingEventTargeter(2))); 232 scoped_ptr<ui::EventTargeter>(new IdCheckingEventTargeter(2)));
231 EXPECT_EQ(parent_r, targeter->FindTargetForEvent(root_target, &mouse2)); 233 EXPECT_EQ(parent_r, targeter->FindTargetForEvent(root_target, &mouse2));
232 234
233 // Now install a targeter on the |child| that looks at the window id as well 235 // Now install a targeter on the |child| that looks at the window id as well
234 // as the bounds and makes sure the event reaches the target only if the id of 236 // as the bounds and makes sure the event reaches the target only if the id of
235 // the window is equal to 1 (correct). 237 // the window is equal to 1 (correct).
236 ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::Point(8, 8), gfx::Point(8, 8), 238 ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::PointF(8.f, 8.f),
237 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 239 gfx::PointF(8.f, 8.f), ui::EventTimeForNow(),
240 ui::EF_NONE, ui::EF_NONE);
238 child_r->SetEventTargeter( 241 child_r->SetEventTargeter(
239 scoped_ptr<ui::EventTargeter>(new IdCheckingEventTargeter(1))); 242 scoped_ptr<ui::EventTargeter>(new IdCheckingEventTargeter(1)));
240 EXPECT_EQ(child_r, targeter->FindTargetForEvent(root_target, &mouse3)); 243 EXPECT_EQ(child_r, targeter->FindTargetForEvent(root_target, &mouse3));
241 244
242 // restore original WindowTargeter for |child|. 245 // restore original WindowTargeter for |child|.
243 child_r->SetEventTargeter(original_targeter.Pass()); 246 child_r->SetEventTargeter(original_targeter.Pass());
244 247
245 // Target |grandchild| location. 248 // Target |grandchild| location.
246 ui::MouseEvent second(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), 249 ui::MouseEvent second(ui::ET_MOUSE_MOVED, gfx::PointF(12.f, 12.f),
247 gfx::Point(12, 12), ui::EventTimeForNow(), ui::EF_NONE, 250 gfx::PointF(12.f, 12.f), ui::EventTimeForNow(),
248 ui::EF_NONE); 251 ui::EF_NONE, ui::EF_NONE);
249 EXPECT_EQ(grandchild_r, targeter->FindTargetForEvent(root_target, &second)); 252 EXPECT_EQ(grandchild_r, targeter->FindTargetForEvent(root_target, &second));
250 253
251 // Target |child| location. 254 // Target |child| location.
252 ui::MouseEvent third(ui::ET_MOUSE_MOVED, gfx::Point(8, 8), gfx::Point(8, 8), 255 ui::MouseEvent third(ui::ET_MOUSE_MOVED, gfx::PointF(8.f, 8.f),
253 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 256 gfx::PointF(8.f, 8.f), ui::EventTimeForNow(),
257 ui::EF_NONE, ui::EF_NONE);
254 EXPECT_EQ(child_r, targeter->FindTargetForEvent(root_target, &third)); 258 EXPECT_EQ(child_r, targeter->FindTargetForEvent(root_target, &third));
255 } 259 }
256 260
257 class IgnoreWindowTargeter : public WindowTargeter { 261 class IgnoreWindowTargeter : public WindowTargeter {
258 public: 262 public:
259 IgnoreWindowTargeter() {} 263 IgnoreWindowTargeter() {}
260 ~IgnoreWindowTargeter() override {} 264 ~IgnoreWindowTargeter() override {}
261 265
262 private: 266 private:
263 // WindowTargeter: 267 // WindowTargeter:
264 bool SubtreeShouldBeExploredForEvent(Window* window, 268 bool SubtreeShouldBeExploredForEvent(Window* window,
265 const ui::LocatedEvent& event) override { 269 const ui::LocatedEvent& event) override {
266 return false; 270 return false;
267 } 271 }
268 }; 272 };
269 273
270 // Verifies that an EventTargeter installed on an EventTarget can dictate 274 // Verifies that an EventTargeter installed on an EventTarget can dictate
271 // whether the target itself can process an event. 275 // whether the target itself can process an event.
272 TEST_F(WindowTargeterTest, TargeterChecksOwningEventTarget) { 276 TEST_F(WindowTargeterTest, TargeterChecksOwningEventTarget) {
273 test::TestWindowDelegate delegate; 277 test::TestWindowDelegate delegate;
274 scoped_ptr<Window> child(CreateNormalWindow(1, root_window(), &delegate)); 278 scoped_ptr<Window> child(CreateNormalWindow(1, root_window(), &delegate));
275 279
276 ui::EventTarget* root_target = root_window(); 280 ui::EventTarget* root_target = root_window();
277 ui::EventTargeter* targeter = root_target->GetEventTargeter(); 281 ui::EventTargeter* targeter = root_target->GetEventTargeter();
278 282
279 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 283 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f),
280 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, 284 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(),
281 ui::EF_NONE); 285 ui::EF_NONE, ui::EF_NONE);
282 EXPECT_EQ(child.get(), targeter->FindTargetForEvent(root_target, &mouse)); 286 EXPECT_EQ(child.get(), targeter->FindTargetForEvent(root_target, &mouse));
283 287
284 // Install an event targeter on |child| which always prevents the target from 288 // Install an event targeter on |child| which always prevents the target from
285 // receiving event. 289 // receiving event.
286 child->SetEventTargeter( 290 child->SetEventTargeter(
287 scoped_ptr<ui::EventTargeter>(new IgnoreWindowTargeter())); 291 scoped_ptr<ui::EventTargeter>(new IgnoreWindowTargeter()));
288 292
289 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 293 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f),
290 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, 294 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(),
291 ui::EF_NONE); 295 ui::EF_NONE, ui::EF_NONE);
292 EXPECT_EQ(root_window(), targeter->FindTargetForEvent(root_target, &mouse2)); 296 EXPECT_EQ(root_window(), targeter->FindTargetForEvent(root_target, &mouse2));
293 } 297 }
294 298
295 } // namespace aura 299 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698