1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
cc / input / scroll_elasticity_helper.cc [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/input/scroll_elasticity_helper.h"
#include "base/memory/raw_ptr.h"
#include "cc/layers/layer_impl.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/scroll_node.h"
namespace cc {
class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
public:
explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* host_impl);
~ScrollElasticityHelperImpl() override;
bool IsUserScrollableHorizontal() const override;
bool IsUserScrollableVertical() const override;
gfx::Vector2dF StretchAmount() const override;
gfx::Size ScrollBounds() const override;
void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
gfx::PointF ScrollOffset() const override;
gfx::PointF MaxScrollOffset() const override;
void ScrollBy(const gfx::Vector2dF& delta) override;
void RequestOneBeginFrame() override;
private:
raw_ptr<LayerTreeHostImpl> host_impl_;
};
ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
LayerTreeHostImpl* layer_tree)
: host_impl_(layer_tree) {}
ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() = default;
bool ScrollElasticityHelperImpl::IsUserScrollableHorizontal() const {
const auto* scroll_node = host_impl_->OuterViewportScrollNode();
if (!scroll_node)
return false;
return scroll_node->user_scrollable_horizontal;
}
bool ScrollElasticityHelperImpl::IsUserScrollableVertical() const {
const auto* scroll_node = host_impl_->OuterViewportScrollNode();
if (!scroll_node)
return false;
return scroll_node->user_scrollable_vertical;
}
gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() const {
return host_impl_->active_tree()->elastic_overscroll()->Current(true);
}
gfx::Size ScrollElasticityHelperImpl::ScrollBounds() const {
return host_impl_->OuterViewportScrollNode()
? host_impl_->OuterViewportScrollNode()->container_bounds
: gfx::Size();
}
void ScrollElasticityHelperImpl::SetStretchAmount(
const gfx::Vector2dF& stretch_amount) {
if (stretch_amount == StretchAmount())
return;
host_impl_->active_tree()->elastic_overscroll()->SetCurrent(stretch_amount);
host_impl_->active_tree()->set_needs_update_draw_properties();
host_impl_->SetNeedsCommit();
host_impl_->SetNeedsRedraw();
host_impl_->SetFullViewportDamage();
}
gfx::PointF ScrollElasticityHelperImpl::ScrollOffset() const {
return host_impl_->active_tree()->TotalScrollOffset();
}
gfx::PointF ScrollElasticityHelperImpl::MaxScrollOffset() const {
return host_impl_->active_tree()->TotalMaxScrollOffset();
}
void ScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF& delta) {
ScrollNode* root_scroll_node = host_impl_->OuterViewportScrollNode()
? host_impl_->OuterViewportScrollNode()
: host_impl_->InnerViewportScrollNode();
if (root_scroll_node) {
LayerTreeImpl* tree_impl = host_impl_->active_tree();
tree_impl->property_trees()->scroll_tree_mutable().ScrollBy(
*root_scroll_node, delta, tree_impl);
}
}
void ScrollElasticityHelperImpl::RequestOneBeginFrame() {
host_impl_->SetNeedsOneBeginImplFrame();
}
// static
ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
LayerTreeHostImpl* host_impl) {
return new ScrollElasticityHelperImpl(host_impl);
}
} // namespace cc