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:)]) { | |
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 Loading... |
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 |
OLD | NEW |