Chromium Code Reviews| 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 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 | 1300 |
| 1301 // Provided the grid container does not have a definite size or max-size in the relevant axis, | 1301 // Provided the grid container does not have a definite size or max-size in the relevant axis, |
| 1302 // if the min size is definite then the number of repetitions is the largest possible positive | 1302 // if the min size is definite then the number of repetitions is the largest possible positive |
| 1303 // integer that fulfills that minimum requirement. | 1303 // integer that fulfills that minimum requirement. |
| 1304 if (needsToFulfillMinimumSize) | 1304 if (needsToFulfillMinimumSize) |
| 1305 ++repetitions; | 1305 ++repetitions; |
| 1306 | 1306 |
| 1307 return repetitions; | 1307 return repetitions; |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 std::unique_ptr<Vector<size_t>> LayoutGrid::computeEmptyTracksCountForAutoRepeat (GridTrackSizingDirection direction, size_t insertionPoint) const | |
| 1311 { | |
|
Manuel Rego
2016/06/21 21:57:38
I think we need a comment explaining what this met
svillar
2016/06/23 08:09:42
Acknowledged.
| |
| 1312 std::unique_ptr<Vector<size_t>> emptyTracksCounter; | |
| 1313 size_t repetitions = autoRepeatCountForDirection(direction); | |
| 1314 if (m_gridItemArea.isEmpty()) { | |
| 1315 emptyTracksCounter = wrapUnique(new Vector<size_t>(repetitions)); | |
| 1316 for (size_t i = 0; i < repetitions; i++) | |
| 1317 emptyTracksCounter->at(i) = i + 1; | |
| 1318 return emptyTracksCounter; | |
| 1319 } | |
| 1320 | |
| 1321 size_t emptyTracksCount = 0; | |
|
Manuel Rego
2016/06/21 21:57:37
emptyTracksCount and emptyTracksCounter in the ver
svillar
2016/06/23 08:09:42
I agree, I even had build issues because I was rep
| |
| 1322 size_t firstAutoRepeatTrack = insertionPoint + std::abs(direction == ForColu mns ? m_smallestColumnStart : m_smallestRowStart); | |
| 1323 size_t lastAutoRepeatTrack = firstAutoRepeatTrack + repetitions; | |
| 1324 for (size_t trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepeatTr ack; ++trackIndex) { | |
| 1325 GridIterator iterator(m_grid, direction, trackIndex); | |
| 1326 if (!iterator.nextGridItem()) | |
| 1327 ++emptyTracksCount; | |
| 1328 | |
| 1329 if (!emptyTracksCounter) | |
|
jfernandez
2016/06/21 07:40:26
Isn't this name a bit confusing ? I understood the
Manuel Rego
2016/06/21 21:57:37
Maybe we can rename emptyTracksCounter to droppedT
svillar
2016/06/23 08:09:42
OK
svillar
2016/06/23 08:09:42
Well it's a pointer that's the standard way to kno
svillar
2016/06/23 08:19:14
So the thing about your suggestion is that it is n
| |
| 1330 emptyTracksCounter = wrapUnique(new Vector<size_t>(repetitions)); | |
| 1331 emptyTracksCounter->at(trackIndex - firstAutoRepeatTrack) = emptyTracksC ount; | |
| 1332 } | |
| 1333 return emptyTracksCounter; | |
| 1334 } | |
| 1335 | |
| 1336 size_t LayoutGrid::droppedTracksBeforeLine(GridTrackSizingDirection direction, s ize_t line) const | |
| 1337 { | |
| 1338 bool isRowAxis = direction == ForColumns; | |
| 1339 auto* droppedTracksCounter = isRowAxis ? m_emptyColumnsCounter.get() : m_emp tyRowsCounter.get(); | |
| 1340 size_t smallestStart = abs(isRowAxis ? m_smallestColumnStart : m_smallestRow Start); | |
| 1341 size_t firstAutoRepeatTrack = (isRowAxis ? styleRef().gridAutoRepeatColumnsI nsertionPoint() : styleRef().gridAutoRepeatRowsInsertionPoint()) + smallestStart ; | |
| 1342 if (droppedTracksCounter && line > firstAutoRepeatTrack) { | |
| 1343 size_t lastAutoRepeatTrack = firstAutoRepeatTrack + droppedTracksCounter ->size(); | |
| 1344 size_t trackIndex = line - firstAutoRepeatTrack - 1; | |
| 1345 size_t droppedTracks = line < lastAutoRepeatTrack ? droppedTracksCounter ->at(trackIndex) : droppedTracksCounter->last(); | |
| 1346 DCHECK_GE(droppedTracksCounter->size(), droppedTracks); | |
| 1347 return droppedTracks; | |
| 1348 } | |
| 1349 return 0; | |
| 1350 } | |
| 1351 | |
| 1310 void LayoutGrid::placeItemsOnGrid() | 1352 void LayoutGrid::placeItemsOnGrid() |
| 1311 { | 1353 { |
| 1312 if (!m_gridIsDirty) | 1354 if (!m_gridIsDirty) |
| 1313 return; | 1355 return; |
| 1314 | 1356 |
| 1315 ASSERT(m_gridItemArea.isEmpty()); | 1357 ASSERT(m_gridItemArea.isEmpty()); |
| 1316 | 1358 |
| 1317 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); | 1359 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); |
| 1318 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); | 1360 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); |
| 1319 | 1361 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1347 } | 1389 } |
| 1348 | 1390 |
| 1349 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style (), m_autoRepeatRows)); | 1391 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style (), m_autoRepeatRows)); |
| 1350 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( *style(), m_autoRepeatColumns)); | 1392 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( *style(), m_autoRepeatColumns)); |
| 1351 | 1393 |
| 1352 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 1394 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 1353 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 1395 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 1354 | 1396 |
| 1355 m_grid.shrinkToFit(); | 1397 m_grid.shrinkToFit(); |
| 1356 | 1398 |
| 1399 /* auto-fit */ | |
|
Manuel Rego
2016/06/21 21:57:38
Nit: I would move this to a separated method,
it d
svillar
2016/06/23 08:09:42
I guess it's a matter of taste. I don't usually li
| |
| 1400 if (m_autoRepeatColumns && styleRef().gridAutoRepeatColumnsType() == AutoFit ) | |
| 1401 m_emptyColumnsCounter = computeEmptyTracksCountForAutoRepeat(ForColumns, styleRef().gridAutoRepeatColumnsInsertionPoint()); | |
| 1402 else | |
| 1403 m_emptyColumnsCounter = nullptr; | |
| 1404 | |
| 1405 if (m_autoRepeatRows && styleRef().gridAutoRepeatRowsType() == AutoFit) | |
| 1406 m_emptyRowsCounter = computeEmptyTracksCountForAutoRepeat(ForRows, style Ref().gridAutoRepeatRowsInsertionPoint()); | |
| 1407 else | |
| 1408 m_emptyRowsCounter = nullptr; | |
| 1409 | |
| 1410 if (m_emptyRowsCounter || m_emptyColumnsCounter) { | |
| 1411 for (auto* child = m_orderIterator.first(); child; child = m_orderIterat or.next()) { | |
| 1412 if (child->isOutOfFlowPositioned()) | |
| 1413 continue; | |
| 1414 | |
| 1415 GridArea area = cachedGridArea(*child); | |
| 1416 size_t droppedColumns = droppedTracksBeforeLine(ForColumns, area.col umns.startLine()); | |
| 1417 size_t droppedRows = droppedTracksBeforeLine(ForRows, area.rows.star tLine()); | |
| 1418 if (droppedColumns || droppedRows) { | |
| 1419 area.adjustForDroppedTracks(droppedColumns, droppedRows); | |
| 1420 m_gridItemArea.set(child, area); | |
| 1421 } | |
| 1422 } | |
| 1423 | |
| 1424 size_t droppedColumnsCount = m_emptyColumnsCounter ? m_emptyColumnsCount er->last() : 0; | |
| 1425 size_t droppedRowsCount = m_emptyRowsCounter ? m_emptyRowsCounter->last( ) : 0; | |
| 1426 DCHECK_GE(m_autoRepeatColumns, droppedColumnsCount); | |
| 1427 DCHECK_GE(m_autoRepeatRows, droppedRowsCount); | |
| 1428 | |
| 1429 m_autoRepeatColumns -= droppedColumnsCount; | |
| 1430 m_autoRepeatRows -= droppedRowsCount; | |
| 1431 | |
| 1432 m_grid.shrink(m_grid.size() - droppedRowsCount); | |
| 1433 for (auto& row : m_grid) | |
| 1434 row.shrink(row.size() - droppedColumnsCount); | |
| 1435 } | |
| 1436 | |
| 1357 #if ENABLE(ASSERT) | 1437 #if ENABLE(ASSERT) |
| 1358 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { | 1438 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { |
| 1359 if (child->isOutOfFlowPositioned()) | 1439 if (child->isOutOfFlowPositioned()) |
| 1360 continue; | 1440 continue; |
| 1361 | 1441 |
| 1362 GridArea area = cachedGridArea(*child); | 1442 GridArea area = cachedGridArea(*child); |
| 1363 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi nite()); | 1443 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi nite()); |
| 1364 } | 1444 } |
| 1365 #endif | 1445 #endif |
| 1366 } | 1446 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1693 bool isForColumns = direction == ForColumns; | 1773 bool isForColumns = direction == ForColumns; |
| 1694 | 1774 |
| 1695 GridSpan positions = GridPositionsResolver::resolveGridPositionsFromStyle(*s tyle(), child, direction, autoRepeatCountForDirection(direction)); | 1775 GridSpan positions = GridPositionsResolver::resolveGridPositionsFromStyle(*s tyle(), child, direction, autoRepeatCountForDirection(direction)); |
| 1696 if (positions.isIndefinite()) { | 1776 if (positions.isIndefinite()) { |
| 1697 offset = LayoutUnit(); | 1777 offset = LayoutUnit(); |
| 1698 breadth = isForColumns ? clientLogicalWidth() : clientLogicalHeight(); | 1778 breadth = isForColumns ? clientLogicalWidth() : clientLogicalHeight(); |
| 1699 return; | 1779 return; |
| 1700 } | 1780 } |
| 1701 | 1781 |
| 1702 // For positioned items we cannot use GridSpan::translate(). Because we coul d end up with negative values, as the positioned items do not create implicit tr acks per spec. | 1782 // For positioned items we cannot use GridSpan::translate(). Because we coul d end up with negative values, as the positioned items do not create implicit tr acks per spec. |
| 1703 int smallestStart = abs(isForColumns ? m_smallestColumnStart : m_smallestRow Start); | 1783 size_t smallestStart = abs(isForColumns ? m_smallestColumnStart : m_smallest RowStart); |
| 1704 int startLine = positions.untranslatedStartLine() + smallestStart; | 1784 int startLine = positions.untranslatedStartLine() + smallestStart; |
| 1705 int endLine = positions.untranslatedEndLine() + smallestStart; | 1785 int endLine = positions.untranslatedEndLine() + smallestStart; |
| 1706 | 1786 |
| 1707 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() : child.style()->gridRowStart(); | 1787 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() : child.style()->gridRowStart(); |
| 1708 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() : c hild.style()->gridRowEnd(); | 1788 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() : c hild.style()->gridRowEnd(); |
| 1709 int lastLine = isForColumns ? gridColumnCount() : gridRowCount(); | 1789 int lastLine = isForColumns ? gridColumnCount() : gridRowCount(); |
| 1710 | 1790 |
| 1711 bool startIsAuto = startPosition.isAuto() | 1791 bool startIsAuto = startPosition.isAuto() |
| 1712 || (startPosition.isNamedGridArea() && !NamedLineCollection::isValidName dLineOrArea(startPosition.namedGridLine(), styleRef(), GridPositionsResolver::in itialPositionSide(direction))) | 1792 || (startPosition.isNamedGridArea() && !NamedLineCollection::isValidName dLineOrArea(startPosition.namedGridLine(), styleRef(), GridPositionsResolver::in itialPositionSide(direction))) |
| 1713 || (startLine < 0) | 1793 || (startLine < 0) |
| 1714 || (startLine > lastLine); | 1794 || (startLine > lastLine); |
| 1715 bool endIsAuto = endPosition.isAuto() | 1795 bool endIsAuto = endPosition.isAuto() |
| 1716 || (endPosition.isNamedGridArea() && !NamedLineCollection::isValidNamedL ineOrArea(endPosition.namedGridLine(), styleRef(), GridPositionsResolver::finalP ositionSide(direction))) | 1796 || (endPosition.isNamedGridArea() && !NamedLineCollection::isValidNamedL ineOrArea(endPosition.namedGridLine(), styleRef(), GridPositionsResolver::finalP ositionSide(direction))) |
| 1717 || (endLine < 0) | 1797 || (endLine < 0) |
| 1718 || (endLine > lastLine); | 1798 || (endLine > lastLine); |
| 1719 | 1799 |
| 1720 LayoutUnit start; | 1800 LayoutUnit start; |
| 1721 if (!startIsAuto) { | 1801 if (!startIsAuto) { |
| 1802 startLine -= droppedTracksBeforeLine(direction, startLine); | |
| 1803 DCHECK_GE(startLine, 0); | |
| 1804 | |
| 1722 if (isForColumns) { | 1805 if (isForColumns) { |
| 1723 if (styleRef().isLeftToRightDirection()) | 1806 if (styleRef().isLeftToRightDirection()) |
| 1724 start = m_columnPositions[startLine] - borderLogicalLeft(); | 1807 start = m_columnPositions[startLine] - borderLogicalLeft(); |
| 1725 else | 1808 else |
| 1726 start = logicalWidth() - translateRTLCoordinate(m_columnPosition s[startLine]) - borderLogicalRight(); | 1809 start = logicalWidth() - translateRTLCoordinate(m_columnPosition s[startLine]) - borderLogicalRight(); |
| 1727 } else { | 1810 } else { |
| 1728 start = m_rowPositions[startLine] - borderBefore(); | 1811 start = m_rowPositions[startLine] - borderBefore(); |
| 1729 } | 1812 } |
| 1730 } | 1813 } |
| 1731 | 1814 |
| 1732 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight() ; | 1815 LayoutUnit end = isForColumns ? clientLogicalWidth() : clientLogicalHeight() ; |
| 1733 if (!endIsAuto) { | 1816 if (!endIsAuto) { |
| 1817 endLine -= droppedTracksBeforeLine(direction, endLine); | |
| 1818 DCHECK_GE(endLine, 0); | |
| 1819 | |
| 1734 if (isForColumns) { | 1820 if (isForColumns) { |
| 1735 if (styleRef().isLeftToRightDirection()) | 1821 if (styleRef().isLeftToRightDirection()) |
| 1736 end = m_columnPositions[endLine] - borderLogicalLeft(); | 1822 end = m_columnPositions[endLine] - borderLogicalLeft(); |
| 1737 else | 1823 else |
| 1738 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight(); | 1824 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[ endLine]) - borderLogicalRight(); |
| 1739 } else { | 1825 } else { |
| 1740 end = m_rowPositions[endLine] - borderBefore(); | 1826 end = m_rowPositions[endLine] - borderBefore(); |
| 1741 } | 1827 } |
| 1742 | 1828 |
| 1743 // These vectors store line positions including gaps, but we shouldn't c onsider them for the edges of the grid. | 1829 // These vectors store line positions including gaps, but we shouldn't c onsider them for the edges of the grid. |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2251 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); | 2337 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); |
| 2252 } | 2338 } |
| 2253 | 2339 |
| 2254 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2340 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
| 2255 { | 2341 { |
| 2256 if (!m_gridItemArea.isEmpty()) | 2342 if (!m_gridItemArea.isEmpty()) |
| 2257 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2343 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2258 } | 2344 } |
| 2259 | 2345 |
| 2260 } // namespace blink | 2346 } // namespace blink |
| OLD | NEW |