Fix missing .Pass() on returning scoped_ptr<SdchManager::DictionarySet>
[chromium-blink-merge.git] / cc / input / scroll_elasticity_helper.cc
blob1e9fe7dff9f59fd482a286d89fc8dc5a613ac2aa
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"
11 namespace cc {
13 class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
14 public:
15 explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* layer_tree_host_impl);
16 ~ScrollElasticityHelperImpl() override;
18 gfx::Vector2dF StretchAmount() const override;
19 void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
20 gfx::ScrollOffset ScrollOffset() const override;
21 gfx::ScrollOffset MaxScrollOffset() const override;
22 void ScrollBy(const gfx::Vector2dF& delta) override;
23 void RequestAnimate() override;
25 private:
26 LayerTreeHostImpl* layer_tree_host_impl_;
29 ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
30 LayerTreeHostImpl* layer_tree)
31 : layer_tree_host_impl_(layer_tree) {
34 ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
37 gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() const {
38 return layer_tree_host_impl_->active_tree()->elastic_overscroll()->Current(
39 true);
42 void ScrollElasticityHelperImpl::SetStretchAmount(
43 const gfx::Vector2dF& stretch_amount) {
44 if (stretch_amount == StretchAmount())
45 return;
47 layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
48 stretch_amount);
49 layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties();
50 layer_tree_host_impl_->SetNeedsCommit();
51 layer_tree_host_impl_->SetNeedsRedraw();
52 layer_tree_host_impl_->SetFullRootLayerDamage();
55 gfx::ScrollOffset ScrollElasticityHelperImpl::ScrollOffset() const {
56 return layer_tree_host_impl_->active_tree()->TotalScrollOffset();
59 gfx::ScrollOffset ScrollElasticityHelperImpl::MaxScrollOffset() const {
60 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset();
63 void ScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF& delta) {
64 LayerImpl* root_scroll_layer =
65 layer_tree_host_impl_->OuterViewportScrollLayer()
66 ? layer_tree_host_impl_->OuterViewportScrollLayer()
67 : layer_tree_host_impl_->InnerViewportScrollLayer();
68 if (root_scroll_layer)
69 root_scroll_layer->ScrollBy(delta);
72 void ScrollElasticityHelperImpl::RequestAnimate() {
73 layer_tree_host_impl_->SetNeedsAnimate();
76 // static
77 ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
78 LayerTreeHostImpl* layer_tree_host_impl) {
79 return new ScrollElasticityHelperImpl(layer_tree_host_impl);
82 } // namespace cc