| 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: |
| 89 // http://trac.webkit.org/browser/trunk/Source/WebKit2/UIProcess/mac/WebPopupM
enuProxyMac.mm#L90 |
| 90 NSCharacterSet* whitespaceSet = [NSCharacterSet whitespaceCharacterSet]; |
| 91 [menuItem setTitle:[title stringByTrimmingCharactersInSet:whitespaceSet]]; |
| 92 |
| 85 [menuItem setTag:[menu_ numberOfItems] - 1]; | 93 [menuItem setTag:[menu_ numberOfItems] - 1]; |
| 86 } | 94 } |
| 87 | 95 |
| 88 // Reflects the result of the user's interaction with the popup menu. If NO, the | 96 // 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 | 97 // 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 | 98 // user clicked outside the menu region or hit the escape key. If YES, the user |
| 91 // selected an item from the menu. | 99 // selected an item from the menu. |
| 92 - (BOOL)menuItemWasChosen { | 100 - (BOOL)menuItemWasChosen { |
| 93 return menuItemWasChosen_; | 101 return menuItemWasChosen_; |
| 94 } | 102 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 146 |
| 139 if ([self menuItemWasChosen]) | 147 if ([self menuItemWasChosen]) |
| 140 index_ = [cell indexOfSelectedItem]; | 148 index_ = [cell indexOfSelectedItem]; |
| 141 } | 149 } |
| 142 | 150 |
| 143 - (int)indexOfSelectedItem { | 151 - (int)indexOfSelectedItem { |
| 144 return index_; | 152 return index_; |
| 145 } | 153 } |
| 146 | 154 |
| 147 @end // WebMenuRunner | 155 @end // WebMenuRunner |
| OLD | NEW |