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

Unified Diff: chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm

Issue 2072833002: [Material][Mac] Replace the default favicon with a vector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
Index: chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
diff --git a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
index d713b62fd46191f2e3d0c7bc57e5c126564abfa9..16074c23d05d43fc0fd3bf3c62ba3ddc23ebac61 100644
--- a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
@@ -4,13 +4,93 @@
#include "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h"
+#import <Cocoa/Cocoa.h>
+
+#include "base/mac/scoped_nsobject.h"
#include "components/favicon/content/content_favicon_driver.h"
+#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/resources/grit/ui_resources.h"
+namespace {
+
+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) {
+NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) {
favicon::FaviconDriver* favicon_driver =
contents ? favicon::ContentFaviconDriver::FromWebContents(contents)
: nullptr;
@@ -23,6 +103,9 @@ NSImage* FaviconForWebContents(content::WebContents* contents) {
}
}
+ if (ui::MaterialDesignController::IsModeMaterial())
+ return [DefaultFaviconImageRep imageForColor:color];
+
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage();
}
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698