Commit ee1e612a authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: makes favicons prefer larger and square images

This matches other parts of the code.

BUG=1076463
TEST=none

Change-Id: I995b0f3449d5a4e4c20fb504a723681e9c8c14d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354792
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797951}
parent 25052a8f
...@@ -13,6 +13,28 @@ ...@@ -13,6 +13,28 @@
#include "weblayer/public/favicon_fetcher_delegate.h" #include "weblayer/public/favicon_fetcher_delegate.h"
namespace weblayer { namespace weblayer {
namespace {
bool IsSquareImage(const gfx::Image& image) {
return !image.IsEmpty() && image.Width() == image.Height();
}
// Returns true if |image_a| is better than |image_b|. A value of false means
// |image_a| is not better than |image_b|. Either image may be empty, if both
// are empty false is returned.
bool IsImageBetterThan(const gfx::Image& image_a, const gfx::Image& image_b) {
// Any image is better than an empty image.
if (!image_a.IsEmpty() && image_b.IsEmpty())
return true;
// Prefer square favicons as they will scale much better.
if (IsSquareImage(image_a) && !IsSquareImage(image_b))
return true;
return image_a.Width() > image_b.Width();
}
} // namespace
FaviconTabHelper::ObserverSubscription::ObserverSubscription( FaviconTabHelper::ObserverSubscription::ObserverSubscription(
FaviconTabHelper* helper, FaviconTabHelper* helper,
...@@ -78,6 +100,9 @@ void FaviconTabHelper::OnFaviconUpdated( ...@@ -78,6 +100,9 @@ void FaviconTabHelper::OnFaviconUpdated(
const GURL& icon_url, const GURL& icon_url,
bool icon_url_changed, bool icon_url_changed,
const gfx::Image& image) { const gfx::Image& image) {
if (!IsImageBetterThan(image, favicon_))
return;
favicon_ = image; favicon_ = image;
for (FaviconFetcherDelegate& delegate : delegates_) for (FaviconFetcherDelegate& delegate : delegates_)
delegate.OnFaviconChanged(favicon_); delegate.OnFaviconChanged(favicon_);
......
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