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

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

Issue 2929873002: Shifting layer position for sticky element to avoid passing unnessary variable to cc (Closed)
Patch Set: Created 3 years, 6 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/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
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
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, LayerPositionForStickyElement) {
1555 SetBodyInnerHTML(
1556 "<style>"
1557 " .scroller { overflow: scroll; width: 200px; height: 600px; }"
1558 " .composited { will-change:transform; }"
1559 " .box { position: sticky; width: 185px; height: 50px; top: 0px; }"
1560 " .container { width: 100%; height: 1000px; }"
1561 "</style>"
1562 "<div id='scroller' class='composited scroller'>"
1563 " <div class='container'>"
1564 " <div id='sticky' class='box'></div>"
1565 " </div>"
1566 "</div>");
1567
1568 CompositedLayerMapping* mapping =
1569 ToLayoutBlock(GetLayoutObjectByElementId("sticky"))
1570 ->Layer()
1571 ->GetCompositedLayerMapping();
1572 ASSERT_TRUE(mapping);
1573 GraphicsLayer* main_graphics_layer = mapping->MainGraphicsLayer();
1574
1575 PaintLayer* scroller =
1576 ToLayoutBlock(GetLayoutObjectByElementId("scroller"))->Layer();
1577 PaintLayerScrollableArea* scrollable_area = scroller->GetScrollableArea();
1578 scrollable_area->ScrollToAbsolutePosition(
1579 FloatPoint(scrollable_area->ScrollPosition().Y(), 100));
1580 GetDocument().View()->UpdateAllLifecyclePhases();
1581
1582 EXPECT_FLOAT_EQ(0, main_graphics_layer->GetPosition().X());
1583 EXPECT_FLOAT_EQ(0, main_graphics_layer->GetPosition().Y());
flackr 2017/06/08 18:56:19 You should have both a composited scroller and non
yigu 2017/06/08 23:30:03 I added a test with non-composited scroller. As th
flackr 2017/06/08 23:54:46 All else being equal, one test should have the sti
1584 }
1585
1564 } // namespace blink 1586 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698