Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 1535463002: Parse border-radius shorthand in CSSPropertyParser with CSSParserTokens (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove ImplicitScope Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/StylePropertyShorthand.h" 7 #include "core/StylePropertyShorthand.h"
8 #include "core/css/CSSCalculationValue.h" 8 #include "core/css/CSSCalculationValue.h"
9 #include "core/css/CSSCounterValue.h" 9 #include "core/css/CSSCounterValue.h"
10 #include "core/css/CSSCrossfadeValue.h" 10 #include "core/css/CSSCrossfadeValue.h"
(...skipping 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeLengthOrPerce nt(args, cssParserMode, ValueRangeNonNegative); 2916 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeLengthOrPerce nt(args, cssParserMode, ValueRangeNonNegative);
2917 if (args.atEnd() && parsedValue && (parsedValue->isCalculated() || parse dValue->getDoubleValue() > 0)) { 2917 if (args.atEnd() && parsedValue && (parsedValue->isCalculated() || parse dValue->getDoubleValue() > 0)) {
2918 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::crea te(CSSValueRepeat); 2918 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::crea te(CSSValueRepeat);
2919 result->append(parsedValue.release()); 2919 result->append(parsedValue.release());
2920 return result.release(); 2920 return result.release();
2921 } 2921 }
2922 } 2922 }
2923 return nullptr; 2923 return nullptr;
2924 } 2924 }
2925 2925
2926 static PassRefPtrWillBeRawPtr<CSSValue> consumeBorderRadiusCorner(CSSParserToken Range& range, CSSParserMode cssParserMode)
2927 {
2928 RefPtrWillBeRawPtr<CSSValue> parsedValue1 = consumeLengthOrPercent(range, cs sParserMode, ValueRangeNonNegative);
2929 if (!parsedValue1)
2930 return nullptr;
2931 RefPtrWillBeRawPtr<CSSValue> parsedValue2 = consumeLengthOrPercent(range, cs sParserMode, ValueRangeNonNegative);
2932 if (!parsedValue2)
2933 parsedValue2 = parsedValue1;
2934 return CSSValuePair::create(parsedValue1.release(), parsedValue2.release(), CSSValuePair::DropIdenticalValues);
2935 }
2936
2926 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) 2937 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty)
2927 { 2938 {
2928 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 2939 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
2929 switch (property) { 2940 switch (property) {
2930 case CSSPropertyWillChange: 2941 case CSSPropertyWillChange:
2931 return consumeWillChange(m_range); 2942 return consumeWillChange(m_range);
2932 case CSSPropertyPage: 2943 case CSSPropertyPage:
2933 return consumePage(m_range); 2944 return consumePage(m_range);
2934 case CSSPropertyQuotes: 2945 case CSSPropertyQuotes:
2935 return consumeQuotes(m_range); 2946 return consumeQuotes(m_range);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 return consumeContent(m_range, m_context); 3179 return consumeContent(m_range, m_context);
3169 case CSSPropertyListStyleImage: 3180 case CSSPropertyListStyleImage:
3170 return consumeImage(m_range, m_context); 3181 return consumeImage(m_range, m_context);
3171 case CSSPropertyPerspective: 3182 case CSSPropertyPerspective:
3172 return consumePerspective(m_range, m_context.mode(), unresolvedProperty) ; 3183 return consumePerspective(m_range, m_context.mode(), unresolvedProperty) ;
3173 case CSSPropertyScrollSnapCoordinate: 3184 case CSSPropertyScrollSnapCoordinate:
3174 return consumeScrollSnapCoordinate(m_range, m_context.mode()); 3185 return consumeScrollSnapCoordinate(m_range, m_context.mode());
3175 case CSSPropertyScrollSnapPointsX: 3186 case CSSPropertyScrollSnapPointsX:
3176 case CSSPropertyScrollSnapPointsY: 3187 case CSSPropertyScrollSnapPointsY:
3177 return consumeScrollSnapPoints(m_range, m_context.mode()); 3188 return consumeScrollSnapPoints(m_range, m_context.mode());
3189 case CSSPropertyBorderTopRightRadius:
3190 case CSSPropertyBorderTopLeftRadius:
3191 case CSSPropertyBorderBottomLeftRadius:
3192 case CSSPropertyBorderBottomRightRadius:
3193 return consumeBorderRadiusCorner(m_range, m_context.mode());
3178 default: 3194 default:
3179 return nullptr; 3195 return nullptr;
3180 } 3196 }
3181 } 3197 }
3182 3198
3183 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) 3199 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range)
3184 { 3200 {
3185 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); 3201 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
3186 3202
3187 do { 3203 do {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 left = right; 3665 left = right;
3650 3666
3651 addProperty(longhands[0], top.release(), important); 3667 addProperty(longhands[0], top.release(), important);
3652 addProperty(longhands[1], right.release(), important); 3668 addProperty(longhands[1], right.release(), important);
3653 addProperty(longhands[2], bottom.release(), important); 3669 addProperty(longhands[2], bottom.release(), important);
3654 addProperty(longhands[3], left.release(), important); 3670 addProperty(longhands[3], left.release(), important);
3655 3671
3656 return m_range.atEnd(); 3672 return m_range.atEnd();
3657 } 3673 }
3658 3674
3675 static bool consumeRadii(RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalRadii[4 ], RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalRadii[4], CSSParserTokenRange& range, CSSParserMode cssParserMode, bool useLegacyParsing)
3676 {
3677 #if ENABLE(OILPAN)
3678 // Unconditionally zero initialize the arrays of raw pointers.
3679 memset(horizontalRadii, 0, 4 * sizeof(horizontalRadii[0]));
3680 memset(verticalRadii, 0, 4 * sizeof(verticalRadii[0]));
3681 #endif
3682 unsigned i = 0;
3683 for (; i < 4 && !range.atEnd() && range.peek().type() != DelimiterToken; ++i ) {
3684 horizontalRadii[i] = consumeLengthOrPercent(range, cssParserMode, ValueR angeNonNegative);
3685 if (!horizontalRadii[i])
3686 return false;
3687 }
3688 if (!horizontalRadii[0])
3689 return false;
3690 if (range.atEnd()) {
3691 // Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border- radius: l1 / l2;
3692 if (useLegacyParsing && i == 2) {
3693 verticalRadii[0] = horizontalRadii[1];
3694 horizontalRadii[1] = nullptr;
3695 } else {
3696 completeBorderRadii(horizontalRadii);
3697 for (unsigned i = 0; i < 4; ++i)
3698 verticalRadii[i] = horizontalRadii[i];
3699 return true;
3700 }
3701 } else {
3702 if (range.peek().type() != DelimiterToken || range.peek().delimiter() != '/')
3703 return false;
3704 range.consumeIncludingWhitespace();
3705 for (i = 0; i < 4 && !range.atEnd(); ++i) {
3706 verticalRadii[i] = consumeLengthOrPercent(range, cssParserMode, Valu eRangeNonNegative);
3707 if (!verticalRadii[i])
3708 return false;
3709 }
3710 if (!verticalRadii[0] || !range.atEnd())
3711 return false;
3712 }
3713 completeBorderRadii(horizontalRadii);
3714 completeBorderRadii(verticalRadii);
3715 return true;
3716 }
3717
3659 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) 3718 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant)
3660 { 3719 {
3661 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 3720 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
3662 3721
3663 CSSPropertyID oldShorthand = m_currentShorthand; 3722 CSSPropertyID oldShorthand = m_currentShorthand;
3664 // TODO(rob.buis): Remove this when the legacy property parser is gone 3723 // TODO(rob.buis): Remove this when the legacy property parser is gone
3665 m_currentShorthand = property; 3724 m_currentShorthand = property;
3666 switch (property) { 3725 switch (property) {
3667 case CSSPropertyWebkitMarginCollapse: { 3726 case CSSPropertyWebkitMarginCollapse: {
3668 CSSValueID id = m_range.consumeIncludingWhitespace().id(); 3727 CSSValueID id = m_range.consumeIncludingWhitespace().id();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 return true; 3822 return true;
3764 } 3823 }
3765 case CSSPropertyFlex: 3824 case CSSPropertyFlex:
3766 return consumeFlex(important); 3825 return consumeFlex(important);
3767 case CSSPropertyFlexFlow: 3826 case CSSPropertyFlexFlow:
3768 return consumeShorthandGreedily(flexFlowShorthand(), important); 3827 return consumeShorthandGreedily(flexFlowShorthand(), important);
3769 case CSSPropertyWebkitColumnRule: 3828 case CSSPropertyWebkitColumnRule:
3770 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); 3829 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important);
3771 case CSSPropertyListStyle: 3830 case CSSPropertyListStyle:
3772 return consumeShorthandGreedily(listStyleShorthand(), important); 3831 return consumeShorthandGreedily(listStyleShorthand(), important);
3832 case CSSPropertyBorderRadius: {
3833 RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalRadii[4];
3834 RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalRadii[4];
3835 if (!consumeRadii(horizontalRadii, verticalRadii, m_range, m_context.mod e(), unresolvedProperty == CSSPropertyAliasWebkitBorderRadius))
3836 return false;
3837 addProperty(CSSPropertyBorderTopLeftRadius, CSSValuePair::create(horizon talRadii[0].release(), verticalRadii[0].release(), CSSValuePair::DropIdenticalVa lues), important);
3838 addProperty(CSSPropertyBorderTopRightRadius, CSSValuePair::create(horizo ntalRadii[1].release(), verticalRadii[1].release(), CSSValuePair::DropIdenticalV alues), important);
3839 addProperty(CSSPropertyBorderBottomRightRadius, CSSValuePair::create(hor izontalRadii[2].release(), verticalRadii[2].release(), CSSValuePair::DropIdentic alValues), important);
3840 addProperty(CSSPropertyBorderBottomLeftRadius, CSSValuePair::create(hori zontalRadii[3].release(), verticalRadii[3].release(), CSSValuePair::DropIdentica lValues), important);
3841 return true;
3842 }
3773 default: 3843 default:
3774 m_currentShorthand = oldShorthand; 3844 m_currentShorthand = oldShorthand;
3775 return false; 3845 return false;
3776 } 3846 }
3777 } 3847 }
3778 3848
3779 } // namespace blink 3849 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698