Chromium Code Reviews| Index: chrome/browser/ui/cocoa/web_intent_sheet_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm b/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm |
| index b284567991f41af567199263e167a75a37547d9a..2c16cdfdd9f7665b217bc70d8d08338214c15204 100644 |
| --- a/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm |
| +++ b/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm |
| @@ -35,6 +35,9 @@ |
| using content::OpenURLParams; |
| using content::Referrer; |
| +@interface CustomLinkButtonCell : HyperlinkButtonCell |
| +@end |
| + |
| namespace { |
| // The width of a service button, in view coordinates. |
| @@ -46,9 +49,6 @@ const CGFloat kVerticalSpacing = 18; |
| // Square size of the close button. |
| const CGFloat kCloseButtonSize = 16; |
| -// Font size for picker header. |
| -const CGFloat kHeaderFontSize = 14.5; |
| - |
| // Width of the text fields. |
| const CGFloat kTextWidth = WebIntentPicker::kWindowWidth - |
| (WebIntentPicker::kContentAreaBorder * 2.0 + kCloseButtonSize); |
| @@ -66,8 +66,8 @@ void ConfigureTextFieldAsLabel(NSTextField* field) { |
| NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { |
| NSButton* button = [[NSButton alloc] initWithFrame:frame]; |
| - scoped_nsobject<HyperlinkButtonCell> cell( |
| - [[HyperlinkButtonCell alloc] initTextCell:title]); |
| + scoped_nsobject<CustomLinkButtonCell> cell( |
| + [[CustomLinkButtonCell alloc] initTextCell:title]); |
| [cell setControlSize:NSSmallControlSize]; |
| [button setCell:cell.get()]; |
| [button setButtonType:NSMomentaryPushInButton]; |
| @@ -78,6 +78,24 @@ NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { |
| } // namespace |
| + |
| +// Overrides attributes for the custom link format in intent picker. |
| +@implementation CustomLinkButtonCell |
| +- (NSDictionary*)linkAttributes { |
| + scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
| + [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
| + [paragraphStyle setAlignment:[self alignment]]; |
| + |
| + return [NSDictionary dictionaryWithObjectsAndKeys: |
|
Nico
2012/09/05 04:32:33
nit:
return @{
NSForegroundColorAttributeName:
groby-ooo-7-16
2012/09/06 02:43:48
Done.
|
| + [self textColor], NSForegroundColorAttributeName, |
| + [self font], NSFontAttributeName, |
| + [NSCursor pointingHandCursor], NSCursorAttributeName, |
| + paragraphStyle.get(), NSParagraphStyleAttributeName, |
| + nil |
|
Nico
2012/09/05 04:32:33
So this is overridden to remove the underline? Why
groby-ooo-7-16
2012/09/06 02:43:48
Because UI directive is to look like WebUI, even i
Nico
2012/09/06 02:48:21
Can you add a comment to that end? (And maybe remo
groby-ooo-7-16
2012/09/07 00:05:21
Done.
|
| + ]; |
| +} |
| +@end |
| + |
| // This simple NSView subclass is used as the single subview of the page info |
| // bubble's window's contentView. Drawing is flipped so that layout of the |
| // sections is easier. Apple recommends flipping the coordinate origin when |
| @@ -637,7 +655,7 @@ const CGFloat kAddButtonWidth = 128.0; |
| inlineDispositionTitleField_.reset([[NSTextField alloc] init]); |
| ConfigureTextFieldAsLabel(inlineDispositionTitleField_); |
| - |
| + [inlineDispositionTitleField_ setFont:[NSFont boldSystemFontOfSize:0]]; |
| flipView_.reset([[WebIntentsContentView alloc] init]); |
| [flipView_ setAutoresizingMask:NSViewMinYMargin]; |
| [[[self window] contentView] setSubviews: |
| @@ -704,7 +722,6 @@ const CGFloat kAddButtonWidth = 128.0; |
| buttonFrame.origin.x = containerSize.width - |
| WebIntentPicker::kContentAreaBorder - kCloseButtonSize; |
| [closeButton_ setFrame:buttonFrame]; |
| - |
| [self setContainerSize:containerSize]; |
| } |
| @@ -856,9 +873,35 @@ const CGFloat kAddButtonWidth = 128.0; |
| - (CGFloat)addAnotherServiceLinkToSubviews:(NSMutableArray*)subviews |
| atOffset:(CGFloat)offset { |
| + DCHECK(model_); |
| + DCHECK(model_->IsInlineDisposition()); |
| + GURL url = model_->inline_disposition_url(); |
| + const WebIntentPickerModel::InstalledService* service = |
| + model_->GetInstalledServiceWithURL(url); |
| + DCHECK(service); |
| + |
| + CGFloat originalOffset = offset; |
| + |
| + // Icon for current service. |
| + scoped_nsobject<NSImageView> icon; |
| + NSRect imageFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, |
| + 0, 0); |
| + icon.reset([[NSImageView alloc] initWithFrame:imageFrame]); |
| + [icon setImage:service->favicon.ToNSImage()]; |
| + [icon setImageFrameStyle:NSImageFrameNone]; |
| + [icon setEnabled:YES]; |
| + |
| + imageFrame.size = [service->favicon.ToNSImage() size]; |
| + [icon setFrame:imageFrame]; |
| + |
| + [subviews addObject:icon]; |
| + |
| + // Resize control to fit text |
| NSRect textFrame = |
| - NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, kTextWidth, 1); |
| + NSMakeRect(NSMaxX(imageFrame) + 4, |
| + offset, |
| + WebIntentPicker::kTitleLinkMaxWidth, 1); |
| [inlineDispositionTitleField_ setFrame:textFrame]; |
| [subviews addObject:inlineDispositionTitleField_]; |
| [GTMUILocalizerAndLayoutTweaker sizeToFitView:inlineDispositionTitleField_]; |
| @@ -870,11 +913,12 @@ const CGFloat kAddButtonWidth = 128.0; |
| model_->GetSuggestedExtensionCount()) { |
| NSRect frame = NSMakeRect( |
| NSMaxX(textFrame) + WebIntentPicker::kContentAreaBorder, offset, |
| - WebIntentPicker::kTitleLinkMaxWidth, 1); |
| + 1, 1); |
| NSString* string = l10n_util::GetNSStringWithFixup( |
| IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE); |
| scoped_nsobject<NSButton> button(CreateHyperlinkButton(string, frame)); |
| [[button cell] setControlSize:NSRegularControlSize]; |
| + [[button cell] setFont:[NSFont controlContentFontOfSize:0]]; |
| [button setTarget:self]; |
| [button setAction:@selector(chooseAnotherService:)]; |
| [subviews addObject:button]; |
| @@ -882,6 +926,13 @@ const CGFloat kAddButtonWidth = 128.0; |
| // Call size-to-fit to fixup for the localized string. |
| [GTMUILocalizerAndLayoutTweaker sizeToFitView:button]; |
| + // Right-align the "use another service" button. |
| + frame = [button frame]; |
| + frame.origin.x = WebIntentPicker::kWindowWidth - NSWidth(frame) - |
| + 2 * WebIntentPicker::kContentAreaBorder - kCloseButtonSize; |
| + [button setFrame:frame]; |
| + [button setAutoresizingMask:NSViewMinXMargin]; |
| + |
| // And finally, make sure the link and the title are horizontally centered. |
| frame = [button frame]; |
| CGFloat height = std::max(NSHeight(textFrame), NSHeight(frame)); |
| @@ -893,7 +944,17 @@ const CGFloat kAddButtonWidth = 128.0; |
| [inlineDispositionTitleField_ setFrame:textFrame]; |
| } |
| - return NSHeight(textFrame); |
| + offset += NSHeight(textFrame) + kVerticalSpacing; |
| + |
| + scoped_nsobject<NSBox> spacer; |
| + NSRect frame = NSMakeRect(0, offset, WebIntentPicker::kWindowWidth, 1.0); |
| + spacer.reset([[NSBox alloc] initWithFrame:frame]); |
| + [spacer setBoxType:NSBoxSeparator]; |
| + [spacer setBorderColor:[NSColor blackColor]]; |
| + [spacer setAutoresizingMask:NSViewWidthSizable]; |
| + [subviews addObject: spacer]; |
| + |
| + return offset + kVerticalSpacing - originalOffset; |
| } |
| - (NSView*)createEmptyView { |
| @@ -970,7 +1031,6 @@ const CGFloat kAddButtonWidth = 128.0; |
| } else if (contents_) { |
| offset += [self addAnotherServiceLinkToSubviews:subviews |
| atOffset:offset]; |
| - offset += WebIntentPicker::kContentAreaBorder; |
| offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; |
| } else { |
| offset += [self addHeaderToSubviews:subviews atOffset:offset]; |