std::unique_ptr<GridSpan> GridResolvedPosition::resolveRowStartColumnStartNamedGridLinePositionAgainstOppositePosition(const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines) { size_t gridLineIndex = std::max<int>(0, firstNamedGridLineBeforePosition(resolvedOppositePosition.toInt(), gridLines) - position.spanPosition() + 1); GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(gridLines[gridLineIndex]); if (resolvedGridLinePosition > resolvedOppositePosition) resolvedGridLinePosition = resolvedOppositePosition; return std::make_unique<GridSpan>(resolvedGridLinePosition, resolvedOppositePosition); }
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); }
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); }
GridSpan GridResolvedPosition::resolveNamedGridLinePositionAgainstOppositePosition(const ComputedStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) { ASSERT(position.isSpan()); ASSERT(!position.namedGridLine().isNull()); // Negative positions are not allowed per the specification and should have been handled during parsing. ASSERT(position.spanPosition() > 0); const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyle, side); NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGridLine()); // If there is no named grid line of that name, we resolve the position to 'auto' (which is equivalent to 'span 1' in this case). // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. if (it == gridLinesNames.end()) { if ((side == ColumnStartSide || side == RowStartSide) && resolvedOppositePosition.toInt()) return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), resolvedOppositePosition); return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppositePosition.next()); } return GridSpan::definiteGridSpanWithNamedSpanAgainstOpposite(resolvedOppositePosition, position, side, it->value); }