diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index fdd33f9e5669..89e6d9a0c031 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -14,9 +14,11 @@ #include "nsHashKeys.h" #include "nsPresContext.h" #include "nsReadableUtils.h" +#include "nsRuleNode.h" #include "nsStyleContext.h" using namespace mozilla; +typedef nsGridContainerFrame::TrackSize TrackSize; /** * Search for the aNth occurrence of aName in aNameList (forward), starting at @@ -687,6 +689,85 @@ nsGridContainerFrame::PlaceGridItems(const nsStylePosition* aStyle) } } +static void +InitializeTrackSize(nscoord aPercentageBasis, + const nsStyleCoord& aMinCoord, + const nsStyleCoord& aMaxCoord, + TrackSize* aTrackSize) +{ + // http://dev.w3.org/csswg/css-grid/#algo-init + nscoord& base = aTrackSize->mBase; + switch (aMaxCoord.GetUnit()) { + case eStyleUnit_Enumerated: + case eStyleUnit_FlexFraction: + base = 0; + break; + default: + base = nsRuleNode::ComputeCoordPercentCalc(aMinCoord, aPercentageBasis); + } + nscoord& limit = aTrackSize->mLimit; + switch (aMaxCoord.GetUnit()) { + case eStyleUnit_Enumerated: + limit = NS_UNCONSTRAINEDSIZE; + break; + case eStyleUnit_FlexFraction: + limit = base; + break; + default: + limit = nsRuleNode::ComputeCoordPercentCalc(aMaxCoord, aPercentageBasis); + if (limit < base) { + limit = base; + } + } +} + +static void +InitializeTrackSizes(nscoord aPercentageBasis, + const nsTArray& aMinSizingFunctions, + const nsTArray& aMaxSizingFunctions, + const nsStyleCoord& aAutoMinFunction, + const nsStyleCoord& aAutoMaxFunction, + nsTArray& aResults) +{ + MOZ_ASSERT(aResults.Length() >= aMinSizingFunctions.Length()); + MOZ_ASSERT(aMinSizingFunctions.Length() == aMaxSizingFunctions.Length()); + const size_t len = aMinSizingFunctions.Length(); + size_t i = 0; + for (; i < len; ++i) { + InitializeTrackSize(aPercentageBasis, + aMinSizingFunctions[i], aMinSizingFunctions[i], + &aResults[i]); + } + for (; i < aResults.Length(); ++i) { + InitializeTrackSize(aPercentageBasis, + aAutoMinFunction, aAutoMaxFunction, + &aResults[i]); + } +} + +void +nsGridContainerFrame::CalculateTrackSizes(const LogicalSize& aPercentageBasis, + const nsStylePosition* aStyle, + nsTArray& aColSizes, + nsTArray& aRowSizes) +{ + aColSizes.SetLength(mGridColEnd - 1); + aRowSizes.SetLength(mGridRowEnd - 1); + WritingMode wm = GetWritingMode(); + InitializeTrackSizes(aPercentageBasis.ISize(wm), + aStyle->mGridTemplateColumns.mMinTrackSizingFunctions, + aStyle->mGridTemplateColumns.mMaxTrackSizingFunctions, + aStyle->mGridAutoColumnsMin, + aStyle->mGridAutoColumnsMax, + aColSizes); + InitializeTrackSizes(aPercentageBasis.BSize(wm), + aStyle->mGridTemplateRows.mMinTrackSizingFunctions, + aStyle->mGridTemplateRows.mMaxTrackSizingFunctions, + aStyle->mGridAutoRowsMin, + aStyle->mGridAutoRowsMax, + aRowSizes); +} + void nsGridContainerFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, @@ -721,6 +802,11 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext, InitImplicitNamedAreas(stylePos); PlaceGridItems(stylePos); + nsAutoTArray colSizes; + nsAutoTArray rowSizes; + LogicalSize percentageBasis(wm, aReflowState.ComputedISize(), contentBSize); + CalculateTrackSizes(percentageBasis, stylePos, colSizes, rowSizes); + aStatus = NS_FRAME_COMPLETE; NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); } diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h index 59deb0e9519e..e3e0565751cd 100644 --- a/layout/generic/nsGridContainerFrame.h +++ b/layout/generic/nsGridContainerFrame.h @@ -38,6 +38,11 @@ public: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; #endif + struct TrackSize { + nscoord mBase; + nscoord mLimit; + }; + protected: typedef mozilla::css::GridNamedArea GridNamedArea; friend nsContainerFrame* NS_NewGridContainerFrame(nsIPresShell* aPresShell, @@ -258,6 +263,14 @@ protected: mGridRowEnd = std::max(mGridRowEnd, aArea.mRows.HypotheticalEnd()); } + /** + * Calculate track sizes. + */ + void CalculateTrackSizes(const mozilla::LogicalSize& aPercentageBasis, + const nsStylePosition* aStyle, + nsTArray& aColSizes, + nsTArray& aRowSizes); + /** * Helper method for ResolveLineRange. * @see ResolveLineRange