Commit 55a443f2 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Convert gfx::LinearAnimation units from int (ms) to TimeDelta.

Bug: none
Change-Id: I8a7313d1007b2cb8e6a9fe5cd584c5286afd818d
Reviewed-on: https://chromium-review.googlesource.com/575348Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488358}
parent c8338737
......@@ -200,17 +200,16 @@ void AutoclickRingHandler::SetGestureCenter(
// AutoclickRingHandler, private
void AutoclickRingHandler::StartAnimation(base::TimeDelta delay) {
int delay_ms = static_cast<int>(delay.InMilliseconds());
switch (current_animation_type_) {
case AnimationType::GROW_ANIMATION: {
view_.reset(new AutoclickRingView(tap_down_location_, ring_widget_));
SetDuration(delay_ms);
SetDuration(delay);
Start();
break;
}
case AnimationType::SHRINK_ANIMATION: {
view_.reset(new AutoclickRingView(tap_down_location_, ring_widget_));
SetDuration(delay_ms);
SetDuration(delay);
Start();
break;
}
......
......@@ -38,8 +38,10 @@ namespace ash {
namespace {
// The duration of the drag cancel animation in millisecond.
const int kCancelAnimationDuration = 250;
const int kTouchCancelAnimationDuration = 20;
constexpr base::TimeDelta kCancelAnimationDuration =
base::TimeDelta::FromMilliseconds(250);
constexpr base::TimeDelta kTouchCancelAnimationDuration =
base::TimeDelta::FromMilliseconds(20);
// The frame rate of the drag cancel animation in hertz.
const int kCancelAnimationFrameRate = 60;
......@@ -392,7 +394,7 @@ void DragDropController::OnWindowDestroyed(aura::Window* window) {
// DragDropController, protected:
gfx::LinearAnimation* DragDropController::CreateCancelAnimation(
int duration,
base::TimeDelta duration,
int frame_rate,
gfx::AnimationDelegate* delegate) {
return new gfx::LinearAnimation(duration, frame_rate, delegate);
......@@ -512,7 +514,8 @@ void DragDropController::AnimationEnded(const gfx::Animation* animation) {
}
}
void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) {
void DragDropController::DoDragCancel(
base::TimeDelta drag_cancel_animation_duration) {
ash::Shell::Get()->cursor_manager()->SetCursor(ui::CursorType::kPointer);
// |drag_window_| can be NULL if we have just started the drag and have not
......@@ -525,7 +528,7 @@ void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) {
Cleanup();
drag_operation_ = 0;
StartCanceledAnimation(drag_cancel_animation_duration_ms);
StartCanceledAnimation(drag_cancel_animation_duration);
if (should_block_during_drag_drop_)
quit_closure_.Run();
}
......@@ -548,13 +551,14 @@ void DragDropController::OnDisplayConfigurationChanging() {
DragCancel();
}
void DragDropController::StartCanceledAnimation(int animation_duration_ms) {
void DragDropController::StartCanceledAnimation(
base::TimeDelta animation_duration) {
DCHECK(drag_image_.get());
drag_image_->SetTouchDragOperationHintOff();
drag_image_initial_bounds_for_cancel_animation_ =
drag_image_->GetBoundsInScreen();
cancel_animation_.reset(CreateCancelAnimation(
animation_duration_ms, kCancelAnimationFrameRate, this));
animation_duration, kCancelAnimationFrameRate, this));
cancel_animation_->Start();
}
......
......@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/window_observer.h"
#include "ui/base/dragdrop/os_exchange_data.h"
......@@ -70,7 +71,7 @@ class ASH_EXPORT DragDropController : public aura::client::DragDropClient,
// cancel animation. Caller take ownership of the returned object. Protected
// for testing.
virtual gfx::LinearAnimation* CreateCancelAnimation(
int duration,
base::TimeDelta duration,
int frame_rate,
gfx::AnimationDelegate* delegate);
......@@ -79,7 +80,7 @@ class ASH_EXPORT DragDropController : public aura::client::DragDropClient,
virtual void Drop(aura::Window* target, const ui::LocatedEvent& event);
// Actual implementation of |DragCancel()|. protected for testing.
virtual void DoDragCancel(int drag_cancel_animation_duration_ms);
virtual void DoDragCancel(base::TimeDelta drag_cancel_animation_duration);
private:
friend class DragDropControllerTest;
......@@ -93,7 +94,7 @@ class ASH_EXPORT DragDropController : public aura::client::DragDropClient,
void OnDisplayConfigurationChanging() override;
// Helper method to start drag widget flying back animation.
void StartCanceledAnimation(int animation_duration_ms);
void StartCanceledAnimation(base::TimeDelta animation_duration);
// Helper method to forward |pending_log_tap_| event to |drag_source_window_|.
void ForwardPendingLongTap();
......
......@@ -118,18 +118,15 @@ class DragTestView : public views::View {
class CompletableLinearAnimation : public gfx::LinearAnimation {
public:
CompletableLinearAnimation(int duration,
CompletableLinearAnimation(base::TimeDelta duration,
int frame_rate,
gfx::AnimationDelegate* delegate)
: gfx::LinearAnimation(duration, frame_rate, delegate),
duration_(duration) {}
: gfx::LinearAnimation(duration, frame_rate, delegate) {}
void Complete() {
Step(start_time() + base::TimeDelta::FromMilliseconds(duration_));
}
void Complete() { Step(start_time() + duration()); }
private:
int duration_;
DISALLOW_COPY_AND_ASSIGN(CompletableLinearAnimation);
};
class TestDragDropController : public DragDropController {
......@@ -173,14 +170,14 @@ class TestDragDropController : public DragDropController {
}
gfx::LinearAnimation* CreateCancelAnimation(
int duration,
base::TimeDelta duration,
int frame_rate,
gfx::AnimationDelegate* delegate) override {
return new CompletableLinearAnimation(duration, frame_rate, delegate);
}
void DoDragCancel(int animation_duration_ms) override {
DragDropController::DoDragCancel(animation_duration_ms);
void DoDragCancel(base::TimeDelta animation_duration) override {
DragDropController::DoDragCancel(animation_duration);
drag_canceled_ = true;
}
......
......@@ -4,6 +4,7 @@
#include "ash/touch_hud/touch_hud_renderer.h"
#include "base/time/time.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_owner.h"
......@@ -22,7 +23,8 @@ const int kPointRadius = 20;
const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC);
const SkColor kProjectionStrokeColor = SK_ColorGRAY;
const int kProjectionAlpha = 0xB0;
const int kFadeoutDurationInMs = 250;
constexpr base::TimeDelta kFadeoutDuration =
base::TimeDelta::FromMilliseconds(250);
const int kFadeoutFrameRate = 60;
// TouchPointView draws a single touch point. This object manages its own
......@@ -59,8 +61,8 @@ class TouchPointView : public views::View,
touch.type() == ui::ET_TOUCH_CANCELLED ||
touch.type() == ui::ET_POINTER_UP ||
touch.type() == ui::ET_POINTER_CANCELLED) {
fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs,
kFadeoutFrameRate, this));
fadeout_.reset(
new gfx::LinearAnimation(kFadeoutDuration, kFadeoutFrameRate, this));
fadeout_->Start();
} else {
SetX(parent()->GetMirroredXInView(touch.root_location().x()) -
......
......@@ -28,9 +28,9 @@ namespace {
constexpr char kWidgetName[] = "TouchCalibratorOverlay";
constexpr int kAnimationFrameRate = 100;
constexpr int kFadeDurationInMs = 150;
constexpr int kPointMoveDurationInMs = 400;
constexpr int kPointMoveDurationLongInMs = 500;
constexpr auto kFadeDuration = base::TimeDelta::FromMilliseconds(150);
constexpr auto kPointMoveDuration = base::TimeDelta::FromMilliseconds(400);
constexpr auto kPointMoveDurationLong = base::TimeDelta::FromMilliseconds(500);
const SkColor kExitLabelColor = SkColorSetARGBInline(255, 138, 138, 138);
constexpr int kExitLabelWidth = 300;
......@@ -46,7 +46,8 @@ constexpr int kHintBoxSublabelTextSize = 3;
constexpr int kThrobberCircleViewWidth = 64;
constexpr float kThrobberCircleRadiusFactor = 3.f / 8.f;
constexpr int kFinalMessageTransitionDurationMs = 200;
constexpr auto kFinalMessageTransitionDuration =
base::TimeDelta::FromMilliseconds(200);
constexpr int kCompleteMessageViewWidth = 427;
constexpr int kCompleteMessageViewHeight = kThrobberCircleViewWidth;
constexpr int kCompleteMessageTextSize = 16;
......@@ -105,14 +106,13 @@ gfx::Size GetSizeForString(const base::string16& text,
}
void AnimateLayerToPosition(views::View* view,
int duration,
base::TimeDelta duration,
gfx::Point end_position,
float opacity = 1.f) {
ui::ScopedLayerAnimationSettings slide_settings(view->layer()->GetAnimator());
slide_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
slide_settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(duration));
slide_settings.SetTransitionDuration(duration);
view->SetBoundsRect(gfx::Rect(end_position, view->size()));
view->layer()->SetOpacity(opacity);
}
......@@ -479,7 +479,7 @@ TouchCalibratorView::TouchCalibratorView(const display::Display& target_display,
set_owned_by_client();
animator_.reset(
new gfx::LinearAnimation(kFadeDurationInMs, kAnimationFrameRate, this));
new gfx::LinearAnimation(kFadeDuration, kAnimationFrameRate, this));
InitViewContents();
AdvanceToNextState();
......@@ -713,7 +713,7 @@ void TouchCalibratorView::AdvanceToNextState() {
end_opacity_value_ = kBackgroundFinalOpacity;
flags_.setStyle(cc::PaintFlags::kFill_Style);
animator_->SetDuration(kFadeDurationInMs);
animator_->SetDuration(kFadeDuration);
animator_->Start();
return;
case DISPLAY_POINT_1:
......@@ -722,7 +722,7 @@ void TouchCalibratorView::AdvanceToNextState() {
// The touch point has to be animated from the top left corner of the
// screen to the top right corner.
AnimateLayerToPosition(
touch_point_view_, kPointMoveDurationInMs,
touch_point_view_, kPointMoveDuration,
gfx::Point(display_.bounds().width() - kTouchPointViewOffset -
touch_point_view_->width(),
touch_point_view_->y()));
......@@ -734,7 +734,7 @@ void TouchCalibratorView::AdvanceToNextState() {
// The touch point has to be animated from the top right corner of the
// screen to the bottom left corner.
AnimateLayerToPosition(
touch_point_view_, kPointMoveDurationLongInMs,
touch_point_view_, kPointMoveDurationLong,
gfx::Point(kTouchPointViewOffset, display_.bounds().height() -
kTouchPointViewOffset -
touch_point_view_->height()));
......@@ -745,7 +745,7 @@ void TouchCalibratorView::AdvanceToNextState() {
// The touch point has to be animated from the bottom left corner of the
// screen to the bottom right corner.
AnimateLayerToPosition(
touch_point_view_, kPointMoveDurationInMs,
touch_point_view_, kPointMoveDuration,
gfx::Point(display_.bounds().width() - kTouchPointViewOffset -
touch_point_view_->width(),
touch_point_view_->y()));
......@@ -758,7 +758,7 @@ void TouchCalibratorView::AdvanceToNextState() {
touch_point_view_->SetVisible(false);
AnimateLayerToPosition(completion_message_view_,
kFinalMessageTransitionDurationMs,
kFinalMessageTransitionDuration,
gfx::Point(completion_message_view_->x(),
display_.bounds().height() / 2));
return;
......@@ -768,7 +768,7 @@ void TouchCalibratorView::AdvanceToNextState() {
// In case of primary view, we also need to fade out the calibration
// complete message view.
AnimateLayerToPosition(
completion_message_view_, kFadeDurationInMs,
completion_message_view_, kFadeDuration,
gfx::Point(completion_message_view_->x(),
completion_message_view_->y() +
2 * completion_message_view_->height()),
......@@ -779,7 +779,7 @@ void TouchCalibratorView::AdvanceToNextState() {
end_opacity_value_ = 0.f;
flags_.setStyle(cc::PaintFlags::kFill_Style);
animator_->SetDuration(kFadeDurationInMs);
animator_->SetDuration(kFadeDuration);
animator_->Start();
return;
default:
......
......@@ -14,7 +14,7 @@ AnimatedIcon::AnimatedIcon(const gfx::VectorIcon& icon, NSView* host_view)
host_view_(host_view),
duration_(gfx::GetDurationOfAnimation(icon)),
animation_(base::MakeUnique<gfx::LinearAnimation>(this)) {
animation_->SetDuration(duration_.InMilliseconds());
animation_->SetDuration(duration_);
}
AnimatedIcon::~AnimatedIcon() {}
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/download/download_started_animation.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -16,7 +17,7 @@
#include "ui/views/widget/widget.h"
// How long to spend moving downwards and fading out after waiting.
const int kMoveTimeMs = 600;
constexpr auto kMoveTime = base::TimeDelta::FromMilliseconds(600);
// The animation framerate.
const int kFrameRateHz = 60;
......@@ -59,8 +60,7 @@ class DownloadStartedAnimationViews : public gfx::LinearAnimation,
DownloadStartedAnimationViews::DownloadStartedAnimationViews(
content::WebContents* web_contents)
: gfx::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL),
popup_(NULL) {
: gfx::LinearAnimation(kMoveTime, kFrameRateHz, NULL), popup_(NULL) {
gfx::ImageSkia download_image =
gfx::CreateVectorIcon(kFileDownloadShelfIcon, 72, gfx::kGoogleBlue500);
......
......@@ -49,38 +49,43 @@
#include "services/ui/public/interfaces/window_manager.mojom.h" // nogncheck
#endif
namespace {
// The alpha and color of the bubble's shadow.
static const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0);
const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0);
// The roundedness of the edges of our bubble.
static const int kBubbleCornerRadius = 4;
const int kBubbleCornerRadius = 4;
// How close the mouse can get to the infobubble before it starts sliding
// off-screen.
static const int kMousePadding = 20;
const int kMousePadding = 20;
// The horizontal offset of the text within the status bubble, not including the
// outer shadow ring.
static const int kTextPositionX = 3;
const int kTextPositionX = 3;
// The minimum horizontal space between the (right) end of the text and the edge
// of the status bubble, not including the outer shadow ring.
static const int kTextHorizPadding = 1;
const int kTextHorizPadding = 1;
// Delays before we start hiding or showing the bubble after we receive a
// show or hide request.
static const int kShowDelay = 80;
static const int kHideDelay = 250;
const int kShowDelay = 80;
const int kHideDelay = 250;
// How long each fade should last for.
static const int kShowFadeDurationMS = 120;
static const int kHideFadeDurationMS = 200;
static const int kFramerate = 25;
constexpr auto kShowFadeDuration = base::TimeDelta::FromMilliseconds(120);
constexpr auto kHideFadeDuration = base::TimeDelta::FromMilliseconds(200);
const int kFramerate = 25;
// How long each expansion step should take.
static const int kMinExpansionStepDurationMS = 20;
static const int kMaxExpansionStepDurationMS = 150;
constexpr auto kMinExpansionStepDuration =
base::TimeDelta::FromMilliseconds(20);
constexpr auto kMaxExpansionStepDuration =
base::TimeDelta::FromMilliseconds(150);
} // namespace
// StatusBubbleViews::StatusViewAnimation --------------------------------------
class StatusBubbleViews::StatusViewAnimation : public gfx::LinearAnimation,
......@@ -179,7 +184,7 @@ class StatusBubbleViews::StatusView : public views::View {
void RestartTimer(base::TimeDelta delay);
// Manage the fades and starting and stopping the animations correctly.
void StartFade(float start, float end, int duration);
void StartFade(float start, float end, base::TimeDelta duration);
void StartHiding();
void StartShowing();
......@@ -274,10 +279,10 @@ void StatusBubbleViews::StatusView::StartTimer(base::TimeDelta time) {
void StatusBubbleViews::StatusView::OnTimer() {
if (state_ == BUBBLE_HIDING_TIMER) {
state_ = BUBBLE_HIDING_FADE;
StartFade(1.0f, 0.0f, kHideFadeDurationMS);
StartFade(1.0f, 0.0f, kHideFadeDuration);
} else if (state_ == BUBBLE_SHOWING_TIMER) {
state_ = BUBBLE_SHOWING_FADE;
StartFade(0.0f, 1.0f, kShowFadeDurationMS);
StartFade(0.0f, 1.0f, kShowFadeDuration);
}
}
......@@ -301,7 +306,7 @@ void StatusBubbleViews::StatusView::ResetTimer() {
void StatusBubbleViews::StatusView::StartFade(float start,
float end,
int duration) {
base::TimeDelta duration) {
animation_.reset(new StatusViewAnimation(this, start, end));
// This will also reset the currently-occurring animation.
......@@ -323,8 +328,7 @@ void StatusBubbleViews::StatusView::StartHiding() {
float current_opacity = animation_->GetCurrentOpacity();
// Start a fade in the opposite direction.
StartFade(current_opacity, 0.0f,
static_cast<int>(kHideFadeDurationMS * current_opacity));
StartFade(current_opacity, 0.0f, kHideFadeDuration * current_opacity);
}
}
......@@ -344,8 +348,7 @@ void StatusBubbleViews::StatusView::StartShowing() {
float current_opacity = animation_->GetCurrentOpacity();
// Start a fade in the opposite direction.
StartFade(current_opacity, 1.0f,
static_cast<int>(kShowFadeDurationMS * current_opacity));
StartFade(current_opacity, 1.0f, kShowFadeDuration * current_opacity);
} else if (state_ == BUBBLE_SHOWING_TIMER) {
// We hadn't yet begun showing anything when we received a new request
// for something to show, so we start from scratch.
......@@ -588,10 +591,10 @@ void StatusBubbleViews::StatusViewExpander::StartExpansion(
expanded_text_ = expanded_text;
expansion_start_ = expansion_start;
expansion_end_ = expansion_end;
int min_duration = std::max(kMinExpansionStepDurationMS,
static_cast<int>(kMaxExpansionStepDurationMS *
(expansion_end - expansion_start) / 100.0));
SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration));
base::TimeDelta min_duration = std::max(
kMinExpansionStepDuration,
kMaxExpansionStepDuration * (expansion_end - expansion_start) / 100.0);
SetDuration(std::min(kMaxExpansionStepDuration, min_duration));
Start();
}
......
......@@ -232,9 +232,8 @@ class Tab::FaviconCrashAnimation : public gfx::LinearAnimation,
public gfx::AnimationDelegate {
public:
explicit FaviconCrashAnimation(Tab* target)
: gfx::LinearAnimation(1000, 25, this),
target_(target) {
}
: gfx::LinearAnimation(base::TimeDelta::FromSeconds(1), 25, this),
target_(target) {}
~FaviconCrashAnimation() override {}
// gfx::Animation overrides:
......
......@@ -57,7 +57,8 @@ const int kMaxRippleRadius = 54;
const SkColor kRippleColor = SkColorSetA(gfx::kGoogleBlue500, 0x66);
const int kMaxRippleBurstRadius = 72;
const gfx::Tween::Type kBurstAnimationTweenType = gfx::Tween::EASE_IN;
const int kRippleBurstAnimationDuration = 160;
constexpr auto kRippleBurstAnimationDuration =
base::TimeDelta::FromMilliseconds(160);
// Offset of the affordance when it is at the maximum distance with content
// border. Since the affordance is initially out of content bounds, this is the
......@@ -66,7 +67,7 @@ const int kMaxAffordanceOffset = 146;
// Parameters defining animation when the affordance is aborted.
const gfx::Tween::Type kAbortAnimationTweenType = gfx::Tween::EASE_IN;
const int kAbortAnimationDuration = 300;
constexpr auto kAbortAnimationDuration = base::TimeDelta::FromMilliseconds(300);
bool ShouldNavigateForward(const NavigationController& controller,
OverscrollMode mode) {
......
......@@ -115,8 +115,8 @@ void SearchResultListView::SetAutoLaunchTimeout(
if (timeout > base::TimeDelta()) {
auto_launch_indicator_->SetVisible(true);
auto_launch_indicator_->SetBounds(0, 0, 0, kTimeoutIndicatorHeight);
auto_launch_animation_.reset(new gfx::LinearAnimation(
timeout.InMilliseconds(), kTimeoutFramerate, this));
auto_launch_animation_.reset(
new gfx::LinearAnimation(timeout, kTimeoutFramerate, this));
auto_launch_animation_->Start();
} else {
auto_launch_indicator_->SetVisible(false);
......
......@@ -47,8 +47,7 @@ class FakeAnimationContainerObserver : public AnimationContainerObserver {
class TestAnimation : public LinearAnimation {
public:
explicit TestAnimation(AnimationDelegate* delegate)
: LinearAnimation(20, 20, delegate) {
}
: LinearAnimation(base::TimeDelta::FromMilliseconds(20), 20, delegate) {}
void AnimateToState(double state) override {}
......
......@@ -44,9 +44,10 @@ class RunAnimation : public LinearAnimation {
class CancelAnimation : public LinearAnimation {
public:
CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
: LinearAnimation(duration, frame_rate, delegate) {
}
CancelAnimation(base::TimeDelta duration,
int frame_rate,
AnimationDelegate* delegate)
: LinearAnimation(duration, frame_rate, delegate) {}
void AnimateToState(double state) override {
if (state >= 0.5)
......@@ -59,9 +60,10 @@ class CancelAnimation : public LinearAnimation {
class EndAnimation : public LinearAnimation {
public:
EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
: LinearAnimation(duration, frame_rate, delegate) {
}
EndAnimation(base::TimeDelta duration,
int frame_rate,
AnimationDelegate* delegate)
: LinearAnimation(duration, frame_rate, delegate) {}
void AnimateToState(double state) override {
if (state >= 0.5)
......@@ -89,7 +91,7 @@ class DeletingAnimationDelegate : public AnimationDelegate {
TEST_F(AnimationTest, RunCase) {
TestAnimationDelegate ad;
RunAnimation a1(150, &ad);
a1.SetDuration(2000);
a1.SetDuration(base::TimeDelta::FromSeconds(2));
a1.Start();
base::RunLoop().Run();
......@@ -99,7 +101,7 @@ TEST_F(AnimationTest, RunCase) {
TEST_F(AnimationTest, CancelCase) {
TestAnimationDelegate ad;
CancelAnimation a2(2000, 150, &ad);
CancelAnimation a2(base::TimeDelta::FromSeconds(2), 150, &ad);
a2.Start();
base::RunLoop().Run();
......@@ -111,7 +113,7 @@ TEST_F(AnimationTest, CancelCase) {
// right delegate methods invoked.
TEST_F(AnimationTest, EndCase) {
TestAnimationDelegate ad;
EndAnimation a2(2000, 150, &ad);
EndAnimation a2(base::TimeDelta::FromSeconds(2), 150, &ad);
a2.Start();
base::RunLoop().Run();
......@@ -143,7 +145,7 @@ TEST_F(AnimationTest, ShouldRenderRichAnimation) {
// Test that current value is always 0 after Start() is called.
TEST_F(AnimationTest, StartState) {
LinearAnimation animation(100, 60, NULL);
LinearAnimation animation(base::TimeDelta::FromMilliseconds(100), 60, NULL);
EXPECT_EQ(0.0, animation.GetCurrentValue());
animation.Start();
EXPECT_EQ(0.0, animation.GetCurrentValue());
......
......@@ -12,27 +12,22 @@
#include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/animation/animation_delegate.h"
using base::Time;
using base::TimeDelta;
namespace gfx {
static TimeDelta CalculateInterval(int frame_rate) {
static base::TimeDelta CalculateInterval(int frame_rate) {
int timer_interval = 1000000 / frame_rate;
if (timer_interval < 10000)
timer_interval = 10000;
return TimeDelta::FromMicroseconds(timer_interval);
return base::TimeDelta::FromMicroseconds(timer_interval);
}
LinearAnimation::LinearAnimation(AnimationDelegate* delegate, int frame_rate)
: LinearAnimation(0, frame_rate, delegate) {}
: LinearAnimation({}, frame_rate, delegate) {}
LinearAnimation::LinearAnimation(int duration,
LinearAnimation::LinearAnimation(base::TimeDelta duration,
int frame_rate,
AnimationDelegate* delegate)
: Animation(CalculateInterval(frame_rate)),
state_(0.0),
in_end_(false) {
: Animation(CalculateInterval(frame_rate)), state_(0.0), in_end_(false) {
set_delegate(delegate);
SetDuration(duration);
}
......@@ -60,8 +55,8 @@ void LinearAnimation::End() {
Stop();
}
void LinearAnimation::SetDuration(int duration) {
duration_ = TimeDelta::FromMilliseconds(duration);
void LinearAnimation::SetDuration(base::TimeDelta duration) {
duration_ = duration;
if (duration_ < timer_interval())
duration_ = timer_interval();
if (is_animating())
......@@ -69,7 +64,7 @@ void LinearAnimation::SetDuration(int duration) {
}
void LinearAnimation::Step(base::TimeTicks time_now) {
TimeDelta elapsed_time = time_now - start_time();
base::TimeDelta elapsed_time = time_now - start_time();
state_ = static_cast<double>(elapsed_time.InMicroseconds()) /
static_cast<double>(duration_.InMicroseconds());
if (state_ >= 1.0)
......
......@@ -30,7 +30,9 @@ class ANIMATION_EXPORT LinearAnimation : public Animation {
int frame_rate = kDefaultFrameRate);
// Initializes all fields.
LinearAnimation(int duration, int frame_rate, AnimationDelegate* delegate);
LinearAnimation(base::TimeDelta duration,
int frame_rate,
AnimationDelegate* delegate);
// Gets the value for the current state, according to the animation curve in
// use. This class provides only for a linear relationship, however subclasses
......@@ -45,7 +47,7 @@ class ANIMATION_EXPORT LinearAnimation : public Animation {
// Changes the length of the animation. This resets the current
// state of the animation to the beginning.
void SetDuration(int duration);
void SetDuration(base::TimeDelta duration);
protected:
// Called when the animation progresses. Subclasses override this to
......@@ -66,6 +68,8 @@ class ANIMATION_EXPORT LinearAnimation : public Animation {
// Overriden to return true if state is not 1.
bool ShouldSendCanceledFromStop() override;
base::TimeDelta duration() const { return duration_; }
private:
base::TimeDelta duration_;
......
......@@ -52,7 +52,8 @@ void SlideAnimation::Show() {
}
// This will also reset the currently-occurring animation.
SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_)));
SetDuration(base::TimeDelta::FromMilliseconds(
static_cast<int>(slide_duration_ * (1 - value_current_))));
Start();
}
......@@ -76,7 +77,8 @@ void SlideAnimation::Hide() {
}
// This will also reset the currently-occurring animation.
SetDuration(static_cast<int>(slide_duration_ * value_current_));
SetDuration(base::TimeDelta::FromMilliseconds(
static_cast<int>(slide_duration_ * value_current_)));
Start();
}
......
......@@ -20,7 +20,8 @@ namespace {
// This value should be the same as the duration of reveal animation of
// the settings view of an Android notification.
constexpr int kBackgroundColorChangeDuration = 360;
constexpr auto kBackgroundColorChangeDuration =
base::TimeDelta::FromMilliseconds(360);
// The initial background color of the view.
constexpr SkColor kInitialBackgroundColor =
......
......@@ -112,7 +112,7 @@ void ProgressBar::SetValue(double value) {
current_value_ = adjusted_value;
if (IsIndeterminate()) {
indeterminate_bar_animation_.reset(new gfx::LinearAnimation(this));
indeterminate_bar_animation_->SetDuration(2000); // In milliseconds.
indeterminate_bar_animation_->SetDuration(base::TimeDelta::FromSeconds(2));
indeterminate_bar_animation_->Start();
} else {
indeterminate_bar_animation_.reset();
......
......@@ -402,13 +402,11 @@ MdTabStrip::MdTabStrip() {
// These durations are taken from the Paper Tabs source:
// https://github.com/PolymerElements/paper-tabs/blob/master/paper-tabs.html
// See |selectionBar.expand| and |selectionBar.contract|.
const int kExpandAnimationDurationMs = 150;
expand_animation_.reset(new gfx::LinearAnimation(this));
expand_animation_->SetDuration(kExpandAnimationDurationMs);
expand_animation_->SetDuration(base::TimeDelta::FromMilliseconds(150));
const int kContractAnimationDurationMs = 180;
contract_animation_.reset(new gfx::LinearAnimation(this));
contract_animation_->SetDuration(kContractAnimationDurationMs);
contract_animation_->SetDuration(base::TimeDelta::FromMilliseconds(180));
}
MdTabStrip::~MdTabStrip() {}
......
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