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

Side by Side Diff: Source/core/layout/LayoutGrid.cpp

Issue 1125703002: [CSS Grid Layout] Refactoring of grid's alignment logic (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 m_columnPositions[0] = borderAndPaddingStart() + sizingData.columnsPositionO ffset; 1323 m_columnPositions[0] = borderAndPaddingStart() + sizingData.columnsPositionO ffset;
1324 for (unsigned i = 0; i < numberOfColumnTracks; ++i) 1324 for (unsigned i = 0; i < numberOfColumnTracks; ++i)
1325 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnsDist ributionOffset + sizingData.columnTracks[i].baseSize(); 1325 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnsDist ributionOffset + sizingData.columnTracks[i].baseSize();
1326 1326
1327 m_rowPositions.resize(numberOfRowTracks + 1); 1327 m_rowPositions.resize(numberOfRowTracks + 1);
1328 m_rowPositions[0] = borderAndPaddingBefore() + sizingData.rowsPositionOffset ; 1328 m_rowPositions[0] = borderAndPaddingBefore() + sizingData.rowsPositionOffset ;
1329 for (unsigned i = 0; i < numberOfRowTracks; ++i) 1329 for (unsigned i = 0; i < numberOfRowTracks; ++i)
1330 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowsDistributionO ffset + sizingData.rowTracks[i].baseSize(); 1330 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowsDistributionO ffset + sizingData.rowTracks[i].baseSize();
1331 } 1331 }
1332 1332
1333 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) 1333 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth)
1334 { 1334 {
1335 LayoutUnit trackBreadth = endOfTrack - startOfTrack;
1336 LayoutUnit offset = trackBreadth - childBreadth; 1335 LayoutUnit offset = trackBreadth - childBreadth;
1337 1336 switch (overflow) {
1338 // If overflow is 'safe', we have to make sure we don't overflow the 'start' 1337 case OverflowAlignmentSafe:
1339 // edge (potentially cause some data loss as the overflow is unreachable). 1338 // If overflow is 'safe', we have to make sure we don't overflow the 'st art'
1340 if (overflow == OverflowAlignmentSafe) 1339 // edge (potentially cause some data loss as the overflow is unreachable ).
1341 offset = std::max<LayoutUnit>(0, offset); 1340 return std::max<LayoutUnit>(0, offset);
1342 1341 case OverflowAlignmentTrue:
1343 // If we overflow our alignment container and overflow is 'true' (default), we 1342 case OverflowAlignmentDefault:
1344 // ignore the overflow and just return the value regardless (which may cause data 1343 // If we overflow our alignment container and overflow is 'true' (defaul t), we
1345 // loss as we overflow the 'start' edge). 1344 // ignore the overflow and just return the value regardless (which may c ause data
1346 return offset; 1345 // loss as we overflow the 'start' edge).
1347 } 1346 return offset;
1348
1349 LayoutUnit LayoutGrid::startOfColumnForChild(const LayoutBox& child) const
1350 {
1351 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1352 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1353 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1354 return startOfColumn + marginStartForChild(child);
1355 }
1356
1357 LayoutUnit LayoutGrid::endOfColumnForChild(const LayoutBox& child) const
1358 {
1359 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1360 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1361 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1362 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child);
1363
1364 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()];
1365 // FIXME: This might not work as expected with orthogonal writing-modes.
1366 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica lWidth() + child.marginLogicalWidth());
1367
1368 return columnPosition + offsetFromColumnPosition;
1369 }
1370
1371 LayoutUnit LayoutGrid::columnPositionLeft(const LayoutBox& child) const
1372 {
1373 if (style()->isLeftToRightDirection())
1374 return startOfColumnForChild(child);
1375
1376 return endOfColumnForChild(child);
1377 }
1378
1379 LayoutUnit LayoutGrid::columnPositionRight(const LayoutBox& child) const
1380 {
1381 if (!style()->isLeftToRightDirection())
1382 return startOfColumnForChild(child);
1383
1384 return endOfColumnForChild(child);
1385 }
1386
1387 LayoutUnit LayoutGrid::centeredColumnPositionForChild(const LayoutBox& child) co nst
1388 {
1389 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1390 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1391 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()];
1392 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child);
1393 // FIXME: This might not work as expected with orthogonal writing-modes.
1394 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica lWidth() + child.marginLogicalWidth());
1395
1396 return columnPosition + offsetFromColumnPosition / 2;
1397 }
1398
1399 LayoutUnit LayoutGrid::columnPositionForChild(const LayoutBox& child) const
1400 {
1401 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
1402
1403 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It emPositionStretch)) {
1404 case ItemPositionSelfStart:
1405 // For orthogonal writing-modes, this computes to 'start'
1406 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1407 if (hasOrthogonalWritingMode)
1408 return startOfColumnForChild(child);
1409
1410 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction.
1411 if (child.style()->direction() != style()->direction())
1412 return endOfColumnForChild(child);
1413
1414 return startOfColumnForChild(child);
1415 case ItemPositionSelfEnd:
1416 // For orthogonal writing-modes, this computes to 'start'
1417 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1418 if (hasOrthogonalWritingMode)
1419 return endOfColumnForChild(child);
1420
1421 // self-end is based on the child's direction. That's why we need to che ck against the grid container's direction.
1422 if (child.style()->direction() != style()->direction())
1423 return startOfColumnForChild(child);
1424
1425 return endOfColumnForChild(child);
1426 case ItemPositionFlexStart:
1427 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1428 return startOfColumnForChild(child);
1429 case ItemPositionFlexEnd:
1430 // Only used in flex layout, for other layout, it's equivalent to 'end'.
1431 return endOfColumnForChild(child);
1432 case ItemPositionLeft:
1433 return columnPositionLeft(child);
1434 case ItemPositionRight:
1435 return columnPositionRight(child);
1436 case ItemPositionCenter:
1437 return centeredColumnPositionForChild(child);
1438 case ItemPositionStart:
1439 return startOfColumnForChild(child);
1440 case ItemPositionEnd:
1441 return endOfColumnForChild(child);
1442 case ItemPositionAuto:
1443 break;
1444 case ItemPositionStretch:
1445 return startOfColumnForChild(child);
1446 case ItemPositionBaseline:
1447 case ItemPositionLastBaseline:
1448 // FIXME: Implement the previous values. For now, we always 'start' alig n the child.
1449 return startOfColumnForChild(child);
1450 } 1347 }
1451 1348
1452 ASSERT_NOT_REACHED(); 1349 ASSERT_NOT_REACHED();
1453 return 0; 1350 return 0;
1454 } 1351 }
1455 1352
1456 LayoutUnit LayoutGrid::endOfRowForChild(const LayoutBox& child) const
1457 {
1458 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1459
1460 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()];
1461 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1462 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child);
1463
1464 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()];
1465 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() + child.marginLogicalHeight());
1466
1467 return rowPosition + offsetFromRowPosition;
1468 }
1469
1470 LayoutUnit LayoutGrid::startOfRowForChild(const LayoutBox& child) const
1471 {
1472 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1473
1474 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()];
1475 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1476 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child);
1477
1478 return rowPosition;
1479 }
1480
1481 LayoutUnit LayoutGrid::centeredRowPositionForChild(const LayoutBox& child) const
1482 {
1483 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1484
1485 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1486 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()];
1487 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()];
1488 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child);
1489 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight() + child.marginLogicalHeight());
1490
1491 return rowPosition + offsetFromRowPosition / 2;
1492 }
1493
1494 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child) 1353 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child)
1495 { 1354 {
1496 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight(); 1355 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight();
1497 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); 1356 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight);
1498 } 1357 }
1499 1358
1500 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c onst 1359 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c onst
1501 { 1360 {
1502 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); 1361 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto();
1503 } 1362 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) 1444 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight())
1586 child.setOverrideLogicalContentHeight(desiredLogicalHeight - chi ld.borderAndPaddingLogicalHeight()); 1445 child.setOverrideLogicalContentHeight(desiredLogicalHeight - chi ld.borderAndPaddingLogicalHeight());
1587 if (childNeedsRelayout) { 1446 if (childNeedsRelayout) {
1588 child.setLogicalHeight(0); 1447 child.setLogicalHeight(0);
1589 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 1448 child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
1590 } 1449 }
1591 } 1450 }
1592 } 1451 }
1593 } 1452 }
1594 1453
1454 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const
1455 {
1456 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
1457 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode();
1458
1459 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) {
1460 case ItemPositionSelfStart:
1461 // If orthogonal writing-modes, this computes to 'start'.
1462 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
svillar 2015/06/10 08:27:20 You're repeating this same FIXME for every single
jfernandez 2015/06/11 12:00:31 I'm not totally sure. The comment helps to realize
1463 // self-start is based on the child's block axis direction. That's why w e need to check against the grid container's block flow.
1464 return (hasOrthogonalWritingMode || hasSameWritingMode) ? GridAxisStart : GridAxisEnd;
1465 case ItemPositionSelfEnd:
1466 // If orthogonal writing-modes, this computes to 'end'.
1467 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1468 // self-end is based on the child's block axis direction. That's why we need to check against the grid container's block flow.
1469 return (hasOrthogonalWritingMode || hasSameWritingMode) ? GridAxisEnd : GridAxisStart;
1470 case ItemPositionLeft:
1471 // The alignment axis (column axis) and the inline axis are parallell in
1472 // orthogonal writing mode. Otherwise this this is equivalent to 'start' .
1473 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1474 return GridAxisStart;
1475 case ItemPositionRight:
1476 // The alignment axis (column axis) and the inline axis are parallell in
1477 // orthogonal writing mode. Otherwise this this is equivalent to 'start' .
1478 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1479 return hasOrthogonalWritingMode ? GridAxisEnd : GridAxisStart;
svillar 2015/06/10 08:27:20 I don't get why you use hastOrthogonalWritingMode
jfernandez 2015/06/11 12:00:31 It's explained in the comment above; we can only a
1480 case ItemPositionCenter:
1481 return GridAxisCenter;
1482 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'.
1483 case ItemPositionStart:
1484 return GridAxisStart;
1485 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'.
1486 case ItemPositionEnd:
1487 return GridAxisEnd;
1488 case ItemPositionStretch:
1489 return GridAxisStart;
1490 case ItemPositionBaseline:
1491 case ItemPositionLastBaseline:
1492 // FIXME: Implement the previous values. For now, we always 'start' alig n the child.
svillar 2015/06/10 08:27:20 Does "previous values" mean baseline alignment? If
jfernandez 2015/06/11 12:00:31 Yes, you are right. That comment was already there
1493 return GridAxisStart;
1494 case ItemPositionAuto:
1495 break;
1496 }
1497
1498 ASSERT_NOT_REACHED();
1499 return GridAxisStart;
1500 }
1501
1502 GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con st
1503 {
1504 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
1505 bool hasSameDirection = child.styleRef().direction() == styleRef().direction ();
1506 bool isLTR = styleRef().isLeftToRightDirection();
1507
1508 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It emPositionStretch)) {
1509 case ItemPositionSelfStart:
1510 // For orthogonal writing-modes, this computes to 'start'
1511 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1512 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction.
1513 return (hasOrthogonalWritingMode || hasSameDirection) ? GridAxisStart : GridAxisEnd;
1514 case ItemPositionSelfEnd:
1515 // For orthogonal writing-modes, this computes to 'start'
1516 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1517 return (hasOrthogonalWritingMode || hasSameDirection) ? GridAxisEnd : Gr idAxisStart;
1518 case ItemPositionLeft:
1519 return isLTR ? GridAxisStart : GridAxisEnd;
1520 case ItemPositionRight:
1521 return isLTR ? GridAxisEnd : GridAxisStart;
1522 case ItemPositionCenter:
1523 return GridAxisCenter;
1524 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'.
1525 case ItemPositionStart:
1526 return GridAxisStart;
1527 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'.
1528 case ItemPositionEnd:
1529 return GridAxisEnd;
1530 case ItemPositionStretch:
1531 return GridAxisStart;
1532 case ItemPositionBaseline:
1533 case ItemPositionLastBaseline:
1534 // FIXME: Implement the previous values. For now, we always 'start' alig n the child.
1535 return GridAxisStart;
1536 case ItemPositionAuto:
1537 break;
1538 }
1539
1540 ASSERT_NOT_REACHED();
1541 return GridAxisStart;
1542 }
1543
1595 LayoutUnit LayoutGrid::rowPositionForChild(const LayoutBox& child) const 1544 LayoutUnit LayoutGrid::rowPositionForChild(const LayoutBox& child) const
1596 { 1545 {
1597 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 1546 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1598 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { 1547 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()];
1599 case ItemPositionSelfStart: 1548 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()];
1600 // If orthogonal writing-modes, this computes to 'start'. 1549 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child);
1601 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. 1550 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.st yleRef().justifySelfOverflowAlignment(), endOfRow - startOfRow, child.logicalHei ght() + child.marginLogicalHeight());
1602 if (hasOrthogonalWritingMode)
1603 return startOfRowForChild(child);
1604 1551
1605 // self-start is based on the child's block axis direction. That's why w e need to check against the grid container's block flow. 1552 switch (columnAxisPositionForChild(child)) {
1606 if (child.style()->writingMode() != style()->writingMode()) 1553 case GridAxisStart:
1607 return endOfRowForChild(child); 1554 return startPosition;
1608 1555 case GridAxisEnd:
1609 return startOfRowForChild(child); 1556 return startPosition + offsetFromStartPosition;
1610 case ItemPositionSelfEnd: 1557 case GridAxisCenter:
1611 // If orthogonal writing-modes, this computes to 'end'. 1558 return startPosition + offsetFromStartPosition / 2;
1612 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1613 if (hasOrthogonalWritingMode)
1614 return endOfRowForChild(child);
1615
1616 // self-end is based on the child's block axis direction. That's why we need to check against the grid container's block flow.
1617 if (child.style()->writingMode() != style()->writingMode())
1618 return startOfRowForChild(child);
1619
1620 return endOfRowForChild(child);
1621 case ItemPositionLeft:
1622 // The alignment axis (column axis) and the inline axis are parallell in
1623 // orthogonal writing mode.
1624 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1625 if (hasOrthogonalWritingMode)
1626 return startOfRowForChild(child);
1627
1628 // Otherwise this this is equivalent to 'start'.
1629 return startOfRowForChild(child);
1630 case ItemPositionRight:
1631 // The alignment axis (column axis) and the inline axis are parallell in
1632 // orthogonal writing mode.
1633 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1634 if (hasOrthogonalWritingMode)
1635 return endOfRowForChild(child);
1636
1637 // Otherwise this this is equivalent to 'start'.
1638 return startOfRowForChild(child);
1639 case ItemPositionCenter:
1640 return centeredRowPositionForChild(child);
1641 // Only used in flex layout, for other layout, it's equivalent to 'start '.
1642 case ItemPositionFlexStart:
1643 case ItemPositionStart:
1644 return startOfRowForChild(child);
1645 // Only used in flex layout, for other layout, it's equivalent to 'end'.
1646 case ItemPositionFlexEnd:
1647 case ItemPositionEnd:
1648 return endOfRowForChild(child);
1649 case ItemPositionStretch:
1650 return startOfRowForChild(child);
1651 case ItemPositionBaseline:
1652 case ItemPositionLastBaseline:
1653 // FIXME: Implement the ItemPositionBaseline value. For now, we always ' start' align the child.
1654 return startOfRowForChild(child);
1655 case ItemPositionAuto:
1656 break;
1657 } 1559 }
1658 1560
1659 ASSERT_NOT_REACHED(); 1561 ASSERT_NOT_REACHED();
1660 return 0; 1562 return 0;
1661 } 1563 }
1662 1564
1565 LayoutUnit LayoutGrid::columnPositionForChild(const LayoutBox& child) const
1566 {
1567 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1568 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit ialPosition.toInt()];
1569 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP osition.next().toInt()];
1570 LayoutUnit startPosition = startOfColumn + marginStartForChild(child);
1571 // FIXME: This should account for the grid item's <overflow-position>.
1572 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.st yleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, child.logi calWidth() + child.marginLogicalWidth());
1573
1574 switch (rowAxisPositionForChild(child)) {
1575 case GridAxisStart:
1576 return startPosition;
1577 case GridAxisEnd:
1578 return startPosition + offsetFromStartPosition;
1579 case GridAxisCenter:
1580 return startPosition + offsetFromStartPosition / 2;
1581 }
1582
1583 ASSERT_NOT_REACHED();
1584 return 0;
1585 }
svillar 2015/06/10 08:27:20 Looks like we could even apply a further refactori
jfernandez 2015/06/11 12:00:31 Yeah, I already considered that idea and actually
1586
1663 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution) 1587 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution)
1664 { 1588 {
1665 switch (distribution) { 1589 switch (distribution) {
1666 case ContentDistributionSpaceBetween: 1590 case ContentDistributionSpaceBetween:
1667 return ContentPositionStart; 1591 return ContentPositionStart;
1668 case ContentDistributionSpaceAround: 1592 case ContentDistributionSpaceAround:
1669 return ContentPositionCenter; 1593 return ContentPositionCenter;
1670 case ContentDistributionSpaceEvenly: 1594 case ContentDistributionSpaceEvenly:
1671 return ContentPositionCenter; 1595 return ContentPositionCenter;
1672 case ContentDistributionStretch: 1596 case ContentDistributionStretch:
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 1757
1834 return LayoutPoint(columnPosition, rowPositionForChild(child)); 1758 return LayoutPoint(columnPosition, rowPositionForChild(child));
1835 } 1759 }
1836 1760
1837 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 1761 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
1838 { 1762 {
1839 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1763 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1840 } 1764 }
1841 1765
1842 } // namespace blink 1766 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698