OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
9 #include "core/css/CSSBasicShapeValues.h" | 9 #include "core/css/CSSBasicShapeValues.h" |
10 #include "core/css/CSSBorderImage.h" | 10 #include "core/css/CSSBorderImage.h" |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // FIXME (crbug.com/397061): Support calc expressions like calc(10% + 0.5) | 809 // FIXME (crbug.com/397061): Support calc expressions like calc(10% + 0.5) |
810 parsedValue = consumePercent(args, ValueRangeNonNegative); | 810 parsedValue = consumePercent(args, ValueRangeNonNegative); |
811 if (!parsedValue) | 811 if (!parsedValue) |
812 parsedValue = consumeNumber(args, ValueRangeNonNegative); | 812 parsedValue = consumeNumber(args, ValueRangeNonNegative); |
813 if (parsedValue && filterType != CSSValueSaturate && | 813 if (parsedValue && filterType != CSSValueSaturate && |
814 filterType != CSSValueContrast) { | 814 filterType != CSSValueContrast) { |
815 bool isPercentage = toCSSPrimitiveValue(parsedValue)->isPercentage(); | 815 bool isPercentage = toCSSPrimitiveValue(parsedValue)->isPercentage(); |
816 double maxAllowed = isPercentage ? 100.0 : 1.0; | 816 double maxAllowed = isPercentage ? 100.0 : 1.0; |
817 if (toCSSPrimitiveValue(parsedValue)->getDoubleValue() > maxAllowed) { | 817 if (toCSSPrimitiveValue(parsedValue)->getDoubleValue() > maxAllowed) { |
818 parsedValue = CSSPrimitiveValue::create( | 818 parsedValue = CSSPrimitiveValue::create( |
819 maxAllowed, isPercentage ? CSSPrimitiveValue::UnitType::Percentage | 819 maxAllowed, |
820 : CSSPrimitiveValue::UnitType::Number); | 820 isPercentage ? CSSPrimitiveValue::UnitType::Percentage |
| 821 : CSSPrimitiveValue::UnitType::Number); |
821 } | 822 } |
822 } | 823 } |
823 } | 824 } |
824 } | 825 } |
825 if (!parsedValue || !args.atEnd()) | 826 if (!parsedValue || !args.atEnd()) |
826 return nullptr; | 827 return nullptr; |
827 filterValue->append(*parsedValue); | 828 filterValue->append(*parsedValue); |
828 return filterValue; | 829 return filterValue; |
829 } | 830 } |
830 | 831 |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 static CSSValue* consumeGridTrackSize(CSSParserTokenRange& range, | 1790 static CSSValue* consumeGridTrackSize(CSSParserTokenRange& range, |
1790 CSSParserMode cssParserMode) { | 1791 CSSParserMode cssParserMode) { |
1791 const CSSParserToken& token = range.peek(); | 1792 const CSSParserToken& token = range.peek(); |
1792 if (identMatches<CSSValueAuto>(token.id())) | 1793 if (identMatches<CSSValueAuto>(token.id())) |
1793 return consumeIdent(range); | 1794 return consumeIdent(range); |
1794 | 1795 |
1795 if (token.functionId() == CSSValueMinmax) { | 1796 if (token.functionId() == CSSValueMinmax) { |
1796 CSSParserTokenRange rangeCopy = range; | 1797 CSSParserTokenRange rangeCopy = range; |
1797 CSSParserTokenRange args = consumeFunction(rangeCopy); | 1798 CSSParserTokenRange args = consumeFunction(rangeCopy); |
1798 CSSValue* minTrackBreadth = consumeGridBreadth(args, cssParserMode); | 1799 CSSValue* minTrackBreadth = consumeGridBreadth(args, cssParserMode); |
1799 if (!minTrackBreadth || (minTrackBreadth->isPrimitiveValue() && | 1800 if (!minTrackBreadth || |
1800 toCSSPrimitiveValue(minTrackBreadth)->isFlex()) || | 1801 (minTrackBreadth->isPrimitiveValue() && |
| 1802 toCSSPrimitiveValue(minTrackBreadth)->isFlex()) || |
1801 !consumeCommaIncludingWhitespace(args)) | 1803 !consumeCommaIncludingWhitespace(args)) |
1802 return nullptr; | 1804 return nullptr; |
1803 CSSValue* maxTrackBreadth = consumeGridBreadth(args, cssParserMode); | 1805 CSSValue* maxTrackBreadth = consumeGridBreadth(args, cssParserMode); |
1804 if (!maxTrackBreadth || !args.atEnd()) | 1806 if (!maxTrackBreadth || !args.atEnd()) |
1805 return nullptr; | 1807 return nullptr; |
1806 range = rangeCopy; | 1808 range = rangeCopy; |
1807 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueMinmax); | 1809 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueMinmax); |
1808 result->append(*minTrackBreadth); | 1810 result->append(*minTrackBreadth); |
1809 result->append(*maxTrackBreadth); | 1811 result->append(*maxTrackBreadth); |
1810 return result; | 1812 return result; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 case CSSPropertyWebkitBorderStartWidth: | 2132 case CSSPropertyWebkitBorderStartWidth: |
2131 case CSSPropertyWebkitBorderEndWidth: | 2133 case CSSPropertyWebkitBorderEndWidth: |
2132 case CSSPropertyWebkitBorderBeforeWidth: | 2134 case CSSPropertyWebkitBorderBeforeWidth: |
2133 case CSSPropertyWebkitBorderAfterWidth: | 2135 case CSSPropertyWebkitBorderAfterWidth: |
2134 return consumeBorderWidth(m_range, m_context->mode(), | 2136 return consumeBorderWidth(m_range, m_context->mode(), |
2135 UnitlessQuirk::Forbid); | 2137 UnitlessQuirk::Forbid); |
2136 case CSSPropertyBorderBottomColor: | 2138 case CSSPropertyBorderBottomColor: |
2137 case CSSPropertyBorderLeftColor: | 2139 case CSSPropertyBorderLeftColor: |
2138 case CSSPropertyBorderRightColor: | 2140 case CSSPropertyBorderRightColor: |
2139 case CSSPropertyBorderTopColor: { | 2141 case CSSPropertyBorderTopColor: { |
2140 bool allowQuirkyColors = | 2142 bool allowQuirkyColors = inQuirksMode() && |
2141 inQuirksMode() && (currentShorthand == CSSPropertyInvalid || | 2143 (currentShorthand == CSSPropertyInvalid || |
2142 currentShorthand == CSSPropertyBorderColor); | 2144 currentShorthand == CSSPropertyBorderColor); |
2143 return consumeColor(m_range, m_context->mode(), allowQuirkyColors); | 2145 return consumeColor(m_range, m_context->mode(), allowQuirkyColors); |
2144 } | 2146 } |
2145 case CSSPropertyBorderBottomWidth: | 2147 case CSSPropertyBorderBottomWidth: |
2146 case CSSPropertyBorderLeftWidth: | 2148 case CSSPropertyBorderLeftWidth: |
2147 case CSSPropertyBorderRightWidth: | 2149 case CSSPropertyBorderRightWidth: |
2148 case CSSPropertyBorderTopWidth: { | 2150 case CSSPropertyBorderTopWidth: { |
2149 bool allowQuirkyLengths = | 2151 bool allowQuirkyLengths = inQuirksMode() && |
2150 inQuirksMode() && (currentShorthand == CSSPropertyInvalid || | 2152 (currentShorthand == CSSPropertyInvalid || |
2151 currentShorthand == CSSPropertyBorderWidth); | 2153 currentShorthand == CSSPropertyBorderWidth); |
2152 UnitlessQuirk unitless = | 2154 UnitlessQuirk unitless = |
2153 allowQuirkyLengths ? UnitlessQuirk::Allow : UnitlessQuirk::Forbid; | 2155 allowQuirkyLengths ? UnitlessQuirk::Allow : UnitlessQuirk::Forbid; |
2154 return consumeBorderWidth(m_range, m_context->mode(), unitless); | 2156 return consumeBorderWidth(m_range, m_context->mode(), unitless); |
2155 } | 2157 } |
2156 case CSSPropertyTextShadow: | 2158 case CSSPropertyTextShadow: |
2157 case CSSPropertyBoxShadow: | 2159 case CSSPropertyBoxShadow: |
2158 return consumeShadow(m_range, m_context->mode(), | 2160 return consumeShadow(m_range, m_context->mode(), |
2159 property == CSSPropertyBoxShadow); | 2161 property == CSSPropertyBoxShadow); |
2160 case CSSPropertyFilter: | 2162 case CSSPropertyFilter: |
2161 case CSSPropertyBackdropFilter: | 2163 case CSSPropertyBackdropFilter: |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 if (id == CSSValueInherit || id == CSSValueInitial) | 2468 if (id == CSSValueInherit || id == CSSValueInitial) |
2467 return false; | 2469 return false; |
2468 } | 2470 } |
2469 // Optional font-style, font-variant, font-stretch and font-weight. | 2471 // Optional font-style, font-variant, font-stretch and font-weight. |
2470 CSSIdentifierValue* fontStyle = nullptr; | 2472 CSSIdentifierValue* fontStyle = nullptr; |
2471 CSSIdentifierValue* fontVariantCaps = nullptr; | 2473 CSSIdentifierValue* fontVariantCaps = nullptr; |
2472 CSSIdentifierValue* fontWeight = nullptr; | 2474 CSSIdentifierValue* fontWeight = nullptr; |
2473 CSSIdentifierValue* fontStretch = nullptr; | 2475 CSSIdentifierValue* fontStretch = nullptr; |
2474 while (!m_range.atEnd()) { | 2476 while (!m_range.atEnd()) { |
2475 CSSValueID id = m_range.peek().id(); | 2477 CSSValueID id = m_range.peek().id(); |
2476 if (!fontStyle && CSSParserFastPaths::isValidKeywordPropertyAndValue( | 2478 if (!fontStyle && |
2477 CSSPropertyFontStyle, id, m_context->mode())) { | 2479 CSSParserFastPaths::isValidKeywordPropertyAndValue( |
| 2480 CSSPropertyFontStyle, id, m_context->mode())) { |
2478 fontStyle = consumeIdent(m_range); | 2481 fontStyle = consumeIdent(m_range); |
2479 continue; | 2482 continue; |
2480 } | 2483 } |
2481 if (!fontVariantCaps && (id == CSSValueNormal || id == CSSValueSmallCaps)) { | 2484 if (!fontVariantCaps && (id == CSSValueNormal || id == CSSValueSmallCaps)) { |
2482 // Font variant in the shorthand is particular, it only accepts normal or | 2485 // Font variant in the shorthand is particular, it only accepts normal or |
2483 // small-caps. | 2486 // small-caps. |
2484 // See https://drafts.csswg.org/css-fonts/#propdef-font | 2487 // See https://drafts.csswg.org/css-fonts/#propdef-font |
2485 fontVariantCaps = consumeFontVariantCSS21(m_range); | 2488 fontVariantCaps = consumeFontVariantCSS21(m_range); |
2486 if (fontVariantCaps) | 2489 if (fontVariantCaps) |
2487 continue; | 2490 continue; |
2488 } | 2491 } |
2489 if (!fontWeight) { | 2492 if (!fontWeight) { |
2490 fontWeight = consumeFontWeight(m_range); | 2493 fontWeight = consumeFontWeight(m_range); |
2491 if (fontWeight) | 2494 if (fontWeight) |
2492 continue; | 2495 continue; |
2493 } | 2496 } |
2494 if (!fontStretch && CSSParserFastPaths::isValidKeywordPropertyAndValue( | 2497 if (!fontStretch && |
2495 CSSPropertyFontStretch, id, m_context->mode())) | 2498 CSSParserFastPaths::isValidKeywordPropertyAndValue( |
| 2499 CSSPropertyFontStretch, id, m_context->mode())) |
2496 fontStretch = consumeIdent(m_range); | 2500 fontStretch = consumeIdent(m_range); |
2497 else | 2501 else |
2498 break; | 2502 break; |
2499 } | 2503 } |
2500 | 2504 |
2501 if (m_range.atEnd()) | 2505 if (m_range.atEnd()) |
2502 return false; | 2506 return false; |
2503 | 2507 |
2504 addProperty( | 2508 addProperty( |
2505 CSSPropertyFontStyle, CSSPropertyFont, | 2509 CSSPropertyFontStyle, CSSPropertyFont, |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3769 case CSSPropertyGridTemplate: | 3773 case CSSPropertyGridTemplate: |
3770 return consumeGridTemplateShorthand(CSSPropertyGridTemplate, important); | 3774 return consumeGridTemplateShorthand(CSSPropertyGridTemplate, important); |
3771 case CSSPropertyGrid: | 3775 case CSSPropertyGrid: |
3772 return consumeGridShorthand(important); | 3776 return consumeGridShorthand(important); |
3773 default: | 3777 default: |
3774 return false; | 3778 return false; |
3775 } | 3779 } |
3776 } | 3780 } |
3777 | 3781 |
3778 } // namespace blink | 3782 } // namespace blink |
OLD | NEW |