Commit 63d02712 authored by spqchan's avatar spqchan Committed by Commit bot

[Material][Mac] Replace hard-coded default favicon with .icon file

BUG=619627

Review-Url: https://codereview.chromium.org/2299423002
Cr-Commit-Position: refs/heads/master@{#416385}
parent 23115497
......@@ -11,6 +11,9 @@
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/resources/grit/ui_resources.h"
namespace {
......@@ -19,75 +22,6 @@ const CGFloat kVectorIconSize = 16;
} // namespace
// A temporary class that draws the default favicon using vector commands.
// This class will be removed once a more general solution that works for all
// platforms is developed.
@interface DefaultFaviconImageRep : NSCustomImageRep
@property(retain, nonatomic) NSColor* strokeColor;
+ (NSImage*)imageForColor:(SkColor)strokeColor;
// NSCustomImageRep delegate method that performs the drawing.
+ (void)drawDefaultFavicon:(DefaultFaviconImageRep*)imageRep;
@end
@implementation DefaultFaviconImageRep
@synthesize strokeColor = strokeColor_;
- (void)dealloc {
[strokeColor_ release];
[super dealloc];
}
+ (NSImage*)imageForColor:(SkColor)strokeColor {
base::scoped_nsobject<DefaultFaviconImageRep> imageRep(
[[DefaultFaviconImageRep alloc]
initWithDrawSelector:@selector(drawDefaultFavicon:)
delegate:[DefaultFaviconImageRep class]]);
[imageRep setStrokeColor:skia::SkColorToSRGBNSColor(strokeColor)];
// Create the image from the image rep.
const NSSize imageSize = NSMakeSize(kVectorIconSize, kVectorIconSize);
NSImage* faviconImage =
[[[NSImage alloc] initWithSize:imageSize] autorelease];
[faviconImage setCacheMode:NSImageCacheAlways];
[faviconImage addRepresentation:imageRep];
[imageRep setSize:imageSize];
return faviconImage;
}
+ (void)drawDefaultFavicon:(DefaultFaviconImageRep*)imageRep {
// Translate by 1/2pt to ensure crisp lines.
CGContextRef context = static_cast<CGContextRef>(
[[NSGraphicsContext currentContext] graphicsPort]);
CGContextTranslateCTM(context, 0.5, 0.5);
NSBezierPath* iconPath = [NSBezierPath bezierPath];
// Create the horizontal and vertical parts of the shape.
[iconPath moveToPoint:NSMakePoint(3, 1)];
[iconPath relativeLineToPoint:NSMakePoint(0, 13)];
[iconPath relativeLineToPoint:NSMakePoint(5, 0)];
[iconPath relativeLineToPoint:NSMakePoint(0, -4)];
[iconPath relativeLineToPoint:NSMakePoint(4, 0)];
[iconPath relativeLineToPoint:NSMakePoint(0, -9)];
[iconPath closePath];
// Add the diagonal line.
[iconPath moveToPoint:NSMakePoint(8, 14)];
[iconPath relativeLineToPoint:NSMakePoint(4, -4)];
// Draw it in the desired color.
[[imageRep strokeColor] set];
[iconPath stroke];
}
@end
namespace mac {
NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) {
......@@ -103,8 +37,10 @@ NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) {
}
}
if (ui::MaterialDesignController::IsModeMaterial())
return [DefaultFaviconImageRep imageForColor:color];
if (ui::MaterialDesignController::IsModeMaterial()) {
return NSImageFromImageSkia(gfx::CreateVectorIcon(
gfx::VectorIconId::DEFAULT_FAVICON, kVectorIconSize, color));
}
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage();
......
......@@ -33,6 +33,7 @@ action("aggregate_vector_icons") {
"crashed_tab.icon",
"credit_card.1x.icon",
"credit_card.icon",
"default_favicon.icon",
"eol.icon",
"error_circle.icon",
"extension.icon",
......
CANVAS_DIMENSIONS, 32,
MOVE_TO, 18, 2,
H_LINE_TO, 6,
R_V_LINE_TO, 28,
R_H_LINE_TO, 20,
V_LINE_TO, 10,
R_LINE_TO, -8, -8,
CLOSE,
R_MOVE_TO, 5, 8,
R_H_LINE_TO, -5,
V_LINE_TO, 5,
R_LINE_TO, 5, 5,
CLOSE,
R_MOVE_TO, 1, 18,
H_LINE_TO, 8,
V_LINE_TO, 4,
R_H_LINE_TO, 8,
R_V_LINE_TO, 8,
R_H_LINE_TO, 8,
R_V_LINE_TO, 16,
CLOSE,
END
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment