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

Unified Diff: chrome/browser/ui/cocoa/web_intent_sheet_controller.mm

Issue 10917077: [WebIntents, OSX] Clean up inline disposition to match mock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better comments. Created 8 years, 3 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 | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1bc3fe829685219653b8f4d7137d14f989092911 100644
--- a/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm
+++ b/chrome/browser/ui/cocoa/web_intent_sheet_controller.mm
@@ -24,7 +24,9 @@
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
#include "grit/ui_resources.h"
+#include "skia/ext/skia_utils_mac.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"
@@ -35,6 +37,13 @@
using content::OpenURLParams;
using content::Referrer;
+@interface HyperlinkButtonCell (Private)
+- (void)customizeButtonCell;
+@end
+
+@interface CustomLinkButtonCell : HyperlinkButtonCell
+@end
+
namespace {
// The width of a service button, in view coordinates.
@@ -46,9 +55,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 +72,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 +84,28 @@ NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) {
} // namespace
+
+// Provide custom link format for intent picker. Removes underline attribute,
+// since UX direction is "look like WebUI".
+@implementation CustomLinkButtonCell
+- (void)customizeButtonCell {
+ [super customizeButtonCell];
+ SkColor linkColor = SkColorSetARGB(0xff, 0x11, 0x55,0xcc);
+ [self setTextColor:gfx::SkColorToDeviceNSColor(linkColor)];
Nico 2012/09/07 16:50:21 What's wrong with NSColor colorWithDeviceR:g:b:a?
groby-ooo-7-16 2012/09/08 00:29:39 Done.
+}
+
+- (NSDictionary*)linkAttributes {
+ scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
+ [[NSParagraphStyle defaultParagraphStyle] mutableCopy]);
+ [paragraphStyle setAlignment:[self alignment]];
+
+ return @{NSForegroundColorAttributeName: [self textColor],
Nico 2012/09/07 16:50:21 break after @{: return @{ foo: ..., bar
groby-ooo-7-16 2012/09/08 00:29:39 Done.
+ NSFontAttributeName: [self font],
+ NSCursorAttributeName: [NSCursor pointingHandCursor],
+ NSParagraphStyleAttributeName: paragraphStyle.get()};
+}
+@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
@@ -196,6 +224,7 @@ NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) {
spacer_.reset([[NSBox alloc] initWithFrame:frame]);
[spacer_ setBoxType:NSBoxSeparator];
[spacer_ setBorderColor:[NSColor blackColor]];
+ [spacer_ setAlphaValue:0.2];
NSArray* subviews = @[titleField_, subtitleField_, spacer_];
[self setSubviews:subviews];
@@ -637,7 +666,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:
@@ -698,13 +727,6 @@ const CGFloat kAddButtonWidth = 128.0;
// Resize web contents.
[webContentView setFrameSize:inlineContentSize];
-
- // Position close button.
- NSRect buttonFrame = [closeButton_ frame];
- buttonFrame.origin.x = containerSize.width -
- WebIntentPicker::kContentAreaBorder - kCloseButtonSize;
- [closeButton_ setFrame:buttonFrame];
-
[self setContainerSize:containerSize];
}
@@ -795,13 +817,16 @@ const CGFloat kAddButtonWidth = 128.0;
}
- (void)addCloseButtonToSubviews:(NSMutableArray*)subviews {
+ const CGFloat kButtonFuzz = 4.0; // whitespace inside button frame.
Nico 2012/09/07 16:50:21 in css speak this is called "padding", so call it
groby-ooo-7-16 2012/09/08 00:29:39 Done.
if (!closeButton_.get()) {
NSRect buttonFrame = NSMakeRect(
- WebIntentPicker::kContentAreaBorder + kTextWidth,
- WebIntentPicker::kContentAreaBorder,
+ WebIntentPicker::kContentAreaBorder + kTextWidth + kButtonFuzz,
+ WebIntentPicker::kContentAreaBorder - kButtonFuzz,
kCloseButtonSize, kCloseButtonSize);
closeButton_.reset(
[[HoverCloseButton alloc] initWithFrame:buttonFrame]);
+ // Anchor close button to upper right.
+ [closeButton_ setAutoresizingMask:NSViewMaxYMargin|NSViewMinXMargin];
Nico 2012/09/07 16:50:21 y grows too the top, so this anchors to lower righ
groby-ooo-7-16 2012/09/08 00:29:39 It's inside a flipped view. so it's actually ancho
Nico 2012/09/08 00:30:45 Might be worth a comment then. On 2012/09/08 00:2
groby-ooo-7-16 2012/09/08 00:48:38 Done.
[closeButton_ setTarget:self];
[closeButton_ setAction:@selector(cancelOperation:)];
}
@@ -856,9 +881,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 +921,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 +934,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 +952,18 @@ 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 setAlphaValue:0.2];
+ [spacer setAutoresizingMask:NSViewWidthSizable];
+ [subviews addObject: spacer];
+
+ return offset + kVerticalSpacing - originalOffset;
}
- (NSView*)createEmptyView {
@@ -970,7 +1040,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];
@@ -984,16 +1053,17 @@ const CGFloat kAddButtonWidth = 128.0;
}
offset += [self addCwsButtonToSubviews:subviews atOffset:offset];
}
- [self addCloseButtonToSubviews:subviews];
// Add the bottom padding.
offset += WebIntentPicker::kContentAreaBorder;
+ // Resize to fit.
+ [self setContainerSize:NSMakeSize(WebIntentPicker::kWindowWidth, offset)];
+
+ [self addCloseButtonToSubviews:subviews];
+
// Replace the window's content.
[flipView_ setSubviews:subviews];
-
- // And resize to fit.
- [self setContainerSize:NSMakeSize(WebIntentPicker::kWindowWidth, offset)];
}
- (void)setActionString:(NSString*)actionString {
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698