blob: 6b55182098e0ab38248b953be6efc2ecc0533700 (
plain)
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
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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 "cc/layers/layer_impl.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
namespace cc {
class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
public:
explicit ScrollElasticityHelperImpl(LayerTreeHostImpl* layer_tree_host_impl);
~ScrollElasticityHelperImpl() override;
bool IsUserScrollable() const override;
gfx::Vector2dF StretchAmount() const override;
void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
gfx::ScrollOffset ScrollOffset() const override;
gfx::ScrollOffset MaxScrollOffset() const override;
void ScrollBy(const gfx::Vector2dF& delta) override;
void RequestOneBeginFrame() override;
private:
LayerTreeHostImpl* layer_tree_host_impl_;
};
ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
LayerTreeHostImpl* layer_tree)
: layer_tree_host_impl_(layer_tree) {
}
ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
}
bool ScrollElasticityHelperImpl::IsUserScrollable() const {
LayerImpl* layer = layer_tree_host_impl_->OuterViewportScrollLayer();
if (!layer)
return false;
return layer->user_scrollable_horizontal() ||
layer->user_scrollable_vertical();
}
gfx::Vector2dF ScrollElasticityHelperImpl::StretchAmount() const {
return layer_tree_host_impl_->active_tree()->elastic_overscroll()->Current(
true);
}
void ScrollElasticityHelperImpl::SetStretchAmount(
const gfx::Vector2dF& stretch_amount) {
if (stretch_amount == StretchAmount())
return;
layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
stretch_amount);
layer_tree_host_impl_->active_tree()->set_needs_update_draw_properties();
layer_tree_host_impl_->SetNeedsCommit();
layer_tree_host_impl_->SetNeedsRedraw();
layer_tree_host_impl_->SetFullRootLayerDamage();
}
gfx::ScrollOffset ScrollElasticityHelperImpl::ScrollOffset() const {
return layer_tree_host_impl_->active_tree()->TotalScrollOffset();
}
gfx::ScrollOffset ScrollElasticityHelperImpl::MaxScrollOffset() const {
return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset();
}
void ScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF& delta) {
LayerImpl* root_scroll_layer =
layer_tree_host_impl_->OuterViewportScrollLayer()
? layer_tree_host_impl_->OuterViewportScrollLayer()
: layer_tree_host_impl_->InnerViewportScrollLayer();
if (root_scroll_layer)
root_scroll_layer->ScrollBy(delta);
}
void ScrollElasticityHelperImpl::RequestOneBeginFrame() {
layer_tree_host_impl_->SetNeedsOneBeginImplFrame();
}
// static
ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
LayerTreeHostImpl* layer_tree_host_impl) {
return new ScrollElasticityHelperImpl(layer_tree_host_impl);
}
} // namespace cc
|