| 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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/input/top_controls_manager.h" | 9 #include "cc/input/top_controls_manager.h" |
| 10 #include "cc/trees/layer_tree_host_impl.h" | 10 #include "cc/trees/layer_tree_host_impl.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 bool Viewport::ShouldAnimateViewport(const gfx::Vector2dF& viewport_delta, | 71 bool Viewport::ShouldAnimateViewport(const gfx::Vector2dF& viewport_delta, |
| 72 const gfx::Vector2dF& pending_delta) { | 72 const gfx::Vector2dF& pending_delta) { |
| 73 float max_dim_viewport_delta = | 73 float max_dim_viewport_delta = |
| 74 std::max(std::abs(viewport_delta.x()), std::abs(viewport_delta.y())); | 74 std::max(std::abs(viewport_delta.x()), std::abs(viewport_delta.y())); |
| 75 float max_dim_pending_delta = | 75 float max_dim_pending_delta = |
| 76 std::max(std::abs(pending_delta.x()), std::abs(pending_delta.y())); | 76 std::max(std::abs(pending_delta.x()), std::abs(pending_delta.y())); |
| 77 return max_dim_viewport_delta > max_dim_pending_delta; | 77 return max_dim_viewport_delta > max_dim_pending_delta; |
| 78 } | 78 } |
| 79 | 79 |
| 80 gfx::Vector2dF Viewport::ScrollAnimated(const gfx::Vector2dF& delta) { | 80 gfx::Vector2dF Viewport::ScrollAnimated(const gfx::Vector2dF& delta, |
| 81 base::TimeDelta delayed_by) { |
| 81 if (!OuterScrollLayer()) | 82 if (!OuterScrollLayer()) |
| 82 return gfx::Vector2dF(0, 0); | 83 return gfx::Vector2dF(0, 0); |
| 83 | 84 |
| 84 ScrollTree& scroll_tree = | 85 ScrollTree& scroll_tree = |
| 85 host_impl_->active_tree()->property_trees()->scroll_tree; | 86 host_impl_->active_tree()->property_trees()->scroll_tree; |
| 86 | 87 |
| 87 float scale_factor = host_impl_->active_tree()->current_page_scale_factor(); | 88 float scale_factor = host_impl_->active_tree()->current_page_scale_factor(); |
| 88 gfx::Vector2dF scaled_delta = delta; | 89 gfx::Vector2dF scaled_delta = delta; |
| 89 scaled_delta.Scale(1.f / scale_factor); | 90 scaled_delta.Scale(1.f / scale_factor); |
| 90 | 91 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 if (inner_delta.IsZero() && outer_delta.IsZero()) | 105 if (inner_delta.IsZero() && outer_delta.IsZero()) |
| 105 return gfx::Vector2dF(0, 0); | 106 return gfx::Vector2dF(0, 0); |
| 106 | 107 |
| 107 // Animate the viewport to which the majority of scroll delta will be applied. | 108 // Animate the viewport to which the majority of scroll delta will be applied. |
| 108 // The animation system only supports running one scroll offset animation. | 109 // The animation system only supports running one scroll offset animation. |
| 109 // TODO(ymalik): Fix the visible jump seen by instant scrolling one of the | 110 // TODO(ymalik): Fix the visible jump seen by instant scrolling one of the |
| 110 // viewports. | 111 // viewports. |
| 111 bool will_animate = false; | 112 bool will_animate = false; |
| 112 if (ShouldAnimateViewport(inner_delta, outer_delta)) { | 113 if (ShouldAnimateViewport(inner_delta, outer_delta)) { |
| 113 scroll_tree.ScrollBy(outer_node, outer_delta, host_impl_->active_tree()); | 114 scroll_tree.ScrollBy(outer_node, outer_delta, host_impl_->active_tree()); |
| 114 will_animate = host_impl_->ScrollAnimationCreate(inner_node, inner_delta); | 115 will_animate = |
| 116 host_impl_->ScrollAnimationCreate(inner_node, inner_delta, delayed_by); |
| 115 } else { | 117 } else { |
| 116 scroll_tree.ScrollBy(inner_node, inner_delta, host_impl_->active_tree()); | 118 scroll_tree.ScrollBy(inner_node, inner_delta, host_impl_->active_tree()); |
| 117 will_animate = host_impl_->ScrollAnimationCreate(outer_node, outer_delta); | 119 will_animate = |
| 120 host_impl_->ScrollAnimationCreate(outer_node, outer_delta, delayed_by); |
| 118 } | 121 } |
| 119 | 122 |
| 120 if (will_animate) { | 123 if (will_animate) { |
| 121 // Consume entire scroll delta as long as we are starting an animation. | 124 // Consume entire scroll delta as long as we are starting an animation. |
| 122 return delta; | 125 return delta; |
| 123 } | 126 } |
| 124 | 127 |
| 125 pending_delta = scaled_delta - inner_delta - outer_delta; | 128 pending_delta = scaled_delta - inner_delta - outer_delta; |
| 126 pending_delta.Scale(scale_factor); | 129 pending_delta.Scale(scale_factor); |
| 127 return pending_delta; | 130 return pending_delta; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 243 |
| 241 LayerImpl* Viewport::InnerScrollLayer() const { | 244 LayerImpl* Viewport::InnerScrollLayer() const { |
| 242 return host_impl_->InnerViewportScrollLayer(); | 245 return host_impl_->InnerViewportScrollLayer(); |
| 243 } | 246 } |
| 244 | 247 |
| 245 LayerImpl* Viewport::OuterScrollLayer() const { | 248 LayerImpl* Viewport::OuterScrollLayer() const { |
| 246 return host_impl_->OuterViewportScrollLayer(); | 249 return host_impl_->OuterViewportScrollLayer(); |
| 247 } | 250 } |
| 248 | 251 |
| 249 } // namespace cc | 252 } // namespace cc |
| OLD | NEW |