summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 18:11:04 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 18:11:04 +0000
commit39b2b7e8d4d4121e431ec1e5cc30ced3f72f39f6 (patch)
tree30bb34c3ba21afaefce3fd5e9d1b34878583471d
parent74684ce7d2c75ca285143884419362475f2bfa70 (diff)
downloadchromium_src-39b2b7e8d4d4121e431ec1e5cc30ced3f72f39f6.zip
chromium_src-39b2b7e8d4d4121e431ec1e5cc30ced3f72f39f6.tar.gz
chromium_src-39b2b7e8d4d4121e431ec1e5cc30ced3f72f39f6.tar.bz2
Revert 255368 "Clean up WindowEventDispatcher some more."
> Clean up WindowEventDispatcher some more. > > . Eliminate the implementation of LayerAnimationObserver. It seems no one expects WED to be a LAO anymore. > . Remove WindowTreeHostDelegate. This involves moving some of the functions to WTH, removing some completely, and moving the remainder to the WED public API. A little icky for now, but I plan to take a pass on cleaning up WED's public API once I get it pared down. > . window_tree_host_x11_unittest provided an implementation of WTHD that was not WED. This is not a valid situation now since various functions in WTH now call directly through to WED. Replaced this with a simple EventHandler to test that events are being dispatched. > > R=sky@chromium.org > http://crbug.com/308843 > > Review URL: https://codereview.chromium.org/188223002 TBR=ben@chromium.org Review URL: https://codereview.chromium.org/188843003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255399 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/cancel_mode.cc2
-rw-r--r--ash/cancel_mode.h2
-rw-r--r--ash/first_run/desktop_cleaner.cc1
-rw-r--r--ash/sticky_keys/sticky_keys_overlay_unittest.cc1
-rw-r--r--ash/sticky_keys/sticky_keys_unittest.cc1
-rw-r--r--ash/wm/overview/window_overview.cc1
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc1
-rw-r--r--mojo/examples/aura_demo/window_tree_host_mojo.cc7
-rw-r--r--ui/app_list/views/app_list_view.cc1
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/remote_window_tree_host_win.cc4
-rw-r--r--ui/aura/remote_window_tree_host_win.h2
-rw-r--r--ui/aura/window_event_dispatcher.cc131
-rw-r--r--ui/aura/window_event_dispatcher.h39
-rw-r--r--ui/aura/window_event_dispatcher_unittest.cc2
-rw-r--r--ui/aura/window_tree_host.cc59
-rw-r--r--ui/aura/window_tree_host.h11
-rw-r--r--ui/aura/window_tree_host_delegate.h60
-rw-r--r--ui/aura/window_tree_host_mac.mm1
-rw-r--r--ui/aura/window_tree_host_ozone.cc2
-rw-r--r--ui/aura/window_tree_host_win.cc14
-rw-r--r--ui/aura/window_tree_host_x11.cc30
-rw-r--r--ui/aura/window_tree_host_x11.h2
-rw-r--r--ui/aura/window_tree_host_x11_unittest.cc177
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc14
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc14
26 files changed, 381 insertions, 199 deletions
diff --git a/ash/cancel_mode.cc b/ash/cancel_mode.cc
index 96d7dcd..9d5456da 100644
--- a/ash/cancel_mode.cc
+++ b/ash/cancel_mode.cc
@@ -15,7 +15,7 @@ void DispatchCancelMode() {
Shell::GetAllRootWindowControllers());
for (Shell::RootWindowControllerList::const_iterator i = controllers.begin();
i != controllers.end(); ++i) {
- (*i)->host()->dispatcher()->DispatchCancelModeEvent();
+ (*i)->host()->dispatcher()->AsWindowTreeHostDelegate()->OnHostCancelMode();
}
}
diff --git a/ash/cancel_mode.h b/ash/cancel_mode.h
index d3c3669..915fe43 100644
--- a/ash/cancel_mode.h
+++ b/ash/cancel_mode.h
@@ -7,7 +7,7 @@
namespace ash {
-// Sends a CancelMode event to all window hierarchies.
+// Sends OnHostCancelMode() to all RootWindows.
void DispatchCancelMode();
} // namespace ash
diff --git a/ash/first_run/desktop_cleaner.cc b/ash/first_run/desktop_cleaner.cc
index 8008cda..9e6da0ff 100644
--- a/ash/first_run/desktop_cleaner.cc
+++ b/ash/first_run/desktop_cleaner.cc
@@ -8,7 +8,6 @@
#include "ash/shell_window_ids.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_observer.h"
-#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification_blocker.h"
diff --git a/ash/sticky_keys/sticky_keys_overlay_unittest.cc b/ash/sticky_keys/sticky_keys_overlay_unittest.cc
index 246481d..5d13f31 100644
--- a/ash/sticky_keys/sticky_keys_overlay_unittest.cc
+++ b/ash/sticky_keys/sticky_keys_overlay_unittest.cc
@@ -9,6 +9,7 @@
#include "ash/test/ash_test_base.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/events/event.h"
namespace ash {
diff --git a/ash/sticky_keys/sticky_keys_unittest.cc b/ash/sticky_keys/sticky_keys_unittest.cc
index e552c22..6da0984 100644
--- a/ash/sticky_keys/sticky_keys_unittest.cc
+++ b/ash/sticky_keys/sticky_keys_unittest.cc
@@ -16,6 +16,7 @@
#include "base/memory/scoped_vector.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/events/event_handler.h"
#include "ui/events/test/events_test_utils_x11.h"
#include "ui/events/x/device_data_manager.h"
diff --git a/ash/wm/overview/window_overview.cc b/ash/wm/overview/window_overview.cc
index 34d4dc4..f2a4b86 100644
--- a/ash/wm/overview/window_overview.cc
+++ b/ash/wm/overview/window_overview.cc
@@ -19,7 +19,6 @@
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
-#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/events/event.h"
#include "ui/views/background.h"
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
index 7081677..905747f 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
@@ -22,6 +22,7 @@
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host_delegate.h"
#endif // defined(USE_AURA)
class OmniboxViewViewsTest : public InProcessBrowserTest {
diff --git a/mojo/examples/aura_demo/window_tree_host_mojo.cc b/mojo/examples/aura_demo/window_tree_host_mojo.cc
index 815cce66..266d923 100644
--- a/mojo/examples/aura_demo/window_tree_host_mojo.cc
+++ b/mojo/examples/aura_demo/window_tree_host_mojo.cc
@@ -10,7 +10,7 @@
#include "mojo/services/native_viewport/geometry_conversions.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
-#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/compositor/compositor.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
@@ -148,7 +148,7 @@ void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) {
// WindowTreeHostMojo, ui::EventSource implementation:
ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
////////////////////////////////////////////////////////////////////////////////
@@ -162,7 +162,8 @@ void WindowTreeHostMojo::OnCreated() {
void WindowTreeHostMojo::OnBoundsChanged(const Rect& bounds) {
bounds_ = gfx::Rect(bounds.position().x(), bounds.position().y(),
bounds.size().width(), bounds.size().height());
- window()->SetBounds(gfx::Rect(bounds_.size()));
+ if (delegate_)
+ window()->SetBounds(gfx::Rect(bounds_.size()));
OnHostResized(bounds_.size());
}
diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc
index cab7fd5..b1f15f4 100644
--- a/ui/app_list/views/app_list_view.cc
+++ b/ui/app_list/views/app_list_view.cc
@@ -23,7 +23,6 @@
#include "ui/app_list/views/speech_view.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
-#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/insets.h"
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 3453031..f3de1fb 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -107,6 +107,7 @@
'window_tracker.h',
'window_tree_host.cc',
'window_tree_host.h',
+ 'window_tree_host_delegate.h',
'window_tree_host_mac.mm',
'window_tree_host_mac.h',
'window_tree_host_observer.h',
diff --git a/ui/aura/remote_window_tree_host_win.cc b/ui/aura/remote_window_tree_host_win.cc
index 17ef1b2..7669fae 100644
--- a/ui/aura/remote_window_tree_host_win.cc
+++ b/ui/aura/remote_window_tree_host_win.cc
@@ -489,7 +489,7 @@ void RemoteWindowTreeHostWin::PrepareForShutdown() {
}
ui::EventProcessor* RemoteWindowTreeHostWin::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
void RemoteWindowTreeHostWin::CancelComposition() {
@@ -591,7 +591,7 @@ void RemoteWindowTreeHostWin::OnChar(uint32 key_code,
}
void RemoteWindowTreeHostWin::OnWindowActivated() {
- OnHostActivated();
+ delegate_->OnHostActivated();
}
void RemoteWindowTreeHostWin::OnEdgeGesture() {
diff --git a/ui/aura/remote_window_tree_host_win.h b/ui/aura/remote_window_tree_host_win.h
index ab03b26..6ccd06c 100644
--- a/ui/aura/remote_window_tree_host_win.h
+++ b/ui/aura/remote_window_tree_host_win.h
@@ -247,7 +247,7 @@ class AURA_EXPORT RemoteWindowTreeHostWin
const std::vector<gfx::Rect>& composition_character_bounds) OVERRIDE;
// Helper function to dispatch a keyboard message to the desired target.
- // The default target is the WindowEventDispatcher. For nested message loop
+ // The default target is the WindowTreeHostDelegate. For nested message loop
// invocations we post a synthetic keyboard message directly into the message
// loop. The dispatcher for the nested loop would then decide how this
// message is routed.
diff --git a/ui/aura/window_event_dispatcher.cc b/ui/aura/window_event_dispatcher.cc
index b6a8dcd..c317e15 100644
--- a/ui/aura/window_event_dispatcher.cc
+++ b/ui/aura/window_event_dispatcher.cc
@@ -4,7 +4,10 @@
#include "ui/aura/window_event_dispatcher.h"
+#include <vector>
+
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
@@ -21,9 +24,14 @@
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/dip_util.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_animator.h"
#include "ui/events/event.h"
#include "ui/events/gestures/gesture_recognizer.h"
#include "ui/events/gestures/gesture_types.h"
+#include "ui/gfx/screen.h"
+
+using std::vector;
typedef ui::EventDispatchDetails DispatchDetails;
@@ -121,6 +129,10 @@ void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent& event) {
}
}
+WindowTreeHostDelegate* WindowEventDispatcher::AsWindowTreeHostDelegate() {
+ return this;
+}
+
void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) {
// Send entered / exited so that visual state can be updated to match
// mouse events state.
@@ -128,17 +140,6 @@ void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) {
// TODO(mazda): Add code to disable mouse events when |enabled| == false.
}
-void WindowEventDispatcher::DispatchCancelModeEvent() {
- ui::CancelModeEvent event;
- Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow();
- if (focused_window && !window()->Contains(focused_window))
- focused_window = NULL;
- DispatchDetails details =
- DispatchEvent(focused_window ? focused_window : window(), &event);
- if (details.dispatcher_destroyed)
- return;
-}
-
Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) {
Window* target = NULL;
if (!event->IsEndingEvent()) {
@@ -274,34 +275,6 @@ gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const {
return location;
}
-void WindowEventDispatcher::OnHostLostMouseGrab() {
- mouse_pressed_handler_ = NULL;
- mouse_moved_handler_ = NULL;
-}
-
-void WindowEventDispatcher::OnHostResized(const gfx::Size& size) {
- TRACE_EVENT1("ui", "WindowEventDispatcher::OnHostResized",
- "size", size.ToString());
-
- DispatchDetails details = DispatchHeldEvents();
- if (details.dispatcher_destroyed)
- return;
-
- // Constrain the mouse position within the new root Window size.
- gfx::Point point;
- if (host_->QueryMouseLocation(&point)) {
- SetLastMouseLocation(window(),
- ui::ConvertPointToDIP(window()->layer(), point));
- }
- synthesize_mouse_move_ = false;
-}
-
-void WindowEventDispatcher::OnCursorMovedToRootLocation(
- const gfx::Point& root_location) {
- SetLastMouseLocation(window(), root_location);
- synthesize_mouse_move_ = false;
-}
-
////////////////////////////////////////////////////////////////////////////////
// WindowEventDispatcher, private:
@@ -583,6 +556,86 @@ void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) {
}
////////////////////////////////////////////////////////////////////////////////
+// WindowEventDispatcher, ui::LayerAnimationObserver implementation:
+
+void WindowEventDispatcher::OnLayerAnimationEnded(
+ ui::LayerAnimationSequence* animation) {
+ host()->UpdateRootWindowSize(host_->GetBounds().size());
+}
+
+void WindowEventDispatcher::OnLayerAnimationScheduled(
+ ui::LayerAnimationSequence* animation) {
+}
+
+void WindowEventDispatcher::OnLayerAnimationAborted(
+ ui::LayerAnimationSequence* animation) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowEventDispatcher, WindowTreeHostDelegate implementation:
+
+void WindowEventDispatcher::OnHostCancelMode() {
+ ui::CancelModeEvent event;
+ Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow();
+ if (focused_window && !window()->Contains(focused_window))
+ focused_window = NULL;
+ DispatchDetails details =
+ DispatchEvent(focused_window ? focused_window : window(), &event);
+ if (details.dispatcher_destroyed)
+ return;
+}
+
+void WindowEventDispatcher::OnHostActivated() {
+ Env::GetInstance()->RootWindowActivated(this);
+}
+
+void WindowEventDispatcher::OnHostLostWindowCapture() {
+ Window* capture_window = client::GetCaptureWindow(window());
+ if (capture_window && capture_window->GetRootWindow() == window())
+ capture_window->ReleaseCapture();
+}
+
+void WindowEventDispatcher::OnHostLostMouseGrab() {
+ mouse_pressed_handler_ = NULL;
+ mouse_moved_handler_ = NULL;
+}
+
+void WindowEventDispatcher::OnHostResized(const gfx::Size& size) {
+ TRACE_EVENT1("ui", "WindowEventDispatcher::OnHostResized",
+ "size", size.ToString());
+
+ DispatchDetails details = DispatchHeldEvents();
+ if (details.dispatcher_destroyed)
+ return;
+
+ // Constrain the mouse position within the new root Window size.
+ gfx::Point point;
+ if (host_->QueryMouseLocation(&point)) {
+ SetLastMouseLocation(window(),
+ ui::ConvertPointToDIP(window()->layer(), point));
+ }
+ synthesize_mouse_move_ = false;
+}
+
+void WindowEventDispatcher::OnCursorMovedToRootLocation(
+ const gfx::Point& root_location) {
+ SetLastMouseLocation(window(), root_location);
+ synthesize_mouse_move_ = false;
+}
+
+WindowEventDispatcher* WindowEventDispatcher::AsDispatcher() {
+ return this;
+}
+
+const WindowEventDispatcher* WindowEventDispatcher::AsDispatcher() const {
+ return this;
+}
+
+ui::EventProcessor* WindowEventDispatcher::GetEventProcessor() {
+ return this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// WindowEventDispatcher, private:
ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() {
diff --git a/ui/aura/window_event_dispatcher.h b/ui/aura/window_event_dispatcher.h
index 7ea3d60..9fe917b 100644
--- a/ui/aura/window_event_dispatcher.h
+++ b/ui/aura/window_event_dispatcher.h
@@ -16,7 +16,10 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/client/capture_delegate.h"
#include "ui/aura/window_tree_host.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/base/cursor/cursor.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/layer_animation_observer.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_targeter.h"
@@ -34,6 +37,7 @@ namespace ui {
class GestureEvent;
class GestureRecognizer;
class KeyEvent;
+class LayerAnimationSequence;
class MouseEvent;
class ScrollEvent;
class TouchEvent;
@@ -50,7 +54,9 @@ class WindowTargeter;
// event dispatch.
class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
public ui::GestureEventHelper,
- public client::CaptureDelegate {
+ public ui::LayerAnimationObserver,
+ public client::CaptureDelegate,
+ public WindowTreeHostDelegate {
public:
explicit WindowEventDispatcher(WindowTreeHost* host);
virtual ~WindowEventDispatcher();
@@ -73,11 +79,11 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
// types (although the latter is currently a no-op).
void RepostEvent(const ui::LocatedEvent& event);
+ WindowTreeHostDelegate* AsWindowTreeHostDelegate();
+
// Invoked when the mouse events get enabled or disabled.
void OnMouseEventsEnableStateChanged(bool enabled);
- void DispatchCancelModeEvent();
-
// Returns a target window for the given gesture event.
Window* GetGestureTarget(ui::GestureEvent* event);
@@ -133,11 +139,6 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
// coordinates. This may return a point outside the root window's bounds.
gfx::Point GetLastMouseLocationInRoot() const;
- void OnHostLostMouseGrab();
- // TODO(beng): replace with a window observer.
- void OnHostResized(const gfx::Size& size);
- void OnCursorMovedToRootLocation(const gfx::Point& root_location);
-
private:
FRIEND_TEST_ALL_PREFIXES(WindowEventDispatcherTest,
KeepTranslatedEventInRoot);
@@ -154,7 +155,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
};
// Updates the event with the appropriate transform for the device scale
- // factor. The WindowEventDispatcher dispatches events in the physical pixel
+ // factor. The WindowTreeHostDelegate dispatches events in the physical pixel
// coordinate. But the event processing from WindowEventDispatcher onwards
// happen in device-independent pixel coordinate. So it is necessary to update
// the event received from the host.
@@ -206,6 +207,26 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
+ // Overridden from ui::LayerAnimationObserver:
+ virtual void OnLayerAnimationEnded(
+ ui::LayerAnimationSequence* animation) OVERRIDE;
+ virtual void OnLayerAnimationScheduled(
+ ui::LayerAnimationSequence* animation) OVERRIDE;
+ virtual void OnLayerAnimationAborted(
+ ui::LayerAnimationSequence* animation) OVERRIDE;
+
+ // Overridden from aura::WindowTreeHostDelegate:
+ virtual void OnHostCancelMode() OVERRIDE;
+ virtual void OnHostActivated() OVERRIDE;
+ virtual void OnHostLostWindowCapture() OVERRIDE;
+ virtual void OnHostLostMouseGrab() OVERRIDE;
+ virtual void OnHostResized(const gfx::Size& size) OVERRIDE;
+ virtual void OnCursorMovedToRootLocation(
+ const gfx::Point& root_location) OVERRIDE;
+ virtual WindowEventDispatcher* AsDispatcher() OVERRIDE;
+ virtual const WindowEventDispatcher* AsDispatcher() const OVERRIDE;
+ virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
+
// We hold and aggregate mouse drags and touch moves as a way of throttling
// resizes when HoldMouseMoves() is called. The following methods are used to
// dispatch held and newly incoming mouse and touch events, typically when an
diff --git a/ui/aura/window_event_dispatcher_unittest.cc b/ui/aura/window_event_dispatcher_unittest.cc
index 67866e9..f091110 100644
--- a/ui/aura/window_event_dispatcher_unittest.cc
+++ b/ui/aura/window_event_dispatcher_unittest.cc
@@ -1831,7 +1831,7 @@ TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) {
EXPECT_FALSE(root_window()->Contains(focused.get()));
EXPECT_EQ(focused.get(),
client::GetFocusClient(root_window())->GetFocusedWindow());
- dispatcher()->DispatchCancelModeEvent();
+ dispatcher()->AsWindowTreeHostDelegate()->OnHostCancelMode();
EXPECT_EQ(focused.get(),
client::GetFocusClient(root_window())->GetFocusedWindow());
}
diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc
index 93c624b..2f60c7c 100644
--- a/ui/aura/window_tree_host.cc
+++ b/ui/aura/window_tree_host.cc
@@ -5,13 +5,13 @@
#include "ui/aura/window_tree_host.h"
#include "base/debug/trace_event.h"
-#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window_transformer.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_targeter.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/base/view_prop.h"
#include "ui/compositor/dip_util.h"
@@ -84,17 +84,6 @@ WindowTreeHost::~WindowTreeHost() {
DCHECK(!compositor_) << "compositor must be destroyed before root window";
}
-#if defined(OS_ANDROID)
-// static
-WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
- // This is only hit for tests and ash, right now these aren't an issue so
- // adding the CHECK.
- // TODO(sky): decide if we want a factory.
- CHECK(false);
- return NULL;
-}
-#endif
-
// static
WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget(
gfx::AcceleratedWidget widget) {
@@ -105,7 +94,7 @@ WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget(
void WindowTreeHost::InitHost() {
InitCompositor();
UpdateRootWindowSize(GetBounds().size());
- Env::GetInstance()->NotifyRootWindowInitialized(dispatcher());
+ Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsDispatcher());
window()->Show();
}
@@ -198,8 +187,8 @@ void WindowTreeHost::OnCursorVisibilityChanged(bool show) {
// visible because that can only happen in response to a mouse event, which
// will trigger its own mouse enter.
if (!show) {
- dispatcher()->DispatchMouseExitAtPoint(
- dispatcher()->GetLastMouseLocationInRoot());
+ delegate_->AsDispatcher()->DispatchMouseExitAtPoint(
+ delegate_->AsDispatcher()->GetLastMouseLocationInRoot());
}
OnCursorVisibilityChangedNative(show);
@@ -217,11 +206,16 @@ void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) {
MoveCursorToInternal(root_location, host_location);
}
+WindowEventDispatcher* WindowTreeHost::GetDispatcher() {
+ return delegate_->AsDispatcher();
+}
+
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHost, protected:
WindowTreeHost::WindowTreeHost()
- : window_(new Window(NULL)),
+ : delegate_(NULL),
+ window_(new Window(NULL)),
last_cursor_(ui::kCursorNull) {
}
@@ -231,6 +225,10 @@ void WindowTreeHost::DestroyCompositor() {
}
void WindowTreeHost::DestroyDispatcher() {
+ // An observer may have been added by an animation on the
+ // WindowEventDispatcher.
+ window()->layer()->GetAnimator()->RemoveObserver(dispatcher());
+
delete window_;
window_ = NULL;
dispatcher_.reset();
@@ -262,6 +260,7 @@ void WindowTreeHost::CreateCompositor(
this));
dispatcher_.reset(new WindowEventDispatcher(this));
}
+ delegate_ = dispatcher();
}
void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) {
@@ -283,7 +282,7 @@ void WindowTreeHost::OnHostResized(const gfx::Size& new_size) {
// transformed size of the root window.
UpdateRootWindowSize(layer_size);
FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, OnHostResized(this));
- dispatcher()->OnHostResized(layer_size);
+ delegate_->OnHostResized(layer_size);
}
void WindowTreeHost::OnHostCloseRequested() {
@@ -291,19 +290,6 @@ void WindowTreeHost::OnHostCloseRequested() {
OnHostCloseRequested(this));
}
-void WindowTreeHost::OnHostActivated() {
- Env::GetInstance()->RootWindowActivated(dispatcher());
-}
-
-void WindowTreeHost::OnHostLostWindowCapture() {
- Window* capture_window = client::GetCaptureWindow(window());
- if (capture_window && capture_window->GetRootWindow() == window())
- capture_window->ReleaseCapture();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowTreeHost, private:
-
void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
const gfx::Point& host_location) {
MoveCursorToNative(host_location);
@@ -313,7 +299,18 @@ void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window());
cursor_client->SetDisplay(display);
}
- dispatcher()->OnCursorMovedToRootLocation(root_location);
+ delegate_->OnCursorMovedToRootLocation(root_location);
}
+#if defined(OS_ANDROID)
+// static
+WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
+ // This is only hit for tests and ash, right now these aren't an issue so
+ // adding the CHECK.
+ // TODO(sky): decide if we want a factory.
+ CHECK(false);
+ return NULL;
+}
+#endif
+
} // namespace aura
diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h
index dc2b7c5..1c7e3d1 100644
--- a/ui/aura/window_tree_host.h
+++ b/ui/aura/window_tree_host.h
@@ -29,6 +29,7 @@ class ViewProp;
namespace aura {
class RootWindowTransformer;
class WindowEventDispatcher;
+class WindowTreeHostDelegate;
class WindowTreeHostObserver;
// WindowTreeHost bridges between a native window and the embedded RootWindow.
@@ -78,6 +79,10 @@ class AURA_EXPORT WindowTreeHost {
// (gfx::Screen only reports on the virtual desktop exposed by Aura.)
static gfx::Size GetNativeScreenSize();
+ void set_delegate(WindowTreeHostDelegate* delegate) {
+ delegate_ = delegate;
+ }
+
// Converts |point| from the root window's coordinate system to native
// screen's.
void ConvertPointToNativeScreen(gfx::Point* point) const;
@@ -111,6 +116,8 @@ class AURA_EXPORT WindowTreeHost {
gfx::NativeCursor last_cursor() const { return last_cursor_; }
+ WindowEventDispatcher* GetDispatcher();
+
// Returns the accelerated widget.
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
@@ -178,8 +185,6 @@ class AURA_EXPORT WindowTreeHost {
void OnHostMoved(const gfx::Point& new_location);
void OnHostResized(const gfx::Size& new_size);
void OnHostCloseRequested();
- void OnHostActivated();
- void OnHostLostWindowCapture();
// Sets the currently displayed cursor.
virtual void SetCursorNative(gfx::NativeCursor cursor) = 0;
@@ -190,6 +195,8 @@ class AURA_EXPORT WindowTreeHost {
// kCalled when the cursor visibility has changed.
virtual void OnCursorVisibilityChangedNative(bool show) = 0;
+ WindowTreeHostDelegate* delegate_;
+
private:
// Moves the cursor to the specified location. This method is internally used
// by MoveCursorTo() and MoveCursorToHostLocation().
diff --git a/ui/aura/window_tree_host_delegate.h b/ui/aura/window_tree_host_delegate.h
new file mode 100644
index 0000000..c5ba407
--- /dev/null
+++ b/ui/aura/window_tree_host_delegate.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 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.
+
+#ifndef UI_AURA_WINDOW_TREE_HOST_DELEGATE_H_
+#define UI_AURA_WINDOW_TREE_HOST_DELEGATE_H_
+
+#include "ui/aura/aura_export.h"
+
+namespace gfx {
+class Point;
+class Rect;
+class Size;
+}
+
+namespace ui {
+class Event;
+class EventProcessor;
+class KeyEvent;
+class MouseEvent;
+class ScrollEvent;
+class TouchEvent;
+}
+
+namespace aura {
+
+class RootWindow;
+
+// A private interface used by WindowTreeHost implementations to communicate
+// with their owning RootWindow.
+class AURA_EXPORT WindowTreeHostDelegate {
+ public:
+ virtual void OnHostCancelMode() = 0;
+
+ // Called when the windowing system activates the window.
+ virtual void OnHostActivated() = 0;
+
+ // Called when system focus is changed to another window.
+ virtual void OnHostLostWindowCapture() = 0;
+
+ // Called when the windowing system has mouse grab because it's performing a
+ // window move on our behalf, but we should still paint as if we're active.
+ virtual void OnHostLostMouseGrab() = 0;
+
+ virtual void OnHostResized(const gfx::Size& size) = 0;
+
+ virtual void OnCursorMovedToRootLocation(const gfx::Point& root_location) = 0;
+
+ virtual WindowEventDispatcher* AsDispatcher() = 0;
+ virtual const WindowEventDispatcher* AsDispatcher() const = 0;
+
+ virtual ui::EventProcessor* GetEventProcessor() = 0;
+
+ protected:
+ virtual ~WindowTreeHostDelegate() {}
+};
+
+} // namespace aura
+
+#endif // UI_AURA_WINDOW_TREE_HOST_DELEGATE_H_
diff --git a/ui/aura/window_tree_host_mac.mm b/ui/aura/window_tree_host_mac.mm
index e75875b..b814f03 100644
--- a/ui/aura/window_tree_host_mac.mm
+++ b/ui/aura/window_tree_host_mac.mm
@@ -6,6 +6,7 @@
#include "ui/aura/window_tree_host_mac.h"
#include "ui/aura/window_tree_host.h"
+#include "ui/aura/window_tree_host_delegate.h"
namespace aura {
diff --git a/ui/aura/window_tree_host_ozone.cc b/ui/aura/window_tree_host_ozone.cc
index ea9c45b..a2c6f3b 100644
--- a/ui/aura/window_tree_host_ozone.cc
+++ b/ui/aura/window_tree_host_ozone.cc
@@ -110,7 +110,7 @@ void WindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
}
ui::EventProcessor* WindowTreeHostOzone::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
// static
diff --git a/ui/aura/window_tree_host_win.cc b/ui/aura/window_tree_host_win.cc
index cddc5b3..eb3af31 100644
--- a/ui/aura/window_tree_host_win.cc
+++ b/ui/aura/window_tree_host_win.cc
@@ -13,7 +13,6 @@
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursor_loader_win.h"
#include "ui/base/view_prop.h"
-#include "ui/compositor/compositor.h"
#include "ui/events/event.h"
#include "ui/gfx/display.h"
#include "ui/gfx/insets.h"
@@ -135,8 +134,9 @@ void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
// Explicity call OnHostResized when the scale has changed because
// the window size may not have changed.
float current_scale = compositor()->device_scale_factor();
- float new_scale = gfx::Screen::GetScreenFor(window())->
- GetDisplayNearestWindow(window()).device_scale_factor();
+ float new_scale = gfx::Screen::GetScreenFor(
+ delegate_->AsDispatcher()->window())->GetDisplayNearestWindow(
+ delegate_->AsDispatcher()->window()).device_scale_factor();
if (current_scale != new_scale)
OnHostResized(bounds.size());
}
@@ -230,7 +230,7 @@ void WindowTreeHostWin::PrepareForShutdown() {
}
ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
void WindowTreeHostWin::OnClose() {
@@ -268,7 +268,7 @@ LRESULT WindowTreeHostWin::OnCaptureChanged(UINT message,
LPARAM l_param) {
if (has_capture_) {
has_capture_ = false;
- OnHostLostWindowCapture();
+ delegate_->OnHostLostWindowCapture();
}
return 0;
}
@@ -277,7 +277,7 @@ LRESULT WindowTreeHostWin::OnNCActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (!!w_param)
- OnHostActivated();
+ delegate_->OnHostActivated();
return DefWindowProc(hwnd(), message, w_param, l_param);
}
@@ -297,7 +297,7 @@ void WindowTreeHostWin::OnPaint(HDC dc) {
void WindowTreeHostWin::OnSize(UINT param, const gfx::Size& size) {
// Minimizing resizes the window to 0x0 which causes our layout to go all
// screwy, so we just ignore it.
- if (param != SIZE_MINIMIZED)
+ if (delegate_ && param != SIZE_MINIMIZED)
OnHostResized(size);
}
diff --git a/ui/aura/window_tree_host_x11.cc b/ui/aura/window_tree_host_x11.cc
index 6286742..8b0f564 100644
--- a/ui/aura/window_tree_host_x11.cc
+++ b/ui/aura/window_tree_host_x11.cc
@@ -36,7 +36,6 @@
#include "ui/base/ui_base_switches.h"
#include "ui/base/view_prop.h"
#include "ui/base/x/x11_util.h"
-#include "ui/compositor/compositor.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
@@ -404,7 +403,7 @@ uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
if (static_cast<int>(xev->xbutton.button) == kBackMouseButton ||
static_cast<int>(xev->xbutton.button) == kForwardMouseButton) {
client::UserActionClient* gesture_client =
- client::GetUserActionClient(window());
+ client::GetUserActionClient(delegate_->AsDispatcher()->window());
if (gesture_client) {
gesture_client->OnUserAction(
static_cast<int>(xev->xbutton.button) == kBackMouseButton ?
@@ -437,7 +436,7 @@ uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
}
case FocusOut:
if (xev->xfocus.mode != NotifyGrab)
- OnHostLostWindowCapture();
+ delegate_->OnHostLostWindowCapture();
break;
case ConfigureNotify: {
DCHECK_EQ(xwindow_, xev->xconfigure.event);
@@ -570,8 +569,9 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) {
// Even if the host window's size doesn't change, aura's root window
// size, which is in DIP, changes when the scale changes.
float current_scale = compositor()->device_scale_factor();
- float new_scale = gfx::Screen::GetScreenFor(window())->
- GetDisplayNearestWindow(window()).device_scale_factor();
+ float new_scale = gfx::Screen::GetScreenFor(
+ delegate_->AsDispatcher()->window())->GetDisplayNearestWindow(
+ delegate_->AsDispatcher()->window()).device_scale_factor();
bool origin_changed = bounds_.origin() != bounds.origin();
bool size_changed = bounds_.size() != bounds.size();
XWindowChanges changes = {0};
@@ -603,7 +603,8 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) {
if (size_changed || current_scale != new_scale) {
OnHostResized(bounds.size());
} else {
- window()->SchedulePaintInRect(window()->bounds());
+ delegate_->AsDispatcher()->window()->SchedulePaintInRect(
+ delegate_->AsDispatcher()->window()->bounds());
}
}
@@ -726,7 +727,7 @@ void WindowTreeHostX11::PostNativeEvent(
xevent.xmotion.time = CurrentTime;
gfx::Point point(xevent.xmotion.x, xevent.xmotion.y);
- ConvertPointToNativeScreen(&point);
+ delegate_->AsDispatcher()->host()->ConvertPointToNativeScreen(&point);
xevent.xmotion.x_root = point.x();
xevent.xmotion.y_root = point.y();
}
@@ -766,11 +767,14 @@ void WindowTreeHostX11::OnWindowInitialized(Window* window) {
void WindowTreeHostX11::OnRootWindowInitialized(
WindowEventDispatcher* d) {
- // UpdateIsInternalDisplay relies on WED's kDisplayIdKey property being set
- // available by the time WED::Init is called. (set in
- // DisplayManager::CreateRootWindowForDisplay)
+ // UpdateIsInternalDisplay relies on:
+ // 1. delegate_ pointing to WindowEventDispatcher - available after
+ // SetDelegate.
+ // 2. WED's kDisplayIdKey property set - available by the time
+ // WED::Init is called.
+ // (set in DisplayManager::CreateRootWindowForDisplay)
// Ready when NotifyRootWindowInitialized is called from WED::Init.
- if (d != dispatcher())
+ if (!delegate_ || d != dispatcher())
return;
UpdateIsInternalDisplay();
@@ -780,7 +784,7 @@ void WindowTreeHostX11::OnRootWindowInitialized(
}
ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) {
@@ -870,7 +874,7 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) {
if (type == ui::ET_MOUSE_RELEASED)
break;
client::UserActionClient* gesture_client =
- client::GetUserActionClient(window());
+ client::GetUserActionClient(delegate_->AsDispatcher()->window());
if (gesture_client) {
bool reverse_direction =
ui::IsTouchpadEvent(xev) && ui::IsNaturalScrollEnabled();
diff --git a/ui/aura/window_tree_host_x11.h b/ui/aura/window_tree_host_x11.h
index c116094..99dbcd3 100644
--- a/ui/aura/window_tree_host_x11.h
+++ b/ui/aura/window_tree_host_x11.h
@@ -90,7 +90,7 @@ class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost,
void SetCursorInternal(gfx::NativeCursor cursor);
// Translates the native mouse location into screen coordinates and and
- // dispatches the event via WindowEventDispatcher.
+ // dispatches the event to WindowTreeHostDelegate.
void TranslateAndDispatchMouseEvent(ui::MouseEvent* event);
// Update is_internal_display_ based on delegate_ state
diff --git a/ui/aura/window_tree_host_x11_unittest.cc b/ui/aura/window_tree_host_x11_unittest.cc
index 0deb034..c1e5579 100644
--- a/ui/aura/window_tree_host_x11_unittest.cc
+++ b/ui/aura/window_tree_host_x11_unittest.cc
@@ -6,8 +6,8 @@
#include "base/sys_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/test/aura_test_base.h"
-#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host_delegate.h"
#include "ui/aura/window_tree_host_x11.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_target.h"
@@ -15,14 +15,37 @@
#include "ui/events/test/events_test_utils_x11.h"
namespace {
-
-class RootWindowEventHandler : public ui::EventHandler {
+class TestWindowTreeHostDelegate : public aura::WindowTreeHostDelegate,
+ public ui::EventProcessor,
+ public ui::EventTarget {
public:
- RootWindowEventHandler() : last_touch_type_(ui::ET_UNKNOWN),
- last_touch_id_(-1),
- last_touch_location_(0, 0) {
+ TestWindowTreeHostDelegate() : last_touch_type_(ui::ET_UNKNOWN),
+ last_touch_id_(-1),
+ last_touch_location_(0, 0) {
+ }
+ virtual ~TestWindowTreeHostDelegate() {}
+
+ // aura::WindowTreeHostDelegate:
+ virtual void OnHostCancelMode() OVERRIDE {}
+ virtual void OnHostActivated() OVERRIDE {}
+ virtual void OnHostLostWindowCapture() OVERRIDE {}
+ virtual void OnHostLostMouseGrab() OVERRIDE {}
+ virtual void OnHostResized(const gfx::Size& size) OVERRIDE {}
+ virtual void OnCursorMovedToRootLocation(
+ const gfx::Point& root_location) OVERRIDE {}
+ virtual aura::WindowEventDispatcher* AsDispatcher() OVERRIDE { return NULL; }
+ virtual const aura::WindowEventDispatcher* AsDispatcher() const OVERRIDE {
+ return NULL;
+ }
+ virtual ui::EventProcessor* GetEventProcessor() OVERRIDE {
+ return this;
+ }
+
+ // ui::EventProcessor:
+ virtual ui::EventTarget* GetRootTarget() OVERRIDE { return this; }
+ virtual bool CanDispatchToTarget(ui::EventTarget* target) OVERRIDE {
+ return true;
}
- virtual ~RootWindowEventHandler () {}
// ui::EventHandler:
virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
@@ -31,6 +54,17 @@ class RootWindowEventHandler : public ui::EventHandler {
last_touch_location_ = event->location();
}
+ // ui::EventTarget:
+ virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE {
+ return true;
+ }
+ virtual ui::EventTarget* GetParentTarget() OVERRIDE { return NULL; }
+ virtual scoped_ptr<ui::EventTargetIterator>
+ GetChildIterator() const OVERRIDE {
+ return scoped_ptr<ui::EventTargetIterator>();
+ }
+ virtual ui::EventTargeter* GetEventTargeter() OVERRIDE { return &targeter_; }
+
ui::EventType last_touch_type() {
return last_touch_type_;
}
@@ -47,8 +81,9 @@ class RootWindowEventHandler : public ui::EventHandler {
ui::EventType last_touch_type_;
int last_touch_id_;
gfx::Point last_touch_location_;
+ ui::EventTargeter targeter_;
- DISALLOW_COPY_AND_ASSIGN(RootWindowEventHandler);
+ DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostDelegate);
};
} // namespace
@@ -69,17 +104,17 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) {
scoped_ptr<WindowTreeHostX11> window_tree_host(
new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700)));
- window_tree_host->InitHost();
- scoped_ptr<RootWindowEventHandler> handler(new RootWindowEventHandler());
- window_tree_host->window()->AddPreTargetHandler(handler.get());
+ scoped_ptr<TestWindowTreeHostDelegate> delegate(
+ new TestWindowTreeHostDelegate());
+ window_tree_host->set_delegate(delegate.get());
std::vector<unsigned int> devices;
devices.push_back(0);
ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
- EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type());
- EXPECT_EQ(-1, handler->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate->last_touch_type());
+ EXPECT_EQ(-1, delegate->last_touch_id());
ui::ScopedXI2Event scoped_xevent;
#if defined(OS_CHROMEOS)
@@ -87,32 +122,32 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) {
scoped_xevent.InitTouchEvent(
0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators);
window_tree_host->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type());
- EXPECT_EQ(-1, handler->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate->last_touch_type());
+ EXPECT_EQ(-1, delegate->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate->last_touch_location());
#endif // defined(OS_CHROMEOS)
// Following touchs are within bounds and are passed to delegate.
scoped_xevent.InitTouchEvent(
0, XI_TouchBegin, 5, gfx::Point(1500, 1500), valuators);
window_tree_host->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler->last_touch_type());
- EXPECT_EQ(0, handler->last_touch_id());
- EXPECT_EQ(gfx::Point(1500, 1500), handler->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate->last_touch_type());
+ EXPECT_EQ(0, delegate->last_touch_id());
+ EXPECT_EQ(gfx::Point(1500, 1500), delegate->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchUpdate, 5, gfx::Point(1500, 1600), valuators);
window_tree_host->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler->last_touch_type());
- EXPECT_EQ(0, handler->last_touch_id());
- EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate->last_touch_type());
+ EXPECT_EQ(0, delegate->last_touch_id());
+ EXPECT_EQ(gfx::Point(1500, 1600), delegate->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchEnd, 5, gfx::Point(1500, 1600), valuators);
window_tree_host->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler->last_touch_type());
- EXPECT_EQ(0, handler->last_touch_id());
- EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate->last_touch_type());
+ EXPECT_EQ(0, delegate->last_touch_id());
+ EXPECT_EQ(gfx::Point(1500, 1600), delegate->last_touch_location());
// Revert the CrOS testing env otherwise the following non-CrOS aura
// tests will fail.
@@ -134,26 +169,26 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) {
scoped_ptr<WindowTreeHostX11> window_tree_host1(
new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700)));
- window_tree_host1->InitHost();
- scoped_ptr<RootWindowEventHandler> handler1(new RootWindowEventHandler());
- window_tree_host1->window()->AddPreTargetHandler(handler1.get());
+ scoped_ptr<TestWindowTreeHostDelegate> delegate1(
+ new TestWindowTreeHostDelegate());
+ window_tree_host1->set_delegate(delegate1.get());
int host2_y_offset = 1700;
scoped_ptr<WindowTreeHostX11> window_tree_host2(
new WindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080)));
- window_tree_host2->InitHost();
- scoped_ptr<RootWindowEventHandler> handler2(new RootWindowEventHandler());
- window_tree_host2->window()->AddPreTargetHandler(handler2.get());
+ scoped_ptr<TestWindowTreeHostDelegate> delegate2(
+ new TestWindowTreeHostDelegate());
+ window_tree_host2->set_delegate(delegate2.get());
std::vector<unsigned int> devices;
devices.push_back(0);
ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(ui::ET_UNKNOWN, handler2->last_touch_type());
- EXPECT_EQ(-1, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate2->last_touch_type());
+ EXPECT_EQ(-1, delegate2->last_touch_id());
// 2 Touch events are targeted at the second WindowTreeHost.
ui::ScopedXI2Event scoped_xevent;
@@ -161,73 +196,73 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) {
0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type());
- EXPECT_EQ(0, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate2->last_touch_type());
+ EXPECT_EQ(0, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1500, 2500 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchBegin, 6, gfx::Point(1600, 2600), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type());
- EXPECT_EQ(1, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate2->last_touch_type());
+ EXPECT_EQ(1, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1600, 2600 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchUpdate, 5, gfx::Point(1500, 2550), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type());
- EXPECT_EQ(0, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate2->last_touch_type());
+ EXPECT_EQ(0, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchUpdate, 6, gfx::Point(1600, 2650), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type());
- EXPECT_EQ(1, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate2->last_touch_type());
+ EXPECT_EQ(1, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchEnd, 5, gfx::Point(1500, 2550), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type());
- EXPECT_EQ(0, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate2->last_touch_type());
+ EXPECT_EQ(0, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
scoped_xevent.InitTouchEvent(
0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators);
window_tree_host1->Dispatch(scoped_xevent);
window_tree_host2->Dispatch(scoped_xevent);
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
- EXPECT_EQ(-1, handler1->last_touch_id());
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type());
- EXPECT_EQ(1, handler2->last_touch_id());
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
+ EXPECT_EQ(-1, delegate1->last_touch_id());
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate2->last_touch_type());
+ EXPECT_EQ(1, delegate2->last_touch_id());
EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset),
- handler2->last_touch_location());
+ delegate2->last_touch_location());
// Revert the CrOS testing env otherwise the following non-CrOS aura
// tests will fail.
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
index f723aeb..b88e3a5 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -586,7 +586,7 @@ void DesktopWindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
// DesktopWindowTreeHostWin, ui::EventSource implementation:
ui::EventProcessor* DesktopWindowTreeHostWin::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
////////////////////////////////////////////////////////////////////////////////
@@ -736,12 +736,11 @@ void DesktopWindowTreeHostWin::HandleAppDeactivated() {
void DesktopWindowTreeHostWin::HandleActivationChanged(bool active) {
// This can be invoked from HWNDMessageHandler::Init(), at which point we're
// not in a good state and need to ignore it.
- // TODO(beng): Do we need this still now the host owns the dispatcher?
- if (!dispatcher())
+ if (!delegate_)
return;
if (active)
- OnHostActivated();
+ delegate_->OnHostActivated();
desktop_native_widget_aura_->HandleActivationChanged(active);
}
@@ -753,11 +752,11 @@ bool DesktopWindowTreeHostWin::HandleAppCommand(short command) {
}
void DesktopWindowTreeHostWin::HandleCancelMode() {
- dispatcher()->DispatchCancelModeEvent();
+ delegate_->OnHostCancelMode();
}
void DesktopWindowTreeHostWin::HandleCaptureLost() {
- OnHostLostWindowCapture();
+ delegate_->OnHostLostWindowCapture();
native_widget_delegate_->OnMouseCaptureLost();
}
@@ -827,7 +826,8 @@ void DesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
void DesktopWindowTreeHostWin::HandleClientSizeChanged(
const gfx::Size& new_size) {
- OnHostResized(new_size);
+ if (delegate_)
+ OnHostResized(new_size);
}
void DesktopWindowTreeHostWin::HandleFrameChanged() {
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index 979cfe9..44f13f4 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -183,7 +183,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const {
void DesktopWindowTreeHostX11::HandleNativeWidgetActivationChanged(
bool active) {
if (active) {
- OnHostActivated();
+ delegate_->OnHostActivated();
open_windows().remove(xwindow_);
open_windows().insert(open_windows().begin(), xwindow_);
}
@@ -237,6 +237,7 @@ void DesktopWindowTreeHostX11::OnRootWindowCreated(
dispatcher_->window()->SetProperty(kViewsWindowForRootWindow,
content_window_);
dispatcher_->window()->SetProperty(kHostForRootWindow, this);
+ delegate_ = dispatcher_;
// Ensure that the X11DesktopHandler exists so that it dispatches activation
// messages to us.
@@ -919,7 +920,7 @@ void DesktopWindowTreeHostX11::PrepareForShutdown() {
// DesktopWindowTreeHostX11, ui::EventSource implementation:
ui::EventProcessor* DesktopWindowTreeHostX11::GetEventProcessor() {
- return dispatcher();
+ return delegate_->GetEventProcessor();
}
////////////////////////////////////////////////////////////////////////////////
@@ -1127,7 +1128,7 @@ void DesktopWindowTreeHostX11::SetUseNativeFrame(bool use_native_frame) {
void DesktopWindowTreeHostX11::OnCaptureReleased() {
x11_capture_.reset();
g_current_capture = NULL;
- OnHostLostWindowCapture();
+ delegate_->OnHostLostWindowCapture();
native_widget_delegate_->OnMouseCaptureLost();
}
@@ -1340,9 +1341,9 @@ uint32_t DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
case FocusOut:
if (xev->xfocus.mode != NotifyGrab) {
ReleaseCapture();
- OnHostLostWindowCapture();
+ delegate_->OnHostLostWindowCapture();
} else {
- dispatcher()->OnHostLostMouseGrab();
+ delegate_->OnHostLostMouseGrab();
}
break;
case FocusIn:
@@ -1413,7 +1414,8 @@ uint32_t DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
int button = xievent->detail;
if (button == kBackMouseButton || button == kForwardMouseButton) {
aura::client::UserActionClient* gesture_client =
- aura::client::GetUserActionClient(window());
+ aura::client::GetUserActionClient(
+ delegate_->AsDispatcher()->window());
if (gesture_client) {
bool reverse_direction =
ui::IsTouchpadEvent(xev) && ui::IsNaturalScrollEnabled();