Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp

Issue 2765503003: Fix position:sticky location bug when scroller is not a stacking context (Closed)
Patch Set: Add unittest Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/FrameView.h" 7 #include "core/frame/FrameView.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 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 WebLayerStickyPositionConstraint constraint = 1534 WebLayerStickyPositionConstraint constraint =
1535 sticky->mainGraphicsLayer() 1535 sticky->mainGraphicsLayer()
1536 ->contentLayer() 1536 ->contentLayer()
1537 ->layer() 1537 ->layer()
1538 ->stickyPositionConstraint(); 1538 ->stickyPositionConstraint();
1539 EXPECT_EQ(IntPoint(0, 50), 1539 EXPECT_EQ(IntPoint(0, 50),
1540 IntPoint(constraint.parentRelativeStickyBoxOffset)); 1540 IntPoint(constraint.parentRelativeStickyBoxOffset));
1541 } 1541 }
1542 1542
1543 TEST_P(CompositedLayerMappingTest, StickyPositionEnclosingLayersContentOffset) { 1543 TEST_P(CompositedLayerMappingTest, StickyPositionEnclosingLayersContentOffset) {
1544 // Using backface-visibility: hidden causes the scroller to become composited
1545 // without creating a stacking context. This is important as enclosing layer
1546 // scroll correction works differently depending on whether you are in a
1547 // stacking context or not.
1548 setBodyInnerHTML(
1549 "<style>.composited { backface-visibility: hidden; }"
1550 "#scroller { overflow: auto; height: 200px; width: 200px; }"
1551 ".container { height: 500px; }"
1552 ".innerPadding { height: 10px; }"
1553 "#sticky { position: sticky; top: 25px; height: 50px; }</style>"
1554 "<div id='scroller' class='composited'>"
1555 "<div class='composited container'>"
flackr 2017/03/23 16:58:03 nit: indent.
smcgruer 2017/03/23 17:22:48 Done.
1556 " <div class='composited container'>"
1557 " <div class='innerPadding'></div>"
1558 " <div id='sticky' class='composited'></div>"
1559 " </div></div></div>");
1560
1561 PaintLayer* stickyLayer =
1562 toLayoutBox(getLayoutObjectByElementId("sticky"))->layer();
1563 CompositedLayerMapping* stickyMapping = stickyLayer->compositedLayerMapping();
1564 ASSERT_TRUE(stickyMapping);
1565
1566 WebLayerStickyPositionConstraint constraint =
1567 stickyMapping->mainGraphicsLayer()
1568 ->contentLayer()
1569 ->layer()
1570 ->stickyPositionConstraint();
1571 EXPECT_EQ(IntPoint(0, 10),
1572 IntPoint(constraint.parentRelativeStickyBoxOffset));
1573
1574 // Now scroll the page - this should not affect the parent-relative offset.
1575 LayoutBoxModelObject* scroller =
1576 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
1577 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
1578 scrollableArea->scrollToAbsolutePosition(
1579 FloatPoint(scrollableArea->scrollPosition().x(), 100));
1580 ASSERT_EQ(100.0, scrollableArea->scrollPosition().y());
1581
1582 stickyLayer->setNeedsCompositingInputsUpdate();
1583 EXPECT_TRUE(stickyLayer->needsCompositingInputsUpdate());
1584 document().view()->updateLifecycleToCompositingCleanPlusScrolling();
1585 EXPECT_FALSE(stickyLayer->needsCompositingInputsUpdate());
1586
1587 constraint = stickyMapping->mainGraphicsLayer()
1588 ->contentLayer()
1589 ->layer()
1590 ->stickyPositionConstraint();
1591 EXPECT_EQ(IntPoint(0, 10),
1592 IntPoint(constraint.parentRelativeStickyBoxOffset));
1593 }
1594
1595 TEST_P(CompositedLayerMappingTest,
1596 StickyPositionEnclosingLayersWithStackingContextContentOffset) {
1597 // Using will-change: transform causes the scroller to become a stacking
1598 // context. This changes how its descendant layers interact with it; they no
1599 // longer have a scrollParent and instead just refer to it only as their
1600 // ancestorOverflowLayer.
1544 setBodyInnerHTML( 1601 setBodyInnerHTML(
1545 "<style>.composited { will-change: transform; }" 1602 "<style>.composited { will-change: transform; }"
1546 "#scroller { overflow: auto; height: 200px; width: 200px; }" 1603 "#scroller { overflow: auto; height: 200px; width: 200px; }"
1547 ".container { height: 500px; }" 1604 ".container { height: 500px; }"
1548 ".innerPadding { height: 10px; }" 1605 ".innerPadding { height: 10px; }"
1549 "#sticky { position: sticky; top: 25px; height: 50px; }</style>" 1606 "#sticky { position: sticky; top: 25px; height: 50px; }</style>"
1550 "<div id='scroller' class='composited'>" 1607 "<div id='scroller' class='composited'>"
1551 "<div class='composited container'>" 1608 "<div class='composited container'>"
1552 " <div class='composited container'>" 1609 " <div class='composited container'>"
1553 " <div class='innerPadding'></div>" 1610 " <div class='innerPadding'></div>"
(...skipping 28 matching lines...) Expand all
1582 1639
1583 constraint = stickyMapping->mainGraphicsLayer() 1640 constraint = stickyMapping->mainGraphicsLayer()
1584 ->contentLayer() 1641 ->contentLayer()
1585 ->layer() 1642 ->layer()
1586 ->stickyPositionConstraint(); 1643 ->stickyPositionConstraint();
1587 EXPECT_EQ(IntPoint(0, 10), 1644 EXPECT_EQ(IntPoint(0, 10),
1588 IntPoint(constraint.parentRelativeStickyBoxOffset)); 1645 IntPoint(constraint.parentRelativeStickyBoxOffset));
1589 } 1646 }
1590 1647
1591 } // namespace blink 1648 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698