Chromium Code Reviews| 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 4b854bcfbe4b1bf089ab06e6bbaf58f9954d4cd4..725305d20069ab74d2b89a93502392f51871f6a5 100644 |
| --- a/chrome/browser/ui/views/tabs/tab.cc |
| +++ b/chrome/browser/ui/views/tabs/tab.cc |
| @@ -31,6 +31,7 @@ |
| #include "grit/components_strings.h" |
| #include "grit/theme_resources.h" |
| #include "third_party/skia/include/effects/SkGradientShader.h" |
| +#include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| #include "third_party/skia/include/pathops/SkPathOps.h" |
| #include "ui/accessibility/ax_view_state.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -578,6 +579,28 @@ void PaintTabBackgroundUsingParams(gfx::Canvas* fill_canvas, |
| } |
| } |
| +// Destaurates the favicon. Should only be used for when a tab encounters a |
| +// network error state. |
| +void PaintDesaturatedFavIcon(gfx::Canvas* canvas, |
| + gfx::ImageSkia& favicon, |
| + gfx::Rect bounds) { |
|
sky
2016/08/12 15:29:25
const gfx::Rect&
edwardjung
2016/08/12 19:29:25
Done.
|
| + SkPaint paint; |
| + paint.setStyle(SkPaint::kFill_Style); |
| + paint.setAntiAlias(true); |
| + SkScalar desaturate[20] = {0.3086f, 0.6094f, 0.0820f, 0.0f, 0.0f, |
|
sky
2016/08/12 15:29:25
These constants look rather magical. Are they defi
edwardjung
2016/08/12 19:29:25
I've switched to use CreateHSLShiftedImage which h
|
| + 0.3086f, 0.6094f, 0.0820f, 0.0f, 0.0f, |
| + 0.3086f, 0.6094f, 0.0820f, 0.0f, 0.0f, |
| + 0.0f, 0.0f, 0.0f, 0.8f, 0.0f}; |
| + paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(desaturate)); |
| + if (!bounds.IsEmpty()) { |
| + canvas->DrawImageInt(favicon, 0, 0, bounds.width(), bounds.height(), |
| + bounds.x(), bounds.y(), bounds.width(), |
| + bounds.height(), false, paint); |
| + } else { |
| + canvas->DrawImageInt(favicon, 0, 0, paint); |
| + } |
| +} |
| + |
| } // namespace |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -759,7 +782,8 @@ bool Tab::ThrobberView::CanProcessEventsWithinSubtree() const { |
| void Tab::ThrobberView::OnPaint(gfx::Canvas* canvas) { |
| const TabRendererData::NetworkState state = owner_->data().network_state; |
| - if (state == TabRendererData::NETWORK_STATE_NONE) |
| + if (state == TabRendererData::NETWORK_STATE_NONE || |
| + state == TabRendererData::NETWORK_STATE_ERROR) |
| return; |
| const ui::ThemeProvider* tp = GetThemeProvider(); |
| @@ -897,7 +921,6 @@ bool Tab::IsSelected() const { |
| void Tab::SetData(const TabRendererData& data) { |
| DCHECK(GetWidget()); |
| - |
| if (data_.Equals(data)) |
| return; |
| @@ -939,7 +962,8 @@ void Tab::SetData(const TabRendererData& data) { |
| void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { |
| if (state == data_.network_state && |
| - state == TabRendererData::NETWORK_STATE_NONE) { |
| + (state == TabRendererData::NETWORK_STATE_NONE || |
| + state == TabRendererData::NETWORK_STATE_ERROR)) { |
| // If the network state is none and hasn't changed, do nothing. Otherwise we |
|
sky
2016/08/12 15:29:25
update comment
edwardjung
2016/08/12 19:29:25
Done.
|
| // need to advance the animation frame. |
| return; |
| @@ -1594,7 +1618,12 @@ void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( |
| const float kIndicatorCropRadius = 4.5; |
| gfx::Canvas icon_canvas(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
| canvas->image_scale(), false); |
| - icon_canvas.DrawImageInt(favicon_, 0, 0); |
| + |
| + if (data().network_state == TabRendererData::NETWORK_STATE_ERROR) |
| + PaintDesaturatedFavIcon(&icon_canvas, favicon_, gfx::Rect()); |
| + else |
| + icon_canvas.DrawImageInt(favicon_, 0, 0); |
| + |
| SkPaint clear_paint; |
| clear_paint.setAntiAlias(true); |
| clear_paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| @@ -1631,7 +1660,8 @@ void Tab::PaintIcon(gfx::Canvas* canvas) { |
| return; |
| // Throbber will do its own painting. |
| - if (data().network_state != TabRendererData::NETWORK_STATE_NONE) |
| + if (data().network_state != TabRendererData::NETWORK_STATE_NONE && |
| + data().network_state != TabRendererData::NETWORK_STATE_ERROR) |
| return; |
| // Ensure that |favicon_| is created. |
| @@ -1657,9 +1687,14 @@ void Tab::PaintIcon(gfx::Canvas* canvas) { |
| !should_display_crashed_favicon_) { |
| PaintPinnedTabTitleChangedIndicatorAndIcon(canvas, bounds); |
| } else if (!favicon_.isNull()) { |
| - canvas->DrawImageInt(favicon_, 0, 0, bounds.width(), bounds.height(), |
| - bounds.x(), bounds.y(), bounds.width(), |
| - bounds.height(), false); |
| + // Desaturate favicons of tabs with network errors. |
| + if (data().network_state == TabRendererData::NETWORK_STATE_ERROR) { |
| + PaintDesaturatedFavIcon(canvas, favicon_, bounds); |
| + } else { |
| + canvas->DrawImageInt(favicon_, 0, 0, bounds.width(), bounds.height(), |
| + bounds.x(), bounds.y(), bounds.width(), |
| + bounds.height(), false); |
| + } |
| } |
| } |
| @@ -1683,7 +1718,8 @@ void Tab::AdvanceLoadingAnimation() { |
| return; |
| } |
| - if (state == TabRendererData::NETWORK_STATE_NONE) { |
| + if (state == TabRendererData::NETWORK_STATE_NONE || |
| + state == TabRendererData::NETWORK_STATE_ERROR) { |
| throbber_->ResetStartTimes(); |
| throbber_->SetVisible(false); |
| ScheduleIconPaint(); |