| 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 "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "ui/events/event_targeter.h" | 9 #include "ui/events/event_targeter.h" |
| 10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| 11 #include "ui/gfx/path.h" | 11 #include "ui/gfx/path.h" |
| 12 #include "ui/views/masked_targeter_delegate.h" | 12 #include "ui/views/masked_targeter_delegate.h" |
| 13 #include "ui/views/test/views_test_base.h" | 13 #include "ui/views/test/views_test_base.h" |
| 14 #include "ui/views/view_targeter.h" | 14 #include "ui/views/view_targeter.h" |
| 15 #include "ui/views/view_targeter_delegate.h" | 15 #include "ui/views/view_targeter_delegate.h" |
| 16 #include "ui/views/views_switches.h" | |
| 17 #include "ui/views/widget/root_view.h" | 16 #include "ui/views/widget/root_view.h" |
| 18 | 17 |
| 19 namespace views { | 18 namespace views { |
| 20 | 19 |
| 21 // A derived class of View used for testing purposes. | 20 // A derived class of View used for testing purposes. |
| 22 class TestingView : public View, public ViewTargeterDelegate { | 21 class TestingView : public View, public ViewTargeterDelegate { |
| 23 public: | 22 public: |
| 24 TestingView() : can_process_events_within_subtree_(true) {} | 23 TestingView() : can_process_events_within_subtree_(true) {} |
| 25 ~TestingView() override {} | 24 ~TestingView() override {} |
| 26 | 25 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 391 |
| 393 EXPECT_EQ(content, targeter->FindTargetForEvent(root_view, &tap)); | 392 EXPECT_EQ(content, targeter->FindTargetForEvent(root_view, &tap)); |
| 394 | 393 |
| 395 // A gesture event with its center not located within the contents | 394 // A gesture event with its center not located within the contents |
| 396 // view but that overlaps the contents view by at least 60% should | 395 // view but that overlaps the contents view by at least 60% should |
| 397 // target the contents view. | 396 // target the contents view. |
| 398 bounding_box = gfx::RectF(gfx::PointF(50.f, 0.f), gfx::SizeF(400.f, 200.f)); | 397 bounding_box = gfx::RectF(gfx::PointF(50.f, 0.f), gfx::SizeF(400.f, 200.f)); |
| 399 details.set_bounding_box(bounding_box); | 398 details.set_bounding_box(bounding_box); |
| 400 tap = GestureEventForTest(details); | 399 tap = GestureEventForTest(details); |
| 401 | 400 |
| 402 // This only applies if rect-based targeting is enabled. | 401 EXPECT_EQ(content, targeter->FindTargetForEvent(root_view, &tap)); |
| 403 if (views::switches::IsRectBasedTargetingEnabled()) { | |
| 404 EXPECT_EQ(content, targeter->FindTargetForEvent(root_view, &tap)); | |
| 405 } else { | |
| 406 EXPECT_EQ(widget.GetRootView(), | |
| 407 targeter->FindTargetForEvent(root_view, &tap)); | |
| 408 } | |
| 409 | 402 |
| 410 // A gesture event not overlapping the contents view by at least | 403 // A gesture event not overlapping the contents view by at least |
| 411 // 60% and not having its center within the contents view should | 404 // 60% and not having its center within the contents view should |
| 412 // be targeted to the root view. | 405 // be targeted to the root view. |
| 413 bounding_box = gfx::RectF(gfx::PointF(196.f, 100.f), gfx::SizeF(8.f, 8.f)); | 406 bounding_box = gfx::RectF(gfx::PointF(196.f, 100.f), gfx::SizeF(8.f, 8.f)); |
| 414 details.set_bounding_box(bounding_box); | 407 details.set_bounding_box(bounding_box); |
| 415 tap = GestureEventForTest(details); | 408 tap = GestureEventForTest(details); |
| 416 | 409 |
| 417 EXPECT_EQ(widget.GetRootView(), | 410 EXPECT_EQ(widget.GetRootView(), |
| 418 targeter->FindTargetForEvent(root_view, &tap)); | 411 targeter->FindTargetForEvent(root_view, &tap)); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); | 659 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); |
| 667 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); | 660 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); |
| 668 | 661 |
| 669 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); | 662 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); |
| 670 | 663 |
| 671 widget->CloseNow(); | 664 widget->CloseNow(); |
| 672 } | 665 } |
| 673 | 666 |
| 674 } // namespace test | 667 } // namespace test |
| 675 } // namespace views | 668 } // namespace views |
| OLD | NEW |