Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: webkit/glue/webmenurunner_mac.mm

Issue 1992006: Do right-alignment of popups when WebKit indicates to do so. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/webmenurunner_mac.h ('k') | webkit/tools/test_shell/mac/test_webview_delegate.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webmenurunner_mac.mm
===================================================================
--- webkit/glue/webmenurunner_mac.mm (revision 47162)
+++ webkit/glue/webmenurunner_mac.mm (working copy)
@@ -26,7 +26,8 @@
@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 @@
@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 @@
[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 @@
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];
}
« no previous file with comments | « webkit/glue/webmenurunner_mac.h ('k') | webkit/tools/test_shell/mac/test_webview_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698