OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
6 #include "cc/animation/scrollbar_animation_controller.h" | 6 #include "cc/animation/scrollbar_animation_controller.h" |
7 #include "cc/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
8 #include "cc/layers/painted_scrollbar_layer.h" | 8 #include "cc/layers/painted_scrollbar_layer.h" |
9 #include "cc/layers/painted_scrollbar_layer_impl.h" | 9 #include "cc/layers/painted_scrollbar_layer_impl.h" |
10 #include "cc/layers/scrollbar_layer_interface.h" | 10 #include "cc/layers/scrollbar_layer_interface.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 128 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
129 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 129 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
130 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 130 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
131 scoped_refptr<Layer> content_layer = Layer::Create(); | 131 scoped_refptr<Layer> content_layer = Layer::Create(); |
132 scoped_refptr<Layer> scrollbar_layer = | 132 scoped_refptr<Layer> scrollbar_layer = |
133 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 133 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
134 | 134 |
135 // Choose bounds to give max_scroll_offset = (30, 50). | 135 // Choose bounds to give max_scroll_offset = (30, 50). |
136 layer_tree_root->SetBounds(gfx::Size(70, 150)); | 136 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
137 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 137 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
138 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); | 138 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
139 scroll_layer->SetBounds(gfx::Size(100, 200)); | 139 scroll_layer->SetBounds(gfx::Size(100, 200)); |
140 content_layer->SetBounds(gfx::Size(100, 200)); | 140 content_layer->SetBounds(gfx::Size(100, 200)); |
141 | 141 |
142 host->SetRootLayer(layer_tree_root); | 142 host->SetRootLayer(layer_tree_root); |
143 layer_tree_root->AddChild(scroll_layer); | 143 layer_tree_root->AddChild(scroll_layer); |
144 scroll_layer->AddChild(content_layer); | 144 scroll_layer->AddChild(content_layer); |
145 layer_tree_root->AddChild(scrollbar_layer); | 145 layer_tree_root->AddChild(scrollbar_layer); |
146 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); | 146 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
147 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); | 147 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
148 | 148 |
149 layer_tree_root->SavePaintProperties(); | 149 layer_tree_root->SavePaintProperties(); |
150 content_layer->SavePaintProperties(); | 150 content_layer->SavePaintProperties(); |
151 | 151 |
152 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 152 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
153 | 153 |
154 ScrollbarLayerImplBase* cc_scrollbar_layer = | 154 ScrollbarLayerImplBase* cc_scrollbar_layer = |
155 static_cast<PaintedScrollbarLayerImpl*>( | 155 static_cast<PaintedScrollbarLayerImpl*>( |
156 layer_impl_tree_root->children()[1]); | 156 layer_impl_tree_root->children()[1]); |
157 | 157 |
158 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); | 158 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
159 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); | 159 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); |
160 | 160 |
161 layer_tree_root->SetBounds(gfx::Size(700, 1500)); | 161 layer_tree_root->SetBounds(gfx::Size(700, 1500)); |
162 layer_tree_root->SavePaintProperties(); | 162 layer_tree_root->SavePaintProperties(); |
163 scroll_layer->SetBounds(gfx::Size(1000, 2000)); | 163 scroll_layer->SetBounds(gfx::Size(1000, 2000)); |
164 scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200)); | 164 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); |
165 scroll_layer->SavePaintProperties(); | 165 scroll_layer->SavePaintProperties(); |
166 content_layer->SetBounds(gfx::Size(1000, 2000)); | 166 content_layer->SetBounds(gfx::Size(1000, 2000)); |
167 content_layer->SavePaintProperties(); | 167 content_layer->SavePaintProperties(); |
168 | 168 |
169 ScrollbarAnimationController* scrollbar_controller = | 169 ScrollbarAnimationController* scrollbar_controller = |
170 layer_impl_tree_root->scrollbar_animation_controller(); | 170 layer_impl_tree_root->scrollbar_animation_controller(); |
171 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 171 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
172 EXPECT_EQ(scrollbar_controller, | 172 EXPECT_EQ(scrollbar_controller, |
173 layer_impl_tree_root->scrollbar_animation_controller()); | 173 layer_impl_tree_root->scrollbar_animation_controller()); |
174 | 174 |
(...skipping 29 matching lines...) Expand all Loading... |
204 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 204 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
205 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 205 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
206 root_layer->SetBounds(gfx::Size(100, 50)); | 206 root_layer->SetBounds(gfx::Size(100, 50)); |
207 content_layer->SetBounds(gfx::Size(100, 50)); | 207 content_layer->SetBounds(gfx::Size(100, 50)); |
208 | 208 |
209 host->SetRootLayer(root_clip_layer); | 209 host->SetRootLayer(root_clip_layer); |
210 root_clip_layer->AddChild(root_layer); | 210 root_clip_layer->AddChild(root_layer); |
211 root_layer->AddChild(content_layer); | 211 root_layer->AddChild(content_layer); |
212 root_layer->AddChild(scrollbar_layer); | 212 root_layer->AddChild(scrollbar_layer); |
213 | 213 |
214 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 214 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
215 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 215 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
216 scrollbar_layer->SetScrollLayer(root_layer->id()); | 216 scrollbar_layer->SetScrollLayer(root_layer->id()); |
217 scrollbar_layer->SetClipLayer(root_clip_layer->id()); | 217 scrollbar_layer->SetClipLayer(root_clip_layer->id()); |
218 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 218 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
219 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 219 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
220 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 220 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
221 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 221 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
222 | 222 |
223 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 223 scrollbar_layer->UpdateThumbAndTrackGeometry(); |
224 LayerImpl* root_clip_layer_impl = NULL; | 224 LayerImpl* root_clip_layer_impl = NULL; |
(...skipping 23 matching lines...) Expand all Loading... |
248 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 248 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
249 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 249 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
250 root_layer->SetBounds(gfx::Size(100, 50)); | 250 root_layer->SetBounds(gfx::Size(100, 50)); |
251 content_layer->SetBounds(gfx::Size(100, 50)); | 251 content_layer->SetBounds(gfx::Size(100, 50)); |
252 | 252 |
253 host->SetRootLayer(root_clip_layer); | 253 host->SetRootLayer(root_clip_layer); |
254 root_clip_layer->AddChild(root_layer); | 254 root_clip_layer->AddChild(root_layer); |
255 root_layer->AddChild(content_layer); | 255 root_layer->AddChild(content_layer); |
256 root_layer->AddChild(scrollbar_layer); | 256 root_layer->AddChild(scrollbar_layer); |
257 | 257 |
258 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 258 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
259 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 259 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
260 scrollbar_layer->SetScrollLayer(root_layer->id()); | 260 scrollbar_layer->SetScrollLayer(root_layer->id()); |
261 scrollbar_layer->SetClipLayer(root_clip_layer->id()); | 261 scrollbar_layer->SetClipLayer(root_clip_layer->id()); |
262 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 262 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
263 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 263 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
264 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 264 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
265 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 265 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
266 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 266 scrollbar_layer->UpdateThumbAndTrackGeometry(); |
267 LayerImpl* root_clip_layer_impl = NULL; | 267 LayerImpl* root_clip_layer_impl = NULL; |
268 LayerImpl* root_layer_impl = NULL; | 268 LayerImpl* root_layer_impl = NULL; |
269 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; | 269 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; |
270 | 270 |
271 // Thumb is at the edge of the scrollbar (should be inset to | 271 // Thumb is at the edge of the scrollbar (should be inset to |
272 // the start of the track within the scrollbar layer's | 272 // the start of the track within the scrollbar layer's |
273 // position). | 273 // position). |
274 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 274 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
275 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 275 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
276 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 276 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
277 | 277 |
278 // Under-scroll (thumb position should clamp and be unchanged). | 278 // Under-scroll (thumb position should clamp and be unchanged). |
279 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); | 279 root_layer->SetScrollOffset(gfx::ScrollOffset(-5, 0)); |
280 | 280 |
281 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 281 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
282 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 282 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
283 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 283 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
284 | 284 |
285 // Over-scroll (thumb position should clamp on the far side). | 285 // Over-scroll (thumb position should clamp on the far side). |
286 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); | 286 root_layer->SetScrollOffset(gfx::ScrollOffset(85, 0)); |
287 | 287 |
288 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 288 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
289 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), | 289 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), |
290 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 290 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
291 | 291 |
292 // Change thumb thickness and length. | 292 // Change thumb thickness and length. |
293 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); | 293 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); |
294 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); | 294 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); |
295 | 295 |
296 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 296 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), | 713 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), |
714 layer_tree_root->id()); | 714 layer_tree_root->id()); |
715 } | 715 } |
716 layer_tree_root->AddChild(content_layer); | 716 layer_tree_root->AddChild(content_layer); |
717 layer_tree_root->AddChild(scrollbar_layer); | 717 layer_tree_root->AddChild(scrollbar_layer); |
718 | 718 |
719 layer_tree_host_->SetRootLayer(layer_tree_root); | 719 layer_tree_host_->SetRootLayer(layer_tree_root); |
720 | 720 |
721 scrollbar_layer->SetIsDrawable(true); | 721 scrollbar_layer->SetIsDrawable(true); |
722 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 722 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
723 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 723 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
724 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 724 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
725 content_layer->SetBounds(gfx::Size(100, 200)); | 725 content_layer->SetBounds(gfx::Size(100, 200)); |
726 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); | 726 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); |
727 scrollbar_layer->draw_properties().visible_content_rect = | 727 scrollbar_layer->draw_properties().visible_content_rect = |
728 gfx::Rect(0, 0, 100, 200); | 728 gfx::Rect(0, 0, 100, 200); |
729 scrollbar_layer->CreateRenderSurface(); | 729 scrollbar_layer->CreateRenderSurface(); |
730 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); | 730 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); |
731 | 731 |
732 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 732 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
733 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 733 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
1097 | 1097 |
1098 // Horizontal Scrollbars. | 1098 // Horizontal Scrollbars. |
1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
1101 } | 1101 } |
1102 | 1102 |
1103 } // namespace | 1103 } // namespace |
1104 } // namespace cc | 1104 } // namespace cc |
OLD | NEW |