Remove hit test mask methods from views::View

The definitions of hit test masks and related logic
have beed moved into MaskedTargeterDelegate, so
remove HasHitTestMask(), GetHitTestMaskDeprecated(),
and the HitTestSource enum from views::View.

BUG=388838
TEST=ViewTargeterTest.HitTestCallsOnView

Review URL: https://codereview.chromium.org/365263004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282779 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d37e5c3
...@@ -954,29 +954,7 @@ bool View::HitTestRect(const gfx::Rect& rect) const { ...@@ -954,29 +954,7 @@ bool View::HitTestRect(const gfx::Rect& rect) const {
if (!view_targeter) if (!view_targeter)
view_targeter = GetWidget()->GetRootView()->targeter(); view_targeter = GetWidget()->GetRootView()->targeter();
CHECK(view_targeter); CHECK(view_targeter);
return view_targeter->DoesIntersectRect(this, rect);
// TODO(tdanderson): The check for !HasHitTestMask() is temporary. Remove
// the check along with the duplicated code below once all
// of the masked views subclass MaskedViewDelegate.
// HasHitTestMask() and GetHitTestMaskDeprecated() can also
// be removed from the View interface at that time.
if (!HasHitTestMask())
return view_targeter->DoesIntersectRect(this, rect);
if (GetLocalBounds().Intersects(rect)) {
gfx::Path mask;
HitTestSource source = HIT_TEST_SOURCE_MOUSE;
if (!views::UsePointBasedTargeting(rect))
source = HIT_TEST_SOURCE_TOUCH;
GetHitTestMaskDeprecated(source, &mask);
SkRegion clip_region;
clip_region.setRect(0, 0, width(), height());
SkRegion mask_region;
return mask_region.setPath(mask, clip_region) &&
mask_region.intersects(RectToSkIRect(rect));
}
// Outside our bounds.
return false;
} }
bool View::IsMouseHovered() { bool View::IsMouseHovered() {
...@@ -1592,15 +1570,6 @@ void View::ReorderChildLayers(ui::Layer* parent_layer) { ...@@ -1592,15 +1570,6 @@ void View::ReorderChildLayers(ui::Layer* parent_layer) {
// Input ----------------------------------------------------------------------- // Input -----------------------------------------------------------------------
bool View::HasHitTestMask() const {
return false;
}
void View::GetHitTestMaskDeprecated(HitTestSource source,
gfx::Path* mask) const {
DCHECK(mask);
}
View::DragInfo* View::GetDragInfo() { View::DragInfo* View::GetDragInfo() {
return parent_ ? parent_->GetDragInfo() : NULL; return parent_ ? parent_->GetDragInfo() : NULL;
} }
......
...@@ -110,19 +110,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -110,19 +110,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
public: public:
typedef std::vector<View*> Views; typedef std::vector<View*> Views;
// TODO(tdanderson): Becomes obsolete with the refactoring of the event
// targeting logic for views and windows. See
// crbug.com/355425.
// Specifies the source of the region used in a hit test.
// HIT_TEST_SOURCE_MOUSE indicates the hit test is being performed with a
// single point and HIT_TEST_SOURCE_TOUCH indicates the hit test is being
// performed with a rect larger than a single point. This value can be used,
// for example, to add extra padding or change the shape of the hit test mask.
enum HitTestSource {
HIT_TEST_SOURCE_MOUSE,
HIT_TEST_SOURCE_TOUCH
};
struct ViewHierarchyChangedDetails { struct ViewHierarchyChangedDetails {
ViewHierarchyChangedDetails() ViewHierarchyChangedDetails()
: is_add(false), : is_add(false),
...@@ -1146,20 +1133,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -1146,20 +1133,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Input --------------------------------------------------------------------- // Input ---------------------------------------------------------------------
// Called by HitTestRect() to see if this View has a custom hit test mask. If
// the return value is true, GetHitTestMask() will be called to obtain the
// mask. Default value is false, in which case the View will hit-test against
// its bounds.
virtual bool HasHitTestMask() const;
// Called by HitTestRect() to retrieve a mask for hit-testing against.
// Subclasses override to provide custom shaped hit test regions.
// TODO(tdanderson): Remove this method once Tab, TabCloseButton,
// NewTabButton, and MicButton all implement
// MaskedViewTargeter.
virtual void GetHitTestMaskDeprecated(HitTestSource source,
gfx::Path* mask) const;
virtual DragInfo* GetDragInfo(); virtual DragInfo* GetDragInfo();
// Focus --------------------------------------------------------------------- // Focus ---------------------------------------------------------------------
......
...@@ -78,6 +78,22 @@ namespace test { ...@@ -78,6 +78,22 @@ namespace test {
typedef ViewsTestBase ViewTargeterTest; typedef ViewsTestBase ViewTargeterTest;
namespace {
gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
gfx::Point tmp(p);
View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp);
return tmp;
}
gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
gfx::Rect tmp(r);
tmp.set_origin(ConvertPointToView(view, r.origin()));
return tmp;
}
} // namespace
// Verifies that the the functions ViewTargeter::FindTargetForEvent() // Verifies that the the functions ViewTargeter::FindTargetForEvent()
// and ViewTargeter::FindNextBestTarget() are implemented correctly // and ViewTargeter::FindNextBestTarget() are implemented correctly
// for key events. // for key events.
...@@ -388,5 +404,80 @@ TEST_F(ViewTargeterTest, DoesIntersectRect) { ...@@ -388,5 +404,80 @@ TEST_F(ViewTargeterTest, DoesIntersectRect) {
gfx::Rect(-20, -20, 10, 10))); gfx::Rect(-20, -20, 10, 10)));
} }
// Tests that calls made directly on the hit-testing methods in View
// (HitTestPoint(), HitTestRect(), etc.) return the correct values.
TEST_F(ViewTargeterTest, HitTestCallsOnView) {
// The coordinates in this test are in the coordinate space of the root view.
Widget* widget = new Widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
widget->Init(params);
View* root_view = widget->GetRootView();
root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
// |v1| has no hit test mask. No ViewTargeter is installed on |v1|, which
// means that View::HitTestRect() will call into the targeter installed on
// the root view instead when we hit test against |v1|.
gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
TestingView* v1 = new TestingView();
v1->SetBoundsRect(v1_bounds);
root_view->AddChildView(v1);
// |v2| has a triangular hit test mask. Install a ViewTargeter on |v2| which
// will be called into by View::HitTestRect().
gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
TestMaskedView* v2 = new TestMaskedView();
v2->SetBoundsRect(v2_bounds);
root_view->AddChildView(v2);
ViewTargeter* view_targeter = new ViewTargeter(v2);
v2->SetEventTargeter(make_scoped_ptr(view_targeter));
gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
gfx::Point v1_origin = v1_bounds.origin();
gfx::Point v2_origin = v2_bounds.origin();
gfx::Rect r1(10, 10, 110, 15);
gfx::Rect r2(106, 1, 98, 98);
gfx::Rect r3(0, 0, 300, 300);
gfx::Rect r4(115, 342, 200, 10);
// Test calls into View::HitTestPoint().
EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint)));
EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint)));
EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin)));
EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin)));
// Test calls into View::HitTestRect().
EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1)));
EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1)));
EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2)));
EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2)));
EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3)));
EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3)));
EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4)));
EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4)));
// Test calls into View::GetEventHandlerForPoint().
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint));
EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
// Test calls into View::GetTooltipHandlerForPoint().
EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_centerpoint));
EXPECT_EQ(v2, root_view->GetTooltipHandlerForPoint(v2_centerpoint));
EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin));
EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin));
EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin));
widget->CloseNow();
}
} // namespace test } // namespace test
} // namespace views } // namespace views
...@@ -785,50 +785,6 @@ TEST_F(ViewTest, RemoveNotification) { ...@@ -785,50 +785,6 @@ TEST_F(ViewTest, RemoveNotification) {
} }
namespace { namespace {
class HitTestView : public View {
public:
explicit HitTestView(bool has_hittest_mask)
: has_hittest_mask_(has_hittest_mask) {
}
virtual ~HitTestView() {}
protected:
// Overridden from View:
virtual bool HasHitTestMask() const OVERRIDE {
return has_hittest_mask_;
}
virtual void GetHitTestMaskDeprecated(HitTestSource source,
gfx::Path* mask) const OVERRIDE {
DCHECK(has_hittest_mask_);
DCHECK(mask);
SkScalar w = SkIntToScalar(width());
SkScalar h = SkIntToScalar(height());
// Create a triangular mask within the bounds of this View.
mask->moveTo(w / 2, 0);
mask->lineTo(w, h);
mask->lineTo(0, h);
mask->close();
}
private:
bool has_hittest_mask_;
DISALLOW_COPY_AND_ASSIGN(HitTestView);
};
gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
gfx::Point tmp(p);
View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp);
return tmp;
}
gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
gfx::Rect tmp(r);
tmp.set_origin(ConvertPointToView(view, r.origin()));
return tmp;
}
void RotateCounterclockwise(gfx::Transform* transform) { void RotateCounterclockwise(gfx::Transform* transform) {
transform->matrix().set3x3(0, -1, 0, transform->matrix().set3x3(0, -1, 0,
...@@ -844,72 +800,6 @@ void RotateClockwise(gfx::Transform* transform) { ...@@ -844,72 +800,6 @@ void RotateClockwise(gfx::Transform* transform) {
} // namespace } // namespace
TEST_F(ViewTest, HitTestMasks) {
Widget* widget = new Widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
widget->Init(params);
View* root_view = widget->GetRootView();
root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
HitTestView* v1 = new HitTestView(false);
v1->SetBoundsRect(v1_bounds);
root_view->AddChildView(v1);
gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
HitTestView* v2 = new HitTestView(true);
v2->SetBoundsRect(v2_bounds);
root_view->AddChildView(v2);
gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
gfx::Point v1_origin = v1_bounds.origin();
gfx::Point v2_origin = v2_bounds.origin();
gfx::Rect r1(10, 10, 110, 15);
gfx::Rect r2(106, 1, 98, 98);
gfx::Rect r3(0, 0, 300, 300);
gfx::Rect r4(115, 342, 200, 10);
// Test HitTestPoint
EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint)));
EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint)));
EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin)));
EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin)));
// Test HitTestRect
EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1)));
EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1)));
EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2)));
EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2)));
EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3)));
EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3)));
EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4)));
EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4)));
// Test GetEventHandlerForPoint
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint));
EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
// Test GetTooltipHandlerForPoint
EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_centerpoint));
EXPECT_EQ(v2, root_view->GetTooltipHandlerForPoint(v2_centerpoint));
EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin));
EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin));
EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin));
widget->CloseNow();
}
// Tests the correctness of the rect-based targeting algorithm implemented in // Tests the correctness of the rect-based targeting algorithm implemented in
// View::GetEventHandlerForRect(). See http://goo.gl/3Jp2BD for a description // View::GetEventHandlerForRect(). See http://goo.gl/3Jp2BD for a description
// of rect-based targeting. // of rect-based targeting.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment