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

Side by Side Diff: ui/views/view_targeter_unittest.cc

Issue 365263004: Remove hit test mask methods from views::View (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-upload Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return true; 71 return true;
72 } 72 }
73 73
74 DISALLOW_COPY_AND_ASSIGN(TestMaskedView); 74 DISALLOW_COPY_AND_ASSIGN(TestMaskedView);
75 }; 75 };
76 76
77 namespace test { 77 namespace test {
78 78
79 typedef ViewsTestBase ViewTargeterTest; 79 typedef ViewsTestBase ViewTargeterTest;
80 80
81 namespace {
82
83 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
84 gfx::Point tmp(p);
85 View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp);
86 return tmp;
87 }
88
89 gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
90 gfx::Rect tmp(r);
91 tmp.set_origin(ConvertPointToView(view, r.origin()));
92 return tmp;
93 }
94
95 } // namespace
96
81 // Verifies that the the functions ViewTargeter::FindTargetForEvent() 97 // Verifies that the the functions ViewTargeter::FindTargetForEvent()
82 // and ViewTargeter::FindNextBestTarget() are implemented correctly 98 // and ViewTargeter::FindNextBestTarget() are implemented correctly
83 // for key events. 99 // for key events.
84 TEST_F(ViewTargeterTest, ViewTargeterForKeyEvents) { 100 TEST_F(ViewTargeterTest, ViewTargeterForKeyEvents) {
85 Widget widget; 101 Widget widget;
86 Widget::InitParams init_params = 102 Widget::InitParams init_params =
87 CreateParams(Widget::InitParams::TYPE_POPUP); 103 CreateParams(Widget::InitParams::TYPE_POPUP);
88 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 104 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
89 widget.Init(init_params); 105 widget.Init(init_params);
90 106
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 EXPECT_FALSE(v3.TestDoesIntersectRect(&v3, gfx::Rect(110, 110, 1, 1))); 397 EXPECT_FALSE(v3.TestDoesIntersectRect(&v3, gfx::Rect(110, 110, 1, 1)));
382 398
383 // Verify that hit-testing is performed correctly when using the 399 // Verify that hit-testing is performed correctly when using the
384 // call-through function ViewTargeter::DoesIntersectRect(). 400 // call-through function ViewTargeter::DoesIntersectRect().
385 EXPECT_TRUE(view_targeter->DoesIntersectRect(root_view, 401 EXPECT_TRUE(view_targeter->DoesIntersectRect(root_view,
386 gfx::Rect(0, 0, 50, 50))); 402 gfx::Rect(0, 0, 50, 50)));
387 EXPECT_FALSE(view_targeter->DoesIntersectRect(root_view, 403 EXPECT_FALSE(view_targeter->DoesIntersectRect(root_view,
388 gfx::Rect(-20, -20, 10, 10))); 404 gfx::Rect(-20, -20, 10, 10)));
389 } 405 }
390 406
407 // Tests that calls made directly on the hit-testing methods in View
408 // (HitTestPoint(), HitTestRect(), etc.) return the correct values.
409 TEST_F(ViewTargeterTest, HitTestCallsOnView) {
410 // The coordinates in this test are in the coordinate space of the root view.
411 Widget* widget = new Widget;
412 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
413 widget->Init(params);
414 View* root_view = widget->GetRootView();
415 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
416
417 // |v1| has no hit test mask. No ViewTargeter is installed on |v1|, which
418 // means that View::HitTestRect() will call into the targeter installed on
419 // the root view instead when we hit test against |v1|.
420 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
421 TestingView* v1 = new TestingView();
422 v1->SetBoundsRect(v1_bounds);
423 root_view->AddChildView(v1);
424
425 // |v2| has a triangular hit test mask. Install a ViewTargeter on |v2| which
426 // will be called into by View::HitTestRect().
427 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
428 TestMaskedView* v2 = new TestMaskedView();
429 v2->SetBoundsRect(v2_bounds);
430 root_view->AddChildView(v2);
431 ViewTargeter* view_targeter = new ViewTargeter(v2);
432 v2->SetEventTargeter(make_scoped_ptr(view_targeter));
433
434 gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
435 gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
436 gfx::Point v1_origin = v1_bounds.origin();
437 gfx::Point v2_origin = v2_bounds.origin();
438 gfx::Rect r1(10, 10, 110, 15);
439 gfx::Rect r2(106, 1, 98, 98);
440 gfx::Rect r3(0, 0, 300, 300);
441 gfx::Rect r4(115, 342, 200, 10);
442
443 // Test calls into View::HitTestPoint().
444 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint)));
445 EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint)));
446
447 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin)));
448 EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin)));
449
450 // Test calls into View::HitTestRect().
451 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1)));
452 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1)));
453
454 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2)));
455 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2)));
456
457 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3)));
458 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3)));
459
460 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4)));
461 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4)));
462
463 // Test calls into View::GetEventHandlerForPoint().
464 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint));
465 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
466
467 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
468 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
469
470 // Test calls into View::GetTooltipHandlerForPoint().
471 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_centerpoint));
472 EXPECT_EQ(v2, root_view->GetTooltipHandlerForPoint(v2_centerpoint));
473
474 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin));
475 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin));
476
477 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin));
478
479 widget->CloseNow();
480 }
481
391 } // namespace test 482 } // namespace test
392 } // namespace views 483 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698