Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 1437413002: cc: Remove ScopedPtrVector and cc::remove_if. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/render_surface_unittest.cc ('k') | cc/output/bsp_tree.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/thread_task_runner_handle.h" 6 #include "base/thread_task_runner_handle.h"
7 #include "cc/animation/scrollbar_animation_controller.h" 7 #include "cc/animation/scrollbar_animation_controller.h"
8 #include "cc/layers/append_quads_data.h" 8 #include "cc/layers/append_quads_data.h"
9 #include "cc/layers/painted_scrollbar_layer.h" 9 #include "cc/layers/painted_scrollbar_layer.h"
10 #include "cc/layers/painted_scrollbar_layer_impl.h" 10 #include "cc/layers/painted_scrollbar_layer_impl.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 }; 146 };
147 147
148 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 148 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
149 // Create and attach a non-overlay scrollbar. 149 // Create and attach a non-overlay scrollbar.
150 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 150 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
151 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 151 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
152 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, 152 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false,
153 0, 0); 153 0, 0);
154 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 154 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
155 static_cast<PaintedScrollbarLayerImpl*>( 155 static_cast<PaintedScrollbarLayerImpl*>(
156 layer_impl_tree_root->children()[1]); 156 layer_impl_tree_root->children()[1].get());
157 157
158 // When the scrollbar is not an overlay scrollbar, the scroll should be 158 // When the scrollbar is not an overlay scrollbar, the scroll should be
159 // responded to on the main thread as the compositor does not yet implement 159 // responded to on the main thread as the compositor does not yet implement
160 // scrollbar scrolling. 160 // scrollbar scrolling.
161 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, 161 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD,
162 scrollbar_layer_impl->TryScroll( 162 scrollbar_layer_impl->TryScroll(
163 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); 163 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE));
164 164
165 // Create and attach an overlay scrollbar. 165 // Create and attach an overlay scrollbar.
166 scrollbar.reset(new FakeScrollbar(false, false, true)); 166 scrollbar.reset(new FakeScrollbar(false, false, true));
167 167
168 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 168 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
169 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, 169 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false,
170 0, 0); 170 0, 0);
171 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 171 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
172 layer_impl_tree_root->children()[1]); 172 layer_impl_tree_root->children()[1].get());
173 173
174 // The user shouldn't be able to drag an overlay scrollbar and the scroll 174 // The user shouldn't be able to drag an overlay scrollbar and the scroll
175 // may be handled in the compositor. 175 // may be handled in the compositor.
176 EXPECT_EQ(InputHandler::SCROLL_IGNORED, 176 EXPECT_EQ(InputHandler::SCROLL_IGNORED,
177 scrollbar_layer_impl->TryScroll( 177 scrollbar_layer_impl->TryScroll(
178 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); 178 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE));
179 } 179 }
180 180
181 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { 181 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
182 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 182 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
(...skipping 17 matching lines...) Expand all
200 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 200 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
201 201
202 layer_tree_root->SavePaintProperties(); 202 layer_tree_root->SavePaintProperties();
203 content_layer->SavePaintProperties(); 203 content_layer->SavePaintProperties();
204 204
205 LayerImpl* layer_impl_tree_root = 205 LayerImpl* layer_impl_tree_root =
206 layer_tree_host_->CommitAndCreateLayerImplTree(); 206 layer_tree_host_->CommitAndCreateLayerImplTree();
207 207
208 ScrollbarLayerImplBase* cc_scrollbar_layer = 208 ScrollbarLayerImplBase* cc_scrollbar_layer =
209 static_cast<PaintedScrollbarLayerImpl*>( 209 static_cast<PaintedScrollbarLayerImpl*>(
210 layer_impl_tree_root->children()[1]); 210 layer_impl_tree_root->children()[1].get());
211 211
212 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 212 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
213 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - 213 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() -
214 cc_scrollbar_layer->clip_layer_length()); 214 cc_scrollbar_layer->clip_layer_length());
215 215
216 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 216 layer_tree_root->SetBounds(gfx::Size(700, 1500));
217 layer_tree_root->SavePaintProperties(); 217 layer_tree_root->SavePaintProperties();
218 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 218 scroll_layer->SetBounds(gfx::Size(1000, 2000));
219 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); 219 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
220 scroll_layer->SavePaintProperties(); 220 scroll_layer->SavePaintProperties();
221 content_layer->SetBounds(gfx::Size(1000, 2000)); 221 content_layer->SetBounds(gfx::Size(1000, 2000));
222 content_layer->SavePaintProperties(); 222 content_layer->SavePaintProperties();
223 223
224 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); 224 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree();
225 225
226 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 226 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
227 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 227 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
228 cc_scrollbar_layer->clip_layer_length()); 228 cc_scrollbar_layer->clip_layer_length());
229 229
230 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 230 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get();
231 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); 231 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
232 232
233 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 233 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
234 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 234 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
235 cc_scrollbar_layer->clip_layer_length()); 235 cc_scrollbar_layer->clip_layer_length());
236 } 236 }
237 237
238 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ 238 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
239 do { \ 239 do { \
240 scrollbar_layer->UpdateInternalContentScale(); \ 240 scrollbar_layer->UpdateInternalContentScale(); \
241 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 241 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
242 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ 242 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \
243 root_layer_impl = root_clip_layer_impl->children()[0]; \ 243 root_layer_impl = root_clip_layer_impl->children()[0].get(); \
244 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 244 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
245 root_layer_impl->children()[1]); \ 245 root_layer_impl->children()[1].get()); \
246 } while (false) 246 } while (false)
247 247
248 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 248 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
249 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings()); 249 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings());
250 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); 250 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings());
251 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); 251 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
252 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 252 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
253 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, 253 FakePaintedScrollbarLayer::Create(layer_settings(), false, true,
254 root_layer->id()); 254 root_layer->id());
255 255
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 const int kThumbThickness = 3; 368 const int kThumbThickness = 3;
369 const int kTrackStart = 1; 369 const int kTrackStart = 1;
370 const int kTrackLength = 100; 370 const int kTrackLength = 100;
371 371
372 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 372 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
373 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 373 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
374 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, true, 374 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, true,
375 kThumbThickness, kTrackStart); 375 kThumbThickness, kTrackStart);
376 ScrollbarLayerImplBase* scrollbar_layer_impl = 376 ScrollbarLayerImplBase* scrollbar_layer_impl =
377 static_cast<SolidColorScrollbarLayerImpl*>( 377 static_cast<SolidColorScrollbarLayerImpl*>(
378 layer_impl_tree_root->children()[1]); 378 layer_impl_tree_root->children()[1].get());
379 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 379 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
380 scrollbar_layer_impl->SetCurrentPos(10.f); 380 scrollbar_layer_impl->SetCurrentPos(10.f);
381 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); 381 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f);
382 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); 382 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f);
383 383
384 // Thickness should be overridden to 3. 384 // Thickness should be overridden to 3.
385 { 385 {
386 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 386 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
387 AppendQuadsData data; 387 AppendQuadsData data;
388 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); 388 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 layer_settings(), scrollbar->Orientation(), kThumbThickness, 442 layer_settings(), scrollbar->Orientation(), kThumbThickness,
443 kTrackStart, kIsLeftSideVerticalScrollbar, child1->id()); 443 kTrackStart, kIsLeftSideVerticalScrollbar, child1->id());
444 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 444 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
445 scroll_layer->AddChild(child1); 445 scroll_layer->AddChild(child1);
446 scroll_layer->InsertChild(child2, 1); 446 scroll_layer->InsertChild(child2, 1);
447 layer_tree_root->AddChild(scroll_layer); 447 layer_tree_root->AddChild(scroll_layer);
448 layer_tree_host_->SetRootLayer(layer_tree_root); 448 layer_tree_host_->SetRootLayer(layer_tree_root);
449 } 449 }
450 LayerImpl* layer_impl_tree_root = 450 LayerImpl* layer_impl_tree_root =
451 layer_tree_host_->CommitAndCreateLayerImplTree(); 451 layer_tree_host_->CommitAndCreateLayerImplTree();
452 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 452 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get();
453 453
454 auto* scrollbar_layer_impl = 454 auto* scrollbar_layer_impl = static_cast<ScrollbarLayerImplBase*>(
455 static_cast<ScrollbarLayerImplBase*>(scroll_layer_impl->children()[1]); 455 scroll_layer_impl->children()[1].get());
456 456
457 // Choose layer bounds to give max_scroll_offset = (8, 8). 457 // Choose layer bounds to give max_scroll_offset = (8, 8).
458 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 458 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
459 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); 459 scroll_layer_impl->SetBounds(gfx::Size(10, 10));
460 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 460 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
461 461
462 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 462 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
463 scrollbar_layer_impl->SetCurrentPos(4.f); 463 scrollbar_layer_impl->SetCurrentPos(4.f);
464 464
465 { 465 {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 999 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1000 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1000 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1001 1001
1002 // Horizontal Scrollbars. 1002 // Horizontal Scrollbars.
1003 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1003 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1004 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1004 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1005 } 1005 }
1006 1006
1007 } // namespace 1007 } // namespace
1008 } // namespace cc 1008 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/render_surface_unittest.cc ('k') | cc/output/bsp_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698