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

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

Issue 2923683002: Fix nested border radius with composited child. (Closed)
Patch Set: Split tests, check layer sizes, document 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 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 ASSERT_TRUE(child_paint_layer); 1386 ASSERT_TRUE(child_paint_layer);
1387 CompositedLayerMapping* child_mapping = 1387 CompositedLayerMapping* child_mapping =
1388 child_paint_layer->GetCompositedLayerMapping(); 1388 child_paint_layer->GetCompositedLayerMapping();
1389 ASSERT_TRUE(child_mapping); 1389 ASSERT_TRUE(child_mapping);
1390 EXPECT_TRUE(child_mapping->AncestorClippingLayer()); 1390 EXPECT_TRUE(child_mapping->AncestorClippingLayer());
1391 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer()); 1391 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer());
1392 EXPECT_TRUE(child_mapping->AncestorClippingMaskLayer()); 1392 EXPECT_TRUE(child_mapping->AncestorClippingMaskLayer());
1393 } 1393 }
1394 1394
1395 TEST_P(CompositedLayerMappingTest, 1395 TEST_P(CompositedLayerMappingTest,
1396 AncestorClipMaskNotRequiredByNestedBorderRadius) {
1397 // This case has the child within all ancestors and does not require a
1398 // mask.
1399 SetBodyInnerHTML(
1400 "<style>"
1401 " #grandparent {"
1402 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;"
1403 " }"
1404 " #parent { position: relative; left: 40px; top: 40px; width: 120px;"
1405 " height: 120px; border-radius: 10px; overflow: hidden;"
1406 " }"
1407 " #child { position: relative; left: 10px; top: 10px; width: 100px;"
1408 " height: 100px; background-color: green;"
1409 " will-change: transform;"
1410 " }"
1411 "</style>"
1412 "<div id='grandparent'>"
1413 " <div id='parent'>"
1414 " <div id='child'></div>"
1415 "</div>");
1416 GetDocument().View()->UpdateAllLifecyclePhases();
1417
1418 Element* child = GetDocument().getElementById("child");
1419 ASSERT_TRUE(child);
1420 PaintLayer* child_paint_layer =
1421 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
1422 ASSERT_TRUE(child_paint_layer);
1423 CompositedLayerMapping* child_mapping =
1424 child_paint_layer->GetCompositedLayerMapping();
1425 ASSERT_TRUE(child_mapping);
1426 EXPECT_TRUE(child_mapping->AncestorClippingLayer());
1427 EXPECT_FALSE(child_mapping->AncestorClippingLayer()->MaskLayer());
1428 EXPECT_FALSE(child_mapping->AncestorClippingMaskLayer());
1429 }
1430
1431 TEST_P(CompositedLayerMappingTest,
1432 AncestorClipMaskRequiredByParentBorderRadius) {
1433 // This case has the child within the grandparent but not the parent, and does
1434 // require a mask so that the parent will clip the corners.
1435 SetBodyInnerHTML(
1436 "<style>"
1437 " #grandparent {"
1438 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;"
1439 " }"
1440 " #parent { position: relative; left: 40px; top: 40px; width: 120px;"
1441 " height: 120px; border-radius: 10px; overflow: hidden;"
1442 " }"
1443 " #child { position: relative; left: 1px; top: 1px; width: 118px;"
1444 " height: 118px; background-color: green;"
1445 " will-change: transform;"
1446 " }"
1447 "</style>"
1448 "<div id='grandparent'>"
1449 " <div id='parent'>"
1450 " <div id='child'></div>"
1451 "</div>");
1452 GetDocument().View()->UpdateAllLifecyclePhases();
1453
1454 Element* child = GetDocument().getElementById("child");
1455 ASSERT_TRUE(child);
1456 PaintLayer* child_paint_layer =
1457 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
1458 ASSERT_TRUE(child_paint_layer);
1459 CompositedLayerMapping* child_mapping =
1460 child_paint_layer->GetCompositedLayerMapping();
1461 ASSERT_TRUE(child_mapping);
1462 ASSERT_TRUE(child_mapping->AncestorClippingLayer());
1463 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer());
1464 ASSERT_TRUE(child_mapping->AncestorClippingMaskLayer());
1465 const FloatSize layer_size =
1466 child_mapping->AncestorClippingMaskLayer()->Size();
1467 EXPECT_EQ(120, layer_size.Width());
1468 EXPECT_EQ(120, layer_size.Height());
1469 }
1470
1471 TEST_P(CompositedLayerMappingTest,
1472 AncestorClipMaskNotRequiredByParentBorderRadius) {
1473 // This case has the child within the grandparent but not the parent, and does
1474 // not require a mask because the parent does not have border radius
1475 SetBodyInnerHTML(
1476 "<style>"
1477 " #grandparent {"
1478 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;"
1479 " }"
1480 " #parent { position: relative; left: 40px; top: 40px; width: 120px;"
1481 " height: 120px; overflow: hidden;"
1482 " }"
1483 " #child { position: relative; left: -10px; top: -10px; width: 140px;"
1484 " height: 140px; background-color: green;"
1485 " will-change: transform;"
1486 " }"
1487 "</style>"
1488 "<div id='grandparent'>"
1489 " <div id='parent'>"
1490 " <div id='child'></div>"
1491 "</div>");
1492 GetDocument().View()->UpdateAllLifecyclePhases();
1493
1494 Element* child = GetDocument().getElementById("child");
1495 ASSERT_TRUE(child);
1496 PaintLayer* child_paint_layer =
1497 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
1498 ASSERT_TRUE(child_paint_layer);
1499 CompositedLayerMapping* child_mapping =
1500 child_paint_layer->GetCompositedLayerMapping();
1501 ASSERT_TRUE(child_mapping);
1502 EXPECT_TRUE(child_mapping->AncestorClippingLayer());
1503 EXPECT_FALSE(child_mapping->AncestorClippingLayer()->MaskLayer());
1504 EXPECT_FALSE(child_mapping->AncestorClippingMaskLayer());
1505 }
1506
1507 TEST_P(CompositedLayerMappingTest,
1508 AncestorClipMaskRequiredByGrandparentBorderRadius1) {
1509 // This case has the child clipped by the grandparent border radius but not
1510 // the parent, and requires a mask to clip to the grandparent. Although in
1511 // an optimized world we would not need this because the parent clips out
1512 // the child before it is clipped by the grandparent.
1513 SetBodyInnerHTML(
1514 "<style>"
1515 " #grandparent {"
1516 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;"
1517 " }"
1518 " #parent { position: relative; left: 40px; top: 40px; width: 120px;"
1519 " height: 120px; overflow: hidden;"
1520 " }"
1521 " #child { position: relative; left: -10px; top: -10px; width: 180px;"
1522 " height: 180px; background-color: green;"
1523 " will-change: transform;"
1524 " }"
1525 "</style>"
1526 "<div id='grandparent'>"
1527 " <div id='parent'>"
1528 " <div id='child'></div>"
1529 "</div>");
1530 GetDocument().View()->UpdateAllLifecyclePhases();
1531
1532 Element* child = GetDocument().getElementById("child");
1533 ASSERT_TRUE(child);
1534 PaintLayer* child_paint_layer =
1535 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
1536 ASSERT_TRUE(child_paint_layer);
1537 CompositedLayerMapping* child_mapping =
1538 child_paint_layer->GetCompositedLayerMapping();
1539 ASSERT_TRUE(child_mapping);
1540 ASSERT_TRUE(child_mapping->AncestorClippingLayer());
1541 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer());
1542 ASSERT_TRUE(child_mapping->AncestorClippingMaskLayer());
1543 const FloatSize layer_size =
1544 child_mapping->AncestorClippingMaskLayer()->Size();
1545 EXPECT_EQ(120, layer_size.Width());
1546 EXPECT_EQ(120, layer_size.Height());
1547 }
1548
1549 TEST_P(CompositedLayerMappingTest,
1550 AncestorClipMaskRequiredByGrandparentBorderRadius2) {
1551 // Similar to the previous case, but here we really do need the mask.
1552 SetBodyInnerHTML(
1553 "<style>"
1554 " #grandparent {"
1555 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;"
1556 " }"
1557 " #parent { position: relative; left: 40px; top: 40px; width: 180px;"
1558 " height: 180px; overflow: hidden;"
1559 " }"
1560 " #child { position: relative; left: -10px; top: -10px; width: 180px;"
1561 " height: 180px; background-color: green;"
1562 " will-change: transform;"
1563 " }"
1564 "</style>"
1565 "<div id='grandparent'>"
1566 " <div id='parent'>"
1567 " <div id='child'></div>"
1568 "</div>");
1569 GetDocument().View()->UpdateAllLifecyclePhases();
1570
1571 Element* child = GetDocument().getElementById("child");
1572 ASSERT_TRUE(child);
1573 PaintLayer* child_paint_layer =
1574 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
1575 ASSERT_TRUE(child_paint_layer);
1576 CompositedLayerMapping* child_mapping =
1577 child_paint_layer->GetCompositedLayerMapping();
1578 ASSERT_TRUE(child_mapping);
1579 ASSERT_TRUE(child_mapping->AncestorClippingLayer());
1580 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer());
1581 ASSERT_TRUE(child_mapping->AncestorClippingMaskLayer());
1582 const FloatSize layer_size =
1583 child_mapping->AncestorClippingMaskLayer()->Size();
1584 EXPECT_EQ(160, layer_size.Width());
1585 EXPECT_EQ(160, layer_size.Height());
1586 }
1587
1588 TEST_P(CompositedLayerMappingTest,
1396 AncestorClipMaskNotRequiredByBorderRadiusInside) { 1589 AncestorClipMaskNotRequiredByBorderRadiusInside) {
1397 // Verify that we do not create the mask layer when the child is contained 1590 // Verify that we do not create the mask layer when the child is contained
1398 // within the rounded rect clip. 1591 // within the rounded rect clip.
1399 SetBodyInnerHTML( 1592 SetBodyInnerHTML(
1400 "<style>" 1593 "<style>"
1401 " #ancestor {" 1594 " #ancestor {"
1402 " width: 100px; height: 100px; overflow: hidden; border-radius: 5px;" 1595 " width: 100px; height: 100px; overflow: hidden; border-radius: 5px;"
1403 " }" 1596 " }"
1404 " #child { position: relative; left: 10px; top: 10px; width: 80px;" 1597 " #child { position: relative; left: 10px; top: 10px; width: 80px;"
1405 " height: 80px; background-color: green;" 1598 " height: 80px; background-color: green;"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1748
1556 // Now that sticky2 and sticky3 overlap sticky1 they will be promoted, but 1749 // 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 1750 // they should not be squashed into the same layer because they scroll with
1558 // respect to each other. 1751 // respect to each other.
1559 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState()); 1752 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState());
1560 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState()); 1753 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState());
1561 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState()); 1754 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState());
1562 } 1755 }
1563 1756
1564 } // namespace blink 1757 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698