| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host_impl.h" | 7 #include "cc/layer_tree_host_impl.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "cc/delegated_renderer_layer_impl.h" | 12 #include "cc/delegated_renderer_layer_impl.h" |
| 13 #include "cc/geometry.h" |
| 13 #include "cc/gl_renderer.h" | 14 #include "cc/gl_renderer.h" |
| 14 #include "cc/heads_up_display_layer_impl.h" | 15 #include "cc/heads_up_display_layer_impl.h" |
| 15 #include "cc/io_surface_layer_impl.h" | 16 #include "cc/io_surface_layer_impl.h" |
| 16 #include "cc/layer_impl.h" | 17 #include "cc/layer_impl.h" |
| 17 #include "cc/layer_tiling_data.h" | 18 #include "cc/layer_tiling_data.h" |
| 18 #include "cc/quad_sink.h" | 19 #include "cc/quad_sink.h" |
| 19 #include "cc/render_pass_draw_quad.h" | 20 #include "cc/render_pass_draw_quad.h" |
| 20 #include "cc/scrollbar_geometry_fixed_thumb.h" | 21 #include "cc/scrollbar_geometry_fixed_thumb.h" |
| 21 #include "cc/scrollbar_layer_impl.h" | 22 #include "cc/scrollbar_layer_impl.h" |
| 22 #include "cc/settings.h" | 23 #include "cc/settings.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 #include "cc/texture_draw_quad.h" | 34 #include "cc/texture_draw_quad.h" |
| 34 #include "cc/texture_layer_impl.h" | 35 #include "cc/texture_layer_impl.h" |
| 35 #include "cc/tile_draw_quad.h" | 36 #include "cc/tile_draw_quad.h" |
| 36 #include "cc/tiled_layer_impl.h" | 37 #include "cc/tiled_layer_impl.h" |
| 37 #include "cc/video_layer_impl.h" | 38 #include "cc/video_layer_impl.h" |
| 38 #include "media/base/media.h" | 39 #include "media/base/media.h" |
| 39 #include "media/base/video_frame.h" | 40 #include "media/base/video_frame.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 41 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "ui/gfx/size_conversions.h" | 43 #include "ui/gfx/size_conversions.h" |
| 44 #include "ui/gfx/vector2d_conversions.h" |
| 43 #include <public/WebVideoFrame.h> | 45 #include <public/WebVideoFrame.h> |
| 44 #include <public/WebVideoFrameProvider.h> | 46 #include <public/WebVideoFrameProvider.h> |
| 45 | 47 |
| 46 using namespace cc; | 48 using namespace cc; |
| 47 using namespace LayerTestCommon; | 49 using namespace LayerTestCommon; |
| 48 using namespace WebKit; | 50 using namespace WebKit; |
| 49 using namespace WebKitTests; | 51 using namespace WebKitTests; |
| 50 | 52 |
| 51 using media::VideoFrame; | 53 using media::VideoFrame; |
| 52 using ::testing::Mock; | 54 using ::testing::Mock; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 root->setBounds(gfx::Size(10, 10)); | 117 root->setBounds(gfx::Size(10, 10)); |
| 116 root->setContentBounds(gfx::Size(10, 10)); | 118 root->setContentBounds(gfx::Size(10, 10)); |
| 117 root->setVisibleContentRect(gfx::Rect(0, 0, 10, 10)); | 119 root->setVisibleContentRect(gfx::Rect(0, 0, 10, 10)); |
| 118 root->setDrawsContent(true); | 120 root->setDrawsContent(true); |
| 119 myHostImpl->setRootLayer(root.Pass()); | 121 myHostImpl->setRootLayer(root.Pass()); |
| 120 return myHostImpl.Pass(); | 122 return myHostImpl.Pass(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 static void expectClearedScrollDeltasRecursive(LayerImpl* layer) | 125 static void expectClearedScrollDeltasRecursive(LayerImpl* layer) |
| 124 { | 126 { |
| 125 ASSERT_EQ(layer->scrollDelta(), IntSize()); | 127 ASSERT_EQ(layer->scrollDelta(), gfx::Vector2d()); |
| 126 for (size_t i = 0; i < layer->children().size(); ++i) | 128 for (size_t i = 0; i < layer->children().size(); ++i) |
| 127 expectClearedScrollDeltasRecursive(layer->children()[i]); | 129 expectClearedScrollDeltasRecursive(layer->children()[i]); |
| 128 } | 130 } |
| 129 | 131 |
| 130 static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, cons
t IntSize& scrollDelta) | 132 static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, cons
t gfx::Vector2d& scrollDelta) |
| 131 { | 133 { |
| 132 int timesEncountered = 0; | 134 int timesEncountered = 0; |
| 133 | 135 |
| 134 for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { | 136 for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { |
| 135 if (scrollInfo.scrolls[i].layerId != id) | 137 if (scrollInfo.scrolls[i].layerId != id) |
| 136 continue; | 138 continue; |
| 137 EXPECT_EQ(scrollDelta.width(), scrollInfo.scrolls[i].scrollDelta.wid
th()); | 139 EXPECT_VECTOR_EQ(scrollDelta, scrollInfo.scrolls[i].scrollDelta); |
| 138 EXPECT_EQ(scrollDelta.height(), scrollInfo.scrolls[i].scrollDelta.he
ight()); | |
| 139 timesEncountered++; | 140 timesEncountered++; |
| 140 } | 141 } |
| 141 | 142 |
| 142 ASSERT_EQ(timesEncountered, 1); | 143 ASSERT_EQ(timesEncountered, 1); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void setupScrollAndContentsLayers(const gfx::Size& contentSize) | 146 void setupScrollAndContentsLayers(const gfx::Size& contentSize) |
| 146 { | 147 { |
| 147 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | 148 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 148 root->setScrollable(true); | 149 root->setScrollable(true); |
| 149 root->setScrollPosition(IntPoint(0, 0)); | 150 root->setScrollOffset(gfx::Vector2d(0, 0)); |
| 150 root->setMaxScrollPosition(cc::IntSize(contentSize)); | 151 root->setMaxScrollOffset(gfx::Vector2d(contentSize.width(), contentSize.
height())); |
| 151 root->setBounds(contentSize); | 152 root->setBounds(contentSize); |
| 152 root->setContentBounds(contentSize); | 153 root->setContentBounds(contentSize); |
| 153 root->setPosition(gfx::PointF(0, 0)); | 154 root->setPosition(gfx::PointF(0, 0)); |
| 154 root->setAnchorPoint(gfx::PointF(0, 0)); | 155 root->setAnchorPoint(gfx::PointF(0, 0)); |
| 155 | 156 |
| 156 scoped_ptr<LayerImpl> contents = LayerImpl::create(2); | 157 scoped_ptr<LayerImpl> contents = LayerImpl::create(2); |
| 157 contents->setDrawsContent(true); | 158 contents->setDrawsContent(true); |
| 158 contents->setBounds(contentSize); | 159 contents->setBounds(contentSize); |
| 159 contents->setContentBounds(contentSize); | 160 contents->setContentBounds(contentSize); |
| 160 contents->setPosition(gfx::PointF(0, 0)); | 161 contents->setPosition(gfx::PointF(0, 0)); |
| 161 contents->setAnchorPoint(gfx::PointF(0, 0)); | 162 contents->setAnchorPoint(gfx::PointF(0, 0)); |
| 162 root->addChild(contents.Pass()); | 163 root->addChild(contents.Pass()); |
| 163 m_hostImpl->setRootLayer(root.Pass()); | 164 m_hostImpl->setRootLayer(root.Pass()); |
| 164 } | 165 } |
| 165 | 166 |
| 166 static scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size&
size) | 167 static scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size&
size) |
| 167 { | 168 { |
| 168 scoped_ptr<LayerImpl> layer = LayerImpl::create(id); | 169 scoped_ptr<LayerImpl> layer = LayerImpl::create(id); |
| 169 layer->setScrollable(true); | 170 layer->setScrollable(true); |
| 170 layer->setDrawsContent(true); | 171 layer->setDrawsContent(true); |
| 171 layer->setBounds(size); | 172 layer->setBounds(size); |
| 172 layer->setContentBounds(size); | 173 layer->setContentBounds(size); |
| 173 layer->setMaxScrollPosition(IntSize(size.width() * 2, size.height() * 2)
); | 174 layer->setMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height()
* 2)); |
| 174 return layer.Pass(); | 175 return layer.Pass(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 void initializeRendererAndDrawFrame() | 178 void initializeRendererAndDrawFrame() |
| 178 { | 179 { |
| 179 m_hostImpl->initializeRenderer(createContext()); | 180 m_hostImpl->initializeRenderer(createContext()); |
| 180 LayerTreeHostImpl::FrameData frame; | 181 LayerTreeHostImpl::FrameData frame; |
| 181 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 182 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 182 m_hostImpl->drawLayers(frame); | 183 m_hostImpl->drawLayers(frame); |
| 183 m_hostImpl->didDrawAllLayers(frame); | 184 m_hostImpl->didDrawAllLayers(frame); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); | 293 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 293 expectClearedScrollDeltasRecursive(root); | 294 expectClearedScrollDeltasRecursive(root); |
| 294 | 295 |
| 295 scrollInfo = m_hostImpl->processScrollDeltas(); | 296 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 296 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); | 297 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 297 expectClearedScrollDeltasRecursive(root); | 298 expectClearedScrollDeltasRecursive(root); |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST_P(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) | 301 TEST_P(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) |
| 301 { | 302 { |
| 302 IntPoint scrollPosition(20, 30); | 303 gfx::Vector2d scrollOffset(20, 30); |
| 303 IntSize scrollDelta(11, -15); | 304 gfx::Vector2d scrollDelta(11, -15); |
| 304 { | 305 { |
| 305 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | 306 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 306 root->setScrollPosition(scrollPosition); | 307 root->setScrollOffset(scrollOffset); |
| 307 root->setScrollable(true); | 308 root->setScrollable(true); |
| 308 root->setMaxScrollPosition(IntSize(100, 100)); | 309 root->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 309 root->scrollBy(scrollDelta); | 310 root->scrollBy(scrollDelta); |
| 310 m_hostImpl->setRootLayer(root.Pass()); | 311 m_hostImpl->setRootLayer(root.Pass()); |
| 311 } | 312 } |
| 312 LayerImpl* root = m_hostImpl->rootLayer(); | 313 LayerImpl* root = m_hostImpl->rootLayer(); |
| 313 | 314 |
| 314 scoped_ptr<ScrollAndScaleSet> scrollInfo; | 315 scoped_ptr<ScrollAndScaleSet> scrollInfo; |
| 315 | 316 |
| 316 scrollInfo = m_hostImpl->processScrollDeltas(); | 317 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 317 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 318 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 318 EXPECT_EQ(root->sentScrollDelta(), scrollDelta); | 319 EXPECT_VECTOR_EQ(root->sentScrollDelta(), scrollDelta); |
| 319 expectContains(*scrollInfo, root->id(), scrollDelta); | 320 expectContains(*scrollInfo, root->id(), scrollDelta); |
| 320 | 321 |
| 321 IntSize scrollDelta2(-5, 27); | 322 gfx::Vector2d scrollDelta2(-5, 27); |
| 322 root->scrollBy(scrollDelta2); | 323 root->scrollBy(scrollDelta2); |
| 323 scrollInfo = m_hostImpl->processScrollDeltas(); | 324 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 324 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 325 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 325 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); | 326 EXPECT_VECTOR_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); |
| 326 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); | 327 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); |
| 327 | 328 |
| 328 root->scrollBy(IntSize()); | 329 root->scrollBy(gfx::Vector2d()); |
| 329 scrollInfo = m_hostImpl->processScrollDeltas(); | 330 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 330 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); | 331 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); |
| 331 } | 332 } |
| 332 | 333 |
| 333 TEST_P(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) | 334 TEST_P(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) |
| 334 { | 335 { |
| 335 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 336 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 336 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 337 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 337 initializeRendererAndDrawFrame(); | 338 initializeRendererAndDrawFrame(); |
| 338 | 339 |
| 339 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 340 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 340 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 10)); | 341 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 341 m_hostImpl->scrollEnd(); | 342 m_hostImpl->scrollEnd(); |
| 342 EXPECT_TRUE(m_didRequestRedraw); | 343 EXPECT_TRUE(m_didRequestRedraw); |
| 343 EXPECT_TRUE(m_didRequestCommit); | 344 EXPECT_TRUE(m_didRequestCommit); |
| 344 } | 345 } |
| 345 | 346 |
| 346 TEST_P(LayerTreeHostImplTest, scrollWithoutRootLayer) | 347 TEST_P(LayerTreeHostImplTest, scrollWithoutRootLayer) |
| 347 { | 348 { |
| 348 // We should not crash when trying to scroll an empty layer tree. | 349 // We should not crash when trying to scroll an empty layer tree. |
| 349 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollIgnored); | 350 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollIgnored); |
| 350 } | 351 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 372 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 373 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 373 initializeRendererAndDrawFrame(); | 374 initializeRendererAndDrawFrame(); |
| 374 | 375 |
| 375 // We should not crash if the tree is replaced while we are scrolling. | 376 // We should not crash if the tree is replaced while we are scrolling. |
| 376 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 377 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 377 m_hostImpl->detachLayerTree(); | 378 m_hostImpl->detachLayerTree(); |
| 378 | 379 |
| 379 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 380 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 380 | 381 |
| 381 // We should still be scrolling, because the scrolled layer also exists in t
he new tree. | 382 // We should still be scrolling, because the scrolled layer also exists in t
he new tree. |
| 382 IntSize scrollDelta(0, 10); | 383 gfx::Vector2d scrollDelta(0, 10); |
| 383 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 384 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 384 m_hostImpl->scrollEnd(); | 385 m_hostImpl->scrollEnd(); |
| 385 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 386 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 386 expectContains(*scrollInfo, scrollLayerId, scrollDelta); | 387 expectContains(*scrollInfo, scrollLayerId, scrollDelta); |
| 387 } | 388 } |
| 388 | 389 |
| 389 TEST_P(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) | 390 TEST_P(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) |
| 390 { | 391 { |
| 391 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 392 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 392 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 393 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 LayerImpl* root = m_hostImpl->rootLayer(); | 436 LayerImpl* root = m_hostImpl->rootLayer(); |
| 436 | 437 |
| 437 root->setNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); | 438 root->setNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 438 | 439 |
| 439 // All scroll types inside the non-fast scrollable region should fail. | 440 // All scroll types inside the non-fast scrollable region should fail. |
| 440 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollOnMainThread); | 441 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollOnMainThread); |
| 441 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollOnMainThread); | 442 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollOnMainThread); |
| 442 | 443 |
| 443 // All scroll types outside this region should succeed. | 444 // All scroll types outside this region should succeed. |
| 444 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); | 445 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 445 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 10)); | 446 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 446 m_hostImpl->scrollEnd(); | 447 m_hostImpl->scrollEnd(); |
| 447 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); | 448 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); |
| 448 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 10)); | 449 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 449 m_hostImpl->scrollEnd(); | 450 m_hostImpl->scrollEnd(); |
| 450 } | 451 } |
| 451 | 452 |
| 452 TEST_P(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) | 453 TEST_P(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) |
| 453 { | 454 { |
| 454 setupScrollAndContentsLayers(gfx::Size(200, 200)); | 455 setupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 455 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); | 456 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
| 456 LayerImpl* root = m_hostImpl->rootLayer(); | 457 LayerImpl* root = m_hostImpl->rootLayer(); |
| 457 | 458 |
| 458 root->setNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); | 459 root->setNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 459 root->setPosition(gfx::PointF(-25, 0)); | 460 root->setPosition(gfx::PointF(-25, 0)); |
| 460 initializeRendererAndDrawFrame(); | 461 initializeRendererAndDrawFrame(); |
| 461 | 462 |
| 462 // This point would fall into the non-fast scrollable region except that we'
ve moved the layer down by 25 pixels. | 463 // This point would fall into the non-fast scrollable region except that we'
ve moved the layer down by 25 pixels. |
| 463 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(40, 10), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); | 464 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(40, 10), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 464 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 1)); | 465 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 1)); |
| 465 m_hostImpl->scrollEnd(); | 466 m_hostImpl->scrollEnd(); |
| 466 | 467 |
| 467 // This point is still inside the non-fast region. | 468 // This point is still inside the non-fast region. |
| 468 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(10, 10), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollOnMainThread); | 469 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(10, 10), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollOnMainThread); |
| 469 } | 470 } |
| 470 | 471 |
| 471 TEST_P(LayerTreeHostImplTest, maxScrollPositionChangedByDeviceScaleFactor) | 472 TEST_P(LayerTreeHostImplTest, maxScrollOffsetChangedByDeviceScaleFactor) |
| 472 { | 473 { |
| 473 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 474 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 474 | 475 |
| 475 float deviceScaleFactor = 2; | 476 float deviceScaleFactor = 2; |
| 476 gfx::Size layoutViewport(25, 25); | 477 gfx::Size layoutViewport(25, 25); |
| 477 gfx::Size deviceViewport(gfx::ToFlooredSize(layoutViewport.Scale(deviceScale
Factor))); | 478 gfx::Size deviceViewport(gfx::ToFlooredSize(layoutViewport.Scale(deviceScale
Factor))); |
| 478 m_hostImpl->setViewportSize(layoutViewport, deviceViewport); | 479 m_hostImpl->setViewportSize(layoutViewport, deviceViewport); |
| 479 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 480 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
| 480 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(25, 25)); | 481 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(25, 25))
; |
| 481 | 482 |
| 482 deviceScaleFactor = 1; | 483 deviceScaleFactor = 1; |
| 483 m_hostImpl->setViewportSize(layoutViewport, layoutViewport); | 484 m_hostImpl->setViewportSize(layoutViewport, layoutViewport); |
| 484 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 485 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
| 485 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(75, 75)); | 486 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(75, 75))
; |
| 486 } | 487 } |
| 487 | 488 |
| 488 TEST_P(LayerTreeHostImplTest, implPinchZoom) | 489 TEST_P(LayerTreeHostImplTest, implPinchZoom) |
| 489 { | 490 { |
| 490 // This test is specific to the page-scale based pinch zoom. | 491 // This test is specific to the page-scale based pinch zoom. |
| 491 if (!Settings::pageScalePinchZoomEnabled()) | 492 if (!Settings::pageScalePinchZoomEnabled()) |
| 492 return; | 493 return; |
| 493 | 494 |
| 494 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 495 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 495 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 496 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 496 initializeRendererAndDrawFrame(); | 497 initializeRendererAndDrawFrame(); |
| 497 | 498 |
| 498 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 499 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 499 DCHECK(scrollLayer); | 500 DCHECK(scrollLayer); |
| 500 | 501 |
| 501 const float minPageScale = 1, maxPageScale = 4; | 502 const float minPageScale = 1, maxPageScale = 4; |
| 502 const WebTransformationMatrix identityScaleTransform; | 503 const WebTransformationMatrix identityScaleTransform; |
| 503 | 504 |
| 504 // The impl-based pinch zoome should not adjust the max scroll position. | 505 // The impl-based pinch zoome should not adjust the max scroll position. |
| 505 { | 506 { |
| 506 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 507 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 507 scrollLayer->setImplTransform(identityScaleTransform); | 508 scrollLayer->setImplTransform(identityScaleTransform); |
| 508 scrollLayer->setScrollDelta(IntSize()); | 509 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 509 | 510 |
| 510 float pageScaleDelta = 2; | 511 float pageScaleDelta = 2; |
| 511 m_hostImpl->pinchGestureBegin(); | 512 m_hostImpl->pinchGestureBegin(); |
| 512 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 513 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 513 m_hostImpl->pinchGestureEnd(); | 514 m_hostImpl->pinchGestureEnd(); |
| 514 EXPECT_TRUE(m_didRequestRedraw); | 515 EXPECT_TRUE(m_didRequestRedraw); |
| 515 EXPECT_TRUE(m_didRequestCommit); | 516 EXPECT_TRUE(m_didRequestCommit); |
| 516 | 517 |
| 517 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 518 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 518 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 519 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 519 | 520 |
| 520 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(50, 50))
; | 521 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(50,
50)); |
| 521 } | 522 } |
| 522 | 523 |
| 523 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not | 524 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not |
| 524 // have the page scale factor applied. | 525 // have the page scale factor applied. |
| 525 { | 526 { |
| 526 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 527 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 527 scrollLayer->setImplTransform(identityScaleTransform); | 528 scrollLayer->setImplTransform(identityScaleTransform); |
| 528 scrollLayer->setScrollDelta(IntSize()); | 529 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 529 | 530 |
| 530 float pageScaleDelta = 2; | 531 float pageScaleDelta = 2; |
| 531 m_hostImpl->pinchGestureBegin(); | 532 m_hostImpl->pinchGestureBegin(); |
| 532 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); | 533 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); |
| 533 m_hostImpl->pinchGestureEnd(); | 534 m_hostImpl->pinchGestureEnd(); |
| 534 | 535 |
| 535 IntSize scrollDelta(0, 10); | 536 gfx::Vector2d scrollDelta(0, 10); |
| 536 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); | 537 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); |
| 537 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 538 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 538 m_hostImpl->scrollEnd(); | 539 m_hostImpl->scrollEnd(); |
| 539 | 540 |
| 540 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 541 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 541 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); | 542 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); |
| 542 } | 543 } |
| 543 } | 544 } |
| 544 | 545 |
| 545 TEST_P(LayerTreeHostImplTest, pinchGesture) | 546 TEST_P(LayerTreeHostImplTest, pinchGesture) |
| 546 { | 547 { |
| 547 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 548 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 548 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 549 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 549 initializeRendererAndDrawFrame(); | 550 initializeRendererAndDrawFrame(); |
| 550 | 551 |
| 551 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 552 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 552 DCHECK(scrollLayer); | 553 DCHECK(scrollLayer); |
| 553 | 554 |
| 554 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; | 555 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 555 const float maxPageScale = 4; | 556 const float maxPageScale = 4; |
| 556 const WebTransformationMatrix identityScaleTransform; | 557 const WebTransformationMatrix identityScaleTransform; |
| 557 | 558 |
| 558 // Basic pinch zoom in gesture | 559 // Basic pinch zoom in gesture |
| 559 { | 560 { |
| 560 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 561 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 561 scrollLayer->setImplTransform(identityScaleTransform); | 562 scrollLayer->setImplTransform(identityScaleTransform); |
| 562 scrollLayer->setScrollDelta(IntSize()); | 563 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 563 | 564 |
| 564 float pageScaleDelta = 2; | 565 float pageScaleDelta = 2; |
| 565 m_hostImpl->pinchGestureBegin(); | 566 m_hostImpl->pinchGestureBegin(); |
| 566 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 567 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 567 m_hostImpl->pinchGestureEnd(); | 568 m_hostImpl->pinchGestureEnd(); |
| 568 EXPECT_TRUE(m_didRequestRedraw); | 569 EXPECT_TRUE(m_didRequestRedraw); |
| 569 EXPECT_TRUE(m_didRequestCommit); | 570 EXPECT_TRUE(m_didRequestCommit); |
| 570 | 571 |
| 571 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 572 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 572 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 573 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 573 } | 574 } |
| 574 | 575 |
| 575 // Zoom-in clamping | 576 // Zoom-in clamping |
| 576 { | 577 { |
| 577 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 578 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 578 scrollLayer->setImplTransform(identityScaleTransform); | 579 scrollLayer->setImplTransform(identityScaleTransform); |
| 579 scrollLayer->setScrollDelta(IntSize()); | 580 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 580 float pageScaleDelta = 10; | 581 float pageScaleDelta = 10; |
| 581 | 582 |
| 582 m_hostImpl->pinchGestureBegin(); | 583 m_hostImpl->pinchGestureBegin(); |
| 583 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 584 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 584 m_hostImpl->pinchGestureEnd(); | 585 m_hostImpl->pinchGestureEnd(); |
| 585 | 586 |
| 586 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 587 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 587 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); | 588 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); |
| 588 } | 589 } |
| 589 | 590 |
| 590 // Zoom-out clamping | 591 // Zoom-out clamping |
| 591 { | 592 { |
| 592 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 593 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 593 scrollLayer->setImplTransform(identityScaleTransform); | 594 scrollLayer->setImplTransform(identityScaleTransform); |
| 594 scrollLayer->setScrollDelta(IntSize()); | 595 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 595 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 596 scrollLayer->setScrollOffset(gfx::Vector2d(50, 50)); |
| 596 | 597 |
| 597 float pageScaleDelta = 0.1f; | 598 float pageScaleDelta = 0.1f; |
| 598 m_hostImpl->pinchGestureBegin(); | 599 m_hostImpl->pinchGestureBegin(); |
| 599 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); | 600 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); |
| 600 m_hostImpl->pinchGestureEnd(); | 601 m_hostImpl->pinchGestureEnd(); |
| 601 | 602 |
| 602 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 603 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 603 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 604 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 604 | 605 |
| 605 if (!Settings::pageScalePinchZoomEnabled()) { | 606 if (!Settings::pageScalePinchZoomEnabled()) { |
| 606 // Pushed to (0,0) via clamping against contents layer size. | 607 // Pushed to (0,0) via clamping against contents layer size. |
| 607 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 608 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -5
0)); |
| 608 } else { | 609 } else { |
| 609 EXPECT_TRUE(scrollInfo->scrolls.empty()); | 610 EXPECT_TRUE(scrollInfo->scrolls.empty()); |
| 610 } | 611 } |
| 611 } | 612 } |
| 612 | 613 |
| 613 // Two-finger panning | 614 // Two-finger panning |
| 614 { | 615 { |
| 615 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 616 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 616 scrollLayer->setImplTransform(identityScaleTransform); | 617 scrollLayer->setImplTransform(identityScaleTransform); |
| 617 scrollLayer->setScrollDelta(IntSize()); | 618 scrollLayer->setScrollDelta(gfx::Vector2d()); |
| 618 scrollLayer->setScrollPosition(IntPoint(20, 20)); | 619 scrollLayer->setScrollOffset(gfx::Vector2d(20, 20)); |
| 619 | 620 |
| 620 float pageScaleDelta = 1; | 621 float pageScaleDelta = 1; |
| 621 m_hostImpl->pinchGestureBegin(); | 622 m_hostImpl->pinchGestureBegin(); |
| 622 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(10, 10)); | 623 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10)); |
| 623 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(20, 20)); | 624 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20)); |
| 624 m_hostImpl->pinchGestureEnd(); | 625 m_hostImpl->pinchGestureEnd(); |
| 625 | 626 |
| 626 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 627 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 627 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 628 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 628 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-10, -10)); | 629 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-10, -10)); |
| 629 } | 630 } |
| 630 } | 631 } |
| 631 | 632 |
| 632 TEST_P(LayerTreeHostImplTest, pageScaleAnimation) | 633 TEST_P(LayerTreeHostImplTest, pageScaleAnimation) |
| 633 { | 634 { |
| 634 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 635 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 635 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 636 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 636 initializeRendererAndDrawFrame(); | 637 initializeRendererAndDrawFrame(); |
| 637 | 638 |
| 638 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 639 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 639 DCHECK(scrollLayer); | 640 DCHECK(scrollLayer); |
| 640 | 641 |
| 641 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; | 642 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 642 const float maxPageScale = 4; | 643 const float maxPageScale = 4; |
| 643 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS
econds(1); | 644 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS
econds(1); |
| 644 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 645 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 645 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; | 646 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; |
| 646 const base::TimeTicks endTime = startTime + duration; | 647 const base::TimeTicks endTime = startTime + duration; |
| 647 const WebTransformationMatrix identityScaleTransform; | 648 const WebTransformationMatrix identityScaleTransform; |
| 648 | 649 |
| 649 // Non-anchor zoom-in | 650 // Non-anchor zoom-in |
| 650 { | 651 { |
| 651 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 652 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 652 scrollLayer->setImplTransform(identityScaleTransform); | 653 scrollLayer->setImplTransform(identityScaleTransform); |
| 653 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 654 scrollLayer->setScrollOffset(gfx::Vector2d(50, 50)); |
| 654 | 655 |
| 655 m_hostImpl->startPageScaleAnimation(IntSize(0, 0), false, 2, startTime,
duration); | 656 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(0, 0), false, 2, start
Time, duration); |
| 656 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); | 657 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); |
| 657 EXPECT_TRUE(m_didRequestRedraw); | 658 EXPECT_TRUE(m_didRequestRedraw); |
| 658 m_hostImpl->animate(endTime, base::Time()); | 659 m_hostImpl->animate(endTime, base::Time()); |
| 659 EXPECT_TRUE(m_didRequestCommit); | 660 EXPECT_TRUE(m_didRequestCommit); |
| 660 | 661 |
| 661 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 662 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 662 EXPECT_EQ(scrollInfo->pageScaleDelta, 2); | 663 EXPECT_EQ(scrollInfo->pageScaleDelta, 2); |
| 663 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 664 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); |
| 664 } | 665 } |
| 665 | 666 |
| 666 // Anchor zoom-out | 667 // Anchor zoom-out |
| 667 { | 668 { |
| 668 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 669 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 669 scrollLayer->setImplTransform(identityScaleTransform); | 670 scrollLayer->setImplTransform(identityScaleTransform); |
| 670 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 671 scrollLayer->setScrollOffset(gfx::Vector2d(50, 50)); |
| 671 | 672 |
| 672 m_hostImpl->startPageScaleAnimation(IntSize(25, 25), true, minPageScale,
startTime, duration); | 673 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(25, 25), true, minPage
Scale, startTime, duration); |
| 673 m_hostImpl->animate(endTime, base::Time()); | 674 m_hostImpl->animate(endTime, base::Time()); |
| 674 EXPECT_TRUE(m_didRequestRedraw); | 675 EXPECT_TRUE(m_didRequestRedraw); |
| 675 EXPECT_TRUE(m_didRequestCommit); | 676 EXPECT_TRUE(m_didRequestCommit); |
| 676 | 677 |
| 677 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 678 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 678 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 679 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 679 // Pushed to (0,0) via clamping against contents layer size. | 680 // Pushed to (0,0) via clamping against contents layer size. |
| 680 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 681 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); |
| 681 } | 682 } |
| 682 } | 683 } |
| 683 | 684 |
| 684 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhilePinchZooming) | 685 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhilePinchZooming) |
| 685 { | 686 { |
| 686 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 687 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 687 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 688 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 688 initializeRendererAndDrawFrame(); | 689 initializeRendererAndDrawFrame(); |
| 689 | 690 |
| 690 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 691 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 691 DCHECK(scrollLayer); | 692 DCHECK(scrollLayer); |
| 692 | 693 |
| 693 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; | 694 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 694 const float maxPageScale = 4; | 695 const float maxPageScale = 4; |
| 695 | 696 |
| 696 // Pinch zoom in. | 697 // Pinch zoom in. |
| 697 { | 698 { |
| 698 // Start a pinch in gesture at the bottom right corner of the viewport. | 699 // Start a pinch in gesture at the bottom right corner of the viewport. |
| 699 const float zoomInDelta = 2; | 700 const float zoomInDelta = 2; |
| 700 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 701 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 701 m_hostImpl->pinchGestureBegin(); | 702 m_hostImpl->pinchGestureBegin(); |
| 702 m_hostImpl->pinchGestureUpdate(zoomInDelta, IntPoint(50, 50)); | 703 m_hostImpl->pinchGestureUpdate(zoomInDelta, gfx::Point(50, 50)); |
| 703 | 704 |
| 704 // Because we are pinch zooming in, we shouldn't get any scroll or page | 705 // Because we are pinch zooming in, we shouldn't get any scroll or page |
| 705 // scale deltas. | 706 // scale deltas. |
| 706 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 707 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 707 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 708 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 708 EXPECT_EQ(scrollInfo->scrolls.size(), 0u); | 709 EXPECT_EQ(scrollInfo->scrolls.size(), 0u); |
| 709 | 710 |
| 710 // Once the gesture ends, we get the final scroll and page scale values. | 711 // Once the gesture ends, we get the final scroll and page scale values. |
| 711 m_hostImpl->pinchGestureEnd(); | 712 m_hostImpl->pinchGestureEnd(); |
| 712 scrollInfo = m_hostImpl->processScrollDeltas(); | 713 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 713 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomInDelta); | 714 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomInDelta); |
| 714 if (!Settings::pageScalePinchZoomEnabled()) { | 715 if (!Settings::pageScalePinchZoomEnabled()) { |
| 715 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 716 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)
); |
| 716 } else { | 717 } else { |
| 717 EXPECT_TRUE(scrollInfo->scrolls.empty()); | 718 EXPECT_TRUE(scrollInfo->scrolls.empty()); |
| 718 } | 719 } |
| 719 } | 720 } |
| 720 | 721 |
| 721 // Pinch zoom out. | 722 // Pinch zoom out. |
| 722 { | 723 { |
| 723 // Start a pinch out gesture at the bottom right corner of the viewport. | 724 // Start a pinch out gesture at the bottom right corner of the viewport. |
| 724 const float zoomOutDelta = 0.75; | 725 const float zoomOutDelta = 0.75; |
| 725 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 726 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 726 m_hostImpl->pinchGestureBegin(); | 727 m_hostImpl->pinchGestureBegin(); |
| 727 m_hostImpl->pinchGestureUpdate(zoomOutDelta, IntPoint(50, 50)); | 728 m_hostImpl->pinchGestureUpdate(zoomOutDelta, gfx::Point(50, 50)); |
| 728 | 729 |
| 729 // Since we are pinch zooming out, we should get an update to zoom all | 730 // Since we are pinch zooming out, we should get an update to zoom all |
| 730 // the way out to the minimum page scale. | 731 // the way out to the minimum page scale. |
| 731 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 732 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 732 if (!Settings::pageScalePinchZoomEnabled()) { | 733 if (!Settings::pageScalePinchZoomEnabled()) { |
| 733 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 734 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 734 expectContains(*scrollInfo, scrollLayer->id(), IntSize(0, 0)); | 735 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(0, 0)); |
| 735 } else { | 736 } else { |
| 736 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 737 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 737 EXPECT_TRUE(scrollInfo->scrolls.empty()); | 738 EXPECT_TRUE(scrollInfo->scrolls.empty()); |
| 738 } | 739 } |
| 739 | 740 |
| 740 // Once the gesture ends, we get the final scroll and page scale values. | 741 // Once the gesture ends, we get the final scroll and page scale values. |
| 741 m_hostImpl->pinchGestureEnd(); | 742 m_hostImpl->pinchGestureEnd(); |
| 742 scrollInfo = m_hostImpl->processScrollDeltas(); | 743 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 743 if (Settings::pageScalePinchZoomEnabled()) { | 744 if (Settings::pageScalePinchZoomEnabled()) { |
| 744 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 745 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 745 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 746 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)
); |
| 746 } else { | 747 } else { |
| 747 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomOutDelta); | 748 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomOutDelta); |
| 748 expectContains(*scrollInfo, scrollLayer->id(), IntSize(8, 8)); | 749 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(8, 8)); |
| 749 } | 750 } |
| 750 } | 751 } |
| 751 } | 752 } |
| 752 | 753 |
| 753 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPage
Scale) | 754 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPage
Scale) |
| 754 { | 755 { |
| 755 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 756 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 756 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 757 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 757 initializeRendererAndDrawFrame(); | 758 initializeRendererAndDrawFrame(); |
| 758 | 759 |
| 759 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 760 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 760 DCHECK(scrollLayer); | 761 DCHECK(scrollLayer); |
| 761 | 762 |
| 762 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; | 763 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 763 const float maxPageScale = 4; | 764 const float maxPageScale = 4; |
| 764 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS
econds(1); | 765 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS
econds(1); |
| 765 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 766 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 766 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; | 767 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; |
| 767 const base::TimeTicks endTime = startTime + duration; | 768 const base::TimeTicks endTime = startTime + duration; |
| 768 // Start a page scale animation. | 769 // Start a page scale animation. |
| 769 const float pageScaleDelta = 2; | 770 const float pageScaleDelta = 2; |
| 770 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 771 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 771 m_hostImpl->startPageScaleAnimation(IntSize(50, 50), false, pageScaleDelta,
startTime, duration); | 772 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(50, 50), false, pageScaleD
elta, startTime, duration); |
| 772 | 773 |
| 773 // We should immediately get the final zoom and scroll values for the | 774 // We should immediately get the final zoom and scroll values for the |
| 774 // animation. | 775 // animation. |
| 775 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); | 776 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); |
| 776 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 777 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 777 | 778 |
| 778 if (!Settings::pageScalePinchZoomEnabled()) { | 779 if (!Settings::pageScalePinchZoomEnabled()) { |
| 779 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 780 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 780 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 781 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)); |
| 781 } else { | 782 } else { |
| 782 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 783 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 783 EXPECT_TRUE(scrollInfo->scrolls.empty()); | 784 EXPECT_TRUE(scrollInfo->scrolls.empty()); |
| 784 } | 785 } |
| 785 | 786 |
| 786 // Scrolling during the animation is ignored. | 787 // Scrolling during the animation is ignored. |
| 787 const IntSize scrollDelta(0, 10); | 788 const gfx::Vector2d scrollDelta(0, 10); |
| 788 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); | 789 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 789 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 790 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 790 m_hostImpl->scrollEnd(); | 791 m_hostImpl->scrollEnd(); |
| 791 | 792 |
| 792 // The final page scale and scroll deltas should match what we got | 793 // The final page scale and scroll deltas should match what we got |
| 793 // earlier. | 794 // earlier. |
| 794 m_hostImpl->animate(endTime, base::Time()); | 795 m_hostImpl->animate(endTime, base::Time()); |
| 795 scrollInfo = m_hostImpl->processScrollDeltas(); | 796 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 796 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 797 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 797 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 798 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)); |
| 798 } | 799 } |
| 799 | 800 |
| 800 class DidDrawCheckLayer : public TiledLayerImpl { | 801 class DidDrawCheckLayer : public TiledLayerImpl { |
| 801 public: | 802 public: |
| 802 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew DidDrawCheckLayer(id)); } | 803 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew DidDrawCheckLayer(id)); } |
| 803 | 804 |
| 804 virtual void didDraw(ResourceProvider*) OVERRIDE | 805 virtual void didDraw(ResourceProvider*) OVERRIDE |
| 805 { | 806 { |
| 806 m_didDrawCalled = true; | 807 m_didDrawCalled = true; |
| 807 } | 808 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 contentLayer->setUseLCDText(true); | 1043 contentLayer->setUseLCDText(true); |
| 1043 contentLayer->setDrawsContent(true); | 1044 contentLayer->setDrawsContent(true); |
| 1044 contentLayer->setPosition(gfx::PointF(0, 0)); | 1045 contentLayer->setPosition(gfx::PointF(0, 0)); |
| 1045 contentLayer->setAnchorPoint(gfx::PointF(0, 0)); | 1046 contentLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 1046 contentLayer->setBounds(surfaceSize); | 1047 contentLayer->setBounds(surfaceSize); |
| 1047 contentLayer->setContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSiz
e.height() * 2)); | 1048 contentLayer->setContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSiz
e.height() * 2)); |
| 1048 contentLayer->setContentsScale(2, 2); | 1049 contentLayer->setContentsScale(2, 2); |
| 1049 | 1050 |
| 1050 scoped_ptr<LayerImpl> scrollLayer = LayerImpl::create(2); | 1051 scoped_ptr<LayerImpl> scrollLayer = LayerImpl::create(2); |
| 1051 scrollLayer->setScrollable(true); | 1052 scrollLayer->setScrollable(true); |
| 1052 scrollLayer->setMaxScrollPosition(cc::IntSize(surfaceSize)); | 1053 scrollLayer->setMaxScrollOffset(gfx::Vector2d(surfaceSize.width(), surfaceSi
ze.height())); |
| 1053 scrollLayer->setBounds(surfaceSize); | 1054 scrollLayer->setBounds(surfaceSize); |
| 1054 scrollLayer->setContentBounds(surfaceSize); | 1055 scrollLayer->setContentBounds(surfaceSize); |
| 1055 scrollLayer->setPosition(gfx::PointF(0, 0)); | 1056 scrollLayer->setPosition(gfx::PointF(0, 0)); |
| 1056 scrollLayer->setAnchorPoint(gfx::PointF(0, 0)); | 1057 scrollLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 1057 scrollLayer->addChild(contentLayer.Pass()); | 1058 scrollLayer->addChild(contentLayer.Pass()); |
| 1058 | 1059 |
| 1059 m_hostImpl->setRootLayer(scrollLayer.Pass()); | 1060 m_hostImpl->setRootLayer(scrollLayer.Pass()); |
| 1060 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1061 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1061 initializeRendererAndDrawFrame(); | 1062 initializeRendererAndDrawFrame(); |
| 1062 | 1063 |
| 1063 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1064 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1064 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 10)); | 1065 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 1065 m_hostImpl->scrollEnd(); | 1066 m_hostImpl->scrollEnd(); |
| 1066 EXPECT_TRUE(m_didRequestRedraw); | 1067 EXPECT_TRUE(m_didRequestRedraw); |
| 1067 EXPECT_TRUE(m_didRequestCommit); | 1068 EXPECT_TRUE(m_didRequestCommit); |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 TEST_P(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) | 1071 TEST_P(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) |
| 1071 { | 1072 { |
| 1072 gfx::Size surfaceSize(10, 10); | 1073 gfx::Size surfaceSize(10, 10); |
| 1073 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | 1074 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1074 root->setBounds(surfaceSize); | 1075 root->setBounds(surfaceSize); |
| 1075 root->setContentBounds(surfaceSize); | 1076 root->setContentBounds(surfaceSize); |
| 1076 root->addChild(createScrollableLayer(2, surfaceSize)); | 1077 root->addChild(createScrollableLayer(2, surfaceSize)); |
| 1077 m_hostImpl->setRootLayer(root.Pass()); | 1078 m_hostImpl->setRootLayer(root.Pass()); |
| 1078 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1079 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1079 initializeRendererAndDrawFrame(); | 1080 initializeRendererAndDrawFrame(); |
| 1080 | 1081 |
| 1081 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1082 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1082 m_hostImpl->scrollBy(gfx::Point(), IntSize(0, 10)); | 1083 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 1083 m_hostImpl->scrollEnd(); | 1084 m_hostImpl->scrollEnd(); |
| 1084 EXPECT_TRUE(m_didRequestRedraw); | 1085 EXPECT_TRUE(m_didRequestRedraw); |
| 1085 EXPECT_TRUE(m_didRequestCommit); | 1086 EXPECT_TRUE(m_didRequestCommit); |
| 1086 } | 1087 } |
| 1087 | 1088 |
| 1088 TEST_P(LayerTreeHostImplTest, scrollMissesChild) | 1089 TEST_P(LayerTreeHostImplTest, scrollMissesChild) |
| 1089 { | 1090 { |
| 1090 gfx::Size surfaceSize(10, 10); | 1091 gfx::Size surfaceSize(10, 10); |
| 1091 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | 1092 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1092 root->addChild(createScrollableLayer(2, surfaceSize)); | 1093 root->addChild(createScrollableLayer(2, surfaceSize)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1144 |
| 1144 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) | 1145 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) |
| 1145 { | 1146 { |
| 1146 gfx::Size surfaceSize(10, 10); | 1147 gfx::Size surfaceSize(10, 10); |
| 1147 float pageScale = 2; | 1148 float pageScale = 2; |
| 1148 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1149 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1149 m_hostImpl->setRootLayer(root.Pass()); | 1150 m_hostImpl->setRootLayer(root.Pass()); |
| 1150 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1151 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1151 initializeRendererAndDrawFrame(); | 1152 initializeRendererAndDrawFrame(); |
| 1152 | 1153 |
| 1153 IntSize scrollDelta(0, 10); | 1154 gfx::Vector2d scrollDelta(0, 10); |
| 1154 IntSize expectedScrollDelta(scrollDelta); | 1155 gfx::Vector2d expectedScrollDelta(scrollDelta); |
| 1155 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); | 1156 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
| 1156 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1157 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1157 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1158 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1158 m_hostImpl->scrollEnd(); | 1159 m_hostImpl->scrollEnd(); |
| 1159 | 1160 |
| 1160 // Set new page scale from main thread. | 1161 // Set new page scale from main thread. |
| 1161 m_hostImpl->setPageScaleFactorAndLimits(pageScale, pageScale, pageScale); | 1162 m_hostImpl->setPageScaleFactorAndLimits(pageScale, pageScale, pageScale); |
| 1162 | 1163 |
| 1163 if (!Settings::pageScalePinchZoomEnabled()) { | 1164 if (!Settings::pageScalePinchZoomEnabled()) { |
| 1164 // The scale should apply to the scroll delta. | 1165 // The scale should apply to the scroll delta. |
| 1165 expectedScrollDelta.scale(pageScale); | 1166 expectedScrollDelta = gfx::ToFlooredVector2d(cc::ScaleVector2d(expectedS
crollDelta, pageScale)); |
| 1166 } | 1167 } |
| 1167 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1168 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1168 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 1169 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); |
| 1169 | 1170 |
| 1170 // The scroll range should also have been updated. | 1171 // The scroll range should also have been updated. |
| 1171 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); | 1172 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), expectedMaxScroll); |
| 1172 | 1173 |
| 1173 // The page scale delta remains constant because the impl thread did not sca
le. | 1174 // The page scale delta remains constant because the impl thread did not sca
le. |
| 1174 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), WebTransformationMatrix(
)); | 1175 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), WebTransformationMatrix(
)); |
| 1175 } | 1176 } |
| 1176 | 1177 |
| 1177 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) | 1178 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
| 1178 { | 1179 { |
| 1179 gfx::Size surfaceSize(10, 10); | 1180 gfx::Size surfaceSize(10, 10); |
| 1180 float pageScale = 2; | 1181 float pageScale = 2; |
| 1181 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1182 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1182 m_hostImpl->setRootLayer(root.Pass()); | 1183 m_hostImpl->setRootLayer(root.Pass()); |
| 1183 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1184 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1184 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 1185 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
| 1185 initializeRendererAndDrawFrame(); | 1186 initializeRendererAndDrawFrame(); |
| 1186 | 1187 |
| 1187 IntSize scrollDelta(0, 10); | 1188 gfx::Vector2d scrollDelta(0, 10); |
| 1188 IntSize expectedScrollDelta(scrollDelta); | 1189 gfx::Vector2d expectedScrollDelta(scrollDelta); |
| 1189 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); | 1190 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
| 1190 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1191 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1191 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1192 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1192 m_hostImpl->scrollEnd(); | 1193 m_hostImpl->scrollEnd(); |
| 1193 | 1194 |
| 1194 // Set new page scale on impl thread by pinching. | 1195 // Set new page scale on impl thread by pinching. |
| 1195 m_hostImpl->pinchGestureBegin(); | 1196 m_hostImpl->pinchGestureBegin(); |
| 1196 m_hostImpl->pinchGestureUpdate(pageScale, IntPoint()); | 1197 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
| 1197 m_hostImpl->pinchGestureEnd(); | 1198 m_hostImpl->pinchGestureEnd(); |
| 1198 m_hostImpl->updateRootScrollLayerImplTransform(); | 1199 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1199 | 1200 |
| 1200 // The scroll delta is not scaled because the main thread did not scale. | 1201 // The scroll delta is not scaled because the main thread did not scale. |
| 1201 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1202 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1202 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 1203 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); |
| 1203 | 1204 |
| 1204 // The scroll range should also have been updated. | 1205 // The scroll range should also have been updated. |
| 1205 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); | 1206 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), expectedMaxScroll); |
| 1206 | 1207 |
| 1207 // The page scale delta should match the new scale on the impl side. | 1208 // The page scale delta should match the new scale on the impl side. |
| 1208 WebTransformationMatrix expectedScale; | 1209 WebTransformationMatrix expectedScale; |
| 1209 expectedScale.scale(pageScale); | 1210 expectedScale.scale(pageScale); |
| 1210 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); | 1211 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); |
| 1211 } | 1212 } |
| 1212 | 1213 |
| 1213 TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) | 1214 TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
| 1214 { | 1215 { |
| 1215 gfx::Size surfaceSize(10, 10); | 1216 gfx::Size surfaceSize(10, 10); |
| 1216 float defaultPageScale = 1; | 1217 float defaultPageScale = 1; |
| 1217 WebTransformationMatrix defaultPageScaleMatrix; | 1218 WebTransformationMatrix defaultPageScaleMatrix; |
| 1218 | 1219 |
| 1219 float newPageScale = 2; | 1220 float newPageScale = 2; |
| 1220 WebTransformationMatrix newPageScaleMatrix; | 1221 WebTransformationMatrix newPageScaleMatrix; |
| 1221 newPageScaleMatrix.scale(newPageScale); | 1222 newPageScaleMatrix.scale(newPageScale); |
| 1222 | 1223 |
| 1223 // Create a normal scrollable root layer and another scrollable child layer. | 1224 // Create a normal scrollable root layer and another scrollable child layer. |
| 1224 setupScrollAndContentsLayers(surfaceSize); | 1225 setupScrollAndContentsLayers(surfaceSize); |
| 1225 LayerImpl* root = m_hostImpl->rootLayer(); | 1226 LayerImpl* root = m_hostImpl->rootLayer(); |
| 1226 LayerImpl* child = root->children()[0]; | 1227 LayerImpl* child = root->children()[0]; |
| 1227 | 1228 |
| 1228 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize
); | 1229 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize
); |
| 1229 child->addChild(scrollableChild.Pass()); | 1230 child->addChild(scrollableChild.Pass()); |
| 1230 LayerImpl* grandChild = child->children()[0]; | 1231 LayerImpl* grandChild = child->children()[0]; |
| 1231 | 1232 |
| 1232 // Set new page scale on impl thread by pinching. | 1233 // Set new page scale on impl thread by pinching. |
| 1233 m_hostImpl->pinchGestureBegin(); | 1234 m_hostImpl->pinchGestureBegin(); |
| 1234 m_hostImpl->pinchGestureUpdate(newPageScale, IntPoint()); | 1235 m_hostImpl->pinchGestureUpdate(newPageScale, gfx::Point()); |
| 1235 m_hostImpl->pinchGestureEnd(); | 1236 m_hostImpl->pinchGestureEnd(); |
| 1236 m_hostImpl->updateRootScrollLayerImplTransform(); | 1237 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1237 | 1238 |
| 1238 // The page scale delta should only be applied to the scrollable root layer. | 1239 // The page scale delta should only be applied to the scrollable root layer. |
| 1239 EXPECT_EQ(root->implTransform(), newPageScaleMatrix); | 1240 EXPECT_EQ(root->implTransform(), newPageScaleMatrix); |
| 1240 EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); | 1241 EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); |
| 1241 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); | 1242 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); |
| 1242 | 1243 |
| 1243 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale | 1244 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale |
| 1244 // delta on the root layer is applied hierarchically. | 1245 // delta on the root layer is applied hierarchically. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1264 // Also mark the root scrollable so it becomes the root scroll layer. | 1265 // Also mark the root scrollable so it becomes the root scroll layer. |
| 1265 root->setScrollable(true); | 1266 root->setScrollable(true); |
| 1266 int scrollLayerId = 2; | 1267 int scrollLayerId = 2; |
| 1267 root->addChild(createScrollableLayer(scrollLayerId, surfaceSize)); | 1268 root->addChild(createScrollableLayer(scrollLayerId, surfaceSize)); |
| 1268 m_hostImpl->setRootLayer(root.Pass()); | 1269 m_hostImpl->setRootLayer(root.Pass()); |
| 1269 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1270 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1270 initializeRendererAndDrawFrame(); | 1271 initializeRendererAndDrawFrame(); |
| 1271 | 1272 |
| 1272 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1273 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1273 | 1274 |
| 1274 IntSize scrollDelta(0, 10); | 1275 gfx::Vector2d scrollDelta(0, 10); |
| 1275 IntSize expectedScrollDelta(scrollDelta); | 1276 gfx::Vector2d expectedScrollDelta(scrollDelta); |
| 1276 IntSize expectedMaxScroll(child->maxScrollPosition()); | 1277 gfx::Vector2d expectedMaxScroll(child->maxScrollOffset()); |
| 1277 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1278 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1278 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1279 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1279 m_hostImpl->scrollEnd(); | 1280 m_hostImpl->scrollEnd(); |
| 1280 | 1281 |
| 1281 float pageScale = 2; | 1282 float pageScale = 2; |
| 1282 m_hostImpl->setPageScaleFactorAndLimits(pageScale, 1, pageScale); | 1283 m_hostImpl->setPageScaleFactorAndLimits(pageScale, 1, pageScale); |
| 1283 | 1284 |
| 1284 m_hostImpl->updateRootScrollLayerImplTransform(); | 1285 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1285 | 1286 |
| 1286 if (!Settings::pageScalePinchZoomEnabled()) { | 1287 if (!Settings::pageScalePinchZoomEnabled()) { |
| 1287 // The scale should apply to the scroll delta. | 1288 // The scale should apply to the scroll delta. |
| 1288 expectedScrollDelta.scale(pageScale); | 1289 expectedScrollDelta = gfx::ToFlooredVector2d(cc::ScaleVector2d(expectedS
crollDelta, pageScale)); |
| 1289 } | 1290 } |
| 1290 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1291 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1291 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); | 1292 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); |
| 1292 | 1293 |
| 1293 // The scroll range should not have changed. | 1294 // The scroll range should not have changed. |
| 1294 EXPECT_EQ(child->maxScrollPosition(), expectedMaxScroll); | 1295 EXPECT_EQ(child->maxScrollOffset(), expectedMaxScroll); |
| 1295 | 1296 |
| 1296 // The page scale delta remains constant because the impl thread did not sca
le. | 1297 // The page scale delta remains constant because the impl thread did not sca
le. |
| 1297 WebTransformationMatrix identityTransform; | 1298 WebTransformationMatrix identityTransform; |
| 1298 EXPECT_EQ(child->implTransform(), WebTransformationMatrix()); | 1299 EXPECT_EQ(child->implTransform(), WebTransformationMatrix()); |
| 1299 } | 1300 } |
| 1300 | 1301 |
| 1301 TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) | 1302 TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) |
| 1302 { | 1303 { |
| 1303 // Scroll a child layer beyond its maximum scroll range and make sure the | 1304 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1304 // parent layer is scrolled on the axis on which the child was unable to | 1305 // parent layer is scrolled on the axis on which the child was unable to |
| 1305 // scroll. | 1306 // scroll. |
| 1306 gfx::Size surfaceSize(10, 10); | 1307 gfx::Size surfaceSize(10, 10); |
| 1307 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1308 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1308 | 1309 |
| 1309 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); | 1310 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
| 1310 grandChild->setScrollPosition(IntPoint(0, 5)); | 1311 grandChild->setScrollOffset(gfx::Vector2d(0, 5)); |
| 1311 | 1312 |
| 1312 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); | 1313 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1313 child->setScrollPosition(IntPoint(3, 0)); | 1314 child->setScrollOffset(gfx::Vector2d(3, 0)); |
| 1314 child->addChild(grandChild.Pass()); | 1315 child->addChild(grandChild.Pass()); |
| 1315 | 1316 |
| 1316 root->addChild(child.Pass()); | 1317 root->addChild(child.Pass()); |
| 1317 m_hostImpl->setRootLayer(root.Pass()); | 1318 m_hostImpl->setRootLayer(root.Pass()); |
| 1318 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1319 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1319 initializeRendererAndDrawFrame(); | 1320 initializeRendererAndDrawFrame(); |
| 1320 { | 1321 { |
| 1321 IntSize scrollDelta(-8, -7); | 1322 gfx::Vector2d scrollDelta(-8, -7); |
| 1322 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); | 1323 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); |
| 1323 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1324 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1324 m_hostImpl->scrollEnd(); | 1325 m_hostImpl->scrollEnd(); |
| 1325 | 1326 |
| 1326 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 1327 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1327 | 1328 |
| 1328 // The grand child should have scrolled up to its limit. | 1329 // The grand child should have scrolled up to its limit. |
| 1329 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1330 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1330 LayerImpl* grandChild = child->children()[0]; | 1331 LayerImpl* grandChild = child->children()[0]; |
| 1331 expectContains(*scrollInfo.get(), grandChild->id(), IntSize(0, -5)); | 1332 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)
); |
| 1332 | 1333 |
| 1333 // The child should have only scrolled on the other axis. | 1334 // The child should have only scrolled on the other axis. |
| 1334 expectContains(*scrollInfo.get(), child->id(), IntSize(-3, 0)); | 1335 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); |
| 1335 } | 1336 } |
| 1336 } | 1337 } |
| 1337 | 1338 |
| 1338 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) | 1339 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) |
| 1339 { | 1340 { |
| 1340 // When we try to scroll a non-scrollable child layer, the scroll delta | 1341 // When we try to scroll a non-scrollable child layer, the scroll delta |
| 1341 // should be applied to one of its ancestors if possible. | 1342 // should be applied to one of its ancestors if possible. |
| 1342 gfx::Size surfaceSize(10, 10); | 1343 gfx::Size surfaceSize(10, 10); |
| 1343 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1344 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1344 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); | 1345 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1345 | 1346 |
| 1346 child->setScrollable(false); | 1347 child->setScrollable(false); |
| 1347 root->addChild(child.Pass()); | 1348 root->addChild(child.Pass()); |
| 1348 | 1349 |
| 1349 m_hostImpl->setRootLayer(root.Pass()); | 1350 m_hostImpl->setRootLayer(root.Pass()); |
| 1350 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1351 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1351 initializeRendererAndDrawFrame(); | 1352 initializeRendererAndDrawFrame(); |
| 1352 { | 1353 { |
| 1353 IntSize scrollDelta(0, 4); | 1354 gfx::Vector2d scrollDelta(0, 4); |
| 1354 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); | 1355 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
Wheel), InputHandlerClient::ScrollStarted); |
| 1355 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1356 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1356 m_hostImpl->scrollEnd(); | 1357 m_hostImpl->scrollEnd(); |
| 1357 | 1358 |
| 1358 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 1359 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1359 | 1360 |
| 1360 // Only the root should have scrolled. | 1361 // Only the root should have scrolled. |
| 1361 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 1362 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 1362 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); | 1363 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); |
| 1363 } | 1364 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1385 // Rotate the root layer 90 degrees counter-clockwise about its center. | 1386 // Rotate the root layer 90 degrees counter-clockwise about its center. |
| 1386 WebTransformationMatrix rotateTransform; | 1387 WebTransformationMatrix rotateTransform; |
| 1387 rotateTransform.rotate(-90); | 1388 rotateTransform.rotate(-90); |
| 1388 m_hostImpl->rootLayer()->setTransform(rotateTransform); | 1389 m_hostImpl->rootLayer()->setTransform(rotateTransform); |
| 1389 | 1390 |
| 1390 gfx::Size surfaceSize(50, 50); | 1391 gfx::Size surfaceSize(50, 50); |
| 1391 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1392 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1392 initializeRendererAndDrawFrame(); | 1393 initializeRendererAndDrawFrame(); |
| 1393 | 1394 |
| 1394 // Scroll to the right in screen coordinates with a gesture. | 1395 // Scroll to the right in screen coordinates with a gesture. |
| 1395 IntSize gestureScrollDelta(10, 0); | 1396 gfx::Vector2d gestureScrollDelta(10, 0); |
| 1396 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollStarted); | 1397 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollStarted); |
| 1397 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); | 1398 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); |
| 1398 m_hostImpl->scrollEnd(); | 1399 m_hostImpl->scrollEnd(); |
| 1399 | 1400 |
| 1400 // The layer should have scrolled down in its local coordinates. | 1401 // The layer should have scrolled down in its local coordinates. |
| 1401 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1402 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1402 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
gestureScrollDelta.width())); | 1403 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), gfx::Vector
2d(0, gestureScrollDelta.x())); |
| 1403 | 1404 |
| 1404 // Reset and scroll down with the wheel. | 1405 // Reset and scroll down with the wheel. |
| 1405 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); | 1406 m_hostImpl->rootLayer()->setScrollDelta(gfx::Vector2dF()); |
| 1406 IntSize wheelScrollDelta(0, 10); | 1407 gfx::Vector2d wheelScrollDelta(0, 10); |
| 1407 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1408 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1408 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); | 1409 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); |
| 1409 m_hostImpl->scrollEnd(); | 1410 m_hostImpl->scrollEnd(); |
| 1410 | 1411 |
| 1411 // The layer should have scrolled down in its local coordinates. | 1412 // The layer should have scrolled down in its local coordinates. |
| 1412 scrollInfo = m_hostImpl->processScrollDeltas(); | 1413 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1413 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); | 1414 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); |
| 1414 } | 1415 } |
| 1415 | 1416 |
| 1416 TEST_P(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) | 1417 TEST_P(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) |
| 1417 { | 1418 { |
| 1418 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 1419 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 1419 int childLayerId = 3; | 1420 int childLayerId = 3; |
| 1420 float childLayerAngle = -20; | 1421 float childLayerAngle = -20; |
| 1421 | 1422 |
| 1422 // Create a child layer that is rotated to a non-axis-aligned angle. | 1423 // Create a child layer that is rotated to a non-axis-aligned angle. |
| 1423 scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl
->rootLayer()->contentBounds()); | 1424 scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl
->rootLayer()->contentBounds()); |
| 1424 WebTransformationMatrix rotateTransform; | 1425 WebTransformationMatrix rotateTransform; |
| 1425 rotateTransform.translate(-50, -50); | 1426 rotateTransform.translate(-50, -50); |
| 1426 rotateTransform.rotate(childLayerAngle); | 1427 rotateTransform.rotate(childLayerAngle); |
| 1427 rotateTransform.translate(50, 50); | 1428 rotateTransform.translate(50, 50); |
| 1428 child->setTransform(rotateTransform); | 1429 child->setTransform(rotateTransform); |
| 1429 | 1430 |
| 1430 // Only allow vertical scrolling. | 1431 // Only allow vertical scrolling. |
| 1431 child->setMaxScrollPosition(IntSize(0, child->contentBounds().height())); | 1432 child->setMaxScrollOffset(gfx::Vector2d(0, child->contentBounds().height()))
; |
| 1432 m_hostImpl->rootLayer()->addChild(child.Pass()); | 1433 m_hostImpl->rootLayer()->addChild(child.Pass()); |
| 1433 | 1434 |
| 1434 gfx::Size surfaceSize(50, 50); | 1435 gfx::Size surfaceSize(50, 50); |
| 1435 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1436 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1436 initializeRendererAndDrawFrame(); | 1437 initializeRendererAndDrawFrame(); |
| 1437 | 1438 |
| 1438 { | 1439 { |
| 1439 // Scroll down in screen coordinates with a gesture. | 1440 // Scroll down in screen coordinates with a gesture. |
| 1440 IntSize gestureScrollDelta(0, 10); | 1441 gfx::Vector2d gestureScrollDelta(0, 10); |
| 1441 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::
Gesture), InputHandlerClient::ScrollStarted); | 1442 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::
Gesture), InputHandlerClient::ScrollStarted); |
| 1442 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); | 1443 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); |
| 1443 m_hostImpl->scrollEnd(); | 1444 m_hostImpl->scrollEnd(); |
| 1444 | 1445 |
| 1445 // The child layer should have scrolled down in its local coordinates an
amount proportional to | 1446 // The child layer should have scrolled down in its local coordinates an
amount proportional to |
| 1446 // the angle between it and the input scroll delta. | 1447 // the angle between it and the input scroll delta. |
| 1447 IntSize expectedScrollDelta(0, gestureScrollDelta.height() * cosf(deg2ra
d(childLayerAngle))); | 1448 gfx::Vector2d expectedScrollDelta(0, gestureScrollDelta.y() * cosf(deg2r
ad(childLayerAngle))); |
| 1448 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 1449 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1449 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); | 1450 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1450 | 1451 |
| 1451 // The root layer should not have scrolled, because the input delta was
close to the layer's | 1452 // The root layer should not have scrolled, because the input delta was
close to the layer's |
| 1452 // axis of movement. | 1453 // axis of movement. |
| 1453 EXPECT_EQ(scrollInfo->scrolls.size(), 1u); | 1454 EXPECT_EQ(scrollInfo->scrolls.size(), 1u); |
| 1454 } | 1455 } |
| 1455 | 1456 |
| 1456 { | 1457 { |
| 1457 // Now reset and scroll the same amount horizontally. | 1458 // Now reset and scroll the same amount horizontally. |
| 1458 m_hostImpl->rootLayer()->children()[1]->setScrollDelta(FloatSize()); | 1459 m_hostImpl->rootLayer()->children()[1]->setScrollDelta(gfx::Vector2dF())
; |
| 1459 IntSize gestureScrollDelta(10, 0); | 1460 gfx::Vector2d gestureScrollDelta(10, 0); |
| 1460 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::
Gesture), InputHandlerClient::ScrollStarted); | 1461 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::
Gesture), InputHandlerClient::ScrollStarted); |
| 1461 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); | 1462 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); |
| 1462 m_hostImpl->scrollEnd(); | 1463 m_hostImpl->scrollEnd(); |
| 1463 | 1464 |
| 1464 // The child layer should have scrolled down in its local coordinates an
amount proportional to | 1465 // The child layer should have scrolled down in its local coordinates an
amount proportional to |
| 1465 // the angle between it and the input scroll delta. | 1466 // the angle between it and the input scroll delta. |
| 1466 IntSize expectedScrollDelta(0, -gestureScrollDelta.width() * sinf(deg2ra
d(childLayerAngle))); | 1467 gfx::Vector2d expectedScrollDelta(0, -gestureScrollDelta.x() * sinf(deg2
rad(childLayerAngle))); |
| 1467 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 1468 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1468 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); | 1469 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1469 | 1470 |
| 1470 // The root layer should have scrolled more, since the input scroll delt
a was mostly | 1471 // The root layer should have scrolled more, since the input scroll delt
a was mostly |
| 1471 // orthogonal to the child layer's vertical scroll axis. | 1472 // orthogonal to the child layer's vertical scroll axis. |
| 1472 IntSize expectedRootScrollDelta(gestureScrollDelta.width() * pow(cosf(de
g2rad(childLayerAngle)), 2), 0); | 1473 gfx::Vector2d expectedRootScrollDelta(gestureScrollDelta.x() * pow(cosf(
deg2rad(childLayerAngle)), 2), 0); |
| 1473 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expecte
dRootScrollDelta); | 1474 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expecte
dRootScrollDelta); |
| 1474 } | 1475 } |
| 1475 } | 1476 } |
| 1476 | 1477 |
| 1477 TEST_P(LayerTreeHostImplTest, scrollScaledLayer) | 1478 TEST_P(LayerTreeHostImplTest, scrollScaledLayer) |
| 1478 { | 1479 { |
| 1479 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 1480 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 1480 | 1481 |
| 1481 // Scale the layer to twice its normal size. | 1482 // Scale the layer to twice its normal size. |
| 1482 int scale = 2; | 1483 int scale = 2; |
| 1483 WebTransformationMatrix scaleTransform; | 1484 WebTransformationMatrix scaleTransform; |
| 1484 scaleTransform.scale(scale); | 1485 scaleTransform.scale(scale); |
| 1485 m_hostImpl->rootLayer()->setTransform(scaleTransform); | 1486 m_hostImpl->rootLayer()->setTransform(scaleTransform); |
| 1486 | 1487 |
| 1487 gfx::Size surfaceSize(50, 50); | 1488 gfx::Size surfaceSize(50, 50); |
| 1488 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1489 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1489 initializeRendererAndDrawFrame(); | 1490 initializeRendererAndDrawFrame(); |
| 1490 | 1491 |
| 1491 // Scroll down in screen coordinates with a gesture. | 1492 // Scroll down in screen coordinates with a gesture. |
| 1492 IntSize scrollDelta(0, 10); | 1493 gfx::Vector2d scrollDelta(0, 10); |
| 1493 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollStarted); | 1494 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollStarted); |
| 1494 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1495 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1495 m_hostImpl->scrollEnd(); | 1496 m_hostImpl->scrollEnd(); |
| 1496 | 1497 |
| 1497 // The layer should have scrolled down in its local coordinates, but half he
amount. | 1498 // The layer should have scrolled down in its local coordinates, but half he
amount. |
| 1498 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1499 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1499 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
scrollDelta.height() / scale)); | 1500 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), gfx::Vector
2d(0, scrollDelta.y() / scale)); |
| 1500 | 1501 |
| 1501 // Reset and scroll down with the wheel. | 1502 // Reset and scroll down with the wheel. |
| 1502 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); | 1503 m_hostImpl->rootLayer()->setScrollDelta(gfx::Vector2dF()); |
| 1503 IntSize wheelScrollDelta(0, 10); | 1504 gfx::Vector2d wheelScrollDelta(0, 10); |
| 1504 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1505 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 1505 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); | 1506 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); |
| 1506 m_hostImpl->scrollEnd(); | 1507 m_hostImpl->scrollEnd(); |
| 1507 | 1508 |
| 1508 // The scale should not have been applied to the scroll delta. | 1509 // The scale should not have been applied to the scroll delta. |
| 1509 scrollInfo = m_hostImpl->processScrollDeltas(); | 1510 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1510 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); | 1511 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); |
| 1511 } | 1512 } |
| 1512 | 1513 |
| 1513 class BlendStateTrackerContext: public FakeWebGraphicsContext3D { | 1514 class BlendStateTrackerContext: public FakeWebGraphicsContext3D { |
| (...skipping 2889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4403 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); | 4404 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); |
| 4404 testCaseIndex++; | 4405 testCaseIndex++; |
| 4405 } | 4406 } |
| 4406 } | 4407 } |
| 4407 | 4408 |
| 4408 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4409 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
| 4409 LayerTreeHostImplTest, | 4410 LayerTreeHostImplTest, |
| 4410 ::testing::Values(false, true)); | 4411 ::testing::Values(false, true)); |
| 4411 | 4412 |
| 4412 } // namespace | 4413 } // namespace |
| OLD | NEW |