OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 3010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3021 | 3021 |
3022 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { | 3022 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { |
3023 public: | 3023 public: |
3024 TestScrollOffsetDelegate() | 3024 TestScrollOffsetDelegate() |
3025 : page_scale_factor_(0.f), | 3025 : page_scale_factor_(0.f), |
3026 min_page_scale_factor_(-1.f), | 3026 min_page_scale_factor_(-1.f), |
3027 max_page_scale_factor_(-1.f) {} | 3027 max_page_scale_factor_(-1.f) {} |
3028 | 3028 |
3029 virtual ~TestScrollOffsetDelegate() {} | 3029 virtual ~TestScrollOffsetDelegate() {} |
3030 | 3030 |
3031 virtual void SetMaxScrollOffset( | |
3032 const gfx::Vector2dF& max_scroll_offset) OVERRIDE { | |
3033 max_scroll_offset_ = max_scroll_offset; | |
3034 } | |
3035 | |
3036 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE { | |
3037 last_set_scroll_offset_ = new_value; | |
3038 } | |
3039 | |
3040 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { | 3031 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { |
3041 return getter_return_value_; | 3032 return getter_return_value_; |
3042 } | 3033 } |
3043 | 3034 |
3044 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } | 3035 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } |
3045 | 3036 |
3046 virtual void SetTotalPageScaleFactorAndLimits( | 3037 virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, |
3047 float page_scale_factor, | 3038 const gfx::Vector2dF& max_scroll_offset, |
3048 float min_page_scale_factor, | 3039 const gfx::SizeF& scrollable_size, |
3049 float max_page_scale_factor) OVERRIDE { | 3040 float page_scale_factor, |
| 3041 float min_page_scale_factor, |
| 3042 float max_page_scale_factor) OVERRIDE { |
| 3043 DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); |
| 3044 DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); |
| 3045 last_set_scroll_offset_ = total_scroll_offset; |
| 3046 max_scroll_offset_ = max_scroll_offset; |
| 3047 scrollable_size_ = scrollable_size; |
3050 page_scale_factor_ = page_scale_factor; | 3048 page_scale_factor_ = page_scale_factor; |
3051 min_page_scale_factor_ = min_page_scale_factor; | 3049 min_page_scale_factor_ = min_page_scale_factor; |
3052 max_page_scale_factor_ = max_page_scale_factor; | 3050 max_page_scale_factor_ = max_page_scale_factor; |
3053 } | 3051 } |
3054 | 3052 |
3055 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE { | |
3056 scrollable_size_ = scrollable_size; | |
3057 } | |
3058 | |
3059 gfx::Vector2dF last_set_scroll_offset() { | 3053 gfx::Vector2dF last_set_scroll_offset() { |
3060 return last_set_scroll_offset_; | 3054 return last_set_scroll_offset_; |
3061 } | 3055 } |
3062 | 3056 |
3063 void set_getter_return_value(const gfx::Vector2dF& value) { | 3057 void set_getter_return_value(const gfx::Vector2dF& value) { |
3064 getter_return_value_ = value; | 3058 getter_return_value_ = value; |
3065 } | 3059 } |
3066 | 3060 |
3067 gfx::Vector2dF max_scroll_offset() const { | 3061 gfx::Vector2dF max_scroll_offset() const { |
3068 return max_scroll_offset_; | 3062 return max_scroll_offset_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3125 host_impl_->active_tree()->SetPageScaleDelta(1.5f); | 3119 host_impl_->active_tree()->SetPageScaleDelta(1.5f); |
3126 EXPECT_EQ(3.f, scroll_delegate.page_scale_factor()); | 3120 EXPECT_EQ(3.f, scroll_delegate.page_scale_factor()); |
3127 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); | 3121 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); |
3128 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); | 3122 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); |
3129 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 3123 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
3130 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 3124 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
3131 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); | 3125 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); |
3132 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); | 3126 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); |
3133 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); | 3127 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); |
3134 | 3128 |
| 3129 // The pinch gesture doesn't put the delegate into a state where the scroll |
| 3130 // offset is outside of the scroll range. (this is verified by DCHECKs in the |
| 3131 // delegate). |
| 3132 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
| 3133 host_impl_->PinchGestureBegin(); |
| 3134 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
| 3135 host_impl_->PinchGestureUpdate(.5f, gfx::Point()); |
| 3136 host_impl_->PinchGestureEnd(); |
| 3137 host_impl_->ScrollEnd(); |
| 3138 |
3135 // Scrolling should be relative to the offset as returned by the delegate. | 3139 // Scrolling should be relative to the offset as returned by the delegate. |
3136 gfx::Vector2dF scroll_delta(0.f, 10.f); | 3140 gfx::Vector2dF scroll_delta(0.f, 10.f); |
3137 gfx::Vector2dF current_offset(7.f, 8.f); | 3141 gfx::Vector2dF current_offset(7.f, 8.f); |
3138 | 3142 |
3139 scroll_delegate.set_getter_return_value(current_offset); | 3143 scroll_delegate.set_getter_return_value(current_offset); |
3140 EXPECT_EQ(InputHandler::ScrollStarted, | 3144 EXPECT_EQ(InputHandler::ScrollStarted, |
3141 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 3145 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
3142 | 3146 |
3143 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3147 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3144 EXPECT_EQ(current_offset + scroll_delta, | 3148 EXPECT_EQ(current_offset + scroll_delta, |
3145 scroll_delegate.last_set_scroll_offset()); | 3149 scroll_delegate.last_set_scroll_offset()); |
3146 | 3150 |
3147 current_offset = gfx::Vector2dF(42.f, 41.f); | 3151 current_offset = gfx::Vector2dF(42.f, 41.f); |
3148 scroll_delegate.set_getter_return_value(current_offset); | 3152 scroll_delegate.set_getter_return_value(current_offset); |
3149 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3153 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3150 EXPECT_EQ(current_offset + scroll_delta, | 3154 EXPECT_EQ(current_offset + scroll_delta, |
3151 scroll_delegate.last_set_scroll_offset()); | 3155 scroll_delegate.last_set_scroll_offset()); |
3152 host_impl_->ScrollEnd(); | 3156 host_impl_->ScrollEnd(); |
| 3157 scroll_delegate.set_getter_return_value(gfx::Vector2dF()); |
3153 | 3158 |
3154 // Forces a full tree synchronization and ensures that the scroll delegate | 3159 // Forces a full tree synchronization and ensures that the scroll delegate |
3155 // sees the correct size of the new tree. | 3160 // sees the correct size of the new tree. |
3156 gfx::Size new_size(42, 24); | 3161 gfx::Size new_size(42, 24); |
3157 host_impl_->CreatePendingTree(); | 3162 host_impl_->CreatePendingTree(); |
3158 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); | 3163 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); |
3159 host_impl_->ActivatePendingTree(); | 3164 host_impl_->ActivatePendingTree(); |
3160 EXPECT_EQ(new_size, scroll_delegate.scrollable_size()); | 3165 EXPECT_EQ(new_size, scroll_delegate.scrollable_size()); |
3161 | 3166 |
3162 // Un-setting the delegate should propagate the delegate's current offset to | 3167 // Un-setting the delegate should propagate the delegate's current offset to |
(...skipping 3322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6485 // Verify implicit limits are calculated correctly with no overflows | 6490 // Verify implicit limits are calculated correctly with no overflows |
6486 host_impl_->SetMemoryPolicy(mem_policy); | 6491 host_impl_->SetMemoryPolicy(mem_policy); |
6487 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, | 6492 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
6488 300u * 1024u * 1024u); | 6493 300u * 1024u * 1024u); |
6489 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, | 6494 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
6490 150u * 1024u * 1024u); | 6495 150u * 1024u * 1024u); |
6491 } | 6496 } |
6492 | 6497 |
6493 } // namespace | 6498 } // namespace |
6494 } // namespace cc | 6499 } // namespace cc |
OLD | NEW |