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 #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, int32_t run_types) | 15 MenuRunner::MenuRunner(ui::MenuModel* menu_model, int32_t run_types) |
| 15 : run_types_(run_types), | 16 : run_types_(run_types), |
| 16 impl_(internal::MenuRunnerImplInterface::Create(menu_model, run_types)) {} | 17 impl_(internal::MenuRunnerImplInterface::Create(menu_model, run_types)) {} |
| 17 | 18 |
| 18 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types) | 19 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types) |
| 19 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {} | 20 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {} |
| 20 | 21 |
| 21 MenuRunner::~MenuRunner() { | 22 MenuRunner::~MenuRunner() { |
| 22 impl_->Release(); | 23 impl_->Release(); |
| 23 } | 24 } |
| 24 | 25 |
| 25 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 26 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
| 26 MenuButton* button, | 27 MenuButton* button, |
| 27 const gfx::Rect& bounds, | 28 const gfx::Rect& bounds, |
| 28 MenuAnchorPosition anchor, | 29 MenuAnchorPosition anchor, |
| 29 ui::MenuSourceType source_type) { | 30 ui::MenuSourceType source_type) { |
| 31 // If we are shown on mouse press, we will eat the subsequent mouse down and | |
| 32 // the parent widget will not be able to reset its state (it might have mouse | |
| 33 // capture from the mouse down). So we clear its state here. | |
| 34 if (parent && parent->GetRootView()) | |
| 35 parent->GetRootView()->SetMouseHandler(nullptr); | |
| 36 | |
| 30 if (runner_handler_.get()) { | 37 if (runner_handler_.get()) { |
| 31 return runner_handler_->RunMenuAt( | 38 return runner_handler_->RunMenuAt( |
| 32 parent, button, bounds, anchor, source_type, run_types_); | 39 parent, button, bounds, anchor, source_type, run_types_); |
| 33 } | 40 } |
| 34 | 41 |
| 35 // The parent of the nested menu will have created a DisplayChangeListener, so | 42 // The parent of the nested menu will have created a DisplayChangeListener, so |
| 36 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 43 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
| 37 // transient, so we don't cancel in that case. | 44 // transient, so we don't cancel in that case. |
| 38 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) { | 45 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
| 39 display_change_listener_.reset( | 46 display_change_listener_.reset( |
| 40 internal::DisplayChangeListener::Create(parent, this)); | 47 internal::DisplayChangeListener::Create(parent, this)); |
| 41 } | 48 } |
| 42 | 49 |
| 43 if (run_types_ & CONTEXT_MENU) { | 50 if (run_types_ & CONTEXT_MENU) { |
| 44 switch (source_type) { | 51 switch (source_type) { |
| 45 case ui::MENU_SOURCE_NONE: | 52 case ui::MENU_SOURCE_NONE: |
| 46 case ui::MENU_SOURCE_KEYBOARD: | 53 case ui::MENU_SOURCE_KEYBOARD: |
| 47 case ui::MENU_SOURCE_MOUSE: | 54 case ui::MENU_SOURCE_MOUSE: |
| 48 anchor = MENU_ANCHOR_TOPLEFT; | 55 anchor = MENU_ANCHOR_TOPLEFT; |
| 49 break; | 56 break; |
| 50 case ui::MENU_SOURCE_TOUCH: | 57 case ui::MENU_SOURCE_TOUCH: |
| 51 case ui::MENU_SOURCE_TOUCH_EDIT_MENU: | 58 case ui::MENU_SOURCE_TOUCH_EDIT_MENU: |
| 52 anchor = MENU_ANCHOR_BOTTOMCENTER; | 59 anchor = MENU_ANCHOR_BOTTOMCENTER; |
| 53 break; | 60 break; |
| 54 default: | 61 default: |
| 55 break; | 62 break; |
| 56 } | 63 } |
| 57 } | 64 } |
| 58 | 65 |
| 59 return impl_->RunMenuAt(parent, button, bounds, anchor, run_types_); | 66 return impl_->RunMenuAt(parent, button, bounds, anchor, run_types_); |
|
tapted
2016/10/27 23:19:24
(answering for themblsha :), This line may call
M
themblsha
2016/10/29 13:47:19
Thanks for your tremendous patience with helping u
| |
| 60 } | 67 } |
| 61 | 68 |
| 62 bool MenuRunner::IsRunning() const { | 69 bool MenuRunner::IsRunning() const { |
| 63 return impl_->IsRunning(); | 70 return impl_->IsRunning(); |
| 64 } | 71 } |
| 65 | 72 |
| 66 void MenuRunner::Cancel() { | 73 void MenuRunner::Cancel() { |
| 67 impl_->Cancel(); | 74 impl_->Cancel(); |
| 68 } | 75 } |
| 69 | 76 |
| 70 base::TimeTicks MenuRunner::closing_event_time() const { | 77 base::TimeTicks MenuRunner::closing_event_time() const { |
| 71 return impl_->GetClosingEventTime(); | 78 return impl_->GetClosingEventTime(); |
| 72 } | 79 } |
| 73 | 80 |
| 74 void MenuRunner::SetRunnerHandler( | 81 void MenuRunner::SetRunnerHandler( |
| 75 std::unique_ptr<MenuRunnerHandler> runner_handler) { | 82 std::unique_ptr<MenuRunnerHandler> runner_handler) { |
| 76 runner_handler_ = std::move(runner_handler); | 83 runner_handler_ = std::move(runner_handler); |
| 77 } | 84 } |
| 78 | 85 |
| 79 } // namespace views | 86 } // namespace views |
| OLD | NEW |