Commit 6caf4f5d authored by yusukes@google.com's avatar yusukes@google.com

Fix aura::Window::ContainsPointInRoot().

Currently, the function tries to compare a point in the window's coordinates and a rect in the root window's coordinates.

BUG=None
TEST=added a unit test (WindowTest.ContainsPointInRoot) which fails on tot and passes with this CL; ./out/Debug/aura_unittests --gtest_filter='*WindowTest.ContainsPoint*'

Review URL: https://chromiumcodereview.appspot.com/10806055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147930 0039d316-1c4b-4281-b951-d872f2087c98
parent deb31207
...@@ -485,12 +485,11 @@ bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) { ...@@ -485,12 +485,11 @@ bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) {
return false; return false;
gfx::Point local_point(point_in_root); gfx::Point local_point(point_in_root);
ConvertPointToWindow(root_window, this, &local_point); ConvertPointToWindow(root_window, this, &local_point);
return GetTargetBounds().Contains(local_point); return gfx::Rect(GetTargetBounds().size()).Contains(local_point);
} }
bool Window::ContainsPoint(const gfx::Point& local_point) { bool Window::ContainsPoint(const gfx::Point& local_point) {
gfx::Rect local_bounds(gfx::Point(), bounds().size()); return gfx::Rect(bounds().size()).Contains(local_point);
return local_bounds.Contains(local_point);
} }
bool Window::HitTest(const gfx::Point& local_point) { bool Window::HitTest(const gfx::Point& local_point) {
......
...@@ -268,6 +268,25 @@ TEST_F(WindowTest, Contains) { ...@@ -268,6 +268,25 @@ TEST_F(WindowTest, Contains) {
EXPECT_FALSE(child2.Contains(&child1)); EXPECT_FALSE(child2.Contains(&child1));
} }
TEST_F(WindowTest, ContainsPointInRoot) {
scoped_ptr<Window> w(
CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL));
EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9)));
EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10)));
EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14)));
EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15)));
EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20)));
}
TEST_F(WindowTest, ContainsPoint) {
scoped_ptr<Window> w(
CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL));
EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0)));
EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4)));
EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5)));
EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10)));
}
TEST_F(WindowTest, ConvertPointToWindow) { TEST_F(WindowTest, ConvertPointToWindow) {
// Window::ConvertPointToWindow is mostly identical to // Window::ConvertPointToWindow is mostly identical to
// Layer::ConvertPointToLayer, except NULL values for |source| are permitted, // Layer::ConvertPointToLayer, except NULL values for |source| are permitted,
......
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