Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
aelias_OOO_until_Jul13
2015/03/25 19:56:06
nit: 2015
bokan
2015/03/25 20:38:34
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/layers/viewport.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "cc/input/top_controls_manager.h" | |
| 9 #include "cc/trees/layer_tree_host_impl.h" | |
| 10 #include "cc/trees/layer_tree_impl.h" | |
| 11 #include "ui/gfx/geometry/vector2d_conversions.h" | |
| 12 #include "ui/gfx/geometry/vector2d_f.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 | |
| 16 // static | |
| 17 scoped_ptr<Viewport> Viewport::Create( | |
| 18 LayerTreeHostImpl* host_impl) { | |
| 19 return make_scoped_ptr(new Viewport(host_impl)); | |
| 20 } | |
| 21 | |
| 22 Viewport::Viewport(LayerTreeHostImpl* host_impl) | |
| 23 : host_impl_(host_impl) { | |
| 24 DCHECK(host_impl_); | |
| 25 } | |
| 26 | |
| 27 Viewport::ScrollResult Viewport::ScrollBy(const gfx::Vector2dF& delta, | |
| 28 const gfx::Point& viewport_point, | |
| 29 bool is_wheel_scroll) { | |
| 30 gfx::Vector2dF content_delta = delta; | |
| 31 ScrollResult result; | |
| 32 | |
| 33 if (ShouldTopControlsConsumeScroll(delta)) { | |
| 34 gfx::Vector2dF applied = ScrollTopControls(delta); | |
| 35 result.did_scroll_top_controls = applied.y() != 0; | |
| 36 content_delta -= applied; | |
| 37 } | |
| 38 | |
| 39 gfx::Vector2dF pending_content_delta = content_delta; | |
| 40 | |
| 41 if (OuterScrollLayer()) { | |
|
aelias_OOO_until_Jul13
2015/03/25 19:56:07
This if statement here seems weird. The nonexiste
bokan
2015/03/25 20:38:34
I think I've run into real-world cases that don't
| |
| 42 pending_content_delta -= host_impl_->ScrollLayer(OuterScrollLayer(), | |
| 43 pending_content_delta, | |
| 44 viewport_point, | |
| 45 is_wheel_scroll); | |
| 46 } | |
| 47 | |
| 48 if (!gfx::ToRoundedVector2d(pending_content_delta).IsZero()) { | |
|
aelias_OOO_until_Jul13
2015/03/25 19:56:07
This looks questionably useful, please fix or add
bokan
2015/03/25 20:38:34
I thought so too but removing it caused the viewpo
| |
| 49 pending_content_delta -= host_impl_->ScrollLayer(InnerScrollLayer(), | |
| 50 pending_content_delta, | |
| 51 viewport_point, | |
| 52 is_wheel_scroll); | |
| 53 result.unused_scroll_delta = AdjustOverscroll(pending_content_delta); | |
| 54 } | |
| 55 | |
| 56 | |
| 57 result.applied_delta = content_delta - pending_content_delta; | |
| 58 return result; | |
| 59 } | |
| 60 | |
| 61 gfx::Vector2dF Viewport::ScrollTopControls(const gfx::Vector2dF& delta) { | |
| 62 gfx::Vector2dF excess_delta = | |
| 63 host_impl_->top_controls_manager()->ScrollBy(delta); | |
| 64 | |
| 65 return delta - excess_delta; | |
| 66 } | |
| 67 | |
| 68 bool Viewport::ShouldTopControlsConsumeScroll( | |
| 69 const gfx::Vector2dF& scroll_delta) const { | |
| 70 // Always consume if it's in the direction to show the top controls. | |
| 71 if (scroll_delta.y() < 0) | |
| 72 return true; | |
| 73 | |
| 74 if (TotalScrollOffset().y() < MaxTotalScrollOffset().y()) | |
| 75 return true; | |
| 76 | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 gfx::Vector2dF Viewport::AdjustOverscroll(const gfx::Vector2dF& delta) const { | |
| 81 const float kEpsilon = 0.1f; | |
| 82 gfx::Vector2dF adjusted = delta; | |
| 83 | |
| 84 if (std::abs(adjusted.x()) < kEpsilon) | |
| 85 adjusted.set_x(0.0f); | |
| 86 if (std::abs(adjusted.y()) < kEpsilon) | |
| 87 adjusted.set_y(0.0f); | |
| 88 | |
| 89 // Disable overscroll on axes which are impossible to scroll. | |
| 90 if (host_impl_->settings().report_overscroll_only_for_scrollable_axes) { | |
| 91 if (std::abs(MaxTotalScrollOffset().x()) <= kEpsilon || | |
| 92 !InnerScrollLayer()->user_scrollable_horizontal()) | |
| 93 adjusted.set_x(0.0f); | |
| 94 if (std::abs(MaxTotalScrollOffset().y()) <= kEpsilon || | |
| 95 !InnerScrollLayer()->user_scrollable_vertical()) | |
| 96 adjusted.set_y(0.0f); | |
| 97 } | |
| 98 | |
| 99 return adjusted; | |
| 100 } | |
| 101 | |
| 102 gfx::ScrollOffset Viewport::MaxTotalScrollOffset() const { | |
| 103 gfx::ScrollOffset offset; | |
| 104 | |
| 105 offset += InnerScrollLayer()->MaxScrollOffset(); | |
| 106 | |
| 107 if (OuterScrollLayer()) | |
| 108 offset += OuterScrollLayer()->MaxScrollOffset(); | |
| 109 | |
| 110 return offset; | |
| 111 } | |
| 112 | |
| 113 gfx::ScrollOffset Viewport::TotalScrollOffset() const { | |
| 114 gfx::ScrollOffset offset; | |
| 115 | |
| 116 offset += InnerScrollLayer()->CurrentScrollOffset(); | |
| 117 | |
| 118 if (OuterScrollLayer()) | |
| 119 offset += OuterScrollLayer()->CurrentScrollOffset(); | |
| 120 | |
| 121 return offset; | |
| 122 } | |
| 123 | |
| 124 LayerImpl* Viewport::InnerScrollLayer() const { | |
| 125 return host_impl_->InnerViewportScrollLayer(); | |
| 126 } | |
| 127 | |
| 128 LayerImpl* Viewport::OuterScrollLayer() const { | |
| 129 return host_impl_->OuterViewportScrollLayer(); | |
| 130 } | |
| 131 | |
| 132 } // namespace cc | |
| OLD | NEW |