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 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2610 if (range.peek().type() == FunctionToken) { | 2611 if (range.peek().type() == FunctionToken) { |
2611 CSSValueID id = range.peek().functionId(); | 2612 CSSValueID id = range.peek().functionId(); |
2612 if (id == CSSValueWebkitImageSet) | 2613 if (id == CSSValueWebkitImageSet) |
2613 return consumeImageSet(range, context); | 2614 return consumeImageSet(range, context); |
2614 if (CSSPropertyParser::isGeneratedImage(id)) | 2615 if (CSSPropertyParser::isGeneratedImage(id)) |
2615 return consumeGeneratedImage(range, context); | 2616 return consumeGeneratedImage(range, context); |
2616 } | 2617 } |
2617 return nullptr; | 2618 return nullptr; |
2618 } | 2619 } |
2619 | 2620 |
2621 static PassRefPtrWillBeRawPtr<CSSValue> consumeAttr(CSSParserTokenRange args, CS SParserContext context) | |
2622 { | |
2623 if (args.peek().type() != IdentToken) | |
2624 return nullptr; | |
2625 | |
2626 String attrName = args.consumeIncludingWhitespace().value(); | |
2627 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image". | |
2628 // But HTML attribute names can't have those characters, and we should not | |
Timothy Loh
2015/12/15 04:44:54
This comment seems wrong. The HTML spec doesn't se
| |
2629 // even parse them inside attr(). | |
2630 if (attrName[0] == '-' || !args.atEnd()) | |
2631 return nullptr; | |
2632 | |
2633 if (context.isHTMLDocument()) | |
2634 attrName = attrName.lower(); | |
2635 | |
2636 RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CS SValueAttr); | |
2637 attrValue->append(CSSCustomIdentValue::create(attrName)); | |
2638 return attrValue.release(); | |
2639 } | |
2640 | |
2641 static PassRefPtrWillBeRawPtr<CSSValue> consumeCounterContent(CSSParserTokenRang e args, bool counters) | |
2642 { | |
2643 RefPtrWillBeRawPtr<CSSCustomIdentValue> identifier = consumeCustomIdent(args ); | |
2644 if (!identifier) | |
2645 return nullptr; | |
2646 | |
2647 RefPtrWillBeRawPtr<CSSCustomIdentValue> separator = nullptr; | |
Timothy Loh
2015/12/15 04:44:54
I guess I'll take a TODO here...
// TODO(timloh):
| |
2648 if (!counters) { | |
2649 separator = CSSCustomIdentValue::create(String()); | |
2650 } else { | |
2651 if (!consumeCommaIncludingWhitespace(args)) | |
2652 return nullptr; | |
2653 if (args.peek().type() != StringToken) | |
2654 return nullptr; | |
2655 separator = CSSCustomIdentValue::create(args.consumeIncludingWhitespace( ).value()); | |
2656 } | |
2657 | |
2658 RefPtrWillBeRawPtr<CSSPrimitiveValue> listStyle = nullptr; | |
2659 if (args.atEnd()) { // Make the list style default decimal | |
Timothy Loh
2015/12/15 04:44:54
How about (one less args.atEnd(), longest line isn
| |
2660 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); | |
2661 } else { | |
2662 if (!consumeCommaIncludingWhitespace(args)) | |
2663 return nullptr; | |
2664 CSSValueID id = args.consumeIncludingWhitespace().id(); | |
2665 if ((id != CSSValueNone && (id < CSSValueDisc || id > CSSValueKatakanaIr oha)) || !args.atEnd()) | |
2666 return nullptr; | |
2667 listStyle = cssValuePool().createIdentifierValue(id); | |
2668 } | |
2669 | |
2670 return CSSCounterValue::create(identifier.release(), listStyle.release(), se parator.release()); | |
2671 } | |
2672 | |
2673 static PassRefPtrWillBeRawPtr<CSSValueList> consumeContent(CSSParserTokenRange& range, CSSParserContext context) | |
2674 { | |
2675 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); | |
2676 | |
2677 do { | |
2678 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeImage(range, context); | |
2679 if (!parsedValue) { | |
2680 parsedValue = consumeIdent<CSSValueOpenQuote, CSSValueCloseQuote, CS SValueNoOpenQuote, CSSValueNoCloseQuote, CSSValueNormal>(range); | |
2681 if (!parsedValue) | |
Timothy Loh
2015/12/15 04:44:54
I think it'd look nicer if these weren't nested --
| |
2682 parsedValue = consumeString(range); | |
2683 if (!parsedValue) { | |
2684 if (range.peek().type() == FunctionToken) { | |
2685 if (range.peek().functionId() == CSSValueAttr) | |
2686 parsedValue = consumeAttr(consumeFunction(range), contex t); | |
2687 else if (range.peek().functionId() == CSSValueCounter) | |
2688 parsedValue = consumeCounterContent(consumeFunction(rang e), false); | |
2689 else if (range.peek().functionId() == CSSValueCounters) | |
2690 parsedValue = consumeCounterContent(consumeFunction(rang e), true); | |
2691 } | |
2692 if (!parsedValue) | |
2693 return nullptr; | |
2694 } | |
2695 } | |
2696 values->append(parsedValue.release()); | |
2697 } while (!range.atEnd()); | |
2698 | |
2699 return values.release(); | |
2700 } | |
2701 | |
2620 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 2702 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
2621 { | 2703 { |
2622 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2704 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
2623 switch (property) { | 2705 switch (property) { |
2624 case CSSPropertyWillChange: | 2706 case CSSPropertyWillChange: |
2625 return consumeWillChange(m_range); | 2707 return consumeWillChange(m_range); |
2626 case CSSPropertyPage: | 2708 case CSSPropertyPage: |
2627 return consumePage(m_range); | 2709 return consumePage(m_range); |
2628 case CSSPropertyQuotes: | 2710 case CSSPropertyQuotes: |
2629 return consumeQuotes(m_range); | 2711 return consumeQuotes(m_range); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2849 case CSSPropertyR: | 2931 case CSSPropertyR: |
2850 case CSSPropertyRx: | 2932 case CSSPropertyRx: |
2851 case CSSPropertyRy: | 2933 case CSSPropertyRy: |
2852 return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid); | 2934 return consumeLengthOrPercent(m_range, SVGAttributeMode, ValueRangeAll, UnitlessQuirk::Forbid); |
2853 case CSSPropertyCursor: | 2935 case CSSPropertyCursor: |
2854 return consumeCursor(m_range, m_context, inQuirksMode()); | 2936 return consumeCursor(m_range, m_context, inQuirksMode()); |
2855 case CSSPropertyContain: | 2937 case CSSPropertyContain: |
2856 return consumeContain(m_range); | 2938 return consumeContain(m_range); |
2857 case CSSPropertyTransformOrigin: | 2939 case CSSPropertyTransformOrigin: |
2858 return consumeTransformOrigin(m_range, m_context.mode(), UnitlessQuirk:: Forbid); | 2940 return consumeTransformOrigin(m_range, m_context.mode(), UnitlessQuirk:: Forbid); |
2941 case CSSPropertyContent: | |
2942 return consumeContent(m_range, m_context); | |
2859 default: | 2943 default: |
2860 return nullptr; | 2944 return nullptr; |
2861 } | 2945 } |
2862 } | 2946 } |
2863 | 2947 |
2864 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 2948 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
2865 { | 2949 { |
2866 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 2950 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
2867 | 2951 |
2868 do { | 2952 do { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3446 return consumeShorthandGreedily(flexFlowShorthand(), important); | 3530 return consumeShorthandGreedily(flexFlowShorthand(), important); |
3447 case CSSPropertyWebkitColumnRule: | 3531 case CSSPropertyWebkitColumnRule: |
3448 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); | 3532 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); |
3449 default: | 3533 default: |
3450 m_currentShorthand = oldShorthand; | 3534 m_currentShorthand = oldShorthand; |
3451 return false; | 3535 return false; |
3452 } | 3536 } |
3453 } | 3537 } |
3454 | 3538 |
3455 } // namespace blink | 3539 } // namespace blink |
OLD | NEW |