OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_ |
| 6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_ |
| 7 |
| 8 #include "ui/views/controls/menu/menu_runner_impl_interface.h" |
| 9 |
| 10 #include <set> |
| 11 |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" |
| 14 #include "ui/views/controls/menu/menu_controller_delegate.h" |
| 15 |
| 16 namespace views { |
| 17 |
| 18 class MenuController; |
| 19 class MenuDelegate; |
| 20 class MenuItemView; |
| 21 |
| 22 namespace internal { |
| 23 |
| 24 // A menu runner implementation that uses views::MenuItemView to show a menu. |
| 25 class MenuRunnerImpl : public MenuRunnerImplInterface, |
| 26 public MenuControllerDelegate { |
| 27 public: |
| 28 explicit MenuRunnerImpl(MenuItemView* menu); |
| 29 |
| 30 virtual MenuItemView* GetMenu() const OVERRIDE; |
| 31 virtual bool IsRunning() const OVERRIDE; |
| 32 virtual void Release() OVERRIDE; |
| 33 virtual MenuRunner::RunResult RunMenuAt(Widget* parent, |
| 34 MenuButton* button, |
| 35 const gfx::Rect& bounds, |
| 36 MenuAnchorPosition anchor, |
| 37 int32 run_types) OVERRIDE; |
| 38 virtual void Cancel() OVERRIDE; |
| 39 virtual base::TimeDelta GetClosingEventTime() const OVERRIDE; |
| 40 |
| 41 // MenuControllerDelegate: |
| 42 virtual void DropMenuClosed(NotifyType type, MenuItemView* menu) OVERRIDE; |
| 43 virtual void SiblingMenuCreated(MenuItemView* menu) OVERRIDE; |
| 44 |
| 45 private: |
| 46 virtual ~MenuRunnerImpl(); |
| 47 |
| 48 // Cleans up after the menu is no longer showing. |result| is the menu that |
| 49 // the user selected, or NULL if nothing was selected. |
| 50 MenuRunner::RunResult MenuDone(MenuItemView* result, int mouse_event_flags); |
| 51 |
| 52 // Returns true if mnemonics should be shown in the menu. |
| 53 bool ShouldShowMnemonics(MenuButton* button); |
| 54 |
| 55 // The menu. We own this. We don't use scoped_ptr as the destructor is |
| 56 // protected and we're a friend. |
| 57 MenuItemView* menu_; |
| 58 |
| 59 // Any sibling menus. Does not include |menu_|. We own these too. |
| 60 std::set<MenuItemView*> sibling_menus_; |
| 61 |
| 62 // Created and set as the delegate of the MenuItemView if Release() is |
| 63 // invoked. This is done to make sure the delegate isn't notified after |
| 64 // Release() is invoked. We do this as we assume the delegate is no longer |
| 65 // valid if MenuRunner has been deleted. |
| 66 scoped_ptr<MenuDelegate> empty_delegate_; |
| 67 |
| 68 // Are we in run waiting for it to return? |
| 69 bool running_; |
| 70 |
| 71 // Set if |running_| and Release() has been invoked. |
| 72 bool delete_after_run_; |
| 73 |
| 74 // Are we running for a drop? |
| 75 bool for_drop_; |
| 76 |
| 77 // The controller. |
| 78 MenuController* controller_; |
| 79 |
| 80 // Do we own the controller? |
| 81 bool owns_controller_; |
| 82 |
| 83 // The timestamp of the event which closed the menu - or 0. |
| 84 base::TimeDelta closing_event_time_; |
| 85 |
| 86 // Used to detect deletion of |this| when notifying delegate of success. |
| 87 base::WeakPtrFactory<MenuRunnerImpl> weak_factory_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(MenuRunnerImpl); |
| 90 }; |
| 91 |
| 92 } // namespace internal |
| 93 } // namespace views |
| 94 |
| 95 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_ |
OLD | NEW |