| 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 #ifndef CC_LAYERS_VIEWPORT_H_ | 5 #ifndef CC_LAYERS_VIEWPORT_H_ |
| 6 #define CC_LAYERS_VIEWPORT_H_ | 6 #define CC_LAYERS_VIEWPORT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // TODO(tdresser): eventually |consumed_delta| should equal | 31 // TODO(tdresser): eventually |consumed_delta| should equal |
| 32 // |content_scrolled_delta|. See crbug.com/510045 for details. | 32 // |content_scrolled_delta|. See crbug.com/510045 for details. |
| 33 struct ScrollResult { | 33 struct ScrollResult { |
| 34 gfx::Vector2dF consumed_delta; | 34 gfx::Vector2dF consumed_delta; |
| 35 gfx::Vector2dF content_scrolled_delta; | 35 gfx::Vector2dF content_scrolled_delta; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 static std::unique_ptr<Viewport> Create(LayerTreeHostImpl* host_impl); | 38 static std::unique_ptr<Viewport> Create(LayerTreeHostImpl* host_impl); |
| 39 | 39 |
| 40 // Differs from scrolling in that only the visual viewport is moved, without | 40 // Differs from scrolling in that only the visual viewport is moved, without |
| 41 // affecting the top controls or outer viewport. | 41 // affecting the browser controls or outer viewport. |
| 42 void Pan(const gfx::Vector2dF& delta); | 42 void Pan(const gfx::Vector2dF& delta); |
| 43 | 43 |
| 44 // Scrolls the viewport, applying the unique bubbling between the inner and | 44 // Scrolls the viewport, applying the unique bubbling between the inner and |
| 45 // outer viewport. Scrolls can be consumed by top controls. | 45 // outer viewport. Scrolls can be consumed by browser controls. |
| 46 ScrollResult ScrollBy(const gfx::Vector2dF& delta, | 46 ScrollResult ScrollBy(const gfx::Vector2dF& delta, |
| 47 const gfx::Point& viewport_point, | 47 const gfx::Point& viewport_point, |
| 48 bool is_wheel_scroll, | 48 bool is_wheel_scroll, |
| 49 bool affect_top_controls); | 49 bool affect_top_controls); |
| 50 | 50 |
| 51 // Scrolls the viewport. Unlike the above method, scrolls the inner before | 51 // Scrolls the viewport. Unlike the above method, scrolls the inner before |
| 52 // the outer viewport. Doesn't affect top controls or return a result since | 52 // the outer viewport. Doesn't affect browser controls or return a result |
| 53 // callers don't need it. | 53 // since callers don't need it. |
| 54 void ScrollByInnerFirst(const gfx::Vector2dF& delta); | 54 void ScrollByInnerFirst(const gfx::Vector2dF& delta); |
| 55 | 55 |
| 56 // Scrolls the viewport, bubbling the delta between the inner and outer | 56 // Scrolls the viewport, bubbling the delta between the inner and outer |
| 57 // viewport. Only animates either of the two viewports. | 57 // viewport. Only animates either of the two viewports. |
| 58 gfx::Vector2dF ScrollAnimated(const gfx::Vector2dF& delta, | 58 gfx::Vector2dF ScrollAnimated(const gfx::Vector2dF& delta, |
| 59 base::TimeDelta delayed_by); | 59 base::TimeDelta delayed_by); |
| 60 | 60 |
| 61 void PinchUpdate(float magnify_delta, const gfx::Point& anchor); | 61 void PinchUpdate(float magnify_delta, const gfx::Point& anchor); |
| 62 void PinchEnd(); | 62 void PinchEnd(); |
| 63 | 63 |
| 64 // Returns the "representative" viewport layer. That is, the one that's set | 64 // Returns the "representative" viewport layer. That is, the one that's set |
| 65 // as the currently scrolling layer when the viewport scrolls and the one used | 65 // as the currently scrolling layer when the viewport scrolls and the one used |
| 66 // in the scrolling code to indicate scrolling should happen via this class. | 66 // in the scrolling code to indicate scrolling should happen via this class. |
| 67 LayerImpl* MainScrollLayer() const; | 67 LayerImpl* MainScrollLayer() const; |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 explicit Viewport(LayerTreeHostImpl* host_impl); | 70 explicit Viewport(LayerTreeHostImpl* host_impl); |
| 71 | 71 |
| 72 // Returns true if viewport_delta is stricly less than pending_delta. | 72 // Returns true if viewport_delta is stricly less than pending_delta. |
| 73 static bool ShouldAnimateViewport(const gfx::Vector2dF& viewport_delta, | 73 static bool ShouldAnimateViewport(const gfx::Vector2dF& viewport_delta, |
| 74 const gfx::Vector2dF& pending_delta); | 74 const gfx::Vector2dF& pending_delta); |
| 75 bool ShouldTopControlsConsumeScroll(const gfx::Vector2dF& scroll_delta) const; | 75 bool ShouldBrowserControlsConsumeScroll( |
| 76 const gfx::Vector2dF& scroll_delta) const; |
| 76 gfx::Vector2dF AdjustOverscroll(const gfx::Vector2dF& delta) const; | 77 gfx::Vector2dF AdjustOverscroll(const gfx::Vector2dF& delta) const; |
| 77 | 78 |
| 78 // Sends the delta to the top controls, returns the amount applied. | 79 // Sends the delta to the browser controls, returns the amount applied. |
| 79 gfx::Vector2dF ScrollTopControls(const gfx::Vector2dF& delta); | 80 gfx::Vector2dF ScrollBrowserControls(const gfx::Vector2dF& delta); |
| 80 | 81 |
| 81 gfx::ScrollOffset MaxTotalScrollOffset() const; | 82 gfx::ScrollOffset MaxTotalScrollOffset() const; |
| 82 gfx::ScrollOffset TotalScrollOffset() const; | 83 gfx::ScrollOffset TotalScrollOffset() const; |
| 83 | 84 |
| 84 LayerImpl* InnerScrollLayer() const; | 85 LayerImpl* InnerScrollLayer() const; |
| 85 LayerImpl* OuterScrollLayer() const; | 86 LayerImpl* OuterScrollLayer() const; |
| 86 | 87 |
| 87 void SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor); | 88 void SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor); |
| 88 | 89 |
| 89 LayerTreeHostImpl* host_impl_; | 90 LayerTreeHostImpl* host_impl_; |
| 90 | 91 |
| 91 bool pinch_zoom_active_; | 92 bool pinch_zoom_active_; |
| 92 | 93 |
| 93 // The pinch zoom anchor point is adjusted by this amount during a pinch. This | 94 // The pinch zoom anchor point is adjusted by this amount during a pinch. This |
| 94 // is used to "snap" a pinch-zoom to the edge of the screen. | 95 // is used to "snap" a pinch-zoom to the edge of the screen. |
| 95 gfx::Vector2d pinch_anchor_adjustment_; | 96 gfx::Vector2d pinch_anchor_adjustment_; |
| 96 | 97 |
| 97 FRIEND_TEST_ALL_PREFIXES(ViewportTest, ShouldAnimateViewport); | 98 FRIEND_TEST_ALL_PREFIXES(ViewportTest, ShouldAnimateViewport); |
| 98 | 99 |
| 99 DISALLOW_COPY_AND_ASSIGN(Viewport); | 100 DISALLOW_COPY_AND_ASSIGN(Viewport); |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 } // namespace cc | 103 } // namespace cc |
| 103 | 104 |
| 104 #endif // CC_LAYERS_VIEWPORT_H_ | 105 #endif // CC_LAYERS_VIEWPORT_H_ |
| OLD | NEW |