static void adjustGridPositionsFromStyle(const RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection direction, GridPosition& initialPosition, GridPosition& finalPosition) { bool isForColumns = direction == ForColumns; initialPosition = isForColumns ? gridItem.style().gridItemColumnStart() : gridItem.style().gridItemRowStart(); finalPosition = isForColumns ? gridItem.style().gridItemColumnEnd() : gridItem.style().gridItemRowEnd(); // We must handle the placement error handling code here instead of in the StyleAdjuster because we don't want to // overwrite the specified values. if (initialPosition.isSpan() && finalPosition.isSpan()) finalPosition.setAutoPosition(); if (gridItem.isOutOfFlowPositioned()) { // Early detect the case of non existing named grid lines for positioned items. if (initialPosition.isNamedGridArea() && !NamedLineCollection::isValidNamedLineOrArea(initialPosition.namedGridLine(), gridContainerStyle, initialPositionSide(direction))) initialPosition.setAutoPosition(); if (finalPosition.isNamedGridArea() && !NamedLineCollection::isValidNamedLineOrArea(finalPosition.namedGridLine(), gridContainerStyle, finalPositionSide(direction))) finalPosition.setAutoPosition(); } // If the grid item has an automatic position and a grid span for a named line in a given dimension, instead treat the grid span as one. if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.namedGridLine().isNull()) finalPosition.setSpanPosition(1, String()); if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.namedGridLine().isNull()) initialPosition.setSpanPosition(1, String()); }
void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection direction, GridPosition& initialPosition, GridPosition& finalPosition) { initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnStart() : gridItem.style()->gridRowStart(); finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd() : gridItem.style()->gridRowEnd(); GridPositionSide initialPositionSide = calculateInitialPositionSide(direction); GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); // We must handle the placement error handling code here instead of in the StyleAdjuster because we don't want to // overwrite the specified values. if (initialPosition.isSpan() && finalPosition.isSpan()) finalPosition.setAutoPosition(); // Try to early detect the case of non existing named grid lines. This way we could assume later that // GridResolvedPosition::resolveGrisPositionFromStyle() always return a valid resolved position. if (initialPosition.isNamedGridArea() && !isValidNamedLineOrArea(initialPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) initialPosition.setAutoPosition(); if (finalPosition.isNamedGridArea() && !isValidNamedLineOrArea(finalPosition.namedGridLine(), gridContainerStyle, finalPositionSide)) finalPosition.setAutoPosition(); // If the grid item has an automatic position and a grid span for a named line in a given dimension, instead treat the grid span as one. if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.namedGridLine().isNull()) finalPosition.setSpanPosition(1, String()); if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.namedGridLine().isNull()) initialPosition.setSpanPosition(1, String()); }
void GridResolvedPosition::adjustGridPositionsFromStyle(const RenderStyle& gridContainerStyle, GridPosition& initialPosition, GridPosition& finalPosition, GridPositionSide initialPositionSide, GridPositionSide finalPositionSide) { ASSERT(isColumnSide(initialPositionSide) == isColumnSide(finalPositionSide)); // We must handle the placement error handling code here instead of in the StyleAdjuster because we don't want to // overwrite the specified values. if (initialPosition.isSpan() && finalPosition.isSpan()) finalPosition.setAutoPosition(); // Try to early detect the case of non existing named grid lines. This way we could assume later that // GridResolvedPosition::resolveGrisPositionFromStyle() won't require the autoplacement to run, i.e., it'll always return a // valid resolved position. if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initialPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) initialPosition.setAutoPosition(); if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPosition.namedGridLine(), gridContainerStyle, finalPositionSide)) finalPosition.setAutoPosition(); // If the grid item has an automatic position and a grid span for a named line in a given dimension, instead treat the grid span as one. if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.namedGridLine().isNull()) finalPosition.setSpanPosition(1, String()); if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.namedGridLine().isNull()) initialPosition.setSpanPosition(1, String()); }
PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) { if (position.isAuto()) return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition); ASSERT(position.isSpan()); ASSERT(position.spanPosition() > 0); if (!position.namedGridLine().isNull()) { // span 2 'c' -> we need to find the appropriate grid line before / after our opposite position. return resolveNamedGridLinePositionAgainstOppositePosition(gridContainerStyle, resolvedOppositePosition, position, side); } return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, position, side); }
GridSpan GridResolvedPosition::resolveGridPositionAgainstOppositePosition(const ComputedStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) { if (position.isAuto()) { if ((side == ColumnStartSide || side == RowStartSide) && resolvedOppositePosition.toInt()) return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), resolvedOppositePosition); return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppositePosition.next()); } ASSERT(position.isSpan()); ASSERT(position.spanPosition() > 0); if (!position.namedGridLine().isNull()) { // span 2 'c' -> we need to find the appropriate grid line before / after our opposite position. return resolveNamedGridLinePositionAgainstOppositePosition(gridContainerStyle, resolvedOppositePosition, position, side); } return GridSpan::definiteGridSpanWithSpanAgainstOpposite(resolvedOppositePosition, position, side); }
std::unique_ptr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) { if (position.isAuto()) return std::make_unique<GridSpan>(resolvedOppositePosition, resolvedOppositePosition); ASSERT(position.isSpan()); ASSERT(position.spanPosition() > 0); if (!position.namedGridLine().isNull()) { // span 2 'c' -> we need to find the appropriate grid line before / after our opposite position. return resolveNamedGridLinePositionAgainstOppositePosition(gridContainerStyle, resolvedOppositePosition, position, side); } // 'span 1' is contained inside a single grid track regardless of the direction. // That's why the CSS span value is one more than the offset we apply. size_t positionOffset = position.spanPosition() - 1; if (isStartSide(side)) { size_t initialResolvedPosition = std::max<int>(0, resolvedOppositePosition.toInt() - positionOffset); return std::make_unique<GridSpan>(initialResolvedPosition, resolvedOppositePosition); } return std::make_unique<GridSpan>(resolvedOppositePosition, resolvedOppositePosition.toInt() + positionOffset); }
static GridSpan resolveGridPositionAgainstOppositePosition(const RenderStyle& gridContainerStyle, int oppositeLine, const GridPosition& position, GridPositionSide side, unsigned autoRepeatTracksCount) { if (position.isAuto()) { if (isStartSide(side)) return GridSpan::untranslatedDefiniteGridSpan(oppositeLine - 1, oppositeLine); return GridSpan::untranslatedDefiniteGridSpan(oppositeLine, oppositeLine + 1); } ASSERT(position.isSpan()); ASSERT(position.spanPosition() > 0); if (!position.namedGridLine().isNull()) { // span 2 'c' -> we need to find the appropriate grid line before / after our opposite position. return resolveNamedGridLinePositionAgainstOppositePosition(gridContainerStyle, oppositeLine, position, side, autoRepeatTracksCount); } // 'span 1' is contained inside a single grid track regardless of the direction. // That's why the CSS span value is one more than the offset we apply. unsigned positionOffset = position.spanPosition(); if (isStartSide(side)) return GridSpan::untranslatedDefiniteGridSpan(oppositeLine - positionOffset, oppositeLine); return GridSpan::untranslatedDefiniteGridSpan(oppositeLine, oppositeLine + positionOffset); }