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

Side by Side Diff: cc/layers/viewport.cc

Issue 1866583002: Connect LTHI::ScrollAnimated to cc::Viewport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 8 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
« no previous file with comments | « cc/layers/viewport.h ('k') | cc/layers/viewport_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/layers/viewport.h" 5 #include "cc/layers/viewport.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "cc/input/top_controls_manager.h" 8 #include "cc/input/top_controls_manager.h"
9 #include "cc/trees/layer_tree_host_impl.h" 9 #include "cc/trees/layer_tree_host_impl.h"
10 #include "cc/trees/layer_tree_impl.h" 10 #include "cc/trees/layer_tree_impl.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 scroll_tree.Node(OuterScrollLayer()->scroll_tree_index()); 57 scroll_tree.Node(OuterScrollLayer()->scroll_tree_index());
58 pending_content_delta -= host_impl_->ScrollSingleNode( 58 pending_content_delta -= host_impl_->ScrollSingleNode(
59 outer_node, pending_content_delta, viewport_point, is_direct_manipulation, 59 outer_node, pending_content_delta, viewport_point, is_direct_manipulation,
60 &scroll_tree); 60 &scroll_tree);
61 result.consumed_delta = delta - AdjustOverscroll(pending_content_delta); 61 result.consumed_delta = delta - AdjustOverscroll(pending_content_delta);
62 62
63 result.content_scrolled_delta = content_delta - pending_content_delta; 63 result.content_scrolled_delta = content_delta - pending_content_delta;
64 return result; 64 return result;
65 } 65 }
66 66
67 bool Viewport::ShouldAnimateViewport(const gfx::Vector2dF& viewport_delta,
68 const gfx::Vector2dF& pending_delta) {
69 float max_dim_viewport_delta =
70 std::max(std::abs(viewport_delta.x()), std::abs(viewport_delta.y()));
71 float max_dim_pending_delta =
72 std::max(std::abs(pending_delta.x()), std::abs(pending_delta.y()));
73 return max_dim_viewport_delta > max_dim_pending_delta;
74 }
75
76 gfx::Vector2dF Viewport::ScrollAnimated(const gfx::Vector2dF& delta) {
77 ScrollTree& scroll_tree =
78 host_impl_->active_tree()->property_trees()->scroll_tree;
79
80 float scale_factor = host_impl_->active_tree()->current_page_scale_factor();
81 gfx::Vector2dF scaled_delta = delta;
82 scaled_delta.Scale(1.f / scale_factor);
83
84 ScrollNode* inner_node =
85 scroll_tree.Node(InnerScrollLayer()->scroll_tree_index());
86 gfx::Vector2dF inner_delta =
87 host_impl_->ComputeScrollDelta(inner_node, delta);
88
89 gfx::Vector2dF pending_delta = scaled_delta - inner_delta;
90 pending_delta.Scale(scale_factor);
91
92 ScrollNode* outer_node =
93 scroll_tree.Node(OuterScrollLayer()->scroll_tree_index());
94 gfx::Vector2dF outer_delta =
95 host_impl_->ComputeScrollDelta(outer_node, pending_delta);
96
97 if (inner_delta.IsZero() && outer_delta.IsZero())
98 return gfx::Vector2dF(0, 0);
99
100 // Animate the viewport to which the majority of scroll delta will be applied.
101 // The animation system only supports running one scroll offset animation.
102 // TODO(ymalik): Fix the visible jump seen by instant scrolling one of the
103 // viewports.
104 bool will_animate = false;
105 if (ShouldAnimateViewport(inner_delta, outer_delta)) {
106 scroll_tree.ScrollBy(outer_node, outer_delta, host_impl_->active_tree());
107 will_animate = host_impl_->ScrollAnimationCreate(inner_node, inner_delta);
108 } else {
109 scroll_tree.ScrollBy(inner_node, inner_delta, host_impl_->active_tree());
110 will_animate = host_impl_->ScrollAnimationCreate(outer_node, outer_delta);
111 }
112
113 if (will_animate) {
114 // Consume entire scroll delta as long as we are starting an animation.
115 return delta;
116 }
117
118 pending_delta = scaled_delta - inner_delta - outer_delta;
119 pending_delta.Scale(scale_factor);
120 return pending_delta;
121 }
122
67 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) { 123 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) {
68 gfx::SizeF viewport_size = gfx::SizeF( 124 gfx::SizeF viewport_size = gfx::SizeF(
69 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds()); 125 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds());
70 126
71 if (anchor.x() < kPinchZoomSnapMarginDips) 127 if (anchor.x() < kPinchZoomSnapMarginDips)
72 pinch_anchor_adjustment_.set_x(-anchor.x()); 128 pinch_anchor_adjustment_.set_x(-anchor.x());
73 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips) 129 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips)
74 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x()); 130 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x());
75 131
76 if (anchor.y() < kPinchZoomSnapMarginDips) 132 if (anchor.y() < kPinchZoomSnapMarginDips)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 233
178 LayerImpl* Viewport::InnerScrollLayer() const { 234 LayerImpl* Viewport::InnerScrollLayer() const {
179 return host_impl_->InnerViewportScrollLayer(); 235 return host_impl_->InnerViewportScrollLayer();
180 } 236 }
181 237
182 LayerImpl* Viewport::OuterScrollLayer() const { 238 LayerImpl* Viewport::OuterScrollLayer() const {
183 return host_impl_->OuterViewportScrollLayer(); 239 return host_impl_->OuterViewportScrollLayer();
184 } 240 }
185 241
186 } // namespace cc 242 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/viewport.h ('k') | cc/layers/viewport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698