| 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 "cc/layers/scrollbar_layer.h" | 5 #include "cc/layers/scrollbar_layer.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "cc/animation/scrollbar_animation_controller.h" | 8 #include "cc/animation/scrollbar_animation_controller.h" |
| 9 #include "cc/debug/test_web_graphics_context_3d.h" | 9 #include "cc/debug/test_web_graphics_context_3d.h" |
| 10 #include "cc/layers/append_quads_data.h" | 10 #include "cc/layers/append_quads_data.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 layer_tree_settings.solid_color_scrollbars = true; | 161 layer_tree_settings.solid_color_scrollbars = true; |
| 162 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | 162 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
| 163 scoped_ptr<FakeLayerTreeHost> host = | 163 scoped_ptr<FakeLayerTreeHost> host = |
| 164 FakeLayerTreeHost::Create(layer_tree_settings); | 164 FakeLayerTreeHost::Create(layer_tree_settings); |
| 165 | 165 |
| 166 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 166 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 167 LayerImpl* layer_impl_tree_root = | 167 LayerImpl* layer_impl_tree_root = |
| 168 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 168 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); |
| 169 ScrollbarLayerImpl* scrollbar_layer_impl = | 169 ScrollbarLayerImpl* scrollbar_layer_impl = |
| 170 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 170 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 171 scrollbar_layer_impl->set_thumb_thickness(3); | 171 scrollbar_layer_impl->SetThumbThickness(3); |
| 172 scrollbar_layer_impl->SetCurrentPos(10.f); | 172 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 173 scrollbar_layer_impl->SetMaximum(100); | 173 scrollbar_layer_impl->SetMaximum(100); |
| 174 scrollbar_layer_impl->set_track_length(100); | 174 scrollbar_layer_impl->SetTrackLength(100); |
| 175 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); | 175 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
| 176 | 176 |
| 177 // Thickness should be overridden to 3. | 177 // Thickness should be overridden to 3. |
| 178 { | 178 { |
| 179 MockQuadCuller quad_culler; | 179 MockQuadCuller quad_culler; |
| 180 AppendQuadsData data; | 180 AppendQuadsData data; |
| 181 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 181 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 182 | 182 |
| 183 const QuadList& quads = quad_culler.quad_list(); | 183 const QuadList& quads = quad_culler.quad_list(); |
| 184 ASSERT_EQ(1u, quads.size()); | 184 ASSERT_EQ(1u, quads.size()); |
| 185 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 185 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 const QuadList& quads = quad_culler.quad_list(); | 197 const QuadList& quads = quad_culler.quad_list(); |
| 198 ASSERT_EQ(1u, quads.size()); | 198 ASSERT_EQ(1u, quads.size()); |
| 199 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 199 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 200 EXPECT_RECT_EQ(gfx::Rect(12, 0, 80, 6), quads[0]->rect); | 200 EXPECT_RECT_EQ(gfx::Rect(12, 0, 80, 6), quads[0]->rect); |
| 201 } | 201 } |
| 202 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; | 202 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; |
| 203 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; | 203 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; |
| 204 | 204 |
| 205 // For solid color scrollbars, position and size should reflect the | 205 // For solid color scrollbars, position and size should reflect the |
| 206 // current viewport state. | 206 // current viewport state. |
| 207 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.2f); | 207 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); |
| 208 { | 208 { |
| 209 MockQuadCuller quad_culler; | 209 MockQuadCuller quad_culler; |
| 210 AppendQuadsData data; | 210 AppendQuadsData data; |
| 211 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 211 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 212 | 212 |
| 213 const QuadList& quads = quad_culler.quad_list(); | 213 const QuadList& quads = quad_culler.quad_list(); |
| 214 ASSERT_EQ(1u, quads.size()); | 214 ASSERT_EQ(1u, quads.size()); |
| 215 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 215 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 216 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 216 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 220 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 221 LayerTreeSettings layer_tree_settings; | 221 LayerTreeSettings layer_tree_settings; |
| 222 layer_tree_settings.solid_color_scrollbars = true; | 222 layer_tree_settings.solid_color_scrollbars = true; |
| 223 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | 223 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
| 224 scoped_ptr<FakeLayerTreeHost> host = | 224 scoped_ptr<FakeLayerTreeHost> host = |
| 225 FakeLayerTreeHost::Create(layer_tree_settings); | 225 FakeLayerTreeHost::Create(layer_tree_settings); |
| 226 | 226 |
| 227 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 227 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 228 LayerImpl* layer_impl_tree_root = | 228 LayerImpl* layer_impl_tree_root = |
| 229 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 229 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); |
| 230 ScrollbarLayerImpl* scrollbar_layer_impl = | 230 ScrollbarLayerImpl* scrollbar_layer_impl = |
| 231 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 231 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 232 | 232 |
| 233 scrollbar_layer_impl->set_thumb_thickness(3); | 233 scrollbar_layer_impl->SetThumbThickness(3); |
| 234 scrollbar_layer_impl->set_track_length(10); | 234 scrollbar_layer_impl->SetTrackLength(10); |
| 235 scrollbar_layer_impl->SetCurrentPos(4.f); | 235 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 236 scrollbar_layer_impl->SetMaximum(8); | 236 scrollbar_layer_impl->SetMaximum(8); |
| 237 | 237 |
| 238 layer_impl_tree_root->SetScrollable(true); | 238 layer_impl_tree_root->SetScrollable(true); |
| 239 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | 239 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
| 240 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | 240 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
| 241 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 241 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 242 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 242 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 243 | 243 |
| 244 { | 244 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 269 protected: | 269 protected: |
| 270 FakeImplProxy proxy_; | 270 FakeImplProxy proxy_; |
| 271 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 271 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
| 272 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; | 272 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; |
| 273 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; | 273 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 276 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
| 277 horizontal_scrollbar_layer_->SetCurrentPos(0); | 277 horizontal_scrollbar_layer_->SetCurrentPos(0); |
| 278 horizontal_scrollbar_layer_->SetMaximum(10); | 278 horizontal_scrollbar_layer_->SetMaximum(10); |
| 279 horizontal_scrollbar_layer_->set_thumb_thickness(3); | 279 horizontal_scrollbar_layer_->SetThumbThickness(3); |
| 280 | 280 |
| 281 // Simple case - one third of the scrollable area is visible, so the thumb | 281 // Simple case - one third of the scrollable area is visible, so the thumb |
| 282 // should be one third as long as the track. | 282 // should be one third as long as the track. |
| 283 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); | 283 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); |
| 284 horizontal_scrollbar_layer_->set_track_length(100); | 284 horizontal_scrollbar_layer_->SetTrackLength(100); |
| 285 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 285 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 286 | 286 |
| 287 // The thumb's length should never be less than its thickness. | 287 // The thumb's length should never be less than its thickness. |
| 288 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); | 288 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); |
| 289 horizontal_scrollbar_layer_->set_track_length(100); | 289 horizontal_scrollbar_layer_->SetTrackLength(100); |
| 290 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 290 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { | 293 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
| 294 horizontal_scrollbar_layer_->set_track_length(100); | 294 horizontal_scrollbar_layer_->SetTrackLength(100); |
| 295 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); | 295 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); |
| 296 horizontal_scrollbar_layer_->set_thumb_thickness(3); | 296 horizontal_scrollbar_layer_->SetThumbThickness(3); |
| 297 | 297 |
| 298 horizontal_scrollbar_layer_->SetCurrentPos(0); | 298 horizontal_scrollbar_layer_->SetCurrentPos(0); |
| 299 horizontal_scrollbar_layer_->SetMaximum(100); | 299 horizontal_scrollbar_layer_->SetMaximum(100); |
| 300 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 300 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 301 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 301 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 302 | 302 |
| 303 horizontal_scrollbar_layer_->SetCurrentPos(100); | 303 horizontal_scrollbar_layer_->SetCurrentPos(100); |
| 304 // The thumb is 10px long and the track is 100px, so the maximum thumb | 304 // The thumb is 10px long and the track is 100px, so the maximum thumb |
| 305 // position is 90px. | 305 // position is 90px. |
| 306 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 306 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 307 | 307 |
| 308 horizontal_scrollbar_layer_->SetCurrentPos(80); | 308 horizontal_scrollbar_layer_->SetCurrentPos(80); |
| 309 // The scroll position is 80% of the maximum, so the thumb's position should | 309 // The scroll position is 80% of the maximum, so the thumb's position should |
| 310 // be at 80% of its maximum or 72px. | 310 // be at 80% of its maximum or 72px. |
| 311 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 311 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 312 } | 312 } |
| 313 | 313 |
| 314 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { | 314 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
| 315 ScrollbarLayerImpl* layers[2] = | 315 ScrollbarLayerImpl* layers[2] = |
| 316 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 316 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
| 317 for (size_t i = 0; i < 2; ++i) { | 317 for (size_t i = 0; i < 2; ++i) { |
| 318 layers[i]->set_track_length(100); | 318 layers[i]->SetTrackLength(100); |
| 319 layers[i]->set_visible_to_total_length_ratio(0.2f); | 319 layers[i]->SetVisibleToTotalLengthRatio(0.2f); |
| 320 layers[i]->set_thumb_thickness(3); | 320 layers[i]->SetThumbThickness(3); |
| 321 layers[i]->SetCurrentPos(25); | 321 layers[i]->SetCurrentPos(25); |
| 322 layers[i]->SetMaximum(100); | 322 layers[i]->SetMaximum(100); |
| 323 } | 323 } |
| 324 | 324 |
| 325 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 325 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
| 326 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 326 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 327 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 327 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
| 328 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 328 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 329 | 329 |
| 330 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); | 330 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 331 vertical_scrollbar_layer_->set_vertical_adjust(10.f); | 331 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 332 | 332 |
| 333 // The vertical adjustment factor has two effects: | 333 // The vertical adjustment factor has two effects: |
| 334 // 1.) Moves the horizontal scrollbar down | 334 // 1.) Moves the horizontal scrollbar down |
| 335 // 2.) Increases the vertical scrollbar's effective track length which both | 335 // 2.) Increases the vertical scrollbar's effective track length which both |
| 336 // increases the thumb's length and its position within the track. | 336 // increases the thumb's length and its position within the track. |
| 337 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), | 337 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), |
| 338 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 338 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 339 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), | 339 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), |
| 340 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 340 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 341 } | 341 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 layer_tree_settings_.solid_color_scrollbars = false; | 605 layer_tree_settings_.solid_color_scrollbars = false; |
| 606 // Pick a test scale that moves the scrollbar's (non-zero) position to | 606 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 607 // a non-pixel-aligned location. | 607 // a non-pixel-aligned location. |
| 608 TestResourceUpload(.041f); | 608 TestResourceUpload(.041f); |
| 609 TestResourceUpload(1.41f); | 609 TestResourceUpload(1.41f); |
| 610 TestResourceUpload(4.1f); | 610 TestResourceUpload(4.1f); |
| 611 } | 611 } |
| 612 | 612 |
| 613 } // namespace | 613 } // namespace |
| 614 } // namespace cc | 614 } // namespace cc |
| OLD | NEW |