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 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 AncestorClipMaskRequirementsForNestedBorderRadius) { | |
| 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 // This case has the child within the grandparent but not the parent, and does | |
| 1431 // require a mask so that the parent will clip the corners. | |
| 1432 SetBodyInnerHTML( | |
|
chrishtr
2017/06/12 19:58:47
Make each of these its own testcase.
Stephen Chennney
2017/06/12 20:41:54
Done.
| |
| 1433 "<style>" | |
| 1434 " #grandparent {" | |
| 1435 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;" | |
| 1436 " }" | |
| 1437 " #parent { position: relative; left: 40px; top: 40px; width: 120px;" | |
| 1438 " height: 120px; border-radius: 10px; overflow: hidden;" | |
| 1439 " }" | |
| 1440 " #child { position: relative; left: 1px; top: 1px; width: 118px;" | |
| 1441 " height: 118px; background-color: green;" | |
| 1442 " will-change: transform;" | |
| 1443 " }" | |
| 1444 "</style>" | |
| 1445 "<div id='grandparent'>" | |
| 1446 " <div id='parent'>" | |
| 1447 " <div id='child'></div>" | |
| 1448 "</div>"); | |
| 1449 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1450 | |
| 1451 child = GetDocument().getElementById("child"); | |
| 1452 ASSERT_TRUE(child); | |
| 1453 child_paint_layer = ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | |
| 1454 ASSERT_TRUE(child_paint_layer); | |
| 1455 child_mapping = child_paint_layer->GetCompositedLayerMapping(); | |
| 1456 ASSERT_TRUE(child_mapping); | |
| 1457 EXPECT_TRUE(child_mapping->AncestorClippingLayer()); | |
| 1458 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer()); | |
| 1459 EXPECT_TRUE(child_mapping->AncestorClippingMaskLayer()); | |
|
chrishtr
2017/06/12 19:58:46
Add an expectation for the size of the mask layer.
Stephen Chennney
2017/06/12 20:41:53
Done.
| |
| 1460 | |
| 1461 // This case has the child within the grandparent but not the parent, and does | |
| 1462 // not require a mask because the parent does not have border radius | |
| 1463 SetBodyInnerHTML( | |
| 1464 "<style>" | |
| 1465 " #grandparent {" | |
| 1466 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;" | |
| 1467 " }" | |
| 1468 " #parent { position: relative; left: 40px; top: 40px; width: 120px;" | |
| 1469 " height: 120px; overflow: hidden;" | |
| 1470 " }" | |
| 1471 " #child { position: relative; left: -10px; top: -10px; width: 140px;" | |
| 1472 " height: 140px; background-color: green;" | |
| 1473 " will-change: transform;" | |
| 1474 " }" | |
| 1475 "</style>" | |
| 1476 "<div id='grandparent'>" | |
| 1477 " <div id='parent'>" | |
| 1478 " <div id='child'></div>" | |
| 1479 "</div>"); | |
| 1480 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1481 | |
| 1482 child = GetDocument().getElementById("child"); | |
| 1483 ASSERT_TRUE(child); | |
| 1484 child_paint_layer = ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | |
| 1485 ASSERT_TRUE(child_paint_layer); | |
| 1486 child_mapping = child_paint_layer->GetCompositedLayerMapping(); | |
| 1487 ASSERT_TRUE(child_mapping); | |
| 1488 EXPECT_TRUE(child_mapping->AncestorClippingLayer()); | |
| 1489 EXPECT_FALSE(child_mapping->AncestorClippingLayer()->MaskLayer()); | |
| 1490 EXPECT_FALSE(child_mapping->AncestorClippingMaskLayer()); | |
| 1491 | |
| 1492 // This case has the child clipped by the grandparent border radius but not | |
| 1493 // the parent, and requires a mask to clip to the grandparent. Although in | |
| 1494 // an optimized world we would not need this because the parent clips out | |
| 1495 // the child before it is clipped by the grandparent. | |
| 1496 SetBodyInnerHTML( | |
| 1497 "<style>" | |
| 1498 " #grandparent {" | |
| 1499 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;" | |
| 1500 " }" | |
| 1501 " #parent { position: relative; left: 40px; top: 40px; width: 120px;" | |
| 1502 " height: 120px; overflow: hidden;" | |
| 1503 " }" | |
| 1504 " #child { position: relative; left: -10px; top: -10px; width: 180px;" | |
| 1505 " height: 180px; background-color: green;" | |
| 1506 " will-change: transform;" | |
| 1507 " }" | |
| 1508 "</style>" | |
| 1509 "<div id='grandparent'>" | |
| 1510 " <div id='parent'>" | |
| 1511 " <div id='child'></div>" | |
| 1512 "</div>"); | |
| 1513 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1514 | |
| 1515 child = GetDocument().getElementById("child"); | |
| 1516 ASSERT_TRUE(child); | |
| 1517 child_paint_layer = ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | |
| 1518 ASSERT_TRUE(child_paint_layer); | |
| 1519 child_mapping = child_paint_layer->GetCompositedLayerMapping(); | |
| 1520 ASSERT_TRUE(child_mapping); | |
| 1521 EXPECT_TRUE(child_mapping->AncestorClippingLayer()); | |
| 1522 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer()); | |
| 1523 EXPECT_TRUE(child_mapping->AncestorClippingMaskLayer()); | |
|
chrishtr
2017/06/12 19:58:46
ditto
Stephen Chennney
2017/06/12 20:41:54
Done.
| |
| 1524 | |
| 1525 // Similar to the previous case, but here we really do need the mask. | |
| 1526 SetBodyInnerHTML( | |
| 1527 "<style>" | |
| 1528 " #grandparent {" | |
| 1529 " width: 200px; height: 200px; overflow: hidden; border-radius: 25px;" | |
| 1530 " }" | |
| 1531 " #parent { position: relative; left: 40px; top: 40px; width: 180px;" | |
| 1532 " height: 180px; overflow: hidden;" | |
| 1533 " }" | |
| 1534 " #child { position: relative; left: -10px; top: -10px; width: 180px;" | |
| 1535 " height: 180px; background-color: green;" | |
| 1536 " will-change: transform;" | |
| 1537 " }" | |
| 1538 "</style>" | |
| 1539 "<div id='grandparent'>" | |
| 1540 " <div id='parent'>" | |
| 1541 " <div id='child'></div>" | |
| 1542 "</div>"); | |
| 1543 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 1544 | |
| 1545 child = GetDocument().getElementById("child"); | |
| 1546 ASSERT_TRUE(child); | |
| 1547 child_paint_layer = ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | |
| 1548 ASSERT_TRUE(child_paint_layer); | |
| 1549 child_mapping = child_paint_layer->GetCompositedLayerMapping(); | |
| 1550 ASSERT_TRUE(child_mapping); | |
| 1551 EXPECT_TRUE(child_mapping->AncestorClippingLayer()); | |
| 1552 EXPECT_TRUE(child_mapping->AncestorClippingLayer()->MaskLayer()); | |
| 1553 EXPECT_TRUE(child_mapping->AncestorClippingMaskLayer()); | |
| 1554 } | |
| 1555 | |
| 1556 TEST_P(CompositedLayerMappingTest, | |
| 1396 AncestorClipMaskNotRequiredByBorderRadiusInside) { | 1557 AncestorClipMaskNotRequiredByBorderRadiusInside) { |
| 1397 // Verify that we do not create the mask layer when the child is contained | 1558 // Verify that we do not create the mask layer when the child is contained |
| 1398 // within the rounded rect clip. | 1559 // within the rounded rect clip. |
| 1399 SetBodyInnerHTML( | 1560 SetBodyInnerHTML( |
| 1400 "<style>" | 1561 "<style>" |
| 1401 " #ancestor {" | 1562 " #ancestor {" |
| 1402 " width: 100px; height: 100px; overflow: hidden; border-radius: 5px;" | 1563 " width: 100px; height: 100px; overflow: hidden; border-radius: 5px;" |
| 1403 " }" | 1564 " }" |
| 1404 " #child { position: relative; left: 10px; top: 10px; width: 80px;" | 1565 " #child { position: relative; left: 10px; top: 10px; width: 80px;" |
| 1405 " height: 80px; background-color: green;" | 1566 " height: 80px; background-color: green;" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1555 | 1716 |
| 1556 // Now that sticky2 and sticky3 overlap sticky1 they will be promoted, but | 1717 // 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 | 1718 // they should not be squashed into the same layer because they scroll with |
| 1558 // respect to each other. | 1719 // respect to each other. |
| 1559 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState()); | 1720 EXPECT_EQ(kPaintsIntoOwnBacking, sticky1->GetCompositingState()); |
| 1560 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState()); | 1721 EXPECT_EQ(kPaintsIntoOwnBacking, sticky2->GetCompositingState()); |
| 1561 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState()); | 1722 EXPECT_EQ(kPaintsIntoOwnBacking, sticky3->GetCompositingState()); |
| 1562 } | 1723 } |
| 1563 | 1724 |
| 1564 } // namespace blink | 1725 } // namespace blink |
| OLD | NEW |