Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 bool reverse_order, | 38 bool reverse_order, |
| 39 bool use_solid_color_scrollbar, | 39 bool use_solid_color_scrollbar, |
| 40 int thumb_thickness) { | 40 int thumb_thickness) { |
| 41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 42 scoped_refptr<Layer> child1 = Layer::Create(); | 42 scoped_refptr<Layer> child1 = Layer::Create(); |
| 43 scoped_refptr<Layer> child2; | 43 scoped_refptr<Layer> child2; |
| 44 if (use_solid_color_scrollbar) { | 44 if (use_solid_color_scrollbar) { |
| 45 const bool kIsLeftSideVerticalScrollbar = false; | 45 const bool kIsLeftSideVerticalScrollbar = false; |
| 46 child2 = SolidColorScrollbarLayer::Create( | 46 child2 = SolidColorScrollbarLayer::Create( |
| 47 scrollbar->Orientation(), thumb_thickness, | 47 scrollbar->Orientation(), thumb_thickness, |
| 48 kIsLeftSideVerticalScrollbar, child1->id()); | 48 kIsLeftSideVerticalScrollbar, child1.get()); |
| 49 } else { | 49 } else { |
| 50 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); | 50 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1.get()); |
| 51 } | 51 } |
| 52 layer_tree_root->AddChild(child1); | 52 layer_tree_root->AddChild(child1); |
| 53 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 53 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
| 54 host->SetRootLayer(layer_tree_root); | 54 host->SetRootLayer(layer_tree_root); |
| 55 return host->CommitAndCreateLayerImplTree(); | 55 return host->CommitAndCreateLayerImplTree(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 58 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
| 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.get()); |
| 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->SetScrollClipLayer(layer_tree_root.get()); |
| 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); | |
| 143 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root); | |
| 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 \ | |
|
enne (OOO)
2014/01/21 19:00:06
Can you make this macro more function-like by addi
wjmaclean
2014/01/21 22:37:27
Done.
| |
| 182 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | |
| 183 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ | |
| 184 root_layer_impl = root_clip_layer_impl->children()[0]; \ | |
| 185 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | |
| 186 root_layer_impl->children()[1]); \ | |
| 187 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ | |
|
enne (OOO)
2014/01/21 19:00:06
Trailing \
wjmaclean
2014/01/21 22:37:27
Done.
| |
| 188 | |
| 172 TEST(ScrollbarLayerTest, ThumbRect) { | 189 TEST(ScrollbarLayerTest, ThumbRect) { |
| 173 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 190 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 191 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | |
| 174 scoped_refptr<Layer> root_layer = Layer::Create(); | 192 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 175 scoped_refptr<Layer> content_layer = Layer::Create(); | 193 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 176 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 194 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 177 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 195 FakePaintedScrollbarLayer::Create(false, true, root_layer.get()); |
| 178 | 196 |
| 179 root_layer->SetScrollable(true); | 197 root_layer->SetScrollClipLayer(root_clip_layer.get()); |
| 180 root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0)); | 198 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 199 root_clip_layer->SetBounds(gfx::Size(20, 50)); | |
| 181 root_layer->SetBounds(gfx::Size(100, 50)); | 200 root_layer->SetBounds(gfx::Size(100, 50)); |
| 182 content_layer->SetBounds(gfx::Size(100, 50)); | 201 content_layer->SetBounds(gfx::Size(100, 50)); |
| 183 | 202 |
| 184 host->SetRootLayer(root_layer); | 203 host->SetRootLayer(root_clip_layer); |
| 204 root_clip_layer->AddChild(root_layer); | |
| 185 root_layer->AddChild(content_layer); | 205 root_layer->AddChild(content_layer); |
| 186 root_layer->AddChild(scrollbar_layer); | 206 root_layer->AddChild(scrollbar_layer); |
| 187 | 207 |
| 188 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 208 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
| 189 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 209 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
| 210 scrollbar_layer->SetScrollLayer(root_layer.get()); | |
| 211 scrollbar_layer->SetClipLayer(root_clip_layer.get()); | |
| 190 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 212 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
| 191 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 213 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
| 192 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 214 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
| 193 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 215 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
| 194 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 216 scrollbar_layer->UpdateThumbAndTrackGeometry(); |
| 217 LayerImpl* root_clip_layer_impl = NULL; | |
| 195 LayerImpl* root_layer_impl = NULL; | 218 LayerImpl* root_layer_impl = NULL; |
| 196 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; | 219 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; |
| 197 | 220 |
| 198 // Thumb is at the edge of the scrollbar (should be inset to | 221 // Thumb is at the edge of the scrollbar (should be inset to |
| 199 // the start of the track within the scrollbar layer's | 222 // the start of the track within the scrollbar layer's |
| 200 // position). | 223 // position). |
| 201 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 224 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(), | 225 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
| 206 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 226 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 207 | 227 |
| 208 // Under-scroll (thumb position should clamp and be unchanged). | 228 // Under-scroll (thumb position should clamp and be unchanged). |
| 209 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); | 229 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); |
| 210 | 230 |
| 211 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 231 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(), | 232 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
| 216 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 233 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 217 | 234 |
| 218 // Over-scroll (thumb position should clamp on the far side). | 235 // Over-scroll (thumb position should clamp on the far side). |
| 219 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); | 236 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); |
| 220 | 237 |
| 221 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 238 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(), | 239 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), |
| 226 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 240 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 227 | 241 |
| 228 // Change thumb thickness and length. | 242 // Change thumb thickness and length. |
| 229 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); | 243 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); |
| 230 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); | 244 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); |
| 231 | 245 |
| 232 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 246 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(), | 247 EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(), |
| 237 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 248 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 238 | 249 |
| 239 // Shrink the scrollbar layer to cover only the track. | 250 // Shrink the scrollbar layer to cover only the track. |
| 240 scrollbar_layer->SetBounds(gfx::Size(50, 10)); | 251 scrollbar_layer->SetBounds(gfx::Size(50, 10)); |
| 241 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); | 252 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); |
| 242 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 253 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
| 243 | 254 |
| 244 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 255 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(), | 256 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 249 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 257 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 250 | 258 |
| 251 // Shrink the track in the non-scrolling dimension so that it only covers the | 259 // 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 | 260 // middle third of the scrollbar layer (this does not affect the thumb |
| 253 // position). | 261 // position). |
| 254 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); | 262 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); |
| 255 | 263 |
| 256 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 264 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(), | 265 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 261 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 266 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 262 } | 267 } |
| 263 | 268 |
| 264 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 269 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 265 const int kThumbThickness = 3; | 270 const int kThumbThickness = 3; |
| 266 const int kTrackLength = 100; | 271 const int kTrackLength = 100; |
| 267 | 272 |
| 268 LayerTreeSettings layer_tree_settings; | 273 LayerTreeSettings layer_tree_settings; |
| 269 scoped_ptr<FakeLayerTreeHost> host = | 274 scoped_ptr<FakeLayerTreeHost> host = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 | 330 |
| 326 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 331 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 327 const int kThumbThickness = 3; | 332 const int kThumbThickness = 3; |
| 328 const int kTrackLength = 10; | 333 const int kTrackLength = 10; |
| 329 | 334 |
| 330 LayerTreeSettings layer_tree_settings; | 335 LayerTreeSettings layer_tree_settings; |
| 331 scoped_ptr<FakeLayerTreeHost> host = | 336 scoped_ptr<FakeLayerTreeHost> host = |
| 332 FakeLayerTreeHost::Create(layer_tree_settings); | 337 FakeLayerTreeHost::Create(layer_tree_settings); |
| 333 | 338 |
| 334 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 339 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 335 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 340 |
| 336 host.get(), scrollbar.Pass(), false, true, kThumbThickness); | 341 { |
| 342 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | |
| 343 scoped_refptr<Layer> scroll_layer = Layer::Create(); | |
| 344 scroll_layer->SetScrollClipLayer(layer_tree_root); | |
| 345 scoped_refptr<Layer> child1 = Layer::Create(); | |
| 346 scoped_refptr<Layer> child2; | |
| 347 const bool kIsLeftSideVerticalScrollbar = false; | |
| 348 child2 = SolidColorScrollbarLayer::Create( | |
| 349 scrollbar->Orientation(), kThumbThickness, | |
| 350 kIsLeftSideVerticalScrollbar, child1.get()); | |
| 351 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer); | |
| 352 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root); | |
| 353 scroll_layer->AddChild(child1); | |
| 354 scroll_layer->InsertChild(child2, 1); | |
| 355 layer_tree_root->AddChild(scroll_layer); | |
| 356 host->SetRootLayer(layer_tree_root); | |
| 357 } | |
| 358 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | |
| 359 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; | |
| 360 | |
| 337 ScrollbarLayerImplBase* scrollbar_layer_impl = | 361 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 338 static_cast<PaintedScrollbarLayerImpl*>( | 362 static_cast<PaintedScrollbarLayerImpl*>( |
| 339 layer_impl_tree_root->children()[1]); | 363 scroll_layer_impl->children()[1]); |
| 364 | |
| 365 // Choose layer bounds to give max_scroll_offset = (8, 8). | |
| 366 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | |
| 367 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); | |
| 368 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | |
| 340 | 369 |
| 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 370 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 342 scrollbar_layer_impl->SetCurrentPos(4.f); | 371 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 343 scrollbar_layer_impl->SetMaximum(8); | 372 scrollbar_layer_impl->SetMaximum(8); |
| 344 | 373 |
| 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 { | 374 { |
| 352 MockQuadCuller quad_culler; | 375 MockQuadCuller quad_culler; |
| 353 AppendQuadsData data; | 376 AppendQuadsData data; |
| 354 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 377 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 355 | 378 |
| 356 const QuadList& quads = quad_culler.quad_list(); | 379 const QuadList& quads = quad_culler.quad_list(); |
| 357 ASSERT_EQ(1u, quads.size()); | 380 ASSERT_EQ(1u, quads.size()); |
| 358 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 381 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 359 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 382 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
| 360 } | 383 } |
| 361 } | 384 } |
| 362 | 385 |
| 363 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 386 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 364 public: | 387 public: |
| 365 ScrollbarLayerSolidColorThumbTest() { | 388 ScrollbarLayerSolidColorThumbTest() { |
| 366 LayerTreeSettings layer_tree_settings; | 389 LayerTreeSettings layer_tree_settings; |
| 367 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 390 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
| 368 | 391 |
| 369 const int kThumbThickness = 3; | 392 const int kThumbThickness = 3; |
| 370 const bool kIsLeftSideVerticalScrollbar = false; | 393 const bool kIsLeftSideVerticalScrollbar = false; |
| 394 const bool kIsOverlayScrollbar = false; | |
| 371 | 395 |
| 372 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | 396 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 373 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness, | 397 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness, |
| 374 kIsLeftSideVerticalScrollbar); | 398 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 375 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | 399 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 376 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness, | 400 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness, |
| 377 kIsLeftSideVerticalScrollbar); | 401 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 378 } | 402 } |
| 379 | 403 |
| 380 protected: | 404 protected: |
| 381 FakeImplProxy proxy_; | 405 FakeImplProxy proxy_; |
| 382 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 406 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
| 383 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; | 407 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
| 384 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; | 408 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
| 385 }; | 409 }; |
| 386 | 410 |
| 387 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 411 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 473 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 450 } | 474 } |
| 451 | 475 |
| 452 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { | 476 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { |
| 453 public: | 477 public: |
| 454 ScrollbarLayerTestMaxTextureSize() {} | 478 ScrollbarLayerTestMaxTextureSize() {} |
| 455 | 479 |
| 456 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } | 480 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } |
| 457 | 481 |
| 458 virtual void BeginTest() OVERRIDE { | 482 virtual void BeginTest() OVERRIDE { |
| 483 scroll_layer_ = Layer::Create(); | |
| 484 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | |
| 485 | |
| 459 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 486 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 460 scrollbar_layer_ = PaintedScrollbarLayer::Create(scrollbar.Pass(), 1); | 487 scrollbar_layer_ = |
| 488 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_.get()); | |
| 489 scrollbar_layer_->SetScrollLayer(scroll_layer_); | |
| 461 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); | 490 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
| 462 scrollbar_layer_->SetBounds(bounds_); | 491 scrollbar_layer_->SetBounds(bounds_); |
| 463 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 492 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
| 464 | 493 |
| 465 scroll_layer_ = Layer::Create(); | |
| 466 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); | |
| 467 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | |
| 468 | |
| 469 PostSetNeedsCommitToMainThread(); | 494 PostSetNeedsCommitToMainThread(); |
| 470 } | 495 } |
| 471 | 496 |
| 472 virtual void DidCommitAndDrawFrame() OVERRIDE { | 497 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 473 const int kMaxTextureSize = | 498 const int kMaxTextureSize = |
| 474 layer_tree_host()->GetRendererCapabilities().max_texture_size; | 499 layer_tree_host()->GetRendererCapabilities().max_texture_size; |
| 475 | 500 |
| 476 // Check first that we're actually testing something. | 501 // Check first that we're actually testing something. |
| 477 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); | 502 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); |
| 478 | 503 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 602 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 578 scoped_refptr<Layer> content_layer = Layer::Create(); | 603 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 579 scoped_refptr<Layer> scrollbar_layer; | 604 scoped_refptr<Layer> scrollbar_layer; |
| 580 if (use_solid_color_scrollbar) { | 605 if (use_solid_color_scrollbar) { |
| 581 const int kThumbThickness = 3; | 606 const int kThumbThickness = 3; |
| 582 const bool kIsLeftSideVerticalScrollbar = false; | 607 const bool kIsLeftSideVerticalScrollbar = false; |
| 583 scrollbar_layer = | 608 scrollbar_layer = |
| 584 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 609 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 585 kThumbThickness, | 610 kThumbThickness, |
| 586 kIsLeftSideVerticalScrollbar, | 611 kIsLeftSideVerticalScrollbar, |
| 587 layer_tree_root->id()); | 612 layer_tree_root.get()); |
| 588 } else { | 613 } else { |
| 589 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), | 614 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), |
| 590 layer_tree_root->id()); | 615 layer_tree_root.get()); |
| 591 } | 616 } |
| 592 layer_tree_root->AddChild(content_layer); | 617 layer_tree_root->AddChild(content_layer); |
| 593 layer_tree_root->AddChild(scrollbar_layer); | 618 layer_tree_root->AddChild(scrollbar_layer); |
| 594 | 619 |
| 595 layer_tree_host_->SetRootLayer(layer_tree_root); | 620 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 596 | 621 |
| 597 scrollbar_layer->SetIsDrawable(true); | 622 scrollbar_layer->SetIsDrawable(true); |
| 598 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 623 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 599 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 624 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)); | 625 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| 602 content_layer->SetBounds(gfx::Size(100, 200)); | 626 content_layer->SetBounds(gfx::Size(100, 200)); |
| 603 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); | 627 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); |
| 604 scrollbar_layer->draw_properties().visible_content_rect = | 628 scrollbar_layer->draw_properties().visible_content_rect = |
| 605 gfx::Rect(0, 0, 100, 200); | 629 gfx::Rect(0, 0, 100, 200); |
| 606 scrollbar_layer->CreateRenderSurface(); | 630 scrollbar_layer->CreateRenderSurface(); |
| 607 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); | 631 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); |
| 608 | 632 |
| 609 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 633 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 610 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 634 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 681 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 658 | 682 |
| 659 void TestResourceUpload(const float test_scale) { | 683 void TestResourceUpload(const float test_scale) { |
| 660 layer_tree_host_.reset( | 684 layer_tree_host_.reset( |
| 661 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 685 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| 662 | 686 |
| 663 gfx::Point scrollbar_location(0, 185); | 687 gfx::Point scrollbar_location(0, 185); |
| 664 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 688 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 665 scoped_refptr<Layer> content_layer = Layer::Create(); | 689 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 666 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 690 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 667 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); | 691 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root.get()); |
| 668 | 692 |
| 669 layer_tree_root->AddChild(content_layer); | 693 layer_tree_root->AddChild(content_layer); |
| 670 layer_tree_root->AddChild(scrollbar_layer); | 694 layer_tree_root->AddChild(scrollbar_layer); |
| 671 | 695 |
| 672 layer_tree_host_->SetRootLayer(layer_tree_root); | 696 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 673 | 697 |
| 674 scrollbar_layer->SetIsDrawable(true); | 698 scrollbar_layer->SetIsDrawable(true); |
| 675 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 699 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 676 scrollbar_layer->SetPosition(scrollbar_location); | 700 scrollbar_layer->SetPosition(scrollbar_location); |
| 677 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 701 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 751 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 728 // Pick a test scale that moves the scrollbar's (non-zero) position to | 752 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 729 // a non-pixel-aligned location. | 753 // a non-pixel-aligned location. |
| 730 TestResourceUpload(.041f); | 754 TestResourceUpload(.041f); |
| 731 TestResourceUpload(1.41f); | 755 TestResourceUpload(1.41f); |
| 732 TestResourceUpload(4.1f); | 756 TestResourceUpload(4.1f); |
| 733 } | 757 } |
| 734 | 758 |
| 735 } // namespace | 759 } // namespace |
| 736 } // namespace cc | 760 } // namespace cc |
| OLD | NEW |