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 | |
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
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.cc | 10 | ||||
-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 |
6 files changed, 134 insertions, 7 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 4150ba5..99c396a 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -715,7 +715,7 @@ bool RenderWidgetHostViewAura::LockMouse() { window_->SetCapture(); aura::Env::GetInstance()->cursor_manager()->ShowCursor(false); synthetic_move_sent_ = true; - root_window->MoveCursorTo(window_->bounds().CenterPoint()); + window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); if (aura::client::GetTooltipClient(root_window)) aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(false); return true; @@ -729,7 +729,7 @@ void RenderWidgetHostViewAura::UnlockMouse() { mouse_locked_ = false; window_->ReleaseCapture(); - root_window->MoveCursorTo(unlocked_global_mouse_position_); + window_->MoveCursorTo(unlocked_mouse_position_); aura::Env::GetInstance()->cursor_manager()->ShowCursor(true); if (aura::client::GetTooltipClient(root_window)) aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(true); @@ -1013,11 +1013,11 @@ bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnMouseEvent"); if (mouse_locked_) { WebKit::WebMouseEvent mouse_event = content::MakeWebMouseEvent(event); - gfx::Point center = window_->bounds().CenterPoint(); + gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || event->type() == ui::ET_MOUSE_DRAGGED) && - mouse_event.globalX == center.x() && mouse_event.globalY == center.y(); + mouse_event.x == center.x() && mouse_event.y == center.y(); ModifyEventMovementAndCoords(&mouse_event); @@ -1028,7 +1028,7 @@ bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { // Check if the mouse has reached the border and needs to be centered. if (ShouldMoveToCenter()) { synthetic_move_sent_ = true; - window_->GetRootWindow()->MoveCursorTo(center); + window_->MoveCursorTo(center); } // Forward event to renderer. 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); |