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

Side by Side Diff: ui/views/controls/menu/menu_runner_impl_cocoa.mm

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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h" 5 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h"
6 6
7 #include "base/mac/sdk_forward_declarations.h" 7 #include "base/mac/sdk_forward_declarations.h"
8 #import "ui/base/cocoa/menu_controller.h" 8 #import "ui/base/cocoa/menu_controller.h"
9 #include "ui/base/models/menu_model.h" 9 #include "ui/base/models/menu_model.h"
10 #include "ui/events/base_event_utils.h" 10 #include "ui/events/base_event_utils.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 if (delete_after_run_) 114 if (delete_after_run_)
115 return; // We already canceled. 115 return; // We already canceled.
116 116
117 delete_after_run_ = true; 117 delete_after_run_ = true;
118 [menu_controller_ cancel]; 118 [menu_controller_ cancel];
119 } else { 119 } else {
120 delete this; 120 delete this;
121 } 121 }
122 } 122 }
123 123
124 MenuRunner::RunResult MenuRunnerImplCocoa::RunMenuAt(Widget* parent, 124 void MenuRunnerImplCocoa::RunMenuAt(Widget* parent,
125 MenuButton* button, 125 MenuButton* button,
126 const gfx::Rect& bounds, 126 const gfx::Rect& bounds,
127 MenuAnchorPosition anchor, 127 MenuAnchorPosition anchor,
128 int32_t run_types) { 128 int32_t run_types) {
129 DCHECK(run_types & kNativeRunTypes); 129 DCHECK(run_types & kNativeRunTypes);
130 DCHECK(!IsRunning()); 130 DCHECK(!IsRunning());
131 DCHECK(parent); 131 DCHECK(parent);
132 closing_event_time_ = base::TimeTicks(); 132 closing_event_time_ = base::TimeTicks();
133 running_ = true; 133 running_ = true;
134 134
135 if (run_types & MenuRunner::CONTEXT_MENU) { 135 if (run_types & MenuRunner::CONTEXT_MENU) {
136 [NSMenu popUpContextMenu:[menu_controller_ menu] 136 [NSMenu popUpContextMenu:[menu_controller_ menu]
137 withEvent:[NSApp currentEvent] 137 withEvent:[NSApp currentEvent]
138 forView:parent->GetNativeView()]; 138 forView:parent->GetNativeView()];
139 } else if (run_types & MenuRunner::COMBOBOX) { 139 } else if (run_types & MenuRunner::COMBOBOX) {
140 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_); 140 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_);
141 base::scoped_nsobject<NSView> anchor_view( 141 base::scoped_nsobject<NSView> anchor_view(
142 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item)); 142 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item));
143 NSMenu* menu = [menu_controller_ menu]; 143 NSMenu* menu = [menu_controller_ menu];
144 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth]; 144 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth];
145 [menu popUpMenuPositioningItem:checked_item 145 [menu popUpMenuPositioningItem:checked_item
146 atLocation:NSZeroPoint 146 atLocation:NSZeroPoint
147 inView:anchor_view]; 147 inView:anchor_view];
148 [anchor_view removeFromSuperview]; 148 [anchor_view removeFromSuperview];
149 } else { 149 } else {
150 NOTREACHED(); 150 NOTREACHED();
151 } 151 }
152 152
153 closing_event_time_ = ui::EventTimeForNow(); 153 closing_event_time_ = ui::EventTimeForNow();
154 running_ = false; 154 running_ = false;
155 155
156 if (delete_after_run_) { 156 if (delete_after_run_) {
157 delete this; 157 delete this;
158 return MenuRunner::MENU_DELETED; 158 return;
159 } 159 }
160 160
161 // Don't invoke the callback if Release() was called, since that usually means 161 // Don't invoke the callback if Release() was called, since that usually means
162 // the owning instance is being destroyed. 162 // the owning instance is being destroyed.
163 if (!on_menu_closed_callback_.is_null()) 163 if (!on_menu_closed_callback_.is_null())
164 on_menu_closed_callback_.Run(); 164 on_menu_closed_callback_.Run();
165
166 return MenuRunner::NORMAL_EXIT;
167 } 165 }
168 166
169 void MenuRunnerImplCocoa::Cancel() { 167 void MenuRunnerImplCocoa::Cancel() {
170 [menu_controller_ cancel]; 168 [menu_controller_ cancel];
171 } 169 }
172 170
173 base::TimeTicks MenuRunnerImplCocoa::GetClosingEventTime() const { 171 base::TimeTicks MenuRunnerImplCocoa::GetClosingEventTime() const {
174 return closing_event_time_; 172 return closing_event_time_;
175 } 173 }
176 174
177 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { 175 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() {
178 } 176 }
179 177
180 } // namespace internal 178 } // namespace internal
181 } // namespace views 179 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl_cocoa.h ('k') | ui/views/controls/menu/menu_runner_impl_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698