diff options
author | rob.buis <rob.buis@samsung.com> | 2015-11-30 17:42:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-01 01:43:38 +0000 |
commit | 53c8da9fe520c90bc1ae325dd4e0513b7851a56c (patch) | |
tree | 25ad7414f3e83c5cb9e9cf9a3aea65aa06c5e76c | |
parent | 4aee42cedfb7b235e754b7cf18d51921249a9b61 (diff) | |
download | chromium_src-53c8da9fe520c90bc1ae325dd4e0513b7851a56c.zip chromium_src-53c8da9fe520c90bc1ae325dd4e0513b7851a56c.tar.gz chromium_src-53c8da9fe520c90bc1ae325dd4e0513b7851a56c.tar.bz2 |
Move remaining SVG properties into CSSPropertyParser
Move remaining SVG property handling from
LegacyCSSPropertyParser into CSSPropertyParser.
With this change, the properties baseline-shift,
stroke-width and stroke-dashoffset will show
computed style without pixel units when set
using user units. Also support for percentages
in the opacity properties is removed as this
is not specified anywhere in the SVG specs.
BUG=499780
Review URL: https://codereview.chromium.org/1441233006
Cr-Commit-Position: refs/heads/master@{#362311}
7 files changed, 148 insertions, 152 deletions
diff --git a/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage-expected.txt b/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage-expected.txt new file mode 100644 index 0000000..a543bb5 --- /dev/null +++ b/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage-expected.txt @@ -0,0 +1,17 @@ +Test opacity properties combined with percentage. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS CSS.supports("stroke-opacity", "0%") is false +PASS CSS.supports("stroke-opacity", "100%") is false +PASS CSS.supports("flood-opacity", "0%") is false +PASS CSS.supports("flood-opacity", "100%") is false +PASS CSS.supports("stop-opacity", "0%") is false +PASS CSS.supports("stop-opacity", "100%") is false +PASS CSS.supports("opacity", "0%") is false +PASS CSS.supports("opacity", "100%") is false +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage.html b/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage.html new file mode 100644 index 0000000..ac7362c --- /dev/null +++ b/third_party/WebKit/LayoutTests/svg/css/opacity-not-supporting-percentage.html @@ -0,0 +1,23 @@ +<!DOCTYPE HTML> +<html> +<head> +<script src="../../resources/js-test.js"></script> +</head> +<body> +<script> + description("Test opacity properties combined with percentage."); + + shouldBeFalse('CSS.supports("stroke-opacity", "0%")'); + shouldBeFalse('CSS.supports("stroke-opacity", "100%")'); + + shouldBeFalse('CSS.supports("flood-opacity", "0%")'); + shouldBeFalse('CSS.supports("flood-opacity", "100%")'); + + shouldBeFalse('CSS.supports("stop-opacity", "0%")'); + shouldBeFalse('CSS.supports("stop-opacity", "100%")'); + + shouldBeFalse('CSS.supports("opacity", "0%")'); + shouldBeFalse('CSS.supports("opacity", "100%")'); +</script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/svg/css/scientific-numbers-expected.txt b/third_party/WebKit/LayoutTests/svg/css/scientific-numbers-expected.txt index 9261b90..f0a3871 100644 --- a/third_party/WebKit/LayoutTests/svg/css/scientific-numbers-expected.txt +++ b/third_party/WebKit/LayoutTests/svg/css/scientific-numbers-expected.txt @@ -6,53 +6,53 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE Test positive exponent values with 'e' PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" Test positive exponent values with 'E' PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" Test negative exponent values with 'e' PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" PASS text.style.baselineShift is "50px" PASS text.style.baselineShift is "baseline" @@ -60,13 +60,13 @@ PASS text.style.baselineShift is "50px" Test negative exponent values with 'E' PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" PASS text.style.baselineShift is "50px" PASS text.style.baselineShift is "baseline" @@ -90,9 +90,9 @@ PASS text.style.baselineShift is "50ex" Trailing and leading whitespaces PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" PASS text.style.baselineShift is "baseline" -PASS text.style.baselineShift is "50px" +PASS text.style.baselineShift is "50" Test behavior on overflow PASS text.style.baselineShift is "baseline" diff --git a/third_party/WebKit/LayoutTests/svg/css/script-tests/scientific-numbers.js b/third_party/WebKit/LayoutTests/svg/css/script-tests/scientific-numbers.js index 938cc2a..3b46d21 100644 --- a/third_party/WebKit/LayoutTests/svg/css/script-tests/scientific-numbers.js +++ b/third_party/WebKit/LayoutTests/svg/css/script-tests/scientific-numbers.js @@ -21,43 +21,43 @@ function test(valueString, expectedValue) { debug(""); debug("Test positive exponent values with 'e'"); -test(".5e2", "50px"); -test("5e1", "50px"); -test("0.5e2", "50px"); -test("+.5e2", "50px"); -test("+5e1", "50px"); -test("+0.5e2", "50px"); -test(".5e+2", "50px"); -test("5e+1", "50px"); -test("0.5e+2", "50px"); +test(".5e2", "50"); +test("5e1", "50"); +test("0.5e2", "50"); +test("+.5e2", "50"); +test("+5e1", "50"); +test("+0.5e2", "50"); +test(".5e+2", "50"); +test("5e+1", "50"); +test("0.5e+2", "50"); debug(""); debug("Test positive exponent values with 'E'"); -test(".5E2", "50px"); -test("5E1", "50px"); -test("0.5E2", "50px"); -test("+.5E2", "50px"); -test("+5E1", "50px"); -test("+0.5E2", "50px"); -test(".5E+2", "50px"); -test("5E+1", "50px"); -test("0.5E+2", "50px"); +test(".5E2", "50"); +test("5E1", "50"); +test("0.5E2", "50"); +test("+.5E2", "50"); +test("+5E1", "50"); +test("+0.5E2", "50"); +test(".5E+2", "50"); +test("5E+1", "50"); +test("0.5E+2", "50"); debug(""); debug("Test negative exponent values with 'e'"); -test("5000e-2", "50px"); -test("500e-1", "50px"); -test("+5000e-2", "50px"); -test("+500e-1", "50px"); +test("5000e-2", "50"); +test("500e-1", "50"); +test("+5000e-2", "50"); +test("+500e-1", "50"); test("+5000e-2px", "50px"); test("+500e-1px", "50px"); debug(""); debug("Test negative exponent values with 'E'"); -test("5000E-2", "50px"); -test("500E-1", "50px"); -test("+5000E-2", "50px"); -test("+500E-1", "50px"); +test("5000E-2", "50"); +test("500E-1", "50"); +test("+5000E-2", "50"); +test("+500E-1", "50"); test("+5000.00E-2px", "50px"); test("+500E-1px", "50px"); @@ -77,8 +77,8 @@ test("50ex", "50ex"); debug(""); debug("Trailing and leading whitespaces"); -test(" 5e1", "50px"); -test("5e1 ", "50px"); +test(" 5e1", "50"); +test("5e1 ", "50"); debug(""); debug("Test behavior on overflow"); diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp index ef06ea5..08f9291 100644 --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp @@ -2096,6 +2096,14 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeStrokeDasharray(CSSParserTokenRan return dashes.release(); } +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeBaselineShift(CSSParserTokenRange& range) +{ + CSSValueID id = range.peek().id(); + if (id == CSSValueBaseline || id == CSSValueSub || id == CSSValueSuper) + return consumeIdent(range); + return consumeLengthOrPercent(range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid); +} + PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty) { CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); @@ -2274,6 +2282,9 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty case CSSPropertyMarkerStart: case CSSPropertyMarkerMid: case CSSPropertyMarkerEnd: + case CSSPropertyClipPath: + case CSSPropertyFilter: + case CSSPropertyMask: return consumeNoneOrURI(m_range); case CSSPropertyFlexBasis: return consumeFlexBasis(m_range, m_context.mode()); @@ -2284,6 +2295,25 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty return consumeStrokeDasharray(m_range); case CSSPropertyWebkitColumnRuleWidth: return consumeColumnRuleWidth(m_range, m_context.mode()); + case CSSPropertyStrokeOpacity: + case CSSPropertyFillOpacity: + case CSSPropertyStopOpacity: + case CSSPropertyFloodOpacity: + return consumeNumber(m_range, ValueRangeAll); + case CSSPropertyBaselineShift: + return consumeBaselineShift(m_range); + case CSSPropertyStrokeMiterlimit: + return consumeNumber(m_range, ValueRangeNonNegative); + case CSSPropertyStrokeWidth: + case CSSPropertyStrokeDashoffset: + case CSSPropertyCx: + case CSSPropertyCy: + case CSSPropertyX: + case CSSPropertyY: + case CSSPropertyR: + case CSSPropertyRx: + case CSSPropertyRy: + return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid); default: return nullptr; } diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h index 2b2c760..ea3e8ce 100644 --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h @@ -200,8 +200,6 @@ private: PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceSrc(); - bool parseSVGValue(CSSPropertyID propId, bool important); - // CSS3 Parsing Routines (for properties specific to CSS3) bool parseBorderImageShorthand(CSSPropertyID, bool important); PassRefPtrWillBeRawPtr<CSSValue> parseBorderImage(CSSPropertyID); diff --git a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp index 09ad1cf..c9696bb 100644 --- a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp +++ b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp @@ -1090,6 +1090,24 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import case CSSPropertyWebkitColumnRule: case CSSPropertyWebkitColumnRuleColor: case CSSPropertyWebkitColumnRuleWidth: + case CSSPropertyClipPath: + case CSSPropertyFilter: + case CSSPropertyMask: + case CSSPropertyStrokeOpacity: + case CSSPropertyFillOpacity: + case CSSPropertyStopOpacity: + case CSSPropertyFloodOpacity: + case CSSPropertyBaselineShift: + case CSSPropertyStrokeMiterlimit: + case CSSPropertyStrokeWidth: + case CSSPropertyStrokeDashoffset: + case CSSPropertyCx: + case CSSPropertyCy: + case CSSPropertyX: + case CSSPropertyY: + case CSSPropertyR: + case CSSPropertyRx: + case CSSPropertyRy: validPrimitive = false; break; @@ -1105,7 +1123,10 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import break; default: - return parseSVGValue(propId, important); + // If you crash here, it's because you added a css property and are not handling it + // in either this switch statement or the one in CSSPropertyParser::parseSingleValue. + ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId); + return false; } if (validPrimitive) { @@ -5293,97 +5314,4 @@ bool CSSPropertyParser::isSystemColor(CSSValueID id) return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSSValueMenu; } -bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important) -{ - CSSParserValue* value = m_valueList->current(); - ASSERT(value); - - CSSValueID id = value->id; - - bool validPrimitive = false; - RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; - - switch (propId) { - /* The comment to the right defines all valid value of these - * properties as defined in SVG 1.1, Appendix N. Property index */ - case CSSPropertyBaselineShift: - // baseline | super | sub | <percentage> | <length> | inherit - if (id == CSSValueBaseline || id == CSSValueSub || id == CSSValueSuper) - validPrimitive = true; - else - validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode); - break; - - case CSSPropertyClipPath: - case CSSPropertyFilter: - case CSSPropertyMask: - if (id == CSSValueNone) { - validPrimitive = true; - } else if (value->m_unit == CSSParserValue::URI) { - parsedValue = CSSURIValue::create(value->string); - if (parsedValue) - m_valueList->next(); - } - break; - - case CSSPropertyStrokeMiterlimit: // <miterlimit> | inherit - validPrimitive = validUnit(value, FNumber | FNonNeg, SVGAttributeMode); - break; - - case CSSPropertyStrokeOpacity: // <opacity-value> | inherit - case CSSPropertyFillOpacity: - case CSSPropertyStopOpacity: - case CSSPropertyFloodOpacity: - validPrimitive = validUnit(value, FNumber | FPercent, SVGAttributeMode); - break; - - /* Start of supported CSS properties with validation. This is needed for parseShortHand to work - * correctly and allows optimization in applyRule(..) - */ - - case CSSPropertyStrokeWidth: // <length> | inherit - case CSSPropertyStrokeDashoffset: - case CSSPropertyCx: - case CSSPropertyCy: - case CSSPropertyX: - case CSSPropertyY: - case CSSPropertyR: - case CSSPropertyRx: - case CSSPropertyRy: - validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode); - break; - - default: - // If you crash here, it's because you added a css property and are not handling it - // in either this switch statement or the one in CSSPropertyParser::parseValue - ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId); - return false; - } - - if (validPrimitive) { - if (id) - parsedValue = CSSPrimitiveValue::createIdentifier(id); - else if (value->m_unit == CSSParserValue::String) - parsedValue = CSSStringValue::create(value->string); - else if (value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit() <= CSSPrimitiveValue::UnitType::Kilohertz) - parsedValue = CSSPrimitiveValue::create(value->fValue, value->unit()); - else if (value->unit() == CSSPrimitiveValue::UnitType::Rems || value->unit() == CSSPrimitiveValue::UnitType::Chs) - parsedValue = CSSPrimitiveValue::create(value->fValue, value->unit()); - else if (value->unit() == CSSPrimitiveValue::UnitType::QuirkyEms) - parsedValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveValue::UnitType::QuirkyEms); - if (isCalculation(value)) { - // FIXME calc() http://webkit.org/b/16662 : actually create a CSSPrimitiveValue here, ie - // parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.release()); - m_parsedCalculation.release(); - parsedValue = nullptr; - } - m_valueList->next(); - } - if (!parsedValue || (m_valueList->current() && !inShorthand())) - return false; - - addProperty(propId, parsedValue.release(), important); - return true; -} - } // namespace blink |