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