| 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 14 matching lines...) Expand all Loading... |
| 25 DCHECK(host_impl_); | 25 DCHECK(host_impl_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void Viewport::Pan(const gfx::Vector2dF& delta) { | 28 void Viewport::Pan(const gfx::Vector2dF& delta) { |
| 29 gfx::Vector2dF pending_delta = delta; | 29 gfx::Vector2dF pending_delta = delta; |
| 30 float page_scale = host_impl_->active_tree()->current_page_scale_factor(); | 30 float page_scale = host_impl_->active_tree()->current_page_scale_factor(); |
| 31 pending_delta.Scale(1 / page_scale); | 31 pending_delta.Scale(1 / page_scale); |
| 32 InnerScrollLayer()->ScrollBy(pending_delta); | 32 InnerScrollLayer()->ScrollBy(pending_delta); |
| 33 } | 33 } |
| 34 | 34 |
| 35 Viewport::ScrollResult Viewport::ScrollBy(const gfx::Vector2dF& delta, | 35 gfx::Vector2dF Viewport::ScrollBy(const gfx::Vector2dF& delta, |
| 36 const gfx::Point& viewport_point, | 36 const gfx::Point& viewport_point, |
| 37 bool is_wheel_scroll, | 37 bool is_direct_manipulation, |
| 38 bool affect_top_controls) { | 38 bool affect_top_controls) { |
| 39 gfx::Vector2dF content_delta = delta; | 39 gfx::Vector2dF pending_delta = delta; |
| 40 ScrollResult result; | 40 if (affect_top_controls && ShouldTopControlsConsumeScroll(delta)) |
| 41 | 41 pending_delta -= ScrollTopControls(delta); |
| 42 if (affect_top_controls && ShouldTopControlsConsumeScroll(delta)) { | |
| 43 result.top_controls_applied_delta = ScrollTopControls(delta); | |
| 44 content_delta -= result.top_controls_applied_delta; | |
| 45 } | |
| 46 | |
| 47 gfx::Vector2dF pending_content_delta = content_delta; | |
| 48 | 42 |
| 49 if (OuterScrollLayer()) { | 43 if (OuterScrollLayer()) { |
| 50 pending_content_delta -= host_impl_->ScrollLayer(OuterScrollLayer(), | 44 pending_delta -= |
| 51 pending_content_delta, | 45 host_impl_->ScrollLayer(OuterScrollLayer(), pending_delta, |
| 52 viewport_point, | 46 viewport_point, is_direct_manipulation); |
| 53 is_wheel_scroll); | |
| 54 } | 47 } |
| 55 | 48 |
| 56 // TODO(bokan): This shouldn't be needed but removing it causes subtle | 49 // TODO(bokan): This shouldn't be needed but removing it causes subtle |
| 57 // viewport movement during top controls manipulation. | 50 // viewport movement during top controls manipulation. |
| 58 if (!gfx::ToRoundedVector2d(pending_content_delta).IsZero()) { | 51 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
| 59 pending_content_delta -= host_impl_->ScrollLayer(InnerScrollLayer(), | 52 return delta; |
| 60 pending_content_delta, | |
| 61 viewport_point, | |
| 62 is_wheel_scroll); | |
| 63 result.unused_scroll_delta = AdjustOverscroll(pending_content_delta); | |
| 64 } | |
| 65 | 53 |
| 66 | 54 pending_delta -= |
| 67 result.applied_delta = content_delta - pending_content_delta; | 55 host_impl_->ScrollLayer(InnerScrollLayer(), pending_delta, viewport_point, |
| 68 return result; | 56 is_direct_manipulation); |
| 57 pending_delta = AdjustOverscroll(pending_delta); |
| 58 return delta - pending_delta; |
| 69 } | 59 } |
| 70 | 60 |
| 71 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) { | 61 void Viewport::SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor) { |
| 72 gfx::SizeF viewport_size = | 62 gfx::SizeF viewport_size = |
| 73 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds(); | 63 host_impl_->active_tree()->InnerViewportContainerLayer()->bounds(); |
| 74 | 64 |
| 75 if (anchor.x() < kPinchZoomSnapMarginDips) | 65 if (anchor.x() < kPinchZoomSnapMarginDips) |
| 76 pinch_anchor_adjustment_.set_x(-anchor.x()); | 66 pinch_anchor_adjustment_.set_x(-anchor.x()); |
| 77 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips) | 67 else if (anchor.x() > viewport_size.width() - kPinchZoomSnapMarginDips) |
| 78 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x()); | 68 pinch_anchor_adjustment_.set_x(viewport_size.width() - anchor.x()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 187 |
| 198 LayerImpl* Viewport::InnerScrollLayer() const { | 188 LayerImpl* Viewport::InnerScrollLayer() const { |
| 199 return host_impl_->InnerViewportScrollLayer(); | 189 return host_impl_->InnerViewportScrollLayer(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 LayerImpl* Viewport::OuterScrollLayer() const { | 192 LayerImpl* Viewport::OuterScrollLayer() const { |
| 203 return host_impl_->OuterViewportScrollLayer(); | 193 return host_impl_->OuterViewportScrollLayer(); |
| 204 } | 194 } |
| 205 | 195 |
| 206 } // namespace cc | 196 } // namespace cc |
| OLD | NEW |