Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/layout/compositing/CompositedLayerMapping.h" | 5 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 6 | 6 |
| 7 #include "core/frame/LocalFrameView.h" | 7 #include "core/frame/LocalFrameView.h" |
| 8 #include "core/layout/LayoutBoxModelObject.h" | 8 #include "core/layout/LayoutBoxModelObject.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/layout/api/LayoutViewItem.h" | 10 #include "core/layout/api/LayoutViewItem.h" |
| (...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 " <div class='composited container'>" | 1488 " <div class='composited container'>" |
| 1489 " <div class='innerPadding'></div>" | 1489 " <div class='innerPadding'></div>" |
| 1490 " <div id='sticky' class='composited'></div>" | 1490 " <div id='sticky' class='composited'></div>" |
| 1491 " </div></div></div>"); | 1491 " </div></div></div>"); |
| 1492 | 1492 |
| 1493 PaintLayer* sticky_layer = | 1493 PaintLayer* sticky_layer = |
| 1494 ToLayoutBox(GetLayoutObjectByElementId("sticky"))->Layer(); | 1494 ToLayoutBox(GetLayoutObjectByElementId("sticky"))->Layer(); |
| 1495 CompositedLayerMapping* sticky_mapping = | 1495 CompositedLayerMapping* sticky_mapping = |
| 1496 sticky_layer->GetCompositedLayerMapping(); | 1496 sticky_layer->GetCompositedLayerMapping(); |
| 1497 ASSERT_TRUE(sticky_mapping); | 1497 ASSERT_TRUE(sticky_mapping); |
| 1498 // Main thread offset for sticky should be "StickyTop - InnerPadding". | |
| 1499 EXPECT_EQ(IntPoint(0, 15), IntPoint(sticky_mapping->MainGraphicsLayer() | |
| 1500 ->ContentLayer() | |
| 1501 ->Layer() | |
| 1502 ->OffsetForStickyPosition())); | |
| 1503 | 1498 |
| 1504 // Now scroll the page - this should increase the main thread offset. | 1499 // Now scroll the page - this should increase the main thread offset. |
| 1505 LayoutBoxModelObject* scroller = | 1500 LayoutBoxModelObject* scroller = |
| 1506 ToLayoutBoxModelObject(GetLayoutObjectByElementId("scroller")); | 1501 ToLayoutBoxModelObject(GetLayoutObjectByElementId("scroller")); |
| 1507 PaintLayerScrollableArea* scrollable_area = scroller->GetScrollableArea(); | 1502 PaintLayerScrollableArea* scrollable_area = scroller->GetScrollableArea(); |
| 1508 scrollable_area->ScrollToAbsolutePosition( | 1503 scrollable_area->ScrollToAbsolutePosition( |
| 1509 FloatPoint(scrollable_area->ScrollPosition().X(), 100)); | 1504 FloatPoint(scrollable_area->ScrollPosition().X(), 100)); |
| 1510 ASSERT_EQ(100.0, scrollable_area->ScrollPosition().Y()); | 1505 ASSERT_EQ(100.0, scrollable_area->ScrollPosition().Y()); |
| 1511 | 1506 |
| 1512 sticky_layer->SetNeedsCompositingInputsUpdate(); | 1507 sticky_layer->SetNeedsCompositingInputsUpdate(); |
| 1513 EXPECT_TRUE(sticky_layer->NeedsCompositingInputsUpdate()); | 1508 EXPECT_TRUE(sticky_layer->NeedsCompositingInputsUpdate()); |
| 1514 GetDocument().View()->UpdateLifecycleToCompositingCleanPlusScrolling(); | 1509 GetDocument().View()->UpdateLifecycleToCompositingCleanPlusScrolling(); |
| 1515 EXPECT_FALSE(sticky_layer->NeedsCompositingInputsUpdate()); | 1510 EXPECT_FALSE(sticky_layer->NeedsCompositingInputsUpdate()); |
| 1516 | |
| 1517 EXPECT_EQ(IntPoint(0, 115), IntPoint(sticky_mapping->MainGraphicsLayer() | |
| 1518 ->ContentLayer() | |
| 1519 ->Layer() | |
| 1520 ->OffsetForStickyPosition())); | |
| 1521 } | 1511 } |
| 1522 | 1512 |
| 1523 TEST_P(CompositedLayerMappingTest, StickyPositionNotSquashed) { | 1513 TEST_P(CompositedLayerMappingTest, StickyPositionNotSquashed) { |
| 1524 SetBodyInnerHTML( | 1514 SetBodyInnerHTML( |
| 1525 "<style>" | 1515 "<style>" |
| 1526 "#scroller { overflow: auto; height: 200px; }" | 1516 "#scroller { overflow: auto; height: 200px; }" |
| 1527 "#sticky1, #sticky2, #sticky3 {position: sticky; top: 0; width: 50px;" | 1517 "#sticky1, #sticky2, #sticky3 {position: sticky; top: 0; width: 50px;" |
| 1528 " height: 50px; background: rgba(0, 128, 0, 0.5);}" | 1518 " height: 50px; background: rgba(0, 128, 0, 0.5);}" |
| 1529 "#sticky1 {backface-visibility: hidden;}" | 1519 "#sticky1 {backface-visibility: hidden;}" |
| 1530 ".spacer {height: 2000px;}" | 1520 ".spacer {height: 2000px;}" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1554 GetDocument().View()->UpdateAllLifecyclePhases(); | 1544 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 1555 | 1545 |
| 1556 // Now that sticky2 and sticky3 overlap sticky1 they will be promoted, but | 1546 // Now that sticky2 and sticky3 overlap sticky1 they will be promoted, but |
| 1557 // they should not be squashed into the same layer because they scroll with | 1547 // they should not be squashed into the same layer because they scroll with |
| 1558 // respect to each other. | 1548 // respect to each other. |
| 1559 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState()); | 1549 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState()); |
| 1560 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState()); | 1550 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState()); |
| 1561 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState()); | 1551 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState()); |
| 1562 } | 1552 } |
| 1563 | 1553 |
| 1554 TEST_P(CompositedLayerMappingTest, | |
| 1555 LayerPositionForStickyElementInCompositedScroller) { | |
| 1556 SetBodyInnerHTML( | |
| 1557 "<style>" | |
| 1558 " .scroller { overflow: scroll; width: 200px; height: 600px; }" | |
| 1559 " .composited { will-change:transform; }" | |
| 1560 " .box { position: sticky; width: 185px; height: 50px; top: 0px; }" | |
| 1561 " .container { width: 100%; height: 1000px; }" | |
| 1562 "</style>" | |
| 1563 "<div id='scroller' class='composited scroller'>" | |
| 1564 " <div class='container'>" | |
| 1565 " <div id='sticky' class='box'></div>" | |
| 1566 " </div>" | |
| 1567 "</div>"); | |
| 1568 | |
| 1569 CompositedLayerMapping* mapping = | |
| 1570 ToLayoutBlock(GetLayoutObjectByElementId("sticky")) | |
| 1571 ->Layer() | |
| 1572 ->GetCompositedLayerMapping(); | |
| 1573 ASSERT_TRUE(mapping); | |
| 1574 GraphicsLayer* main_graphics_layer = mapping->MainGraphicsLayer(); | |
| 1575 | |
| 1576 PaintLayer* scroller = | |
| 1577 ToLayoutBlock(GetLayoutObjectByElementId("scroller"))->Layer(); | |
| 1578 PaintLayerScrollableArea* scrollable_area = scroller->GetScrollableArea(); | |
| 1579 scrollable_area->ScrollToAbsolutePosition( | |
| 1580 FloatPoint(scrollable_area->ScrollPosition().Y(), 100)); | |
| 1581 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1582 | |
| 1583 EXPECT_FLOAT_EQ(0, main_graphics_layer->GetPosition().X()); | |
| 1584 EXPECT_FLOAT_EQ(0, main_graphics_layer->GetPosition().Y()); | |
| 1585 } | |
| 1586 | |
| 1587 TEST_P(CompositedLayerMappingTest, | |
| 1588 LayerPositionForStickyElementInNonCompositedScroller) { | |
| 1589 SetBodyInnerHTML( | |
| 1590 "<style>" | |
| 1591 " .scroller { overflow: scroll; width: 200px; height: 600px; }" | |
| 1592 " .composited { will-change:transform; }" | |
| 1593 " .box { position: sticky; width: 185px; height: 50px; top: 0px; }" | |
| 1594 " .container { width: 100%; height: 1000px; }" | |
| 1595 "</style>" | |
| 1596 "<div id='scroller' class='scroller'>" | |
| 1597 " <div class='composited container'>" | |
|
flackr
2017/06/09 17:33:33
Add this above too so the cases are identical othe
yigu
2017/06/09 17:41:16
Done.
| |
| 1598 " <div id='sticky' class='box'></div>" | |
| 1599 " </div>" | |
| 1600 "</div>"); | |
| 1601 | |
| 1602 CompositedLayerMapping* mapping = | |
| 1603 ToLayoutBlock(GetLayoutObjectByElementId("sticky")) | |
| 1604 ->Layer() | |
| 1605 ->GetCompositedLayerMapping(); | |
| 1606 ASSERT_TRUE(mapping); | |
| 1607 GraphicsLayer* main_graphics_layer = mapping->MainGraphicsLayer(); | |
| 1608 | |
| 1609 PaintLayer* scroller = | |
| 1610 ToLayoutBlock(GetLayoutObjectByElementId("scroller"))->Layer(); | |
| 1611 PaintLayerScrollableArea* scrollable_area = scroller->GetScrollableArea(); | |
| 1612 ASSERT_TRUE(scrollable_area); | |
| 1613 scrollable_area->ScrollToAbsolutePosition( | |
| 1614 FloatPoint(scrollable_area->ScrollPosition().Y(), 100)); | |
| 1615 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1616 | |
| 1617 EXPECT_FLOAT_EQ(0, main_graphics_layer->GetPosition().X()); | |
| 1618 EXPECT_FLOAT_EQ(100, main_graphics_layer->GetPosition().Y()); | |
| 1619 } | |
| 1620 | |
| 1564 } // namespace blink | 1621 } // namespace blink |
| OLD | NEW |