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

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

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « cc/input/scroll_elasticity_helper.h ('k') | cc/layers/heads_up_display_layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ScrollElasticityHelper::ScrollElasticityHelper(LayerTreeHostImpl* layer_tree) 13 class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
14 : layer_tree_host_impl_(layer_tree), timer_active_(false) { 14 public:
15 explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* layer_tree_host_impl);
16 virtual ~ScrollElasticityHelperImpl();
17
18 // The amount that the view is stretched past the normal allowable bounds.
19 // The "overhang" amount.
20 gfx::Vector2dF StretchAmount() override;
21 void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
22 bool PinnedInDirection(const gfx::Vector2dF& direction) override;
23 bool CanScrollHorizontally() override;
24 bool CanScrollVertically() override;
25 void RequestAnimate() override;
26
27 private:
28 LayerTreeHostImpl* layer_tree_host_impl_;
29 };
30
31 ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
32 LayerTreeHostImpl* layer_tree)
33 : layer_tree_host_impl_(layer_tree) {
15 } 34 }
16 35
17 ScrollElasticityHelper::~ScrollElasticityHelper() { 36 ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
18 } 37 }
19 38
20 bool ScrollElasticityHelper::AllowsHorizontalStretching() { 39 gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() {
21 // The WebKit implementation has this interface because it is written in terms 40 return -layer_tree_host_impl_->active_tree()->elastic_overscroll()->Current(
22 // of overscrolling on a per-layer basis, not for the whole layer tree. In 41 true);
23 // that implementation, this always returns true for the frame view's
24 // scrollable area.
25 // TODO(ccameron): This is function is redundant and may be removed.
26 return true;
27 } 42 }
28 43
29 bool ScrollElasticityHelper::AllowsVerticalStretching() { 44 void ScrollElasticityHelperImpl::SetStretchAmount(
30 // TODO(ccameron): This is function is redundant and may be removed. 45 const gfx::Vector2dF& stretch_amount) {
31 return true; 46 if (stretch_amount == StretchAmount())
47 return;
48
49 layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
50 -stretch_amount);
51 layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties();
52 layer_tree_host_impl_->SetNeedsCommit();
53 layer_tree_host_impl_->SetNeedsRedraw();
54 layer_tree_host_impl_->SetFullRootLayerDamage();
32 } 55 }
33 56
34 gfx::Vector2dF ScrollElasticityHelper::StretchAmount() { 57 bool ScrollElasticityHelperImpl::PinnedInDirection(
35 // TODO(ccameron): Use the value of active_tree->elastic_overscroll directly
36 return stretch_offset_;
37 }
38
39 bool ScrollElasticityHelper::PinnedInDirection(
40 const gfx::Vector2dF& direction) { 58 const gfx::Vector2dF& direction) {
41 gfx::ScrollOffset scroll_offset = 59 gfx::ScrollOffset scroll_offset =
42 layer_tree_host_impl_->active_tree()->TotalScrollOffset(); 60 layer_tree_host_impl_->active_tree()->TotalScrollOffset();
43 gfx::ScrollOffset max_scroll_offset = 61 gfx::ScrollOffset max_scroll_offset =
44 layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset(); 62 layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset();
45 bool result = false; 63 bool result = false;
46 if (direction.x() < 0) 64 if (direction.x() < 0)
47 result |= scroll_offset.x() <= 0; 65 result |= scroll_offset.x() <= 0;
48 if (direction.x() > 0) 66 if (direction.x() > 0)
49 result |= scroll_offset.x() >= max_scroll_offset.x(); 67 result |= scroll_offset.x() >= max_scroll_offset.x();
50 if (direction.y() < 0) 68 if (direction.y() < 0)
51 result |= scroll_offset.y() <= 0; 69 result |= scroll_offset.y() <= 0;
52 if (direction.y() > 0) 70 if (direction.y() > 0)
53 result |= scroll_offset.y() >= max_scroll_offset.y(); 71 result |= scroll_offset.y() >= max_scroll_offset.y();
54 return result; 72 return result;
55 } 73 }
56 74
57 bool ScrollElasticityHelper::CanScrollHorizontally() { 75 bool ScrollElasticityHelperImpl::CanScrollHorizontally() {
58 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().x() > 0; 76 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().x() > 0;
59 } 77 }
60 78
61 bool ScrollElasticityHelper::CanScrollVertically() { 79 bool ScrollElasticityHelperImpl::CanScrollVertically() {
62 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().y() > 0; 80 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().y() > 0;
63 } 81 }
64 82
65 gfx::Vector2dF ScrollElasticityHelper::AbsoluteScrollPosition() { 83 void ScrollElasticityHelperImpl::RequestAnimate() {
66 // TODO(ccameron): This is function is redundant and may be removed.
67 return StretchAmount();
68 }
69
70 void ScrollElasticityHelper::ImmediateScrollBy(const gfx::Vector2dF& scroll) {
71 // TODO(ccameron): This is function is redundant and may be removed.
72 }
73
74 void ScrollElasticityHelper::ImmediateScrollByWithoutContentEdgeConstraints(
75 const gfx::Vector2dF& scroll) {
76 stretch_offset_ += scroll;
77 // TODO(ccameron): Use the value of active_tree->elastic_overscroll directly
78 // Note that this assumes that this property's true value is ever changed
79 // by the impl thread. While this is true, it is redundant state.
80 layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
81 -stretch_offset_);
82 layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties();
83 layer_tree_host_impl_->SetNeedsCommit();
84 layer_tree_host_impl_->SetNeedsRedraw();
85 }
86
87 void ScrollElasticityHelper::StartSnapRubberbandTimer() {
88 if (timer_active_)
89 return;
90 timer_active_ = true;
91 layer_tree_host_impl_->SetNeedsAnimate(); 84 layer_tree_host_impl_->SetNeedsAnimate();
92 } 85 }
93 86
94 void ScrollElasticityHelper::StopSnapRubberbandTimer() { 87 // static
95 timer_active_ = false; 88 ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
96 } 89 LayerTreeHostImpl* layer_tree_host_impl) {
97 90 return new ScrollElasticityHelperImpl(layer_tree_host_impl);
98 void ScrollElasticityHelper::SnapRubberbandTimerFired() {
99 if (timer_active_)
100 layer_tree_host_impl_->SetNeedsAnimate();
101 }
102
103 void ScrollElasticityHelper::AdjustScrollPositionToBoundsIfNecessary() {
104 // TODO(ccameron): This is function is redundant and may be removed.
105 } 91 }
106 92
107 } // namespace cc 93 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scroll_elasticity_helper.h ('k') | cc/layers/heads_up_display_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698