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

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

Issue 2072653002: Experiments for using textfieldy context menus Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/cocoa/bridged_content_view.mm ('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"
11 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/mac/coordinate_conversion.h" 12 #include "ui/gfx/mac/coordinate_conversion.h"
13 #include "ui/views/cocoa/bridged_content_view.h"
13 #include "ui/views/controls/menu/menu_runner_impl_adapter.h" 14 #include "ui/views/controls/menu/menu_runner_impl_adapter.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 16
16 namespace views { 17 namespace views {
17 namespace internal { 18 namespace internal {
18 namespace { 19 namespace {
19 20
20 // The menu run types that should show a native NSMenu rather than a toolkit- 21 // The menu run types that should show a native NSMenu rather than a toolkit-
21 // views menu. Only supported when the menu is backed by a ui::MenuModel. 22 // views menu. Only supported when the menu is backed by a ui::MenuModel.
22 const int kNativeRunTypes = MenuRunner::CONTEXT_MENU | MenuRunner::COMBOBOX; 23 const int kNativeRunTypes = MenuRunner::CONTEXT_MENU | MenuRunner::COMBOBOX;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const gfx::Rect& bounds, 122 const gfx::Rect& bounds,
122 MenuAnchorPosition anchor, 123 MenuAnchorPosition anchor,
123 int32_t run_types) { 124 int32_t run_types) {
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 running_ = true;
129 130
130 if (run_types & MenuRunner::CONTEXT_MENU) { 131 if (run_types & MenuRunner::CONTEXT_MENU) {
131 [NSMenu popUpContextMenu:[menu_controller_ menu] 132 id view = parent->GetNativeView();
133 if ([view respondsToSelector:@selector(contextMenuView)])
134 view = [view contextMenuView];
135 [NSMenu popUpContextMenu:[NSTextView defaultMenu] //[menu_controller_ menu]
132 withEvent:[NSApp currentEvent] 136 withEvent:[NSApp currentEvent]
133 forView:parent->GetNativeView()]; 137 forView:view];
134 } else if (run_types & MenuRunner::COMBOBOX) { 138 } else if (run_types & MenuRunner::COMBOBOX) {
135 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_); 139 NSMenuItem* checked_item = FirstCheckedItem(menu_controller_);
136 base::scoped_nsobject<NSView> anchor_view( 140 base::scoped_nsobject<NSView> anchor_view(
137 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item)); 141 CreateMenuAnchorView(parent->GetNativeWindow(), bounds, checked_item));
138 NSMenu* menu = [menu_controller_ menu]; 142 NSMenu* menu = [menu_controller_ menu];
139 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth]; 143 [menu setMinimumWidth:bounds.width() + kNativeCheckmarkWidth];
140 [menu popUpMenuPositioningItem:checked_item 144 [menu popUpMenuPositioningItem:checked_item
141 atLocation:NSZeroPoint 145 atLocation:NSZeroPoint
142 inView:anchor_view]; 146 inView:anchor_view];
143 [anchor_view removeFromSuperview]; 147 [anchor_view removeFromSuperview];
(...skipping 18 matching lines...) Expand all
162 166
163 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const { 167 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const {
164 return closing_event_time_; 168 return closing_event_time_;
165 } 169 }
166 170
167 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { 171 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() {
168 } 172 }
169 173
170 } // namespace internal 174 } // namespace internal
171 } // namespace views 175 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698