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

Unified Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 2091053002: Change chrome:// favicons in tabstrip based on theming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: special case for about:crash 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/views/tabs/tab.cc
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc
index ba54c9f8529263a58a8373d7abfd567659e641e9..2075c05d6f611e9fef511f6fa82aec9eeca2476c 100644
--- a/chrome/browser/ui/views/tabs/tab.cc
+++ b/chrome/browser/ui/views/tabs/tab.cc
@@ -25,6 +25,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/user_metrics.h"
+#include "content/public/common/url_constants.h"
#include "grit/components_scaled_resources.h"
#include "grit/components_strings.h"
#include "grit/theme_resources.h"
@@ -169,7 +170,7 @@ class Tab::FaviconCrashAnimation : public gfx::LinearAnimation,
static_cast<int>(floor(kHidingOffset * 2.0 * state)));
} else {
// Animate the crashed icon up.
- target_->set_should_display_crashed_favicon();
+ target_->SetShouldDisplayCrashedFavicon(true);
target_->SetFaviconHidingOffset(
static_cast<int>(
floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset))));
@@ -640,7 +641,7 @@ void Tab::SetData(const TabRendererData& data) {
if (!data_.IsCrashed()) {
crash_icon_animation_->Stop();
- should_display_crashed_favicon_ = false;
+ SetShouldDisplayCrashedFavicon(false);
favicon_hiding_offset_ = 0;
} else if (!should_display_crashed_favicon_ &&
!crash_icon_animation_->is_animating()) {
@@ -1011,6 +1012,7 @@ void Tab::Layout() {
void Tab::OnThemeChanged() {
LoadTabImages();
OnButtonColorMaybeChanged();
+ favicon_ = gfx::ImageSkia();
}
const char* Tab::GetClassName() const {
@@ -1193,6 +1195,11 @@ void Tab::MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds) const {
}
void Tab::DataChanged(const TabRendererData& old) {
+ // Clear the cached themed favicon except in the case of about:crash, which
+ // should go on using the old icon, whatever it was.
+ if (data().url != GURL(content::kChromeUICrashURL))
+ favicon_ = gfx::ImageSkia();
+
if (data().alert_state != old.alert_state || data().title != old.title)
TooltipTextChanged();
@@ -1500,19 +1507,31 @@ void Tab::PaintIcon(gfx::Canvas* canvas) {
if (bounds.IsEmpty())
return;
- if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
- // Throbber will do its own painting.
- } else {
- const gfx::ImageSkia& favicon = should_display_crashed_favicon_ ?
- *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_CRASH_SAD_FAVICON) :
- data().favicon;
- if (!favicon.isNull()) {
- canvas->DrawImageInt(favicon, 0, 0, bounds.width(), bounds.height(),
- bounds.x(), bounds.y(), bounds.width(),
- bounds.height(), false);
+ // Throbber will do its own painting.
+ if (data().network_state != TabRendererData::NETWORK_STATE_NONE)
+ return;
+
+ if (favicon_.isNull()) {
+ favicon_ = should_display_crashed_favicon_
+ ? *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_CRASH_SAD_FAVICON)
+ : data().favicon;
+ // Theme the icon if it's a chrome:// page or if it's the sadtab favicon.
+ if (!favicon_.isNull() &&
+ (should_display_crashed_favicon_ ||
+ (data().url.SchemeIs(content::kChromeUIScheme)))) {
+ color_utils::HSL icon_shift =
+ GetThemeProvider()->GetTint(ThemeProperties::TINT_BUTTONS);
+ favicon_ =
+ gfx::ImageSkiaOperations::CreateHSLShiftedImage(favicon_, icon_shift);
}
}
+
+ if (!favicon_.isNull()) {
+ canvas->DrawImageInt(favicon_, 0, 0, bounds.width(), bounds.height(),
+ bounds.x(), bounds.y(), bounds.width(),
+ bounds.height(), false);
+ }
}
void Tab::AdvanceLoadingAnimation() {
@@ -1627,6 +1646,14 @@ double Tab::GetThrobValue() {
return val;
}
+void Tab::SetShouldDisplayCrashedFavicon(bool value) {
+ if (value == should_display_crashed_favicon_)
+ return;
+
+ should_display_crashed_favicon_ = value;
+ favicon_ = gfx::ImageSkia();
+}
+
void Tab::SetFaviconHidingOffset(int offset) {
favicon_hiding_offset_ = offset;
ScheduleIconPaint();

Powered by Google App Engine
This is Rietveld 408576698