Commit 856c2d86 authored by kojii's avatar kojii Committed by Commit bot

Add CSS parser support for the snap-height property

This patch adds CSS parser support for the snap-height property, behind
the CSSSnapSize runtime flag.

Supporting layout will be in following patches.

A test was imported from csswg-test and was marked as failure. This
patch makes the test pass.

Spec: https://drafts.csswg.org/css-snap-size/
Dashboard: https://www.chromestatus.com/features/5734273533345792

BUG=586413
TEST=imported/csswg-test/css-snap-size-1/snap-height-parsing-001.html

Review URL: https://codereview.chromium.org/1696373003

Cr-Commit-Position: refs/heads/master@{#376051}
parent 475197e0
...@@ -249,6 +249,7 @@ shape-image-threshold: 0 ...@@ -249,6 +249,7 @@ shape-image-threshold: 0
shape-margin: 0px shape-margin: 0px
shape-outside: none shape-outside: none
shape-rendering: auto shape-rendering: auto
snap-height: 0px
speak: normal speak: normal
stop-color: rgb(0, 0, 0) stop-color: rgb(0, 0, 0)
stop-opacity: 1 stop-opacity: 1
......
...@@ -249,6 +249,7 @@ shape-image-threshold: 0 ...@@ -249,6 +249,7 @@ shape-image-threshold: 0
shape-margin: 0px shape-margin: 0px
shape-outside: none shape-outside: none
shape-rendering: auto shape-rendering: auto
snap-height: 0px
speak: normal speak: normal
stop-color: rgb(0, 0, 0) stop-color: rgb(0, 0, 0)
stop-opacity: 1 stop-opacity: 1
......
This is a testharness.js-based test.
FAIL initial value assert_equals: expected (string) "0px" but got (undefined) undefined
FAIL snap-height: 20px 60 assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height should inherit assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: initial assert_equals: expected (string) "0px" but got (undefined) undefined
FAIL snap-height: initial; snap-height: inherit assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: 40px assert_equals: expected (string) "40px" but got (undefined) undefined
FAIL snap-height: 0 assert_equals: expected (string) "0px" but got (undefined) undefined
FAIL snap-height: 1 assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: -1px assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: 40px -1 assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: 40px 0 assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL snap-height: 40px 101 assert_equals: expected (string) "20px 60" but got (undefined) undefined
FAIL Computed value must be the absolute length Cannot read property 'slice' of undefined
Harness: the test ran to completion.
...@@ -249,6 +249,7 @@ shape-image-threshold: 0 ...@@ -249,6 +249,7 @@ shape-image-threshold: 0
shape-margin: 0px shape-margin: 0px
shape-outside: none shape-outside: none
shape-rendering: auto shape-rendering: auto
snap-height: 0px
speak: normal speak: normal
stop-color: rgb(0, 0, 0) stop-color: rgb(0, 0, 0)
stop-opacity: 1 stop-opacity: 1
......
...@@ -229,6 +229,7 @@ shapeMargin ...@@ -229,6 +229,7 @@ shapeMargin
shapeOutside shapeOutside
shapeRendering shapeRendering
size size
snapHeight
speak speak
src src
stopColor stopColor
......
...@@ -154,6 +154,7 @@ static const CSSPropertyID staticComputableProperties[] = { ...@@ -154,6 +154,7 @@ static const CSSPropertyID staticComputableProperties[] = {
CSSPropertyResize, CSSPropertyResize,
CSSPropertyRight, CSSPropertyRight,
CSSPropertyScrollBehavior, CSSPropertyScrollBehavior,
CSSPropertySnapHeight,
CSSPropertySpeak, CSSPropertySpeak,
CSSPropertyTableLayout, CSSPropertyTableLayout,
CSSPropertyTabSize, CSSPropertyTabSize,
......
...@@ -271,6 +271,7 @@ shape-margin interpolable, converter=convertLength ...@@ -271,6 +271,7 @@ shape-margin interpolable, converter=convertLength
shape-outside interpolable, converter=convertShapeValue shape-outside interpolable, converter=convertShapeValue
shape-rendering inherited, svg shape-rendering inherited, svg
size custom_all size custom_all
snap-height runtime_flag=CSSSnapSize, inherited, custom_all
speak inherited speak inherited
stop-color interpolable, svg, converter=convertColor stop-color interpolable, svg, converter=convertColor
stop-opacity interpolable, svg, converter=convertNumberOrPercentage stop-opacity interpolable, svg, converter=convertNumberOrPercentage
......
...@@ -2697,6 +2697,15 @@ PassRefPtrWillBeRawPtr<CSSValue> ComputedStyleCSSValueMapping::get(CSSPropertyID ...@@ -2697,6 +2697,15 @@ PassRefPtrWillBeRawPtr<CSSValue> ComputedStyleCSSValueMapping::get(CSSPropertyID
ASSERT(list->length()); ASSERT(list->length());
return list.release(); return list.release();
} }
case CSSPropertySnapHeight: {
if (!style.snapHeightUnit())
return cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Pixels);
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
list->append(cssValuePool().createValue(style.snapHeightUnit(), CSSPrimitiveValue::UnitType::Pixels));
if (style.snapHeightPosition())
list->append(cssValuePool().createValue(style.snapHeightPosition(), CSSPrimitiveValue::UnitType::Integer));
return list.release();
}
case CSSPropertyVariable: case CSSPropertyVariable:
// Variables are retrieved via get(AtomicString). // Variables are retrieved via get(AtomicString).
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
......
...@@ -1289,6 +1289,23 @@ static PassRefPtrWillBeRawPtr<CSSValueList> consumeSize(CSSParserTokenRange& ran ...@@ -1289,6 +1289,23 @@ static PassRefPtrWillBeRawPtr<CSSValueList> consumeSize(CSSParserTokenRange& ran
return result.release(); return result.release();
} }
static PassRefPtrWillBeRawPtr<CSSValue> consumeSnapHeight(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> unit = consumeLength(range, cssParserMode, ValueRangeNonNegative);
if (!unit)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
list->append(unit.release());
if (RefPtrWillBeRawPtr<CSSPrimitiveValue> position = consumePositiveInteger(range)) {
if (position->getIntValue() > 100)
return nullptr;
list->append(position.release());
}
return list.release();
}
static PassRefPtrWillBeRawPtr<CSSValue> consumeTextIndent(CSSParserTokenRange& range, CSSParserMode cssParserMode) static PassRefPtrWillBeRawPtr<CSSValue> consumeTextIndent(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{ {
// [ <length> | <percentage> ] && hanging? && each-line? // [ <length> | <percentage> ] && hanging? && each-line?
...@@ -3425,6 +3442,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ...@@ -3425,6 +3442,8 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
return consumeCounter(m_range, m_context.mode(), property == CSSPropertyCounterIncrement ? 1 : 0); return consumeCounter(m_range, m_context.mode(), property == CSSPropertyCounterIncrement ? 1 : 0);
case CSSPropertySize: case CSSPropertySize:
return consumeSize(m_range, m_context.mode()); return consumeSize(m_range, m_context.mode());
case CSSPropertySnapHeight:
return consumeSnapHeight(m_range, m_context.mode());
case CSSPropertyTextIndent: case CSSPropertyTextIndent:
return consumeTextIndent(m_range, m_context.mode()); return consumeTextIndent(m_range, m_context.mode());
case CSSPropertyMaxWidth: case CSSPropertyMaxWidth:
......
...@@ -374,6 +374,40 @@ void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state, ...@@ -374,6 +374,40 @@ void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state,
state.style()->setPageSize(size); state.style()->setPageSize(size);
} }
void StyleBuilderFunctions::applyInitialCSSPropertySnapHeight(StyleResolverState& state)
{
state.style()->setSnapHeightUnit(0);
state.style()->setSnapHeightPosition(0);
}
void StyleBuilderFunctions::applyInheritCSSPropertySnapHeight(StyleResolverState& state)
{
state.style()->setSnapHeightUnit(state.parentStyle()->snapHeightUnit());
state.style()->setSnapHeightPosition(state.parentStyle()->snapHeightPosition());
}
void StyleBuilderFunctions::applyValueCSSPropertySnapHeight(StyleResolverState& state, CSSValue* value)
{
CSSValueList* list = toCSSValueList(value);
CSSPrimitiveValue* first = toCSSPrimitiveValue(list->item(0));
ASSERT(first->isLength());
int unit = first->computeLength<int>(state.cssToLengthConversionData());
ASSERT(unit >= 0);
state.style()->setSnapHeightUnit(clampTo<uint8_t>(unit));
if (list->length() == 1) {
state.style()->setSnapHeightPosition(0);
return;
}
ASSERT(list->length() == 2);
CSSPrimitiveValue* second = toCSSPrimitiveValue(list->item(1));
ASSERT(second->isNumber());
int position = second->getIntValue();
ASSERT(position > 0 && position <= 100);
state.style()->setSnapHeightPosition(position);
}
void StyleBuilderFunctions::applyValueCSSPropertyTextAlign(StyleResolverState& state, CSSValue* value) void StyleBuilderFunctions::applyValueCSSPropertyTextAlign(StyleResolverState& state, CSSValue* value)
{ {
CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
......
...@@ -551,6 +551,7 @@ int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) ...@@ -551,6 +551,7 @@ int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id)
case CSSPropertyFontDisplay: return 516; case CSSPropertyFontDisplay: return 516;
case CSSPropertyContain: return 517; case CSSPropertyContain: return 517;
case CSSPropertyD: return 518; case CSSPropertyD: return 518;
case CSSPropertySnapHeight: return 519;
// 1. Add new features above this line (don't change the assigned numbers of the existing // 1. Add new features above this line (don't change the assigned numbers of the existing
// items). // items).
...@@ -567,7 +568,7 @@ int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) ...@@ -567,7 +568,7 @@ int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id)
return 0; return 0;
} }
static int maximumCSSSampleId() { return 518; } static int maximumCSSSampleId() { return 519; }
static EnumerationHistogram& featureObserverHistogram() static EnumerationHistogram& featureObserverHistogram()
{ {
......
...@@ -935,6 +935,9 @@ public: ...@@ -935,6 +935,9 @@ public:
TextCombine textCombine() const { return static_cast<TextCombine>(rareInheritedData->m_textCombine); } TextCombine textCombine() const { return static_cast<TextCombine>(rareInheritedData->m_textCombine); }
bool hasTextCombine() const { return textCombine() != TextCombineNone; } bool hasTextCombine() const { return textCombine() != TextCombineNone; }
uint8_t snapHeightPosition() const { return rareInheritedData->m_snapHeightPosition; }
uint8_t snapHeightUnit() const { return rareInheritedData->m_snapHeightUnit; }
TabSize tabSize() const { return rareInheritedData->m_tabSize; } TabSize tabSize() const { return rareInheritedData->m_tabSize; }
RespectImageOrientationEnum respectImageOrientation() const { return static_cast<RespectImageOrientationEnum>(rareInheritedData->m_respectImageOrientation); } RespectImageOrientationEnum respectImageOrientation() const { return static_cast<RespectImageOrientationEnum>(rareInheritedData->m_respectImageOrientation); }
...@@ -1440,6 +1443,9 @@ public: ...@@ -1440,6 +1443,9 @@ public:
void setFilter(const FilterOperations& ops) { SET_NESTED_VAR(rareNonInheritedData, m_filter, m_operations, ops); } void setFilter(const FilterOperations& ops) { SET_NESTED_VAR(rareNonInheritedData, m_filter, m_operations, ops); }
void setBackdropFilter(const FilterOperations& ops) { SET_NESTED_VAR(rareNonInheritedData, m_backdropFilter, m_operations, ops); } void setBackdropFilter(const FilterOperations& ops) { SET_NESTED_VAR(rareNonInheritedData, m_backdropFilter, m_operations, ops); }
void setSnapHeightPosition(uint8_t position) { SET_VAR(rareInheritedData, m_snapHeightPosition, position); }
void setSnapHeightUnit(uint8_t unit) { SET_VAR(rareInheritedData, m_snapHeightUnit, unit); }
void setTabSize(TabSize size) { SET_VAR(rareInheritedData, m_tabSize, size); } void setTabSize(TabSize size) { SET_VAR(rareInheritedData, m_tabSize, size); }
void setRespectImageOrientation(RespectImageOrientationEnum v) { SET_VAR(rareInheritedData, m_respectImageOrientation, v); } void setRespectImageOrientation(RespectImageOrientationEnum v) { SET_VAR(rareInheritedData, m_respectImageOrientation, v); }
......
...@@ -51,6 +51,7 @@ struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareI ...@@ -51,6 +51,7 @@ struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareI
unsigned m_bitfields[2]; unsigned m_bitfields[2];
short pagedMediaShorts[2]; short pagedMediaShorts[2];
short hyphenationShorts[3]; short hyphenationShorts[3];
uint8_t snapHeight;
Color touchColors; Color touchColors;
TabSize tabSize; TabSize tabSize;
...@@ -96,9 +97,11 @@ StyleRareInheritedData::StyleRareInheritedData() ...@@ -96,9 +97,11 @@ StyleRareInheritedData::StyleRareInheritedData()
, m_subtreeWillChangeContents(false) , m_subtreeWillChangeContents(false)
, m_selfOrAncestorHasDirAutoAttribute(false) , m_selfOrAncestorHasDirAutoAttribute(false)
, m_respectImageOrientation(false) , m_respectImageOrientation(false)
, m_snapHeightPosition(0)
, hyphenationLimitBefore(-1) , hyphenationLimitBefore(-1)
, hyphenationLimitAfter(-1) , hyphenationLimitAfter(-1)
, hyphenationLimitLines(-1) , hyphenationLimitLines(-1)
, m_snapHeightUnit(0)
, tapHighlightColor(ComputedStyle::initialTapHighlightColor()) , tapHighlightColor(ComputedStyle::initialTapHighlightColor())
, m_tabSize(ComputedStyle::initialTabSize()) , m_tabSize(ComputedStyle::initialTabSize())
{ {
...@@ -151,10 +154,12 @@ StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o) ...@@ -151,10 +154,12 @@ StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
, m_subtreeWillChangeContents(o.m_subtreeWillChangeContents) , m_subtreeWillChangeContents(o.m_subtreeWillChangeContents)
, m_selfOrAncestorHasDirAutoAttribute(o.m_selfOrAncestorHasDirAutoAttribute) , m_selfOrAncestorHasDirAutoAttribute(o.m_selfOrAncestorHasDirAutoAttribute)
, m_respectImageOrientation(o.m_respectImageOrientation) , m_respectImageOrientation(o.m_respectImageOrientation)
, m_snapHeightPosition(o.m_snapHeightPosition)
, hyphenationString(o.hyphenationString) , hyphenationString(o.hyphenationString)
, hyphenationLimitBefore(o.hyphenationLimitBefore) , hyphenationLimitBefore(o.hyphenationLimitBefore)
, hyphenationLimitAfter(o.hyphenationLimitAfter) , hyphenationLimitAfter(o.hyphenationLimitAfter)
, hyphenationLimitLines(o.hyphenationLimitLines) , hyphenationLimitLines(o.hyphenationLimitLines)
, m_snapHeightUnit(o.m_snapHeightUnit)
, textEmphasisCustomMark(o.textEmphasisCustomMark) , textEmphasisCustomMark(o.textEmphasisCustomMark)
, tapHighlightColor(o.tapHighlightColor) , tapHighlightColor(o.tapHighlightColor)
, appliedTextDecorations(o.appliedTextDecorations) , appliedTextDecorations(o.appliedTextDecorations)
...@@ -214,7 +219,9 @@ bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const ...@@ -214,7 +219,9 @@ bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
&& m_subtreeWillChangeContents == o.m_subtreeWillChangeContents && m_subtreeWillChangeContents == o.m_subtreeWillChangeContents
&& m_selfOrAncestorHasDirAutoAttribute == o.m_selfOrAncestorHasDirAutoAttribute && m_selfOrAncestorHasDirAutoAttribute == o.m_selfOrAncestorHasDirAutoAttribute
&& m_respectImageOrientation == o.m_respectImageOrientation && m_respectImageOrientation == o.m_respectImageOrientation
&& m_snapHeightPosition == o.m_snapHeightPosition
&& hyphenationString == o.hyphenationString && hyphenationString == o.hyphenationString
&& m_snapHeightUnit == o.m_snapHeightUnit
&& textEmphasisCustomMark == o.textEmphasisCustomMark && textEmphasisCustomMark == o.textEmphasisCustomMark
&& quotesDataEquivalent(o) && quotesDataEquivalent(o)
&& m_tabSize == o.m_tabSize && m_tabSize == o.m_tabSize
......
...@@ -145,11 +145,15 @@ public: ...@@ -145,11 +145,15 @@ public:
unsigned m_respectImageOrientation : 1; unsigned m_respectImageOrientation : 1;
unsigned m_snapHeightPosition : 7;
AtomicString hyphenationString; AtomicString hyphenationString;
short hyphenationLimitBefore; short hyphenationLimitBefore;
short hyphenationLimitAfter; short hyphenationLimitAfter;
short hyphenationLimitLines; short hyphenationLimitLines;
uint8_t m_snapHeightUnit;
AtomicString textEmphasisCustomMark; AtomicString textEmphasisCustomMark;
RefPtr<QuotesData> quotes; RefPtr<QuotesData> quotes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment