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 "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSPropertyParser.h" | 6 #include "core/css/parser/CSSPropertyParser.h" |
7 | 7 |
8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
| 10 #include "core/css/CSSCounterValue.h" |
10 #include "core/css/CSSCrossfadeValue.h" | 11 #include "core/css/CSSCrossfadeValue.h" |
11 #include "core/css/CSSCursorImageValue.h" | 12 #include "core/css/CSSCursorImageValue.h" |
12 #include "core/css/CSSCustomIdentValue.h" | 13 #include "core/css/CSSCustomIdentValue.h" |
13 #include "core/css/CSSFontFaceSrcValue.h" | 14 #include "core/css/CSSFontFaceSrcValue.h" |
14 #include "core/css/CSSFontFeatureValue.h" | 15 #include "core/css/CSSFontFeatureValue.h" |
15 #include "core/css/CSSFunctionValue.h" | 16 #include "core/css/CSSFunctionValue.h" |
16 #include "core/css/CSSImageSetValue.h" | 17 #include "core/css/CSSImageSetValue.h" |
17 #include "core/css/CSSPathValue.h" | 18 #include "core/css/CSSPathValue.h" |
18 #include "core/css/CSSPrimitiveValueMappings.h" | 19 #include "core/css/CSSPrimitiveValueMappings.h" |
19 #include "core/css/CSSQuadValue.h" | 20 #include "core/css/CSSQuadValue.h" |
(...skipping 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2789 if (range.peek().type() == FunctionToken) { | 2790 if (range.peek().type() == FunctionToken) { |
2790 CSSValueID id = range.peek().functionId(); | 2791 CSSValueID id = range.peek().functionId(); |
2791 if (id == CSSValueWebkitImageSet) | 2792 if (id == CSSValueWebkitImageSet) |
2792 return consumeImageSet(range, context); | 2793 return consumeImageSet(range, context); |
2793 if (CSSPropertyParser::isGeneratedImage(id)) | 2794 if (CSSPropertyParser::isGeneratedImage(id)) |
2794 return consumeGeneratedImage(range, context); | 2795 return consumeGeneratedImage(range, context); |
2795 } | 2796 } |
2796 return nullptr; | 2797 return nullptr; |
2797 } | 2798 } |
2798 | 2799 |
| 2800 static PassRefPtrWillBeRawPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CS
SParserContext context) |
| 2801 { |
| 2802 if (args.peek().type() != IdentToken) |
| 2803 return nullptr; |
| 2804 |
| 2805 String attrName = args.consumeIncludingWhitespace().value(); |
| 2806 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image". |
| 2807 // But HTML attribute names can't have those characters, and we should not |
| 2808 // even parse them inside attr(). |
| 2809 // TODO(timloh): We should allow any <ident-token> here. |
| 2810 if (attrName[0] == '-' || !args.atEnd()) |
| 2811 return nullptr; |
| 2812 |
| 2813 if (context.isHTMLDocument()) |
| 2814 attrName = attrName.lower(); |
| 2815 |
| 2816 RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CS
SValueAttr); |
| 2817 attrValue->append(CSSCustomIdentValue::create(attrName)); |
| 2818 return attrValue.release(); |
| 2819 } |
| 2820 |
| 2821 static PassRefPtrWillBeRawPtr<CSSValue> consumeCounterContent(CSSParserTokenRang
e args, bool counters) |
| 2822 { |
| 2823 RefPtrWillBeRawPtr<CSSCustomIdentValue> identifier = consumeCustomIdent(args
); |
| 2824 if (!identifier) |
| 2825 return nullptr; |
| 2826 |
| 2827 // TODO(timloh): Make this a CSSStringValue. |
| 2828 RefPtrWillBeRawPtr<CSSCustomIdentValue> separator = nullptr; |
| 2829 if (!counters) { |
| 2830 separator = CSSCustomIdentValue::create(String()); |
| 2831 } else { |
| 2832 if (!consumeCommaIncludingWhitespace(args)) |
| 2833 return nullptr; |
| 2834 if (args.peek().type() != StringToken) |
| 2835 return nullptr; |
| 2836 separator = CSSCustomIdentValue::create(args.consumeIncludingWhitespace(
).value()); |
| 2837 } |
| 2838 |
| 2839 RefPtrWillBeRawPtr<CSSPrimitiveValue> listStyle = nullptr; |
| 2840 if (consumeCommaIncludingWhitespace(args)) { |
| 2841 CSSValueID id = args.peek().id(); |
| 2842 if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIr
oha))) |
| 2843 return nullptr; |
| 2844 listStyle = consumeIdent(args); |
| 2845 } else { |
| 2846 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); |
| 2847 } |
| 2848 |
| 2849 if (!args.atEnd()) |
| 2850 return nullptr; |
| 2851 return CSSCounterValue::create(identifier.release(), listStyle.release(), se
parator.release()); |
| 2852 } |
| 2853 |
| 2854 static PassRefPtrWillBeRawPtr<CSSValueList> consumeContent(CSSParserTokenRange&
range, CSSParserContext context) |
| 2855 { |
| 2856 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated
(); |
| 2857 |
| 2858 do { |
| 2859 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeImage(range, context); |
| 2860 if (!parsedValue) |
| 2861 parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CS
SValueNoOpenQuote, CSSValueNoCloseQuote, CSSValueNormal>(range); |
| 2862 if (!parsedValue) |
| 2863 parsedValue = consumeString(range); |
| 2864 if (!parsedValue) { |
| 2865 if (range.peek().functionId() == CSSValueAttr) |
| 2866 parsedValue = consumeAttr(consumeFunction(range), context); |
| 2867 else if (range.peek().functionId() == CSSValueCounter) |
| 2868 parsedValue = consumeCounterContent(consumeFunction(range), fals
e); |
| 2869 else if (range.peek().functionId() == CSSValueCounters) |
| 2870 parsedValue = consumeCounterContent(consumeFunction(range), true
); |
| 2871 if (!parsedValue) |
| 2872 return nullptr; |
| 2873 } |
| 2874 values->append(parsedValue.release()); |
| 2875 } while (!range.atEnd()); |
| 2876 |
| 2877 return values.release(); |
| 2878 } |
| 2879 |
2799 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) | 2880 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) |
2800 { | 2881 { |
2801 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2882 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
2802 switch (property) { | 2883 switch (property) { |
2803 case CSSPropertyWillChange: | 2884 case CSSPropertyWillChange: |
2804 return consumeWillChange(m_range); | 2885 return consumeWillChange(m_range); |
2805 case CSSPropertyPage: | 2886 case CSSPropertyPage: |
2806 return consumePage(m_range); | 2887 return consumePage(m_range); |
2807 case CSSPropertyQuotes: | 2888 case CSSPropertyQuotes: |
2808 return consumeQuotes(m_range); | 2889 return consumeQuotes(m_range); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3030 case CSSPropertyR: | 3111 case CSSPropertyR: |
3031 case CSSPropertyRx: | 3112 case CSSPropertyRx: |
3032 case CSSPropertyRy: | 3113 case CSSPropertyRy: |
3033 return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll,
UnitlessQuirk::Forbid); | 3114 return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll,
UnitlessQuirk::Forbid); |
3034 case CSSPropertyCursor: | 3115 case CSSPropertyCursor: |
3035 return consumeCursor(m_range, m_context, inQuirksMode()); | 3116 return consumeCursor(m_range, m_context, inQuirksMode()); |
3036 case CSSPropertyContain: | 3117 case CSSPropertyContain: |
3037 return consumeContain(m_range); | 3118 return consumeContain(m_range); |
3038 case CSSPropertyTransformOrigin: | 3119 case CSSPropertyTransformOrigin: |
3039 return consumeTransformOrigin(m_range, m_context.mode(), UnitlessQuirk::
Forbid); | 3120 return consumeTransformOrigin(m_range, m_context.mode(), UnitlessQuirk::
Forbid); |
| 3121 case CSSPropertyContent: |
| 3122 return consumeContent(m_range, m_context); |
3040 default: | 3123 default: |
3041 return nullptr; | 3124 return nullptr; |
3042 } | 3125 } |
3043 } | 3126 } |
3044 | 3127 |
3045 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) | 3128 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) |
3046 { | 3129 { |
3047 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); | 3130 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); |
3048 | 3131 |
3049 do { | 3132 do { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 return consumeShorthandGreedily(flexFlowShorthand(), important); | 3710 return consumeShorthandGreedily(flexFlowShorthand(), important); |
3628 case CSSPropertyWebkitColumnRule: | 3711 case CSSPropertyWebkitColumnRule: |
3629 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); | 3712 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); |
3630 default: | 3713 default: |
3631 m_currentShorthand = oldShorthand; | 3714 m_currentShorthand = oldShorthand; |
3632 return false; | 3715 return false; |
3633 } | 3716 } |
3634 } | 3717 } |
3635 | 3718 |
3636 } // namespace blink | 3719 } // namespace blink |
OLD | NEW |