mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-26 00:17:47 -10:00
Bug 1144096 part 1 - [css-grid] Refactor nsGridContainerFrame state and methods. r=dholbert
This commit is contained in:
1 parent
e574cf77b6
commit
3513ad82e6
2 files changed
+568
-548
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -130,6 +130,7 @@ protected:
|
||||
typedef mozilla::css::GridNamedArea GridNamedArea;
|
||||
typedef nsLayoutUtils::IntrinsicISizeType IntrinsicISizeType;
|
||||
class GridItemCSSOrderIterator;
|
||||
struct Grid;
|
||||
struct TrackSizingFunctions;
|
||||
struct Tracks;
|
||||
struct GridReflowState;
|
||||
@@ -328,48 +329,6 @@ protected:
|
||||
LineRange mRows;
|
||||
};
|
||||
|
||||
/**
|
||||
* A CellMap holds state for each cell in the grid.
|
||||
* It's row major. It's sparse in the sense that it only has enough rows to
|
||||
* cover the last row that has a grid item. Each row only has enough entries
|
||||
* to cover columns that are occupied *on that row*, i.e. it's not a full
|
||||
* matrix covering the entire implicit grid. An absent Cell means that it's
|
||||
* unoccupied by any grid item.
|
||||
*/
|
||||
struct CellMap {
|
||||
struct Cell {
|
||||
Cell() : mIsOccupied(false) {}
|
||||
bool mIsOccupied : 1;
|
||||
};
|
||||
void Fill(const GridArea& aGridArea);
|
||||
void ClearOccupied();
|
||||
uint32_t IsEmptyCol(uint32_t aCol) const
|
||||
{
|
||||
for (auto& row : mCells) {
|
||||
if (aCol < row.Length() && row[aCol].mIsOccupied) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
uint32_t IsEmptyRow(uint32_t aRow) const
|
||||
{
|
||||
if (aRow >= mCells.Length()) {
|
||||
return true;
|
||||
}
|
||||
for (const Cell& cell : mCells[aRow]) {
|
||||
if (cell.mIsOccupied) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#if DEBUG
|
||||
void Dump() const;
|
||||
#endif
|
||||
nsTArray<nsTArray<Cell>> mCells;
|
||||
};
|
||||
|
||||
struct GridItemInfo {
|
||||
explicit GridItemInfo(const GridArea& aArea)
|
||||
: mArea(aArea)
|
||||
@@ -387,210 +346,6 @@ protected:
|
||||
#endif
|
||||
};
|
||||
|
||||
enum LineRangeSide {
|
||||
eLineRangeSideStart, eLineRangeSideEnd
|
||||
};
|
||||
/**
|
||||
* Return a line number for (non-auto) aLine, per:
|
||||
* http://dev.w3.org/csswg/css-grid/#line-placement
|
||||
* @param aLine style data for the line (must be non-auto)
|
||||
* @param aNth a number of lines to find from aFromIndex, negative if the
|
||||
* search should be in reverse order. In the case aLine has
|
||||
* a specified line name, it's permitted to pass in zero which
|
||||
* will be treated as one.
|
||||
* @param aFromIndex the zero-based index to start counting from
|
||||
* @param aNameMap for looking up explicit named lines
|
||||
* @param aAreaStart a pointer to GridNamedArea::mColumnStart/mRowStart
|
||||
* @param aAreaEnd a pointer to GridNamedArea::mColumnEnd/mRowEnd
|
||||
* @param aExplicitGridEnd the last line in the explicit grid
|
||||
* @param aEdge indicates whether we are resolving a start or end line
|
||||
* @param aStyle the StylePosition() for the grid container
|
||||
* @return a definite line (1-based), clamped to the kMinLine..kMaxLine range
|
||||
*/
|
||||
int32_t ResolveLine(const nsStyleGridLine& aLine,
|
||||
int32_t aNth,
|
||||
uint32_t aFromIndex,
|
||||
const LineNameMap& aNameMap,
|
||||
uint32_t GridNamedArea::* aAreaStart,
|
||||
uint32_t GridNamedArea::* aAreaEnd,
|
||||
uint32_t aExplicitGridEnd,
|
||||
LineRangeSide aEdge,
|
||||
const nsStylePosition* aStyle);
|
||||
/**
|
||||
* Return a LineRange based on the given style data. Non-auto lines
|
||||
* are resolved to a definite line number (1-based) per:
|
||||
* http://dev.w3.org/csswg/css-grid/#line-placement
|
||||
* with placement errors corrected per:
|
||||
* http://dev.w3.org/csswg/css-grid/#grid-placement-errors
|
||||
* @param aStyle the StylePosition() for the grid container
|
||||
* @param aStart style data for the start line
|
||||
* @param aEnd style data for the end line
|
||||
* @param aNameMap for looking up explicit named lines
|
||||
* @param aAreaStart a pointer to GridNamedArea::mColumnStart/mRowStart
|
||||
* @param aAreaEnd a pointer to GridNamedArea::mColumnEnd/mRowEnd
|
||||
* @param aExplicitGridEnd the last line in the explicit grid
|
||||
* @param aStyle the StylePosition() for the grid container
|
||||
*/
|
||||
LineRange ResolveLineRange(const nsStyleGridLine& aStart,
|
||||
const nsStyleGridLine& aEnd,
|
||||
const LineNameMap& aNameMap,
|
||||
uint32_t GridNamedArea::* aAreaStart,
|
||||
uint32_t GridNamedArea::* aAreaEnd,
|
||||
uint32_t aExplicitGridEnd,
|
||||
const nsStylePosition* aStyle);
|
||||
|
||||
/**
|
||||
* As above but for an abs.pos. child. Any 'auto' lines will be represented
|
||||
* by kAutoLine in the LineRange result.
|
||||
* @param aGridStart the first line in the final, but untranslated grid
|
||||
* @param aGridEnd the last line in the final, but untranslated grid
|
||||
*/
|
||||
LineRange
|
||||
ResolveAbsPosLineRange(const nsStyleGridLine& aStart,
|
||||
const nsStyleGridLine& aEnd,
|
||||
const LineNameMap& aNameMap,
|
||||
uint32_t GridNamedArea::* aAreaStart,
|
||||
uint32_t GridNamedArea::* aAreaEnd,
|
||||
uint32_t aExplicitGridEnd,
|
||||
int32_t aGridStart,
|
||||
int32_t aGridEnd,
|
||||
const nsStylePosition* aStyle);
|
||||
|
||||
/**
|
||||
* Return a GridArea with non-auto lines placed at a definite line (1-based)
|
||||
* with placement errors resolved. One or both positions may still
|
||||
* be 'auto'.
|
||||
* @param aChild the grid item
|
||||
* @param aColLineNameMap for looking up explicit named column lines
|
||||
* @param aRowLineNameMap for looking up explicit named row lines
|
||||
* @param aStyle the StylePosition() for the grid container
|
||||
*/
|
||||
GridArea PlaceDefinite(nsIFrame* aChild,
|
||||
const LineNameMap& aColLineNameMap,
|
||||
const LineNameMap& aRowLineNameMap,
|
||||
const nsStylePosition* aStyle);
|
||||
|
||||
/**
|
||||
* Place aArea in the first column (in row aArea->mRows.mStart) starting at
|
||||
* aStartCol without overlapping other items. The resulting aArea may
|
||||
* overflow the current implicit grid bounds.
|
||||
* Pre-condition: aArea->mRows.IsDefinite() is true.
|
||||
* Post-condition: aArea->IsDefinite() is true.
|
||||
*/
|
||||
void PlaceAutoCol(uint32_t aStartCol, GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Find the first column in row aLockedRow starting at aStartCol where aArea
|
||||
* could be placed without overlapping other items. The returned column may
|
||||
* cause aArea to overflow the current implicit grid bounds if placed there.
|
||||
*/
|
||||
uint32_t FindAutoCol(uint32_t aStartCol, uint32_t aLockedRow,
|
||||
const GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Place aArea in the first row (in column aArea->mCols.mStart) starting at
|
||||
* aStartRow without overlapping other items. The resulting aArea may
|
||||
* overflow the current implicit grid bounds.
|
||||
* Pre-condition: aArea->mCols.IsDefinite() is true.
|
||||
* Post-condition: aArea->IsDefinite() is true.
|
||||
*/
|
||||
void PlaceAutoRow(uint32_t aStartRow, GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Find the first row in column aLockedCol starting at aStartRow where aArea
|
||||
* could be placed without overlapping other items. The returned row may
|
||||
* cause aArea to overflow the current implicit grid bounds if placed there.
|
||||
*/
|
||||
uint32_t FindAutoRow(uint32_t aLockedCol, uint32_t aStartRow,
|
||||
const GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Place aArea in the first column starting at aStartCol,aStartRow without
|
||||
* causing it to overlap other items or overflow mGridColEnd.
|
||||
* If there's no such column in aStartRow, continue in position 1,aStartRow+1.
|
||||
* Pre-condition: aArea->mCols.IsAuto() && aArea->mRows.IsAuto() is true.
|
||||
* Post-condition: aArea->IsDefinite() is true.
|
||||
*/
|
||||
void PlaceAutoAutoInRowOrder(uint32_t aStartCol, uint32_t aStartRow,
|
||||
GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Place aArea in the first row starting at aStartCol,aStartRow without
|
||||
* causing it to overlap other items or overflow mGridRowEnd.
|
||||
* If there's no such row in aStartCol, continue in position aStartCol+1,1.
|
||||
* Pre-condition: aArea->mCols.IsAuto() && aArea->mRows.IsAuto() is true.
|
||||
* Post-condition: aArea->IsDefinite() is true.
|
||||
*/
|
||||
void PlaceAutoAutoInColOrder(uint32_t aStartCol, uint32_t aStartRow,
|
||||
GridArea* aArea) const;
|
||||
|
||||
/**
|
||||
* Return a GridArea for abs.pos. item with non-auto lines placed at
|
||||
* a definite line (1-based) with placement errors resolved. One or both
|
||||
* positions may still be 'auto'.
|
||||
* @param aChild the abs.pos. grid item to place
|
||||
* @param aColLineNameMap for looking up explicit named column lines
|
||||
* @param aRowLineNameMap for looking up explicit named row lines
|
||||
* @param aStyle the StylePosition() for the grid container
|
||||
*/
|
||||
GridArea PlaceAbsPos(nsIFrame* aChild,
|
||||
const LineNameMap& aColLineNameMap,
|
||||
const LineNameMap& aRowLineNameMap,
|
||||
const nsStylePosition* aStyle);
|
||||
|
||||
/**
|
||||
* Place all child frames into the grid and expand the (implicit) grid as
|
||||
* needed. The allocated GridAreas are stored in the GridAreaProperty
|
||||
* frame property on the child frame.
|
||||
* @param aComputedMinSize the container's min-size - used to determine
|
||||
* the number of repeat(auto-fill/fit) tracks.
|
||||
* @param aComputedSize the container's size - used to determine
|
||||
* the number of repeat(auto-fill/fit) tracks.
|
||||
* @param aComputedMaxSize the container's max-size - used to determine
|
||||
* the number of repeat(auto-fill/fit) tracks.
|
||||
*/
|
||||
void PlaceGridItems(GridReflowState& aState,
|
||||
const LogicalSize& aComputedMinSize,
|
||||
const LogicalSize& aComputedSize,
|
||||
const LogicalSize& aComputedMaxSize);
|
||||
// Helper for the above.
|
||||
void PlaceGridItems(GridReflowState& aState,
|
||||
const LineNameMap& aColLineNameMap,
|
||||
const LineNameMap& aRowLineNameMap);
|
||||
|
||||
/**
|
||||
* Inflate the implicit grid to include aArea.
|
||||
* @param aArea may be definite or auto
|
||||
*/
|
||||
void InflateGridFor(const GridArea& aArea)
|
||||
{
|
||||
mGridColEnd = std::max(mGridColEnd, aArea.mCols.HypotheticalEnd());
|
||||
mGridRowEnd = std::max(mGridRowEnd, aArea.mRows.HypotheticalEnd());
|
||||
MOZ_ASSERT(mGridColEnd <= kTranslatedMaxLine &&
|
||||
mGridRowEnd <= kTranslatedMaxLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate track sizes.
|
||||
*/
|
||||
void CalculateTrackSizes(GridReflowState& aState,
|
||||
const mozilla::LogicalSize& aContentBox,
|
||||
IntrinsicISizeType aConstraint);
|
||||
|
||||
/**
|
||||
* Helper method for ResolveLineRange.
|
||||
* @see ResolveLineRange
|
||||
* @return a pair (start,end) of lines
|
||||
*/
|
||||
typedef std::pair<int32_t, int32_t> LinePair;
|
||||
LinePair ResolveLineRangeHelper(const nsStyleGridLine& aStart,
|
||||
const nsStyleGridLine& aEnd,
|
||||
const LineNameMap& aNameMap,
|
||||
uint32_t GridNamedArea::* aAreaStart,
|
||||
uint32_t GridNamedArea::* aAreaEnd,
|
||||
uint32_t aExplicitGridEnd,
|
||||
const nsStylePosition* aStyle);
|
||||
|
||||
/**
|
||||
* XXX temporary - move the ImplicitNamedAreas stuff to the style system.
|
||||
* The implicit area names that come from x-start .. x-end lines in
|
||||
@@ -605,28 +360,6 @@ protected:
|
||||
ImplicitNamedAreas* GetImplicitNamedAreas() const {
|
||||
return Properties().Get(ImplicitNamedAreasProperty());
|
||||
}
|
||||
bool HasImplicitNamedArea(const nsString& aName) const {
|
||||
ImplicitNamedAreas* areas = GetImplicitNamedAreas();
|
||||
return areas && areas->Contains(aName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the containing block for a grid item occupying aArea.
|
||||
*/
|
||||
LogicalRect ContainingBlockFor(const GridReflowState& aState,
|
||||
const GridArea& aArea) const;
|
||||
|
||||
/**
|
||||
* Return the containing block for an abs.pos. grid item occupying aArea.
|
||||
* Any 'auto' lines in the grid area will be aligned with grid container
|
||||
* containing block on that side.
|
||||
* @param aGridOrigin the origin of the grid
|
||||
* @param aGridCB the grid container containing block (its padding area)
|
||||
*/
|
||||
LogicalRect ContainingBlockForAbsPos(const GridReflowState& aState,
|
||||
const GridArea& aArea,
|
||||
const LogicalPoint& aGridOrigin,
|
||||
const LogicalRect& aGridCB) const;
|
||||
|
||||
/**
|
||||
* Reflow and place our children.
|
||||
@@ -647,46 +380,6 @@ protected:
|
||||
#endif // DEBUG
|
||||
|
||||
private:
|
||||
/**
|
||||
* Info about each (normal flow) grid item.
|
||||
*/
|
||||
nsTArray<GridItemInfo> mGridItems;
|
||||
|
||||
/**
|
||||
* Info about each grid-aligned abs.pos. child.
|
||||
*/
|
||||
nsTArray<GridItemInfo> mAbsPosItems;
|
||||
|
||||
/**
|
||||
* State for each cell in the grid.
|
||||
*/
|
||||
CellMap mCellMap;
|
||||
|
||||
/**
|
||||
* The last column grid line (1-based) in the explicit grid.
|
||||
* (i.e. the number of explicit columns + 1)
|
||||
*/
|
||||
uint32_t mExplicitGridColEnd;
|
||||
/**
|
||||
* The last row grid line (1-based) in the explicit grid.
|
||||
* (i.e. the number of explicit rows + 1)
|
||||
*/
|
||||
uint32_t mExplicitGridRowEnd;
|
||||
// Same for the implicit grid, except these become zero-based after
|
||||
// resolving definite lines.
|
||||
uint32_t mGridColEnd;
|
||||
uint32_t mGridRowEnd;
|
||||
|
||||
/**
|
||||
* Offsets from the start of the implicit grid to the start of the translated
|
||||
* explicit grid. They are zero if there are no implicit lines before 1,1.
|
||||
* e.g. "grid-column: span 3 / 1" makes mExplicitGridOffsetCol = 3 and the
|
||||
* corresponding GridArea::mCols will be 0 / 3 in the zero-based translated
|
||||
* grid.
|
||||
*/
|
||||
uint32_t mExplicitGridOffsetCol;
|
||||
uint32_t mExplicitGridOffsetRow;
|
||||
|
||||
/**
|
||||
* Cached values to optimize GetMinISize/GetPrefISize.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user