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

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

Issue 1951223002: MacViews: Fix failing Menu Runner Cocoa Tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl_cocoa.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/event_utils.h" 10 #include "ui/events/event_utils.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 int32_t run_types) { 86 int32_t run_types) {
87 if ((run_types & kNativeRunTypes) != 0 && 87 if ((run_types & kNativeRunTypes) != 0 &&
88 (run_types & MenuRunner::IS_NESTED) == 0) { 88 (run_types & MenuRunner::IS_NESTED) == 0) {
89 return new MenuRunnerImplCocoa(menu_model); 89 return new MenuRunnerImplCocoa(menu_model);
90 } 90 }
91 91
92 return new MenuRunnerImplAdapter(menu_model); 92 return new MenuRunnerImplAdapter(menu_model);
93 } 93 }
94 94
95 MenuRunnerImplCocoa::MenuRunnerImplCocoa(ui::MenuModel* menu) 95 MenuRunnerImplCocoa::MenuRunnerImplCocoa(ui::MenuModel* menu)
96 : running_(false), 96 : in_run_menu_at_(false),
97 delete_after_run_(false), 97 delete_after_run_(false),
98 closing_event_time_(base::TimeDelta()) { 98 closing_event_time_(base::TimeDelta()) {
99 menu_controller_.reset( 99 menu_controller_.reset(
100 [[MenuController alloc] initWithModel:menu useWithPopUpButtonCell:NO]); 100 [[MenuController alloc] initWithModel:menu useWithPopUpButtonCell:NO]);
101 } 101 }
102 102
103 bool MenuRunnerImplCocoa::IsRunning() const { 103 bool MenuRunnerImplCocoa::IsRunning() const {
104 return running_; 104 return [menu_controller_ isMenuOpen];
tapted 2016/05/06 00:37:56 I think this is different to what menu_runner_impl
karandeepb 2016/05/25 04:19:33 Not sure if my understanding is correct, but on Ma
tapted 2016/05/25 05:07:19 yup - but with this change Cocoa *would* return fa
105 } 105 }
106 106
107 void MenuRunnerImplCocoa::Release() { 107 void MenuRunnerImplCocoa::Release() {
108 if (IsRunning()) { 108 if (in_run_menu_at_) {
109 if (delete_after_run_) 109 if (delete_after_run_)
110 return; // We already canceled. 110 return; // We already canceled.
111 111
112 delete_after_run_ = true; 112 delete_after_run_ = true;
113 [menu_controller_ cancel]; 113 [menu_controller_ cancel];
114 } else { 114 } else {
115 delete this; 115 delete this;
116 } 116 }
117 } 117 }
118 118
119 MenuRunner::RunResult MenuRunnerImplCocoa::RunMenuAt(Widget* parent, 119 MenuRunner::RunResult MenuRunnerImplCocoa::RunMenuAt(Widget* parent,
120 MenuButton* button, 120 MenuButton* button,
121 const gfx::Rect& bounds, 121 const gfx::Rect& bounds,
122 MenuAnchorPosition anchor, 122 MenuAnchorPosition anchor,
123 int32_t run_types) { 123 int32_t run_types) {
124 in_run_menu_at_ = true;
124 DCHECK(run_types & kNativeRunTypes); 125 DCHECK(run_types & kNativeRunTypes);
125 DCHECK(!IsRunning()); 126 DCHECK(!IsRunning());
126 DCHECK(parent); 127 DCHECK(parent);
127 closing_event_time_ = base::TimeDelta(); 128 closing_event_time_ = base::TimeDelta();
128 running_ = true;
129 129
130 if (run_types & MenuRunner::CONTEXT_MENU) { 130 if (run_types & MenuRunner::CONTEXT_MENU) {
131 [NSMenu popUpContextMenu:[menu_controller_ menu] 131 [NSMenu popUpContextMenu:[menu_controller_ menu]
132 withEvent:[NSApp currentEvent] 132 withEvent:[NSApp currentEvent]
133 forView:parent->GetNativeView()]; 133 forView:parent->GetNativeView()];
134 } else if (run_types & MenuRunner::COMBOBOX) { 134 } else if (run_types & MenuRunner::COMBOBOX) {
135 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_); 135 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_);
136 base::scoped_nsobject<NSView> anchor_view( 136 base::scoped_nsobject<NSView> anchor_view(
137 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item)); 137 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item));
138 NSMenu* menu = [menu_controller_ menu]; 138 NSMenu* menu = [menu_controller_ menu];
139 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth]; 139 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth];
140 [menu popUpMenuPositioningItem:checked_item 140 [menu popUpMenuPositioningItem:checked_item
141 atLocation:NSZeroPoint 141 atLocation:NSZeroPoint
142 inView:anchor_view]; 142 inView:anchor_view];
143 [anchor_view removeFromSuperview]; 143 [anchor_view removeFromSuperview];
144 } else { 144 } else {
145 NOTREACHED(); 145 NOTREACHED();
146 } 146 }
147 147
148 closing_event_time_ = ui::EventTimeForNow(); 148 closing_event_time_ = ui::EventTimeForNow();
149 running_ = false; 149 in_run_menu_at_ = false;
150 150
151 if (delete_after_run_) { 151 if (delete_after_run_) {
152 delete this; 152 delete this;
153 return MenuRunner::MENU_DELETED; 153 return MenuRunner::MENU_DELETED;
154 } 154 }
155 155
156 return MenuRunner::NORMAL_EXIT; 156 return MenuRunner::NORMAL_EXIT;
157 } 157 }
158 158
159 void MenuRunnerImplCocoa::Cancel() { 159 void MenuRunnerImplCocoa::Cancel() {
160 [menu_controller_ cancel]; 160 [menu_controller_ cancel];
161 } 161 }
162 162
163 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const { 163 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const {
164 return closing_event_time_; 164 return closing_event_time_;
165 } 165 }
166 166
167 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { 167 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() {
168 } 168 }
169 169
170 } // namespace internal 170 } // namespace internal
171 } // namespace views 171 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl_cocoa.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698