diff options
48 files changed, 734 insertions, 365 deletions
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc index 08a0ee9..04fff18 100644 --- a/cc/animation/layer_animation_controller.cc +++ b/cc/animation/layer_animation_controller.cc @@ -534,7 +534,7 @@ void LayerAnimationController::PushNewAnimationsToImplThread( // Scroll animations always start at the current scroll offset. if (animations_[i]->target_property() == Animation::ScrollOffset) { - gfx::Vector2dF current_scroll_offset; + gfx::ScrollOffset current_scroll_offset; if (controller_impl->value_provider_) { current_scroll_offset = controller_impl->value_provider_->ScrollOffsetForAnimation(); @@ -889,7 +889,7 @@ void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { case Animation::ScrollOffset: { const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = animations_[i]->curve()->ToScrollOffsetAnimationCurve(); - const gfx::Vector2dF scroll_offset = + const gfx::ScrollOffset scroll_offset = scroll_offset_animation_curve->GetValue(trimmed); NotifyObserversScrollOffsetAnimated( scroll_offset, @@ -977,7 +977,7 @@ void LayerAnimationController::NotifyObserversFilterAnimated( } void LayerAnimationController::NotifyObserversScrollOffsetAnimated( - const gfx::Vector2dF& scroll_offset, + const gfx::ScrollOffset& scroll_offset, bool notify_active_observers, bool notify_pending_observers) { if (value_observers_.might_have_observers()) { diff --git a/cc/animation/layer_animation_controller.h b/cc/animation/layer_animation_controller.h index dbb3239..4f56772 100644 --- a/cc/animation/layer_animation_controller.h +++ b/cc/animation/layer_animation_controller.h @@ -15,6 +15,7 @@ #include "cc/animation/layer_animation_event_observer.h" #include "cc/base/cc_export.h" #include "cc/base/scoped_ptr_vector.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/transform.h" namespace gfx { @@ -182,9 +183,10 @@ class CC_EXPORT LayerAnimationController void NotifyObserversFilterAnimated(const FilterOperations& filter, bool notify_active_observers, bool notify_pending_observers); - void NotifyObserversScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset, - bool notify_active_observers, - bool notify_pending_observers); + void NotifyObserversScrollOffsetAnimated( + const gfx::ScrollOffset& scroll_offset, + bool notify_active_observers, + bool notify_pending_observers); void NotifyObserversAnimationWaitingForDeletion(); diff --git a/cc/animation/layer_animation_controller_unittest.cc b/cc/animation/layer_animation_controller_unittest.cc index 5ecf857..34bdad0 100644 --- a/cc/animation/layer_animation_controller_unittest.cc +++ b/cc/animation/layer_animation_controller_unittest.cc @@ -663,8 +663,8 @@ TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { controller->AddValueObserver(&dummy); controller->set_value_provider(&dummy_provider); - gfx::Vector2dF initial_value(100.f, 300.f); - gfx::Vector2dF target_value(300.f, 200.f); + gfx::ScrollOffset initial_value(100.f, 300.f); + gfx::ScrollOffset target_value(300.f, 200.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, @@ -745,8 +745,8 @@ TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { controller->AddValueObserver(&dummy); controller->set_value_provider(&dummy_provider); - gfx::Vector2dF initial_value(500.f, 100.f); - gfx::Vector2dF target_value(300.f, 200.f); + gfx::ScrollOffset initial_value(500.f, 100.f); + gfx::ScrollOffset target_value(300.f, 200.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, @@ -819,8 +819,8 @@ TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { scoped_ptr<AnimationEventsVector> events( make_scoped_ptr(new AnimationEventsVector)); - gfx::Vector2dF initial_value(100.f, 300.f); - gfx::Vector2dF target_value(300.f, 200.f); + gfx::ScrollOffset initial_value(100.f, 300.f); + gfx::ScrollOffset target_value(300.f, 200.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, diff --git a/cc/animation/layer_animation_value_observer.h b/cc/animation/layer_animation_value_observer.h index e091806..420317e 100644 --- a/cc/animation/layer_animation_value_observer.h +++ b/cc/animation/layer_animation_value_observer.h @@ -9,6 +9,8 @@ namespace cc { +class ScrollOffset; + class CC_EXPORT LayerAnimationValueObserver { public: virtual ~LayerAnimationValueObserver() {} @@ -16,7 +18,8 @@ class CC_EXPORT LayerAnimationValueObserver { virtual void OnFilterAnimated(const FilterOperations& filters) = 0; virtual void OnOpacityAnimated(float opacity) = 0; virtual void OnTransformAnimated(const gfx::Transform& transform) = 0; - virtual void OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) = 0; + virtual void OnScrollOffsetAnimated( + const gfx::ScrollOffset& scroll_offset) = 0; virtual void OnAnimationWaitingForDeletion() = 0; virtual bool IsActive() const = 0; }; @@ -24,4 +27,3 @@ class CC_EXPORT LayerAnimationValueObserver { } // namespace cc #endif // CC_ANIMATION_LAYER_ANIMATION_VALUE_OBSERVER_H_ - diff --git a/cc/animation/layer_animation_value_provider.h b/cc/animation/layer_animation_value_provider.h index c814968..9070838 100644 --- a/cc/animation/layer_animation_value_provider.h +++ b/cc/animation/layer_animation_value_provider.h @@ -6,10 +6,11 @@ #define CC_ANIMATION_LAYER_ANIMATION_VALUE_PROVIDER_H_ #include "cc/base/cc_export.h" -#include "ui/gfx/vector2d_f.h" namespace cc { +class ScrollOffset; + // A LayerAnimationValueProvider is used for determining the starting value // for animations that start at their 'current' value rather than at a // pre-specified value. @@ -17,7 +18,7 @@ class CC_EXPORT LayerAnimationValueProvider { public: virtual ~LayerAnimationValueProvider() {} - virtual gfx::Vector2dF ScrollOffsetForAnimation() const = 0; + virtual gfx::ScrollOffset ScrollOffsetForAnimation() const = 0; }; } // namespace cc diff --git a/cc/animation/scroll_offset_animation_curve.cc b/cc/animation/scroll_offset_animation_curve.cc index 5d51621..641c9e0 100644 --- a/cc/animation/scroll_offset_animation_curve.cc +++ b/cc/animation/scroll_offset_animation_curve.cc @@ -44,14 +44,14 @@ static scoped_ptr<TimingFunction> EaseOutWithInitialVelocity(double velocity) { } // namespace scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( - const gfx::Vector2dF& target_value, + const gfx::ScrollOffset& target_value, scoped_ptr<TimingFunction> timing_function) { return make_scoped_ptr( new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); } ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( - const gfx::Vector2dF& target_value, + const gfx::ScrollOffset& target_value, scoped_ptr<TimingFunction> timing_function) : target_value_(target_value), timing_function_(timing_function.Pass()) { } @@ -59,12 +59,13 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} void ScrollOffsetAnimationCurve::SetInitialValue( - const gfx::Vector2dF& initial_value) { + const gfx::ScrollOffset& initial_value) { initial_value_ = initial_value; - total_animation_duration_ = DurationFromDelta(target_value_ - initial_value_); + total_animation_duration_ = DurationFromDelta( + target_value_.DeltaFrom(initial_value_)); } -gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { +gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(double t) const { double duration = (total_animation_duration_ - last_retarget_).InSecondsF(); t -= last_retarget_.InSecondsF(); @@ -75,10 +76,11 @@ gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { return target_value_; double progress = (timing_function_->GetValue(t / duration)); - return gfx::Vector2dF(gfx::Tween::FloatValueBetween( - progress, initial_value_.x(), target_value_.x()), - gfx::Tween::FloatValueBetween( - progress, initial_value_.y(), target_value_.y())); + return gfx::ScrollOffset( + gfx::Tween::FloatValueBetween( + progress, initial_value_.x(), target_value_.x()), + gfx::Tween::FloatValueBetween( + progress, initial_value_.y(), target_value_.y())); } double ScrollOffsetAnimationCurve::Duration() const { @@ -102,10 +104,10 @@ scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { void ScrollOffsetAnimationCurve::UpdateTarget( double t, - const gfx::Vector2dF& new_target) { - gfx::Vector2dF current_position = GetValue(t); - gfx::Vector2dF old_delta = target_value_ - initial_value_; - gfx::Vector2dF new_delta = new_target - current_position; + const gfx::ScrollOffset& new_target) { + gfx::ScrollOffset current_position = GetValue(t); + gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); + gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position); double old_duration = (total_animation_duration_ - last_retarget_).InSecondsF(); diff --git a/cc/animation/scroll_offset_animation_curve.h b/cc/animation/scroll_offset_animation_curve.h index 3d71e13..452da27 100644 --- a/cc/animation/scroll_offset_animation_curve.h +++ b/cc/animation/scroll_offset_animation_curve.h @@ -9,6 +9,7 @@ #include "base/time/time.h" #include "cc/animation/animation_curve.h" #include "cc/base/cc_export.h" +#include "ui/gfx/geometry/scroll_offset.h" namespace cc { @@ -17,15 +18,15 @@ class TimingFunction; class CC_EXPORT ScrollOffsetAnimationCurve : public AnimationCurve { public: static scoped_ptr<ScrollOffsetAnimationCurve> Create( - const gfx::Vector2dF& target_value, + const gfx::ScrollOffset& target_value, scoped_ptr<TimingFunction> timing_function); virtual ~ScrollOffsetAnimationCurve(); - void SetInitialValue(const gfx::Vector2dF& initial_value); - gfx::Vector2dF GetValue(double t) const; - gfx::Vector2dF target_value() const { return target_value_; } - void UpdateTarget(double t, const gfx::Vector2dF& new_target); + void SetInitialValue(const gfx::ScrollOffset& initial_value); + gfx::ScrollOffset GetValue(double t) const; + gfx::ScrollOffset target_value() const { return target_value_; } + void UpdateTarget(double t, const gfx::ScrollOffset& new_target); // AnimationCurve implementation virtual double Duration() const OVERRIDE; @@ -33,11 +34,11 @@ class CC_EXPORT ScrollOffsetAnimationCurve : public AnimationCurve { virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; private: - ScrollOffsetAnimationCurve(const gfx::Vector2dF& target_value, + ScrollOffsetAnimationCurve(const gfx::ScrollOffset& target_value, scoped_ptr <TimingFunction> timing_function); - gfx::Vector2dF initial_value_; - gfx::Vector2dF target_value_; + gfx::ScrollOffset initial_value_; + gfx::ScrollOffset target_value_; base::TimeDelta total_animation_duration_; // Time from animation start to most recent UpdateTarget. diff --git a/cc/animation/scroll_offset_animation_curve_unittest.cc b/cc/animation/scroll_offset_animation_curve_unittest.cc index 1b8fdb5..d89784a0 100644 --- a/cc/animation/scroll_offset_animation_curve_unittest.cc +++ b/cc/animation/scroll_offset_animation_curve_unittest.cc @@ -12,7 +12,7 @@ namespace cc { namespace { TEST(ScrollOffsetAnimationCurveTest, Duration) { - gfx::Vector2dF target_value(100.f, 200.f); + gfx::ScrollOffset target_value(100.f, 200.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, @@ -22,41 +22,41 @@ TEST(ScrollOffsetAnimationCurveTest, Duration) { EXPECT_DOUBLE_EQ(0.0, curve->Duration()); // x decreases, y stays the same. - curve->SetInitialValue(gfx::Vector2dF(136.f, 200.f)); + curve->SetInitialValue(gfx::ScrollOffset(136.f, 200.f)); EXPECT_DOUBLE_EQ(0.1, curve->Duration()); // x increases, y stays the same. - curve->SetInitialValue(gfx::Vector2dF(19.f, 200.f)); + curve->SetInitialValue(gfx::ScrollOffset(19.f, 200.f)); EXPECT_DOUBLE_EQ(0.15, curve->Duration()); // x stays the same, y decreases. - curve->SetInitialValue(gfx::Vector2dF(100.f, 344.f)); + curve->SetInitialValue(gfx::ScrollOffset(100.f, 344.f)); EXPECT_DOUBLE_EQ(0.2, curve->Duration()); // x stays the same, y increases. - curve->SetInitialValue(gfx::Vector2dF(100.f, 191.f)); + curve->SetInitialValue(gfx::ScrollOffset(100.f, 191.f)); EXPECT_DOUBLE_EQ(0.05, curve->Duration()); // x decreases, y decreases. - curve->SetInitialValue(gfx::Vector2dF(32500.f, 500.f)); + curve->SetInitialValue(gfx::ScrollOffset(32500.f, 500.f)); EXPECT_DOUBLE_EQ(3.0, curve->Duration()); // x decreases, y increases. - curve->SetInitialValue(gfx::Vector2dF(150.f, 119.f)); + curve->SetInitialValue(gfx::ScrollOffset(150.f, 119.f)); EXPECT_DOUBLE_EQ(0.15, curve->Duration()); // x increases, y decreases. - curve->SetInitialValue(gfx::Vector2dF(0.f, 14600.f)); + curve->SetInitialValue(gfx::ScrollOffset(0.f, 14600.f)); EXPECT_DOUBLE_EQ(2.0, curve->Duration()); // x increases, y increases. - curve->SetInitialValue(gfx::Vector2dF(95.f, 191.f)); + curve->SetInitialValue(gfx::ScrollOffset(95.f, 191.f)); EXPECT_DOUBLE_EQ(0.05, curve->Duration()); } TEST(ScrollOffsetAnimationCurveTest, GetValue) { - gfx::Vector2dF initial_value(2.f, 40.f); - gfx::Vector2dF target_value(10.f, 20.f); + gfx::ScrollOffset initial_value(2.f, 40.f); + gfx::ScrollOffset target_value(10.f, 20.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, @@ -72,20 +72,21 @@ TEST(ScrollOffsetAnimationCurveTest, GetValue) { EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0)); EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0)); - EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(6.f, 30.f), curve->GetValue(duration/2.0)); + EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f), + curve->GetValue(duration/2.0)); EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration)); EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration+1.0)); // Verify that GetValue takes the timing function into account. - gfx::Vector2dF value = curve->GetValue(duration/4.0); + gfx::ScrollOffset value = curve->GetValue(duration/4.0); EXPECT_NEAR(3.0333f, value.x(), 0.00015f); EXPECT_NEAR(37.4168f, value.y(), 0.00015f); } // Verify that a clone behaves exactly like the original. TEST(ScrollOffsetAnimationCurveTest, Clone) { - gfx::Vector2dF initial_value(2.f, 40.f); - gfx::Vector2dF target_value(10.f, 20.f); + gfx::ScrollOffset initial_value(2.f, 40.f); + gfx::ScrollOffset target_value(10.f, 20.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, @@ -103,7 +104,7 @@ TEST(ScrollOffsetAnimationCurveTest, Clone) { EXPECT_VECTOR2DF_EQ(initial_value, clone->ToScrollOffsetAnimationCurve()->GetValue(0.0)); EXPECT_VECTOR2DF_EQ( - gfx::Vector2dF(6.f, 30.f), + gfx::ScrollOffset(6.f, 30.f), clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 2.0)); EXPECT_VECTOR2DF_EQ( target_value, @@ -113,15 +114,15 @@ TEST(ScrollOffsetAnimationCurveTest, Clone) { clone->ToScrollOffsetAnimationCurve()->GetValue(duration + 1.0)); // Verify that the timing function was cloned correctly. - gfx::Vector2dF value = + gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 4.0); EXPECT_NEAR(3.0333f, value.x(), 0.00015f); EXPECT_NEAR(37.4168f, value.y(), 0.00015f); } TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { - gfx::Vector2dF initial_value(0.f, 0.f); - gfx::Vector2dF target_value(0.f, 3600.f); + gfx::ScrollOffset initial_value(0.f, 0.f); + gfx::ScrollOffset target_value(0.f, 3600.f); scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( target_value, EaseInOutTimingFunction::Create().Pass())); @@ -130,14 +131,14 @@ TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); EXPECT_EQ(3600.0, curve->GetValue(1.0).y()); - curve->UpdateTarget(0.5, gfx::Vector2dF(0.0, 9900.0)); + curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0)); EXPECT_EQ(2.0, curve->Duration()); EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); EXPECT_EQ(9900.0, curve->GetValue(2.0).y()); - curve->UpdateTarget(1.0, gfx::Vector2dF(0.0, 7200.0)); + curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0)); EXPECT_NEAR(1.674, curve->Duration(), 0.01); EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index 7ed0c9a..5df1e56 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -778,6 +778,12 @@ void MathUtil::AddToTracedValue(const gfx::Vector2dF& v, res->AppendDouble(v.y()); } +void MathUtil::AddToTracedValue(const gfx::ScrollOffset& v, + base::debug::TracedValue* res) { + res->AppendDouble(v.x()); + res->AppendDouble(v.y()); +} + void MathUtil::AddToTracedValue(const gfx::QuadF& q, base::debug::TracedValue* res) { res->AppendDouble(q.p1().x()); diff --git a/cc/base/math_util.h b/cc/base/math_util.h index eaaf924..622ea4d 100644 --- a/cc/base/math_util.h +++ b/cc/base/math_util.h @@ -13,6 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "ui/gfx/box_f.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/point3_f.h" #include "ui/gfx/point_f.h" #include "ui/gfx/size.h" @@ -212,6 +213,8 @@ class CC_EXPORT MathUtil { base::debug::TracedValue* res); static void AddToTracedValue(const gfx::Vector2dF& v, base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::ScrollOffset& v, + base::debug::TracedValue* res); static void AddToTracedValue(const gfx::QuadF& q, base::debug::TracedValue* res); static void AddToTracedValue(const gfx::RectF& rect, diff --git a/cc/blink/web_layer_impl.cc b/cc/blink/web_layer_impl.cc index c1f67fb..ddbad41 100644 --- a/cc/blink/web_layer_impl.cc +++ b/cc/blink/web_layer_impl.cc @@ -27,6 +27,7 @@ #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" #include "third_party/WebKit/public/platform/WebSize.h" #include "third_party/skia/include/utils/SkMatrix44.h" +#include "ui/gfx/geometry/vector2d_conversions.h" using cc::Animation; using cc::Layer; @@ -268,11 +269,12 @@ void WebLayerImpl::setForceRenderSurface(bool force_render_surface) { } void WebLayerImpl::setScrollPosition(blink::WebPoint position) { - layer_->SetScrollOffset(gfx::Point(position).OffsetFromOrigin()); + layer_->SetScrollOffset(gfx::ScrollOffset(position.x, position.y)); } blink::WebPoint WebLayerImpl::scrollPosition() const { - return gfx::PointAtOffsetFromOrigin(layer_->scroll_offset()); + return gfx::PointAtOffsetFromOrigin( + gfx::ScrollOffsetToFlooredVector2d(layer_->scroll_offset())); } void WebLayerImpl::setScrollClipLayer(WebLayer* clip_layer) { diff --git a/cc/blink/web_scroll_offset_animation_curve_impl.cc b/cc/blink/web_scroll_offset_animation_curve_impl.cc index e1f1bfd..e789631 100644 --- a/cc/blink/web_scroll_offset_animation_curve_impl.cc +++ b/cc/blink/web_scroll_offset_animation_curve_impl.cc @@ -16,7 +16,7 @@ WebScrollOffsetAnimationCurveImpl::WebScrollOffsetAnimationCurveImpl( WebFloatPoint target_value, TimingFunctionType timing_function) : curve_(cc::ScrollOffsetAnimationCurve::Create( - gfx::Vector2dF(target_value.x, target_value.y), + gfx::ScrollOffset(target_value.x, target_value.y), CreateTimingFunction(timing_function))) { } @@ -30,11 +30,11 @@ WebScrollOffsetAnimationCurveImpl::type() const { void WebScrollOffsetAnimationCurveImpl::setInitialValue( WebFloatPoint initial_value) { - curve_->SetInitialValue(gfx::Vector2dF(initial_value.x, initial_value.y)); + curve_->SetInitialValue(gfx::ScrollOffset(initial_value.x, initial_value.y)); } WebFloatPoint WebScrollOffsetAnimationCurveImpl::getValue(double time) const { - gfx::Vector2dF value = curve_->GetValue(time); + gfx::ScrollOffset value = curve_->GetValue(time); return WebFloatPoint(value.x(), value.y()); } diff --git a/cc/input/layer_scroll_offset_delegate.h b/cc/input/layer_scroll_offset_delegate.h index ba11c38..f7ca485 100644 --- a/cc/input/layer_scroll_offset_delegate.h +++ b/cc/input/layer_scroll_offset_delegate.h @@ -6,8 +6,8 @@ #define CC_INPUT_LAYER_SCROLL_OFFSET_DELEGATE_H_ #include "base/basictypes.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/size_f.h" -#include "ui/gfx/vector2d_f.h" namespace cc { @@ -24,7 +24,7 @@ class LayerScrollOffsetDelegate { // The return value is not required to be related to the values passed in to // the SetTotalScrollOffset method in any way however it is required to be no // more than the value passed to the most recent SetMaxScrollOffset call. - virtual gfx::Vector2dF GetTotalScrollOffset() = 0; + virtual gfx::ScrollOffset GetTotalScrollOffset() = 0; // This is called by the compositor to notify the delegate of any change to // the following parameters: @@ -34,12 +34,13 @@ class LayerScrollOffsetDelegate { // |page_scale_factor| current page scale, // |min_page_scale_factor| page scale lower limit, // |max_page_scale_factor| page scale upper limit. - virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, - const gfx::Vector2dF& max_scroll_offset, - const gfx::SizeF& scrollable_size, - float page_scale_factor, - float min_page_scale_factor, - float max_page_scale_factor) = 0; + virtual void UpdateRootLayerState( + const gfx::ScrollOffset& total_scroll_offset, + const gfx::ScrollOffset& max_scroll_offset, + const gfx::SizeF& scrollable_size, + float page_scale_factor, + float min_page_scale_factor, + float max_page_scale_factor) = 0; // This is called by the compositor to check whether a delegate-managed fling // is active or not. diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc index 1326b79..08bf345 100644 --- a/cc/layers/layer.cc +++ b/cc/layers/layer.cc @@ -654,7 +654,7 @@ void Layer::RemoveClipChild(Layer* child) { SetNeedsCommit(); } -void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { +void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { DCHECK(IsPropertyChangeAllowed()); if (scroll_offset_ == scroll_offset) @@ -663,7 +663,8 @@ void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { SetNeedsCommit(); } -void Layer::SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset) { +void Layer::SetScrollOffsetFromImplSide( + const gfx::ScrollOffset& scroll_offset) { DCHECK(IsPropertyChangeAllowed()); // This function only gets called during a BeginMainFrame, so there // is no need to call SetNeedsUpdate here. @@ -963,8 +964,9 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetScrollOffset(scroll_offset_); } else { layer->SetScrollOffsetAndDelta( - scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); - layer->SetSentScrollDelta(gfx::Vector2d()); + scroll_offset_, + layer->ScrollDelta() - layer->sent_scroll_delta()); + layer->SetSentScrollDelta(gfx::Vector2dF()); } // Wrap the copy_requests_ in a PostTask to the main thread. @@ -1093,7 +1095,7 @@ void Layer::ClearRenderSurfaceLayerList() { draw_properties_.render_surface->layer_list().clear(); } -gfx::Vector2dF Layer::ScrollOffsetForAnimation() const { +gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const { return TotalScrollOffset(); } @@ -1116,7 +1118,7 @@ void Layer::OnTransformAnimated(const gfx::Transform& transform) { transform_is_invertible_ = transform.IsInvertible(); } -void Layer::OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) { +void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { // Do nothing. Scroll deltas will be sent from the compositor thread back // to the main thread in the same manner as during non-animated // compositor-driven scrolling. diff --git a/cc/layers/layer.h b/cc/layers/layer.h index 3452e8b..a627140 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -29,6 +29,7 @@ #include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkXfermode.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/point3_f.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_f.h" @@ -261,9 +262,9 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, return draw_properties_.num_unclipped_descendants; } - void SetScrollOffset(gfx::Vector2d scroll_offset); - gfx::Vector2d scroll_offset() const { return scroll_offset_; } - void SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset); + void SetScrollOffset(const gfx::ScrollOffset& scroll_offset); + gfx::ScrollOffset scroll_offset() const { return scroll_offset_; } + void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset); void SetScrollClipLayerId(int clip_layer_id); bool scrollable() const { return scroll_clip_layer_id_ != INVALID_ID; } @@ -309,10 +310,9 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, void SetForceRenderSurface(bool force_render_surface); bool force_render_surface() const { return force_render_surface_; } - gfx::Vector2d ScrollDelta() const { return gfx::Vector2d(); } - gfx::Vector2dF TotalScrollOffset() const { - // Floating point to match the LayerImpl version. - return scroll_offset() + ScrollDelta(); + gfx::Vector2dF ScrollDelta() const { return gfx::Vector2dF(); } + gfx::ScrollOffset TotalScrollOffset() const { + return ScrollOffsetWithDelta(scroll_offset(), ScrollDelta()); } void SetDoubleSided(bool double_sided); @@ -552,14 +552,14 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, void RemoveChildOrDependent(Layer* child); // LayerAnimationValueProvider implementation. - virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE; + virtual gfx::ScrollOffset ScrollOffsetForAnimation() const OVERRIDE; // LayerAnimationValueObserver implementation. virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE; virtual void OnOpacityAnimated(float opacity) OVERRIDE; virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE; virtual void OnScrollOffsetAnimated( - const gfx::Vector2dF& scroll_offset) OVERRIDE; + const gfx::ScrollOffset& scroll_offset) OVERRIDE; virtual void OnAnimationWaitingForDeletion() OVERRIDE; virtual bool IsActive() const OVERRIDE; @@ -584,7 +584,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, // Layer properties. gfx::Size bounds_; - gfx::Vector2d scroll_offset_; + gfx::ScrollOffset scroll_offset_; // This variable indicates which ancestor layer (if any) whose size, // transformed relative to this layer, defines the maximum scroll offset for // this layer. diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc index 224513c..3e0e009 100644 --- a/cc/layers/layer_impl.cc +++ b/cc/layers/layer_impl.cc @@ -354,7 +354,7 @@ ResourceProvider::ResourceId LayerImpl::ContentsResourceId() const { return 0; } -void LayerImpl::SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta) { +void LayerImpl::SetSentScrollDelta(const gfx::Vector2dF& sent_scroll_delta) { // Pending tree never has sent scroll deltas DCHECK(layer_tree_impl()->IsActiveTree()); @@ -366,8 +366,8 @@ void LayerImpl::SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta) { gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { DCHECK(scrollable()); - gfx::Vector2dF min_delta = -scroll_offset_; - gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_; + gfx::Vector2dF min_delta = -ScrollOffsetToVector2dF(scroll_offset_); + gfx::Vector2dF max_delta = MaxScrollOffset().DeltaFrom(scroll_offset_); // Clamp new_delta so that position + delta stays within scroll bounds. gfx::Vector2dF new_delta = (ScrollDelta() + scroll); new_delta.SetToMax(min_delta); @@ -398,9 +398,9 @@ void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { // Because of the way scroll delta is calculated with a delegate, this will // leave the total scroll offset unchanged on this layer regardless of // whether a delegate is being used. - scroll_offset_ += sent_scroll_delta_; + scroll_offset_ += gfx::ScrollOffset(sent_scroll_delta_); scroll_delta_ -= sent_scroll_delta_; - sent_scroll_delta_ = gfx::Vector2d(); + sent_scroll_delta_ = gfx::Vector2dF(); } void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() { @@ -472,7 +472,7 @@ InputHandler::ScrollStatus LayerImpl::TryScroll( return InputHandler::ScrollIgnored; } - gfx::Vector2d max_scroll_offset = MaxScrollOffset(); + gfx::ScrollOffset max_scroll_offset = MaxScrollOffset(); if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored. Technically scrollable," @@ -538,8 +538,9 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); layer->set_user_scrollable_vertical(user_scrollable_vertical_); layer->SetScrollOffsetAndDelta( - scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); - layer->SetSentScrollDelta(gfx::Vector2d()); + scroll_offset_, + layer->ScrollDelta() - layer->sent_scroll_delta()); + layer->SetSentScrollDelta(gfx::Vector2dF()); layer->Set3dSortingContextId(sorting_context_id_); layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); @@ -736,7 +737,7 @@ void LayerImpl::ResetAllChangeTrackingForSubtree() { num_dependents_need_push_properties_ = 0; } -gfx::Vector2dF LayerImpl::ScrollOffsetForAnimation() const { +gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { return TotalScrollOffset(); } @@ -752,14 +753,14 @@ void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { SetTransform(transform); } -void LayerImpl::OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) { +void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { // Only layers in the active tree should need to do anything here, since // layers in the pending tree will find out about these changes as a // result of the call to SetScrollDelta. if (!IsActive()) return; - SetScrollDelta(scroll_offset - scroll_offset_); + SetScrollDelta(scroll_offset.DeltaFrom(scroll_offset_)); layer_tree_impl_->DidAnimateScrollOffset(); } @@ -1064,10 +1065,10 @@ void LayerImpl::SetScrollOffsetDelegate( // Having both a scroll parent and a scroll offset delegate is unsupported. DCHECK(!scroll_parent_); if (!scroll_offset_delegate && scroll_offset_delegate_) { - scroll_delta_ = - scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; + scroll_delta_ = scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom( + scroll_offset_); } - gfx::Vector2dF total_offset = TotalScrollOffset(); + gfx::ScrollOffset total_offset = TotalScrollOffset(); scroll_offset_delegate_ = scroll_offset_delegate; if (scroll_offset_delegate_) scroll_offset_delegate_->SetTotalScrollOffset(total_offset); @@ -1078,11 +1079,11 @@ bool LayerImpl::IsExternalFlingActive() const { scroll_offset_delegate_->IsExternalFlingActive(); } -void LayerImpl::SetScrollOffset(const gfx::Vector2d& scroll_offset) { +void LayerImpl::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); } -void LayerImpl::SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, +void LayerImpl::SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset, const gfx::Vector2dF& scroll_delta) { bool changed = false; @@ -1113,8 +1114,8 @@ void LayerImpl::SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, } if (scroll_offset_delegate_) { - scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + - scroll_delta); + scroll_offset_delegate_->SetTotalScrollOffset( + ScrollOffsetWithDelta(scroll_offset_, scroll_delta)); } else { scroll_delta_ = scroll_delta; } @@ -1127,8 +1128,10 @@ void LayerImpl::SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, } gfx::Vector2dF LayerImpl::ScrollDelta() const { - if (scroll_offset_delegate_) - return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; + if (scroll_offset_delegate_) { + return scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom( + scroll_offset_); + } return scroll_delta_; } @@ -1136,8 +1139,8 @@ void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { SetScrollOffsetAndDelta(scroll_offset_, scroll_delta); } -gfx::Vector2dF LayerImpl::TotalScrollOffset() const { - return scroll_offset_ + ScrollDelta(); +gfx::ScrollOffset LayerImpl::TotalScrollOffset() const { + return ScrollOffsetWithDelta(scroll_offset_, ScrollDelta()); } void LayerImpl::SetDoubleSided(bool double_sided) { @@ -1158,9 +1161,9 @@ void LayerImpl::DidBeginTracing() {} void LayerImpl::ReleaseResources() {} -gfx::Vector2d LayerImpl::MaxScrollOffset() const { +gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { if (!scroll_clip_layer_ || bounds().IsEmpty()) - return gfx::Vector2d(); + return gfx::ScrollOffset(); LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); DCHECK(this != page_scale_layer); @@ -1202,23 +1205,23 @@ gfx::Vector2d LayerImpl::MaxScrollOffset() const { scale_factor * scaled_scroll_bounds.height()); scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); - gfx::Vector2dF max_offset( + gfx::ScrollOffset max_offset( scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); // We need the final scroll offset to be in CSS coords. max_offset.Scale(1 / scale_factor); - max_offset.SetToMax(gfx::Vector2dF()); - return gfx::ToFlooredVector2d(max_offset); + max_offset.SetToMax(gfx::ScrollOffset()); + return max_offset; } gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { - gfx::Vector2dF max_offset = MaxScrollOffset(); - gfx::Vector2dF old_offset = TotalScrollOffset(); - gfx::Vector2dF clamped_offset = old_offset; + gfx::ScrollOffset max_offset = MaxScrollOffset(); + gfx::ScrollOffset old_offset = TotalScrollOffset(); + gfx::ScrollOffset clamped_offset = old_offset; clamped_offset.SetToMin(max_offset); - clamped_offset.SetToMax(gfx::Vector2d()); - gfx::Vector2dF delta = clamped_offset - old_offset; + clamped_offset.SetToMax(gfx::ScrollOffset()); + gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); if (!delta.IsZero()) ScrollBy(delta); @@ -1245,7 +1248,7 @@ void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, // TODO(wjmaclean) This computation is nearly identical to the one in // MaxScrollOffset. Find some way to combine these. - gfx::Vector2dF current_offset; + gfx::ScrollOffset current_offset; for (LayerImpl const* current_layer = this; current_layer != scrollbar_clip_layer; current_layer = current_layer->parent()) { @@ -1260,8 +1263,8 @@ void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, DCHECK(layer_transform.IsScale2d()); gfx::Vector2dF layer_scale = layer_transform.Scale2d(); DCHECK(layer_scale.x() == layer_scale.y()); - gfx::Vector2dF new_offset = - current_layer->scroll_offset() + current_layer->ScrollDelta(); + gfx::ScrollOffset new_offset = ScrollOffsetWithDelta( + current_layer->scroll_offset(), current_layer->ScrollDelta()); new_offset.Scale(layer_scale.x(), layer_scale.y()); current_offset += new_offset; } diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h index d3aa8b0..fc7f1c6 100644 --- a/cc/layers/layer_impl.h +++ b/cc/layers/layer_impl.h @@ -30,6 +30,7 @@ #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkPicture.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/point3_f.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_f.h" @@ -77,8 +78,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // of the layer. class ScrollOffsetDelegate { public: - virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) = 0; - virtual gfx::Vector2dF GetTotalScrollOffset() = 0; + virtual void SetTotalScrollOffset(const gfx::ScrollOffset& new_value) = 0; + virtual gfx::ScrollOffset GetTotalScrollOffset() = 0; virtual bool IsExternalFlingActive() const = 0; }; @@ -97,14 +98,14 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, int id() const { return layer_id_; } // LayerAnimationValueProvider implementation. - virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE; + virtual gfx::ScrollOffset ScrollOffsetForAnimation() const OVERRIDE; // LayerAnimationValueObserver implementation. virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE; virtual void OnOpacityAnimated(float opacity) OVERRIDE; virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE; virtual void OnScrollOffsetAnimated( - const gfx::Vector2dF& scroll_offset) OVERRIDE; + const gfx::ScrollOffset& scroll_offset) OVERRIDE; virtual void OnAnimationWaitingForDeletion() OVERRIDE; virtual bool IsActive() const OVERRIDE; @@ -377,22 +378,22 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate); bool IsExternalFlingActive() const; - void SetScrollOffset(const gfx::Vector2d& scroll_offset); - void SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, + void SetScrollOffset(const gfx::ScrollOffset& scroll_offset); + void SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset, const gfx::Vector2dF& scroll_delta); - gfx::Vector2d scroll_offset() const { return scroll_offset_; } + gfx::ScrollOffset scroll_offset() const { return scroll_offset_; } - gfx::Vector2d MaxScrollOffset() const; + gfx::ScrollOffset MaxScrollOffset() const; gfx::Vector2dF ClampScrollToMaxScrollOffset(); void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, LayerImpl* scrollbar_clip_layer) const; void SetScrollDelta(const gfx::Vector2dF& scroll_delta); gfx::Vector2dF ScrollDelta() const; - gfx::Vector2dF TotalScrollOffset() const; + gfx::ScrollOffset TotalScrollOffset() const; - void SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta); - gfx::Vector2d sent_scroll_delta() const { return sent_scroll_delta_; } + void SetSentScrollDelta(const gfx::Vector2dF& sent_scroll_delta); + gfx::Vector2dF sent_scroll_delta() const { return sent_scroll_delta_; } // Returns the delta of the scroll that was outside of the bounds of the // initial scroll @@ -607,7 +608,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, gfx::Point3F transform_origin_; gfx::Size bounds_; gfx::Vector2dF bounds_delta_; - gfx::Vector2d scroll_offset_; + gfx::ScrollOffset scroll_offset_; ScrollOffsetDelegate* scroll_offset_delegate_; LayerImpl* scroll_clip_layer_; bool scrollable_ : 1; @@ -650,8 +651,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, LayerPositionConstraint position_constraint_; gfx::Vector2dF scroll_delta_; - gfx::Vector2d sent_scroll_delta_; - gfx::Vector2dF last_scroll_offset_; + gfx::Vector2dF sent_scroll_delta_; + gfx::ScrollOffset last_scroll_offset_; int num_descendants_that_draw_content_; diff --git a/cc/layers/layer_impl_unittest.cc b/cc/layers/layer_impl_unittest.cc index b9366ac..dc046a0 100644 --- a/cc/layers/layer_impl_unittest.cc +++ b/cc/layers/layer_impl_unittest.cc @@ -160,7 +160,8 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { root->SetDoubleSided(false)); // constructor initializes it to "true". EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d())); - EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollOffset(arbitrary_vector2d)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED( + root->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d))); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); @@ -219,7 +220,7 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( root->SetScrollDelta(gfx::Vector2d())); EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( - root->SetScrollOffset(arbitrary_vector2d)); + root->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d))); EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( root->SetContentBounds(arbitrary_size)); EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( @@ -291,9 +292,9 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( layer->SetScrollDelta(arbitrary_vector2d)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( - layer->SetScrollOffset(arbitrary_vector2d)); + layer->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d))); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( - layer->SetScrollOffset(arbitrary_vector2d)); + layer->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d))); // Unrelated functions, always set to new values, always set needs update. VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( @@ -464,7 +465,7 @@ TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { } TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); layer()->SetScrollOffset(scroll_offset); EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); @@ -474,23 +475,26 @@ TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) { layer()->ScrollBy(gfx::Vector2dF(-100, 100)); EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); - EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, + layer()->ScrollDelta()), layer()->TotalScrollOffset()); EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); layer()->ScrollBy(gfx::Vector2dF(100, -100)); EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset()); - EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, + layer()->ScrollDelta()), layer()->TotalScrollOffset()); EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); } class ScrollDelegateIgnore : public LayerImpl::ScrollOffsetDelegate { public: - virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE {} - virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { - return fixed_offset_; + virtual void SetTotalScrollOffset( + const gfx::ScrollOffset& new_value) OVERRIDE {} + virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE { + return gfx::ScrollOffset(fixed_offset_); } virtual bool IsExternalFlingActive() const OVERRIDE { return false; } @@ -503,7 +507,7 @@ class ScrollDelegateIgnore : public LayerImpl::ScrollOffsetDelegate { }; TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); layer()->SetScrollOffset(scroll_offset); EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); @@ -537,20 +541,21 @@ TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) { class ScrollDelegateAccept : public LayerImpl::ScrollOffsetDelegate { public: - virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE { + virtual void SetTotalScrollOffset( + const gfx::ScrollOffset& new_value) OVERRIDE { current_offset_ = new_value; } - virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { + virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE { return current_offset_; } virtual bool IsExternalFlingActive() const OVERRIDE { return false; } private: - gfx::Vector2dF current_offset_; + gfx::ScrollOffset current_offset_; }; TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); layer()->SetScrollOffset(scroll_offset); EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); @@ -582,7 +587,7 @@ TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) { } TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); gfx::Vector2dF scroll_delta(20.5f, 8.5f); gfx::Vector2d sent_scroll_delta(12, -3); @@ -590,21 +595,24 @@ TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) { layer()->ScrollBy(scroll_delta); layer()->SetSentScrollDelta(sent_scroll_delta); - EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta), + layer()->TotalScrollOffset()); EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta()); EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); layer()->ApplySentScrollDeltasFromAbortedCommit(); - EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta), + layer()->TotalScrollOffset()); EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta()); - EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta), + layer()->scroll_offset()); EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); } TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); gfx::Vector2d sent_scroll_delta(12, -3); gfx::Vector2dF fixed_offset(32, 12); @@ -621,12 +629,13 @@ TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) { layer()->ApplySentScrollDeltasFromAbortedCommit(); EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); - EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta), + layer()->scroll_offset()); EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); } TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); gfx::Vector2d sent_scroll_delta(12, -3); gfx::Vector2dF scroll_delta(20.5f, 8.5f); @@ -636,21 +645,24 @@ TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) { layer()->ScrollBy(scroll_delta); layer()->SetSentScrollDelta(sent_scroll_delta); - EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta), + layer()->TotalScrollOffset()); EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); layer()->ApplySentScrollDeltasFromAbortedCommit(); - EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); - EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta), + layer()->TotalScrollOffset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta), + layer()->scroll_offset()); EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); } // The user-scrollability breaks for zoomed-in pages. So disable this. // http://crbug.com/322223 TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); gfx::Vector2dF scroll_delta(20.5f, 8.5f); layer()->set_user_scrollable_vertical(false); @@ -662,7 +674,7 @@ TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { } TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) { - gfx::Vector2d scroll_offset(10, 5); + gfx::ScrollOffset scroll_offset(10, 5); layer()->SetScrollOffset(scroll_offset); scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc index 846951d..0ea8f3d 100644 --- a/cc/layers/layer_unittest.cc +++ b/cc/layers/layer_unittest.cc @@ -611,7 +611,7 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { test_layer->SetScrollClipLayerId(test_layer->id())); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUserScrollable(true, false)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollOffset( - gfx::Vector2d(10, 10))); + gfx::ScrollOffset(10, 10))); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetShouldScrollOnMainThread(true)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNonFastScrollableRegion( Region(gfx::Rect(1, 1, 2, 2)))); diff --git a/cc/layers/picture_layer_impl_perftest.cc b/cc/layers/picture_layer_impl_perftest.cc index a969027..c26b07d 100644 --- a/cc/layers/picture_layer_impl_perftest.cc +++ b/cc/layers/picture_layer_impl_perftest.cc @@ -97,7 +97,8 @@ class PictureLayerImplPerfTest : public testing::Test { void RunRasterIteratorConstructTest(const std::string& test_name, const gfx::Rect& viewport) { host_impl_.SetViewportSize(viewport.size()); - pending_layer_->SetScrollOffset(gfx::Vector2d(viewport.x(), viewport.y())); + pending_layer_->SetScrollOffset( + gfx::ScrollOffset(viewport.x(), viewport.y())); host_impl_.pending_tree()->UpdateDrawProperties(); timer_.Reset(); @@ -150,7 +151,8 @@ class PictureLayerImplPerfTest : public testing::Test { void RunEvictionIteratorConstructTest(const std::string& test_name, const gfx::Rect& viewport) { host_impl_.SetViewportSize(viewport.size()); - pending_layer_->SetScrollOffset(gfx::Vector2d(viewport.x(), viewport.y())); + pending_layer_->SetScrollOffset( + gfx::ScrollOffset(viewport.x(), viewport.y())); host_impl_.pending_tree()->UpdateDrawProperties(); TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc index 56d525a..44158d5 100644 --- a/cc/layers/scrollbar_layer_unittest.cc +++ b/cc/layers/scrollbar_layer_unittest.cc @@ -139,7 +139,7 @@ TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { // Choose bounds to give max_scroll_offset = (30, 50). layer_tree_root->SetBounds(gfx::Size(70, 150)); scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); - scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); scroll_layer->SetBounds(gfx::Size(100, 200)); content_layer->SetBounds(gfx::Size(100, 200)); @@ -165,7 +165,7 @@ TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { layer_tree_root->SetBounds(gfx::Size(700, 1500)); layer_tree_root->SavePaintProperties(); scroll_layer->SetBounds(gfx::Size(1000, 2000)); - scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); scroll_layer->SavePaintProperties(); content_layer->SetBounds(gfx::Size(1000, 2000)); content_layer->SavePaintProperties(); @@ -216,7 +216,7 @@ TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { root_layer->AddChild(content_layer); root_layer->AddChild(scrollbar_layer); - root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); + root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); scrollbar_layer->SetBounds(gfx::Size(70, 10)); scrollbar_layer->SetScrollLayer(root_layer->id()); scrollbar_layer->SetClipLayer(root_clip_layer->id()); @@ -261,7 +261,7 @@ TEST(ScrollbarLayerTest, ThumbRect) { root_layer->AddChild(content_layer); root_layer->AddChild(scrollbar_layer); - root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); + root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); scrollbar_layer->SetBounds(gfx::Size(70, 10)); scrollbar_layer->SetScrollLayer(root_layer->id()); scrollbar_layer->SetClipLayer(root_clip_layer->id()); @@ -282,14 +282,14 @@ TEST(ScrollbarLayerTest, ThumbRect) { scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); // Under-scroll (thumb position should clamp and be unchanged). - root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); + root_layer->SetScrollOffset(gfx::ScrollOffset(-5, 0)); UPDATE_AND_EXTRACT_LAYER_POINTERS(); EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); // Over-scroll (thumb position should clamp on the far side). - root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); + root_layer->SetScrollOffset(gfx::ScrollOffset(85, 0)); UPDATE_AND_EXTRACT_LAYER_POINTERS(); EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), @@ -728,7 +728,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public testing::Test { scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 100)); - layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); + layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); layer_tree_root->SetBounds(gfx::Size(100, 200)); content_layer->SetBounds(gfx::Size(100, 200)); scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); diff --git a/cc/test/animation_test_common.cc b/cc/test/animation_test_common.cc index 953dac4..9966b34 100644 --- a/cc/test/animation_test_common.cc +++ b/cc/test/animation_test_common.cc @@ -216,7 +216,7 @@ void FakeLayerAnimationValueObserver::OnTransformAnimated( } void FakeLayerAnimationValueObserver::OnScrollOffsetAnimated( - const gfx::Vector2dF& scroll_offset) { + const gfx::ScrollOffset& scroll_offset) { scroll_offset_ = scroll_offset; } @@ -232,7 +232,7 @@ bool FakeInactiveLayerAnimationValueObserver::IsActive() const { return false; } -gfx::Vector2dF FakeLayerAnimationValueProvider::ScrollOffsetForAnimation() +gfx::ScrollOffset FakeLayerAnimationValueProvider::ScrollOffsetForAnimation() const { return scroll_offset_; } diff --git a/cc/test/animation_test_common.h b/cc/test/animation_test_common.h index eb030df..bd680d6 100644 --- a/cc/test/animation_test_common.h +++ b/cc/test/animation_test_common.h @@ -79,14 +79,14 @@ class FakeLayerAnimationValueObserver : public LayerAnimationValueObserver { virtual void OnOpacityAnimated(float opacity) OVERRIDE; virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE; virtual void OnScrollOffsetAnimated( - const gfx::Vector2dF& scroll_offset) OVERRIDE; + const gfx::ScrollOffset& scroll_offset) OVERRIDE; virtual void OnAnimationWaitingForDeletion() OVERRIDE; virtual bool IsActive() const OVERRIDE; const FilterOperations& filters() const { return filters_; } float opacity() const { return opacity_; } const gfx::Transform& transform() const { return transform_; } - gfx::Vector2dF scroll_offset() { return scroll_offset_; } + gfx::ScrollOffset scroll_offset() { return scroll_offset_; } bool animation_waiting_for_deletion() { return animation_waiting_for_deletion_; @@ -96,7 +96,7 @@ class FakeLayerAnimationValueObserver : public LayerAnimationValueObserver { FilterOperations filters_; float opacity_; gfx::Transform transform_; - gfx::Vector2dF scroll_offset_; + gfx::ScrollOffset scroll_offset_; bool animation_waiting_for_deletion_; }; @@ -108,14 +108,14 @@ class FakeInactiveLayerAnimationValueObserver class FakeLayerAnimationValueProvider : public LayerAnimationValueProvider { public: - virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE; + virtual gfx::ScrollOffset ScrollOffsetForAnimation() const OVERRIDE; - void set_scroll_offset(const gfx::Vector2dF& scroll_offset) { + void set_scroll_offset(const gfx::ScrollOffset& scroll_offset) { scroll_offset_ = scroll_offset; } private: - gfx::Vector2dF scroll_offset_; + gfx::ScrollOffset scroll_offset_; }; int AddOpacityTransitionToController(LayerAnimationController* controller, diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index 84b1644..1c66185 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -1085,8 +1085,9 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) { } else if (layer == inner_viewport_scroll_layer_.get()) { inner_viewport_scroll_delta += info->scrolls[i].scroll_delta; } else { - layer->SetScrollOffsetFromImplSide(layer->scroll_offset() + - info->scrolls[i].scroll_delta); + layer->SetScrollOffsetFromImplSide( + gfx::ScrollOffsetWithDelta(layer->scroll_offset(), + info->scrolls[i].scroll_delta)); } } @@ -1103,12 +1104,14 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) { // it to the client. If the client comes back and sets it to the same // value, then the layer can early out without needing a full commit. inner_viewport_scroll_layer_->SetScrollOffsetFromImplSide( - inner_viewport_scroll_layer_->scroll_offset() + - inner_viewport_scroll_delta); + gfx::ScrollOffsetWithDelta( + inner_viewport_scroll_layer_->scroll_offset(), + inner_viewport_scroll_delta)); if (outer_viewport_scroll_layer_.get()) { outer_viewport_scroll_layer_->SetScrollOffsetFromImplSide( - outer_viewport_scroll_layer_->scroll_offset() + - outer_viewport_scroll_delta); + gfx::ScrollOffsetWithDelta( + outer_viewport_scroll_layer_->scroll_offset(), + outer_viewport_scroll_delta)); } ApplyPageScaleDeltaFromImplSide(info->page_scale_delta); diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc index 8d25539..3bd1e79 100644 --- a/cc/trees/layer_tree_host_common.cc +++ b/cc/trees/layer_tree_host_common.cc @@ -52,13 +52,13 @@ static gfx::Vector2dF GetEffectiveScrollDelta(LayerType* layer) { } template <typename LayerType> -static gfx::Vector2dF GetEffectiveTotalScrollOffset(LayerType* layer) { - gfx::Vector2dF offset = layer->TotalScrollOffset(); +static gfx::ScrollOffset GetEffectiveTotalScrollOffset(LayerType* layer) { + gfx::ScrollOffset offset = layer->TotalScrollOffset(); // The scroll parent's total scroll offset (scroll offset + scroll delta) // can't be used because its scroll offset has already been applied to the // scroll children's positions by the main thread layer positioning code. if (layer->scroll_parent()) - offset += layer->scroll_parent()->ScrollDelta(); + offset += gfx::ScrollOffset(layer->scroll_parent()->ScrollDelta()); return offset; } @@ -1645,8 +1645,9 @@ static void CalculateDrawPropertiesInternal( layer->parent()->screen_space_transform_is_animating(); } gfx::Point3F transform_origin = layer->transform_origin(); - gfx::Vector2dF scroll_offset = GetEffectiveTotalScrollOffset(layer); - gfx::PointF position = layer->position() - scroll_offset; + gfx::ScrollOffset scroll_offset = GetEffectiveTotalScrollOffset(layer); + gfx::PointF position = + layer->position() - ScrollOffsetToVector2dF(scroll_offset); gfx::Transform combined_transform = data_from_ancestor.parent_matrix; if (!layer->transform().IsIdentity()) { // LT = Tr[origin] * Tr[origin2transformOrigin] diff --git a/cc/trees/layer_tree_host_common.h b/cc/trees/layer_tree_host_common.h index 1f47172..d4c09c6 100644 --- a/cc/trees/layer_tree_host_common.h +++ b/cc/trees/layer_tree_host_common.h @@ -130,6 +130,8 @@ class CC_EXPORT LayerTreeHostCommon { struct ScrollUpdateInfo { int layer_id; + // TODO(miletus) : Use ScrollOffset once LayerTreeHost/Blink fully supports + // franctional scroll offset. gfx::Vector2d scroll_delta; }; }; diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc index 82e34fa..7278b33 100644 --- a/cc/trees/layer_tree_host_common_unittest.cc +++ b/cc/trees/layer_tree_host_common_unittest.cc @@ -284,7 +284,7 @@ TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { } TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { - const gfx::Vector2d kScrollOffset(50, 100); + const gfx::ScrollOffset kScrollOffset(50, 100); const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); const gfx::Vector2d kMaxScrollOffset(200, 200); const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), @@ -6587,7 +6587,7 @@ TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { intervening->SetMasksToBounds(true); clip_parent->SetMasksToBounds(true); intervening->SetScrollClipLayerId(clip_parent->id()); - intervening->SetScrollOffset(gfx::Vector2d(3, 3)); + intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); render_surface1->SetForceRenderSurface(true); render_surface2->SetForceRenderSurface(true); diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 1aca0b0..ab6309b 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -440,7 +440,7 @@ void LayerTreeHostImpl::StartPageScaleAnimation( if (!InnerViewportScrollLayer()) return; - gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); + gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); gfx::SizeF viewport_size = active_tree_->InnerViewportContainerLayer()->bounds(); @@ -449,8 +449,9 @@ void LayerTreeHostImpl::StartPageScaleAnimation( scoped_ptr<TimingFunction> timing_function = CubicBezierTimingFunction::Create(.8, 0, .3, .9); + // TODO(miletus) : Pass in ScrollOffset. page_scale_animation_ = - PageScaleAnimation::Create(scroll_total, + PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total), active_tree_->total_page_scale_factor(), viewport_size, scaled_scrollable_size, @@ -1492,7 +1493,9 @@ CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { if (!InnerViewportScrollLayer()) return metadata; - metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); + // TODO(miletus) : Change the metadata to hold ScrollOffset. + metadata.root_scroll_offset = gfx::ScrollOffsetToVector2dF( + active_tree_->TotalScrollOffset()); return metadata; } @@ -2384,8 +2387,9 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( ScrollOffsetAnimationCurve* curve = animation->curve()->ToScrollOffsetAnimationCurve(); - gfx::Vector2dF new_target = curve->target_value() + scroll_delta; - new_target.SetToMax(gfx::Vector2dF()); + gfx::ScrollOffset new_target = + gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); + new_target.SetToMax(gfx::ScrollOffset()); new_target.SetToMin(layer_impl->MaxScrollOffset()); curve->UpdateTarget(animation->TrimTimeToCurrentIteration( @@ -2405,11 +2409,12 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( if (!layer_impl->scrollable()) continue; - gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset(); - gfx::Vector2dF target_offset = current_offset + pending_delta; - target_offset.SetToMax(gfx::Vector2dF()); + gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); + gfx::ScrollOffset target_offset = + ScrollOffsetWithDelta(current_offset, pending_delta); + target_offset.SetToMax(gfx::ScrollOffset()); target_offset.SetToMin(layer_impl->MaxScrollOffset()); - gfx::Vector2dF actual_delta = target_offset - current_offset; + gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); const float kEpsilon = 0.1f; bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || @@ -2630,7 +2635,7 @@ bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point, float angle_threshold = 45; if (MathUtil::SmallestAngleBetweenVectors( applied_delta, pending_delta) < angle_threshold) { - pending_delta = gfx::Vector2d(); + pending_delta = gfx::Vector2dF(); break; } @@ -2987,7 +2992,7 @@ void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { if (!page_scale_animation_) return; - gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); + gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); if (!page_scale_animation_->IsAnimationStarted()) page_scale_animation_->StartAnimation(monotonic_time); @@ -2995,10 +3000,10 @@ void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { active_tree_->SetPageScaleDelta( page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / active_tree_->page_scale_factor()); - gfx::Vector2dF next_scroll = - page_scale_animation_->ScrollOffsetAtTime(monotonic_time); + gfx::ScrollOffset next_scroll = gfx::ScrollOffset( + page_scale_animation_->ScrollOffsetAtTime(monotonic_time)); - ScrollViewportInnerFirst(next_scroll - scroll_total); + ScrollViewportInnerFirst(next_scroll.DeltaFrom(scroll_total)); SetNeedsRedraw(); if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index dddc512..56b8c22 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -237,7 +237,7 @@ class LayerTreeHostImplTest : public testing::Test, LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); LayerImpl* scroll_layer = scroll.get(); scroll->SetIsContainerForFixedPositionLayers(true); - scroll->SetScrollOffset(gfx::Vector2d()); + scroll->SetScrollOffset(gfx::ScrollOffset()); scoped_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); @@ -458,7 +458,7 @@ TEST_F(LayerTreeHostImplTest, ScrollDeltaTreeButNoChanges) { } TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { - gfx::Vector2d scroll_offset(20, 30); + gfx::ScrollOffset scroll_offset(20, 30); gfx::Vector2d scroll_delta(11, -15); { scoped_ptr<LayerImpl> root_clip = @@ -834,7 +834,7 @@ TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { overflow->SetBounds(overflow_size); overflow->SetContentBounds(overflow_size); overflow->SetScrollClipLayer(scroll_layer->parent()->id()); - overflow->SetScrollOffset(gfx::Vector2d()); + overflow->SetScrollOffset(gfx::ScrollOffset()); overflow->SetPosition(gfx::PointF()); DrawFrame(); @@ -934,7 +934,7 @@ TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { host_impl_->ProcessScrollDeltas(); EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); - EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), + EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), scroll_layer->MaxScrollOffset().ToString()); } @@ -1044,7 +1044,7 @@ TEST_F(LayerTreeHostImplTest, PinchGesture) { min_page_scale, max_page_scale); scroll_layer->SetScrollDelta(gfx::Vector2d()); - scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); float page_scale_delta = 0.1f; host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); @@ -1066,7 +1066,7 @@ TEST_F(LayerTreeHostImplTest, PinchGesture) { min_page_scale, max_page_scale); scroll_layer->SetScrollDelta(gfx::Vector2d()); - scroll_layer->SetScrollOffset(gfx::Vector2d(20, 20)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); float page_scale_delta = 1.f; host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); @@ -1088,7 +1088,7 @@ TEST_F(LayerTreeHostImplTest, PinchGesture) { min_page_scale, max_page_scale); scroll_layer->SetScrollDelta(gfx::Vector2d()); - scroll_layer->SetScrollOffset(gfx::Vector2d(20, 20)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); float page_scale_delta = 1.f; host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); @@ -1111,7 +1111,7 @@ TEST_F(LayerTreeHostImplTest, PinchGesture) { 0.5f, 4.f); scroll_layer->SetScrollDelta(gfx::Vector2d()); - scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); host_impl_->PinchGestureBegin(); @@ -1150,7 +1150,7 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, min_page_scale, max_page_scale); - scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); did_request_redraw_ = false; did_request_animate_ = false; @@ -1188,7 +1188,7 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, min_page_scale, max_page_scale); - scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); did_request_redraw_ = false; did_request_animate_ = false; @@ -1240,7 +1240,7 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, min_page_scale, max_page_scale); - scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration); host_impl_->Animate(start_time); @@ -1304,7 +1304,7 @@ class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { scoped_ptr<LayerImpl> scroll = \ LayerImpl::Create(host_impl_->active_tree(), 2); \ scroll->SetScrollClipLayer(root->id()); \ - scroll->SetScrollOffset(gfx::Vector2d()); \ + scroll->SetScrollOffset(gfx::ScrollOffset()); \ root->SetBounds(viewport_size); \ scroll->SetBounds(content_size); \ scroll->SetContentBounds(content_size); \ @@ -1375,7 +1375,8 @@ TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) { // Setting the scroll offset outside a scroll should also cause the scrollbar // to appear and to schedule a fade. - host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); + host_impl_->InnerViewportScrollLayer()->SetScrollOffset( + gfx::ScrollOffset(5, 5)); EXPECT_LT(base::TimeDelta::FromMilliseconds(19), requested_scrollbar_animation_delay_); EXPECT_FALSE(did_request_redraw_); @@ -1470,7 +1471,7 @@ void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( scoped_ptr<LayerImpl> scroll = LayerImpl::Create(host_impl_->active_tree(), 2); scroll->SetScrollClipLayer(root->id()); - scroll->SetScrollOffset(gfx::Vector2d()); + scroll->SetScrollOffset(gfx::ScrollOffset()); scroll->SetBounds(content_size); scroll->SetContentBounds(content_size); scroll->SetIsContainerForFixedPositionLayers(true); @@ -2409,7 +2410,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, // Verify the layer is once-again non-scrollable. EXPECT_EQ( - gfx::Vector2d(), + gfx::ScrollOffset(), host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); EXPECT_EQ(InputHandler::ScrollStarted, @@ -2572,7 +2573,7 @@ TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { gfx::Vector2d scroll_delta(0, 10); gfx::Vector2d expected_scroll_delta = scroll_delta; - gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); + gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->ScrollBegin(gfx::Point(5, 5), InputHandler::Wheel)); @@ -2623,7 +2624,7 @@ TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { gfx::Vector2d scroll_delta(0, 10); gfx::Vector2d expected_scroll_delta = scroll_delta; - gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); + gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->ScrollBegin(gfx::Point(5, 5), InputHandler::Wheel)); @@ -2733,7 +2734,7 @@ TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { gfx::Vector2d scroll_delta(0, 10); gfx::Vector2d expected_scroll_delta(scroll_delta); - gfx::Vector2d expected_max_scroll(child->MaxScrollOffset()); + gfx::ScrollOffset expected_max_scroll(child->MaxScrollOffset()); EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->ScrollBegin(gfx::Point(5, 5), InputHandler::Wheel)); @@ -2781,8 +2782,8 @@ TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { host_impl_->active_tree()->SetRootLayer(root.Pass()); host_impl_->active_tree()->DidBecomeActive(); host_impl_->SetViewportSize(surface_size); - grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 5)); - child_layer->SetScrollOffset(gfx::Vector2d(3, 0)); + grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 5)); + child_layer->SetScrollOffset(gfx::ScrollOffset(3, 0)); DrawFrame(); { @@ -2833,8 +2834,8 @@ TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { host_impl_->active_tree()->DidBecomeActive(); host_impl_->SetViewportSize(viewport_size); - grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); - child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); + grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 2)); + child_layer->SetScrollOffset(gfx::ScrollOffset(0, 3)); DrawFrame(); { @@ -3172,7 +3173,7 @@ TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { LayerImpl* inner_viewport_scroll_layer = host_impl_->active_tree()->InnerViewportScrollLayer(); - EXPECT_EQ(gfx::Vector2d(0, 0), + EXPECT_EQ(gfx::ScrollOffset(0, 0), inner_viewport_scroll_layer->MaxScrollOffset()); } @@ -3185,18 +3186,19 @@ class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { virtual ~TestScrollOffsetDelegate() {} - virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { + virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE { return getter_return_value_; } virtual bool IsExternalFlingActive() const OVERRIDE { return false; } - virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, - const gfx::Vector2dF& max_scroll_offset, - const gfx::SizeF& scrollable_size, - float page_scale_factor, - float min_page_scale_factor, - float max_page_scale_factor) OVERRIDE { + virtual void UpdateRootLayerState( + const gfx::ScrollOffset& total_scroll_offset, + const gfx::ScrollOffset& max_scroll_offset, + const gfx::SizeF& scrollable_size, + float page_scale_factor, + float min_page_scale_factor, + float max_page_scale_factor) OVERRIDE { DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); last_set_scroll_offset_ = total_scroll_offset; @@ -3207,15 +3209,15 @@ class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { max_page_scale_factor_ = max_page_scale_factor; } - gfx::Vector2dF last_set_scroll_offset() { + gfx::ScrollOffset last_set_scroll_offset() { return last_set_scroll_offset_; } - void set_getter_return_value(const gfx::Vector2dF& value) { + void set_getter_return_value(const gfx::ScrollOffset& value) { getter_return_value_ = value; } - gfx::Vector2dF max_scroll_offset() const { + gfx::ScrollOffset max_scroll_offset() const { return max_scroll_offset_; } @@ -3236,9 +3238,9 @@ class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { } private: - gfx::Vector2dF last_set_scroll_offset_; - gfx::Vector2dF getter_return_value_; - gfx::Vector2dF max_scroll_offset_; + gfx::ScrollOffset last_set_scroll_offset_; + gfx::ScrollOffset getter_return_value_; + gfx::ScrollOffset max_scroll_offset_; gfx::SizeF scrollable_size_; float page_scale_factor_; float min_page_scale_factor_; @@ -3254,7 +3256,7 @@ TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { // Setting the delegate results in the current scroll offset being set. gfx::Vector2dF initial_scroll_delta(10.f, 10.f); - scroll_layer->SetScrollOffset(gfx::Vector2d()); + scroll_layer->SetScrollOffset(gfx::ScrollOffset()); scroll_layer->SetScrollDelta(initial_scroll_delta); host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); EXPECT_EQ(initial_scroll_delta.ToString(), @@ -3263,7 +3265,7 @@ TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { // Setting the delegate results in the scrollable_size, max_scroll_offset, // page_scale_factor and {min|max}_page_scale_factor being set. EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size()); - EXPECT_EQ(gfx::Vector2dF(90, 80), scroll_delegate.max_scroll_offset()); + EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_delegate.max_scroll_offset()); EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); EXPECT_EQ(0.f, scroll_delegate.min_page_scale_factor()); EXPECT_EQ(0.f, scroll_delegate.max_page_scale_factor()); @@ -3295,23 +3297,23 @@ TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { // Scrolling should be relative to the offset as returned by the delegate. gfx::Vector2dF scroll_delta(0.f, 10.f); - gfx::Vector2dF current_offset(7.f, 8.f); + gfx::ScrollOffset current_offset(7.f, 8.f); scroll_delegate.set_getter_return_value(current_offset); EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); host_impl_->ScrollBy(gfx::Point(), scroll_delta); - EXPECT_EQ(current_offset + scroll_delta, + EXPECT_EQ(ScrollOffsetWithDelta(current_offset, scroll_delta), scroll_delegate.last_set_scroll_offset()); - current_offset = gfx::Vector2dF(42.f, 41.f); + current_offset = gfx::ScrollOffset(42.f, 41.f); scroll_delegate.set_getter_return_value(current_offset); host_impl_->ScrollBy(gfx::Point(), scroll_delta); - EXPECT_EQ(current_offset + scroll_delta, + EXPECT_EQ(current_offset + gfx::ScrollOffset(scroll_delta), scroll_delegate.last_set_scroll_offset()); host_impl_->ScrollEnd(); - scroll_delegate.set_getter_return_value(gfx::Vector2dF()); + scroll_delegate.set_getter_return_value(gfx::ScrollOffset()); // Forces a full tree synchronization and ensures that the scroll delegate // sees the correct size of the new tree. @@ -3323,7 +3325,7 @@ TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { // Un-setting the delegate should propagate the delegate's current offset to // the root scrollable layer. - current_offset = gfx::Vector2dF(13.f, 12.f); + current_offset = gfx::ScrollOffset(13.f, 12.f); scroll_delegate.set_getter_return_value(current_offset); host_impl_->SetRootLayerScrollOffsetDelegate(NULL); @@ -3356,13 +3358,13 @@ TEST_F(LayerTreeHostImplTest, EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); // Set external scroll delta on delegate and notify LayerTreeHost. - gfx::Vector2dF scroll_delta(10.f, 10.f); - scroll_delegate.set_getter_return_value(scroll_delta); + gfx::ScrollOffset scroll_offset(10.f, 10.f); + scroll_delegate.set_getter_return_value(scroll_offset); host_impl_->OnRootLayerDelegatedScrollOffsetChanged(); // Check scroll delta reflected in layer. DrawFrame(); - CheckLayerScrollDelta(scroll_layer, scroll_delta); + CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); host_impl_->SetRootLayerScrollOffsetDelegate(NULL); } @@ -3433,8 +3435,8 @@ TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { LayerImpl* child_layer = child.get(); root->AddChild(child.Pass()); root_clip->AddChild(root.Pass()); - child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); - grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); + child_layer->SetScrollOffset(gfx::ScrollOffset(0, 3)); + grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 2)); host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); host_impl_->active_tree()->DidBecomeActive(); host_impl_->SetViewportSize(surface_size); @@ -5639,7 +5641,7 @@ TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { root->SetBounds(root_size); - gfx::Vector2d scroll_offset(100000, 0); + gfx::ScrollOffset scroll_offset(100000, 0); scrolling_layer->SetScrollClipLayer(root->id()); scrolling_layer->SetScrollOffset(scroll_offset); @@ -6166,11 +6168,11 @@ TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size, root.get()); - grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); + grand_child->SetScrollOffset(gfx::ScrollOffset(0, 2)); scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size, root.get()); - child->SetScrollOffset(gfx::Vector2d(0, 4)); + child->SetScrollOffset(gfx::ScrollOffset(0, 4)); child->AddChild(grand_child.Pass()); root_scrolling->AddChild(child.Pass()); @@ -6658,14 +6660,14 @@ const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { SetupScrollAndContentsLayers(gfx::Size(100, 100)) - ->SetScrollOffset(gfx::Vector2d(0, 10)); + ->SetScrollOffset(gfx::ScrollOffset(0, 10)); host_impl_->Animate(base::TimeTicks()); EXPECT_FALSE(did_request_redraw_); } TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { SetupScrollAndContentsLayers(gfx::Size(100, 100)) - ->SetScrollOffset(gfx::Vector2d(0, 10)); + ->SetScrollOffset(gfx::ScrollOffset(0, 10)); host_impl_->DidChangeTopControlsPosition(); EXPECT_TRUE(did_request_animate_); EXPECT_TRUE(did_request_redraw_); @@ -6797,7 +6799,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { host_impl_->top_controls_manager()->UpdateTopControlsState( BOTH, SHOWN, false); float initial_scroll_offset = 50; - scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); + scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, initial_scroll_offset)); DrawFrame(); EXPECT_EQ(InputHandler::ScrollStarted, @@ -6864,7 +6866,7 @@ class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { scoped_ptr<LayerImpl> inner_scroll = LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); inner_scroll->SetIsContainerForFixedPositionLayers(true); - inner_scroll->SetScrollOffset(gfx::Vector2d()); + inner_scroll->SetScrollOffset(gfx::ScrollOffset()); scoped_ptr<LayerImpl> inner_clip = LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); @@ -6886,7 +6888,7 @@ class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { scoped_ptr<LayerImpl> outer_scroll = LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); outer_scroll->SetScrollClipLayer(outer_clip->id()); - outer_scroll->SetScrollOffset(gfx::Vector2d()); + outer_scroll->SetScrollOffset(gfx::ScrollOffset()); outer_scroll->SetBounds(content_size); outer_scroll->SetContentBounds(content_size); outer_scroll->SetPosition(gfx::PointF()); @@ -7027,7 +7029,7 @@ TEST_F(LayerTreeHostImplTest, ScrollAnimated) { host_impl_->Animate(start_time); host_impl_->UpdateAnimationState(true); - EXPECT_EQ(gfx::Vector2dF(), scrolling_layer->TotalScrollOffset()); + EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->TotalScrollOffset()); host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(50)); host_impl_->UpdateAnimationState(true); @@ -7049,7 +7051,8 @@ TEST_F(LayerTreeHostImplTest, ScrollAnimated) { host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(250)); host_impl_->UpdateAnimationState(true); - EXPECT_EQ(gfx::Vector2dF(0, 100), scrolling_layer->TotalScrollOffset()); + EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), + scrolling_layer->TotalScrollOffset()); EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); } diff --git a/cc/trees/layer_tree_host_perftest.cc b/cc/trees/layer_tree_host_perftest.cc index 1862355..6e43ddf 100644 --- a/cc/trees/layer_tree_host_perftest.cc +++ b/cc/trees/layer_tree_host_perftest.cc @@ -231,7 +231,8 @@ class ScrollingLayerTreePerfTest : public LayerTreeHostPerfTestJsonReader { if (TestEnded()) return; static const gfx::Vector2d delta = gfx::Vector2d(0, 10); - scrollable_->SetScrollOffset(scrollable_->scroll_offset() + delta); + scrollable_->SetScrollOffset( + gfx::ScrollOffsetWithDelta(scrollable_->scroll_offset(), delta)); } private: diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 6db1326..4a3fa7e 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -852,7 +852,7 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { scroll_layer_->SetIsContainerForFixedPositionLayers(true); scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(), 2 * root_layer->bounds().height())); - scroll_layer_->SetScrollOffset(gfx::Vector2d()); + scroll_layer_->SetScrollOffset(gfx::ScrollOffset()); layer_tree_host()->root_layer()->AddChild(scroll_layer_); // This test requires the page_scale and inner viewport layers to be // identified. @@ -866,8 +866,9 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, float scale, float) OVERRIDE { - gfx::Vector2d offset = scroll_layer_->scroll_offset(); - scroll_layer_->SetScrollOffset(offset + scroll_delta); + gfx::ScrollOffset offset = scroll_layer_->scroll_offset(); + scroll_layer_->SetScrollOffset(ScrollOffsetWithDelta(offset, + scroll_delta)); layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f); } diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation.cc index d7668c1..da4acb9 100644 --- a/cc/trees/layer_tree_host_unittest_animation.cc +++ b/cc/trees/layer_tree_host_unittest_animation.cc @@ -1029,7 +1029,7 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated scroll_layer_ = FakeContentLayer::Create(&client_); scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); scroll_layer_->SetBounds(gfx::Size(1000, 1000)); - scroll_layer_->SetScrollOffset(gfx::Vector2d(10, 20)); + scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); layer_tree_host()->root_layer()->AddChild(scroll_layer_); } @@ -1042,7 +1042,7 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated case 1: { scoped_ptr<ScrollOffsetAnimationCurve> curve( ScrollOffsetAnimationCurve::Create( - gfx::Vector2dF(500.f, 550.f), + gfx::ScrollOffset(500.f, 550.f), EaseInOutTimingFunction::Create())); scoped_ptr<Animation> animation( Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); diff --git a/cc/trees/layer_tree_host_unittest_damage.cc b/cc/trees/layer_tree_host_unittest_damage.cc index eab8ed6..7d8535e 100644 --- a/cc/trees/layer_tree_host_unittest_damage.cc +++ b/cc/trees/layer_tree_host_unittest_damage.cc @@ -364,7 +364,7 @@ class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); scoped_refptr<Layer> content_layer = FakeContentLayer::Create(&client_); content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); - content_layer->SetScrollOffset(gfx::Vector2d(10, 20)); + content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); content_layer->SetBounds(gfx::Size(100, 200)); scroll_clip_layer->SetBounds( gfx::Size(content_layer->bounds().width() - 30, diff --git a/cc/trees/layer_tree_host_unittest_scroll.cc b/cc/trees/layer_tree_host_unittest_scroll.cc index 9f2786c..4f18d00 100644 --- a/cc/trees/layer_tree_host_unittest_scroll.cc +++ b/cc/trees/layer_tree_host_unittest_scroll.cc @@ -54,7 +54,8 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { if (!layer_tree_host()->source_frame_number()) { EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); } else { - EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, + scroll_amount_), scroll_layer->scroll_offset()); // Pretend like Javascript updated the scroll position itself. @@ -95,9 +96,9 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } private: - gfx::Vector2d initial_scroll_; - gfx::Vector2d second_scroll_; - gfx::Vector2d scroll_amount_; + gfx::ScrollOffset initial_scroll_; + gfx::ScrollOffset second_scroll_; + gfx::Vector2dF scroll_amount_; int num_scrolls_; }; @@ -130,11 +131,15 @@ class LayerTreeHostScrollTestScrollMultipleRedraw EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); break; case 1: - EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), - initial_scroll_ + scroll_amount_ + scroll_amount_); + EXPECT_VECTOR_EQ( + scroll_layer_->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, + scroll_amount_ + scroll_amount_)); case 2: - EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), - initial_scroll_ + scroll_amount_ + scroll_amount_); + EXPECT_VECTOR_EQ( + scroll_layer_->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, + scroll_amount_ + scroll_amount_)); break; } } @@ -165,8 +170,10 @@ class LayerTreeHostScrollTestScrollMultipleRedraw // Third or later draw after second commit. EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); EXPECT_VECTOR_EQ(scroll_layer_->ScrollDelta(), gfx::Vector2d()); - EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), - initial_scroll_ + scroll_amount_ + scroll_amount_); + EXPECT_VECTOR_EQ( + scroll_layer_->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, + scroll_amount_ + scroll_amount_)); EndTest(); } } @@ -180,8 +187,8 @@ class LayerTreeHostScrollTestScrollMultipleRedraw virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } private: - gfx::Vector2d initial_scroll_; - gfx::Vector2d scroll_amount_; + gfx::ScrollOffset initial_scroll_; + gfx::Vector2dF scroll_amount_; int num_scrolls_; scoped_refptr<Layer> scroll_layer_; }; @@ -238,8 +245,9 @@ class LayerTreeHostScrollTestScrollAbortedCommit // initiated from the redraw. EXPECT_EQ(1, num_impl_scrolls_); EXPECT_EQ(1, layer_tree_host()->source_frame_number()); - EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_); + EXPECT_VECTOR_EQ( + root_scroll_layer->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_)); EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); PostSetNeedsRedrawToMainThread(); break; @@ -248,20 +256,24 @@ class LayerTreeHostScrollTestScrollAbortedCommit EXPECT_EQ(2, num_impl_scrolls_); // The source frame number still increases even with the abort. EXPECT_EQ(2, layer_tree_host()->source_frame_number()); - EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_ + impl_scroll_); + EXPECT_VECTOR_EQ( + root_scroll_layer->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, + impl_scroll_ + impl_scroll_)); EXPECT_EQ(impl_scale_ * impl_scale_, layer_tree_host()->page_scale_factor()); - root_scroll_layer->SetScrollOffset(root_scroll_layer->scroll_offset() + - second_main_scroll_); + root_scroll_layer->SetScrollOffset(gfx::ScrollOffsetWithDelta( + root_scroll_layer->scroll_offset(), second_main_scroll_)); break; case 4: // This commit will also be aborted. EXPECT_EQ(3, num_impl_scrolls_); EXPECT_EQ(3, layer_tree_host()->source_frame_number()); + gfx::Vector2dF delta = + impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_ + impl_scroll_ + - impl_scroll_ + second_main_scroll_); + gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); + // End the test by drawing to verify this commit is also aborted. PostSetNeedsRedrawToMainThread(); break; @@ -306,8 +318,9 @@ class LayerTreeHostScrollTestScrollAbortedCommit EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); root_scroll_layer->ScrollBy(impl_scroll_); EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); - EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_); + EXPECT_VECTOR_EQ( + root_scroll_layer->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_)); EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); @@ -327,16 +340,17 @@ class LayerTreeHostScrollTestScrollAbortedCommit root_scroll_layer->ScrollBy(impl_scroll_); impl->SetNeedsCommit(); EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); - EXPECT_VECTOR_EQ( - root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); + gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_; + EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); } else if (impl->active_tree()->source_frame_number() == 2 && impl->SourceAnimationFrameNumber() == 4) { // Final draw after the second aborted commit. EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); + gfx::Vector2dF delta = + impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), - initial_scroll_ + impl_scroll_ + impl_scroll_ + - impl_scroll_ + second_main_scroll_); + gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); EndTest(); } else { // Commit for source frame 3 is aborted. @@ -362,9 +376,9 @@ class LayerTreeHostScrollTestScrollAbortedCommit } private: - gfx::Vector2d initial_scroll_; - gfx::Vector2d impl_scroll_; - gfx::Vector2d second_main_scroll_; + gfx::ScrollOffset initial_scroll_; + gfx::Vector2dF impl_scroll_; + gfx::Vector2dF second_main_scroll_; float impl_scale_; int num_will_begin_main_frames_; int num_did_begin_main_frames_; @@ -532,14 +546,16 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { expected_scroll_layer_->scroll_offset()); break; case 1: - EXPECT_VECTOR_EQ(initial_offset_ + scroll_amount_, - expected_scroll_layer_->scroll_offset()); + EXPECT_VECTOR_EQ( + gfx::ScrollOffsetWithDelta(initial_offset_, scroll_amount_), + expected_scroll_layer_->scroll_offset()); // Pretend like Javascript updated the scroll position itself. expected_scroll_layer_->SetScrollOffset(javascript_scroll_); break; case 2: - EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, + scroll_amount_), expected_scroll_layer_->scroll_offset()); break; } @@ -605,7 +621,8 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { } case 2: - EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, + scroll_amount_), expected_scroll_layer_impl->scroll_offset()); EXPECT_VECTOR_EQ(gfx::Vector2d(), expected_scroll_layer_impl->ScrollDelta()); @@ -618,11 +635,12 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { virtual void AfterTest() OVERRIDE { if (scroll_child_layer_) { EXPECT_EQ(0, num_scrolls_); - EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, + EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, + scroll_amount_), final_scroll_offset_); } else { EXPECT_EQ(2, num_scrolls_); - EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_); + EXPECT_VECTOR_EQ(gfx::ScrollOffset(), final_scroll_offset_); } } @@ -630,11 +648,11 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { float device_scale_factor_; bool scroll_child_layer_; - gfx::Vector2d initial_offset_; - gfx::Vector2d javascript_scroll_; + gfx::ScrollOffset initial_offset_; + gfx::ScrollOffset javascript_scroll_; gfx::Vector2d scroll_amount_; int num_scrolls_; - gfx::Vector2d final_scroll_offset_; + gfx::ScrollOffset final_scroll_offset_; FakeContentLayerClient fake_content_layer_client_; @@ -777,13 +795,15 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { if (!layer_tree_host()->source_frame_number()) { EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); } else { - EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), - initial_scroll_ + impl_thread_scroll1_); + EXPECT_VECTOR_EQ( + scroll_layer->scroll_offset(), + gfx::ScrollOffsetWithDelta(initial_scroll_, impl_thread_scroll1_)); // Pretend like Javascript updated the scroll position itself with a // change of main_thread_scroll. - scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + - impl_thread_scroll1_); + scroll_layer->SetScrollOffset( + gfx::ScrollOffsetWithDelta( + initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); } } @@ -831,7 +851,8 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { LayerImpl* pending_scroll_layer = pending_root->children()[0]; EXPECT_VECTOR_EQ( pending_scroll_layer->scroll_offset(), - initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); + gfx::ScrollOffsetWithDelta( + initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), impl_thread_scroll2_); EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), @@ -842,7 +863,8 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { EXPECT_FALSE(impl->pending_tree()); EXPECT_VECTOR_EQ( scroll_layer->scroll_offset(), - initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); + gfx::ScrollOffsetWithDelta( + initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); EndTest(); @@ -859,10 +881,10 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } private: - gfx::Vector2d initial_scroll_; - gfx::Vector2d main_thread_scroll_; - gfx::Vector2d impl_thread_scroll1_; - gfx::Vector2d impl_thread_scroll2_; + gfx::ScrollOffset initial_scroll_; + gfx::Vector2dF main_thread_scroll_; + gfx::Vector2dF impl_thread_scroll1_; + gfx::Vector2dF impl_thread_scroll2_; int num_scrolls_; }; @@ -966,7 +988,8 @@ class ImplSidePaintingScrollTestImplOnlyScroll case 2: // On the next commit, this delta should have been sent and applied. EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), - initial_scroll_ + impl_thread_scroll_); + gfx::ScrollOffsetWithDelta(initial_scroll_, + impl_thread_scroll_)); EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), gfx::Vector2d()); @@ -1000,8 +1023,8 @@ class ImplSidePaintingScrollTestImplOnlyScroll virtual void AfterTest() OVERRIDE {} private: - gfx::Vector2d initial_scroll_; - gfx::Vector2d impl_thread_scroll_; + gfx::ScrollOffset initial_scroll_; + gfx::Vector2dF impl_thread_scroll_; }; MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index 0763fc7..ab6aa81 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -43,17 +43,18 @@ class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate { : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {} virtual ~LayerScrollOffsetDelegateProxy() {} - gfx::Vector2dF last_set_scroll_offset() const { + gfx::ScrollOffset last_set_scroll_offset() const { return last_set_scroll_offset_; } // LayerScrollOffsetDelegate implementation. - virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_offset) OVERRIDE { + virtual void SetTotalScrollOffset( + const gfx::ScrollOffset& new_offset) OVERRIDE { last_set_scroll_offset_ = new_offset; layer_tree_impl_->UpdateScrollOffsetDelegate(); } - virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { + virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE { return layer_tree_impl_->GetDelegatedScrollOffset(layer_); } @@ -65,7 +66,7 @@ class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate { LayerImpl* layer_; LayerScrollOffsetDelegate* delegate_; LayerTreeImpl* layer_tree_impl_; - gfx::Vector2dF last_set_scroll_offset_; + gfx::ScrollOffset last_set_scroll_offset_; }; LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) @@ -142,8 +143,8 @@ LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { return outer_viewport_scroll_layer_; } -gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const { - gfx::Vector2dF offset; +gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const { + gfx::ScrollOffset offset; if (inner_viewport_scroll_layer_) offset += inner_viewport_scroll_layer_->TotalScrollOffset(); @@ -154,8 +155,8 @@ gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const { return offset; } -gfx::Vector2dF LayerTreeImpl::TotalMaxScrollOffset() const { - gfx::Vector2dF offset; +gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const { + gfx::ScrollOffset offset; if (inner_viewport_scroll_layer_) offset += inner_viewport_scroll_layer_->MaxScrollOffset(); @@ -928,7 +929,7 @@ void LayerTreeImpl::UpdateScrollOffsetDelegate() { DCHECK(InnerViewportScrollLayer()); DCHECK(root_layer_scroll_offset_delegate_); - gfx::Vector2dF offset = + gfx::ScrollOffset offset = inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); if (OuterViewportScrollLayer()) @@ -943,7 +944,7 @@ void LayerTreeImpl::UpdateScrollOffsetDelegate() { max_page_scale_factor()); } -gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { +gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { DCHECK(root_layer_scroll_offset_delegate_); DCHECK(InnerViewportScrollLayer()); if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer()) @@ -953,13 +954,13 @@ gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { // the scroll offset between them. DCHECK(inner_viewport_scroll_delegate_proxy_); DCHECK(outer_viewport_scroll_delegate_proxy_); - gfx::Vector2dF inner_viewport_offset = + gfx::ScrollOffset inner_viewport_offset = inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); - gfx::Vector2dF outer_viewport_offset = + gfx::ScrollOffset outer_viewport_offset = outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); // It may be nothing has changed. - gfx::Vector2dF delegate_offset = + gfx::ScrollOffset delegate_offset = root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); if (inner_viewport_offset + outer_viewport_offset == delegate_offset) { if (layer == InnerViewportScrollLayer()) @@ -968,12 +969,12 @@ gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { return outer_viewport_offset; } - gfx::Vector2d max_outer_viewport_scroll_offset = + gfx::ScrollOffset max_outer_viewport_scroll_offset = OuterViewportScrollLayer()->MaxScrollOffset(); outer_viewport_offset = delegate_offset - inner_viewport_offset; outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset); - outer_viewport_offset.SetToMax(gfx::Vector2d()); + outer_viewport_offset.SetToMax(gfx::ScrollOffset()); if (layer == OuterViewportScrollLayer()) return outer_viewport_offset; diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index e1b2335..6e5994b 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -136,8 +136,8 @@ class CC_EXPORT LayerTreeImpl { LayerImpl* InnerViewportScrollLayer() const; // This function may return NULL, it is the caller's responsibility to check. LayerImpl* OuterViewportScrollLayer() const; - gfx::Vector2dF TotalScrollOffset() const; - gfx::Vector2dF TotalMaxScrollOffset() const; + gfx::ScrollOffset TotalScrollOffset() const; + gfx::ScrollOffset TotalMaxScrollOffset() const; gfx::Vector2dF TotalScrollDelta() const; LayerImpl* InnerViewportContainerLayer() const; @@ -247,7 +247,7 @@ class CC_EXPORT LayerTreeImpl { void SetRootLayerScrollOffsetDelegate( LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate); void UpdateScrollOffsetDelegate(); - gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer); + gfx::ScrollOffset GetDelegatedScrollOffset(LayerImpl* layer); // Call this function when you expect there to be a swap buffer. // See swap_promise.h for how to use SwapPromise. diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc index 66ce2cc..702164b 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc @@ -256,11 +256,15 @@ void SynchronousCompositorImpl::DidActivatePendingTree() { compositor_client_->DidUpdateContent(); } -gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { +gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { DCHECK(CalledOnValidThread()); - if (compositor_client_) - return compositor_client_->GetTotalRootLayerScrollOffset(); - return gfx::Vector2dF(); + if (compositor_client_) { + // TODO(miletus): Make GetTotalRootLayerScrollOffset return + // ScrollOffset. crbug.com/414283. + return gfx::ScrollOffset( + compositor_client_->GetTotalRootLayerScrollOffset()); + } + return gfx::ScrollOffset(); } bool SynchronousCompositorImpl::IsExternalFlingActive() const { @@ -271,8 +275,8 @@ bool SynchronousCompositorImpl::IsExternalFlingActive() const { } void SynchronousCompositorImpl::UpdateRootLayerState( - const gfx::Vector2dF& total_scroll_offset, - const gfx::Vector2dF& max_scroll_offset, + const gfx::ScrollOffset& total_scroll_offset, + const gfx::ScrollOffset& max_scroll_offset, const gfx::SizeF& scrollable_size, float page_scale_factor, float min_page_scale_factor, @@ -281,12 +285,14 @@ void SynchronousCompositorImpl::UpdateRootLayerState( if (!compositor_client_) return; - compositor_client_->UpdateRootLayerState(total_scroll_offset, - max_scroll_offset, - scrollable_size, - page_scale_factor, - min_page_scale_factor, - max_page_scale_factor); + // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. + compositor_client_->UpdateRootLayerState( + gfx::ScrollOffsetToVector2dF(total_scroll_offset), + gfx::ScrollOffsetToVector2dF(max_scroll_offset), + scrollable_size, + page_scale_factor, + min_page_scale_factor, + max_page_scale_factor); } // Not using base::NonThreadSafe as we want to enforce a more exacting threading diff --git a/content/browser/android/in_process/synchronous_compositor_impl.h b/content/browser/android/in_process/synchronous_compositor_impl.h index 582e4df..3dbd509 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_impl.h @@ -76,13 +76,14 @@ class SynchronousCompositorImpl virtual void DidActivatePendingTree() OVERRIDE; // LayerScrollOffsetDelegate - virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE; - virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, - const gfx::Vector2dF& max_scroll_offset, - const gfx::SizeF& scrollable_size, - float page_scale_factor, - float min_page_scale_factor, - float max_page_scale_factor) OVERRIDE; + virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE; + virtual void UpdateRootLayerState( + const gfx::ScrollOffset& total_scroll_offset, + const gfx::ScrollOffset& max_scroll_offset, + const gfx::SizeF& scrollable_size, + float page_scale_factor, + float min_page_scale_factor, + float max_page_scale_factor) OVERRIDE; virtual bool IsExternalFlingActive() const OVERRIDE; void SetInputHandler(cc::InputHandler* input_handler); diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index db9fa0d..291b2b6 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -448,6 +448,7 @@ test("gfx_unittests") { "geometry/r_tree_unittest.cc", "geometry/rect_unittest.cc", "geometry/safe_integer_conversions_unittest.cc", + "geometry/scroll_offset_unittest.cc", "geometry/size_unittest.cc", "geometry/vector2d_unittest.cc", "geometry/vector3d_unittest.cc", diff --git a/ui/gfx/geometry/BUILD.gn b/ui/gfx/geometry/BUILD.gn index 32a86c7..8849def 100644 --- a/ui/gfx/geometry/BUILD.gn +++ b/ui/gfx/geometry/BUILD.gn @@ -39,6 +39,8 @@ component("geometry") { "r_tree_base.cc", "r_tree_base.h", "safe_integer_conversions.h", + "scroll_offset.cc", + "scroll_offset.h", "size.cc", "size.h", "size_base.h", diff --git a/ui/gfx/geometry/safe_integer_conversions.h b/ui/gfx/geometry/safe_integer_conversions.h index 4d289ec..58ed2a9 100644 --- a/ui/gfx/geometry/safe_integer_conversions.h +++ b/ui/gfx/geometry/safe_integer_conversions.h @@ -30,6 +30,14 @@ inline int ToCeiledInt(float value) { return ClampToInt(std::ceil(value)); } +inline int ToFlooredInt(double value) { + return ClampToInt(std::floor(value)); +} + +inline int ToCeiledInt(double value) { + return ClampToInt(std::ceil(value)); +} + inline int ToRoundedInt(float value) { float rounded; if (value >= 0.0f) diff --git a/ui/gfx/geometry/safe_integer_conversions_unittest.cc b/ui/gfx/geometry/safe_integer_conversions_unittest.cc index e00671b..20e05b4 100644 --- a/ui/gfx/geometry/safe_integer_conversions_unittest.cc +++ b/ui/gfx/geometry/safe_integer_conversions_unittest.cc @@ -48,7 +48,7 @@ TEST(SafeIntegerConversions, ToFlooredInt) { EXPECT_EQ(int_max, ToFlooredInt(max + 100)); EXPECT_EQ(-101, ToFlooredInt(-100.5f)); - EXPECT_EQ(0, ToFlooredInt(0)); + EXPECT_EQ(0, ToFlooredInt(0.f)); EXPECT_EQ(100, ToFlooredInt(100.5f)); EXPECT_EQ(int_min, ToFlooredInt(-infinity)); @@ -71,7 +71,7 @@ TEST(SafeIntegerConversions, ToCeiledInt) { EXPECT_EQ(int_max, ToCeiledInt(max + 100)); EXPECT_EQ(-100, ToCeiledInt(-100.5f)); - EXPECT_EQ(0, ToCeiledInt(0)); + EXPECT_EQ(0, ToCeiledInt(0.f)); EXPECT_EQ(101, ToCeiledInt(100.5f)); EXPECT_EQ(int_min, ToCeiledInt(-infinity)); diff --git a/ui/gfx/geometry/scroll_offset.cc b/ui/gfx/geometry/scroll_offset.cc new file mode 100644 index 0000000..37356d8 --- /dev/null +++ b/ui/gfx/geometry/scroll_offset.cc @@ -0,0 +1,15 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/geometry/scroll_offset.h" + +#include "base/strings/stringprintf.h" + +namespace gfx { + +std::string ScrollOffset::ToString() const { + return base::StringPrintf("[%lf %lf]", x_, y_); +} + +} // namespace gfx diff --git a/ui/gfx/geometry/scroll_offset.h b/ui/gfx/geometry/scroll_offset.h new file mode 100644 index 0000000..496b5f4 --- /dev/null +++ b/ui/gfx/geometry/scroll_offset.h @@ -0,0 +1,125 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ +#define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ + +#include <iosfwd> +#include <string> + +#include "ui/gfx/geometry/safe_integer_conversions.h" +#include "ui/gfx/geometry/vector2d.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +class GFX_EXPORT ScrollOffset { + public: + ScrollOffset() : x_(0), y_(0) {} + ScrollOffset(double x, double y) : x_(x), y_(y) {} + explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {} + explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {} + + double x() const { return x_; } + void set_x(double x) { x_ = x; } + + double y() const { return y_; } + void set_y(double y) { y_ = y; } + + // True if both components are 0. + bool IsZero() const { + return x_ == 0 && y_ == 0; + } + + // Add the components of the |other| ScrollOffset to the current ScrollOffset. + void Add(const ScrollOffset& other) { + x_ += other.x_; + y_ += other.y_; + } + + // Subtract the components of the |other| ScrollOffset from the current + // ScrollOffset. + void Subtract(const ScrollOffset& other) { + x_ -= other.x_; + y_ -= other.y_; + } + + Vector2dF DeltaFrom(const ScrollOffset& v) const { + return Vector2dF(x_ - v.x(), y_ - v.y()); + } + + void operator+=(const ScrollOffset& other) { Add(other); } + void operator-=(const ScrollOffset& other) { Subtract(other); } + + void SetToMin(const ScrollOffset& other) { + x_ = x_ <= other.x_ ? x_ : other.x_; + y_ = y_ <= other.y_ ? y_ : other.y_; + } + + void SetToMax(const ScrollOffset& other) { + x_ = x_ >= other.x_ ? x_ : other.x_; + y_ = y_ >= other.y_ ? y_ : other.y_; + } + + void Scale(double scale) { Scale(scale, scale); } + void Scale(double x_scale, double y_scale) { + x_ *= x_scale; + y_ *= y_scale; + } + + std::string ToString() const; + + private: + double x_; + double y_; +}; + +inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { + return lhs.x() == rhs.x() && lhs.y() == rhs.y(); +} + +inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { + return lhs.x() != rhs.x() || lhs.y() != rhs.y(); +} + +inline ScrollOffset operator-(const ScrollOffset& v) { + return ScrollOffset(-v.x(), -v.y()); +} + +inline ScrollOffset operator+(const ScrollOffset& lhs, + const ScrollOffset& rhs) { + ScrollOffset result = lhs; + result.Add(rhs); + return result; +} + +inline ScrollOffset operator-(const ScrollOffset& lhs, + const ScrollOffset& rhs) { + ScrollOffset result = lhs; + result.Add(-rhs); + return result; +} + +inline Vector2d ScrollOffsetToFlooredVector2d(const ScrollOffset& v) { + return Vector2d(ToFlooredInt(v.x()), ToFlooredInt(v.y())); +} + +inline Vector2dF ScrollOffsetToVector2dF(const ScrollOffset& v) { + return Vector2dF(v.x(), v.y()); +} + +inline ScrollOffset ScrollOffsetWithDelta(const ScrollOffset& offset, + const Vector2dF& delta) { + return ScrollOffset(offset.x() + delta.x(), + offset.y() + delta.y()); +} + +// This is declared here for use in gtest-based unit tests but is defined in +// the gfx_test_support target. Depend on that to use this in your unit test. +// This should not be used in production code - call ToString() instead. +void PrintTo(const ScrollOffset& scroll_offset, ::std::ostream* os); + +} // namespace gfx + +#endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ diff --git a/ui/gfx/geometry/scroll_offset_unittest.cc b/ui/gfx/geometry/scroll_offset_unittest.cc new file mode 100644 index 0000000..4049b83 --- /dev/null +++ b/ui/gfx/geometry/scroll_offset_unittest.cc @@ -0,0 +1,122 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <cmath> +#include <limits> + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/geometry/scroll_offset.h" + +namespace gfx { + +TEST(ScrollOffsetTest, IsZero) { + ScrollOffset zero(0, 0); + ScrollOffset nonzero(0.1, -0.1); + + EXPECT_TRUE(zero.IsZero()); + EXPECT_FALSE(nonzero.IsZero()); +} + +TEST(ScrollOffsetTest, Add) { + ScrollOffset f1(3.1, 5.1); + ScrollOffset f2(4.3, -1.3); + + const struct { + ScrollOffset expected; + ScrollOffset actual; + } scroll_offset_tests[] = { + { ScrollOffset(3.1, 5.1), f1 + ScrollOffset() }, + { ScrollOffset(3.1 + 4.3, 5.1f - 1.3), f1 + f2 }, + { ScrollOffset(3.1 - 4.3, 5.1f + 1.3), f1 - f2 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(scroll_offset_tests); ++i) + EXPECT_EQ(scroll_offset_tests[i].expected.ToString(), + scroll_offset_tests[i].actual.ToString()); +} + +TEST(ScrollOffsetTest, Negative) { + const struct { + ScrollOffset expected; + ScrollOffset actual; + } scroll_offset_tests[] = { + { ScrollOffset(-0.3, -0.3), -ScrollOffset(0.3, 0.3) }, + { ScrollOffset(0.3, 0.3), -ScrollOffset(-0.3, -0.3) }, + { ScrollOffset(-0.3, 0.3), -ScrollOffset(0.3, -0.3) }, + { ScrollOffset(0.3, -0.3), -ScrollOffset(-0.3, 0.3) } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(scroll_offset_tests); ++i) + EXPECT_EQ(scroll_offset_tests[i].expected.ToString(), + scroll_offset_tests[i].actual.ToString()); +} + +TEST(ScrollOffsetTest, Scale) { + double double_values[][4] = { + { 4.5, 1.2, 3.3, 5.6 }, + { 4.5, -1.2, 3.3, 5.6 }, + { 4.5, 1.2, 3.3, -5.6 }, + { 4.5, 1.2, -3.3, -5.6 }, + { -4.5, 1.2, 3.3, 5.6 }, + { -4.5, 1.2, 0, 5.6 }, + { -4.5, 1.2, 3.3, 0 }, + { 4.5, 0, 3.3, 5.6 }, + { 0, 1.2, 3.3, 5.6 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(double_values); ++i) { + ScrollOffset v(double_values[i][0], double_values[i][1]); + v.Scale(double_values[i][2], double_values[i][3]); + EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]); + EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]); + } + + double single_values[][3] = { + { 4.5, 1.2, 3.3 }, + { 4.5, -1.2, 3.3 }, + { 4.5, 1.2, 3.3 }, + { 4.5, 1.2, -3.3 }, + { -4.5, 1.2, 3.3 }, + { -4.5, 1.2, 0 }, + { -4.5, 1.2, 3.3 }, + { 4.5, 0, 3.3 }, + { 0, 1.2, 3.3 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(single_values); ++i) { + ScrollOffset v(single_values[i][0], single_values[i][1]); + v.Scale(single_values[i][2]); + EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]); + EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]); + } +} + +TEST(ScrollOffsetTest, ClampScrollOffset) { + ScrollOffset a; + + a = ScrollOffset(3.5, 5.5); + EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString()); + a.SetToMax(ScrollOffset(2.5, 4.5)); + EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString()); + a.SetToMax(ScrollOffset(3.5, 5.5)); + EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString()); + a.SetToMax(ScrollOffset(4.5, 2.5)); + EXPECT_EQ(ScrollOffset(4.5, 5.5).ToString(), a.ToString()); + a.SetToMax(ScrollOffset(8.5, 10.5)); + EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString()); + + a.SetToMin(ScrollOffset(9.5, 11.5)); + EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString()); + a.SetToMin(ScrollOffset(8.5, 10.5)); + EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString()); + a.SetToMin(ScrollOffset(11.5, 9.5)); + EXPECT_EQ(ScrollOffset(8.5, 9.5).ToString(), a.ToString()); + a.SetToMin(ScrollOffset(7.5, 11.5)); + EXPECT_EQ(ScrollOffset(7.5, 9.5).ToString(), a.ToString()); + a.SetToMin(ScrollOffset(3.5, 5.5)); + EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString()); +} + +} // namespace gfx diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index 873e9cd..10f2bfa 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -51,6 +51,8 @@ 'geometry/r_tree_base.cc', 'geometry/r_tree_base.h', 'geometry/safe_integer_conversions.h', + 'geometry/scroll_offset.cc', + 'geometry/scroll_offset.h', 'geometry/size.cc', 'geometry/size.h', 'geometry/size_base.h', diff --git a/ui/gfx/gfx_tests.gyp b/ui/gfx/gfx_tests.gyp index 1404552..a6a68e0 100644 --- a/ui/gfx/gfx_tests.gyp +++ b/ui/gfx/gfx_tests.gyp @@ -52,6 +52,7 @@ 'geometry/r_tree_unittest.cc', 'geometry/rect_unittest.cc', 'geometry/safe_integer_conversions_unittest.cc', + 'geometry/scroll_offset_unittest.cc', 'geometry/size_unittest.cc', 'geometry/vector2d_unittest.cc', 'geometry/vector3d_unittest.cc', diff --git a/ui/gfx/test/gfx_util.cc b/ui/gfx/test/gfx_util.cc index 2d670d4..d8bf5f2 100644 --- a/ui/gfx/test/gfx_util.cc +++ b/ui/gfx/test/gfx_util.cc @@ -15,6 +15,7 @@ #include "ui/gfx/geometry/quad_f.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect_f.h" +#include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size_f.h" #include "ui/gfx/geometry/vector2d.h" @@ -118,6 +119,10 @@ void PrintTo(const RectF& rect, ::std::ostream* os) { *os << rect.ToString(); } +void PrintTo(const ScrollOffset& offset, ::std::ostream* os) { + *os << offset.ToString(); +} + void PrintTo(const Size& size, ::std::ostream* os) { *os << size.ToString(); } |