diff options
Diffstat (limited to 'ui')
44 files changed, 235 insertions, 236 deletions
diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc index 79a1b29..99e7552 100644 --- a/ui/app_list/views/app_list_view.cc +++ b/ui/app_list/views/app_list_view.cc @@ -249,7 +249,7 @@ HWND AppListView::GetHWND() const { #if defined(USE_AURA) gfx::NativeWindow window = GetWidget()->GetTopLevelWidget()->GetNativeWindow(); - return window->GetDispatcher()->host()->GetAcceleratedWidget(); + return window->GetHost()->GetAcceleratedWidget(); #else return GetWidget()->GetTopLevelWidget()->GetNativeWindow(); #endif diff --git a/ui/aura/client/default_capture_client.cc b/ui/aura/client/default_capture_client.cc index b0a1055..3cde703 100644 --- a/ui/aura/client/default_capture_client.cc +++ b/ui/aura/client/default_capture_client.cc @@ -31,7 +31,7 @@ void DefaultCaptureClient::SetCapture(Window* window) { Window* old_capture_window = capture_window_; capture_window_ = window; - CaptureDelegate* capture_delegate = root_window_->GetDispatcher(); + CaptureDelegate* capture_delegate = root_window_->GetHost()->dispatcher(); if (capture_window_) capture_delegate->SetNativeCapture(); else diff --git a/ui/aura/remote_window_tree_host_win.cc b/ui/aura/remote_window_tree_host_win.cc index 3fe87b7..92a37c2 100644 --- a/ui/aura/remote_window_tree_host_win.cc +++ b/ui/aura/remote_window_tree_host_win.cc @@ -369,7 +369,7 @@ bool RemoteWindowTreeHostWin::IsForegroundWindow() { } Window* RemoteWindowTreeHostWin::GetAshWindow() { - return GetDispatcher()->window(); + return window(); } gfx::AcceleratedWidget RemoteWindowTreeHostWin::GetAcceleratedWidget() { @@ -421,7 +421,7 @@ void RemoteWindowTreeHostWin::ReleaseCapture() { bool RemoteWindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { aura::client::CursorClient* cursor_client = - aura::client::GetCursorClient(GetDispatcher()->window()); + aura::client::GetCursorClient(window()); if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { *location_return = gfx::Point(0, 0); return false; diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc index 705df12..b1dcab5 100644 --- a/ui/aura/test/event_generator.cc +++ b/ui/aura/test/event_generator.cc @@ -41,7 +41,7 @@ class DefaultEventGeneratorDelegate : public EventGeneratorDelegate { // EventGeneratorDelegate overrides: virtual WindowEventDispatcher* GetDispatcherAt( const gfx::Point& point) const OVERRIDE { - return root_window_->GetDispatcher(); + return root_window_->GetHost()->dispatcher(); } virtual client::ScreenPositionClient* GetScreenPositionClient( diff --git a/ui/aura/test/ui_controls_factory_aurawin.cc b/ui/aura/test/ui_controls_factory_aurawin.cc index 8cbf927..a505fbb 100644 --- a/ui/aura/test/ui_controls_factory_aurawin.cc +++ b/ui/aura/test/ui_controls_factory_aurawin.cc @@ -38,7 +38,7 @@ class UIControlsWin : public UIControlsAura { bool command) { DCHECK(!command); // No command key on Aura HWND window = - native_window->GetDispatcher()->host()->GetAcceleratedWidget(); + native_window->GetHost()->GetAcceleratedWidget(); return SendKeyPressImpl( window, key, control, shift, alt, base::Closure()); } @@ -51,7 +51,7 @@ class UIControlsWin : public UIControlsAura { const base::Closure& task) { DCHECK(!command); // No command key on Aura HWND window = - native_window->GetDispatcher()->host()->GetAcceleratedWidget(); + native_window->GetHost()->GetAcceleratedWidget(); return SendKeyPressImpl(window, key, control, shift, alt, task); } virtual bool SendMouseMove(long screen_x, long screen_y) { diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 59dfc4c..bae67a9 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -162,7 +162,7 @@ class ScopedCursorHider { explicit ScopedCursorHider(Window* window) : window_(window), hid_cursor_(false) { - if (!window_->HasDispatcher()) + if (!window_->IsRootWindow()) return; const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains( Env::GetInstance()->last_mouse_location()); @@ -174,7 +174,7 @@ class ScopedCursorHider { } } ~ScopedCursorHider() { - if (!window_->HasDispatcher()) + if (!window_->IsRootWindow()) return; // Update the device scale factor of the cursor client only when the last @@ -199,7 +199,7 @@ class ScopedCursorHider { }; Window::Window(WindowDelegate* delegate) - : dispatcher_(NULL), + : host_(NULL), type_(ui::wm::WINDOW_TYPE_UNKNOWN), owned_by_parent_(true), delegate_(delegate), @@ -227,9 +227,9 @@ Window::~Window() { FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); // Let the root know so that it can remove any references to us. - WindowEventDispatcher* dispatcher = GetDispatcher(); - if (dispatcher) - dispatcher->OnWindowDestroying(this); + WindowTreeHost* host = GetHost(); + if (host) + host->dispatcher()->OnWindowDestroying(this); // Then destroy the children. RemoveOrDestroyChildren(); @@ -343,17 +343,17 @@ Window* Window::GetRootWindow() { } const Window* Window::GetRootWindow() const { - return dispatcher_ ? this : parent_ ? parent_->GetRootWindow() : NULL; + return IsRootWindow() ? this : parent_ ? parent_->GetRootWindow() : NULL; } -WindowEventDispatcher* Window::GetDispatcher() { - return const_cast<WindowEventDispatcher*>(const_cast<const Window*>(this)-> - GetDispatcher()); +WindowTreeHost* Window::GetHost() { + return const_cast<WindowTreeHost*>(const_cast<const Window*>(this)-> + GetHost()); } -const WindowEventDispatcher* Window::GetDispatcher() const { +const WindowTreeHost* Window::GetHost() const { const Window* root_window = GetRootWindow(); - return root_window ? root_window->dispatcher_ : NULL; + return root_window ? root_window->host_ : NULL; } void Window::Show() { @@ -411,7 +411,7 @@ void Window::SetTransform(const gfx::Transform& transform) { NOTREACHED(); return; } - WindowEventDispatcher* dispatcher = GetDispatcher(); + WindowEventDispatcher* dispatcher = GetHost()->dispatcher(); bool contained_mouse = IsVisible() && dispatcher && ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); layer_->SetTransform(transform); @@ -548,7 +548,7 @@ void Window::AddChild(Window* child) { Window* root_window = GetRootWindow(); if (root_window && old_root != root_window) { - root_window->GetDispatcher()->OnWindowAddedToRootWindow(child); + root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); child->NotifyAddedToRootWindow(); } @@ -630,7 +630,7 @@ void Window::MoveCursorTo(const gfx::Point& point_in_window) { DCHECK(root_window); gfx::Point point_in_root(point_in_window); ConvertPointToTarget(this, root_window, &point_in_root); - root_window->GetDispatcher()->host()->MoveCursorTo(point_in_root); + root_window->GetHost()->MoveCursorTo(point_in_root); } gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { @@ -705,7 +705,7 @@ bool Window::HasFocus() const { } bool Window::CanFocus() const { - if (dispatcher_) + if (IsRootWindow()) return IsVisible(); // NOTE: as part of focusing the window the ActivationClient may make the @@ -724,7 +724,7 @@ bool Window::CanFocus() const { } bool Window::CanReceiveEvents() const { - if (dispatcher_) + if (IsRootWindow()) return IsVisible(); // The client may forbid certain windows from receiving events at a given @@ -779,8 +779,8 @@ void* Window::GetNativeWindowProperty(const char* key) const { void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { ScopedCursorHider hider(this); - if (dispatcher_) - dispatcher_->host()->OnDeviceScaleFactorChanged(device_scale_factor); + if (IsRootWindow()) + host_->OnDeviceScaleFactorChanged(device_scale_factor); if (delegate_) delegate_->OnDeviceScaleFactorChanged(device_scale_factor); } @@ -920,9 +920,9 @@ void Window::SetVisible(bool visible) { FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowVisibilityChanging(this, visible)); - WindowEventDispatcher* dispatcher = GetDispatcher(); - if (dispatcher) - dispatcher->DispatchMouseExitToHidingWindow(this); + WindowTreeHost* host = GetHost(); + if (host) + host->dispatcher()->DispatchMouseExitToHidingWindow(this); client::VisibilityClient* visibility_client = client::GetVisibilityClient(this); @@ -940,8 +940,8 @@ void Window::SetVisible(bool visible) { NotifyWindowVisibilityChanged(this, visible); - if (dispatcher) - dispatcher->OnWindowVisibilityChanged(this, visible); + if (host) + host->dispatcher()->OnWindowVisibilityChanged(this, visible); } void Window::SchedulePaint() { @@ -1030,7 +1030,7 @@ void Window::RemoveChildImpl(Window* child, Window* new_parent) { Window* root_window = child->GetRootWindow(); Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL; if (root_window && root_window != new_root_window) { - root_window->GetDispatcher()->OnWindowRemovedFromRootWindow( + root_window->GetHost()->dispatcher()->OnWindowRemovedFromRootWindow( child, new_root_window); child->NotifyRemovingFromRootWindow(); } @@ -1344,9 +1344,9 @@ void Window::OnWindowBoundsChanged(const gfx::Rect& old_bounds, FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowBoundsChanged(this, old_bounds, bounds())); - WindowEventDispatcher* dispatcher = GetDispatcher(); - if (dispatcher) - dispatcher->OnWindowBoundsChanged(this, contained_mouse); + WindowTreeHost* host = GetHost(); + if (host) + host->dispatcher()->OnWindowBoundsChanged(this, contained_mouse); } void Window::OnPaintLayer(gfx::Canvas* canvas) { @@ -1385,7 +1385,7 @@ bool Window::CanAcceptEvent(const ui::Event& event) { } ui::EventTarget* Window::GetParentTarget() { - if (dispatcher_) { + if (IsRootWindow()) { return client::GetEventClient(this) ? client::GetEventClient(this)->GetToplevelEventTarget() : Env::GetInstance(); @@ -1426,9 +1426,9 @@ void Window::UpdateLayerName(const std::string& name) { bool Window::ContainsMouse() { bool contains_mouse = false; if (IsVisible()) { - WindowEventDispatcher* dispatcher = GetDispatcher(); - contains_mouse = dispatcher && - ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); + WindowTreeHost* host = GetHost(); + contains_mouse = host && + ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); } return contains_mouse; } diff --git a/ui/aura/window.h b/ui/aura/window.h index 010bf95..d01a331 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -45,8 +45,8 @@ namespace aura { class LayoutManager; class WindowDelegate; -class WindowEventDispatcher; class WindowObserver; +class WindowTreeHost; // Defined in window_property.h (which we do not include) template<typename T> @@ -123,12 +123,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate, virtual Window* GetRootWindow(); virtual const Window* GetRootWindow() const; - WindowEventDispatcher* GetDispatcher(); - const WindowEventDispatcher* GetDispatcher() const; - void set_dispatcher(WindowEventDispatcher* dispatcher) { - dispatcher_ = dispatcher; - } - bool HasDispatcher() const { return !!dispatcher_; } + WindowTreeHost* GetHost(); + const WindowTreeHost* GetHost() const; + void set_host(WindowTreeHost* host) { host_ = host; } + bool IsRootWindow() const { return !!host_; } // The Window does not own this object. void set_user_data(void* user_data) { user_data_ = user_data; } @@ -337,7 +335,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate, private: friend class test::WindowTestApi; friend class LayoutManager; - friend class WindowEventDispatcher; friend class WindowTargeter; // Called by the public {Set,Get,Clear}Property functions. @@ -492,7 +489,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate, // is relative to the parent Window. gfx::Rect bounds_; - WindowEventDispatcher* dispatcher_; + WindowTreeHost* host_; ui::wm::WindowType type_; diff --git a/ui/aura/window_event_dispatcher.cc b/ui/aura/window_event_dispatcher.cc index a071830..98d268e 100644 --- a/ui/aura/window_event_dispatcher.cc +++ b/ui/aura/window_event_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. @@ -24,7 +24,6 @@ #include "ui/aura/window_tracker.h" #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" -#include "ui/base/view_prop.h" #include "ui/compositor/dip_util.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" @@ -41,9 +40,6 @@ namespace aura { namespace { -const char kRootWindowForAcceleratedWidget[] = - "__AURA_ROOT_WINDOW_ACCELERATED_WIDGET__"; - // Returns true if |target| has a non-client (frame) component at |location|, // in window coordinates. bool IsNonClientLocation(Window* target, const gfx::Point& location) { @@ -86,8 +82,7 @@ bool IsEventCandidateForHold(const ui::Event& event) { // WindowEventDispatcher, public: WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) - : window_(new Window(NULL)), - host_(host), + : host_(host), touch_ids_down_(0), mouse_pressed_handler_(NULL), mouse_moved_handler_(NULL), @@ -98,40 +93,12 @@ WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) dispatching_held_event_(false), repost_event_factory_(this), held_event_factory_(this) { - window()->Init(WINDOW_LAYER_NOT_DRAWN); - window()->set_dispatcher(this); - window()->SetName("RootWindow"); - window()->SetEventTargeter( - scoped_ptr<ui::EventTargeter>(new WindowTargeter())); - - prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), - kRootWindowForAcceleratedWidget, - this)); ui::GestureRecognizer::Get()->AddGestureEventHelper(this); } WindowEventDispatcher::~WindowEventDispatcher() { TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); - ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); - - // An observer may have been added by an animation on the - // WindowEventDispatcher. - window()->layer()->GetAnimator()->RemoveObserver(this); - - // Destroy child windows while we're still valid. This is also done by - // ~Window, but by that time any calls to virtual methods overriden here (such - // as GetRootWindow()) result in Window's implementation. By destroying here - // we ensure GetRootWindow() still returns this. - window()->RemoveOrDestroyChildren(); - window()->set_dispatcher(NULL); -} - -// static -WindowEventDispatcher* WindowEventDispatcher::GetForAcceleratedWidget( - gfx::AcceleratedWidget widget) { - return reinterpret_cast<WindowEventDispatcher*>( - ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); } void WindowEventDispatcher::PrepareForShutdown() { diff --git a/ui/aura/window_event_dispatcher.h b/ui/aura/window_event_dispatcher.h index 94ecd77..d1b6bfa 100644 --- a/ui/aura/window_event_dispatcher.h +++ b/ui/aura/window_event_dispatcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. @@ -41,7 +41,6 @@ class LayerAnimationSequence; class MouseEvent; class ScrollEvent; class TouchEvent; -class ViewProp; } namespace aura { @@ -49,7 +48,10 @@ class RootWindowObserver; class TestScreen; class WindowTargeter; -// RootWindow is responsible for hosting a set of windows. +// WindowEventDispatcher orchestrates event dispatch within a window tree +// owned by WindowTreeHost. WTH also owns the WED. +// TODO(beng): In progress, remove functionality not directly related to +// event dispatch. class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, public ui::GestureEventHelper, public ui::LayerAnimationObserver, @@ -59,16 +61,8 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, explicit WindowEventDispatcher(WindowTreeHost* host); virtual ~WindowEventDispatcher(); - // Returns the WindowTreeHost for the specified accelerated widget, or NULL - // if there is none associated. - static WindowEventDispatcher* GetForAcceleratedWidget( - gfx::AcceleratedWidget widget); - - Window* window() { - return const_cast<Window*>( - const_cast<const WindowEventDispatcher*>(this)->window()); - } - const Window* window() const { return window_.get(); } + Window* window() { return host()->window(); } + const Window* window() const { return host()->window(); } WindowTreeHost* host() { return const_cast<WindowTreeHost*>( const_cast<const WindowEventDispatcher*>(this)->host()); @@ -105,7 +99,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // the bounds before change contained the |last_moust_location()|. void OnWindowBoundsChanged(Window* window, bool contained_mouse); - // Dispatches OnMouseExited to the |window| which is hiding if nessessary. + // Dispatches OnMouseExited to the |window| which is hiding if necessary. void DispatchMouseExitToHidingWindow(Window* window); // Dispatches a ui::ET_MOUSE_EXITED event at |point|. @@ -114,13 +108,13 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // Invoked when |window|'s visibility has changed. void OnWindowVisibilityChanged(Window* window, bool is_visible); - // Invoked when |window|'s tranfrom has changed. |contained_mouse| + // Invoked when |window|'s transform has changed. |contained_mouse| // indicates if the bounds before change contained the // |last_moust_location()|. void OnWindowTransformed(Window* window, bool contained_mouse); // Invoked when the keyboard mapping (in X11 terms: the mapping between - // keycodes and keysyms) has changed. + // key-codes and key-syms) has changed. void OnKeyboardMappingChanged(); // The system windowing system has sent a request that we close our window. @@ -271,9 +265,6 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, void PreDispatchMouseEvent(Window* target, ui::MouseEvent* event); void PreDispatchTouchEvent(Window* target, ui::TouchEvent* event); - // TODO(beng): should be owned by WindowTreeHost. - scoped_ptr<Window> window_; - WindowTreeHost* host_; // Touch ids that are currently down. @@ -300,8 +291,6 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // Set when dispatching a held event. bool dispatching_held_event_; - scoped_ptr<ui::ViewProp> prop_; - // Used to schedule reposting an event. base::WeakPtrFactory<WindowEventDispatcher> repost_event_factory_; diff --git a/ui/aura/window_event_dispatcher_unittest.cc b/ui/aura/window_event_dispatcher_unittest.cc index e919c64..f091110 100644 --- a/ui/aura/window_event_dispatcher_unittest.cc +++ b/ui/aura/window_event_dispatcher_unittest.cc @@ -1133,7 +1133,7 @@ class RepostGestureEventRecorder : public EventFilterRecorder { if (!reposted_) { EXPECT_NE(repost_target_, event->target()); reposted_ = true; - repost_target_->GetDispatcher()->RepostEvent(*event); + repost_target_->GetHost()->dispatcher()->RepostEvent(*event); // Ensure that the reposted gesture event above goes to the // repost_target_; repost_source_->GetRootWindow()->RemoveChild(repost_source_); @@ -1351,7 +1351,7 @@ class DontResetHeldEventWindowDelegate : public test::TestWindowDelegate { ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), ui::EF_SHIFT_DOWN, 0); - root_->GetDispatcher()->RepostEvent(mouse_event); + root_->GetHost()->dispatcher()->RepostEvent(mouse_event); } } @@ -1376,7 +1376,7 @@ TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), ui::EF_SHIFT_DOWN, 0); - root_window()->GetDispatcher()->RepostEvent(pressed); + root_window()->GetHost()->dispatcher()->RepostEvent(pressed); ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); // Dispatch an event to flush event scheduled by way of RepostEvent(). @@ -1853,7 +1853,7 @@ class DispatchEventHandler : public ui::EventHandler { ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE); ui::EventDispatchDetails details = - target_->GetDispatcher()->OnEventFromSource(&move); + target_->GetHost()->dispatcher()->OnEventFromSource(&move); ASSERT_FALSE(details.dispatcher_destroyed); EXPECT_FALSE(details.target_destroyed); EXPECT_EQ(target_, move.target()); diff --git a/ui/aura/window_targeter.cc b/ui/aura/window_targeter.cc index a50f981..c0c194e 100644 --- a/ui/aura/window_targeter.cc +++ b/ui/aura/window_targeter.cc @@ -56,7 +56,7 @@ ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, // from here. Instead, dispatch the event through the // WindowEventDispatcher that owns |target|. ui::EventDispatchDetails details ALLOW_UNUSED = - target->GetDispatcher()->OnEventFromSource(event); + target->GetHost()->dispatcher()->OnEventFromSource(event); target = NULL; } } @@ -113,7 +113,7 @@ Window* WindowTargeter::FindTargetInRootWindow(Window* root_window, // Mouse events should be dispatched to the window that processed the // mouse-press events (if any). if (event.IsScrollEvent() || event.IsMouseEvent()) { - WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); + WindowEventDispatcher* dispatcher = root_window->GetHost()->dispatcher(); if (dispatcher->mouse_pressed_handler()) return dispatcher->mouse_pressed_handler(); } diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc index fd3d217..ebaf15c 100644 --- a/ui/aura/window_tree_host.cc +++ b/ui/aura/window_tree_host.cc @@ -9,7 +9,9 @@ #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/base/view_prop.h" #include "ui/compositor/dip_util.h" #include "ui/compositor/layer.h" #include "ui/gfx/display.h" @@ -22,6 +24,9 @@ namespace aura { +const char kWindowTreeHostForAcceleratedWidget[] = + "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; + float GetDeviceScaleFactorFromDisplay(Window* window) { gfx::Display display = gfx::Screen::GetScreenFor(window)-> GetDisplayNearestWindow(window); @@ -77,6 +82,13 @@ WindowTreeHost::~WindowTreeHost() { DCHECK(!compositor_) << "compositor must be destroyed before root window"; } +// static +WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( + gfx::AcceleratedWidget widget) { + return reinterpret_cast<WindowTreeHost*>( + ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); +} + void WindowTreeHost::InitHost() { InitCompositor(); UpdateRootWindowSize(GetBounds().size()); @@ -92,14 +104,6 @@ void WindowTreeHost::InitCompositor() { new SimpleRootWindowTransformer(window(), gfx::Transform())); } -aura::Window* WindowTreeHost::window() { - return const_cast<Window*>(const_cast<const WindowTreeHost*>(this)->window()); -} - -const aura::Window* WindowTreeHost::window() const { - return delegate_->AsDispatcher()->window(); -} - void WindowTreeHost::SetRootWindowTransformer( scoped_ptr<RootWindowTransformer> transformer) { transformer_ = transformer.Pass(); @@ -201,6 +205,7 @@ WindowEventDispatcher* WindowTreeHost::GetDispatcher() { WindowTreeHost::WindowTreeHost() : delegate_(NULL), + window_(new Window(NULL)), last_cursor_(ui::kCursorNull) { } @@ -210,7 +215,22 @@ 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(); + + // TODO(beng): this comment is no longer quite valid since this function + // isn't called from WED, and WED isn't a subclass of Window. So it seems + // like we could just rely on ~Window now. + // Destroy child windows while we're still valid. This is also done by + // ~Window, but by that time any calls to virtual methods overriden here (such + // as GetRootWindow()) result in Window's implementation. By destroying here + // we ensure GetRootWindow() still returns this. + //window()->RemoveOrDestroyChildren(); } void WindowTreeHost::CreateCompositor( @@ -219,8 +239,17 @@ void WindowTreeHost::CreateCompositor( DCHECK(compositor_.get()); // TODO(beng): I think this setup should probably all move to a "accelerated // widget available" function. - if (!dispatcher()) + if (!dispatcher()) { + window()->Init(WINDOW_LAYER_NOT_DRAWN); + window()->set_host(this); + window()->SetName("RootWindow"); + window()->SetEventTargeter( + scoped_ptr<ui::EventTargeter>(new WindowTargeter())); + prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), + kWindowTreeHostForAcceleratedWidget, + this)); dispatcher_.reset(new WindowEventDispatcher(this)); + } delegate_ = dispatcher(); } diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h index 6418791..71e990e 100644 --- a/ui/aura/window_tree_host.h +++ b/ui/aura/window_tree_host.h @@ -23,6 +23,7 @@ class Transform; namespace ui { class Compositor; +class ViewProp; } namespace aura { @@ -40,13 +41,16 @@ class AURA_EXPORT WindowTreeHost { // Creates a new WindowTreeHost. The caller owns the returned value. static WindowTreeHost* Create(const gfx::Rect& bounds); + // Returns the WindowTreeHost for the specified accelerated widget, or NULL + // if there is none associated. + static WindowTreeHost* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); + void InitHost(); void InitCompositor(); - // TODO(beng): these will become trivial accessors in a future CL. - Window* window(); - const Window* window() const; + Window* window() { return window_; } + const Window* window() const { return window_; } WindowEventDispatcher* dispatcher() { return const_cast<WindowEventDispatcher*>( @@ -193,6 +197,12 @@ class AURA_EXPORT WindowTreeHost { void MoveCursorToInternal(const gfx::Point& root_location, const gfx::Point& host_location); + // We don't use a scoped_ptr for |window_| since we need this ptr to be valid + // during its deletion. (Window's dtor notifies observers that may attempt to + // reach back up to access this object which will be valid until the end of + // the dtor). + Window* window_; // Owning. + scoped_ptr<WindowEventDispatcher> dispatcher_; scoped_ptr<ui::Compositor> compositor_; @@ -202,6 +212,8 @@ class AURA_EXPORT WindowTreeHost { // Last cursor set. Used for testing. gfx::NativeCursor last_cursor_; + scoped_ptr<ui::ViewProp> prop_; + DISALLOW_COPY_AND_ASSIGN(WindowTreeHost); }; diff --git a/ui/aura/window_tree_host_win.cc b/ui/aura/window_tree_host_win.cc index 2d592e5..33d50e6 100644 --- a/ui/aura/window_tree_host_win.cc +++ b/ui/aura/window_tree_host_win.cc @@ -170,8 +170,7 @@ void WindowTreeHostWin::ReleaseCapture() { } bool WindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { - client::CursorClient* cursor_client = - client::GetCursorClient(GetDispatcher()->window()); + client::CursorClient* cursor_client = client::GetCursorClient(window()); if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { *location_return = gfx::Point(0, 0); return false; diff --git a/ui/aura/window_tree_host_x11.cc b/ui/aura/window_tree_host_x11.cc index 5f0c6ac..aa8d0c2 100644 --- a/ui/aura/window_tree_host_x11.cc +++ b/ui/aura/window_tree_host_x11.cc @@ -363,7 +363,7 @@ uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) { switch (xev->type) { case EnterNotify: { - aura::Window* root_window = GetDispatcher()->window(); + aura::Window* root_window = window(); client::CursorClient* cursor_client = client::GetCursorClient(root_window); if (cursor_client) { @@ -635,7 +635,7 @@ void WindowTreeHostX11::ReleaseCapture() { bool WindowTreeHostX11::QueryMouseLocation(gfx::Point* location_return) { client::CursorClient* cursor_client = - client::GetCursorClient(GetDispatcher()->window()); + client::GetCursorClient(window()); if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { *location_return = gfx::Point(0, 0); return false; @@ -767,7 +767,7 @@ void WindowTreeHostX11::OnWindowInitialized(Window* window) { } void WindowTreeHostX11::OnRootWindowInitialized( - WindowEventDispatcher* dispatcher) { + WindowEventDispatcher* d) { // UpdateIsInternalDisplay relies on: // 1. delegate_ pointing to WindowEventDispatcher - available after // SetDelegate. @@ -775,7 +775,7 @@ void WindowTreeHostX11::OnRootWindowInitialized( // WED::Init is called. // (set in DisplayManager::CreateRootWindowForDisplay) // Ready when NotifyRootWindowInitialized is called from WED::Init. - if (!delegate_ || dispatcher != GetDispatcher()) + if (!delegate_ || d != dispatcher()) return; UpdateIsInternalDisplay(); @@ -930,7 +930,7 @@ void WindowTreeHostX11::SetCursorInternal(gfx::NativeCursor cursor) { void WindowTreeHostX11::TranslateAndDispatchMouseEvent( ui::MouseEvent* event) { - Window* root_window = GetDispatcher()->window(); + Window* root_window = window(); client::ScreenPositionClient* screen_position_client = client::GetScreenPositionClient(root_window); gfx::Rect local(bounds_.size()); @@ -951,7 +951,7 @@ void WindowTreeHostX11::TranslateAndDispatchMouseEvent( } void WindowTreeHostX11::UpdateIsInternalDisplay() { - Window* root_window = GetDispatcher()->window(); + Window* root_window = window(); gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); gfx::Display display = screen->GetDisplayNearestWindow(root_window); is_internal_display_ = display.IsInternal(); diff --git a/ui/keyboard/keyboard_ui_handler.cc b/ui/keyboard/keyboard_ui_handler.cc index c2398ca..c0873b8 100644 --- a/ui/keyboard/keyboard_ui_handler.cc +++ b/ui/keyboard/keyboard_ui_handler.cc @@ -115,8 +115,8 @@ void KeyboardUIHandler::HandleSendKeyEventMessage( return; } - aura::WindowEventDispatcher* dispatcher = - web_ui()->GetWebContents()->GetView()->GetNativeView()->GetDispatcher(); + aura::WindowEventDispatcher* dispatcher = web_ui()->GetWebContents()-> + GetView()->GetNativeView()->GetHost()->dispatcher(); if (!dispatcher) { LOG(ERROR) << "sendKeyEvent failed: no dispatcher"; return; diff --git a/ui/keyboard/keyboard_util.h b/ui/keyboard/keyboard_util.h index 51001fe..2e37a2e 100644 --- a/ui/keyboard/keyboard_util.h +++ b/ui/keyboard/keyboard_util.h @@ -14,6 +14,10 @@ struct GritResourceMap; +namespace aura { +class WindowEventDispatcher; +} + namespace keyboard { // Enumeration of swipe directions. diff --git a/ui/shell_dialogs/select_file_dialog_win.cc b/ui/shell_dialogs/select_file_dialog_win.cc index 9ae2137..7a8e2e6 100644 --- a/ui/shell_dialogs/select_file_dialog_win.cc +++ b/ui/shell_dialogs/select_file_dialog_win.cc @@ -601,7 +601,7 @@ void SelectFileDialogImpl::SelectFileImpl( } } HWND owner = owning_window && owning_window->GetRootWindow() - ? owning_window->GetDispatcher()->host()->GetAcceleratedWidget() : NULL; + ? owning_window->GetHost()->GetAcceleratedWidget() : NULL; #else HWND owner = owning_window; #endif @@ -623,7 +623,7 @@ bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow owning_window) const { #if defined(USE_AURA) if (!owning_window->GetRootWindow()) return false; - HWND owner = owning_window->GetDispatcher()->host()->GetAcceleratedWidget(); + HWND owner = owning_window->GetHost()->GetAcceleratedWidget(); #else HWND owner = owning_window; #endif diff --git a/ui/views/corewm/capture_controller.cc b/ui/views/corewm/capture_controller.cc index 686e877..daa34dd1 100644 --- a/ui/views/corewm/capture_controller.cc +++ b/ui/views/corewm/capture_controller.cc @@ -57,7 +57,7 @@ void CaptureController::SetCapture(aura::Window* new_capture_window) { for (RootWindows::const_iterator i = root_windows.begin(); i != root_windows.end(); ++i) { - aura::client::CaptureDelegate* delegate = (*i)->GetDispatcher(); + aura::client::CaptureDelegate* delegate = (*i)->GetHost()->dispatcher(); delegate->UpdateCapture(old_capture_window, new_capture_window); } @@ -66,11 +66,12 @@ void CaptureController::SetCapture(aura::Window* new_capture_window) { if (capture_root != old_capture_root) { if (old_capture_root) { aura::client::CaptureDelegate* delegate = - old_capture_root->GetDispatcher(); + old_capture_root->GetHost()->dispatcher(); delegate->ReleaseNativeCapture(); } if (capture_root) { - aura::client::CaptureDelegate* delegate = capture_root->GetDispatcher(); + aura::client::CaptureDelegate* delegate = + capture_root->GetHost()->dispatcher(); delegate->SetNativeCapture(); } } diff --git a/ui/views/corewm/capture_controller_unittest.cc b/ui/views/corewm/capture_controller_unittest.cc index cf622d4..9f53768 100644 --- a/ui/views/corewm/capture_controller_unittest.cc +++ b/ui/views/corewm/capture_controller_unittest.cc @@ -42,14 +42,11 @@ class CaptureControllerTest : public aura::test::AuraTestBase { new corewm::ScopedCaptureClient(second_host_->window())); #if !defined(OS_CHROMEOS) - desktop_position_client_.reset(new DesktopScreenPositionClient()); - aura::client::SetScreenPositionClient(root_window(), - desktop_position_client_.get()); - - second_desktop_position_client_.reset(new DesktopScreenPositionClient()); - aura::client::SetScreenPositionClient( - second_host_->window(), - second_desktop_position_client_.get()); + desktop_position_client_.reset( + new DesktopScreenPositionClient(root_window())); + + second_desktop_position_client_.reset( + new DesktopScreenPositionClient(second_host_->window())); #endif } diff --git a/ui/views/corewm/desktop_capture_controller_unittest.cc b/ui/views/corewm/desktop_capture_controller_unittest.cc index 504b3dd..18b3976 100644 --- a/ui/views/corewm/desktop_capture_controller_unittest.cc +++ b/ui/views/corewm/desktop_capture_controller_unittest.cc @@ -73,7 +73,7 @@ TEST_F(DesktopCaptureControllerTest, ResetMouseHandlers) { generator1.PressLeftButton(); EXPECT_FALSE(w1->HasCapture()); aura::WindowEventDispatcher* w1_dispatcher = - w1->GetNativeView()->GetDispatcher(); + w1->GetNativeView()->GetHost()->dispatcher(); EXPECT_TRUE(w1_dispatcher->mouse_pressed_handler() != NULL); EXPECT_TRUE(w1_dispatcher->mouse_moved_handler() != NULL); w2->SetCapture(w2->GetRootView()); @@ -105,7 +105,8 @@ TEST_F(DesktopCaptureControllerTest, CaptureWindowInputEventTest) { internal::RootView* root1 = static_cast<internal::RootView*>(widget1->GetRootView()); - desktop_position_client1.reset(new DesktopScreenPositionClient()); + desktop_position_client1.reset( + new DesktopScreenPositionClient(params.context->GetRootWindow())); aura::client::SetScreenPositionClient( widget1->GetNativeView()->GetRootWindow(), desktop_position_client1.get()); @@ -124,7 +125,8 @@ TEST_F(DesktopCaptureControllerTest, CaptureWindowInputEventTest) { internal::RootView* root2 = static_cast<internal::RootView*>(widget2->GetRootView()); - desktop_position_client2.reset(new DesktopScreenPositionClient()); + desktop_position_client2.reset( + new DesktopScreenPositionClient(params.context->GetRootWindow())); aura::client::SetScreenPositionClient( widget2->GetNativeView()->GetRootWindow(), desktop_position_client2.get()); diff --git a/ui/views/corewm/input_method_event_filter.cc b/ui/views/corewm/input_method_event_filter.cc index 0d1672a..cd7943c 100644 --- a/ui/views/corewm/input_method_event_filter.cc +++ b/ui/views/corewm/input_method_event_filter.cc @@ -47,7 +47,7 @@ void InputMethodEventFilter::OnKeyEvent(ui::KeyEvent* event) { // If the focused window is changed, all requests to IME will be // discarded so it's safe to update the target_dispatcher_ here. aura::Window* target = static_cast<aura::Window*>(event->target()); - target_dispatcher_ = target->GetRootWindow()->GetDispatcher(); + target_dispatcher_ = target->GetRootWindow()->GetHost()->dispatcher(); DCHECK(target_dispatcher_); if (input_method_->DispatchKeyEvent(*event)) event->StopPropagation(); diff --git a/ui/views/corewm/input_method_event_filter.h b/ui/views/corewm/input_method_event_filter.h index 6f6e6b8..cb76c1f 100644 --- a/ui/views/corewm/input_method_event_filter.h +++ b/ui/views/corewm/input_method_event_filter.h @@ -13,6 +13,10 @@ #include "ui/events/event_handler.h" #include "ui/views/views_export.h" +namespace aura { +class WindowEventDispatcher; +} + namespace ui { class InputMethod; } diff --git a/ui/views/corewm/tooltip_aura.cc b/ui/views/corewm/tooltip_aura.cc index 5ba5989..eb2149c 100644 --- a/ui/views/corewm/tooltip_aura.cc +++ b/ui/views/corewm/tooltip_aura.cc @@ -169,7 +169,7 @@ gfx::Rect TooltipAura::GetBoundsForTooltip( // (which comes from the RootWindow). if (screen_type_ == gfx::SCREEN_TYPE_NATIVE && gfx::SCREEN_TYPE_NATIVE != gfx::SCREEN_TYPE_ALTERNATE) { - widget_bounds = tooltip_window_->GetDispatcher()->host()->GetBounds(); + widget_bounds = tooltip_window_->GetHost()->GetBounds(); } gfx::Screen* screen = gfx::Screen::GetScreenByType(screen_type_); gfx::Rect bounds(screen->GetDisplayNearestPoint(origin).bounds()); diff --git a/ui/views/event_utils_aura.cc b/ui/views/event_utils_aura.cc index 4ac21d1..6bdc2ea3 100644 --- a/ui/views/event_utils_aura.cc +++ b/ui/views/event_utils_aura.cc @@ -31,7 +31,7 @@ bool RepostLocatedEvent(gfx::NativeWindow window, } else { if (ViewsDelegate::views_delegate && !ViewsDelegate::views_delegate->IsWindowInMetro(window)) - target_window = window->GetDispatcher()->host()->GetAcceleratedWidget(); + target_window = window->GetHost()->GetAcceleratedWidget(); } return RepostLocatedEventWin(target_window, event); #endif @@ -63,7 +63,7 @@ bool RepostLocatedEvent(gfx::NativeWindow window, relocated->set_location(root_loc); relocated->set_root_location(root_loc); - root_window->GetDispatcher()->RepostEvent(*relocated); + root_window->GetHost()->dispatcher()->RepostEvent(*relocated); return true; } diff --git a/ui/views/test/ui_controls_factory_desktop_aurax11.cc b/ui/views/test/ui_controls_factory_desktop_aurax11.cc index 2819c5b..75abae60 100644 --- a/ui/views/test/ui_controls_factory_desktop_aurax11.cc +++ b/ui/views/test/ui_controls_factory_desktop_aurax11.cc @@ -125,33 +125,31 @@ class UIControlsDesktopX11 : public UIControlsAura { const base::Closure& closure) OVERRIDE { DCHECK(!command); // No command key on Aura - aura::WindowEventDispatcher* dispatcher = window->GetDispatcher(); + aura::WindowTreeHost* host = window->GetHost(); XEvent xevent = {0}; xevent.xkey.type = KeyPress; if (control) { - SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Control_L, - ControlMask); + SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); } if (shift) - SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Shift_L, ShiftMask); + SetKeycodeAndSendThenMask(host, &xevent, XK_Shift_L, ShiftMask); if (alt) - SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Alt_L, Mod1Mask); + SetKeycodeAndSendThenMask(host, &xevent, XK_Alt_L, Mod1Mask); xevent.xkey.keycode = XKeysymToKeycode(x_display_, ui::XKeysymForWindowsKeyCode(key, shift)); - dispatcher->host()->PostNativeEvent(&xevent); + host->PostNativeEvent(&xevent); // Send key release events. xevent.xkey.type = KeyRelease; - dispatcher->host()->PostNativeEvent(&xevent); + host->PostNativeEvent(&xevent); if (alt) - UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, Mod1Mask, XK_Alt_L); + UnmaskAndSetKeycodeThenSend(host, &xevent, Mod1Mask, XK_Alt_L); if (shift) - UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ShiftMask, XK_Shift_L); + UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); if (control) { - UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ControlMask, - XK_Control_L); + UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); } DCHECK(!xevent.xkey.state); RunClosureAfterAllPendingUIEvents(closure); @@ -176,10 +174,10 @@ class UIControlsDesktopX11 : public UIControlsAura { &root_location); } - aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); + aura::WindowTreeHost* host = root_window->GetHost(); gfx::Point root_current_location; - dispatcher->host()->QueryMouseLocation(&root_current_location); - dispatcher->host()->ConvertPointFromHost(&root_current_location); + host->QueryMouseLocation(&root_current_location); + host->ConvertPointFromHost(&root_current_location); if (root_location != root_current_location && button_down_mask == 0) { // Move the cursor because EnterNotify/LeaveNotify are generated with the @@ -194,7 +192,7 @@ class UIControlsDesktopX11 : public UIControlsAura { xmotion->state = button_down_mask; xmotion->same_screen = True; // RootWindow will take care of other necessary fields. - dispatcher->host()->PostNativeEvent(&xevent); + host->PostNativeEvent(&xevent); } RunClosureAfterAllPendingUIEvents(closure); return true; @@ -234,12 +232,12 @@ class UIControlsDesktopX11 : public UIControlsAura { // RootWindow will take care of other necessary fields. if (state & DOWN) { xevent.xbutton.type = ButtonPress; - root_window->GetDispatcher()->host()->PostNativeEvent(&xevent); + root_window->GetHost()->PostNativeEvent(&xevent); button_down_mask |= xbutton->state; } if (state & UP) { xevent.xbutton.type = ButtonRelease; - root_window->GetDispatcher()->host()->PostNativeEvent(&xevent); + root_window->GetHost()->PostNativeEvent(&xevent); button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; } RunClosureAfterAllPendingUIEvents(closure); @@ -285,22 +283,22 @@ class UIControlsDesktopX11 : public UIControlsAura { return NULL; } - void SetKeycodeAndSendThenMask(aura::WindowEventDispatcher* dispatcher, + void SetKeycodeAndSendThenMask(aura::WindowTreeHost* host, XEvent* xevent, KeySym keysym, unsigned int mask) { xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); - dispatcher->host()->PostNativeEvent(xevent); + host->PostNativeEvent(xevent); xevent->xkey.state |= mask; } - void UnmaskAndSetKeycodeThenSend(aura::WindowEventDispatcher* dispatcher, + void UnmaskAndSetKeycodeThenSend(aura::WindowTreeHost* host, XEvent* xevent, unsigned int mask, KeySym keysym) { xevent->xkey.state ^= mask; xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); - dispatcher->host()->PostNativeEvent(xevent); + host->PostNativeEvent(xevent); } // Our X11 state. diff --git a/ui/views/widget/desktop_aura/desktop_capture_client.cc b/ui/views/widget/desktop_aura/desktop_capture_client.cc index 121c0a2..3367f86 100644 --- a/ui/views/widget/desktop_aura/desktop_capture_client.cc +++ b/ui/views/widget/desktop_aura/desktop_capture_client.cc @@ -52,7 +52,7 @@ void DesktopCaptureClient::SetCapture(aura::Window* new_capture_window) { capture_window_ = new_capture_window; - aura::client::CaptureDelegate* delegate = root_->GetDispatcher(); + aura::client::CaptureDelegate* delegate = root_->GetHost()->dispatcher(); delegate->UpdateCapture(old_capture_window, new_capture_window); // Initiate native capture updating. @@ -67,7 +67,8 @@ void DesktopCaptureClient::SetCapture(aura::Window* new_capture_window) { for (CaptureClients::iterator i = capture_clients.begin(); i != capture_clients.end(); ++i) { if (*i != this) { - aura::client::CaptureDelegate* delegate = (*i)->root_->GetDispatcher(); + aura::client::CaptureDelegate* delegate = + (*i)->root_->GetHost()->dispatcher(); delegate->OnOtherRootGotCapture(); } } diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc index ef65d68..e92b270 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc @@ -691,7 +691,7 @@ void DesktopDragDropClientAuraX11::DragTranslate( scoped_ptr<ui::DropTargetEvent>* event, aura::client::DragDropDelegate** delegate) { gfx::Point root_location = root_window_location; - root_window_->GetDispatcher()->host()->ConvertPointFromNativeScreen( + root_window_->GetHost()->ConvertPointFromNativeScreen( &root_location); aura::Window* target_window = root_window_->GetEventHandlerForPoint(root_location); diff --git a/ui/views/widget/desktop_aura/desktop_drop_target_win.cc b/ui/views/widget/desktop_aura/desktop_drop_target_win.cc index 665f282..26eeb89 100644 --- a/ui/views/widget/desktop_aura/desktop_drop_target_win.cc +++ b/ui/views/widget/desktop_aura/desktop_drop_target_win.cc @@ -96,7 +96,7 @@ void DesktopDropTargetWin::Translate( DragDropDelegate** delegate) { gfx::Point location(position.x, position.y); gfx::Point root_location = location; - root_window_->GetDispatcher()->host()->ConvertPointFromNativeScreen( + root_window_->GetHost()->ConvertPointFromNativeScreen( &root_location); aura::Window* target_window = root_window_->GetEventHandlerForPoint(root_location); diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc index d373a0c..f6ecab3 100644 --- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc @@ -470,9 +470,7 @@ void DesktopNativeWidgetAura::InitNativeWidget( aura::client::SetDispatcherClient(host_->window(), dispatcher_client_.get()); - position_client_.reset(new DesktopScreenPositionClient()); - aura::client::SetScreenPositionClient(host_->window(), - position_client_.get()); + position_client_.reset(new DesktopScreenPositionClient(host_->window())); InstallInputMethodEventFilter(); 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 23018c5..b5187f5 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_position_client.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_position_client.cc @@ -16,7 +16,7 @@ namespace { gfx::Point GetOrigin(const aura::Window* root_window) { gfx::Point origin_in_pixels = - root_window->GetDispatcher()->host()->GetBounds().origin(); + root_window->GetHost()->GetBounds().origin(); aura::Window* window = const_cast<aura::Window*>(root_window); float scale = gfx::Screen::GetScreenFor(window)-> GetDisplayNearestWindow(window).device_scale_factor(); @@ -37,10 +37,13 @@ bool PositionWindowInScreenCoordinates(aura::Window* window) { } // namespace -DesktopScreenPositionClient::DesktopScreenPositionClient() { +DesktopScreenPositionClient::DesktopScreenPositionClient( + aura::Window* root_window) : root_window_(root_window) { + aura::client::SetScreenPositionClient(root_window_, this); } DesktopScreenPositionClient::~DesktopScreenPositionClient() { + aura::client::SetScreenPositionClient(root_window_, NULL); } void DesktopScreenPositionClient::ConvertPointToScreen( @@ -92,7 +95,7 @@ void DesktopScreenPositionClient::SetBounds( desktop_native_widget->GetNativeView() == window) { // |window| is the content_window. // Setting bounds of root resizes |window|. - root->GetDispatcher()->host()->SetBounds(bounds); + root->GetHost()->SetBounds(bounds); } else { window->SetBounds(bounds); } 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 da8ad40..222c2a1 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_position_client.h +++ b/ui/views/widget/desktop_aura/desktop_screen_position_client.h @@ -15,7 +15,7 @@ namespace views { class VIEWS_EXPORT DesktopScreenPositionClient : public aura::client::ScreenPositionClient { public: - DesktopScreenPositionClient(); + explicit DesktopScreenPositionClient(aura::Window* root_window); virtual ~DesktopScreenPositionClient(); // aura::client::ScreenPositionClient overrides: @@ -28,6 +28,11 @@ class VIEWS_EXPORT DesktopScreenPositionClient virtual void SetBounds(aura::Window* window, const gfx::Rect& bounds, const gfx::Display& display) OVERRIDE; + + private: + aura::Window* root_window_; + + DISALLOW_COPY_AND_ASSIGN(DesktopScreenPositionClient); }; } // namespace views diff --git a/ui/views/widget/desktop_aura/desktop_screen_win.cc b/ui/views/widget/desktop_aura/desktop_screen_win.cc index 5cf42f5..c5edf76 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_win.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_win.cc @@ -54,8 +54,8 @@ gfx::Display DesktopScreenWin::GetDisplayMatching( } HWND DesktopScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { - aura::WindowEventDispatcher* dispatcher = window->GetDispatcher(); - return dispatcher ? dispatcher->host()->GetAcceleratedWidget() : NULL; + aura::WindowTreeHost* host = window->GetHost(); + return host ? host->GetAcceleratedWidget() : NULL; } gfx::NativeWindow DesktopScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/ui/views/widget/desktop_aura/desktop_screen_x11.cc index a72b503..c47a2d2 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_x11.cc @@ -249,10 +249,10 @@ gfx::Display DesktopScreenX11::GetDisplayNearestWindow( // created before we create the aura::WindowEventDispatcher. So we ask what // the DRWHX11 believes the window bounds are instead of going through the // aura::Window's screen bounds. - aura::WindowEventDispatcher* dispatcher = window->GetDispatcher(); - if (dispatcher) { + aura::WindowTreeHost* host = window->GetHost(); + if (host) { DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( - dispatcher->host()->GetAcceleratedWidget()); + host->GetAcceleratedWidget()); if (rwh) return GetDisplayMatching(rwh->GetX11RootWindowBounds()); } diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc b/ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc index da4d1fd..3f2a610 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc @@ -39,7 +39,7 @@ class ActivationWaiter : public base::MessagePumpDispatcher { NULL }; atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); - widget_xid_ = widget->GetNativeWindow()->GetDispatcher()->host()-> + widget_xid_ = widget->GetNativeWindow()->GetHost()-> GetAcceleratedWidget(); base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); } 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 02a7e43..8375e6d 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 @@ -98,20 +98,18 @@ DesktopWindowTreeHostWin::~DesktopWindowTreeHostWin() { // static aura::Window* DesktopWindowTreeHostWin::GetContentWindowForHWND(HWND hwnd) { - aura::WindowEventDispatcher* dispatcher = - aura::WindowEventDispatcher::GetForAcceleratedWidget(hwnd); - return dispatcher ? - dispatcher->window()->GetProperty(kContentWindowForRootWindow) : NULL; + aura::WindowTreeHost* host = + aura::WindowTreeHost::GetForAcceleratedWidget(hwnd); + return host ? host->window()->GetProperty(kContentWindowForRootWindow) : NULL; } // static ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { // Use NativeThemeWin for windows shown on the desktop, those not on the // desktop come from Ash and get NativeThemeAura. - aura::WindowEventDispatcher* dispatcher = - window ? window->GetDispatcher() : NULL; - if (dispatcher) { - HWND host_hwnd = dispatcher->host()->GetAcceleratedWidget(); + aura::WindowTreeHost* host = window ? window->GetHost() : NULL; + if (host) { + HWND host_hwnd = host->GetAcceleratedWidget(); if (host_hwnd && DesktopWindowTreeHostWin::GetContentWindowForHWND(host_hwnd)) { return ui::NativeThemeWin::instance(); @@ -135,10 +133,8 @@ void DesktopWindowTreeHostWin::Init(aura::Window* content_window, native_widget_delegate_); HWND parent_hwnd = NULL; - if (params.parent && params.parent->GetDispatcher()) { - parent_hwnd = - params.parent->GetDispatcher()->host()->GetAcceleratedWidget(); - } + if (params.parent && params.parent->GetHost()) + parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget(); message_handler_->set_remove_standard_frame(params.remove_standard_frame); @@ -880,11 +876,11 @@ void DesktopWindowTreeHostWin::HandleTouchEvent( return; // Currently we assume the window that has capture gets touch events too. - aura::WindowEventDispatcher* dispatcher = - aura::WindowEventDispatcher::GetForAcceleratedWidget(GetCapture()); - if (dispatcher) { + aura::WindowTreeHost* host = + aura::WindowTreeHost::GetForAcceleratedWidget(GetCapture()); + if (host) { DesktopWindowTreeHostWin* target = - dispatcher->window()->GetProperty(kDesktopWindowTreeHostKey); + host->window()->GetProperty(kDesktopWindowTreeHostKey); if (target && target->HasCapture() && target != this) { POINT target_location(event.location().ToPOINT()); ClientToScreen(GetHWND(), &target_location); 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 9cbe512..785a816 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 @@ -154,18 +154,16 @@ DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { // static aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { - aura::WindowEventDispatcher* dispatcher = - aura::WindowEventDispatcher::GetForAcceleratedWidget(xid); - return dispatcher ? - dispatcher->window()->GetProperty(kViewsWindowForRootWindow) : NULL; + aura::WindowTreeHost* host = + aura::WindowTreeHost::GetForAcceleratedWidget(xid); + return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL; } // static DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::GetHostForXID(XID xid) { - aura::WindowEventDispatcher* dispatcher = - aura::WindowEventDispatcher::GetForAcceleratedWidget(xid); - return dispatcher ? - dispatcher->window()->GetProperty(kHostForRootWindow) : NULL; + aura::WindowTreeHost* host = + aura::WindowTreeHost::GetForAcceleratedWidget(xid); + return host ? host->window()->GetProperty(kHostForRootWindow) : NULL; } // static @@ -839,7 +837,7 @@ void DesktopWindowTreeHostX11::ReleaseCapture() { bool DesktopWindowTreeHostX11::QueryMouseLocation( gfx::Point* location_return) { aura::client::CursorClient* cursor_client = - aura::client::GetCursorClient(GetDispatcher()->window()); + aura::client::GetCursorClient(window()); if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { *location_return = gfx::Point(0, 0); return false; @@ -1078,9 +1076,9 @@ void DesktopWindowTreeHostX11::InitX11Window( // If we have a parent, record the parent/child relationship. We use this // data during destruction to make sure that when we try to close a parent // window, we also destroy all child windows. - if (params.parent && params.parent->GetDispatcher()) { + if (params.parent && params.parent->GetHost()) { XID parent_xid = - params.parent->GetDispatcher()->host()->GetAcceleratedWidget(); + params.parent->GetHost()->GetAcceleratedWidget(); window_parent_ = GetHostForXID(parent_xid); DCHECK(window_parent_); window_parent_->window_children_.insert(this); diff --git a/ui/views/widget/desktop_aura/x11_desktop_window_move_client.cc b/ui/views/widget/desktop_aura/x11_desktop_window_move_client.cc index 1c3da3b..072d1ef 100644 --- a/ui/views/widget/desktop_aura/x11_desktop_window_move_client.cc +++ b/ui/views/widget/desktop_aura/x11_desktop_window_move_client.cc @@ -76,7 +76,7 @@ aura::client::WindowMoveResult X11DesktopWindowMoveClient::RunMoveLoop( const gfx::Vector2d& drag_offset, aura::client::WindowMoveSource move_source) { window_offset_ = drag_offset; - dispatcher_ = source->GetDispatcher(); + dispatcher_ = source->GetHost()->dispatcher(); bool success = move_loop_.RunMoveLoop(source, dispatcher_->host()->last_cursor()); diff --git a/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc b/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc index ce066da5..9fd02a3 100644 --- a/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc +++ b/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc @@ -110,7 +110,7 @@ bool X11WholeScreenMoveLoop::RunMoveLoop(aura::Window* source, // get released while we still need the pointer grab, which is why we restrict // the scope here. { - ScopedCapturer capturer(source->GetDispatcher()->host()); + ScopedCapturer capturer(source->GetHost()); DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. in_move_loop_ = true; diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index ecf524f..e4c6670 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -46,7 +46,7 @@ class NativeWidgetAuraTest : public ViewsTestBase { protected: aura::Window* root_window() { return GetContext(); } aura::WindowEventDispatcher* dispatcher() { - return root_window()->GetDispatcher(); + return root_window()->GetHost()->dispatcher(); } private: diff --git a/ui/views/widget/tooltip_manager_aura.cc b/ui/views/widget/tooltip_manager_aura.cc index 05a96e5..8208063 100644 --- a/ui/views/widget/tooltip_manager_aura.cc +++ b/ui/views/widget/tooltip_manager_aura.cc @@ -49,7 +49,7 @@ void TooltipManagerAura::UpdateTooltipManagerForCapture(Widget* source) { return; gfx::Point screen_loc( - root_window->GetDispatcher()->GetLastMouseLocationInRoot()); + root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()); aura::client::ScreenPositionClient* screen_position_client = aura::client::GetScreenPositionClient(root_window); if (!screen_position_client) @@ -91,7 +91,7 @@ void TooltipManagerAura::UpdateTooltip() { aura::Window* root_window = GetWindow()->GetRootWindow(); if (aura::client::GetTooltipClient(root_window)) { gfx::Point view_point = - root_window->GetDispatcher()->GetLastMouseLocationInRoot(); + root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point); View* view = GetViewUnderPoint(view_point); UpdateTooltipForTarget(view, view_point, root_window); @@ -102,7 +102,7 @@ void TooltipManagerAura::TooltipTextChanged(View* view) { aura::Window* root_window = GetWindow()->GetRootWindow(); if (aura::client::GetTooltipClient(root_window)) { gfx::Point view_point = - root_window->GetDispatcher()->GetLastMouseLocationInRoot(); + root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); aura::Window::ConvertPointToTarget(root_window, GetWindow(), &view_point); View* target = GetViewUnderPoint(view_point); if (target != view) diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc index f39cbfc..8c8bbe2 100644 --- a/ui/views/widget/widget_interactive_uitest.cc +++ b/ui/views/widget/widget_interactive_uitest.cc @@ -192,7 +192,7 @@ TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) { aura::Window* root_window2 = widget2.GetNativeView()->GetRootWindow(); contents_view2->RequestFocus(); ::SetActiveWindow( - root_window2->GetDispatcher()->host()->GetAcceleratedWidget()); + root_window2->GetHost()->GetAcceleratedWidget()); aura::client::ActivationClient* activation_client2 = aura::client::GetActivationClient(root_window2); @@ -205,7 +205,7 @@ TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) { // window. contents_view1->RequestFocus(); ::SetActiveWindow( - root_window1->GetDispatcher()->host()->GetAcceleratedWidget()); + root_window1->GetHost()->GetAcceleratedWidget()); EXPECT_EQ(activation_client2->GetActiveWindow(), reinterpret_cast<aura::Window*>(NULL)); EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); @@ -778,7 +778,7 @@ TEST_F(WidgetCaptureTest, MAYBE_MouseEventDispatchedToRightWindow) { ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), ui::EF_NONE, ui::EF_NONE); ui::EventDispatchDetails details = widget1.GetNativeWindow()-> - GetDispatcher()->OnEventFromSource(&mouse_event); + GetHost()->dispatcher()->OnEventFromSource(&mouse_event); ASSERT_FALSE(details.dispatcher_destroyed); EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc index adecf03..1b10418 100644 --- a/ui/views/widget/widget_unittest.cc +++ b/ui/views/widget/widget_unittest.cc @@ -1295,7 +1295,7 @@ void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), screen_bounds.CenterPoint(), 0, 0); aura::WindowEventDispatcher* dispatcher = - widget->GetNativeWindow()->GetDispatcher(); + widget->GetNativeWindow()->GetHost()->dispatcher(); ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) return; @@ -2065,7 +2065,7 @@ TEST_F(WidgetTest, WindowMouseModalityTest) { ui::EF_NONE, ui::EF_NONE); ui::EventDispatchDetails details = top_level_widget.GetNativeView()-> - GetDispatcher()->OnEventFromSource(&move_main); + GetHost()->dispatcher()->OnEventFromSource(&move_main); ASSERT_FALSE(details.dispatcher_destroyed); EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); @@ -2092,7 +2092,7 @@ TEST_F(WidgetTest, WindowMouseModalityTest) { cursor_location_dialog, ui::EF_NONE, ui::EF_NONE); - details = top_level_widget.GetNativeView()->GetDispatcher()-> + details = top_level_widget.GetNativeView()->GetHost()->dispatcher()-> OnEventFromSource(&mouse_down_dialog); ASSERT_FALSE(details.dispatcher_destroyed); EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); @@ -2105,7 +2105,7 @@ TEST_F(WidgetTest, WindowMouseModalityTest) { cursor_location_main2, ui::EF_NONE, ui::EF_NONE); - details = top_level_widget.GetNativeView()->GetDispatcher()-> + details = top_level_widget.GetNativeView()->GetHost()->dispatcher()-> OnEventFromSource(&mouse_down_main); ASSERT_FALSE(details.dispatcher_destroyed); EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); diff --git a/ui/views/win/hwnd_util_aurawin.cc b/ui/views/win/hwnd_util_aurawin.cc index da4275e..76e6e90 100644 --- a/ui/views/win/hwnd_util_aurawin.cc +++ b/ui/views/win/hwnd_util_aurawin.cc @@ -20,21 +20,20 @@ HWND HWNDForWidget(const Widget* widget) { HWND HWNDForNativeView(const gfx::NativeView view) { return view && view->GetRootWindow() ? - view->GetDispatcher()->host()->GetAcceleratedWidget() : NULL; + view->GetHost()->GetAcceleratedWidget() : NULL; } HWND HWNDForNativeWindow(const gfx::NativeWindow window) { return window && window->GetRootWindow() ? - window->GetDispatcher()->host()->GetAcceleratedWidget() : NULL; + window->GetHost()->GetAcceleratedWidget() : NULL; } gfx::Rect GetWindowBoundsForClientBounds(View* view, const gfx::Rect& client_bounds) { DCHECK(view); - aura::WindowEventDispatcher* dispatcher = - view->GetWidget()->GetNativeWindow()->GetDispatcher(); - if (dispatcher) { - HWND hwnd = dispatcher->host()->GetAcceleratedWidget(); + aura::WindowTreeHost* host = view->GetWidget()->GetNativeWindow()->GetHost(); + if (host) { + HWND hwnd = host->GetAcceleratedWidget(); RECT rect = client_bounds.ToRECT(); DWORD style = ::GetWindowLong(hwnd, GWL_STYLE); DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); |