Chromium Code Reviews| Index: ui/views/controls/menu/menu_controller.cc |
| diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc |
| index f5d28ef1d79a610f3834115b463b4b74d7566fc0..7a118b78454108e3d96310ada95f72d5567fb7b5 100644 |
| --- a/ui/views/controls/menu/menu_controller.cc |
| +++ b/ui/views/controls/menu/menu_controller.cc |
| @@ -4,27 +4,15 @@ |
| #include "ui/views/controls/menu/menu_controller.h" |
| -#if defined(OS_WIN) |
| -#include <windowsx.h> |
| -#endif |
| - |
| #include "base/i18n/case_conversion.h" |
| #include "base/i18n/rtl.h" |
| -#include "base/run_loop.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/time/time.h" |
| -#include "ui/aura/client/screen_position_client.h" |
| -#include "ui/aura/env.h" |
| -#include "ui/aura/window.h" |
| -#include "ui/aura/window_event_dispatcher.h" |
| -#include "ui/aura/window_tree_host.h" |
| #include "ui/base/dragdrop/drag_utils.h" |
| #include "ui/base/dragdrop/os_exchange_data.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/events/event.h" |
| #include "ui/events/event_utils.h" |
| -#include "ui/events/platform/platform_event_source.h" |
| -#include "ui/events/platform/scoped_event_dispatcher.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/native_widget_types.h" |
| #include "ui/gfx/point.h" |
| @@ -36,6 +24,7 @@ |
| #include "ui/views/controls/menu/menu_controller_delegate.h" |
| #include "ui/views/controls/menu/menu_host_root_view.h" |
| #include "ui/views/controls/menu/menu_item_view.h" |
| +#include "ui/views/controls/menu/menu_message_loop.h" |
| #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| #include "ui/views/controls/menu/submenu_view.h" |
| #include "ui/views/drag_utils.h" |
| @@ -47,20 +36,7 @@ |
| #include "ui/views/widget/root_view.h" |
| #include "ui/views/widget/tooltip_manager.h" |
| #include "ui/views/widget/widget.h" |
| -#include "ui/wm/public/activation_change_observer.h" |
| -#include "ui/wm/public/activation_client.h" |
| -#include "ui/wm/public/dispatcher_client.h" |
| -#include "ui/wm/public/drag_drop_client.h" |
| - |
| -#if defined(OS_WIN) |
| -#include "ui/base/win/internal_constants.h" |
| -#include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" |
| -#include "ui/views/win/hwnd_util.h" |
| -#else |
| -#include "ui/views/controls/menu/menu_event_dispatcher_linux.h" |
| -#endif |
| -using aura::client::ScreenPositionClient; |
| using base::Time; |
| using base::TimeDelta; |
| using ui::OSExchangeData; |
| @@ -108,67 +84,6 @@ bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { |
| return !lower_title.empty() && lower_title[0] == key; |
| } |
| -aura::Window* GetOwnerRootWindow(views::Widget* owner) { |
| - return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; |
| -} |
| - |
| -// ActivationChangeObserverImpl is used to observe activation changes and close |
| -// the menu. Additionally it listens for the root window to be destroyed and |
| -// cancel the menu as well. |
| -class ActivationChangeObserverImpl |
| - : public aura::client::ActivationChangeObserver, |
| - public aura::WindowObserver, |
| - public ui::EventHandler { |
| - public: |
| - ActivationChangeObserverImpl(MenuController* controller, aura::Window* root) |
| - : controller_(controller), |
| - root_(root) { |
| - aura::client::GetActivationClient(root_)->AddObserver(this); |
| - root_->AddObserver(this); |
| - root_->AddPreTargetHandler(this); |
| - } |
| - |
| - virtual ~ActivationChangeObserverImpl() { |
| - Cleanup(); |
| - } |
| - |
| - // aura::client::ActivationChangeObserver: |
| - virtual void OnWindowActivated(aura::Window* gained_active, |
| - aura::Window* lost_active) OVERRIDE { |
| - if (!controller_->drag_in_progress()) |
| - controller_->CancelAll(); |
| - } |
| - |
| - // aura::WindowObserver: |
| - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| - Cleanup(); |
| - } |
| - |
| - // ui::EventHandler: |
| - virtual void OnCancelMode(ui::CancelModeEvent* event) OVERRIDE { |
| - controller_->CancelAll(); |
| - } |
| - |
| - private: |
| - void Cleanup() { |
| - if (!root_) |
| - return; |
| - // The ActivationClient may have been destroyed by the time we get here. |
| - aura::client::ActivationClient* client = |
| - aura::client::GetActivationClient(root_); |
| - if (client) |
| - client->RemoveObserver(this); |
| - root_->RemovePreTargetHandler(this); |
| - root_->RemoveObserver(this); |
| - root_ = NULL; |
| - } |
| - |
| - MenuController* controller_; |
| - aura::Window* root_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); |
| -}; |
| - |
| } // namespace |
| // Returns the first descendant of |view| that is hot tracked. |
| @@ -445,7 +360,9 @@ MenuItemView* MenuController::Run(Widget* parent, |
| // appears totally broken. |
| message_loop_depth_++; |
| DCHECK_LE(message_loop_depth_, 2); |
| - RunMessageLoop(nested_menu); |
| + if (!message_loop_) |
| + message_loop_.reset(MenuMessageLoop::Create()); |
|
tapted
2014/05/06 00:02:46
I think maybe do this unconditionally in the const
Andre
2014/05/07 23:12:39
Done.
|
| + message_loop_->Run(this, owner_, nested_menu); |
| message_loop_depth_--; |
| if (ViewsDelegate::views_delegate) |
| @@ -1174,52 +1091,6 @@ MenuController::~MenuController() { |
| StopCancelAllTimer(); |
| } |
| -#if defined(OS_WIN) |
| -void MenuController::RunMessageLoop(bool nested_menu) { |
| - internal::MenuMessagePumpDispatcher nested_dispatcher(this); |
| - |
| - // |owner_| may be NULL. |
| - aura::Window* root = GetOwnerRootWindow(owner_); |
| - if (root) { |
| - scoped_ptr<ActivationChangeObserverImpl> observer; |
| - if (!nested_menu) |
| - observer.reset(new ActivationChangeObserverImpl(this, root)); |
| - aura::client::GetDispatcherClient(root) |
| - ->RunWithDispatcher(&nested_dispatcher); |
| - } else { |
| - base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| - base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| - base::RunLoop run_loop(&nested_dispatcher); |
| - run_loop.Run(); |
| - } |
| -} |
| -#else |
| -void MenuController::RunMessageLoop(bool nested_menu) { |
| - internal::MenuEventDispatcher event_dispatcher(this); |
| - scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher = |
| - nested_dispatcher_.Pass(); |
| - if (ui::PlatformEventSource::GetInstance()) { |
| - nested_dispatcher_ = |
| - ui::PlatformEventSource::GetInstance()->OverrideDispatcher( |
| - &event_dispatcher); |
| - } |
| - // |owner_| may be NULL. |
| - aura::Window* root = GetOwnerRootWindow(owner_); |
| - if (root) { |
| - scoped_ptr<ActivationChangeObserverImpl> observer; |
| - if (!nested_menu) |
| - observer.reset(new ActivationChangeObserverImpl(this, root)); |
| - aura::client::GetDispatcherClient(root)->RunWithDispatcher(NULL); |
| - } else { |
| - base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| - base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| - base::RunLoop run_loop; |
| - run_loop.Run(); |
| - } |
| - nested_dispatcher_ = old_dispatcher.Pass(); |
| -} |
| -#endif |
| - |
| MenuController::SendAcceleratorResultType |
| MenuController::SendAcceleratorToHotTrackedView() { |
| CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); |
| @@ -2230,18 +2101,7 @@ void MenuController::RepostEvent(SubmenuView* source, |
| if (!window) |
| return; |
| - aura::Window* root = window->GetRootWindow(); |
| - ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); |
| - if (!spc) |
| - return; |
| - |
| - gfx::Point root_loc(screen_loc); |
| - spc->ConvertPointFromScreen(root, &root_loc); |
| - |
| - ui::MouseEvent clone(static_cast<const ui::MouseEvent&>(event)); |
| - clone.set_location(root_loc); |
| - clone.set_root_location(root_loc); |
| - root->GetHost()->dispatcher()->RepostEvent(clone); |
| + message_loop_->RepostEventToWindow(event, window, screen_loc); |
| } |
| void MenuController::SetDropMenuItem( |
| @@ -2376,25 +2236,11 @@ void MenuController::SetExitType(ExitType type) { |
| // |
| // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects |
| // the current loop. |
| - bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && |
| - message_loop_depth_; |
| - |
| - if (quit_now) { |
| - if (owner_) { |
| - aura::Window* root = owner_->GetNativeWindow()->GetRootWindow(); |
| - aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop(); |
| - } else { |
| - base::MessageLoop::current()->QuitNow(); |
| - } |
| - // Restore the previous dispatcher. |
| - nested_dispatcher_.reset(); |
| - } |
| -} |
| + bool quit_now = message_loop_->ShouldQuitNow() && exit_type_ != EXIT_NONE && |
| + message_loop_depth_; |
| -bool MenuController::ShouldQuitNow() const { |
| - aura::Window* root = GetOwnerRootWindow(owner_); |
| - return !aura::client::GetDragDropClient(root) || |
| - !aura::client::GetDragDropClient(root)->IsDragDropInProgress(); |
| + if (quit_now) |
| + message_loop_->QuitNow(); |
| } |
| void MenuController::HandleMouseLocation(SubmenuView* source, |
| @@ -2430,8 +2276,8 @@ void MenuController::HandleMouseLocation(SubmenuView* source, |
| } |
| gfx::Screen* MenuController::GetScreen() { |
| - aura::Window* root = GetOwnerRootWindow(owner_); |
| - return root ? gfx::Screen::GetScreenFor(root) |
| + Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; |
| + return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) |
| : gfx::Screen::GetNativeScreen(); |
| } |