1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/input/scroll_elasticity_helper.h"
7 #include "cc/layers/layer_impl.h"
8 #include "cc/trees/layer_tree_host_impl.h"
9 #include "cc/trees/layer_tree_impl.h"
13 class ScrollElasticityHelperImpl
: public ScrollElasticityHelper
{
15 explicit ScrollElasticityHelperImpl(LayerTreeHostImpl
* layer_tree_host_impl
);
16 ~ScrollElasticityHelperImpl() override
;
18 bool IsUserScrollable() const override
;
19 gfx::Vector2dF
StretchAmount() const override
;
20 void SetStretchAmount(const gfx::Vector2dF
& stretch_amount
) override
;
21 gfx::ScrollOffset
ScrollOffset() const override
;
22 gfx::ScrollOffset
MaxScrollOffset() const override
;
23 void ScrollBy(const gfx::Vector2dF
& delta
) override
;
24 void RequestAnimate() override
;
27 LayerTreeHostImpl
* layer_tree_host_impl_
;
30 ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
31 LayerTreeHostImpl
* layer_tree
)
32 : layer_tree_host_impl_(layer_tree
) {
35 ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
38 bool ScrollElasticityHelperImpl::IsUserScrollable() const {
39 LayerImpl
* layer
= layer_tree_host_impl_
->OuterViewportScrollLayer();
42 return layer
->user_scrollable_horizontal() ||
43 layer
->user_scrollable_vertical();
46 gfx::Vector2dF
ScrollElasticityHelperImpl::StretchAmount() const {
47 return layer_tree_host_impl_
->active_tree()->elastic_overscroll()->Current(
51 void ScrollElasticityHelperImpl::SetStretchAmount(
52 const gfx::Vector2dF
& stretch_amount
) {
53 if (stretch_amount
== StretchAmount())
56 layer_tree_host_impl_
->active_tree()->elastic_overscroll()->SetCurrent(
58 layer_tree_host_impl_
->active_tree()->set_needs_update_draw_properties();
59 layer_tree_host_impl_
->SetNeedsCommit();
60 layer_tree_host_impl_
->SetNeedsRedraw();
61 layer_tree_host_impl_
->SetFullRootLayerDamage();
64 gfx::ScrollOffset
ScrollElasticityHelperImpl::ScrollOffset() const {
65 return layer_tree_host_impl_
->active_tree()->TotalScrollOffset();
68 gfx::ScrollOffset
ScrollElasticityHelperImpl::MaxScrollOffset() const {
69 return layer_tree_host_impl_
->active_tree()->TotalMaxScrollOffset();
72 void ScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF
& delta
) {
73 LayerImpl
* root_scroll_layer
=
74 layer_tree_host_impl_
->OuterViewportScrollLayer()
75 ? layer_tree_host_impl_
->OuterViewportScrollLayer()
76 : layer_tree_host_impl_
->InnerViewportScrollLayer();
77 if (root_scroll_layer
)
78 root_scroll_layer
->ScrollBy(delta
);
81 void ScrollElasticityHelperImpl::RequestAnimate() {
82 layer_tree_host_impl_
->SetNeedsAnimate();
86 ScrollElasticityHelper
* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
87 LayerTreeHostImpl
* layer_tree_host_impl
) {
88 return new ScrollElasticityHelperImpl(layer_tree_host_impl
);