diff options
-rw-r--r-- | cc/input/page_scale_animation.cc | 25 | ||||
-rw-r--r-- | cc/input/page_scale_animation.h | 12 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 9 |
3 files changed, 33 insertions, 13 deletions
diff --git a/cc/input/page_scale_animation.cc b/cc/input/page_scale_animation.cc index d4b139b..1a7a244 100644 --- a/cc/input/page_scale_animation.cc +++ b/cc/input/page_scale_animation.cc @@ -7,6 +7,7 @@ #include <math.h> #include "base/logging.h" +#include "cc/animation/timing_function.h" #include "ui/gfx/point_f.h" #include "ui/gfx/rect_f.h" #include "ui/gfx/vector2d_conversions.h" @@ -44,19 +45,23 @@ scoped_ptr<PageScaleAnimation> PageScaleAnimation::Create( float start_page_scale_factor, gfx::SizeF viewport_size, gfx::SizeF root_layer_size, - double start_time) { + double start_time, + scoped_ptr<TimingFunction> timing_function) { return make_scoped_ptr(new PageScaleAnimation(start_scroll_offset, start_page_scale_factor, viewport_size, root_layer_size, - start_time)); + start_time, + timing_function.Pass())); } -PageScaleAnimation::PageScaleAnimation(gfx::Vector2dF start_scroll_offset, - float start_page_scale_factor, - gfx::SizeF viewport_size, - gfx::SizeF root_layer_size, - double start_time) +PageScaleAnimation::PageScaleAnimation( + gfx::Vector2dF start_scroll_offset, + float start_page_scale_factor, + gfx::SizeF viewport_size, + gfx::SizeF root_layer_size, + double start_time, + scoped_ptr<TimingFunction> timing_function) : start_page_scale_factor_(start_page_scale_factor), target_page_scale_factor_(0.f), start_scroll_offset_(start_scroll_offset), @@ -65,7 +70,8 @@ PageScaleAnimation::PageScaleAnimation(gfx::Vector2dF start_scroll_offset, viewport_size_(viewport_size), root_layer_size_(root_layer_size), start_time_(start_time), - duration_(0.0) {} + duration_(0.0), + timing_function_(timing_function.Pass()) {} PageScaleAnimation::~PageScaleAnimation() {} @@ -176,7 +182,8 @@ float PageScaleAnimation::InterpAtTime(double time) const { if (IsAnimationCompleteAtTime(time)) return 1.f; - return (time - start_time_) / duration_; + const double normalized_time = (time - start_time_) / duration_; + return timing_function_->GetValue(normalized_time); } gfx::Vector2dF PageScaleAnimation::ScrollOffsetAt(float interp) const { diff --git a/cc/input/page_scale_animation.h b/cc/input/page_scale_animation.h index 09fbd15..b6d3510 100644 --- a/cc/input/page_scale_animation.h +++ b/cc/input/page_scale_animation.h @@ -11,11 +11,13 @@ #include "ui/gfx/vector2d_f.h" namespace cc { +class TimingFunction; // A small helper class that does the math for zoom animations, primarily for // double-tap zoom. Initialize it with starting and ending scroll/page scale // positions and an animation length time, then call ...AtTime() at every frame -// to obtain the current interpolated position. +// to obtain the current interpolated position. The supplied timing function +// is used to ease the animation. // // All sizes and vectors in this class's public methods are in the root scroll // layer's coordinate space. @@ -27,7 +29,8 @@ class PageScaleAnimation { float start_page_scale_factor, gfx::SizeF viewport_size, gfx::SizeF root_layer_size, - double start_time); + double start_time, + scoped_ptr<TimingFunction> timing_function); ~PageScaleAnimation(); @@ -66,7 +69,8 @@ class PageScaleAnimation { float start_page_scale_factor, gfx::SizeF viewport_size, gfx::SizeF root_layer_size, - double start_time); + double start_time, + scoped_ptr<TimingFunction> timing_function); private: void ClampTargetScrollOffset(); @@ -96,6 +100,8 @@ class PageScaleAnimation { double start_time_; double duration_; + scoped_ptr<TimingFunction> timing_function_; + DISALLOW_COPY_AND_ASSIGN(PageScaleAnimation); }; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 9505939..a966089 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -13,6 +13,7 @@ #include "base/stl_util.h" #include "base/stringprintf.h" #include "cc/animation/scrollbar_animation_controller.h" +#include "cc/animation/timing_function.h" #include "cc/base/math_util.h" #include "cc/base/util.h" #include "cc/debug/debug_rect_history.h" @@ -317,12 +318,18 @@ void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, gfx::SizeF viewport_size = VisibleViewportSize(); double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); + + // Easing constants experimentally determined. + scoped_ptr<TimingFunction> timing_function = + CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); + page_scale_animation_ = PageScaleAnimation::Create(scroll_total, active_tree_->total_page_scale_factor(), viewport_size, scaled_scrollable_size, - start_time_seconds); + start_time_seconds, + timing_function.Pass()); if (anchor_point) { gfx::Vector2dF anchor(target_offset); |