OLD | NEW |
---|---|
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 Loading... | |
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::abs(viewport_delta.x()) > std::abs(viewport_delta.y()) | |
71 ? viewport_delta.x() | |
72 : viewport_delta.y(); | |
73 float max_dim_pending_delta = | |
74 std::abs(pending_delta.x()) > std::abs(pending_delta.y()) | |
75 ? pending_delta.x() | |
76 : pending_delta.y(); | |
77 return std::abs(max_dim_viewport_delta) > std::abs(max_dim_pending_delta); | |
bokan
2016/04/06 13:35:52
If you want to animate the viewport which will scr
ymalik
2016/04/06 15:33:45
I think the animation duration is determined by th
bokan
2016/04/06 19:38:23
Ok, this is fine then. IMO, std::max(viewport_delt
| |
78 } | |
79 | |
80 gfx::Vector2dF Viewport::ScrollAnimated(const gfx::Vector2dF& delta) { | |
81 ScrollTree& scroll_tree = | |
82 host_impl_->active_tree()->property_trees()->scroll_tree; | |
83 | |
84 float scale_factor = host_impl_->active_tree()->current_page_scale_factor(); | |
85 gfx::Vector2dF scaled_delta = delta; | |
86 scaled_delta.Scale(1.f / scale_factor); | |
87 | |
88 ScrollNode* inner_node = | |
89 scroll_tree.Node(InnerScrollLayer()->scroll_tree_index()); | |
90 LayerTreeHostImpl::ScrollAmount inner_scroll = | |
91 host_impl_->ComputeScrollDelta(inner_node, delta); | |
92 | |
93 // Animate the viewport to which the majority of scroll delta will be applied. | |
94 // The animation system only supports running one scroll offset animation. | |
95 gfx::Vector2dF pending_delta = scaled_delta - inner_scroll.delta; | |
96 bool animating_inner_viewport = | |
97 ShouldAnimateViewport(inner_scroll.delta, pending_delta); | |
bokan
2016/04/06 13:35:52
Shouldn't this compare inner_scroll.delta to outer
ymalik
2016/04/06 15:33:45
Yes, you're right! Done.
| |
98 pending_delta.Scale(scale_factor); | |
99 | |
100 ScrollNode* outer_node = | |
101 scroll_tree.Node(OuterScrollLayer()->scroll_tree_index()); | |
102 LayerTreeHostImpl::ScrollAmount outer_scroll = | |
103 host_impl_->ComputeScrollDelta(outer_node, pending_delta); | |
104 | |
105 if (inner_scroll.delta.IsZero() && outer_scroll.delta.IsZero()) | |
106 return gfx::Vector2dF(0, 0); | |
107 | |
108 bool will_animate = false; | |
109 if (animating_inner_viewport) { | |
110 scroll_tree.ScrollBy(outer_node, outer_scroll.delta, | |
bokan
2016/04/06 13:35:52
Won't this cause a visible "jump"? I would guess t
ymalik
2016/04/06 15:33:45
The jump doesn't look terribly bad IMO. It also on
bokan
2016/04/06 19:38:23
Acknowledged.
| |
111 host_impl_->active_tree()); | |
112 will_animate = host_impl_->ScrollAnimationCreate(inner_node, inner_scroll); | |
113 } else { | |
114 scroll_tree.ScrollBy(inner_node, inner_scroll.delta, | |
115 host_impl_->active_tree()); | |
116 will_animate = host_impl_->ScrollAnimationCreate(outer_node, outer_scroll); | |
117 } | |
118 | |
119 if (will_animate) { | |
120 // Consume entire scroll delta as long as we are starting an animation. | |
121 return delta; | |
122 } | |
123 | |
124 pending_delta = scaled_delta - inner_scroll.delta - outer_scroll.delta; | |
125 pending_delta.Scale(scale_factor); | |
126 return pending_delta; | |
127 } | |
128 | |
67 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) { | 129 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) { |
68 gfx::SizeF viewport_size = gfx::SizeF( | 130 gfx::SizeF viewport_size = gfx::SizeF( |
69 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds()); | 131 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds()); |
70 | 132 |
71 if (anchor.x() < kPinchZoomSnapMarginDips) | 133 if (anchor.x() < kPinchZoomSnapMarginDips) |
72 pinch_anchor_adjustment_.set_x(-anchor.x()); | 134 pinch_anchor_adjustment_.set_x(-anchor.x()); |
73 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips) | 135 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips) |
74 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x()); | 136 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x()); |
75 | 137 |
76 if (anchor.y() < kPinchZoomSnapMarginDips) | 138 if (anchor.y() < kPinchZoomSnapMarginDips) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 239 |
178 LayerImpl* Viewport::InnerScrollLayer() const { | 240 LayerImpl* Viewport::InnerScrollLayer() const { |
179 return host_impl_->InnerViewportScrollLayer(); | 241 return host_impl_->InnerViewportScrollLayer(); |
180 } | 242 } |
181 | 243 |
182 LayerImpl* Viewport::OuterScrollLayer() const { | 244 LayerImpl* Viewport::OuterScrollLayer() const { |
183 return host_impl_->OuterViewportScrollLayer(); | 245 return host_impl_->OuterViewportScrollLayer(); |
184 } | 246 } |
185 | 247 |
186 } // namespace cc | 248 } // namespace cc |
OLD | NEW |