diff options
-rw-r--r-- | ash/accelerators/accelerator_dispatcher_linux.cc | 3 | ||||
-rw-r--r-- | ash/accelerators/accelerator_dispatcher_win.cc | 3 | ||||
-rw-r--r-- | ash/drag_drop/drag_drop_controller.cc | 3 | ||||
-rw-r--r-- | ash/wm/toplevel_window_event_filter.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/simple_message_box_views.cc | 3 | ||||
-rw-r--r-- | ui/aura/aura.gyp | 1 | ||||
-rw-r--r-- | ui/aura/dispatcher_win.cc | 34 | ||||
-rw-r--r-- | ui/aura/env.cc | 23 | ||||
-rw-r--r-- | ui/aura/env.h | 17 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 6 | ||||
-rw-r--r-- | ui/aura/root_window.h | 10 | ||||
-rw-r--r-- | ui/aura/root_window_host.h | 7 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 5 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.cc | 7 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.h | 3 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.cc | 3 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_controller.cc | 5 | ||||
-rw-r--r-- | ui/views/test/views_test_base.cc | 3 |
18 files changed, 105 insertions, 34 deletions
diff --git a/ash/accelerators/accelerator_dispatcher_linux.cc b/ash/accelerators/accelerator_dispatcher_linux.cc index 05d28c5..4743e94 100644 --- a/ash/accelerators/accelerator_dispatcher_linux.cc +++ b/ash/accelerators/accelerator_dispatcher_linux.cc @@ -13,6 +13,7 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/shell.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" #include "ui/base/accelerators/accelerator.h" @@ -31,7 +32,7 @@ base::MessagePumpDispatcher::DispatchStatus AcceleratorDispatcher::Dispatch( if (!associated_window_) return EVENT_QUIT; if (!associated_window_->CanReceiveEvents()) - return Shell::GetRootWindow()->GetDispatcher()->Dispatch(xev); + return aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev); if (xev->type == KeyPress) { ash::AcceleratorController* accelerator_controller = diff --git a/ash/accelerators/accelerator_dispatcher_win.cc b/ash/accelerators/accelerator_dispatcher_win.cc index 8a64f6c..2aeceda 100644 --- a/ash/accelerators/accelerator_dispatcher_win.cc +++ b/ash/accelerators/accelerator_dispatcher_win.cc @@ -6,6 +6,7 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/shell.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" #include "ui/base/accelerators/accelerator.h" @@ -23,7 +24,7 @@ bool AcceleratorDispatcher::Dispatch(const MSG& msg) { if (!associated_window_) return false; if (!associated_window_->CanReceiveEvents()) - return Shell::GetRootWindow()->GetDispatcher()->Dispatch(msg); + return aura::Env::GetInstance()->GetDispatcher()->Dispatch(msg); if(msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) { ash::AcceleratorController* accelerator_controller = diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc index 227e0810..9ff111c 100644 --- a/ash/drag_drop/drag_drop_controller.cc +++ b/ash/drag_drop/drag_drop_controller.cc @@ -8,6 +8,7 @@ #include "ash/shell.h" #include "base/message_loop.h" #include "ui/aura/client/drag_drop_delegate.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/base/dragdrop/drag_drop_types.h" @@ -81,7 +82,7 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, if (should_block_during_drag_drop_) { MessageLoopForUI* loop = MessageLoopForUI::current(); MessageLoop::ScopedNestableTaskAllower allow_nested(loop); - loop->RunWithDispatcher(Shell::GetRootWindow()->GetDispatcher()); + loop->RunWithDispatcher(aura::Env::GetInstance()->GetDispatcher()); } #endif // !defined(OS_MACOSX) diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc index 6fa928c..0ffc170 100644 --- a/ash/wm/toplevel_window_event_filter.cc +++ b/ash/wm/toplevel_window_event_filter.cc @@ -11,6 +11,7 @@ #include "base/message_loop.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/cursor.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" @@ -127,7 +128,7 @@ void ToplevelWindowEventFilter::RunMoveLoop(aura::Window* source) { new WindowResizer(source, source_mouse_location, HTCAPTION, grid_size_)); #if !defined(OS_MACOSX) MessageLoopForUI::current()->RunWithDispatcher( - Shell::GetRootWindow()->GetDispatcher()); + aura::Env::GetInstance()->GetDispatcher()); #endif // !defined(OS_MACOSX) in_move_loop_ = false; } diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc index 1e0fae6..442fdba 100644 --- a/chrome/browser/ui/views/simple_message_box_views.cc +++ b/chrome/browser/ui/views/simple_message_box_views.cc @@ -17,6 +17,7 @@ #if defined(USE_AURA) #include "ash/shell.h" #include "ui/aura/client/dispatcher_client.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" #endif @@ -157,7 +158,7 @@ bool SimpleMessageBoxViews::Dispatch(const MSG& msg) { #elif defined(USE_AURA) base::MessagePumpDispatcher::DispatchStatus SimpleMessageBoxViews::Dispatch(XEvent* xev) { - if (!ash::Shell::GetRootWindow()->GetDispatcher()->Dispatch(xev)) + if (!aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev)) return EVENT_IGNORED; if (disposition_ == DISPOSITION_UNKNOWN) diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 364c10b..db28b95 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -48,6 +48,7 @@ 'client/window_move_client.h', 'client/window_types.h', 'cursor.h', + 'dispatcher_win.cc', 'env.cc', 'env.h', 'env_observer.h', diff --git a/ui/aura/dispatcher_win.cc b/ui/aura/dispatcher_win.cc new file mode 100644 index 0000000..f8a4232 --- /dev/null +++ b/ui/aura/dispatcher_win.cc @@ -0,0 +1,34 @@ +// 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. + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/message_loop.h" +#include "ui/aura/root_window.h" + +namespace aura { + +class DispatcherWin : public MessageLoop::Dispatcher { + public: + DispatcherWin() {} + virtual ~DispatcherWin() {} + + // Overridden from MessageLoop::Dispatcher: + virtual bool Dispatch(const MSG& msg) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(DispatcherWin); +}; + +bool DispatcherWin::Dispatch(const MSG& msg) { + TranslateMessage(&msg); + DispatchMessage(&msg); + return true; +} + +MessageLoop::Dispatcher* CreateDispatcher() { + return new DispatcherWin; +} + +} // namespace aura diff --git a/ui/aura/env.cc b/ui/aura/env.cc index e8cee8707..5052e32 100644 --- a/ui/aura/env.cc +++ b/ui/aura/env.cc @@ -4,8 +4,13 @@ #include "ui/aura/env.h" #include "ui/aura/env_observer.h" +#include "ui/aura/root_window_host.h" #include "ui/aura/window.h" +#if !defined(OS_MACOSX) && !defined(OS_WIN) +#include "ui/aura/root_window.h" +#endif + namespace aura { // static @@ -14,7 +19,11 @@ Env* Env::instance_ = NULL; //////////////////////////////////////////////////////////////////////////////// // Env, public: -Env::Env() {} +Env::Env() { +#if defined(OS_WIN) + dispatcher_.reset(CreateDispatcher()); +#endif +} Env::~Env() {} @@ -39,6 +48,18 @@ void Env::RemoveObserver(EnvObserver* observer) { observers_.RemoveObserver(observer); } +#if !defined(OS_MACOSX) +MessageLoop::Dispatcher* Env::GetDispatcher() { +#if defined(OS_WIN) + return dispatcher_.get(); +#else + // TODO(beng): Consolidate in the previous branch of this macro once the linux + // dispatcher is complete. + return RootWindow::GetInstance()->host_->GetDispatcher(); +#endif +} +#endif + //////////////////////////////////////////////////////////////////////////////// // Env, private: diff --git a/ui/aura/env.h b/ui/aura/env.h index 12cb2ef..a4fee63 100644 --- a/ui/aura/env.h +++ b/ui/aura/env.h @@ -6,6 +6,8 @@ #define UI_AURA_ENV_H_ #pragma once +#include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "base/observer_list.h" #include "ui/aura/aura_export.h" @@ -14,6 +16,9 @@ namespace aura { class EnvObserver; class Window; +// Creates a platform-specific native event dispatcher. +MessageLoop::Dispatcher* CreateDispatcher(); + // A singleton object that tracks general state within Aura. // TODO(beng): manage RootWindows. class AURA_EXPORT Env { @@ -27,6 +32,14 @@ class AURA_EXPORT Env { void AddObserver(EnvObserver* observer); void RemoveObserver(EnvObserver* observer); + // Returns the native event dispatcher. The result should only be passed to + // MessageLoopForUI::RunWithDispatcher() or + // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch + // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored. +#if !defined(OS_MACOSX) + MessageLoop::Dispatcher* GetDispatcher(); +#endif + private: friend class Window; @@ -34,6 +47,10 @@ class AURA_EXPORT Env { void NotifyWindowInitialized(Window* window); ObserverList<EnvObserver> observers_; +#if defined(OS_WIN) + // TODO(beng): remove the ifdef once the linux dispatcher is complete. + scoped_ptr<MessageLoop::Dispatcher> dispatcher_; +#endif static Env* instance_; diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 9ec0f8b..a638564 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -311,12 +311,6 @@ void RootWindow::OnWindowTransformed(Window* window, bool contained_mouse) { } } -#if !defined(OS_MACOSX) -MessageLoop::Dispatcher* RootWindow::GetDispatcher() { - return host_.get(); -} -#endif // !defined(OS_MACOSX) - void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) { observers_.AddObserver(observer); } diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index dfaf153..c84d697 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -144,14 +144,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // |last_moust_location()|. void OnWindowTransformed(Window* window, bool contained_mouse); - // Returns the root window's dispatcher. The result should only be passed to - // MessageLoopForUI::RunWithDispatcher() or - // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch - // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored. -#if !defined(OS_MACOSX) - MessageLoop::Dispatcher* GetDispatcher(); -#endif - // Add/remove observer. void AddRootWindowObserver(RootWindowObserver* observer); void RemoveRootWindowObserver(RootWindowObserver* observer); @@ -204,6 +196,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, virtual void ScheduleDraw() OVERRIDE; private: + // TODO(beng): remove this friendship once the linux dispatcher is moved. + friend class Env; friend class Window; RootWindow(); diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h index a6c7c53..4af42ac 100644 --- a/ui/aura/root_window_host.h +++ b/ui/aura/root_window_host.h @@ -23,7 +23,7 @@ class RootWindow; // RootWindowHost bridges between a native window and the embedded RootWindow. // It provides the accelerated widget and maps events from the native os to // aura. -#if defined(OS_MACOSX) +#if defined(OS_MACOSX) || defined(OS_WIN) class RootWindowHost { #else class RootWindowHost : public MessageLoop::Dispatcher { @@ -86,6 +86,11 @@ class RootWindowHost : public MessageLoop::Dispatcher { // Posts |native_event| to the platform's event queue. #if !defined(OS_MACOSX) virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0; + +#if !defined(OS_WIN) + // See documentation for RootWindow::GetDispatcher(). + virtual MessageLoop::Dispatcher* GetDispatcher() = 0; +#endif #endif }; diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index cf5d762..95665dd 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -300,6 +300,7 @@ class RootWindowHostLinux : public RootWindowHost, virtual void UnConfineCursor() OVERRIDE; virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; + virtual MessageLoop::Dispatcher* GetDispatcher() OVERRIDE; // MessageLoop::DestructionObserver Overrides. virtual void WillDestroyCurrentMessageLoop() OVERRIDE; @@ -696,6 +697,10 @@ void RootWindowHostLinux::PostNativeEvent( XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); } +MessageLoop::Dispatcher* RootWindowHostLinux::GetDispatcher() { + return this; +} + void RootWindowHostLinux::WillDestroyCurrentMessageLoop() { aura::RootWindow::DeleteInstance(); } diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc index a4f60b6..84f5103 100644 --- a/ui/aura/root_window_host_win.cc +++ b/ui/aura/root_window_host_win.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "ui/aura/root_window.h" +#include "ui/aura/env.h" #include "ui/aura/event.h" using std::max; @@ -126,12 +127,6 @@ RootWindowHostWin::~RootWindowHostWin() { DestroyWindow(hwnd()); } -bool RootWindowHostWin::Dispatch(const MSG& msg) { - TranslateMessage(&msg); - DispatchMessage(&msg); - return true; -} - void RootWindowHostWin::SetRootWindow(RootWindow* root_window) { root_window_ = root_window; } diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h index 3e1edcb..1c1a25a 100644 --- a/ui/aura/root_window_host_win.h +++ b/ui/aura/root_window_host_win.h @@ -17,9 +17,6 @@ class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl { explicit RootWindowHostWin(const gfx::Rect& bounds); virtual ~RootWindowHostWin(); - // MessageLoop::Dispatcher: - virtual bool Dispatch(const MSG& msg); - // RootWindowHost: virtual void SetRootWindow(RootWindow* root_window) OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc index cdc513c..4eb08dd 100644 --- a/ui/aura/test/aura_test_helper.cc +++ b/ui/aura/test/aura_test_helper.cc @@ -53,7 +53,8 @@ void AuraTestHelper::TearDown() { void AuraTestHelper::RunAllPendingInMessageLoop(RootWindow* root_window) { #if !defined(OS_MACOSX) - message_loop_.RunAllPendingWithDispatcher(root_window->GetDispatcher()); + message_loop_.RunAllPendingWithDispatcher( + Env::GetInstance()->GetDispatcher()); #endif } diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index a7ac848..d3b8e3f 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -26,6 +26,7 @@ #if defined(USE_AURA) #include "ui/aura/client/dispatcher_client.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" #elif defined(TOOLKIT_USES_GTK) #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" @@ -925,7 +926,7 @@ base::MessagePumpDispatcher::DispatchStatus base::MessagePumpDispatcher::DispatchStatus MenuController::Dispatch(XEvent* xev) { if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) { - aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev); + aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev); return base::MessagePumpDispatcher::EVENT_QUIT; } switch (ui::EventTypeFromNative(xev)) { @@ -944,7 +945,7 @@ base::MessagePumpDispatcher::DispatchStatus // TODO(oshima): Update Windows' Dispatcher to return DispatchStatus // instead of bool. - if (aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch(xev) == + if (aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev) == base::MessagePumpDispatcher::EVENT_IGNORED) return EVENT_IGNORED; return exit_type_ != EXIT_NONE ? diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc index c0c077e..61bef5c 100644 --- a/ui/views/test/views_test_base.cc +++ b/ui/views/test/views_test_base.cc @@ -11,6 +11,7 @@ #if defined(USE_AURA) #include "base/compiler_specific.h" #include "ui/aura/client/aura_constants.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/test/test_activation_client.h" #include "ui/base/ime/input_method.h" @@ -102,7 +103,7 @@ void ViewsTestBase::TearDown() { void ViewsTestBase::RunPendingMessages() { #if defined(USE_AURA) message_loop_.RunAllPendingWithDispatcher( - aura::RootWindow::GetInstance()->GetDispatcher()); + aura::Env::GetInstance()->GetDispatcher()); #else message_loop_.RunAllPending(); #endif |