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 "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 | 8 |
9 @interface WebMenuRunner (PrivateAPI) | 9 @interface WebMenuRunner (PrivateAPI) |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 [attrs setObject:directionArray forKey:NSWritingDirectionAttributeName]; | 75 [attrs setObject:directionArray forKey:NSWritingDirectionAttributeName]; |
76 } | 76 } |
77 | 77 |
78 [attrs setObject:[NSFont menuFontOfSize:fontSize_] | 78 [attrs setObject:[NSFont menuFontOfSize:fontSize_] |
79 forKey:NSFontAttributeName]; | 79 forKey:NSFontAttributeName]; |
80 | 80 |
81 base::scoped_nsobject<NSAttributedString> attrTitle( | 81 base::scoped_nsobject<NSAttributedString> attrTitle( |
82 [[NSAttributedString alloc] initWithString:title attributes:attrs]); | 82 [[NSAttributedString alloc] initWithString:title attributes:attrs]); |
83 [menuItem setAttributedTitle:attrTitle]; | 83 [menuItem setAttributedTitle:attrTitle]; |
84 | 84 |
85 // We set the title as well as the attributed title here. The attributed title | |
86 // will be displayed in the menu, but typeahead will use the non-attributed | |
87 // string that doesn't contain any leading or trailing whitespace. This is | |
88 // what Apple uses in WebKit as well. | |
Avi (use Gerrit)
2013/12/02 14:53:06
If you're referring to "what Apple uses in WebKit"
| |
89 NSCharacterSet* whitespaceSet = [NSCharacterSet whitespaceCharacterSet]; | |
90 [menuItem setTitle:[title stringByTrimmingCharactersInSet:whitespaceSet]]; | |
91 | |
85 [menuItem setTag:[menu_ numberOfItems] - 1]; | 92 [menuItem setTag:[menu_ numberOfItems] - 1]; |
86 } | 93 } |
87 | 94 |
88 // Reflects the result of the user's interaction with the popup menu. If NO, the | 95 // Reflects the result of the user's interaction with the popup menu. If NO, the |
89 // menu was dismissed without the user choosing an item, which can happen if the | 96 // menu was dismissed without the user choosing an item, which can happen if the |
90 // user clicked outside the menu region or hit the escape key. If YES, the user | 97 // user clicked outside the menu region or hit the escape key. If YES, the user |
91 // selected an item from the menu. | 98 // selected an item from the menu. |
92 - (BOOL)menuItemWasChosen { | 99 - (BOOL)menuItemWasChosen { |
93 return menuItemWasChosen_; | 100 return menuItemWasChosen_; |
94 } | 101 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 145 |
139 if ([self menuItemWasChosen]) | 146 if ([self menuItemWasChosen]) |
140 index_ = [cell indexOfSelectedItem]; | 147 index_ = [cell indexOfSelectedItem]; |
141 } | 148 } |
142 | 149 |
143 - (int)indexOfSelectedItem { | 150 - (int)indexOfSelectedItem { |
144 return index_; | 151 return index_; |
145 } | 152 } |
146 | 153 |
147 @end // WebMenuRunner | 154 @end // WebMenuRunner |
OLD | NEW |