diff options
author | lionel.g.landwerlin <lionel.g.landwerlin@intel.com> | 2014-12-03 08:46:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-03 16:47:24 +0000 |
commit | 164046d3753535889d3ba1f0060a0280a94bc1c7 (patch) | |
tree | 87f44023922fa59e2433946ec2b2e6748b815c06 | |
parent | e2e9de9c4c933898fe503cec2848701fff08a3cf (diff) | |
download | chromium_src-164046d3753535889d3ba1f0060a0280a94bc1c7.zip chromium_src-164046d3753535889d3ba1f0060a0280a94bc1c7.tar.gz chromium_src-164046d3753535889d3ba1f0060a0280a94bc1c7.tar.bz2 |
ash: ozone: apply transformation to events outside the root window
When dragging windows from one screen to another, events need to be
captured and send to the window where the drag started. As a result we
also need to translate event back into the original window's location.
BUG=423383
TEST=none
Review URL: https://codereview.chromium.org/657603002
Cr-Commit-Position: refs/heads/master@{#306623}
-rw-r--r-- | ash/ash.gyp | 1 | ||||
-rw-r--r-- | ash/host/ash_window_tree_host.cc | 39 | ||||
-rw-r--r-- | ash/host/ash_window_tree_host.h | 8 | ||||
-rw-r--r-- | ash/host/ash_window_tree_host_ozone.cc | 7 | ||||
-rw-r--r-- | ash/host/ash_window_tree_host_x11.cc | 23 | ||||
-rw-r--r-- | ui/aura/window_tree_host_ozone.cc | 8 | ||||
-rw-r--r-- | ui/aura/window_tree_host_ozone.h | 5 |
7 files changed, 64 insertions, 27 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 376376a..2577a4a 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -143,6 +143,7 @@ 'high_contrast/high_contrast_controller.h', 'host/ash_remote_window_tree_host_win.cc', 'host/ash_remote_window_tree_host_win.h', + 'host/ash_window_tree_host.cc', 'host/ash_window_tree_host.h', 'host/ash_window_tree_host_init_params.cc', 'host/ash_window_tree_host_init_params.h', diff --git a/ash/host/ash_window_tree_host.cc b/ash/host/ash_window_tree_host.cc new file mode 100644 index 0000000..916f5d8 --- /dev/null +++ b/ash/host/ash_window_tree_host.cc @@ -0,0 +1,39 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/host/ash_window_tree_host.h" + +#include "ui/aura/client/screen_position_client.h" +#include "ui/aura/window_tree_host.h" +#include "ui/events/event.h" +#include "ui/gfx/rect.h" + +namespace ash { + +void AshWindowTreeHost::TranslateLocatedEvent(ui::LocatedEvent* event) { + if (event->IsTouchEvent()) + return; + + aura::WindowTreeHost* wth = AsWindowTreeHost(); + aura::Window* root_window = wth->window(); + aura::client::ScreenPositionClient* screen_position_client = + aura::client::GetScreenPositionClient(root_window); + gfx::Rect local(wth->GetBounds().size()); + local.Inset(GetHostInsets()); + + if (screen_position_client && !local.Contains(event->location())) { + gfx::Point location(event->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); + wth->ConvertPointToHost(&location); + event->set_location(location); + event->set_root_location(location); + } +} + +} // namespace ash diff --git a/ash/host/ash_window_tree_host.h b/ash/host/ash_window_tree_host.h index b9c617f..51d2f86 100644 --- a/ash/host/ash_window_tree_host.h +++ b/ash/host/ash_window_tree_host.h @@ -18,6 +18,10 @@ class Insets; class Rect; } +namespace ui { +class LocatedEvent; +} + namespace ash { struct AshWindowTreeHostInitParams; class RootWindowTransformer; @@ -57,6 +61,10 @@ class ASH_EXPORT AshWindowTreeHost { // Stop listening for events in preparation for shutdown. virtual void PrepareForShutdown() {} + + protected: + // Translates the native mouse location into screen coordinates. + void TranslateLocatedEvent(ui::LocatedEvent* event); }; } // namespace ash diff --git a/ash/host/ash_window_tree_host_ozone.cc b/ash/host/ash_window_tree_host_ozone.cc index 764eede..d83d484 100644 --- a/ash/host/ash_window_tree_host_ozone.cc +++ b/ash/host/ash_window_tree_host_ozone.cc @@ -34,6 +34,7 @@ class AshWindowTreeHostOzone : public AshWindowTreeHost, virtual gfx::Transform GetRootTransform() const override; virtual gfx::Transform GetInverseRootTransform() const override; virtual void UpdateRootWindowSize(const gfx::Size& host_size) override; + virtual void DispatchEvent(ui::Event* event) override; TransformerHelper transformer_helper_; @@ -87,6 +88,12 @@ void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) { transformer_helper_.UpdateWindowSize(host_size); } +void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) { + if (event->IsLocatedEvent()) + TranslateLocatedEvent(static_cast<ui::LocatedEvent*>(event)); + SendEventToProcessor(event); +} + } // namespace AshWindowTreeHost* AshWindowTreeHost::Create( diff --git a/ash/host/ash_window_tree_host_x11.cc b/ash/host/ash_window_tree_host_x11.cc index 7dbb94e..a768195 100644 --- a/ash/host/ash_window_tree_host_x11.cc +++ b/ash/host/ash_window_tree_host_x11.cc @@ -16,7 +16,6 @@ #include "ash/host/root_window_transformer.h" #include "base/basictypes.h" #include "base/sys_info.h" -#include "ui/aura/client/screen_position_client.h" #include "ui/aura/env.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" @@ -226,27 +225,7 @@ bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { } void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( ui::LocatedEvent* event) { - if (!event->IsTouchEvent()) { - aura::Window* root_window = window(); - aura::client::ScreenPositionClient* screen_position_client = - aura::client::GetScreenPositionClient(root_window); - gfx::Rect local(bounds().size()); - local.Inset(transformer_helper_.GetHostInsets()); - - if (screen_position_client && !local.Contains(event->location())) { - gfx::Point location(event->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); - ConvertPointToHost(&location); - event->set_location(location); - event->set_root_location(location); - } - } + TranslateLocatedEvent(event); SendEventToProcessor(event); } diff --git a/ui/aura/window_tree_host_ozone.cc b/ui/aura/window_tree_host_ozone.cc index 790ba91..2fe6a9f 100644 --- a/ui/aura/window_tree_host_ozone.cc +++ b/ui/aura/window_tree_host_ozone.cc @@ -21,6 +21,10 @@ WindowTreeHostOzone::~WindowTreeHostOzone() { DestroyDispatcher(); } +gfx::Rect WindowTreeHostOzone::GetBounds() const { + return platform_window_->GetBounds(); +} + void WindowTreeHostOzone::OnBoundsChanged(const gfx::Rect& new_bounds) { // TOOD(spang): Should we determine which parts changed? OnHostResized(new_bounds.size()); @@ -73,10 +77,6 @@ void WindowTreeHostOzone::Hide() { platform_window_->Hide(); } -gfx::Rect WindowTreeHostOzone::GetBounds() const { - return platform_window_->GetBounds(); -} - void WindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) { platform_window_->SetBounds(bounds); } diff --git a/ui/aura/window_tree_host_ozone.h b/ui/aura/window_tree_host_ozone.h index 296b14f..16c187a 100644 --- a/ui/aura/window_tree_host_ozone.h +++ b/ui/aura/window_tree_host_ozone.h @@ -24,6 +24,10 @@ class AURA_EXPORT WindowTreeHostOzone : public WindowTreeHost, explicit WindowTreeHostOzone(const gfx::Rect& bounds); virtual ~WindowTreeHostOzone(); + protected: + // WindowTreeHost: + virtual gfx::Rect GetBounds() const override; + private: // ui::PlatformWindowDelegate: virtual void OnBoundsChanged(const gfx::Rect&) override; @@ -42,7 +46,6 @@ class AURA_EXPORT WindowTreeHostOzone : public WindowTreeHost, virtual gfx::AcceleratedWidget GetAcceleratedWidget() override; virtual void Show() override; virtual void Hide() override; - virtual gfx::Rect GetBounds() const override; virtual void SetBounds(const gfx::Rect& bounds) override; virtual gfx::Point GetLocationOnNativeScreen() const override; virtual void SetCapture() override; |