| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ui/views/controls/menu/menu_runner_handler.h" | 9 #include "ui/views/controls/menu/menu_runner_handler.h" |
| 10 #include "ui/views/controls/menu/menu_runner_impl.h" | 10 #include "ui/views/controls/menu/menu_runner_impl.h" |
| 11 #include "ui/views/widget/widget.h" |
| 11 | 12 |
| 12 namespace views { | 13 namespace views { |
| 13 | 14 |
| 14 MenuRunner::MenuRunner(ui::MenuModel* menu_model, | 15 MenuRunner::MenuRunner(ui::MenuModel* menu_model, |
| 15 int32_t run_types, | 16 int32_t run_types, |
| 16 const base::Closure& on_menu_closed_callback) | 17 const base::Closure& on_menu_closed_callback) |
| 17 : run_types_(run_types), | 18 : run_types_(run_types), |
| 18 impl_( | 19 impl_( |
| 19 internal::MenuRunnerImplInterface::Create(menu_model, | 20 internal::MenuRunnerImplInterface::Create(menu_model, |
| 20 run_types, | 21 run_types, |
| 21 on_menu_closed_callback)) {} | 22 on_menu_closed_callback)) {} |
| 22 | 23 |
| 23 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types) | 24 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types) |
| 24 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {} | 25 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {} |
| 25 | 26 |
| 26 MenuRunner::~MenuRunner() { | 27 MenuRunner::~MenuRunner() { |
| 27 impl_->Release(); | 28 impl_->Release(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 31 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
| 31 MenuButton* button, | 32 MenuButton* button, |
| 32 const gfx::Rect& bounds, | 33 const gfx::Rect& bounds, |
| 33 MenuAnchorPosition anchor, | 34 MenuAnchorPosition anchor, |
| 34 ui::MenuSourceType source_type) { | 35 ui::MenuSourceType source_type) { |
| 36 // If we are shown on mouse press, we will eat the subsequent mouse down and |
| 37 // the parent widget will not be able to reset its state (it might have mouse |
| 38 // capture from the mouse down). So we clear its state here. |
| 39 if (parent && parent->GetRootView()) |
| 40 parent->GetRootView()->SetMouseHandler(nullptr); |
| 41 |
| 35 if (runner_handler_.get()) { | 42 if (runner_handler_.get()) { |
| 36 return runner_handler_->RunMenuAt( | 43 return runner_handler_->RunMenuAt( |
| 37 parent, button, bounds, anchor, source_type, run_types_); | 44 parent, button, bounds, anchor, source_type, run_types_); |
| 38 } | 45 } |
| 39 | 46 |
| 40 // The parent of the nested menu will have created a DisplayChangeListener, so | 47 // The parent of the nested menu will have created a DisplayChangeListener, so |
| 41 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 48 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
| 42 // transient, so we don't cancel in that case. | 49 // transient, so we don't cancel in that case. |
| 43 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) { | 50 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
| 44 display_change_listener_.reset( | 51 display_change_listener_.reset( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 75 base::TimeTicks MenuRunner::closing_event_time() const { | 82 base::TimeTicks MenuRunner::closing_event_time() const { |
| 76 return impl_->GetClosingEventTime(); | 83 return impl_->GetClosingEventTime(); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void MenuRunner::SetRunnerHandler( | 86 void MenuRunner::SetRunnerHandler( |
| 80 std::unique_ptr<MenuRunnerHandler> runner_handler) { | 87 std::unique_ptr<MenuRunnerHandler> runner_handler) { |
| 81 runner_handler_ = std::move(runner_handler); | 88 runner_handler_ = std::move(runner_handler); |
| 82 } | 89 } |
| 83 | 90 |
| 84 } // namespace views | 91 } // namespace views |
| OLD | NEW |