Commit 54b9145d authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup found while touching tabstrip code:

* More consistent names
* Move initializers to .h
* Remove using directives

BUG=none
TEST=none

Change-Id: I52939db0418f50d3cef9c1ab92a04a79c326a9b9
Reviewed-on: https://chromium-review.googlesource.com/1094256Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568326}
parent c57280be
...@@ -177,39 +177,35 @@ int Tween::LinearIntValueBetween(double value, int start, int target) { ...@@ -177,39 +177,35 @@ int Tween::LinearIntValueBetween(double value, int start, int target) {
// static // static
gfx::Rect Tween::RectValueBetween(double value, gfx::Rect Tween::RectValueBetween(double value,
const gfx::Rect& start_bounds, const gfx::Rect& start,
const gfx::Rect& target_bounds) { const gfx::Rect& target) {
return gfx::Rect( return gfx::Rect(
LinearIntValueBetween(value, start_bounds.x(), target_bounds.x()), LinearIntValueBetween(value, start.x(), target.x()),
LinearIntValueBetween(value, start_bounds.y(), target_bounds.y()), LinearIntValueBetween(value, start.y(), target.y()),
LinearIntValueBetween(value, start_bounds.width(), target_bounds.width()), LinearIntValueBetween(value, start.width(), target.width()),
LinearIntValueBetween( LinearIntValueBetween(value, start.height(), target.height()));
value, start_bounds.height(), target_bounds.height()));
} }
// static // static
gfx::Transform Tween::TransformValueBetween( gfx::Transform Tween::TransformValueBetween(double value,
double value, const gfx::Transform& start,
const gfx::Transform& start_transform, const gfx::Transform& target) {
const gfx::Transform& end_transform) {
if (value >= 1.0) if (value >= 1.0)
return end_transform; return target;
if (value <= 0.0) if (value <= 0.0)
return start_transform; return start;
gfx::Transform to_return = end_transform;
to_return.Blend(start_transform, value);
gfx::Transform to_return = target;
to_return.Blend(start, value);
return to_return; return to_return;
} }
gfx::SizeF Tween::SizeValueBetween(double value, gfx::SizeF Tween::SizeValueBetween(double value,
const gfx::SizeF& start_size, const gfx::SizeF& start,
const gfx::SizeF& target_size) { const gfx::SizeF& target) {
return gfx::SizeF( return gfx::SizeF(
Tween::FloatValueBetween(value, start_size.width(), target_size.width()), Tween::FloatValueBetween(value, start.width(), target.width()),
Tween::FloatValueBetween(value, start_size.height(), Tween::FloatValueBetween(value, start.height(), target.height()));
target_size.height()));
} }
} // namespace gfx } // namespace gfx
...@@ -65,17 +65,16 @@ class ANIMATION_EXPORT Tween { ...@@ -65,17 +65,16 @@ class ANIMATION_EXPORT Tween {
// other integers in the range. This is the integer interpolation approach // other integers in the range. This is the integer interpolation approach
// specified by www.w3.org/TR/css3-transitions. // specified by www.w3.org/TR/css3-transitions.
static int LinearIntValueBetween(double value, int start, int target); static int LinearIntValueBetween(double value, int start, int target);
static gfx::Rect RectValueBetween(double value,
const gfx::Rect& start_bounds,
const gfx::Rect& target_bounds);
static gfx::Transform TransformValueBetween(
double value,
const gfx::Transform& start_transform,
const gfx::Transform& target_transform);
static gfx::Rect RectValueBetween(double value,
const gfx::Rect& start,
const gfx::Rect& target);
static gfx::Transform TransformValueBetween(double value,
const gfx::Transform& start,
const gfx::Transform& target);
static gfx::SizeF SizeValueBetween(double value, static gfx::SizeF SizeValueBetween(double value,
const gfx::SizeF& start_size, const gfx::SizeF& start,
const gfx::SizeF& target_size); const gfx::SizeF& target);
private: private:
Tween(); Tween();
......
...@@ -11,21 +11,10 @@ ...@@ -11,21 +11,10 @@
#include "ui/views/animation/bounds_animator_observer.h" #include "ui/views/animation/bounds_animator_observer.h"
#include "ui/views/view.h" #include "ui/views/view.h"
// Duration in milliseconds for animations.
static const int kDefaultAnimationDuration = 200;
using gfx::Animation;
using gfx::AnimationContainer;
using gfx::SlideAnimation;
using gfx::Tween;
namespace views { namespace views {
BoundsAnimator::BoundsAnimator(View* parent) BoundsAnimator::BoundsAnimator(View* parent)
: parent_(parent), : parent_(parent), container_(new gfx::AnimationContainer()) {
container_(new AnimationContainer()),
animation_duration_ms_(kDefaultAnimationDuration),
tween_type_(Tween::EASE_OUT) {
container_->set_observer(this); container_->set_observer(this);
} }
...@@ -86,7 +75,7 @@ gfx::Rect BoundsAnimator::GetTargetBounds(View* view) { ...@@ -86,7 +75,7 @@ gfx::Rect BoundsAnimator::GetTargetBounds(View* view) {
void BoundsAnimator::SetAnimationForView( void BoundsAnimator::SetAnimationForView(
View* view, View* view,
std::unique_ptr<SlideAnimation> animation) { std::unique_ptr<gfx::SlideAnimation> animation) {
DCHECK(animation); DCHECK(animation);
if (!IsAnimating(view)) if (!IsAnimating(view))
...@@ -94,9 +83,9 @@ void BoundsAnimator::SetAnimationForView( ...@@ -94,9 +83,9 @@ void BoundsAnimator::SetAnimationForView(
// We delay deleting the animation until the end so that we don't prematurely // We delay deleting the animation until the end so that we don't prematurely
// send out notification that we're done. // send out notification that we're done.
std::unique_ptr<Animation> old_animation = ResetAnimationForView(view); std::unique_ptr<gfx::Animation> old_animation = ResetAnimationForView(view);
SlideAnimation* animation_ptr = animation.get(); gfx::SlideAnimation* animation_ptr = animation.get();
data_[view].animation = std::move(animation); data_[view].animation = std::move(animation);
animation_to_view_[animation_ptr] = view; animation_to_view_[animation_ptr] = view;
...@@ -105,7 +94,7 @@ void BoundsAnimator::SetAnimationForView( ...@@ -105,7 +94,7 @@ void BoundsAnimator::SetAnimationForView(
animation_ptr->Show(); animation_ptr->Show();
} }
const SlideAnimation* BoundsAnimator::GetAnimationForView(View* view) { const gfx::SlideAnimation* BoundsAnimator::GetAnimationForView(View* view) {
return !IsAnimating(view) ? nullptr : data_[view].animation.get(); return !IsAnimating(view) ? nullptr : data_[view].animation.get();
} }
...@@ -156,8 +145,7 @@ void BoundsAnimator::RemoveObserver(BoundsAnimatorObserver* observer) { ...@@ -156,8 +145,7 @@ void BoundsAnimator::RemoveObserver(BoundsAnimatorObserver* observer) {
} }
std::unique_ptr<gfx::SlideAnimation> BoundsAnimator::CreateAnimation() { std::unique_ptr<gfx::SlideAnimation> BoundsAnimator::CreateAnimation() {
std::unique_ptr<gfx::SlideAnimation> animation = auto animation = std::make_unique<gfx::SlideAnimation>(this);
std::make_unique<SlideAnimation>(this);
animation->SetContainer(container_.get()); animation->SetContainer(container_.get());
animation->SetSlideDuration(animation_duration_ms_); animation->SetSlideDuration(animation_duration_ms_);
animation->SetTweenType(tween_type_); animation->SetTweenType(tween_type_);
...@@ -191,11 +179,13 @@ void BoundsAnimator::CleanupData(bool send_cancel, Data* data, View* view) { ...@@ -191,11 +179,13 @@ void BoundsAnimator::CleanupData(bool send_cancel, Data* data, View* view) {
} }
} }
std::unique_ptr<Animation> BoundsAnimator::ResetAnimationForView(View* view) { std::unique_ptr<gfx::Animation> BoundsAnimator::ResetAnimationForView(
View* view) {
if (!IsAnimating(view)) if (!IsAnimating(view))
return nullptr; return nullptr;
std::unique_ptr<Animation> old_animation = std::move(data_[view].animation); std::unique_ptr<gfx::Animation> old_animation =
std::move(data_[view].animation);
animation_to_view_.erase(old_animation.get()); animation_to_view_.erase(old_animation.get());
// Reset the delegate so that we don't attempt any processing when the // Reset the delegate so that we don't attempt any processing when the
// animation calls us back. // animation calls us back.
...@@ -203,7 +193,7 @@ std::unique_ptr<Animation> BoundsAnimator::ResetAnimationForView(View* view) { ...@@ -203,7 +193,7 @@ std::unique_ptr<Animation> BoundsAnimator::ResetAnimationForView(View* view) {
return old_animation; return old_animation;
} }
void BoundsAnimator::AnimationEndedOrCanceled(const Animation* animation, void BoundsAnimator::AnimationEndedOrCanceled(const gfx::Animation* animation,
AnimationEndType type) { AnimationEndType type) {
DCHECK(animation_to_view_.find(animation) != animation_to_view_.end()); DCHECK(animation_to_view_.find(animation) != animation_to_view_.end());
...@@ -225,7 +215,7 @@ void BoundsAnimator::AnimationEndedOrCanceled(const Animation* animation, ...@@ -225,7 +215,7 @@ void BoundsAnimator::AnimationEndedOrCanceled(const Animation* animation,
CleanupData(false, &data, view); CleanupData(false, &data, view);
} }
void BoundsAnimator::AnimationProgressed(const Animation* animation) { void BoundsAnimator::AnimationProgressed(const gfx::Animation* animation) {
DCHECK(animation_to_view_.find(animation) != animation_to_view_.end()); DCHECK(animation_to_view_.find(animation) != animation_to_view_.end());
View* view = animation_to_view_[animation]; View* view = animation_to_view_[animation];
...@@ -247,16 +237,16 @@ void BoundsAnimator::AnimationProgressed(const Animation* animation) { ...@@ -247,16 +237,16 @@ void BoundsAnimator::AnimationProgressed(const Animation* animation) {
data.delegate->AnimationProgressed(animation); data.delegate->AnimationProgressed(animation);
} }
void BoundsAnimator::AnimationEnded(const Animation* animation) { void BoundsAnimator::AnimationEnded(const gfx::Animation* animation) {
AnimationEndedOrCanceled(animation, ANIMATION_ENDED); AnimationEndedOrCanceled(animation, ANIMATION_ENDED);
} }
void BoundsAnimator::AnimationCanceled(const Animation* animation) { void BoundsAnimator::AnimationCanceled(const gfx::Animation* animation) {
AnimationEndedOrCanceled(animation, ANIMATION_CANCELED); AnimationEndedOrCanceled(animation, ANIMATION_CANCELED);
} }
void BoundsAnimator::AnimationContainerProgressed( void BoundsAnimator::AnimationContainerProgressed(
AnimationContainer* container) { gfx::AnimationContainer* container) {
if (!repaint_bounds_.IsEmpty()) { if (!repaint_bounds_.IsEmpty()) {
// Adjust for rtl. // Adjust for rtl.
repaint_bounds_.set_x(parent_->GetMirroredXWithWidthInView( repaint_bounds_.set_x(parent_->GetMirroredXWithWidthInView(
...@@ -276,7 +266,7 @@ void BoundsAnimator::AnimationContainerProgressed( ...@@ -276,7 +266,7 @@ void BoundsAnimator::AnimationContainerProgressed(
} }
} }
void BoundsAnimator::AnimationContainerEmpty(AnimationContainer* container) { void BoundsAnimator::AnimationContainerEmpty(
} gfx::AnimationContainer* container) {}
} // namespace views } // namespace views
...@@ -178,9 +178,9 @@ class VIEWS_EXPORT BoundsAnimator : public gfx::AnimationDelegate, ...@@ -178,9 +178,9 @@ class VIEWS_EXPORT BoundsAnimator : public gfx::AnimationDelegate,
// to repaint these bounds. // to repaint these bounds.
gfx::Rect repaint_bounds_; gfx::Rect repaint_bounds_;
int animation_duration_ms_; int animation_duration_ms_ = 200;
gfx::Tween::Type tween_type_; gfx::Tween::Type tween_type_ = gfx::Tween::EASE_OUT;
DISALLOW_COPY_AND_ASSIGN(BoundsAnimator); DISALLOW_COPY_AND_ASSIGN(BoundsAnimator);
}; };
......
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