| OLD | NEW |
| 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 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight()
; | 1534 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight()
; |
| 1535 if (!endIsAuto) { | 1535 if (!endIsAuto) { |
| 1536 if (isForColumns) | 1536 if (isForColumns) |
| 1537 end = m_columnPositions[endLine] - m_columnPositions[0] + paddingSta
rt(); | 1537 end = m_columnPositions[endLine] - m_columnPositions[0] + paddingSta
rt(); |
| 1538 else | 1538 else |
| 1539 end = m_rowPositions[endLine] - m_rowPositions[0] + paddingBefore(); | 1539 end = m_rowPositions[endLine] - m_rowPositions[0] + paddingBefore(); |
| 1540 | 1540 |
| 1541 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. | 1541 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. |
| 1542 if (endLine > firstExplicitLine && endLine < lastExplicitLine) | 1542 if (endLine > firstExplicitLine && endLine < lastExplicitLine) { |
| 1543 end -= guttersSize(direction, 2); | 1543 end -= guttersSize(direction, 2); |
| 1544 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 1545 } |
| 1544 } | 1546 } |
| 1545 | 1547 |
| 1548 LayoutUnit alignmentOffset = isForColumns ? m_columnPositions[0] - borderAnd
PaddingStart() : m_rowPositions[0] - borderAndPaddingBefore(); |
| 1549 if (isForColumns && !styleRef().isLeftToRightDirection()) |
| 1550 alignmentOffset = contentLogicalWidth() - (m_columnPositions[m_columnPos
itions.size() - 1] - borderAndPaddingStart()); |
| 1551 |
| 1552 if (!startIsAuto) |
| 1553 start += alignmentOffset; |
| 1554 if (!endIsAuto) |
| 1555 end += alignmentOffset; |
| 1556 |
| 1546 breadth = end - start; | 1557 breadth = end - start; |
| 1547 offset = start; | 1558 offset = start; |
| 1548 | 1559 |
| 1549 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { | 1560 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { |
| 1550 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", | 1561 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", |
| 1551 // we need to calculate the offset from the left (even if we're in RTL). | 1562 // we need to calculate the offset from the left (even if we're in RTL). |
| 1552 if (endIsAuto) { | 1563 if (endIsAuto) { |
| 1553 offset = LayoutUnit(); | 1564 offset = LayoutUnit(); |
| 1554 } else { | 1565 } else { |
| 1555 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddin
gStart(); | 1566 alignmentOffset = m_columnPositions[0] - borderAndPaddingStart(); |
| 1556 LayoutUnit offsetFromLastLine = m_columnPositions[m_columnPositions.
size() - 1] - m_columnPositions[endLine]; | 1567 LayoutUnit offsetFromLastLine = m_columnPositions[m_columnPositions.
size() - 1] - m_columnPositions[endLine]; |
| 1557 offset = paddingLeft() + alignmentOffset + offsetFromLastLine; | 1568 offset = paddingLeft() + alignmentOffset + offsetFromLastLine; |
| 1558 | 1569 |
| 1559 if (endLine > firstExplicitLine && endLine < lastExplicitLine) | 1570 if (endLine > firstExplicitLine && endLine < lastExplicitLine) { |
| 1560 offset += guttersSize(direction, 2); | 1571 offset += guttersSize(direction, 2); |
| 1572 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee
nRows; |
| 1573 } |
| 1561 } | 1574 } |
| 1562 } | 1575 } |
| 1563 | 1576 |
| 1564 if (child.parent() == this && !startIsAuto) { | 1577 if (child.parent() == this && !startIsAuto) { |
| 1565 // If column/row start is "auto" the static position has been already se
t in prepareChildForPositionedLayout(). | 1578 // If column/row start is "auto" the static position has been already se
t in prepareChildForPositionedLayout(). |
| 1566 PaintLayer* childLayer = child.layer(); | 1579 PaintLayer* childLayer = child.layer(); |
| 1567 if (isForColumns) | 1580 if (isForColumns) |
| 1568 childLayer->setStaticInlinePosition(borderStart() + offset); | 1581 childLayer->setStaticInlinePosition(borderStart() + offset); |
| 1569 else | 1582 else |
| 1570 childLayer->setStaticBlockPosition(borderBefore() + offset); | 1583 childLayer->setStaticBlockPosition(borderBefore() + offset); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 unsigned numberOfLines = numberOfTracks + 1; | 1633 unsigned numberOfLines = numberOfTracks + 1; |
| 1621 unsigned lastLine = numberOfLines - 1; | 1634 unsigned lastLine = numberOfLines - 1; |
| 1622 unsigned nextToLastLine = numberOfLines - 2; | 1635 unsigned nextToLastLine = numberOfLines - 2; |
| 1623 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(Fo
rColumns, sizingData.freeSpaceForDirection(ForColumns), numberOfTracks); | 1636 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(Fo
rColumns, sizingData.freeSpaceForDirection(ForColumns), numberOfTracks); |
| 1624 LayoutUnit trackGap = guttersSize(ForColumns, 2); | 1637 LayoutUnit trackGap = guttersSize(ForColumns, 2); |
| 1625 m_columnPositions.resize(numberOfLines); | 1638 m_columnPositions.resize(numberOfLines); |
| 1626 m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset; | 1639 m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset; |
| 1627 for (unsigned i = 0; i < lastLine; ++i) | 1640 for (unsigned i = 0; i < lastLine; ++i) |
| 1628 m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOff
set + sizingData.columnTracks[i].baseSize() + trackGap; | 1641 m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOff
set + sizingData.columnTracks[i].baseSize() + trackGap; |
| 1629 m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData
.columnTracks[nextToLastLine].baseSize(); | 1642 m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData
.columnTracks[nextToLastLine].baseSize(); |
| 1643 m_offsetBetweenColumns = offset.distributionOffset; |
| 1630 | 1644 |
| 1631 numberOfTracks = sizingData.rowTracks.size(); | 1645 numberOfTracks = sizingData.rowTracks.size(); |
| 1632 numberOfLines = numberOfTracks + 1; | 1646 numberOfLines = numberOfTracks + 1; |
| 1633 lastLine = numberOfLines - 1; | 1647 lastLine = numberOfLines - 1; |
| 1634 nextToLastLine = numberOfLines - 2; | 1648 nextToLastLine = numberOfLines - 2; |
| 1635 offset = computeContentPositionAndDistributionOffset(ForRows, sizingData.fre
eSpaceForDirection(ForRows), numberOfTracks); | 1649 offset = computeContentPositionAndDistributionOffset(ForRows, sizingData.fre
eSpaceForDirection(ForRows), numberOfTracks); |
| 1636 trackGap = guttersSize(ForRows, 2); | 1650 trackGap = guttersSize(ForRows, 2); |
| 1637 m_rowPositions.resize(numberOfLines); | 1651 m_rowPositions.resize(numberOfLines); |
| 1638 m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset; | 1652 m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset; |
| 1639 for (unsigned i = 0; i < lastLine; ++i) | 1653 for (unsigned i = 0; i < lastLine; ++i) |
| 1640 m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset +
sizingData.rowTracks[i].baseSize() + trackGap; | 1654 m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset +
sizingData.rowTracks[i].baseSize() + trackGap; |
| 1641 m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTr
acks[nextToLastLine].baseSize(); | 1655 m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTr
acks[nextToLastLine].baseSize(); |
| 1656 m_offsetBetweenRows = offset.distributionOffset; |
| 1642 } | 1657 } |
| 1643 | 1658 |
| 1644 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackBreadth, LayoutUnit childBreadth) | 1659 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackBreadth, LayoutUnit childBreadth) |
| 1645 { | 1660 { |
| 1646 LayoutUnit offset = trackBreadth - childBreadth; | 1661 LayoutUnit offset = trackBreadth - childBreadth; |
| 1647 switch (overflow) { | 1662 switch (overflow) { |
| 1648 case OverflowAlignmentSafe: | 1663 case OverflowAlignmentSafe: |
| 1649 // If overflow is 'safe', we have to make sure we don't overflow the 'st
art' | 1664 // If overflow is 'safe', we have to make sure we don't overflow the 'st
art' |
| 1650 // edge (potentially cause some data loss as the overflow is unreachable
). | 1665 // edge (potentially cause some data loss as the overflow is unreachable
). |
| 1651 return offset.clampNegativeToZero(); | 1666 return offset.clampNegativeToZero(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 // crbug.com/234191 | 1874 // crbug.com/234191 |
| 1860 return GridAxisStart; | 1875 return GridAxisStart; |
| 1861 case ItemPositionAuto: | 1876 case ItemPositionAuto: |
| 1862 break; | 1877 break; |
| 1863 } | 1878 } |
| 1864 | 1879 |
| 1865 ASSERT_NOT_REACHED(); | 1880 ASSERT_NOT_REACHED(); |
| 1866 return GridAxisStart; | 1881 return GridAxisStart; |
| 1867 } | 1882 } |
| 1868 | 1883 |
| 1869 static inline LayoutUnit offsetBetweenTracks(ContentDistributionType distributio
n, const Vector<GridTrack>& trackSizes, const Vector<LayoutUnit>& trackPositions
, LayoutUnit trackGap) | |
| 1870 { | |
| 1871 // FIXME: Perhaps a good idea to cache the result of this operation, since t
he ContentDistribution offset between tracks is always the same, | |
| 1872 return (distribution == ContentDistributionStretch || distribution == Conten
tDistributionDefault) ? LayoutUnit() : trackPositions[1] - trackPositions[0] - t
rackSizes[0].baseSize() - trackGap; | |
| 1873 } | |
| 1874 | |
| 1875 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child, GridSizi
ngData& sizingData) const | 1884 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child, GridSizi
ngData& sizingData) const |
| 1876 { | 1885 { |
| 1877 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); | 1886 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); |
| 1878 size_t childStartLine = rowsSpan.startLine(); | 1887 size_t childStartLine = rowsSpan.startLine(); |
| 1879 LayoutUnit startOfRow = m_rowPositions[childStartLine]; | 1888 LayoutUnit startOfRow = m_rowPositions[childStartLine]; |
| 1880 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); | 1889 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); |
| 1881 if (hasAutoMarginsInColumnAxis(child)) | 1890 if (hasAutoMarginsInColumnAxis(child)) |
| 1882 return startPosition; | 1891 return startPosition; |
| 1883 GridAxisPosition axisPosition = columnAxisPositionForChild(child); | 1892 GridAxisPosition axisPosition = columnAxisPositionForChild(child); |
| 1884 switch (axisPosition) { | 1893 switch (axisPosition) { |
| 1885 case GridAxisStart: | 1894 case GridAxisStart: |
| 1886 return startPosition; | 1895 return startPosition; |
| 1887 case GridAxisEnd: | 1896 case GridAxisEnd: |
| 1888 case GridAxisCenter: { | 1897 case GridAxisCenter: { |
| 1889 size_t childEndLine = rowsSpan.endLine(); | 1898 size_t childEndLine = rowsSpan.endLine(); |
| 1890 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 1899 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
| 1891 // m_rowPositions include gutters so we need to subtract them to get the
actual end position for a given | 1900 // m_rowPositions include gutters so we need to subtract them to get the
actual end position for a given |
| 1892 // row (this does not have to be done for the last track as there are no
more m_rowPositions after it) | 1901 // row (this does not have to be done for the last track as there are no
more m_rowPositions after it) |
| 1893 LayoutUnit trackGap = guttersSize(ForRows, 2); | 1902 LayoutUnit trackGap = guttersSize(ForRows, 2); |
| 1894 if (childEndLine < m_rowPositions.size() - 1) | 1903 if (childEndLine < m_rowPositions.size() - 1) |
| 1895 endOfRow -= trackGap; | 1904 endOfRow -= trackGap; |
| 1896 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); | 1905 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); |
| 1897 // The track's start and end lines may be not adjacent because of conten
t alignment, so we assume the stored | 1906 // The track's start and end lines may be not adjacent because of conten
t alignment, so we assume the stored |
| 1898 // lines are all start plus a content-alignment distribution offset. | 1907 // lines are all start plus a content-alignment distribution offset. |
| 1899 // We must subtract last line's offset because is not part of the track
the items belongs to. | 1908 // We must subtract last line's offset because is not part of the track
the items belongs to. |
| 1900 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s
ize() - 1) | 1909 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s
ize() - 1) |
| 1901 endOfRow -= offsetBetweenTracks(styleRef().resolvedAlignContentDistr
ibution(normalValueBehavior()), sizingData.rowTracks, m_rowPositions, trackGap); | 1910 endOfRow -= m_offsetBetweenRows; |
| 1902 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); | 1911 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); |
| 1903 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, childBreadth); | 1912 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, childBreadth); |
| 1904 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 1913 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| 1905 } | 1914 } |
| 1906 } | 1915 } |
| 1907 | 1916 |
| 1908 ASSERT_NOT_REACHED(); | 1917 ASSERT_NOT_REACHED(); |
| 1909 return LayoutUnit(); | 1918 return LayoutUnit(); |
| 1910 } | 1919 } |
| 1911 | 1920 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1928 // m_columnPositions include gutters so we need to subtract them to get
the actual end position for a given | 1937 // m_columnPositions include gutters so we need to subtract them to get
the actual end position for a given |
| 1929 // column (this does not have to be done for the last track as there are
no more m_columnPositions after it) | 1938 // column (this does not have to be done for the last track as there are
no more m_columnPositions after it) |
| 1930 LayoutUnit trackGap = guttersSize(ForColumns, 2); | 1939 LayoutUnit trackGap = guttersSize(ForColumns, 2); |
| 1931 if (childEndLine < m_columnPositions.size() - 1) | 1940 if (childEndLine < m_columnPositions.size() - 1) |
| 1932 endOfColumn -= trackGap; | 1941 endOfColumn -= trackGap; |
| 1933 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); | 1942 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); |
| 1934 // The track's start and end lines may be not adjacent because of conten
t alignment, so we assume the stored | 1943 // The track's start and end lines may be not adjacent because of conten
t alignment, so we assume the stored |
| 1935 // lines are all start plus a content-alignment distribution offset. | 1944 // lines are all start plus a content-alignment distribution offset. |
| 1936 // We must subtract last line's offset because is not part of the track
the items belongs to. | 1945 // We must subtract last line's offset because is not part of the track
the items belongs to. |
| 1937 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition
s.size() - 1) | 1946 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition
s.size() - 1) |
| 1938 endOfColumn -= offsetBetweenTracks(styleRef().resolvedJustifyContent
Distribution(normalValueBehavior()), sizingData.columnTracks, m_columnPositions,
trackGap); | 1947 endOfColumn -= m_offsetBetweenColumns; |
| 1939 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); | 1948 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); |
| 1940 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 1949 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| 1941 } | 1950 } |
| 1942 } | 1951 } |
| 1943 | 1952 |
| 1944 ASSERT_NOT_REACHED(); | 1953 ASSERT_NOT_REACHED(); |
| 1945 return LayoutUnit(); | 1954 return LayoutUnit(); |
| 1946 } | 1955 } |
| 1947 | 1956 |
| 1948 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp
e distribution) | 1957 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp
e distribution) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 | 2068 |
| 2060 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData
)); | 2069 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData
)); |
| 2061 } | 2070 } |
| 2062 | 2071 |
| 2063 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2072 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
| 2064 { | 2073 { |
| 2065 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2074 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2066 } | 2075 } |
| 2067 | 2076 |
| 2068 } // namespace blink | 2077 } // namespace blink |
| OLD | NEW |