diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-16 16:14:58 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-16 16:14:58 +0000 |
commit | 4ee40ff3a33075d6a2bf91e97097abecef12893f (patch) | |
tree | 82f689f418b199511892a4e9f0235f3ea1362708 /ui | |
parent | ac7f5a0bf83bc30c7866a1473723a57cc8f770c8 (diff) | |
download | chromium_src-4ee40ff3a33075d6a2bf91e97097abecef12893f.zip chromium_src-4ee40ff3a33075d6a2bf91e97097abecef12893f.tar.gz chromium_src-4ee40ff3a33075d6a2bf91e97097abecef12893f.tar.bz2 |
Translate points correctly with root window's transform
- Renamed ConvertNativePointToScreen to ConvertHostPointToScreen to be more clear
- Apply root window's transform correctly in
RootWindow::ConvertPointTo/FromScreen
- Fix tests.
BUG=179997, 119268
TEST=covered by test. On device, you can drag window between displays with rotation/ui scale applied.
Review URL: https://chromiumcodereview.appspot.com/12842007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/client/screen_position_client.h | 8 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 45 | ||||
-rw-r--r-- | ui/aura/root_window.h | 10 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 20 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_screen_position_client.cc | 4 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_screen_position_client.h | 4 |
6 files changed, 57 insertions, 34 deletions
diff --git a/ui/aura/client/screen_position_client.h b/ui/aura/client/screen_position_client.h index 28a8603..e5505eb 100644 --- a/ui/aura/client/screen_position_client.h +++ b/ui/aura/client/screen_position_client.h @@ -31,13 +31,13 @@ class AURA_EXPORT ScreenPositionClient { gfx::Point* point) = 0; virtual void ConvertPointFromScreen(const Window* window, gfx::Point* point) = 0; - // Converts the |screen_point| from a given |window|'s native screen - // coordinate space into screen coordinate space. + // Converts the |screen_point| from root window host's coordinate of + // into screen coordinate space. // A typical example of using this function instead of ConvertPointToScreen is // when X's native input is captured by a drag operation. // See the comments for ash::GetRootWindowRelativeToWindow for details. - virtual void ConvertNativePointToScreen(Window* window, - gfx::Point* point) = 0; + virtual void ConvertHostPointToScreen(aura::RootWindow* root_window, + gfx::Point* point) = 0; // Sets the bounds of the window. The implementation is responsible // for finding out and translating the right coordinates for the |window|. virtual void SetBounds(Window* window, diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 8ecb365..d66ad30 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -264,9 +264,9 @@ void RootWindow::OnMouseEventsEnableStateChanged(bool enabled) { } void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) { - gfx::Point location = location_in_dip; - layer()->transform().TransformPoint(location); - host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location)); + gfx::Point3F point_3f(location_in_dip); + GetRootTransform().TransformPoint(point_3f); + host_->MoveCursorTo(gfx::ToRoundedPoint(point_3f.AsPointF())); SetLastMouseLocation(this, location_in_dip); client::CursorClient* cursor_client = client::GetCursorClient(this); if (cursor_client) { @@ -384,9 +384,7 @@ void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { } void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const { - // TODO(oshima): Take the root window's transform into account. - *point = gfx::ToFlooredPoint( - gfx::ScalePoint(*point, ui::GetDeviceScaleFactor(layer()))); + ConvertPointToHost(point); gfx::Point location = host_->GetLocationOnNativeScreen(); point->Offset(location.x(), location.y()); } @@ -394,8 +392,19 @@ void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const { void RootWindow::ConvertPointFromNativeScreen(gfx::Point* point) const { gfx::Point location = host_->GetLocationOnNativeScreen(); point->Offset(-location.x(), -location.y()); - *point = gfx::ToFlooredPoint( - gfx::ScalePoint(*point, 1 / ui::GetDeviceScaleFactor(layer()))); + ConvertPointFromHost(point); +} + +void RootWindow::ConvertPointToHost(gfx::Point* point) const { + gfx::Point3F point_3f(*point); + GetRootTransform().TransformPoint(point_3f); + *point = gfx::ToRoundedPoint(point_3f.AsPointF()); +} + +void RootWindow::ConvertPointFromHost(gfx::Point* point) const { + gfx::Point3F point_3f(*point); + GetRootTransform().TransformPointReverse(point_3f); + *point = gfx::ToRoundedPoint(point_3f.AsPointF()); } void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event, @@ -661,11 +670,7 @@ void RootWindow::ClearMouseHandlers() { // RootWindow, private: void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) { - float scale = ui::GetDeviceScaleFactor(layer()); - gfx::Transform transform; - transform.Scale(scale, scale); - transform *= layer()->transform(); - event->UpdateForRootTransform(transform); + event->UpdateForRootTransform(GetRootTransform()); } void RootWindow::HandleMouseMoved(const ui::MouseEvent& event, Window* target) { @@ -1131,11 +1136,7 @@ void RootWindow::SynthesizeMouseMoveEvent() { return; synthesize_mouse_move_ = false; gfx::Point3F point(GetLastMouseLocationInRoot()); - float scale = ui::GetDeviceScaleFactor(layer()); - gfx::Transform transform; - transform.Scale(scale, scale); - transform *= layer()->transform(); - transform.TransformPoint(point); + GetRootTransform().TransformPoint(point); gfx::Point orig_mouse_location = gfx::ToFlooredPoint(point.AsPointF()); // TODO(derat|oshima): Don't use mouse_button_flags_ as it's @@ -1148,4 +1149,12 @@ void RootWindow::SynthesizeMouseMoveEvent() { OnHostMouseEvent(&event); } +gfx::Transform RootWindow::GetRootTransform() const { + float scale = ui::GetDeviceScaleFactor(layer()); + gfx::Transform transform; + transform.Scale(scale, scale); + transform *= layer()->transform(); + return transform; +} + } // namespace aura diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 34a2433..57d58f6 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -191,6 +191,14 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // Converts |point| from native screen coordinate system to the root window's. void ConvertPointFromNativeScreen(gfx::Point* point) const; + // Converts |point| from the root window's coordinate system to the + // host window's. + void ConvertPointToHost(gfx::Point* point) const; + + // Converts |point| from the host window's coordinate system to the + // root window's. + void ConvertPointFromHost(gfx::Point* point) const; + // Gesture Recognition ------------------------------------------------------- // When a touch event is dispatched to a Window, it may want to process the @@ -391,6 +399,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // current mouse location. void SynthesizeMouseMoveEvent(); + gfx::Transform GetRootTransform() const; + scoped_ptr<ui::Compositor> compositor_; scoped_ptr<RootWindowHost> host_; diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index 48b1b27..22c8ada 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -1003,16 +1003,20 @@ void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { void RootWindowHostLinux::TranslateAndDispatchMouseEvent( ui::MouseEvent* event) { - RootWindow* root = GetRootWindow(); + RootWindow* root_window = GetRootWindow(); client::ScreenPositionClient* screen_position_client = - GetScreenPositionClient(root); - if (screen_position_client && !bounds_.Contains(event->location())) { + GetScreenPositionClient(root_window); + gfx::Rect local(bounds_.size()); + + if (screen_position_client && !local.Contains(event->location())) { gfx::Point location(event->location()); - screen_position_client->ConvertNativePointToScreen(root, &location); - screen_position_client->ConvertPointFromScreen(root, &location); - // |delegate_|'s OnHostMouseEvent expects native coordinates relative to - // root. - location = ui::ConvertPointToPixel(root->layer(), location); + // In order to get the correct point in screen coordinates + // during passive grab, we first need to find on which host window + // the mouse is on, and find out the screen coordinates on that + // host window, then convert it back to this host window's coordinate. + screen_position_client->ConvertHostPointToScreen(root_window, &location); + screen_position_client->ConvertPointFromScreen(root_window, &location); + root_window->ConvertPointToHost(&location); event->set_location(location); event->set_root_location(location); } diff --git a/ui/views/widget/desktop_aura/desktop_screen_position_client.cc b/ui/views/widget/desktop_aura/desktop_screen_position_client.cc index 19fcbed..5b4dbc0 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_position_client.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_position_client.cc @@ -31,8 +31,8 @@ void DesktopScreenPositionClient::ConvertPointFromScreen( aura::Window::ConvertPointToTarget(root_window, window, point); } -void DesktopScreenPositionClient::ConvertNativePointToScreen( - aura::Window* window, gfx::Point* point) { +void DesktopScreenPositionClient::ConvertHostPointToScreen( + aura::RootWindow* window, gfx::Point* point) { ConvertPointToScreen(window, point); } diff --git a/ui/views/widget/desktop_aura/desktop_screen_position_client.h b/ui/views/widget/desktop_aura/desktop_screen_position_client.h index 44fbbab..479a1cc 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_position_client.h +++ b/ui/views/widget/desktop_aura/desktop_screen_position_client.h @@ -23,8 +23,8 @@ class VIEWS_EXPORT DesktopScreenPositionClient gfx::Point* point) OVERRIDE; virtual void ConvertPointFromScreen(const aura::Window* window, gfx::Point* point) OVERRIDE; - virtual void ConvertNativePointToScreen(aura::Window* window, - gfx::Point* point) OVERRIDE; + virtual void ConvertHostPointToScreen(aura::RootWindow* window, + gfx::Point* point) OVERRIDE; virtual void SetBounds(aura::Window* window, const gfx::Rect& bounds, const gfx::Display& display) OVERRIDE; |