Commit 910efca5 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Refactor the tab-loading animation

This change instead updates the animation progress in delta-time
increments, which prevents a bunch of clock math and rewinding of start
timestamps.

Bug: None
Change-Id: I6848e3c3ca2d7c844f56f126d72c9b8420364b2a
Reviewed-on: https://chromium-review.googlesource.com/c/1356261
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613161}
parent 7e4b519f
This diff is collapsed.
......@@ -69,10 +69,15 @@ class TabIcon : public views::View {
// last-painted state to know to redraw the final frame as the animation
// finishes.
struct LoadingAnimationState {
LoadingAnimationState();
base::TimeDelta elapsed_time;
double loading_progress;
SkAlpha loading_progress_alpha;
double favicon_fade_in_progress;
base::Optional<double> loading_progress;
base::Optional<double> loading_progress_fade_out;
// TODO(pbos): Make this a type that can represent "not started" and "ended"
// separately. Right now the value 1.0 is used to indicate that the
// animation has ended (and we're not waiting for it to start).
base::Optional<double> favicon_fade_in_progress = 1.0;
};
// views::View:
......@@ -94,10 +99,7 @@ class TabIcon : public views::View {
// current tab state.
void PaintLoadingAnimation(gfx::Canvas* canvas, const gfx::Rect& bounds);
void UpdateLoadingAnimationState();
LoadingAnimationState GetLoadingAnimationState() const;
void RewindLoadingProgressTimerIfNecessary(double progress);
void UpdatePendingAnimationState();
// Returns false if painting the loading animation would paint the same thing
// that's already painted.
......@@ -171,13 +173,9 @@ class TabIcon : public views::View {
// Loading progress used for drawing the progress indicator.
double target_loading_progress_ = 1.0;
base::TimeTicks last_animation_update_time_;
LoadingAnimationState animation_state_;
base::Optional<base::TimeTicks> loading_progress_timer_;
// Fade-in animation for the favicon. Starts when a favicon loads or the tab
// is no longer loading. The latter case will fade into a placeholder icon.
base::Optional<base::TimeTicks> favicon_fade_in_animation_;
LoadingAnimationState pending_animation_state_;
// Crash animation (in place of favicon). Lazily created since most of the
// time it will be unneeded.
......
......@@ -143,7 +143,10 @@ class FakeTabController : public TabController {
class TabTest : public ChromeViewsTestBase {
public:
TabTest() {}
TabTest() {
// Prevent the fake clock from starting at 0 which is the null time.
fake_clock_.Advance(base::TimeDelta::FromMilliseconds(2000));
}
~TabTest() override {}
static TabIcon* GetTabIcon(const Tab& tab) { return tab.icon_; }
......@@ -312,7 +315,8 @@ class TabTest : public ChromeViewsTestBase {
// Forward the clock enough for any running animations to finish.
DCHECK(icon->clock_ == &fake_clock_);
fake_clock_.Advance(base::TimeDelta::FromMilliseconds(2000));
icon->UpdateLoadingAnimationState();
icon->StepLoadingAnimation(icon->waiting_state_.elapsed_time);
icon->animation_state_ = icon->pending_animation_state_;
}
static float GetLoadingProgress(TabIcon* icon) {
......@@ -650,6 +654,7 @@ TEST_F(TabTest, LayeredThrobber) {
// Reset.
data.network_state = TabNetworkState::kNone;
tab.SetData(data);
FinishRunningLoadingAnimations(icon);
EXPECT_FALSE(icon->ShowingLoadingAnimation());
// Simulate a drag started and stopped during a load: layer painting stops
......@@ -668,6 +673,7 @@ TEST_F(TabTest, LayeredThrobber) {
EXPECT_TRUE(icon->layer());
data.network_state = TabNetworkState::kNone;
tab.SetData(data);
FinishRunningLoadingAnimations(icon);
EXPECT_FALSE(icon->ShowingLoadingAnimation());
// Simulate a tab load starting and stopping during tab dragging (or with
......@@ -679,6 +685,7 @@ TEST_F(TabTest, LayeredThrobber) {
EXPECT_FALSE(icon->layer());
data.network_state = TabNetworkState::kNone;
tab.SetData(data);
FinishRunningLoadingAnimations(icon);
EXPECT_FALSE(icon->ShowingLoadingAnimation());
}
......
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