From cbe699d03c2df74ff6be4f9363e0800aff819b35 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Thu, 3 Dec 2015 14:23:00 +0100 Subject: [PATCH] Bug 978212 - Resolved value of grid-template-{columns,rows} in px units. r=mats --- layout/generic/nsGridContainerFrame.cpp | 15 ++++ layout/generic/nsGridContainerFrame.h | 14 ++++ layout/style/nsComputedDOMStyle.cpp | 61 ++++++++++---- layout/style/nsComputedDOMStyle.h | 3 +- layout/style/test/mochitest.ini | 1 + .../style/test/test_grid_computed_values.html | 81 +++++++++++++++++++ 6 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 layout/style/test/test_grid_computed_values.html diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index d172cc939b2f..553b1d409c24 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -2998,6 +2998,21 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext, LogicalSize(wm, computedISize, computedBSize), nsLayoutUtils::PREF_ISIZE); + // FIXME bug 1229180: Instead of doing this on every reflow, we should only + // set these properties if they are needed. + nsTArray colTrackSizes(gridReflowState.mCols.mSizes.Length()); + for (const TrackSize& sz : gridReflowState.mCols.mSizes) { + colTrackSizes.AppendElement(sz.mBase); + } + Properties().Set(GridColTrackSizes(), + new nsTArray(mozilla::Move(colTrackSizes))); + nsTArray rowTrackSizes(gridReflowState.mRows.mSizes.Length()); + for (const TrackSize& sz : gridReflowState.mRows.mSizes) { + rowTrackSizes.AppendElement(sz.mBase); + } + Properties().Set(GridRowTrackSizes(), + new nsTArray(mozilla::Move(rowTrackSizes))); + nscoord bSize = 0; if (computedBSize == NS_AUTOHEIGHT) { for (uint32_t i = 0; i < mGridRowEnd; ++i) { diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h index 3113037b18fd..6fd8e79d099c 100644 --- a/layout/generic/nsGridContainerFrame.h +++ b/layout/generic/nsGridContainerFrame.h @@ -91,6 +91,20 @@ public: NS_DECLARE_FRAME_PROPERTY(GridItemContainingBlockRect, DeleteValue) + NS_DECLARE_FRAME_PROPERTY(GridColTrackSizes, DeleteValue>) + + const nsTArray* GetComputedTemplateColumns() + { + return static_cast*>(Properties().Get(GridColTrackSizes())); + } + + NS_DECLARE_FRAME_PROPERTY(GridRowTrackSizes, DeleteValue>) + + const nsTArray* GetComputedTemplateRows() + { + return static_cast*>(Properties().Get(GridRowTrackSizes())); + } + protected: static const uint32_t kAutoLine; // The maximum line number, in the zero-based translated grid. diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index a0c3f24ab849..40fbe7d8d4a8 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -25,6 +25,7 @@ #include "nsDOMCSSRGBColor.h" #include "nsDOMCSSValueList.h" #include "nsFlexContainerFrame.h" +#include "nsGridContainerFrame.h" #include "nsGkAtoms.h" #include "nsHTMLReflowState.h" #include "nsStyleUtil.h" @@ -2378,10 +2379,6 @@ CSSValue* nsComputedDOMStyle::GetGridTrackSize(const nsStyleCoord& aMinValue, const nsStyleCoord& aMaxValue) { - // FIXME bug 978212: for grid-template-columns and grid-template-rows - // (not grid-auto-columns and grid-auto-rows), if we have frame, - // every should be resolved into 'px' here, - // based on layout results. if (aMinValue == aMaxValue) { nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue; SetValueToCoord(val, aMinValue, true, @@ -2411,7 +2408,8 @@ nsComputedDOMStyle::GetGridTrackSize(const nsStyleCoord& aMinValue, } CSSValue* -nsComputedDOMStyle::GetGridTemplateColumnsRows(const nsStyleGridTemplate& aTrackList) +nsComputedDOMStyle::GetGridTemplateColumnsRows(const nsStyleGridTemplate& aTrackList, + const nsTArray* aTrackSizes) { if (aTrackList.mIsSubgrid) { NS_ASSERTION(aTrackList.mMinTrackSizingFunctions.IsEmpty() && @@ -2444,16 +2442,31 @@ nsComputedDOMStyle::GetGridTemplateColumnsRows(const nsStyleGridTemplate& aTrack // one before each track, plus one at the very end. MOZ_ASSERT(aTrackList.mLineNameLists.Length() == numSizes + 1, "Unexpected number of line name lists"); - for (uint32_t i = 0;; i++) { - const nsTArray& lineNames = aTrackList.mLineNameLists[i]; - if (!lineNames.IsEmpty()) { - valueList->AppendCSSValue(GetGridLineNames(lineNames)); + if (aTrackSizes) { + for (uint32_t i = 0;; i++) { + const nsTArray& lineNames = aTrackList.mLineNameLists[i]; + if (!lineNames.IsEmpty()) { + valueList->AppendCSSValue(GetGridLineNames(lineNames)); + } + if (i == numSizes) { + break; + } + nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue; + val->SetAppUnits(aTrackSizes->ElementAt(i)); + valueList->AppendCSSValue(val); } - if (i == numSizes) { - break; + } else { + for (uint32_t i = 0;; i++) { + const nsTArray& lineNames = aTrackList.mLineNameLists[i]; + if (!lineNames.IsEmpty()) { + valueList->AppendCSSValue(GetGridLineNames(lineNames)); + } + if (i == numSizes) { + break; + } + valueList->AppendCSSValue(GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i], + aTrackList.mMaxTrackSizingFunctions[i])); } - valueList->AppendCSSValue(GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i], - aTrackList.mMaxTrackSizingFunctions[i])); } return valueList; @@ -2490,13 +2503,31 @@ nsComputedDOMStyle::DoGetGridAutoRows() CSSValue* nsComputedDOMStyle::DoGetGridTemplateColumns() { - return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateColumns); + const nsTArray* trackSizes = nullptr; + if (mInnerFrame) { + nsIFrame* gridContainerCandidate = mInnerFrame->GetContentInsertionFrame(); + if (gridContainerCandidate && + gridContainerCandidate->GetType() == nsGkAtoms::gridContainerFrame) { + auto gridContainer = static_cast(gridContainerCandidate); + trackSizes = gridContainer->GetComputedTemplateColumns(); + } + } + return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateColumns, trackSizes); } CSSValue* nsComputedDOMStyle::DoGetGridTemplateRows() { - return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateRows); + const nsTArray* trackSizes = nullptr; + if (mInnerFrame) { + nsIFrame* gridContainerCandidate = mInnerFrame->GetContentInsertionFrame(); + if (gridContainerCandidate && + gridContainerCandidate->GetType() == nsGkAtoms::gridContainerFrame) { + auto gridContainer = static_cast(gridContainerCandidate); + trackSizes = gridContainer->GetComputedTemplateRows(); + } + } + return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateRows, trackSizes); } CSSValue* diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index fef3bd73d3e2..ce7a6d02b4bc 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -179,7 +179,8 @@ private: mozilla::dom::CSSValue* GetGridLineNames(const nsTArray& aLineNames); mozilla::dom::CSSValue* GetGridTrackSize(const nsStyleCoord& aMinSize, const nsStyleCoord& aMaxSize); - mozilla::dom::CSSValue* GetGridTemplateColumnsRows(const nsStyleGridTemplate& aTrackList); + mozilla::dom::CSSValue* GetGridTemplateColumnsRows(const nsStyleGridTemplate& aTrackList, + const nsTArray* aTrackSizes); mozilla::dom::CSSValue* GetGridLine(const nsStyleGridLine& aGridLine); bool GetLineHeightCoord(nscoord& aCoord); diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 4edf924c58d2..c45ecde6578a 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -181,6 +181,7 @@ skip-if = (toolkit == 'gonk' && debug) # Bug 1186440 [test_grid_container_shorthands.html] [test_grid_item_shorthands.html] [test_grid_shorthand_serialization.html] +[test_grid_computed_values.html] [test_group_insertRule.html] [test_hover_quirk.html] [test_html_attribute_computed_values.html] diff --git a/layout/style/test/test_grid_computed_values.html b/layout/style/test/test_grid_computed_values.html new file mode 100644 index 000000000000..4f7ab3009b94 --- /dev/null +++ b/layout/style/test/test_grid_computed_values.html @@ -0,0 +1,81 @@ + + + + + Test computed grid values + + + + + + + + +
+
+
+
+
+
+ + + +