| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <unordered_map> | 7 #include <unordered_map> |
| 8 | 8 |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "cc/input/scrollbar_animation_controller.h" | 10 #include "cc/input/scrollbar_animation_controller.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "cc/trees/layer_tree_impl.h" | 30 #include "cc/trees/layer_tree_impl.h" |
| 31 #include "cc/trees/occlusion_tracker.h" | 31 #include "cc/trees/occlusion_tracker.h" |
| 32 #include "cc/trees/single_thread_proxy.h" | 32 #include "cc/trees/single_thread_proxy.h" |
| 33 #include "cc/trees/tree_synchronizer.h" | 33 #include "cc/trees/tree_synchronizer.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 LayerImpl* LayerImplForScrollAreaAndScrollbar( | |
| 41 FakeLayerTreeHost* host, | |
| 42 std::unique_ptr<Scrollbar> scrollbar, | |
| 43 bool reverse_order, | |
| 44 bool use_solid_color_scrollbar, | |
| 45 int thumb_thickness, | |
| 46 int track_start) { | |
| 47 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | |
| 48 scoped_refptr<Layer> child1 = Layer::Create(); | |
| 49 scoped_refptr<Layer> child2; | |
| 50 if (use_solid_color_scrollbar) { | |
| 51 const bool kIsLeftSideVerticalScrollbar = false; | |
| 52 child2 = SolidColorScrollbarLayer::Create( | |
| 53 scrollbar->Orientation(), thumb_thickness, track_start, | |
| 54 kIsLeftSideVerticalScrollbar, child1->id()); | |
| 55 } else { | |
| 56 child2 = PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id()); | |
| 57 } | |
| 58 layer_tree_root->AddChild(child1); | |
| 59 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | |
| 60 host->SetRootLayer(layer_tree_root); | |
| 61 return host->CommitAndCreateLayerImplTree(); | |
| 62 } | |
| 63 | |
| 64 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { | 40 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { |
| 65 public: | 41 public: |
| 66 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, | 42 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, |
| 67 LayerTreeHost::InitParams* params) | 43 LayerTreeHost::InitParams* params) |
| 68 : FakeLayerTreeHost(client, params, CompositorMode::SINGLE_THREADED), | 44 : FakeLayerTreeHost(client, params, CompositorMode::SINGLE_THREADED), |
| 69 next_id_(1), | 45 next_id_(1), |
| 70 total_ui_resource_created_(0), | 46 total_ui_resource_created_(0), |
| 71 total_ui_resource_deleted_(0) { | 47 total_ui_resource_deleted_(0) { |
| 72 InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), | 48 InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), |
| 73 nullptr); | 49 nullptr); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 int total_ui_resource_created_; | 93 int total_ui_resource_created_; |
| 118 int total_ui_resource_deleted_; | 94 int total_ui_resource_deleted_; |
| 119 }; | 95 }; |
| 120 | 96 |
| 121 class ScrollbarLayerTest : public testing::Test { | 97 class ScrollbarLayerTest : public testing::Test { |
| 122 public: | 98 public: |
| 123 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { | 99 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { |
| 124 layer_tree_settings_.single_thread_proxy_scheduler = false; | 100 layer_tree_settings_.single_thread_proxy_scheduler = false; |
| 125 layer_tree_settings_.use_zero_copy = true; | 101 layer_tree_settings_.use_zero_copy = true; |
| 126 | 102 |
| 103 scrollbar_layer_id_ = -1; |
| 104 |
| 127 LayerTreeHost::InitParams params; | 105 LayerTreeHost::InitParams params; |
| 128 params.client = &fake_client_; | 106 params.client = &fake_client_; |
| 129 params.settings = &layer_tree_settings_; | 107 params.settings = &layer_tree_settings_; |
| 130 params.task_graph_runner = &task_graph_runner_; | 108 params.task_graph_runner = &task_graph_runner_; |
| 131 | 109 |
| 132 layer_tree_host_.reset( | 110 layer_tree_host_.reset( |
| 133 new FakeResourceTrackingLayerTreeHost(&fake_client_, ¶ms)); | 111 new FakeResourceTrackingLayerTreeHost(&fake_client_, ¶ms)); |
| 134 layer_tree_host_->SetVisible(true); | 112 layer_tree_host_->SetVisible(true); |
| 135 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); | 113 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); |
| 136 // Force output surface creation for renderer capabilities. | 114 // Force output surface creation for renderer capabilities. |
| 137 layer_tree_host_->Composite(base::TimeTicks()); | 115 layer_tree_host_->Composite(base::TimeTicks()); |
| 138 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); | 116 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); |
| 139 } | 117 } |
| 140 | 118 |
| 119 LayerImpl* LayerImplForScrollAreaAndScrollbar( |
| 120 FakeLayerTreeHost* host, |
| 121 std::unique_ptr<Scrollbar> scrollbar, |
| 122 bool reverse_order, |
| 123 bool use_solid_color_scrollbar, |
| 124 int thumb_thickness, |
| 125 int track_start) { |
| 126 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 127 scoped_refptr<Layer> child1 = Layer::Create(); |
| 128 scoped_refptr<Layer> child2; |
| 129 if (use_solid_color_scrollbar) { |
| 130 const bool kIsLeftSideVerticalScrollbar = false; |
| 131 child2 = SolidColorScrollbarLayer::Create( |
| 132 scrollbar->Orientation(), thumb_thickness, track_start, |
| 133 kIsLeftSideVerticalScrollbar, child1->id()); |
| 134 } else { |
| 135 child2 = |
| 136 PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id()); |
| 137 } |
| 138 layer_tree_root->AddChild(child1); |
| 139 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
| 140 scrollbar_layer_id_ = reverse_order ? child1->id() : child2->id(); |
| 141 host->SetRootLayer(layer_tree_root); |
| 142 return host->CommitAndCreateLayerImplTree(); |
| 143 } |
| 144 |
| 141 protected: | 145 protected: |
| 142 FakeLayerTreeHostClient fake_client_; | 146 FakeLayerTreeHostClient fake_client_; |
| 143 TestTaskGraphRunner task_graph_runner_; | 147 TestTaskGraphRunner task_graph_runner_; |
| 144 LayerTreeSettings layer_tree_settings_; | 148 LayerTreeSettings layer_tree_settings_; |
| 145 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; | 149 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; |
| 150 int scrollbar_layer_id_; |
| 146 }; | 151 }; |
| 147 | 152 |
| 148 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 153 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 149 // Create and attach a non-overlay scrollbar. | 154 // Create and attach a non-overlay scrollbar. |
| 150 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 155 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 151 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 156 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 152 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); | 157 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); |
| 153 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 158 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 154 static_cast<PaintedScrollbarLayerImpl*>( | 159 static_cast<PaintedScrollbarLayerImpl*>( |
| 155 layer_impl_tree_root->children()[1]); | 160 layer_impl_tree_root->layer_tree_impl()->LayerById( |
| 161 scrollbar_layer_id_)); |
| 156 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); | 162 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 157 ScrollTree& scroll_tree = | 163 ScrollTree& scroll_tree = |
| 158 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; | 164 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; |
| 159 ScrollNode* scroll_node = | 165 ScrollNode* scroll_node = |
| 160 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); | 166 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); |
| 161 | 167 |
| 162 // When the scrollbar is not an overlay scrollbar, the scroll should be | 168 // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 163 // responded to on the main thread as the compositor does not yet implement | 169 // responded to on the main thread as the compositor does not yet implement |
| 164 // scrollbar scrolling. | 170 // scrollbar scrolling. |
| 165 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( | 171 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( |
| 166 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); | 172 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); |
| 167 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | 173 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
| 168 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, | 174 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, |
| 169 status.main_thread_scrolling_reasons); | 175 status.main_thread_scrolling_reasons); |
| 170 | 176 |
| 171 // Create and attach an overlay scrollbar. | 177 // Create and attach an overlay scrollbar. |
| 172 scrollbar.reset(new FakeScrollbar(false, false, true)); | 178 scrollbar.reset(new FakeScrollbar(false, false, true)); |
| 173 | 179 |
| 174 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 180 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 175 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); | 181 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); |
| 176 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 182 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
| 177 layer_impl_tree_root->children()[1]); | 183 layer_impl_tree_root->layer_tree_impl()->LayerById(scrollbar_layer_id_)); |
| 178 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); | 184 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 179 scroll_tree = | 185 scroll_tree = |
| 180 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; | 186 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; |
| 181 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); | 187 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); |
| 182 | 188 |
| 183 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 189 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 184 // may be handled in the compositor. | 190 // may be handled in the compositor. |
| 185 status = layer_tree_host_->host_impl()->TryScroll( | 191 status = layer_tree_host_->host_impl()->TryScroll( |
| 186 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); | 192 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); |
| 187 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); | 193 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 212 | 218 |
| 213 layer_tree_root->SavePaintProperties(); | 219 layer_tree_root->SavePaintProperties(); |
| 214 content_layer->SavePaintProperties(); | 220 content_layer->SavePaintProperties(); |
| 215 | 221 |
| 216 layer_tree_host_->UpdateLayers(); | 222 layer_tree_host_->UpdateLayers(); |
| 217 LayerImpl* layer_impl_tree_root = | 223 LayerImpl* layer_impl_tree_root = |
| 218 layer_tree_host_->CommitAndCreateLayerImplTree(); | 224 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 219 | 225 |
| 220 ScrollbarLayerImplBase* cc_scrollbar_layer = | 226 ScrollbarLayerImplBase* cc_scrollbar_layer = |
| 221 static_cast<PaintedScrollbarLayerImpl*>( | 227 static_cast<PaintedScrollbarLayerImpl*>( |
| 222 layer_impl_tree_root->children()[1]); | 228 layer_impl_tree_root->layer_tree_impl()->LayerById( |
| 229 scrollbar_layer->id())); |
| 223 | 230 |
| 224 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); | 231 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
| 225 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - | 232 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - |
| 226 cc_scrollbar_layer->clip_layer_length()); | 233 cc_scrollbar_layer->clip_layer_length()); |
| 227 | 234 |
| 228 layer_tree_root->SetBounds(gfx::Size(700, 1500)); | 235 layer_tree_root->SetBounds(gfx::Size(700, 1500)); |
| 229 layer_tree_root->SavePaintProperties(); | 236 layer_tree_root->SavePaintProperties(); |
| 230 scroll_layer->SetBounds(gfx::Size(1000, 2000)); | 237 scroll_layer->SetBounds(gfx::Size(1000, 2000)); |
| 231 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); | 238 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); |
| 232 scroll_layer->SavePaintProperties(); | 239 scroll_layer->SavePaintProperties(); |
| 233 content_layer->SetBounds(gfx::Size(1000, 2000)); | 240 content_layer->SetBounds(gfx::Size(1000, 2000)); |
| 234 content_layer->SavePaintProperties(); | 241 content_layer->SavePaintProperties(); |
| 235 | 242 |
| 236 layer_tree_host_->UpdateLayers(); | 243 layer_tree_host_->UpdateLayers(); |
| 237 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); | 244 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 238 | 245 |
| 239 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); | 246 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); |
| 240 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - | 247 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - |
| 241 cc_scrollbar_layer->clip_layer_length()); | 248 cc_scrollbar_layer->clip_layer_length()); |
| 242 | 249 |
| 243 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; | 250 LayerImpl* scroll_layer_impl = |
| 251 layer_impl_tree_root->layer_tree_impl()->LayerById(scroll_layer->id()); |
| 244 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); | 252 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); |
| 245 | 253 |
| 246 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); | 254 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
| 247 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - | 255 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - |
| 248 cc_scrollbar_layer->clip_layer_length()); | 256 cc_scrollbar_layer->clip_layer_length()); |
| 249 } | 257 } |
| 250 | 258 |
| 251 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ | 259 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ |
| 252 do { \ | 260 do { \ |
| 253 scrollbar_layer->UpdateInternalContentScale(); \ | 261 scrollbar_layer->UpdateInternalContentScale(); \ |
| 254 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | 262 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
| 255 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ | 263 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ |
| 256 root_layer_impl = root_clip_layer_impl->children()[0]; \ | |
| 257 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | 264 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
| 258 root_layer_impl->children()[1]); \ | 265 root_clip_layer_impl->layer_tree_impl()->LayerById( \ |
| 266 scrollbar_layer->id())); \ |
| 259 } while (false) | 267 } while (false) |
| 260 | 268 |
| 261 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { | 269 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { |
| 262 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 270 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 263 scoped_refptr<Layer> root_layer = Layer::Create(); | 271 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 264 scoped_refptr<Layer> content_layer = Layer::Create(); | 272 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 265 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 273 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 266 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 274 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 267 | 275 |
| 268 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 276 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 269 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 277 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 270 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 278 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 271 root_layer->SetBounds(gfx::Size(100, 50)); | 279 root_layer->SetBounds(gfx::Size(100, 50)); |
| 272 content_layer->SetBounds(gfx::Size(100, 50)); | 280 content_layer->SetBounds(gfx::Size(100, 50)); |
| 273 | 281 |
| 274 layer_tree_host_->SetRootLayer(root_clip_layer); | 282 layer_tree_host_->SetRootLayer(root_clip_layer); |
| 275 root_clip_layer->AddChild(root_layer); | 283 root_clip_layer->AddChild(root_layer); |
| 276 root_layer->AddChild(content_layer); | 284 root_layer->AddChild(content_layer); |
| 277 root_layer->AddChild(scrollbar_layer); | 285 root_layer->AddChild(scrollbar_layer); |
| 278 | 286 |
| 279 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); | 287 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
| 280 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 288 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
| 281 scrollbar_layer->SetScrollLayer(root_layer->id()); | 289 scrollbar_layer->SetScrollLayer(root_layer->id()); |
| 282 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 290 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
| 283 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 291 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
| 284 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 292 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
| 285 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 293 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
| 286 LayerImpl* root_clip_layer_impl = nullptr; | 294 LayerImpl* root_clip_layer_impl = nullptr; |
| 287 LayerImpl* root_layer_impl = nullptr; | |
| 288 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; | 295 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; |
| 289 | 296 |
| 290 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 297 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 291 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 298 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
| 292 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 299 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 293 | 300 |
| 294 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); | 301 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); |
| 295 | 302 |
| 296 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 303 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 297 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), | 304 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 318 | 325 |
| 319 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); | 326 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
| 320 scrollbar_layer->SetBounds(gfx::Size(70, 10)); | 327 scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
| 321 scrollbar_layer->SetScrollLayer(root_layer->id()); | 328 scrollbar_layer->SetScrollLayer(root_layer->id()); |
| 322 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); | 329 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
| 323 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); | 330 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
| 324 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); | 331 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
| 325 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); | 332 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
| 326 layer_tree_host_->UpdateLayers(); | 333 layer_tree_host_->UpdateLayers(); |
| 327 LayerImpl* root_clip_layer_impl = nullptr; | 334 LayerImpl* root_clip_layer_impl = nullptr; |
| 328 LayerImpl* root_layer_impl = nullptr; | |
| 329 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; | 335 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; |
| 330 | 336 |
| 331 // Thumb is at the edge of the scrollbar (should be inset to | 337 // Thumb is at the edge of the scrollbar (should be inset to |
| 332 // the start of the track within the scrollbar layer's | 338 // the start of the track within the scrollbar layer's |
| 333 // position). | 339 // position). |
| 334 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 340 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 335 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), | 341 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
| 336 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 342 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 337 | 343 |
| 338 // Under-scroll (thumb position should clamp and be unchanged). | 344 // Under-scroll (thumb position should clamp and be unchanged). |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 const int kThumbThickness = 3; | 386 const int kThumbThickness = 3; |
| 381 const int kTrackStart = 1; | 387 const int kTrackStart = 1; |
| 382 const int kTrackLength = 100; | 388 const int kTrackLength = 100; |
| 383 | 389 |
| 384 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 390 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 385 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 391 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 386 layer_tree_host_.get(), std::move(scrollbar), false, true, | 392 layer_tree_host_.get(), std::move(scrollbar), false, true, |
| 387 kThumbThickness, kTrackStart); | 393 kThumbThickness, kTrackStart); |
| 388 ScrollbarLayerImplBase* scrollbar_layer_impl = | 394 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 389 static_cast<SolidColorScrollbarLayerImpl*>( | 395 static_cast<SolidColorScrollbarLayerImpl*>( |
| 390 layer_impl_tree_root->children()[1]); | 396 layer_impl_tree_root->layer_tree_impl()->LayerById( |
| 397 scrollbar_layer_id_)); |
| 391 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 398 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 392 scrollbar_layer_impl->SetCurrentPos(10.f); | 399 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 393 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); | 400 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); |
| 394 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); | 401 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); |
| 395 | 402 |
| 396 // Thickness should be overridden to 3. | 403 // Thickness should be overridden to 3. |
| 397 { | 404 { |
| 398 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | 405 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 399 AppendQuadsData data; | 406 AppendQuadsData data; |
| 400 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); | 407 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 443 } |
| 437 } | 444 } |
| 438 | 445 |
| 439 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 446 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 440 const int kThumbThickness = 3; | 447 const int kThumbThickness = 3; |
| 441 const int kTrackStart = 0; | 448 const int kTrackStart = 0; |
| 442 const int kTrackLength = 10; | 449 const int kTrackLength = 10; |
| 443 | 450 |
| 444 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 451 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 445 | 452 |
| 446 { | 453 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 447 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 454 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 448 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 455 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 449 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 456 scoped_refptr<Layer> child1 = Layer::Create(); |
| 450 scoped_refptr<Layer> child1 = Layer::Create(); | 457 scoped_refptr<Layer> child2; |
| 451 scoped_refptr<Layer> child2; | 458 const bool kIsLeftSideVerticalScrollbar = false; |
| 452 const bool kIsLeftSideVerticalScrollbar = false; | 459 child2 = SolidColorScrollbarLayer::Create( |
| 453 child2 = SolidColorScrollbarLayer::Create( | 460 scrollbar->Orientation(), kThumbThickness, kTrackStart, |
| 454 scrollbar->Orientation(), kThumbThickness, kTrackStart, | 461 kIsLeftSideVerticalScrollbar, child1->id()); |
| 455 kIsLeftSideVerticalScrollbar, child1->id()); | 462 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
| 456 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); | 463 scroll_layer->AddChild(child1); |
| 457 scroll_layer->AddChild(child1); | 464 scroll_layer->InsertChild(child2, 1); |
| 458 scroll_layer->InsertChild(child2, 1); | 465 layer_tree_root->AddChild(scroll_layer); |
| 459 layer_tree_root->AddChild(scroll_layer); | 466 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 460 layer_tree_host_->SetRootLayer(layer_tree_root); | |
| 461 | 467 |
| 462 // Choose layer bounds to give max_scroll_offset = (8, 8). | 468 // Choose layer bounds to give max_scroll_offset = (8, 8). |
| 463 layer_tree_root->SetBounds(gfx::Size(2, 2)); | 469 layer_tree_root->SetBounds(gfx::Size(2, 2)); |
| 464 scroll_layer->SetBounds(gfx::Size(10, 10)); | 470 scroll_layer->SetBounds(gfx::Size(10, 10)); |
| 465 | 471 |
| 466 layer_tree_host_->UpdateLayers(); | 472 layer_tree_host_->UpdateLayers(); |
| 467 } | |
| 468 | 473 |
| 469 LayerImpl* layer_impl_tree_root = | 474 LayerImpl* layer_impl_tree_root = |
| 470 layer_tree_host_->CommitAndCreateLayerImplTree(); | 475 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 471 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; | 476 LayerImpl* scroll_layer_impl = |
| 477 layer_impl_tree_root->layer_tree_impl()->LayerById(scroll_layer->id()); |
| 472 | 478 |
| 473 auto* scrollbar_layer_impl = | 479 auto* scrollbar_layer_impl = static_cast<ScrollbarLayerImplBase*>( |
| 474 static_cast<ScrollbarLayerImplBase*>(scroll_layer_impl->children()[1]); | 480 scroll_layer_impl->layer_tree_impl()->LayerById(child2->id())); |
| 475 | 481 |
| 476 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 482 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 477 | 483 |
| 478 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 484 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 479 scrollbar_layer_impl->SetCurrentPos(4.f); | 485 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 480 | 486 |
| 481 { | 487 { |
| 482 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | 488 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 483 | 489 |
| 484 AppendQuadsData data; | 490 AppendQuadsData data; |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1019 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1014 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1020 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1015 | 1021 |
| 1016 // Horizontal Scrollbars. | 1022 // Horizontal Scrollbars. |
| 1017 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1023 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1018 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1024 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1019 } | 1025 } |
| 1020 | 1026 |
| 1021 } // namespace | 1027 } // namespace |
| 1022 } // namespace cc | 1028 } // namespace cc |
| OLD | NEW |