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 "cc/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 // The grand child should have scrolled up to its limit. | 1406 // The grand child should have scrolled up to its limit. |
1407 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1407 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
1408 LayerImpl* grandChild = child->children()[0]; | 1408 LayerImpl* grandChild = child->children()[0]; |
1409 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)
); | 1409 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)
); |
1410 | 1410 |
1411 // The child should have only scrolled on the other axis. | 1411 // The child should have only scrolled on the other axis. |
1412 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); | 1412 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); |
1413 } | 1413 } |
1414 } | 1414 } |
1415 | 1415 |
| 1416 TEST_P(LayerTreeHostImplTest, scrollWithoutBubbling) |
| 1417 { |
| 1418 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1419 // the scroll doesn't bubble up to the parent layer. |
| 1420 gfx::Size surfaceSize(10, 10); |
| 1421 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1422 |
| 1423 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
| 1424 grandChild->setScrollOffset(gfx::Vector2d(0, 2)); |
| 1425 |
| 1426 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1427 child->setScrollOffset(gfx::Vector2d(0, 3)); |
| 1428 child->addChild(grandChild.Pass()); |
| 1429 |
| 1430 root->addChild(child.Pass()); |
| 1431 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
| 1432 m_hostImpl->activeTree()->DidBecomeActive(); |
| 1433 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1434 initializeRendererAndDrawFrame(); |
| 1435 { |
| 1436 gfx::Vector2d scrollDelta(0, -10); |
| 1437 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1438 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1439 m_hostImpl->scrollEnd(); |
| 1440 |
| 1441 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1442 |
| 1443 // The grand child should have scrolled up to its limit. |
| 1444 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1445 LayerImpl* grandChild = child->children()[0]; |
| 1446 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)
); |
| 1447 |
| 1448 // The child should not have scrolled. |
| 1449 expectNone(*scrollInfo.get(), child->id()); |
| 1450 |
| 1451 // The next time we scroll we should only scroll the parent. |
| 1452 scrollDelta = gfx::Vector2d(0, -3); |
| 1453 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1454 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1455 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1456 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), child); |
| 1457 m_hostImpl->scrollEnd(); |
| 1458 |
| 1459 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1460 |
| 1461 // The child should have scrolled up to its limit. |
| 1462 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
| 1463 |
| 1464 // The grand child should not have scrolled. |
| 1465 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)
); |
| 1466 |
| 1467 // After scrolling the parent, another scroll on the opposite direction |
| 1468 // should still scroll the child. |
| 1469 scrollDelta = gfx::Vector2d(0, 7); |
| 1470 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1471 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1472 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1473 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1474 m_hostImpl->scrollEnd(); |
| 1475 |
| 1476 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1477 |
| 1478 // The grand child should have scrolled. |
| 1479 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 5))
; |
| 1480 |
| 1481 // The child should not have scrolled. |
| 1482 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
| 1483 } |
| 1484 } |
| 1485 |
1416 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) | 1486 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) |
1417 { | 1487 { |
1418 // When we try to scroll a non-scrollable child layer, the scroll delta | 1488 // When we try to scroll a non-scrollable child layer, the scroll delta |
1419 // should be applied to one of its ancestors if possible. | 1489 // should be applied to one of its ancestors if possible. |
1420 gfx::Size surfaceSize(10, 10); | 1490 gfx::Size surfaceSize(10, 10); |
1421 gfx::Size contentSize(20, 20); | 1491 gfx::Size contentSize(20, 20); |
1422 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); | 1492 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); |
1423 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); | 1493 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); |
1424 | 1494 |
1425 child->setScrollable(false); | 1495 child->setScrollable(false); |
(...skipping 2783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4209 m_hostImpl->didDrawAllLayers(frame); | 4279 m_hostImpl->didDrawAllLayers(frame); |
4210 } | 4280 } |
4211 } | 4281 } |
4212 | 4282 |
4213 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4283 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
4214 LayerTreeHostImplTest, | 4284 LayerTreeHostImplTest, |
4215 ::testing::Values(false, true)); | 4285 ::testing::Values(false, true)); |
4216 | 4286 |
4217 } // namespace | 4287 } // namespace |
4218 } // namespace cc | 4288 } // namespace cc |
OLD | NEW |