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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 59 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
60 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 60 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
61 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 61 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
62 host.get(), scrollbar.Pass(), false, false, 0); | 62 host.get(), scrollbar.Pass(), false, false, 0); |
63 | 63 |
64 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 64 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
65 PaintedScrollbarLayerImpl* cc_child2 = | 65 PaintedScrollbarLayerImpl* cc_child2 = |
66 static_cast<PaintedScrollbarLayerImpl*>( | 66 static_cast<PaintedScrollbarLayerImpl*>( |
67 layer_impl_tree_root->children()[1]); | 67 layer_impl_tree_root->children()[1]); |
68 | 68 |
69 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); | 69 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); |
| 70 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); |
70 } | 71 } |
71 | 72 |
72 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 73 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
73 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 74 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
74 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 75 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
75 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 76 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
76 host.get(), scrollbar.Pass(), true, false, 0); | 77 host.get(), scrollbar.Pass(), true, false, 0); |
77 | 78 |
78 PaintedScrollbarLayerImpl* cc_child1 = | 79 PaintedScrollbarLayerImpl* cc_child1 = |
79 static_cast<PaintedScrollbarLayerImpl*>( | 80 static_cast<PaintedScrollbarLayerImpl*>( |
80 layer_impl_tree_root->children()[0]); | 81 layer_impl_tree_root->children()[0]); |
81 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 82 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
82 | 83 |
83 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); | 84 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); |
| 85 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); |
84 } | 86 } |
85 | 87 |
86 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 88 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
87 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 89 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
88 | 90 |
89 // Create and attach a non-overlay scrollbar. | 91 // Create and attach a non-overlay scrollbar. |
90 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 92 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
91 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 93 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
92 host.get(), scrollbar.Pass(), false, false, 0); | 94 host.get(), scrollbar.Pass(), false, false, 0); |
93 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 95 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
(...skipping 20 matching lines...) Expand all Loading... |
114 EXPECT_EQ(InputHandler::ScrollIgnored, | 116 EXPECT_EQ(InputHandler::ScrollIgnored, |
115 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 117 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
116 InputHandler::Gesture)); | 118 InputHandler::Gesture)); |
117 } | 119 } |
118 | 120 |
119 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { | 121 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { |
120 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 122 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
121 | 123 |
122 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 124 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
123 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 125 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 126 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
124 scoped_refptr<Layer> content_layer = Layer::Create(); | 127 scoped_refptr<Layer> content_layer = Layer::Create(); |
125 scoped_refptr<Layer> scrollbar_layer = | 128 scoped_refptr<Layer> scrollbar_layer = |
126 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 129 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
127 | 130 |
128 layer_tree_root->SetScrollable(true); | 131 // Choose bounds to give max_scroll_offset = (30, 50). |
129 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 132 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
130 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); | 133 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
131 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 134 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); |
| 135 scroll_layer->SetBounds(gfx::Size(100, 200)); |
132 content_layer->SetBounds(gfx::Size(100, 200)); | 136 content_layer->SetBounds(gfx::Size(100, 200)); |
133 | 137 |
134 host->SetRootLayer(layer_tree_root); | 138 host->SetRootLayer(layer_tree_root); |
135 layer_tree_root->AddChild(content_layer); | 139 layer_tree_root->AddChild(scroll_layer); |
| 140 scroll_layer->AddChild(content_layer); |
136 layer_tree_root->AddChild(scrollbar_layer); | 141 layer_tree_root->AddChild(scrollbar_layer); |
| 142 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
| 143 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
137 | 144 |
138 layer_tree_root->SavePaintProperties(); | 145 layer_tree_root->SavePaintProperties(); |
139 content_layer->SavePaintProperties(); | 146 content_layer->SavePaintProperties(); |
140 | 147 |
141 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 148 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
142 | 149 |
143 ScrollbarLayerImplBase* cc_scrollbar_layer = | 150 ScrollbarLayerImplBase* cc_scrollbar_layer = |
144 static_cast<PaintedScrollbarLayerImpl*>( | 151 static_cast<PaintedScrollbarLayerImpl*>( |
145 layer_impl_tree_root->children()[1]); | 152 layer_impl_tree_root->children()[1]); |
146 | 153 |
147 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); | 154 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
148 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); | 155 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); |
149 | 156 |
150 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); | 157 layer_tree_root->SetBounds(gfx::Size(700, 1500)); |
151 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); | |
152 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); | |
153 layer_tree_root->SavePaintProperties(); | 158 layer_tree_root->SavePaintProperties(); |
| 159 scroll_layer->SetBounds(gfx::Size(1000, 2000)); |
| 160 scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200)); |
| 161 scroll_layer->SavePaintProperties(); |
154 content_layer->SetBounds(gfx::Size(1000, 2000)); | 162 content_layer->SetBounds(gfx::Size(1000, 2000)); |
155 content_layer->SavePaintProperties(); | 163 content_layer->SavePaintProperties(); |
156 | 164 |
157 ScrollbarAnimationController* scrollbar_controller = | 165 ScrollbarAnimationController* scrollbar_controller = |
158 layer_impl_tree_root->scrollbar_animation_controller(); | 166 layer_impl_tree_root->scrollbar_animation_controller(); |
159 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 167 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
160 EXPECT_EQ(scrollbar_controller, | 168 EXPECT_EQ(scrollbar_controller, |
161 layer_impl_tree_root->scrollbar_animation_controller()); | 169 layer_impl_tree_root->scrollbar_animation_controller()); |
162 | 170 |
163 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); | 171 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); |
164 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); | 172 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
165 | 173 |
166 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); | 174 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
| 175 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); |
167 | 176 |
168 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); | 177 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
169 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); | 178 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
170 } | 179 } |
171 | 180 |
| 181 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ |
| 182 do { \ |
| 183 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
| 184 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ |
| 185 root_layer_impl = root_clip_layer_impl->children()[0]; \ |
| 186 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
| 187 root_layer_impl->children()[1]); \ |
| 188 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ |
| 189 } while (false) |
| 190 |
172 TEST(ScrollbarLayerTest, ThumbRect) { | 191 TEST(ScrollbarLayerTest, ThumbRect) { |
173 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 192 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 193 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
174 scoped_refptr<Layer> root_layer = Layer::Create(); | 194 scoped_refptr<Layer> root_layer = Layer::Create(); |
175 scoped_refptr<Layer> content_layer = Layer::Create(); | 195 scoped_refptr<Layer> content_layer = Layer::Create(); |
176 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 196 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
177 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 197 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
178 | 198 |
179 root_layer->SetScrollable(true); | 199 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
180 root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0)); | 200 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 201 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
181 root_layer->SetBounds(gfx::Size(100, 50)); | 202 root_layer->SetBounds(gfx::Size(100, 50)); |
182 content_layer->SetBounds(gfx::Size(100, 50)); | 203 content_layer->SetBounds(gfx::Size(100, 50)); |
183 | 204 |
184 host->SetRootLayer(root_layer); | 205 host->SetRootLayer(root_clip_layer); |
| 206 root_clip_layer->AddChild(root_layer); |
185 root_layer->AddChild(content_layer); | 207 root_layer->AddChild(content_layer); |
186 root_layer->AddChild(scrollbar_layer); | 208 root_layer->AddChild(scrollbar_layer); |
187 | 209 |
188 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 210 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
189 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 211 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
| 212 scrollbar_layer->SetScrollLayer(root_layer->id()); |
| 213 scrollbar_layer->SetClipLayer(root_clip_layer->id()); |
190 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 214 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
191 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 215 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
192 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 216 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
193 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 217 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
194 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 218 scrollbar_layer->UpdateThumbAndTrackGeometry(); |
| 219 LayerImpl* root_clip_layer_impl = NULL; |
195 LayerImpl* root_layer_impl = NULL; | 220 LayerImpl* root_layer_impl = NULL; |
196 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; | 221 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; |
197 | 222 |
198 // Thumb is at the edge of the scrollbar (should be inset to | 223 // Thumb is at the edge of the scrollbar (should be inset to |
199 // the start of the track within the scrollbar layer's | 224 // the start of the track within the scrollbar layer's |
200 // position). | 225 // position). |
201 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 226 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
202 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
203 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
204 root_layer_impl->children()[1]); | |
205 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 227 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
206 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 228 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
207 | 229 |
208 // Under-scroll (thumb position should clamp and be unchanged). | 230 // Under-scroll (thumb position should clamp and be unchanged). |
209 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); | 231 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); |
210 | 232 |
211 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 233 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
212 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
213 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
214 root_layer_impl->children()[1]); | |
215 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 234 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
216 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
217 | 236 |
218 // Over-scroll (thumb position should clamp on the far side). | 237 // Over-scroll (thumb position should clamp on the far side). |
219 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); | 238 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); |
220 | 239 |
221 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 240 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
222 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
223 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
224 root_layer_impl->children()[1]); | |
225 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), | 241 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), |
226 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 242 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
227 | 243 |
228 // Change thumb thickness and length. | 244 // Change thumb thickness and length. |
229 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); | 245 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); |
230 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); | 246 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); |
231 | 247 |
232 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 248 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
233 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
234 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
235 root_layer_impl->children()[1]); | |
236 EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(), | 249 EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(), |
237 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 250 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
238 | 251 |
239 // Shrink the scrollbar layer to cover only the track. | 252 // Shrink the scrollbar layer to cover only the track. |
240 scrollbar_layer->SetBounds(gfx::Size(50, 10)); | 253 scrollbar_layer->SetBounds(gfx::Size(50, 10)); |
241 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); | 254 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); |
242 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 255 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
243 | 256 |
244 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 257 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
245 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
246 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
247 root_layer_impl->children()[1]); | |
248 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 258 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
249 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 259 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
250 | 260 |
251 // Shrink the track in the non-scrolling dimension so that it only covers the | 261 // Shrink the track in the non-scrolling dimension so that it only covers the |
252 // middle third of the scrollbar layer (this does not affect the thumb | 262 // middle third of the scrollbar layer (this does not affect the thumb |
253 // position). | 263 // position). |
254 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); | 264 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); |
255 | 265 |
256 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 266 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
257 root_layer_impl = host->CommitAndCreateLayerImplTree(); | |
258 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | |
259 root_layer_impl->children()[1]); | |
260 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 267 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
261 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 268 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
262 } | 269 } |
263 | 270 |
264 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 271 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
265 const int kThumbThickness = 3; | 272 const int kThumbThickness = 3; |
266 const int kTrackLength = 100; | 273 const int kTrackLength = 100; |
267 | 274 |
268 LayerTreeSettings layer_tree_settings; | 275 LayerTreeSettings layer_tree_settings; |
269 scoped_ptr<FakeLayerTreeHost> host = | 276 scoped_ptr<FakeLayerTreeHost> host = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 332 |
326 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 333 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
327 const int kThumbThickness = 3; | 334 const int kThumbThickness = 3; |
328 const int kTrackLength = 10; | 335 const int kTrackLength = 10; |
329 | 336 |
330 LayerTreeSettings layer_tree_settings; | 337 LayerTreeSettings layer_tree_settings; |
331 scoped_ptr<FakeLayerTreeHost> host = | 338 scoped_ptr<FakeLayerTreeHost> host = |
332 FakeLayerTreeHost::Create(layer_tree_settings); | 339 FakeLayerTreeHost::Create(layer_tree_settings); |
333 | 340 |
334 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 341 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
335 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 342 |
336 host.get(), scrollbar.Pass(), false, true, kThumbThickness); | 343 { |
| 344 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 345 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 346 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 347 scoped_refptr<Layer> child1 = Layer::Create(); |
| 348 scoped_refptr<Layer> child2; |
| 349 const bool kIsLeftSideVerticalScrollbar = false; |
| 350 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 351 kThumbThickness, |
| 352 kIsLeftSideVerticalScrollbar, |
| 353 child1->id()); |
| 354 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
| 355 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
| 356 scroll_layer->AddChild(child1); |
| 357 scroll_layer->InsertChild(child2, 1); |
| 358 layer_tree_root->AddChild(scroll_layer); |
| 359 host->SetRootLayer(layer_tree_root); |
| 360 } |
| 361 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
| 362 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
| 363 |
337 ScrollbarLayerImplBase* scrollbar_layer_impl = | 364 ScrollbarLayerImplBase* scrollbar_layer_impl = |
338 static_cast<PaintedScrollbarLayerImpl*>( | 365 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]); |
339 layer_impl_tree_root->children()[1]); | 366 |
| 367 // Choose layer bounds to give max_scroll_offset = (8, 8). |
| 368 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 369 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); |
| 370 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
340 | 371 |
341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 372 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
342 scrollbar_layer_impl->SetCurrentPos(4.f); | 373 scrollbar_layer_impl->SetCurrentPos(4.f); |
343 scrollbar_layer_impl->SetMaximum(8); | 374 scrollbar_layer_impl->SetMaximum(8); |
344 | 375 |
345 layer_impl_tree_root->SetScrollable(true); | |
346 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | |
347 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | |
348 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | |
349 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | |
350 | |
351 { | 376 { |
352 MockQuadCuller quad_culler; | 377 MockQuadCuller quad_culler; |
353 AppendQuadsData data; | 378 AppendQuadsData data; |
354 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 379 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
355 | 380 |
356 const QuadList& quads = quad_culler.quad_list(); | 381 const QuadList& quads = quad_culler.quad_list(); |
357 ASSERT_EQ(1u, quads.size()); | 382 ASSERT_EQ(1u, quads.size()); |
358 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 383 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
359 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 384 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
360 } | 385 } |
361 } | 386 } |
362 | 387 |
363 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 388 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
364 public: | 389 public: |
365 ScrollbarLayerSolidColorThumbTest() { | 390 ScrollbarLayerSolidColorThumbTest() { |
366 LayerTreeSettings layer_tree_settings; | 391 LayerTreeSettings layer_tree_settings; |
367 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 392 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
368 | 393 |
369 const int kThumbThickness = 3; | 394 const int kThumbThickness = 3; |
370 const bool kIsLeftSideVerticalScrollbar = false; | 395 const bool kIsLeftSideVerticalScrollbar = false; |
| 396 const bool kIsOverlayScrollbar = false; |
371 | 397 |
372 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | 398 horizontal_scrollbar_layer_ = |
373 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness, | 399 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), |
374 kIsLeftSideVerticalScrollbar); | 400 1, |
375 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | 401 HORIZONTAL, |
376 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness, | 402 kThumbThickness, |
377 kIsLeftSideVerticalScrollbar); | 403 kIsLeftSideVerticalScrollbar, |
| 404 kIsOverlayScrollbar); |
| 405 vertical_scrollbar_layer_ = |
| 406 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), |
| 407 2, |
| 408 VERTICAL, |
| 409 kThumbThickness, |
| 410 kIsLeftSideVerticalScrollbar, |
| 411 kIsOverlayScrollbar); |
378 } | 412 } |
379 | 413 |
380 protected: | 414 protected: |
381 FakeImplProxy proxy_; | 415 FakeImplProxy proxy_; |
382 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 416 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
383 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; | 417 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
384 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; | 418 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
385 }; | 419 }; |
386 | 420 |
387 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 421 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 483 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
450 } | 484 } |
451 | 485 |
452 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { | 486 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { |
453 public: | 487 public: |
454 ScrollbarLayerTestMaxTextureSize() {} | 488 ScrollbarLayerTestMaxTextureSize() {} |
455 | 489 |
456 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } | 490 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } |
457 | 491 |
458 virtual void BeginTest() OVERRIDE { | 492 virtual void BeginTest() OVERRIDE { |
| 493 scroll_layer_ = Layer::Create(); |
| 494 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 495 |
459 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 496 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
460 scrollbar_layer_ = PaintedScrollbarLayer::Create(scrollbar.Pass(), 1); | 497 scrollbar_layer_ = |
| 498 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); |
| 499 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); |
461 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); | 500 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
462 scrollbar_layer_->SetBounds(bounds_); | 501 scrollbar_layer_->SetBounds(bounds_); |
463 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 502 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
464 | 503 |
465 scroll_layer_ = Layer::Create(); | |
466 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); | |
467 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | |
468 | |
469 PostSetNeedsCommitToMainThread(); | 504 PostSetNeedsCommitToMainThread(); |
470 } | 505 } |
471 | 506 |
472 virtual void DidCommitAndDrawFrame() OVERRIDE { | 507 virtual void DidCommitAndDrawFrame() OVERRIDE { |
473 const int kMaxTextureSize = | 508 const int kMaxTextureSize = |
474 layer_tree_host()->GetRendererCapabilities().max_texture_size; | 509 layer_tree_host()->GetRendererCapabilities().max_texture_size; |
475 | 510 |
476 // Check first that we're actually testing something. | 511 // Check first that we're actually testing something. |
477 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); | 512 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); |
478 | 513 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 layer_tree_root->id()); | 625 layer_tree_root->id()); |
591 } | 626 } |
592 layer_tree_root->AddChild(content_layer); | 627 layer_tree_root->AddChild(content_layer); |
593 layer_tree_root->AddChild(scrollbar_layer); | 628 layer_tree_root->AddChild(scrollbar_layer); |
594 | 629 |
595 layer_tree_host_->SetRootLayer(layer_tree_root); | 630 layer_tree_host_->SetRootLayer(layer_tree_root); |
596 | 631 |
597 scrollbar_layer->SetIsDrawable(true); | 632 scrollbar_layer->SetIsDrawable(true); |
598 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 633 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
599 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 634 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); |
600 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); | |
601 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 635 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
602 content_layer->SetBounds(gfx::Size(100, 200)); | 636 content_layer->SetBounds(gfx::Size(100, 200)); |
603 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); | 637 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); |
604 scrollbar_layer->draw_properties().visible_content_rect = | 638 scrollbar_layer->draw_properties().visible_content_rect = |
605 gfx::Rect(0, 0, 100, 200); | 639 gfx::Rect(0, 0, 100, 200); |
606 scrollbar_layer->CreateRenderSurface(); | 640 scrollbar_layer->CreateRenderSurface(); |
607 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); | 641 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); |
608 | 642 |
609 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 643 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
610 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 644 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 761 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
728 // Pick a test scale that moves the scrollbar's (non-zero) position to | 762 // Pick a test scale that moves the scrollbar's (non-zero) position to |
729 // a non-pixel-aligned location. | 763 // a non-pixel-aligned location. |
730 TestResourceUpload(.041f); | 764 TestResourceUpload(.041f); |
731 TestResourceUpload(1.41f); | 765 TestResourceUpload(1.41f); |
732 TestResourceUpload(4.1f); | 766 TestResourceUpload(4.1f); |
733 } | 767 } |
734 | 768 |
735 } // namespace | 769 } // namespace |
736 } // namespace cc | 770 } // namespace cc |
OLD | NEW |