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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" 5 #include "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/mac_util.h"
9 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
10 #include "components/favicon/content/content_favicon_driver.h" 11 #include "components/favicon/content/content_favicon_driver.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h"
11 #include "skia/ext/skia_utils_mac.h" 14 #include "skia/ext/skia_utils_mac.h"
12 #include "ui/base/material_design/material_design_controller.h" 15 #include "ui/base/material_design/material_design_controller.h"
13 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image_skia_operations.h"
14 #include "ui/gfx/image/image_skia_util_mac.h" 18 #include "ui/gfx/image/image_skia_util_mac.h"
15 #include "ui/gfx/paint_vector_icon.h" 19 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/gfx/vector_icons_public.h" 20 #include "ui/gfx/vector_icons_public.h"
17 #include "ui/resources/grit/ui_resources.h" 21 #include "ui/resources/grit/ui_resources.h"
18 22
19 namespace { 23 namespace {
20 24
21 const CGFloat kVectorIconSize = 16; 25 const CGFloat kVectorIconSize = 16;
22 26
27 // Desaturate favicon HSL shift values.
28 const double kDesaturateHue = -1.0;
29 const double kDesaturateSaturation = 0.0;
30 const double kDesaturateLightness = 0.6;
31
23 } // namespace 32 } // namespace
24 33
25 namespace mac { 34 namespace mac {
26 35
27 NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) { 36 NSImage* FaviconForWebContents(content::WebContents* contents, SkColor color) {
28 favicon::FaviconDriver* favicon_driver = 37 favicon::FaviconDriver* favicon_driver =
29 contents ? favicon::ContentFaviconDriver::FromWebContents(contents) 38 contents ? favicon::ContentFaviconDriver::FromWebContents(contents)
30 : nullptr; 39 : nullptr;
31 if (favicon_driver && favicon_driver->FaviconIsValid()) { 40 if (favicon_driver && favicon_driver->FaviconIsValid()) {
32 NSImage* image = favicon_driver->GetFavicon().AsNSImage(); 41 gfx::Image favicon = favicon_driver->GetFavicon();
42 NSImage* image = nil;
43
44 // Check if there's a network error. If there is, desaturate the favicon.
45 content::NavigationEntry* entry =
46 contents->GetController().GetLastCommittedEntry();
47 if (entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR)) {
48 const gfx::ImageSkia* image_skia = favicon.ToImageSkia();
49 if (image_skia) {
50 color_utils::HSL shift = {kDesaturateHue, kDesaturateSaturation,
51 kDesaturateLightness};
52 gfx::ImageSkia desaturated_favicon =
53 gfx::ImageSkiaOperations::CreateHSLShiftedImage(*image_skia, shift);
Nico 2016/09/08 20:54:12 it feels like this should be code that's shared be
54 image = gfx::NSImageFromImageSkiaWithColorSpace(
55 desaturated_favicon, base::mac::GetSRGBColorSpace());
56 }
57 } else {
58 image = favicon.ToNSImage();
59 }
60
33 // The |image| could be nil if the bitmap is null. In that case, fallback 61 // The |image| could be nil if the bitmap is null. In that case, fallback
34 // to the default image. 62 // to the default image.
35 if (image) { 63 if (image)
36 return image; 64 return image;
37 }
38 } 65 }
39 66
40 if (ui::MaterialDesignController::IsModeMaterial()) { 67 if (ui::MaterialDesignController::IsModeMaterial()) {
41 return NSImageFromImageSkia(gfx::CreateVectorIcon( 68 return NSImageFromImageSkia(gfx::CreateVectorIcon(
42 gfx::VectorIconId::DEFAULT_FAVICON, kVectorIconSize, color)); 69 gfx::VectorIconId::DEFAULT_FAVICON, kVectorIconSize, color));
43 } 70 }
44 71
45 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 72 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
46 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); 73 return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage();
47 } 74 }
48 75
49 } // namespace mac 76 } // namespace mac
OLDNEW
« 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