| 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 6d0d78ae342129de7cfe6e2eb8a11b18c20d701b..7ea8247ab2463603761d0cddb93d1a8ab312f069 100644
|
| --- a/chrome/browser/ui/views/tabs/tab.cc
|
| +++ b/chrome/browser/ui/views/tabs/tab.cc
|
| @@ -30,6 +30,8 @@
|
| #include "ui/base/models/list_selection_model.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/base/theme_provider.h"
|
| +#include "ui/compositor/layer_animator.h"
|
| +#include "ui/compositor/paint_recorder.h"
|
| #include "ui/gfx/animation/animation_container.h"
|
| #include "ui/gfx/animation/multi_animation.h"
|
| #include "ui/gfx/animation/throb_animation.h"
|
| @@ -56,6 +58,8 @@
|
| #include "ui/aura/env.h"
|
| #endif
|
|
|
| +#include "base/debug/stack_trace.h"
|
| +
|
| using base::UserMetricsAction;
|
|
|
| namespace {
|
| @@ -392,6 +396,163 @@ Tab::ImageCacheEntry::ImageCacheEntry()
|
| Tab::ImageCacheEntry::~ImageCacheEntry() {}
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| +// ThrobberView
|
| +
|
| +class Tab::ThrobberView : public views::View {
|
| + public:
|
| + ThrobberView(Tab* owner, const gfx::Rect& bounds)
|
| + : owner_(owner),
|
| + waiting_arc_(owner_->GetThemeProvider()->GetColor(
|
| + ThemeProperties::COLOR_THROBBER_WAITING),
|
| + 180) {
|
| + SetPaintToLayer(true);
|
| + SetFillsBoundsOpaquely(false);
|
| + SetBoundsRect(bounds);
|
| + owner_->AddChildView(this);
|
| +
|
| + mask_.SetFillsBoundsOpaquely(false);
|
| + mask_.SetMasksToBounds(true);
|
| + }
|
| +
|
| + void SchedulePaintIfRequired() {
|
| + if (NeedsPaint())
|
| + SchedulePaint();
|
| + }
|
| +
|
| + // views::View:
|
| + void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
|
| + gfx::Rect bounds = GetLocalBounds();
|
| + waiting_arc_.layer()->SetBounds(
|
| + gfx::Rect(0, 0, bounds.width() * Arc::kAA, bounds.height() * Arc::kAA));
|
| +
|
| + bounds.set_width(bounds.width() / 2);
|
| + mask_.SetBounds(bounds);
|
| + }
|
| +
|
| + void OnPaint(gfx::Canvas* canvas) override {
|
| + state_ = owner_->data().network_state;
|
| + if (state_ == TabRendererData::NETWORK_STATE_NONE)
|
| + return;
|
| +
|
| + const gfx::Rect bounds = GetLocalBounds();
|
| +
|
| + // Paint network activity (aka throbber) animation frame.
|
| + ui::ThemeProvider* tp = owner_->GetThemeProvider();
|
| + if (state_ == TabRendererData::NETWORK_STATE_WAITING) {
|
| + // Painted by Arc.
|
| + } else {
|
| + if (loading_start_time_ == base::TimeTicks())
|
| + loading_start_time_ = base::TimeTicks::Now();
|
| +
|
| + waiting_state_.color =
|
| + tp->GetColor(ThemeProperties::COLOR_THROBBER_WAITING);
|
| + gfx::PaintThrobberSpinningAfterWaiting(
|
| + canvas, bounds,
|
| + tp->GetColor(ThemeProperties::COLOR_THROBBER_SPINNING),
|
| + base::TimeTicks::Now() - loading_start_time_, &waiting_state_);
|
| + }
|
| + }
|
| +
|
| + private:
|
| + class Arc : public ui::LayerDelegate {
|
| + public:
|
| + // Since the rotation transform mis-aligns the pixel anti-aliasing done by
|
| + // Skia, perform a kind of FSAA by drawing on a larger canvas and scaling
|
| + // down as part of the transform.
|
| + static const int kAA = 4;
|
| +
|
| + Arc(SkColor color, SkScalar sweep)
|
| + : color_(color), sweep_(sweep), layer_(ui::LAYER_TEXTURED) {
|
| + layer_.set_delegate(this);
|
| + layer_.SetFillsBoundsOpaquely(false);
|
| + }
|
| +
|
| + ui::Layer* layer() { return &layer_; }
|
| +
|
| + void SetAngle(SkScalar angle) {
|
| + const gfx::Size size = layer()->size();
|
| + gfx::Transform transform;
|
| + transform.Translate(size.width() / 2.0 / kAA, size.height() / 2.0 / kAA);
|
| + transform.Rotate(-angle);
|
| + transform.Scale(1.0 / kAA, 1.0 / kAA);
|
| + transform.Translate(-size.width() / 2, -size.height() / 2);
|
| + layer()->SetTransform(transform);
|
| + }
|
| +
|
| + // LayerDelegate:
|
| + void OnPaintLayer(const ui::PaintContext& context) override {
|
| + const gfx::Size size = layer()->size();
|
| + ui::PaintRecorder recorder(context, size);
|
| + gfx::PaintThrobberArc(recorder.canvas(), gfx::Rect(size), color_, -90,
|
| + sweep_);
|
| + }
|
| +
|
| + void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
|
| + void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
|
| + base::Closure PrepareForLayerBoundsChange() override {
|
| + return base::Closure();
|
| + }
|
| +
|
| + private:
|
| + SkColor color_;
|
| + SkScalar sweep_;
|
| + ui::Layer layer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Arc);
|
| + };
|
| +
|
| + void ApplyWaitingRotation(const base::TimeDelta& elapsed_time) {
|
| + const base::TimeDelta revolution_time =
|
| + base::TimeDelta::FromMilliseconds(1320);
|
| + bool needs_mask = elapsed_time < revolution_time / 2;
|
| + mask_.SetMasksToBounds(needs_mask);
|
| + waiting_arc_.SetAngle(360 * waiting_state_.elapsed_time / revolution_time);
|
| + }
|
| +
|
| + bool NeedsPaint() {
|
| + if (bounds().IsEmpty())
|
| + return false;
|
| +
|
| + TabRendererData::NetworkState new_state = owner_->data().network_state;
|
| + const bool changing_state = new_state != state_;
|
| +
|
| + // Waiting throbber is fully layer-backed.
|
| + if (new_state == TabRendererData::NETWORK_STATE_WAITING) {
|
| + if (waiting_start_time_ == base::TimeTicks())
|
| + waiting_start_time_ = base::TimeTicks::Now();
|
| +
|
| + state_ = new_state;
|
| + waiting_state_.elapsed_time =
|
| + base::TimeTicks::Now() - waiting_start_time_;
|
| + layer()->Add(&mask_);
|
| + mask_.Add(waiting_arc_.layer());
|
| + ApplyWaitingRotation(waiting_state_.elapsed_time);
|
| + return changing_state;
|
| + }
|
| +
|
| + return true;
|
| + }
|
| +
|
| + Tab* owner_; // Weak. Owns this.
|
| +
|
| + TabRendererData::NetworkState state_ = TabRendererData::NETWORK_STATE_NONE;
|
| +
|
| + // The point in time when the tab icon was first painted in the waiting state.
|
| + base::TimeTicks waiting_start_time_;
|
| +
|
| + // The point in time when the tab icon was first painted in the loading state.
|
| + base::TimeTicks loading_start_time_;
|
| +
|
| + // Paint state for the throbber after the most recent waiting paint.
|
| + gfx::ThrobberWaitingState waiting_state_;
|
| +
|
| + ui::Layer mask_;
|
| + Arc waiting_arc_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ThrobberView);
|
| +};
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| // Tab, statics:
|
|
|
| // static
|
| @@ -412,6 +573,7 @@ Tab::Tab(TabController* controller)
|
| favicon_hiding_offset_(0),
|
| immersive_loading_step_(0),
|
| should_display_crashed_favicon_(false),
|
| + throbber_(nullptr),
|
| media_indicator_button_(nullptr),
|
| close_button_(nullptr),
|
| title_(new views::Label()),
|
| @@ -552,9 +714,8 @@ void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) {
|
| return;
|
| }
|
|
|
| - TabRendererData::NetworkState old_state = data_.network_state;
|
| data_.network_state = state;
|
| - AdvanceLoadingAnimation(old_state, state);
|
| + AdvanceLoadingAnimation(state);
|
| }
|
|
|
| void Tab::StartPulse() {
|
| @@ -787,6 +948,8 @@ void Tab::Layout() {
|
| favicon_bounds_.set_y(lb.y() + (lb.height() - gfx::kFaviconSize + 1) / 2);
|
| MaybeAdjustLeftForPinnedTab(&favicon_bounds_);
|
| }
|
| + if (throbber_)
|
| + throbber_->SetBoundsRect(favicon_bounds_);
|
|
|
| showing_close_button_ = ShouldShowCloseBox();
|
| if (showing_close_button_) {
|
| @@ -1347,28 +1510,7 @@ void Tab::PaintIcon(gfx::Canvas* canvas) {
|
| bounds.set_x(GetMirroredXForRect(bounds));
|
|
|
| if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
|
| - // Paint network activity (aka throbber) animation frame.
|
| - ui::ThemeProvider* tp = GetThemeProvider();
|
| - if (data().network_state == TabRendererData::NETWORK_STATE_WAITING) {
|
| - if (waiting_start_time_ == base::TimeTicks())
|
| - waiting_start_time_ = base::TimeTicks::Now();
|
| -
|
| - waiting_state_.elapsed_time =
|
| - base::TimeTicks::Now() - waiting_start_time_;
|
| - gfx::PaintThrobberWaiting(
|
| - canvas, bounds, tp->GetColor(ThemeProperties::COLOR_THROBBER_WAITING),
|
| - waiting_state_.elapsed_time);
|
| - } else {
|
| - if (loading_start_time_ == base::TimeTicks())
|
| - loading_start_time_ = base::TimeTicks::Now();
|
| -
|
| - waiting_state_.color =
|
| - tp->GetColor(ThemeProperties::COLOR_THROBBER_WAITING);
|
| - gfx::PaintThrobberSpinningAfterWaiting(
|
| - canvas, bounds,
|
| - tp->GetColor(ThemeProperties::COLOR_THROBBER_SPINNING),
|
| - base::TimeTicks::Now() - loading_start_time_, &waiting_state_);
|
| - }
|
| + // Throbber will do its own painting.
|
| } else if (should_display_crashed_favicon_) {
|
| // Paint crash favicon.
|
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| @@ -1387,8 +1529,7 @@ void Tab::PaintIcon(gfx::Canvas* canvas) {
|
| }
|
| }
|
|
|
| -void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
|
| - TabRendererData::NetworkState state) {
|
| +void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState state) {
|
| if (state == TabRendererData::NETWORK_STATE_WAITING) {
|
| // Waiting steps backwards.
|
| immersive_loading_step_ =
|
| @@ -1398,16 +1539,25 @@ void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
|
| immersive_loading_step_ = (immersive_loading_step_ + 1) %
|
| kImmersiveLoadingStepCount;
|
| } else {
|
| - waiting_start_time_ = base::TimeTicks();
|
| - loading_start_time_ = base::TimeTicks();
|
| - waiting_state_ = gfx::ThrobberWaitingState();
|
| immersive_loading_step_ = 0;
|
| }
|
| +
|
| if (controller_->IsImmersiveStyle()) {
|
| SchedulePaintInRect(GetImmersiveBarRect());
|
| - } else {
|
| + return;
|
| + }
|
| +
|
| + const bool needs_throbber = state != TabRendererData::NETWORK_STATE_NONE;
|
| + if (needs_throbber && !throbber_) {
|
| + throbber_ = new ThrobberView(this, favicon_bounds_);
|
| + ScheduleIconPaint(); // Repaint the icon area to not show the icon.
|
| + } else if (!needs_throbber) {
|
| + delete throbber_;
|
| + throbber_ = nullptr;
|
| ScheduleIconPaint();
|
| }
|
| + if (throbber_)
|
| + throbber_->SchedulePaintIfRequired();
|
| }
|
|
|
| int Tab::IconCapacity() const {
|
|
|