| Index: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
|
| diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
|
| index f4ea29a5901ee79692407df978956765e1eaae17..b174404f0e70daf2611b85b8c3f61c539e9aace9 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
|
| @@ -86,7 +86,6 @@ namespace {
|
| const static int kFirstRunBubbleYOffset = 1;
|
|
|
| const int kDefaultIconSize = 16;
|
| -const int kMaterialIconSize = 18;
|
|
|
| // Color of the vector graphic icons when the location bar is dark.
|
| // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF);
|
| @@ -94,6 +93,158 @@ const SkColor kMaterialDarkVectorIconColor = 0xCCFFFFFF;
|
|
|
| } // namespace
|
|
|
| +// A temporary class that draws hardcoded HTTP graphic icons for Material
|
| +// design. This class will be removed once the Material icons are available
|
| +// in M53.
|
| +@interface LocationBarImageRep : NSCustomImageRep
|
| +@property(assign, nonatomic) gfx::VectorIconId iconId;
|
| +@property(retain, nonatomic) NSColor* fillColor;
|
| +
|
| ++ (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
|
| + color:(SkColor)vectorIconColor;
|
| +
|
| +// NSCustomImageRep delegate method that performs the drawing.
|
| ++ (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep;
|
| +
|
| +@end
|
| +
|
| +@implementation LocationBarImageRep
|
| +
|
| +@synthesize iconId = iconId_;
|
| +@synthesize fillColor = fillColor_;
|
| +
|
| +- (void)dealloc {
|
| + [fillColor_ release];
|
| + [super dealloc];
|
| +}
|
| +
|
| ++ (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
|
| + color:(SkColor)vectorIconColor {
|
| + if (vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTP &&
|
| + vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID &&
|
| + vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID) {
|
| + return NSImageFromImageSkiaWithColorSpace(
|
| + gfx::CreateVectorIcon(vectorIconId, kDefaultIconSize, vectorIconColor),
|
| + base::mac::GetSRGBColorSpace());
|
| + }
|
| +
|
| + base::scoped_nsobject<LocationBarImageRep> imageRep =
|
| + [[LocationBarImageRep alloc]
|
| + initWithDrawSelector:@selector(drawLocationBarIcon:)
|
| + delegate:[LocationBarImageRep class]];
|
| + [imageRep setIconId:vectorIconId];
|
| + [imageRep setFillColor:skia::SkColorToSRGBNSColor(vectorIconColor)];
|
| +
|
| + // Create the image from the image rep.
|
| + const NSSize kImageSize = NSMakeSize(kDefaultIconSize, kDefaultIconSize);
|
| + NSImage* locationBarImage =
|
| + [[[NSImage alloc] initWithSize:kImageSize] autorelease];
|
| + [locationBarImage setCacheMode:NSImageCacheAlways];
|
| + [locationBarImage addRepresentation:imageRep];
|
| +
|
| + return locationBarImage;
|
| +}
|
| +
|
| ++ (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep {
|
| + [[imageRep fillColor] set];
|
| +
|
| + // Determine the scale factor.
|
| + CGContextRef context = static_cast<CGContextRef>(
|
| + [[NSGraphicsContext currentContext] graphicsPort]);
|
| + CGRect unitRect = CGRectMake(0.0, 0.0, 1.0, 1.0);
|
| + CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect);
|
| + int scaleFactor = deviceRect.size.height;
|
| +
|
| + switch ([imageRep iconId]) {
|
| + case gfx::VectorIconId::LOCATION_BAR_HTTP:
|
| + [self drawLocationBarIconHTTPForScale:scaleFactor];
|
| + break;
|
| + case gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID:
|
| + [self drawLocationBarIconHTTPSInvalidForScale:scaleFactor];
|
| + break;
|
| + case gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID:
|
| + [self drawLocationBarIconHTTPSValidForScale:scaleFactor];
|
| + break;
|
| + default:
|
| + // Make it obvious that there's a problem.
|
| + [[NSColor redColor] set];
|
| + NSRectFill(NSMakeRect(0, 0, kDefaultIconSize, kDefaultIconSize));
|
| + break;
|
| + }
|
| +}
|
| +
|
| ++ (void)drawLocationBarIconHTTPForScale:(int)scaleFactor {
|
| + NSBezierPath* circlePath =
|
| + [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(2, 2, 12, 12)];
|
| + [circlePath setLineWidth:1.5];
|
| + [circlePath stroke];
|
| +
|
| + NSRectFill(NSMakeRect(7, 4, 2, 5));
|
| + NSRectFill(NSMakeRect(7, 10, 2, 2));
|
| +}
|
| +
|
| ++ (void)drawLocationBarIconHTTPSInvalidForScale:(int)scaleFactor {
|
| + // The vector icon is upside down relative to the default OS X coordinate
|
| + // system so rotate by 180 degrees.
|
| + CGContextRef context = static_cast<CGContextRef>(
|
| + [[NSGraphicsContext currentContext] graphicsPort]);
|
| + const int kHalfDefaultIconSize = kDefaultIconSize / 2;
|
| + CGContextTranslateCTM(context, kHalfDefaultIconSize, kHalfDefaultIconSize);
|
| + CGContextRotateCTM(context, M_PI);
|
| + CGContextTranslateCTM(context, -kHalfDefaultIconSize, -kHalfDefaultIconSize);
|
| +
|
| + // If Retina, nudge the icon up 1/2pt.
|
| + if (scaleFactor == 2) {
|
| + CGContextTranslateCTM(context, 0, -0.5);
|
| + }
|
| +
|
| + NSBezierPath* trianglePath = [NSBezierPath bezierPath];
|
| + [trianglePath moveToPoint:NSMakePoint(0.5f, 14)];
|
| + [trianglePath relativeLineToPoint:NSMakePoint(15, 0)];
|
| + [trianglePath lineToPoint:NSMakePoint(8, 1)];
|
| + [trianglePath closePath];
|
| +
|
| + NSBezierPath* cutOutPath = [NSBezierPath bezierPath];
|
| + [cutOutPath moveToPoint:NSMakePoint(9, 12)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(0, -2)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(0, 2)];
|
| + [cutOutPath closePath];
|
| + [cutOutPath relativeMoveToPoint:NSMakePoint(0, -3)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(0, -3)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
|
| + [cutOutPath relativeLineToPoint:NSMakePoint(0, 3)];
|
| + [cutOutPath closePath];
|
| +
|
| + [trianglePath appendBezierPath:cutOutPath];
|
| + [trianglePath fill];
|
| +}
|
| +
|
| ++ (void)drawLocationBarIconHTTPSValidForScale:(int)scaleFactor {
|
| + NSBezierPath* rectPath =
|
| + [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(4, 3, 8, 7)
|
| + xRadius:1
|
| + yRadius:1];
|
| + [rectPath fill];
|
| +
|
| + NSBezierPath* curvePath = [NSBezierPath bezierPath];
|
| + [curvePath moveToPoint:NSMakePoint(5.5, 9.75)];
|
| + [curvePath lineToPoint:NSMakePoint(5.5, 10)];
|
| + [curvePath curveToPoint:NSMakePoint(8, 13)
|
| + controlPoint1:NSMakePoint(5.5, 13)
|
| + controlPoint2:NSMakePoint(7.5, 13)];
|
| + [curvePath curveToPoint:NSMakePoint(10.5, 10)
|
| + controlPoint1:NSMakePoint(8.5, 13)
|
| + controlPoint2:NSMakePoint(10.5, 13)];
|
| + [curvePath lineToPoint:NSMakePoint(10.5, 9.75)];
|
| + [curvePath setLineWidth:1.25];
|
| + [curvePath stroke];
|
| +}
|
| +
|
| +@end
|
| +
|
| // TODO(shess): This code is mostly copied from the gtk
|
| // implementation. Make sure it's all appropriate and flesh it out.
|
|
|
| @@ -569,13 +720,11 @@ void LocationBarViewMac::UpdateLocationIcon() {
|
|
|
| SkColor vector_icon_color = gfx::kPlaceholderColor;
|
| gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE;
|
| - int icon_size = kDefaultIconSize;
|
| if (ShouldShowEVBubble()) {
|
| - vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP;
|
| + vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID;
|
| vector_icon_color = in_dark_mode
|
| ? LocationBarDecoration::kMaterialDarkModeTextColor
|
| : gfx::kGoogleGreen700;
|
| - icon_size = kMaterialIconSize;
|
| } else {
|
| vector_icon_id = omnibox_view_->GetVectorIcon();
|
| if (in_dark_mode) {
|
| @@ -596,9 +745,8 @@ void LocationBarViewMac::UpdateLocationIcon() {
|
| }
|
|
|
| DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
|
| - NSImage* image = NSImageFromImageSkiaWithColorSpace(
|
| - gfx::CreateVectorIcon(vector_icon_id, icon_size, vector_icon_color),
|
| - base::mac::GetSRGBColorSpace());
|
| + NSImage* image =
|
| + [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color];
|
|
|
| location_icon_decoration_->SetImage(image);
|
| ev_bubble_decoration_->SetImage(image);
|
|
|