OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 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/input/scroll_elasticity_helper.h" |
| 6 |
| 7 #include "cc/layers/layer_impl.h" |
| 8 #include "cc/trees/layer_tree_host_impl.h" |
| 9 #include "cc/trees/layer_tree_impl.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 ScrollElasticityHelper::ScrollElasticityHelper(LayerTreeHostImpl* layer_tree) |
| 14 : layer_tree_host_impl_(layer_tree), timer_active_(false) { |
| 15 } |
| 16 |
| 17 ScrollElasticityHelper::~ScrollElasticityHelper() { |
| 18 } |
| 19 |
| 20 bool ScrollElasticityHelper::AllowsHorizontalStretching() { |
| 21 // The WebKit implementation has this interface because it is written in terms |
| 22 // of overscrolling on a per-layer basis, not for the whole layer tree. In |
| 23 // that implementation, this always returns true for the frame view's |
| 24 // scrollable area. |
| 25 // TODO(ccameron): This is function is redundant and may be removed. |
| 26 return true; |
| 27 } |
| 28 |
| 29 bool ScrollElasticityHelper::AllowsVerticalStretching() { |
| 30 // TODO(ccameron): This is function is redundant and may be removed. |
| 31 return true; |
| 32 } |
| 33 |
| 34 gfx::Vector2dF ScrollElasticityHelper::StretchAmount() { |
| 35 return stretch_offset_; |
| 36 } |
| 37 |
| 38 bool ScrollElasticityHelper::PinnedInDirection( |
| 39 const gfx::Vector2dF& direction) { |
| 40 gfx::ScrollOffset scroll_offset = |
| 41 layer_tree_host_impl_->active_tree()->TotalScrollOffset(); |
| 42 gfx::ScrollOffset max_scroll_offset = |
| 43 layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset(); |
| 44 bool result = false; |
| 45 if (direction.x() < 0) |
| 46 result |= scroll_offset.x() <= 0; |
| 47 if (direction.x() > 0) |
| 48 result |= scroll_offset.x() >= max_scroll_offset.x(); |
| 49 if (direction.y() < 0) |
| 50 result |= scroll_offset.y() <= 0; |
| 51 if (direction.y() > 0) |
| 52 result |= scroll_offset.y() >= max_scroll_offset.y(); |
| 53 return result; |
| 54 } |
| 55 |
| 56 bool ScrollElasticityHelper::CanScrollHorizontally() { |
| 57 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().x() > 0; |
| 58 } |
| 59 |
| 60 bool ScrollElasticityHelper::CanScrollVertically() { |
| 61 return layer_tree_host_impl_->active_tree()->TotalMaxScrollOffset().y() > 0; |
| 62 } |
| 63 |
| 64 gfx::Vector2dF ScrollElasticityHelper::AbsoluteScrollPosition() { |
| 65 // TODO(ccameron): This is function is redundant and may be removed. |
| 66 return stretch_offset_; |
| 67 } |
| 68 |
| 69 void ScrollElasticityHelper::ImmediateScrollBy(const gfx::Vector2dF& scroll) { |
| 70 // TODO(ccameron): This is function is redundant and may be removed. |
| 71 } |
| 72 |
| 73 void ScrollElasticityHelper::ImmediateScrollByWithoutContentEdgeConstraints( |
| 74 const gfx::Vector2dF& scroll) { |
| 75 stretch_offset_ += scroll; |
| 76 |
| 77 // TODO(ccameron): Update the transform of the appropriate layer in the |
| 78 // LayerTreeHostImpl, and request that a frame be drawn. |
| 79 } |
| 80 |
| 81 void ScrollElasticityHelper::StartSnapRubberbandTimer() { |
| 82 if (timer_active_) |
| 83 return; |
| 84 timer_active_ = true; |
| 85 layer_tree_host_impl_->SetNeedsAnimate(); |
| 86 } |
| 87 |
| 88 void ScrollElasticityHelper::StopSnapRubberbandTimer() { |
| 89 timer_active_ = false; |
| 90 } |
| 91 |
| 92 void ScrollElasticityHelper::SnapRubberbandTimerFired() { |
| 93 if (timer_active_) |
| 94 layer_tree_host_impl_->SetNeedsAnimate(); |
| 95 } |
| 96 |
| 97 void ScrollElasticityHelper::AdjustScrollPositionToBoundsIfNecessary() { |
| 98 // TODO(ccameron): This is function is redundant and may be removed. |
| 99 } |
| 100 |
| 101 } // namespace cc |
OLD | NEW |