diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webmenurunner_mac.h | 3 | ||||
-rw-r--r-- | webkit/glue/webmenurunner_mac.mm | 27 | ||||
-rw-r--r-- | webkit/tools/test_shell/mac/test_webview_delegate.mm | 4 |
3 files changed, 28 insertions, 6 deletions
diff --git a/webkit/glue/webmenurunner_mac.h b/webkit/glue/webmenurunner_mac.h index 6f01daf..c56eeeb 100644 --- a/webkit/glue/webmenurunner_mac.h +++ b/webkit/glue/webmenurunner_mac.h @@ -37,7 +37,8 @@ // Initializes the MenuDelegate with a list of items sent from WebKit. - (id)initWithItems:(const std::vector<WebMenuItem>&)items - fontSize:(CGFloat)fontSize; + fontSize:(CGFloat)fontSize + rightAligned:(BOOL)rightAligned; // Returns YES if an item was selected from the menu, NO if the menu was // dismissed. 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]; } diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm index 83d0237..9e4d949 100644 --- a/webkit/tools/test_shell/mac/test_webview_delegate.mm +++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm @@ -48,6 +48,7 @@ void TestWebViewDelegate::show(WebNavigationPolicy policy) { int item_height = popup_menu_info_->itemHeight; double font_size = popup_menu_info_->itemFontSize; int selected_index = popup_menu_info_->selectedIndex; + bool right_aligned = popup_menu_info_->rightAligned; popup_menu_info_.reset(); // No longer needed. const WebRect& bounds = popup_bounds_; @@ -62,7 +63,8 @@ void TestWebViewDelegate::show(WebNavigationPolicy policy) { // Display the menu. scoped_nsobject<WebMenuRunner> menu_runner; menu_runner.reset([[WebMenuRunner alloc] initWithItems:items - fontSize:font_size]); + fontSize:font_size + rightAligned:right_aligned]); [menu_runner runMenuInView:shell_->webViewWnd() withBounds:position |