Commit 11644850 authored by timloh's avatar timloh Committed by Commit bot

CSS Properties & Values API: Support <resolution> values

This patch adds support for <resolution>-typed registered properties.
We already parse the string '<resolution>', so this patch just adds the
logic to parse the actual <resolution> values.

BUG=641877

Review-Url: https://codereview.chromium.org/2618553003
Cr-Commit-Position: refs/heads/master@{#441795}
parent af664d30
...@@ -34,8 +34,9 @@ PASS syntax:'<angle>', initialValue:'20.5rad' is valid ...@@ -34,8 +34,9 @@ PASS syntax:'<angle>', initialValue:'20.5rad' is valid
PASS syntax:'<angle>', initialValue:'calc(50grad + 3.14159rad)' is valid PASS syntax:'<angle>', initialValue:'calc(50grad + 3.14159rad)' is valid
PASS syntax:'<time>', initialValue:'2s' is valid PASS syntax:'<time>', initialValue:'2s' is valid
PASS syntax:'<time>', initialValue:'calc(2s - 9ms)' is valid PASS syntax:'<time>', initialValue:'calc(2s - 9ms)' is valid
FAIL syntax:'<resolution>', initialValue:'10dpi' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. PASS syntax:'<resolution>', initialValue:'10dpi' is valid
FAIL syntax:'<resolution>', initialValue:'-5.3dpcm' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. PASS syntax:'<resolution>', initialValue:'3dPpX' is valid
PASS syntax:'<resolution>', initialValue:'-5.3dpcm' is valid
FAIL syntax:'<transform-function>', initialValue:'scale(2)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. FAIL syntax:'<transform-function>', initialValue:'scale(2)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax.
FAIL syntax:'<transform-function>+', initialValue:'translateX(2px) rotate(20deg)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. FAIL syntax:'<transform-function>+', initialValue:'translateX(2px) rotate(20deg)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax.
PASS syntax:'<color>', initialValue:'rgb(12, 34, 56)' is valid PASS syntax:'<color>', initialValue:'rgb(12, 34, 56)' is valid
......
...@@ -60,6 +60,7 @@ assert_valid("<angle>", "calc(50grad + 3.14159rad)"); ...@@ -60,6 +60,7 @@ assert_valid("<angle>", "calc(50grad + 3.14159rad)");
assert_valid("<time>", "2s"); assert_valid("<time>", "2s");
assert_valid("<time>", "calc(2s - 9ms)"); assert_valid("<time>", "calc(2s - 9ms)");
assert_valid("<resolution>", "10dpi"); assert_valid("<resolution>", "10dpi");
assert_valid("<resolution>", "3dPpX");
assert_valid("<resolution>", "-5.3dpcm"); assert_valid("<resolution>", "-5.3dpcm");
assert_valid("<transform-function>", "scale(2)"); assert_valid("<transform-function>", "scale(2)");
assert_valid("<transform-function>+", "translateX(2px) rotate(20deg)"); assert_valid("<transform-function>+", "translateX(2px) rotate(20deg)");
......
...@@ -165,7 +165,7 @@ const CSSValue* consumeSingleType(const CSSSyntaxComponent& syntax, ...@@ -165,7 +165,7 @@ const CSSValue* consumeSingleType(const CSSSyntaxComponent& syntax,
case CSSSyntaxType::Time: case CSSSyntaxType::Time:
return consumeTime(range, ValueRange::ValueRangeAll); return consumeTime(range, ValueRange::ValueRangeAll);
case CSSSyntaxType::Resolution: case CSSSyntaxType::Resolution:
return nullptr; // TODO(timloh): Implement this. return consumeResolution(range);
case CSSSyntaxType::TransformFunction: case CSSSyntaxType::TransformFunction:
return nullptr; // TODO(timloh): Implement this. return nullptr; // TODO(timloh): Implement this.
case CSSSyntaxType::CustomIdent: case CSSSyntaxType::CustomIdent:
......
...@@ -313,6 +313,21 @@ CSSPrimitiveValue* consumeTime(CSSParserTokenRange& range, ...@@ -313,6 +313,21 @@ CSSPrimitiveValue* consumeTime(CSSParserTokenRange& range,
return nullptr; return nullptr;
} }
CSSPrimitiveValue* consumeResolution(CSSParserTokenRange& range) {
const CSSParserToken& token = range.peek();
// Unlike the other types, calc() does not work with <resolution>.
if (token.type() != DimensionToken)
return nullptr;
CSSPrimitiveValue::UnitType unit = token.unitType();
if (unit == CSSPrimitiveValue::UnitType::DotsPerPixel ||
unit == CSSPrimitiveValue::UnitType::DotsPerInch ||
unit == CSSPrimitiveValue::UnitType::DotsPerCentimeter) {
return CSSPrimitiveValue::create(
range.consumeIncludingWhitespace().numericValue(), unit);
}
return nullptr;
}
CSSIdentifierValue* consumeIdent(CSSParserTokenRange& range) { CSSIdentifierValue* consumeIdent(CSSParserTokenRange& range) {
if (range.peek().type() != IdentToken) if (range.peek().type() != IdentToken)
return nullptr; return nullptr;
......
...@@ -52,6 +52,7 @@ CSSPrimitiveValue* consumeLengthOrPercent( ...@@ -52,6 +52,7 @@ CSSPrimitiveValue* consumeLengthOrPercent(
UnitlessQuirk = UnitlessQuirk::Forbid); UnitlessQuirk = UnitlessQuirk::Forbid);
CSSPrimitiveValue* consumeAngle(CSSParserTokenRange&); CSSPrimitiveValue* consumeAngle(CSSParserTokenRange&);
CSSPrimitiveValue* consumeTime(CSSParserTokenRange&, ValueRange); CSSPrimitiveValue* consumeTime(CSSParserTokenRange&, ValueRange);
CSSPrimitiveValue* consumeResolution(CSSParserTokenRange&);
CSSIdentifierValue* consumeIdent(CSSParserTokenRange&); CSSIdentifierValue* consumeIdent(CSSParserTokenRange&);
CSSIdentifierValue* consumeIdentRange(CSSParserTokenRange&, CSSIdentifierValue* consumeIdentRange(CSSParserTokenRange&,
......
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