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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 // The grand child should have scrolled up to its limit. | 1502 // The grand child should have scrolled up to its limit. |
1503 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1503 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
1504 LayerImpl* grandChild = child->children()[0]; | 1504 LayerImpl* grandChild = child->children()[0]; |
1505 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)
); | 1505 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)
); |
1506 | 1506 |
1507 // The child should have only scrolled on the other axis. | 1507 // The child should have only scrolled on the other axis. |
1508 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); | 1508 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); |
1509 } | 1509 } |
1510 } | 1510 } |
1511 | 1511 |
| 1512 TEST_P(LayerTreeHostImplTest, scrollWithoutBubbling) |
| 1513 { |
| 1514 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1515 // the scroll doesn't bubble up to the parent layer. |
| 1516 gfx::Size surfaceSize(10, 10); |
| 1517 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1518 |
| 1519 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
| 1520 grandChild->setScrollOffset(gfx::Vector2d(0, 2)); |
| 1521 |
| 1522 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1523 child->setScrollOffset(gfx::Vector2d(0, 3)); |
| 1524 child->addChild(grandChild.Pass()); |
| 1525 |
| 1526 root->addChild(child.Pass()); |
| 1527 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
| 1528 m_hostImpl->activeTree()->DidBecomeActive(); |
| 1529 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1530 initializeRendererAndDrawFrame(); |
| 1531 { |
| 1532 gfx::Vector2d scrollDelta(0, -10); |
| 1533 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1534 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1535 m_hostImpl->scrollEnd(); |
| 1536 |
| 1537 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1538 |
| 1539 // The grand child should have scrolled up to its limit. |
| 1540 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1541 LayerImpl* grandChild = child->children()[0]; |
| 1542 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)
); |
| 1543 |
| 1544 // The child should not have scrolled. |
| 1545 expectNone(*scrollInfo.get(), child->id()); |
| 1546 |
| 1547 // The next time we scroll we should only scroll the parent. |
| 1548 scrollDelta = gfx::Vector2d(0, -3); |
| 1549 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1550 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1551 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1552 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), child); |
| 1553 m_hostImpl->scrollEnd(); |
| 1554 |
| 1555 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1556 |
| 1557 // The child should have scrolled up to its limit. |
| 1558 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
| 1559 |
| 1560 // The grand child should not have scrolled. |
| 1561 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)
); |
| 1562 |
| 1563 // After scrolling the parent, another scroll on the opposite direction |
| 1564 // should still scroll the child. |
| 1565 scrollDelta = gfx::Vector2d(0, 7); |
| 1566 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::
NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1567 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1568 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
| 1569 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); |
| 1570 m_hostImpl->scrollEnd(); |
| 1571 |
| 1572 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1573 |
| 1574 // The grand child should have scrolled. |
| 1575 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 5))
; |
| 1576 |
| 1577 // The child should not have scrolled. |
| 1578 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
| 1579 } |
| 1580 } |
| 1581 |
1512 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) | 1582 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) |
1513 { | 1583 { |
1514 // When we try to scroll a non-scrollable child layer, the scroll delta | 1584 // When we try to scroll a non-scrollable child layer, the scroll delta |
1515 // should be applied to one of its ancestors if possible. | 1585 // should be applied to one of its ancestors if possible. |
1516 gfx::Size surfaceSize(10, 10); | 1586 gfx::Size surfaceSize(10, 10); |
1517 gfx::Size contentSize(20, 20); | 1587 gfx::Size contentSize(20, 20); |
1518 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); | 1588 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); |
1519 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); | 1589 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); |
1520 | 1590 |
1521 child->setScrollable(false); | 1591 child->setScrollable(false); |
(...skipping 3154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4676 m_hostImpl->didDrawAllLayers(frame); | 4746 m_hostImpl->didDrawAllLayers(frame); |
4677 } | 4747 } |
4678 } | 4748 } |
4679 | 4749 |
4680 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4750 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
4681 LayerTreeHostImplTest, | 4751 LayerTreeHostImplTest, |
4682 ::testing::Values(false, true)); | 4752 ::testing::Values(false, true)); |
4683 | 4753 |
4684 } // namespace | 4754 } // namespace |
4685 } // namespace cc | 4755 } // namespace cc |
OLD | NEW |