OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/view_targeter.h" | 5 #include "ui/views/view_targeter.h" |
6 | 6 |
7 #include "ui/events/event_targeter.h" | 7 #include "ui/events/event_targeter.h" |
8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
9 #include "ui/gfx/path.h" | 9 #include "ui/gfx/path.h" |
10 #include "ui/views/masked_targeter_delegate.h" | 10 #include "ui/views/masked_targeter_delegate.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 224 } |
225 | 225 |
226 // Convenience to make constructing a GestureEvent simpler. | 226 // Convenience to make constructing a GestureEvent simpler. |
227 class GestureEventForTest : public ui::GestureEvent { | 227 class GestureEventForTest : public ui::GestureEvent { |
228 public: | 228 public: |
229 GestureEventForTest(ui::EventType type, int x, int y) | 229 GestureEventForTest(ui::EventType type, int x, int y) |
230 : GestureEvent(x, | 230 : GestureEvent(x, |
231 y, | 231 y, |
232 0, | 232 0, |
233 base::TimeDelta(), | 233 base::TimeDelta(), |
234 ui::GestureEventDetails(type)) {} | 234 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} |
235 | 235 |
236 GestureEventForTest(ui::GestureEventDetails details, int x, int y) | 236 GestureEventForTest(ui::GestureEventDetails details, int x, int y) |
237 : GestureEvent(x, y, 0, base::TimeDelta(), details) {} | 237 : GestureEvent(x, y, 0, base::TimeDelta(), details) {} |
238 }; | 238 }; |
239 | 239 |
240 // Verifies that the the functions ViewTargeter::FindTargetForEvent() | 240 // Verifies that the the functions ViewTargeter::FindTargetForEvent() |
241 // and ViewTargeter::FindNextBestTarget() are implemented correctly | 241 // and ViewTargeter::FindNextBestTarget() are implemented correctly |
242 // for gesture events. | 242 // for gesture events. |
243 TEST_F(ViewTargeterTest, ViewTargeterForGestureEvents) { | 243 TEST_F(ViewTargeterTest, ViewTargeterForGestureEvents) { |
244 Widget widget; | 244 Widget widget; |
(...skipping 14 matching lines...) Expand all Loading... |
259 content->AddChildView(child); | 259 content->AddChildView(child); |
260 child->AddChildView(grandchild); | 260 child->AddChildView(grandchild); |
261 | 261 |
262 internal::RootView* root_view = | 262 internal::RootView* root_view = |
263 static_cast<internal::RootView*>(widget.GetRootView()); | 263 static_cast<internal::RootView*>(widget.GetRootView()); |
264 ui::EventTargeter* targeter = root_view->targeter(); | 264 ui::EventTargeter* targeter = root_view->targeter(); |
265 | 265 |
266 // Define some gesture events for testing. | 266 // Define some gesture events for testing. |
267 gfx::Rect bounding_box(gfx::Point(46, 46), gfx::Size(8, 8)); | 267 gfx::Rect bounding_box(gfx::Point(46, 46), gfx::Size(8, 8)); |
268 gfx::Point center_point(bounding_box.CenterPoint()); | 268 gfx::Point center_point(bounding_box.CenterPoint()); |
269 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); | 269 ui::GestureEventDetails details(ui::ET_GESTURE_TAP, 0.0f, 0.0f); |
270 details.set_bounding_box(bounding_box); | 270 details.set_bounding_box(bounding_box); |
271 GestureEventForTest tap(details, center_point.x(), center_point.y()); | 271 GestureEventForTest tap(details, center_point.x(), center_point.y()); |
272 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN); | 272 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0.0f, 0.0f); |
273 details.set_bounding_box(bounding_box); | 273 details.set_bounding_box(bounding_box); |
274 GestureEventForTest scroll_begin(details, center_point.x(), center_point.y()); | 274 GestureEventForTest scroll_begin(details, center_point.x(), center_point.y()); |
275 details = ui::GestureEventDetails(ui::ET_GESTURE_END); | 275 details = ui::GestureEventDetails(ui::ET_GESTURE_END, 0.0f, 0.0f); |
276 details.set_bounding_box(bounding_box); | 276 details.set_bounding_box(bounding_box); |
277 GestureEventForTest end(details, center_point.x(), center_point.y()); | 277 GestureEventForTest end(details, center_point.x(), center_point.y()); |
278 | 278 |
279 // Assume that the view currently handling gestures has been set as | 279 // Assume that the view currently handling gestures has been set as |
280 // |grandchild| by a previous gesture event. Thus subsequent TAP and | 280 // |grandchild| by a previous gesture event. Thus subsequent TAP and |
281 // SCROLL_BEGIN events should be initially targeted to |grandchild|, and | 281 // SCROLL_BEGIN events should be initially targeted to |grandchild|, and |
282 // re-targeting should be prohibited for TAP but permitted for | 282 // re-targeting should be prohibited for TAP but permitted for |
283 // GESTURE_SCROLL_BEGIN (which should be re-targeted to the parent of | 283 // GESTURE_SCROLL_BEGIN (which should be re-targeted to the parent of |
284 // |grandchild|). | 284 // |grandchild|). |
285 SetGestureHandlerSetBeforeProcessing(root_view, true); | 285 SetGestureHandlerSetBeforeProcessing(root_view, true); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 EXPECT_EQ(NULL, targeter->FindNextBestTarget(child, &tap)); | 317 EXPECT_EQ(NULL, targeter->FindNextBestTarget(child, &tap)); |
318 EXPECT_EQ(NULL, targeter->FindNextBestTarget(NULL, &tap)); | 318 EXPECT_EQ(NULL, targeter->FindNextBestTarget(NULL, &tap)); |
319 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &scroll_begin)); | 319 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &scroll_begin)); |
320 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &end)); | 320 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &end)); |
321 | 321 |
322 // Reset the locations of the gesture events to be in the root view | 322 // Reset the locations of the gesture events to be in the root view |
323 // coordinate space since we are about to call FindTargetForEvent() | 323 // coordinate space since we are about to call FindTargetForEvent() |
324 // again (calls to FindTargetForEvent() and FindNextBestTarget() | 324 // again (calls to FindTargetForEvent() and FindNextBestTarget() |
325 // mutate the location of the gesture events to be in the coordinate | 325 // mutate the location of the gesture events to be in the coordinate |
326 // space of the returned view). | 326 // space of the returned view). |
327 details = ui::GestureEventDetails(ui::ET_GESTURE_TAP); | 327 details = ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0.0f, 0.0f); |
328 details.set_bounding_box(bounding_box); | 328 details.set_bounding_box(bounding_box); |
329 tap = GestureEventForTest(details, center_point.x(), center_point.y()); | 329 tap = GestureEventForTest(details, center_point.x(), center_point.y()); |
330 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN); | 330 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0.0f, 0.0f); |
331 details.set_bounding_box(bounding_box); | 331 details.set_bounding_box(bounding_box); |
332 scroll_begin = | 332 scroll_begin = |
333 GestureEventForTest(details, center_point.x(), center_point.y()); | 333 GestureEventForTest(details, center_point.x(), center_point.y()); |
334 details = ui::GestureEventDetails(ui::ET_GESTURE_END); | 334 details = ui::GestureEventDetails(ui::ET_GESTURE_END, 0.0f, 0.0f); |
335 details.set_bounding_box(bounding_box); | 335 details.set_bounding_box(bounding_box); |
336 end = GestureEventForTest(details, center_point.x(), center_point.y()); | 336 end = GestureEventForTest(details, center_point.x(), center_point.y()); |
337 | 337 |
338 // If no default gesture handler is currently set, targeting should be | 338 // If no default gesture handler is currently set, targeting should be |
339 // performed using the location of the gesture event for a TAP and a | 339 // performed using the location of the gesture event for a TAP and a |
340 // SCROLL_BEGIN. | 340 // SCROLL_BEGIN. |
341 SetGestureHandlerSetBeforeProcessing(root_view, false); | 341 SetGestureHandlerSetBeforeProcessing(root_view, false); |
342 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap)); | 342 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap)); |
343 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin)); | 343 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin)); |
344 | 344 |
(...skipping 29 matching lines...) Expand all Loading... |
374 grandchild->AddChildView(great_grandchild); | 374 grandchild->AddChildView(great_grandchild); |
375 | 375 |
376 internal::RootView* root_view = | 376 internal::RootView* root_view = |
377 static_cast<internal::RootView*>(widget.GetRootView()); | 377 static_cast<internal::RootView*>(widget.GetRootView()); |
378 ui::EventTargeter* targeter = root_view->targeter(); | 378 ui::EventTargeter* targeter = root_view->targeter(); |
379 | 379 |
380 // Define a GESTURE_TAP event with a bounding box centered at (60, 60) | 380 // Define a GESTURE_TAP event with a bounding box centered at (60, 60) |
381 // in root view coordinates with width and height of 4. | 381 // in root view coordinates with width and height of 4. |
382 gfx::Rect bounding_box(gfx::Point(58, 58), gfx::Size(4, 4)); | 382 gfx::Rect bounding_box(gfx::Point(58, 58), gfx::Size(4, 4)); |
383 gfx::Point center_point(bounding_box.CenterPoint()); | 383 gfx::Point center_point(bounding_box.CenterPoint()); |
384 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); | 384 ui::GestureEventDetails details(ui::ET_GESTURE_TAP, 0.0f, 0.0f); |
385 details.set_bounding_box(bounding_box); | 385 details.set_bounding_box(bounding_box); |
386 GestureEventForTest tap(details, center_point.x(), center_point.y()); | 386 GestureEventForTest tap(details, center_point.x(), center_point.y()); |
387 | 387 |
388 // Calculate the location of the gesture in each of the different | 388 // Calculate the location of the gesture in each of the different |
389 // coordinate spaces. | 389 // coordinate spaces. |
390 gfx::Point location_in_root(center_point); | 390 gfx::Point location_in_root(center_point); |
391 EXPECT_EQ(gfx::Point(60, 60), location_in_root); | 391 EXPECT_EQ(gfx::Point(60, 60), location_in_root); |
392 gfx::Point location_in_great_grandchild( | 392 gfx::Point location_in_great_grandchild( |
393 ConvertPointFromWidgetToView(great_grandchild, location_in_root)); | 393 ConvertPointFromWidgetToView(great_grandchild, location_in_root)); |
394 EXPECT_EQ(gfx::Point(2, 2), location_in_great_grandchild); | 394 EXPECT_EQ(gfx::Point(2, 2), location_in_great_grandchild); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); | 571 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); |
572 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); | 572 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); |
573 | 573 |
574 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); | 574 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); |
575 | 575 |
576 widget->CloseNow(); | 576 widget->CloseNow(); |
577 } | 577 } |
578 | 578 |
579 } // namespace test | 579 } // namespace test |
580 } // namespace views | 580 } // namespace views |
OLD | NEW |