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

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

Issue 2299423002: [Material][Mac] Replace hard-coded default favicon with .icon file (Closed)
Patch Set: Vector icon file Created 4 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 | « no previous file | ui/gfx/vector_icons/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 16074c23d05d43fc0fd3bf3c62ba3ddc23ebac61..348cf20030e259e4998c894867f326f02ab4ebf3 100644
--- a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
@@ -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();
« no previous file with comments | « no previous file | ui/gfx/vector_icons/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698