diff options
author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 01:31:44 +0000 |
---|---|---|
committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 01:31:44 +0000 |
commit | dad7ad48393cb560438ec23b7242d8354fed62ec (patch) | |
tree | 8fdd75524363df0a9af92fc42422ce9214e6840e /ui/aura | |
parent | d0215d215ffdc9abd2678110758aac6c643f69fe (diff) | |
download | chromium_src-dad7ad48393cb560438ec23b7242d8354fed62ec.zip chromium_src-dad7ad48393cb560438ec23b7242d8354fed62ec.tar.gz chromium_src-dad7ad48393cb560438ec23b7242d8354fed62ec.tar.bz2 |
Aura: Add Window::MoveCursorTo() taking relative location to the window.
Previously, although RootWindow::MoveCursorTo() takes a ponit coordinate relative to Root, but OnMouseEvent/LockMouse in RWHVA are using coordinate relative to parent window (which may not be root). UnlockMouse is using global X/Y from webkit.
This CL added Window::MoveCursorTo() taking relative location to the window, and made RWHVA use it.
BUG=none
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/10543174
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/root_window.cc | 9 | ||||
-rw-r--r-- | ui/aura/root_window.h | 5 | ||||
-rw-r--r-- | ui/aura/window.cc | 8 | ||||
-rw-r--r-- | ui/aura/window.h | 3 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 106 |
5 files changed, 129 insertions, 2 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 864f735..b54c74f 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -224,7 +224,10 @@ void RootWindow::ShowCursor(bool show) { } void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) { - host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location_in_dip)); + gfx::Point location = location_in_dip; + layer()->transform().TransformPoint(location); + host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location)); + last_mouse_location_ = location_in_dip; } bool RootWindow::ConfineCursorToWindow() { @@ -658,6 +661,10 @@ void RootWindow::ReleaseNativeCapture() { host_->ReleaseCapture(); } +gfx::Point RootWindow::QueryMouseLocationForTest() const { + return host_->QueryMouseLocation(); +} + //////////////////////////////////////////////////////////////////////////////// // RootWindow, private: diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 4a9ac6a..f0722b5 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -129,7 +129,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, void ShowCursor(bool show); // Moves the cursor to the specified location relative to the root window. - void MoveCursorTo(const gfx::Point& location); + virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; // Clips the cursor movement to the root_window. bool ConfineCursorToWindow(); @@ -267,6 +267,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, virtual void SetNativeCapture() OVERRIDE; virtual void ReleaseNativeCapture() OVERRIDE; + // Exposes RootWindowHost::QueryMouseLocation() for test purposes. + gfx::Point QueryMouseLocationForTest() const; + private: friend class Window; friend class CompositorLock; diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 92a4025..6d6230c 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -408,6 +408,14 @@ void Window::ConvertPointToWindow(const Window* source, ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); } +void Window::MoveCursorTo(const gfx::Point& point_in_window) { + RootWindow* root_window = GetRootWindow(); + DCHECK(root_window); + gfx::Point point_in_root(point_in_window); + ConvertPointToWindow(this, root_window, &point_in_root); + root_window->MoveCursorTo(point_in_root); +} + gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; } diff --git a/ui/aura/window.h b/ui/aura/window.h index a516730..34a5702 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -213,6 +213,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate, const Window* target, gfx::Point* point); + // Moves the cursor to the specified location relative to the window. + virtual void MoveCursorTo(const gfx::Point& point_in_window); + // Returns the cursor for the specified point, in window coordinates. gfx::NativeCursor GetCursor(const gfx::Point& point) const; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index d46ddbf..cd6384e 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -16,6 +16,7 @@ #include "ui/aura/event.h" #include "ui/aura/layout_manager.h" #include "ui/aura/root_window.h" +#include "ui/aura/root_window_host.h" #include "ui/aura/root_window_observer.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/event_generator.h" @@ -323,6 +324,111 @@ TEST_F(WindowTest, ConvertPointToWindow) { EXPECT_EQ(reference_point, test_point); } +TEST_F(WindowTest, MoveCursorTo) { + scoped_ptr<Window> w1( + CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); + scoped_ptr<Window> w11( + CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); + scoped_ptr<Window> w111( + CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); + scoped_ptr<Window> w1111( + CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); + + RootWindow* root = root_window(); + root->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("10,10", root->last_mouse_location().ToString()); + w1->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("20,20", root->last_mouse_location().ToString()); + w11->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("25,25", root->last_mouse_location().ToString()); + w111->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("30,30", root->last_mouse_location().ToString()); + w1111->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("35,35", root->last_mouse_location().ToString()); +} + +// Test Window::ConvertPointToWindow() with transform to root_window. +TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { + RootWindow* root = root_window(); + ui::Transform transform; + transform.ConcatScale(2, 5); + transform.ConcatRotate(90.0f); + transform.ConcatTranslate(100, 100); + root->SetTransform(transform); + root->MoveCursorTo(gfx::Point(10, 10)); +#if !defined(OS_WIN) + // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD + EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); +#endif + EXPECT_EQ("10,10", root->last_mouse_location().ToString()); +} + +// Tests Window::ConvertPointToWindow() with transform to non-root windows. +TEST_F(WindowTest, MoveCursorToWithTransformWindow) { + scoped_ptr<Window> w1( + CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); + + RootWindow* root = root_window(); + ui::Transform transform1; + transform1.ConcatScale(2, 2); + w1->SetTransform(transform1); + w1->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("30,30", root->last_mouse_location().ToString()); + + ui::Transform transform2; + transform2.ConcatTranslate(-10, 20); + w1->SetTransform(transform2); + w1->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("10,40", root->last_mouse_location().ToString()); + + ui::Transform transform3; + transform3.ConcatRotate(90.0f); + w1->SetTransform(transform3); + w1->MoveCursorTo(gfx::Point(5, 5)); + EXPECT_EQ("5,15", root->last_mouse_location().ToString()); + + ui::Transform transform4; + transform4.ConcatScale(2, 5); + transform4.ConcatRotate(90.0f); + transform4.ConcatTranslate(100, 100); + w1->SetTransform(transform4); + w1->MoveCursorTo(gfx::Point(10, 10)); + EXPECT_EQ("60,130", root->last_mouse_location().ToString()); +} + +// Test Window::ConvertPointToWindow() with complex transforms to both root and +// non-root windows. +TEST_F(WindowTest, MoveCursorToWithComplexTransform) { + scoped_ptr<Window> w1( + CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); + scoped_ptr<Window> w11( + CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); + scoped_ptr<Window> w111( + CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); + scoped_ptr<Window> w1111( + CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); + + RootWindow* root = root_window(); + ui::Transform transform; + transform.ConcatScale(0.3f, 0.5f); + transform.ConcatRotate(10.0f); + transform.ConcatTranslate(10, 20); + + root->SetTransform(transform); + w1->SetTransform(transform); + w11->SetTransform(transform); + w111->SetTransform(transform); + w1111->SetTransform(transform); + + w1111->MoveCursorTo(gfx::Point(10, 10)); + +#if !defined(OS_WIN) + // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD + EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString()); +#endif + EXPECT_EQ("20,53", root->last_mouse_location().ToString()); +} + TEST_F(WindowTest, HitTest) { Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); w1.set_id(1); |