Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: ui/views/controls/menu/menu_runner.cc

Issue 2790773002: Cleanup MenuRunner API (Closed)
Patch Set: Rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
21 run_types, 21 run_types,
22 on_menu_closed_callback)) {} 22 on_menu_closed_callback)) {}
23 23
24 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types) 24 MenuRunner::MenuRunner(MenuItemView* menu_view, int32_t run_types)
25 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {} 25 : run_types_(run_types), impl_(new internal::MenuRunnerImpl(menu_view)) {}
26 26
27 MenuRunner::~MenuRunner() { 27 MenuRunner::~MenuRunner() {
28 impl_->Release(); 28 impl_->Release();
29 } 29 }
30 30
31 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, 31 void MenuRunner::RunMenuAt(Widget* parent,
32 MenuButton* button, 32 MenuButton* button,
33 const gfx::Rect& bounds, 33 const gfx::Rect& bounds,
34 MenuAnchorPosition anchor, 34 MenuAnchorPosition anchor,
35 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 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 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. 38 // capture from the mouse down). So we clear its state here.
39 if (parent && parent->GetRootView()) 39 if (parent && parent->GetRootView())
40 parent->GetRootView()->SetMouseHandler(nullptr); 40 parent->GetRootView()->SetMouseHandler(nullptr);
41 41
42 if (runner_handler_.get()) { 42 if (runner_handler_.get()) {
43 return runner_handler_->RunMenuAt( 43 runner_handler_->RunMenuAt(parent, button, bounds, anchor, source_type,
44 parent, button, bounds, anchor, source_type, run_types_); 44 run_types_);
45 return;
45 } 46 }
46 47
47 // The parent of the nested menu will have created a DisplayChangeListener, so 48 // The parent of the nested menu will have created a DisplayChangeListener, so
48 // we avoid creating a DisplayChangeListener if nested. Drop menus are 49 // we avoid creating a DisplayChangeListener if nested. Drop menus are
49 // transient, so we don't cancel in that case. 50 // transient, so we don't cancel in that case.
50 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) { 51 if ((run_types_ & (IS_NESTED | FOR_DROP)) == 0 && parent) {
51 display_change_listener_.reset( 52 display_change_listener_.reset(
52 internal::DisplayChangeListener::Create(parent, this)); 53 internal::DisplayChangeListener::Create(parent, this));
53 } 54 }
54 55
55 if (run_types_ & CONTEXT_MENU) { 56 if (run_types_ & CONTEXT_MENU) {
56 switch (source_type) { 57 switch (source_type) {
57 case ui::MENU_SOURCE_NONE: 58 case ui::MENU_SOURCE_NONE:
58 case ui::MENU_SOURCE_KEYBOARD: 59 case ui::MENU_SOURCE_KEYBOARD:
59 case ui::MENU_SOURCE_MOUSE: 60 case ui::MENU_SOURCE_MOUSE:
60 anchor = MENU_ANCHOR_TOPLEFT; 61 anchor = MENU_ANCHOR_TOPLEFT;
61 break; 62 break;
62 case ui::MENU_SOURCE_TOUCH: 63 case ui::MENU_SOURCE_TOUCH:
63 case ui::MENU_SOURCE_TOUCH_EDIT_MENU: 64 case ui::MENU_SOURCE_TOUCH_EDIT_MENU:
64 anchor = MENU_ANCHOR_BOTTOMCENTER; 65 anchor = MENU_ANCHOR_BOTTOMCENTER;
65 break; 66 break;
66 default: 67 default:
67 break; 68 break;
68 } 69 }
69 } 70 }
70 71
71 return impl_->RunMenuAt(parent, button, bounds, anchor, run_types_); 72 impl_->RunMenuAt(parent, button, bounds, anchor, run_types_);
72 } 73 }
73 74
74 bool MenuRunner::IsRunning() const { 75 bool MenuRunner::IsRunning() const {
75 return impl_->IsRunning(); 76 return impl_->IsRunning();
76 } 77 }
77 78
78 void MenuRunner::Cancel() { 79 void MenuRunner::Cancel() {
79 impl_->Cancel(); 80 impl_->Cancel();
80 } 81 }
81 82
82 base::TimeTicks MenuRunner::closing_event_time() const { 83 base::TimeTicks MenuRunner::closing_event_time() const {
83 return impl_->GetClosingEventTime(); 84 return impl_->GetClosingEventTime();
84 } 85 }
85 86
86 void MenuRunner::SetRunnerHandler( 87 void MenuRunner::SetRunnerHandler(
87 std::unique_ptr<MenuRunnerHandler> runner_handler) { 88 std::unique_ptr<MenuRunnerHandler> runner_handler) {
88 runner_handler_ = std::move(runner_handler); 89 runner_handler_ = std::move(runner_handler);
89 } 90 }
90 91
91 } // namespace views 92 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner.h ('k') | ui/views/controls/menu/menu_runner_cocoa_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698