Chromium Code Reviews| Index: ui/views/controls/menu/menu_runner_impl.cc |
| diff --git a/ui/views/controls/menu/menu_runner.cc b/ui/views/controls/menu/menu_runner_impl.cc |
| similarity index 54% |
| copy from ui/views/controls/menu/menu_runner.cc |
| copy to ui/views/controls/menu/menu_runner_impl.cc |
| index ca36d026433a6bca30cca080259f56b3fdaccef2..23871cd049f77740bceafe6f134c3db247a57fd5 100644 |
| --- a/ui/views/controls/menu/menu_runner.cc |
| +++ b/ui/views/controls/menu/menu_runner_impl.cc |
| @@ -1,20 +1,14 @@ |
| -// 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. |
| -#include "ui/views/controls/menu/menu_runner.h" |
| +#include "ui/views/controls/menu/menu_runner_impl.h" |
| -#include <set> |
| - |
| -#include "base/memory/weak_ptr.h" |
| -#include "ui/base/models/menu_model.h" |
| +#include "ui/native_theme/native_theme.h" |
| #include "ui/views/controls/button/menu_button.h" |
| #include "ui/views/controls/menu/menu_controller.h" |
| -#include "ui/views/controls/menu/menu_controller_delegate.h" |
| #include "ui/views/controls/menu/menu_delegate.h" |
| #include "ui/views/controls/menu/menu_item_view.h" |
| -#include "ui/views/controls/menu/menu_model_adapter.h" |
| -#include "ui/views/controls/menu/menu_runner_handler.h" |
| #include "ui/views/widget/widget.h" |
| #if defined(OS_WIN) |
| @@ -22,87 +16,8 @@ |
| #endif |
| namespace views { |
| - |
| namespace internal { |
| -// Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() |
| -// deletes immediately if the menu isn't showing. If the menu is showing |
| -// Release() cancels the menu and when the nested RunMenuAt() call returns |
| -// deletes itself and the menu. |
| -class MenuRunnerImpl : public internal::MenuControllerDelegate { |
| - public: |
| - explicit MenuRunnerImpl(MenuItemView* menu); |
| - |
| - MenuItemView* menu() { return menu_; } |
| - |
| - bool running() const { return running_; } |
| - |
| - // See description above class for details. |
| - void Release(); |
| - |
| - // Runs the menu. |
| - MenuRunner::RunResult RunMenuAt(Widget* parent, |
| - MenuButton* button, |
| - const gfx::Rect& bounds, |
| - MenuAnchorPosition anchor, |
| - int32 types) WARN_UNUSED_RESULT; |
| - |
| - void Cancel(); |
| - |
| - // Returns the time from the event which closed the menu - or 0. |
| - base::TimeDelta closing_event_time() const; |
| - |
| - // MenuControllerDelegate: |
| - virtual void DropMenuClosed(NotifyType type, MenuItemView* menu) OVERRIDE; |
| - virtual void SiblingMenuCreated(MenuItemView* menu) OVERRIDE; |
| - |
| - private: |
| - virtual ~MenuRunnerImpl(); |
| - |
| - // Cleans up after the menu is no longer showing. |result| is the menu that |
| - // the user selected, or NULL if nothing was selected. |
| - MenuRunner::RunResult MenuDone(MenuItemView* result, int mouse_event_flags); |
| - |
| - // Returns true if mnemonics should be shown in the menu. |
| - bool ShouldShowMnemonics(MenuButton* button); |
| - |
| - // The menu. We own this. We don't use scoped_ptr as the destructor is |
| - // protected and we're a friend. |
| - MenuItemView* menu_; |
| - |
| - // Any sibling menus. Does not include |menu_|. We own these too. |
| - std::set<MenuItemView*> sibling_menus_; |
| - |
| - // Created and set as the delegate of the MenuItemView if Release() is |
| - // invoked. This is done to make sure the delegate isn't notified after |
| - // Release() is invoked. We do this as we assume the delegate is no longer |
| - // valid if MenuRunner has been deleted. |
| - scoped_ptr<MenuDelegate> empty_delegate_; |
| - |
| - // Are we in run waiting for it to return? |
| - bool running_; |
| - |
| - // Set if |running_| and Release() has been invoked. |
| - bool delete_after_run_; |
| - |
| - // Are we running for a drop? |
| - bool for_drop_; |
| - |
| - // The controller. |
| - MenuController* controller_; |
| - |
| - // Do we own the controller? |
| - bool owns_controller_; |
| - |
| - // The timestamp of the event which closed the menu - or 0. |
| - base::TimeDelta closing_event_time_; |
| - |
| - // Used to detect deletion of |this| when notifying delegate of success. |
| - base::WeakPtrFactory<MenuRunnerImpl> weak_factory_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(MenuRunnerImpl); |
| -}; |
| - |
| MenuRunnerImpl::MenuRunnerImpl(MenuItemView* menu) |
| : menu_(menu), |
| running_(false), |
| @@ -114,6 +29,10 @@ MenuRunnerImpl::MenuRunnerImpl(MenuItemView* menu) |
| weak_factory_(this) { |
| } |
| +bool MenuRunnerImpl::running() const { |
| + return running_; |
|
tapted
2014/06/25 08:30:28
can this just do holder_->running()?
Andre
2014/06/27 01:18:08
I'm not sure what you mean, we are the holder_ her
tapted
2014/06/27 11:14:35
oops - the diff probably threw me
|
| +} |
| + |
| void MenuRunnerImpl::Release() { |
| if (running_) { |
| if (delete_after_run_) |
| @@ -181,8 +100,8 @@ MenuRunner::RunResult MenuRunnerImpl::RunMenuAt(Widget* parent, |
| owns_controller_ = false; |
| if (!controller) { |
| // No menus are showing, show one. |
| - ui::NativeTheme* theme = parent ? parent->GetNativeTheme() : |
| - ui::NativeTheme::instance(); |
| + ui::NativeTheme* theme = |
| + parent ? parent->GetNativeTheme() : ui::NativeTheme::instance(); |
| controller = new MenuController(theme, !for_drop_, this); |
| owns_controller_ = true; |
| } |
| @@ -233,7 +152,8 @@ void MenuRunnerImpl::SiblingMenuCreated(MenuItemView* menu) { |
| MenuRunnerImpl::~MenuRunnerImpl() { |
| delete menu_; |
| for (std::set<MenuItemView*>::iterator i = sibling_menus_.begin(); |
| - i != sibling_menus_.end(); ++i) |
| + i != sibling_menus_.end(); |
| + ++i) |
| delete *i; |
| } |
| @@ -279,77 +199,4 @@ bool MenuRunnerImpl::ShouldShowMnemonics(MenuButton* button) { |
| } |
| } // namespace internal |
| - |
| -MenuRunner::MenuRunner(ui::MenuModel* menu_model) |
| - : menu_model_adapter_(new MenuModelAdapter(menu_model)), |
| - holder_(new internal::MenuRunnerImpl(menu_model_adapter_->CreateMenu())) { |
| -} |
| - |
| -MenuRunner::MenuRunner(MenuItemView* menu) |
| - : holder_(new internal::MenuRunnerImpl(menu)) { |
| -} |
| - |
| -MenuRunner::~MenuRunner() { |
| - holder_->Release(); |
| -} |
| - |
| -MenuItemView* MenuRunner::GetMenu() { |
| - return holder_->menu(); |
| -} |
| - |
| -MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
| - MenuButton* button, |
| - const gfx::Rect& bounds, |
| - MenuAnchorPosition anchor, |
| - ui::MenuSourceType source_type, |
| - int32 types) { |
| - if (runner_handler_.get()) { |
| - return runner_handler_->RunMenuAt(parent, button, bounds, anchor, |
| - source_type, types); |
| - } |
| - |
| - // The parent of the nested menu will have created a DisplayChangeListener, so |
| - // we avoid creating a DisplayChangeListener if nested. Drop menus are |
| - // transient, so we don't cancel in that case. |
| - if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
| - display_change_listener_.reset( |
| - internal::DisplayChangeListener::Create(parent, this)); |
| - } |
| - |
| - if (types & CONTEXT_MENU) { |
| - switch (source_type) { |
| - case ui::MENU_SOURCE_NONE: |
| - case ui::MENU_SOURCE_KEYBOARD: |
| - case ui::MENU_SOURCE_MOUSE: |
| - anchor = MENU_ANCHOR_TOPLEFT; |
| - break; |
| - case ui::MENU_SOURCE_TOUCH: |
| - case ui::MENU_SOURCE_TOUCH_EDIT_MENU: |
| - anchor = MENU_ANCHOR_BOTTOMCENTER; |
| - break; |
| - default: |
| - break; |
| - } |
| - } |
| - |
| - return holder_->RunMenuAt(parent, button, bounds, anchor, types); |
| -} |
| - |
| -bool MenuRunner::IsRunning() const { |
| - return holder_->running(); |
| -} |
| - |
| -void MenuRunner::Cancel() { |
| - holder_->Cancel(); |
| -} |
| - |
| -base::TimeDelta MenuRunner::closing_event_time() const { |
| - return holder_->closing_event_time(); |
| -} |
| - |
| -void MenuRunner::SetRunnerHandler( |
| - scoped_ptr<MenuRunnerHandler> runner_handler) { |
| - runner_handler_ = runner_handler.Pass(); |
| -} |
| - |
| } // namespace views |