diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 22:13:04 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 22:13:04 +0000 |
commit | b88ab037fc20ab5dfe0f35d71e78acc8499979a5 (patch) | |
tree | 7d0a9863885e4c70fe1a24f021a28da8a95a736b /webkit/glue/webmenurunner_mac.mm | |
parent | 5e26d9d482761e38a15f8cb987294d979bc58576 (diff) | |
download | chromium_src-b88ab037fc20ab5dfe0f35d71e78acc8499979a5.zip chromium_src-b88ab037fc20ab5dfe0f35d71e78acc8499979a5.tar.gz chromium_src-b88ab037fc20ab5dfe0f35d71e78acc8499979a5.tar.bz2 |
Do right-alignment of popups when WebKit indicates to do so.
BUG=http://crbug.com/23106
TEST=as in bug
Review URL: http://codereview.chromium.org/1992006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webmenurunner_mac.mm')
-rw-r--r-- | webkit/glue/webmenurunner_mac.mm | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/webkit/glue/webmenurunner_mac.mm b/webkit/glue/webmenurunner_mac.mm index 6144376..e4c8a4b 100644 --- a/webkit/glue/webmenurunner_mac.mm +++ b/webkit/glue/webmenurunner_mac.mm @@ -26,7 +26,8 @@ BOOL gNewNSMenuAPI; @interface WebMenuRunner (PrivateAPI) // Worker function used during initialization. -- (void)addItem:(const WebMenuItem&)item; +- (void)addItem:(const WebMenuItem&)item + withAttributes:(NSDictionary*)attrs; // A callback for the menu controller object to call when an item is selected // from the menu. This is not called if the menu is dismissed without a @@ -38,7 +39,8 @@ BOOL gNewNSMenuAPI; @implementation WebMenuRunner - (id)initWithItems:(const std::vector<WebMenuItem>&)items - fontSize:(CGFloat)fontSize { + fontSize:(CGFloat)fontSize + rightAligned:(BOOL)rightAligned { static BOOL newNSMenuAPIInitialized = NO; if (!newNSMenuAPIInitialized) { newNSMenuAPIInitialized = YES; @@ -54,13 +56,24 @@ BOOL gNewNSMenuAPI; [menu_ setAutoenablesItems:NO]; index_ = -1; fontSize_ = fontSize; + scoped_nsobject<NSDictionary> attrs; + if (rightAligned) { + // NB: Right-aligning menu items in this manner is known to not work in + // Mac OS X 10.5. + scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( + [[NSMutableParagraphStyle alloc] init]); + [paragraphStyle setAlignment:NSRightTextAlignment]; + attrs.reset([[NSDictionary alloc] initWithObjectsAndKeys: + paragraphStyle, NSParagraphStyleAttributeName, nil]); + } for (size_t i = 0; i < items.size(); ++i) - [self addItem:items[i]]; + [self addItem:items[i] withAttributes:attrs]; } return self; } -- (void)addItem:(const WebMenuItem&)item { +- (void)addItem:(const WebMenuItem&)item + withAttributes:(NSDictionary*)attrs { if (item.type == WebMenuItem::SEPARATOR) { [menu_ addItem:[NSMenuItem separatorItem]]; return; @@ -72,6 +85,12 @@ BOOL gNewNSMenuAPI; keyEquivalent:@""]; [menuItem setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)]; [menuItem setTarget:self]; + if (attrs) { + scoped_nsobject<NSAttributedString> attrTitle( + [[NSAttributedString alloc] initWithString:title + attributes:attrs]); + [menuItem setAttributedTitle:attrTitle]; + } if (gNewNSMenuAPI) [menuItem setTag:[menu_ numberOfItems] - 1]; } |