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 #include "ui/views/controls/menu/menu_runner.h" | 5 #include "ui/views/controls/menu/menu_runner.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "ui/base/models/menu_model.h" | 10 #include "ui/base/models/menu_model.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace internal { | 26 namespace internal { |
27 | 27 |
28 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() | 28 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() |
29 // deletes immediately if the menu isn't showing. If the menu is showing | 29 // deletes immediately if the menu isn't showing. If the menu is showing |
30 // Release() cancels the menu and when the nested RunMenuAt() call returns | 30 // Release() cancels the menu and when the nested RunMenuAt() call returns |
31 // deletes itself and the menu. | 31 // deletes itself and the menu. |
32 class MenuRunnerImpl : public internal::MenuControllerDelegate { | 32 class MenuRunnerImpl : public internal::MenuControllerDelegate { |
33 public: | 33 public: |
34 explicit MenuRunnerImpl(MenuItemView* menu); | 34 explicit MenuRunnerImpl(MenuItemView* menu); |
35 | 35 |
36 MenuItemView* menu() { return menu_; } | |
37 | |
38 bool running() const { return running_; } | 36 bool running() const { return running_; } |
39 | 37 |
40 // See description above class for details. | 38 // See description above class for details. |
41 void Release(); | 39 void Release(); |
42 | 40 |
43 // Runs the menu. | 41 // Runs the menu. |
44 MenuRunner::RunResult RunMenuAt(Widget* parent, | 42 MenuRunner::RunResult RunMenuAt(Widget* parent, |
45 MenuButton* button, | 43 MenuButton* button, |
46 const gfx::Rect& bounds, | 44 const gfx::Rect& bounds, |
47 MenuAnchorPosition anchor, | 45 MenuAnchorPosition anchor, |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 285 } |
288 | 286 |
289 MenuRunner::MenuRunner(MenuItemView* menu_view, int32 run_types) | 287 MenuRunner::MenuRunner(MenuItemView* menu_view, int32 run_types) |
290 : run_types_(run_types), holder_(new internal::MenuRunnerImpl(menu_view)) { | 288 : run_types_(run_types), holder_(new internal::MenuRunnerImpl(menu_view)) { |
291 } | 289 } |
292 | 290 |
293 MenuRunner::~MenuRunner() { | 291 MenuRunner::~MenuRunner() { |
294 holder_->Release(); | 292 holder_->Release(); |
295 } | 293 } |
296 | 294 |
297 MenuItemView* MenuRunner::GetMenu() { | |
298 return holder_->menu(); | |
299 } | |
300 | |
301 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 295 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
302 MenuButton* button, | 296 MenuButton* button, |
303 const gfx::Rect& bounds, | 297 const gfx::Rect& bounds, |
304 MenuAnchorPosition anchor, | 298 MenuAnchorPosition anchor, |
305 ui::MenuSourceType source_type) { | 299 ui::MenuSourceType source_type) { |
306 if (runner_handler_.get()) { | 300 if (runner_handler_.get()) { |
307 return runner_handler_->RunMenuAt( | 301 return runner_handler_->RunMenuAt( |
308 parent, button, bounds, anchor, source_type, run_types_); | 302 parent, button, bounds, anchor, source_type, run_types_); |
309 } | 303 } |
310 | 304 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 base::TimeDelta MenuRunner::closing_event_time() const { | 340 base::TimeDelta MenuRunner::closing_event_time() const { |
347 return holder_->closing_event_time(); | 341 return holder_->closing_event_time(); |
348 } | 342 } |
349 | 343 |
350 void MenuRunner::SetRunnerHandler( | 344 void MenuRunner::SetRunnerHandler( |
351 scoped_ptr<MenuRunnerHandler> runner_handler) { | 345 scoped_ptr<MenuRunnerHandler> runner_handler) { |
352 runner_handler_ = runner_handler.Pass(); | 346 runner_handler_ = runner_handler.Pass(); |
353 } | 347 } |
354 | 348 |
355 } // namespace views | 349 } // namespace views |
OLD | NEW |