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