Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: cc/input/scroll_elasticity_helper.cc

Issue 817653003: Update from https://crrev.com/309717 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/input/scroll_elasticity_helper.h" 5 #include "cc/input/scroll_elasticity_helper.h"
6 6
7 #include "cc/layers/layer_impl.h" 7 #include "cc/layers/layer_impl.h"
8 #include "cc/trees/layer_tree_host_impl.h" 8 #include "cc/trees/layer_tree_host_impl.h"
9 #include "cc/trees/layer_tree_impl.h" 9 #include "cc/trees/layer_tree_impl.h"
10 10
11 namespace cc { 11 namespace cc {
12 12
13 class ScrollElasticityHelperImpl : public ScrollElasticityHelper { 13 class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
14 public: 14 public:
15 explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* layer_tree_host_impl); 15 explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* layer_tree_host_impl);
16 virtual ~ScrollElasticityHelperImpl(); 16 ~ScrollElasticityHelperImpl() override;
17 17
18 // The amount that the view is stretched past the normal allowable bounds. 18 gfx::Vector2dF StretchAmount() const override;
19 // The "overhang" amount.
20 gfx::Vector2dF StretchAmount() override;
21 void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override; 19 void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
22 bool PinnedInDirection(const gfx::Vector2dF& direction) override; 20 gfx::ScrollOffset ScrollOffset() const override;
23 bool CanScrollHorizontally() override; 21 gfx::ScrollOffset MaxScrollOffset() const override;
24 bool CanScrollVertically() override; 22 void ScrollBy(const gfx::Vector2dF& delta) override;
25 void RequestAnimate() override; 23 void RequestAnimate() override;
26 24
27 private: 25 private:
28 LayerTreeHostImpl* layer_tree_host_impl_; 26 LayerTreeHostImpl* layer_tree_host_impl_;
29 }; 27 };
30 28
31 ScrollElasticityHelperImpl::ScrollElasticityHelperImpl( 29 ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
32 LayerTreeHostImpl* layer_tree) 30 LayerTreeHostImpl* layer_tree)
33 : layer_tree_host_impl_(layer_tree) { 31 : layer_tree_host_impl_(layer_tree) {
34 } 32 }
35 33
36 ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() { 34 ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
37 } 35 }
38 36
39 gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() { 37 gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() const {
40 return -layer_tree_host_impl_->active_tree()->elastic_overscroll()->Current( 38 return layer_tree_host_impl_->active_tree()->elastic_overscroll()->Current(
41 true); 39 true);
42 } 40 }
43 41
44 void ScrollElasticityHelperImpl::SetStretchAmount( 42 void ScrollElasticityHelperImpl::SetStretchAmount(
45 const gfx::Vector2dF& stretch_amount) { 43 const gfx::Vector2dF& stretch_amount) {
46 if (stretch_amount == StretchAmount()) 44 if (stretch_amount == StretchAmount())
47 return; 45 return;
48 46
49 layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent( 47 layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
50 -stretch_amount); 48 stretch_amount);
51 layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties(); 49 layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties();
52 layer_tree_host_impl_->SetNeedsCommit(); 50 layer_tree_host_impl_->SetNeedsCommit();
53 layer_tree_host_impl_->SetNeedsRedraw(); 51 layer_tree_host_impl_->SetNeedsRedraw();
54 layer_tree_host_impl_->SetFullRootLayerDamage(); 52 layer_tree_host_impl_->SetFullRootLayerDamage();
55 } 53 }
56 54
57 bool ScrollElasticityHelperImpl::PinnedInDirection( 55 gfx::ScrollOffset ScrollElasticityHelperImpl::ScrollOffset() const {
58 const gfx::Vector2dF& direction) { 56 return layer_tree_host_impl_->active_tree()->TotalScrollOffset();
59 gfx::ScrollOffset scroll_offset =
60 layer_tree_host_impl_->active_tree()->TotalScrollOffset();
61 gfx::ScrollOffset max_scroll_offset =
62 layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset();
63 bool result = false;
64 if (direction.x() < 0)
65 result |= scroll_offset.x() <= 0;
66 if (direction.x() > 0)
67 result |= scroll_offset.x() >= max_scroll_offset.x();
68 if (direction.y() < 0)
69 result |= scroll_offset.y() <= 0;
70 if (direction.y() > 0)
71 result |= scroll_offset.y() >= max_scroll_offset.y();
72 return result;
73 } 57 }
74 58
75 bool ScrollElasticityHelperImpl::CanScrollHorizontally() { 59 gfx::ScrollOffset ScrollElasticityHelperImpl::MaxScrollOffset() const {
76 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().x() > 0; 60 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset();
77 } 61 }
78 62
79 bool ScrollElasticityHelperImpl::CanScrollVertically() { 63 void ScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF& delta) {
80 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().y() > 0; 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);
81 } 70 }
82 71
83 void ScrollElasticityHelperImpl::RequestAnimate() { 72 void ScrollElasticityHelperImpl::RequestAnimate() {
84 layer_tree_host_impl_->SetNeedsAnimate(); 73 layer_tree_host_impl_->SetNeedsAnimate();
85 } 74 }
86 75
87 // static 76 // static
88 ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl( 77 ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
89 LayerTreeHostImpl* layer_tree_host_impl) { 78 LayerTreeHostImpl* layer_tree_host_impl) {
90 return new ScrollElasticityHelperImpl(layer_tree_host_impl); 79 return new ScrollElasticityHelperImpl(layer_tree_host_impl);
91 } 80 }
92 81
93 } // namespace cc 82 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scroll_elasticity_helper.h ('k') | cc/layers/delegated_renderer_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698