OLD | NEW |
---|---|
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 Loading... | |
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:)]) { | 124 SEL sel = @selector(setUserInterfaceLayoutDirection:); |
125 [cell setUserInterfaceLayoutDirection: | 125 if ([cell respondsToSelector:sel]) { |
Avi (use Gerrit)
2016/11/30 17:25:04
NSCell has supported this property since 10.6, so
tkent
2016/11/30 23:43:57
Done.
| |
126 NSUserInterfaceLayoutDirectionRightToLeft]; | 126 [cell setUserInterfaceLayoutDirection: |
127 NSUserInterfaceLayoutDirectionRightToLeft]; | |
128 } | |
129 // setUserInterfaceLayoutDirection for NSMenu is supported on macOS 10.11+. | |
130 if ([menu_ respondsToSelector:sel]) { | |
131 NSUserInterfaceLayoutDirection direction = | |
132 NSUserInterfaceLayoutDirectionRightToLeft; | |
133 NSMethodSignature* signature = | |
134 [NSMenu instanceMethodSignatureForSelector:sel]; | |
135 NSInvocation* invocation = | |
136 [NSInvocation invocationWithMethodSignature:signature]; | |
137 [invocation setTarget:menu_.get()]; | |
138 [invocation setSelector:sel]; | |
139 [invocation setArgument:&direction atIndex:2]; | |
140 [invocation invoke]; | |
141 } | |
127 } | 142 } |
128 | 143 |
129 // When popping up a menu near the Dock, Cocoa restricts the menu | 144 // 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 | 145 // 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 | 146 // 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 | 147 // popped up above the element, so that the current item can be |
133 // selected without mouse-tracking selecting a different item | 148 // selected without mouse-tracking selecting a different item |
134 // immediately. | 149 // immediately. |
135 // | 150 // |
136 // Unfortunately, instead of popping up above the passed |bounds|, | 151 // Unfortunately, instead of popping up above the passed |bounds|, |
(...skipping 15 matching lines...) Expand all Loading... | |
152 | 167 |
153 - (void)hide { | 168 - (void)hide { |
154 [menu_ cancelTracking]; | 169 [menu_ cancelTracking]; |
155 } | 170 } |
156 | 171 |
157 - (int)indexOfSelectedItem { | 172 - (int)indexOfSelectedItem { |
158 return index_; | 173 return index_; |
159 } | 174 } |
160 | 175 |
161 @end // WebMenuRunner | 176 @end // WebMenuRunner |
OLD | NEW |