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

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

Issue 2321833002: [Mac] Desaturate the Favicon for Network Errors (Closed)
Patch Set: nit 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 | no next file » | 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 348cf20030e259e4998c894867f326f02ab4ebf3..6270f63d954f7d0a5f9272021f6b0cb12caa9730 100644
--- a/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm
@@ -6,11 +6,15 @@
#import <Cocoa/Cocoa.h>
+#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "components/favicon/content/content_favicon_driver.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.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/gfx/image/image_skia_operations.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
@@ -20,6 +24,11 @@ namespace {
const CGFloat kVectorIconSize = 16;
+// Desaturate favicon HSL shift values.
+const double kDesaturateHue = -1.0;
+const double kDesaturateSaturation = 0.0;
+const double kDesaturateLightness = 0.6;
+
} // namespace
namespace mac {
@@ -29,12 +38,30 @@ NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) {
contents ? favicon::ContentFaviconDriver::FromWebContents(contents)
: nullptr;
if (favicon_driver && favicon_driver->FaviconIsValid()) {
- NSImage* image = favicon_driver->GetFavicon().AsNSImage();
+ gfx::Image favicon = favicon_driver->GetFavicon();
+ NSImage* image = nil;
+
+ // Check if there's a network error. If there is, desaturate the favicon.
+ content::NavigationEntry* entry =
+ contents->GetController().GetLastCommittedEntry();
+ if (entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR)) {
+ const gfx::ImageSkia* image_skia = favicon.ToImageSkia();
+ if (image_skia) {
+ color_utils::HSL shift = {kDesaturateHue, kDesaturateSaturation,
+ kDesaturateLightness};
+ gfx::ImageSkia desaturated_favicon =
+ gfx::ImageSkiaOperations::CreateHSLShiftedImage(*image_skia, shift);
Nico 2016/09/08 20:54:12 it feels like this should be code that's shared be
+ image = gfx::NSImageFromImageSkiaWithColorSpace(
+ desaturated_favicon, base::mac::GetSRGBColorSpace());
+ }
+ } else {
+ image = favicon.ToNSImage();
+ }
+
// The |image| could be nil if the bitmap is null. In that case, fallback
// to the default image.
- if (image) {
+ if (image)
return image;
- }
}
if (ui::MaterialDesignController::IsModeMaterial()) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698