Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
| 6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/views/controls/menu/menu_item_view.h" | 11 #include "ui/views/controls/menu/menu_item_view.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 class MenuModel; | 14 class MenuModel; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 class MenuButton; | 19 class MenuButton; |
| 20 class MenuModelAdapter; | 20 class MenuModelAdapter; |
| 21 class MenuRunnerCore; | |
| 21 class Widget; | 22 class Widget; |
| 22 | 23 |
| 23 namespace internal { | 24 namespace internal { |
| 24 class DisplayChangeListener; | 25 class DisplayChangeListener; |
| 25 class MenuRunnerImpl; | 26 class MenuRunnerImpl; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // MenuRunner is responsible for showing (running) the menu and additionally | 29 // MenuRunner is responsible for showing (running) the menu and additionally |
| 29 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe | 30 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe |
| 30 // to delete MenuRunner at any point, but MenuRunner internally only deletes the | 31 // to delete MenuRunner at any point, but MenuRunner internally only deletes the |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 105 |
| 105 // Returns true if we're in a nested message loop running the menu. | 106 // Returns true if we're in a nested message loop running the menu. |
| 106 bool IsRunning() const; | 107 bool IsRunning() const; |
| 107 | 108 |
| 108 // Hides and cancels the menu. This does nothing if the menu is not open. | 109 // Hides and cancels the menu. This does nothing if the menu is not open. |
| 109 void Cancel(); | 110 void Cancel(); |
| 110 | 111 |
| 111 // Returns the time from the event which closed the menu - or 0. | 112 // Returns the time from the event which closed the menu - or 0. |
| 112 base::TimeDelta closing_event_time() const; | 113 base::TimeDelta closing_event_time() const; |
| 113 | 114 |
| 115 // Sets an implementation of RunMenuAt. This is intended to be used at test. | |
| 116 void set_runner_core(MenuRunnerCore* runner_core) { | |
|
sky
2013/12/09 14:54:04
Make this private and only settable by way of a te
hajimehoshi
2013/12/10 06:04:25
Done.
| |
| 117 runner_core_ = runner_core; | |
| 118 } | |
| 119 | |
| 114 private: | 120 private: |
| 115 scoped_ptr<MenuModelAdapter> menu_model_adapter_; | 121 scoped_ptr<MenuModelAdapter> menu_model_adapter_; |
| 116 | 122 |
| 117 internal::MenuRunnerImpl* holder_; | 123 internal::MenuRunnerImpl* holder_; |
| 118 | 124 |
| 125 // An implementation of RunMenuAt. This is usually NULL and ignored. If this | |
| 126 // is not NULL, this implementation will be used. | |
| 127 MenuRunnerCore* runner_core_; | |
| 128 | |
| 119 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; | 129 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; |
| 120 | 130 |
| 121 DISALLOW_COPY_AND_ASSIGN(MenuRunner); | 131 DISALLOW_COPY_AND_ASSIGN(MenuRunner); |
| 122 }; | 132 }; |
| 123 | 133 |
| 124 namespace internal { | 134 namespace internal { |
| 125 | 135 |
| 126 // DisplayChangeListener is intended to listen for changes in the display size | 136 // DisplayChangeListener is intended to listen for changes in the display size |
| 127 // and cancel the menu. DisplayChangeListener is created when the menu is | 137 // and cancel the menu. DisplayChangeListener is created when the menu is |
| 128 // shown. | 138 // shown. |
| 129 class DisplayChangeListener { | 139 class DisplayChangeListener { |
| 130 public: | 140 public: |
| 131 virtual ~DisplayChangeListener() {} | 141 virtual ~DisplayChangeListener() {} |
| 132 | 142 |
| 133 // Creates the platform specified DisplayChangeListener, or NULL if there | 143 // Creates the platform specified DisplayChangeListener, or NULL if there |
| 134 // isn't one. Caller owns the returned value. | 144 // isn't one. Caller owns the returned value. |
| 135 static DisplayChangeListener* Create(Widget* parent, | 145 static DisplayChangeListener* Create(Widget* parent, |
| 136 MenuRunner* runner); | 146 MenuRunner* runner); |
| 137 | 147 |
| 138 protected: | 148 protected: |
| 139 DisplayChangeListener() {} | 149 DisplayChangeListener() {} |
| 140 }; | 150 }; |
| 141 | 151 |
| 142 } | 152 } |
| 143 | 153 |
| 144 } // namespace views | 154 } // namespace views |
| 145 | 155 |
| 146 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 156 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
| OLD | NEW |