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

Unified Diff: cc/input/scroll_elasticity_helper.cc

Issue 2194833002: Overscroll and Elasticity for views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@20160728-MacViews-RouteThroughInputHandler
Patch Set: Restore functionality and fix bugs \o/ Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/input/scroll_elasticity_helper.h ('k') | cc/input/scroll_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/input/scroll_elasticity_helper.cc
diff --git a/cc/input/scroll_elasticity_helper.cc b/cc/input/scroll_elasticity_helper.cc
index 413d64f6bf9b285a35e599e39f5aa0fb4cb28700..901f8b242ddd3475ff57f1aa996b08ed0d6a0325 100644
--- a/cc/input/scroll_elasticity_helper.cc
+++ b/cc/input/scroll_elasticity_helper.cc
@@ -4,11 +4,14 @@
#include "cc/input/scroll_elasticity_helper.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
namespace cc {
+namespace {
class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
public:
@@ -23,14 +26,21 @@ class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
void ScrollBy(const gfx::Vector2dF& delta) override;
void RequestOneBeginFrame() override;
+ base::WeakPtr<ScrollElasticityHelper> GetWeakPtr() override {
+ return weak_ptr_factory_.GetWeakPtr();
+ }
+
private:
LayerTreeHostImpl* layer_tree_host_impl_;
+
+ base::WeakPtrFactory<ScrollElasticityHelperImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScrollElasticityHelperImpl);
};
ScrollElasticityHelperImpl::ScrollElasticityHelperImpl(
LayerTreeHostImpl* layer_tree)
- : layer_tree_host_impl_(layer_tree) {
-}
+ : layer_tree_host_impl_(layer_tree), weak_ptr_factory_(this) {}
ScrollElasticityHelperImpl::~ScrollElasticityHelperImpl() {
}
@@ -82,6 +92,99 @@ void ScrollElasticityHelperImpl::RequestOneBeginFrame() {
layer_tree_host_impl_->SetNeedsOneBeginImplFrame();
}
+class LayerScrollElasticityHelperImpl : public ScrollElasticityHelper {
+ public:
+ LayerScrollElasticityHelperImpl(int layer_scroll_layer_id,
+ LayerTreeHostImpl* layer_tree_host_impl);
+
+ 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;
+
+ base::WeakPtr<ScrollElasticityHelper> GetWeakPtr() override {
+ return weak_ptr_factory_.GetWeakPtr();
+ }
+
+ private:
+ LayerImpl* layer() const;
+
+ LayerTreeHostImpl* layer_tree_host_impl_;
+ int layer_scroll_layer_id_;
+
+ base::WeakPtrFactory<LayerScrollElasticityHelperImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerScrollElasticityHelperImpl);
+};
+
+LayerScrollElasticityHelperImpl::LayerScrollElasticityHelperImpl(
+ int layer_scroll_layer_id,
+ LayerTreeHostImpl* layer_tree_host_impl)
+ : layer_tree_host_impl_(layer_tree_host_impl),
+ layer_scroll_layer_id_(layer_scroll_layer_id),
+ weak_ptr_factory_(this) {}
+
+bool LayerScrollElasticityHelperImpl::IsUserScrollable() const {
+ // LayerTreeHostImpl wouldn't have created |this| in the first place if the
+ // layer wasn't user-scrollable.
+ return true;
+}
+
+gfx::Vector2dF LayerScrollElasticityHelperImpl::StretchAmount() const {
+ return ScrollOffsetToVector2dF(layer()->CurrentOverscroll());
+}
+
+void LayerScrollElasticityHelperImpl::SetStretchAmount(
+ const gfx::Vector2dF& stretch_amount) {
+ if (stretch_amount == StretchAmount())
+ return;
+
+ layer()->SetCurrentOverscroll(gfx::ScrollOffset(stretch_amount));
+
+ // For now, also inform the LayerTreeImpl of the stretch amount. This will
+ // then get redistributed over the scrolling layer.
+ // TODO(tapted): Remove this - it shouldn't be necessary.
+ layer_tree_host_impl_->active_tree()->elastic_overscroll()->SetCurrent(
+ stretch_amount);
+ layer_tree_host_impl_->SetNeedsCommit();
+}
+
+gfx::ScrollOffset LayerScrollElasticityHelperImpl::ScrollOffset() const {
+ return layer()->CurrentScrollOffset();
+}
+
+gfx::ScrollOffset LayerScrollElasticityHelperImpl::MaxScrollOffset() const {
+ return layer()->MaxScrollOffset();
+}
+
+void LayerScrollElasticityHelperImpl::ScrollBy(const gfx::Vector2dF& delta) {
+ layer()->ScrollBy(delta);
+}
+
+void LayerScrollElasticityHelperImpl::RequestOneBeginFrame() {
+ layer_tree_host_impl_->SetNeedsOneBeginImplFrame();
+}
+
+LayerImpl* LayerScrollElasticityHelperImpl::layer() const {
+ LayerImpl* scrolling_layer =
+ layer_tree_host_impl_->active_tree()->FindActiveTreeLayerById(
+ layer_scroll_layer_id_);
+ return scrolling_layer;
+}
+
+} // namespace
+
+// static
+std::unique_ptr<ScrollElasticityHelper> ScrollElasticityHelper::CreateForLayer(
+ int layer_scroll_layer_id,
+ LayerTreeHostImpl* layer_tree_host_impl) {
+ return base::MakeUnique<LayerScrollElasticityHelperImpl>(
+ layer_scroll_layer_id, layer_tree_host_impl);
+}
+
// static
ScrollElasticityHelper* ScrollElasticityHelper::CreateForLayerTreeHostImpl(
LayerTreeHostImpl* layer_tree_host_impl) {
« no previous file with comments | « cc/input/scroll_elasticity_helper.h ('k') | cc/input/scroll_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698