Bug 978212 - Resolved value of grid-template-{columns,rows} in px units. r=mats

This commit is contained in:
Tobias Schneider 2015-12-03 14:23:00 +01:00
Родитель bc30932b74
Коммит cbe699d03c
6 изменённых файлов: 159 добавлений и 16 удалений

Просмотреть файл

@ -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<nscoord> colTrackSizes(gridReflowState.mCols.mSizes.Length());
for (const TrackSize& sz : gridReflowState.mCols.mSizes) {
colTrackSizes.AppendElement(sz.mBase);
}
Properties().Set(GridColTrackSizes(),
new nsTArray<nscoord>(mozilla::Move(colTrackSizes)));
nsTArray<nscoord> rowTrackSizes(gridReflowState.mRows.mSizes.Length());
for (const TrackSize& sz : gridReflowState.mRows.mSizes) {
rowTrackSizes.AppendElement(sz.mBase);
}
Properties().Set(GridRowTrackSizes(),
new nsTArray<nscoord>(mozilla::Move(rowTrackSizes)));
nscoord bSize = 0;
if (computedBSize == NS_AUTOHEIGHT) {
for (uint32_t i = 0; i < mGridRowEnd; ++i) {

Просмотреть файл

@ -91,6 +91,20 @@ public:
NS_DECLARE_FRAME_PROPERTY(GridItemContainingBlockRect, DeleteValue<nsRect>)
NS_DECLARE_FRAME_PROPERTY(GridColTrackSizes, DeleteValue<nsTArray<nscoord>>)
const nsTArray<nscoord>* GetComputedTemplateColumns()
{
return static_cast<nsTArray<nscoord>*>(Properties().Get(GridColTrackSizes()));
}
NS_DECLARE_FRAME_PROPERTY(GridRowTrackSizes, DeleteValue<nsTArray<nscoord>>)
const nsTArray<nscoord>* GetComputedTemplateRows()
{
return static_cast<nsTArray<nscoord>*>(Properties().Get(GridRowTrackSizes()));
}
protected:
static const uint32_t kAutoLine;
// The maximum line number, in the zero-based translated grid.

Просмотреть файл

@ -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 <track-size> 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<nscoord>* 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<nsString>& lineNames = aTrackList.mLineNameLists[i];
if (!lineNames.IsEmpty()) {
valueList->AppendCSSValue(GetGridLineNames(lineNames));
if (aTrackSizes) {
for (uint32_t i = 0;; i++) {
const nsTArray<nsString>& 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<nsString>& 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<nscoord>* trackSizes = nullptr;
if (mInnerFrame) {
nsIFrame* gridContainerCandidate = mInnerFrame->GetContentInsertionFrame();
if (gridContainerCandidate &&
gridContainerCandidate->GetType() == nsGkAtoms::gridContainerFrame) {
auto gridContainer = static_cast<nsGridContainerFrame*>(gridContainerCandidate);
trackSizes = gridContainer->GetComputedTemplateColumns();
}
}
return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateColumns, trackSizes);
}
CSSValue*
nsComputedDOMStyle::DoGetGridTemplateRows()
{
return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateRows);
const nsTArray<nscoord>* trackSizes = nullptr;
if (mInnerFrame) {
nsIFrame* gridContainerCandidate = mInnerFrame->GetContentInsertionFrame();
if (gridContainerCandidate &&
gridContainerCandidate->GetType() == nsGkAtoms::gridContainerFrame) {
auto gridContainer = static_cast<nsGridContainerFrame*>(gridContainerCandidate);
trackSizes = gridContainer->GetComputedTemplateRows();
}
}
return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateRows, trackSizes);
}
CSSValue*

Просмотреть файл

@ -179,7 +179,8 @@ private:
mozilla::dom::CSSValue* GetGridLineNames(const nsTArray<nsString>& 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<nscoord>* aTrackSizes);
mozilla::dom::CSSValue* GetGridLine(const nsStyleGridLine& aGridLine);
bool GetLineHeightCoord(nscoord& aCoord);

Просмотреть файл

@ -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]

Просмотреть файл

@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Test computed grid values</title>
<link rel="author" title="Tobias Schneider" href="mailto:schneider@jancona.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel='stylesheet' href='/resources/testharness.css'>
<style>
#grid {
display: grid;
width: 500px;
height: 400px;
grid-template-columns:
[a] auto
[b] minmax(min-content, 1fr)
[b c d] repeat(2, [e] 40px)
repeat(5, auto);
grid-template-rows:
[a] minmax(min-content, 1fr)
[b] auto
[b c d e] 30px 30px
auto auto;
grid-auto-columns: 3fr;
grid-auto-rows: 2fr;
}
</style>
</head>
<body>
<div>
<div id="grid">
<div style="grid-column-start:1; width:50px"></div>
<div style="grid-column-start:9; width:50px"></div>
</div>
<div>
<script>
var gridElement = document.getElementById("grid");
function test_grid_template(assert_fn, width, desc) {
test(function() {
assert_fn(getComputedStyle(gridElement).gridTemplateColumns,
"[a] 50px [b] " + width + "px [b c d e] 40px [e] 40px 0px 0px 0px 0px 50px");
assert_fn(getComputedStyle(gridElement).gridTemplateRows,
"[a] 340px [b] 0px [b c d e] 30px 30px 0px 0px");
}, desc);
}
test_grid_template(assert_equals, 320, "test computed grid-template-{columns,rows} values");
gridElement.style.overflow = 'scroll';
test_grid_template(assert_equals, 320,
"test computed grid-template-{columns,rows} values, overflow: scroll");
gridElement.style.width = '600px';
gridElement.style.overflow = 'visible';
test_grid_template(assert_equals, 420,
"test computed grid-template-{columns,rows} values, after reflow");
gridElement.style.display = 'none';
test_grid_template(assert_not_equals, 420,
"test computed grid-template-{columns,rows} values, display: none");
gridElement.style.display = 'grid';
gridElement.parentNode.style.display = 'none';
test_grid_template(assert_not_equals, 420,
"test computed grid-template-{columns,rows} values, display: none on parent");
test(function() {
assert_equals(getComputedStyle(gridElement).gridAutoColumns, "3fr");
assert_equals(getComputedStyle(gridElement).gridAutoRows, "2fr");
}, "test computed grid-auto-{columns,rows} values");
</script>
</body>
</html>