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

Side by Side Diff: content/browser/renderer_host/webmenurunner_mac.mm

Issue 2539543007: macOS: Fix <select> popup menu position in RTL. (Closed)
Patch Set: No respondoToSelector for NSPopUpButtonCell Created 4 years 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 | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/renderer_host/webmenurunner_mac.h" 5 #include "content/browser/renderer_host/webmenurunner_mac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Set up the button cell, converting to NSView coordinates. The menu is 113 // Set up the button cell, converting to NSView coordinates. The menu is
114 // positioned such that the currently selected menu item appears over the 114 // positioned such that the currently selected menu item appears over the
115 // popup button, which is the expected Mac popup menu behavior. 115 // popup button, which is the expected Mac popup menu behavior.
116 base::scoped_nsobject<NSPopUpButtonCell> cell( 116 base::scoped_nsobject<NSPopUpButtonCell> cell(
117 [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]); 117 [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]);
118 [cell setMenu:menu_]; 118 [cell setMenu:menu_];
119 // We use selectItemWithTag below so if the index is out-of-bounds nothing 119 // We use selectItemWithTag below so if the index is out-of-bounds nothing
120 // bad happens. 120 // bad happens.
121 [cell selectItemWithTag:index]; 121 [cell selectItemWithTag:index];
122 122
123 if (rightAligned_ && 123 if (rightAligned_) {
124 [cell respondsToSelector:@selector(setUserInterfaceLayoutDirection:)]) {
125 [cell setUserInterfaceLayoutDirection: 124 [cell setUserInterfaceLayoutDirection:
126 NSUserInterfaceLayoutDirectionRightToLeft]; 125 NSUserInterfaceLayoutDirectionRightToLeft];
126 // setUserInterfaceLayoutDirection for NSMenu is supported on macOS 10.11+.
127 SEL sel = @selector(setUserInterfaceLayoutDirection:);
128 if ([menu_ respondsToSelector:sel]) {
129 NSUserInterfaceLayoutDirection direction =
130 NSUserInterfaceLayoutDirectionRightToLeft;
131 NSMethodSignature* signature =
132 [NSMenu instanceMethodSignatureForSelector:sel];
133 NSInvocation* invocation =
134 [NSInvocation invocationWithMethodSignature:signature];
135 [invocation setTarget:menu_.get()];
136 [invocation setSelector:sel];
137 [invocation setArgument:&direction atIndex:2];
138 [invocation invoke];
139 }
127 } 140 }
128 141
129 // When popping up a menu near the Dock, Cocoa restricts the menu 142 // When popping up a menu near the Dock, Cocoa restricts the menu
130 // size to not overlap the Dock, with a scroll arrow. Below a 143 // size to not overlap the Dock, with a scroll arrow. Below a
131 // certain point this doesn't work. At that point the menu is 144 // certain point this doesn't work. At that point the menu is
132 // popped up above the element, so that the current item can be 145 // popped up above the element, so that the current item can be
133 // selected without mouse-tracking selecting a different item 146 // selected without mouse-tracking selecting a different item
134 // immediately. 147 // immediately.
135 // 148 //
136 // Unfortunately, instead of popping up above the passed |bounds|, 149 // Unfortunately, instead of popping up above the passed |bounds|,
(...skipping 15 matching lines...) Expand all
152 165
153 - (void)hide { 166 - (void)hide {
154 [menu_ cancelTracking]; 167 [menu_ cancelTracking];
155 } 168 }
156 169
157 - (int)indexOfSelectedItem { 170 - (int)indexOfSelectedItem {
158 return index_; 171 return index_;
159 } 172 }
160 173
161 @end // WebMenuRunner 174 @end // WebMenuRunner
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698