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

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: Fix test fails 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> radii[4], RefPtrW illBeRawPtr<CSSPrimitiveValue> radii2[4], CSSParserTokenRange& range, CSSParserM ode cssParserMode, CSSPropertyID unresolvedProperty)
Timothy Loh 2016/01/14 06:38:45 I'd rather if the last argument was useLegacyParsi
rwlbuis 2016/01/14 22:45:50 Done.
3676 {
3677 #if ENABLE(OILPAN)
3678 // Unconditionally zero initialize the arrays of raw pointers.
3679 memset(radii, 0, 4 * sizeof(radii[0]));
3680 memset(radii2, 0, 4 * sizeof(radii2[0]));
3681 #endif
3682 for (unsigned i = 0; i < 4 && !range.atEnd() && range.peek().type() != Delim iterToken; ++i) {
3683 radii[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNeg ative);
3684 if (!radii[i])
3685 return false;
3686 // Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border- radius: l1 / l2;
3687 if (range.atEnd() && i == 1 && unresolvedProperty == CSSPropertyAliasWeb kitBorderRadius) {
Timothy Loh 2016/01/14 06:38:45 I think this code should be adjacent to the code h
rwlbuis 2016/01/14 22:45:50 Actually it is hard to find a nice structure... Ho
Timothy Loh 2016/01/15 01:11:56 I know, otherwise I would've suggested something e
3688 radii2[0] = radii[1];
3689 radii[1] = nullptr;
3690 completeBorderRadii(radii);
3691 completeBorderRadii(radii2);
3692 return true;
3693 }
3694 }
3695 if (!radii[0])
3696 return false;
3697 completeBorderRadii(radii);
3698 if (!range.atEnd()) {
3699 if (range.peek().type() != DelimiterToken || range.peek().delimiter() != '/')
3700 return false;
3701 range.consumeIncludingWhitespace();
3702 for (unsigned i = 0; i < 4 && !range.atEnd(); ++i) {
3703 radii2[i] = consumeLengthOrPercent(range, cssParserMode, ValueRangeN onNegative);
3704 if (!radii2[i])
3705 break;
Timothy Loh 2016/01/14 06:38:45 The first loop returns false in this case, can we
rwlbuis 2016/01/14 22:45:50 Done.
3706 }
3707 if (!radii2[0] || !range.atEnd())
3708 return false;
3709 completeBorderRadii(radii2);
3710 } else {
3711 for (unsigned i = 0; i < 4; ++i)
3712 radii2[i] = radii[i];
3713 }
3714 return true;
3715 }
3716
3659 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) 3717 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant)
3660 { 3718 {
3661 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 3719 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
3662 3720
3663 CSSPropertyID oldShorthand = m_currentShorthand; 3721 CSSPropertyID oldShorthand = m_currentShorthand;
3664 // TODO(rob.buis): Remove this when the legacy property parser is gone 3722 // TODO(rob.buis): Remove this when the legacy property parser is gone
3665 m_currentShorthand = property; 3723 m_currentShorthand = property;
3666 switch (property) { 3724 switch (property) {
3667 case CSSPropertyWebkitMarginCollapse: { 3725 case CSSPropertyWebkitMarginCollapse: {
3668 CSSValueID id = m_range.consumeIncludingWhitespace().id(); 3726 CSSValueID id = m_range.consumeIncludingWhitespace().id();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 return true; 3821 return true;
3764 } 3822 }
3765 case CSSPropertyFlex: 3823 case CSSPropertyFlex:
3766 return consumeFlex(important); 3824 return consumeFlex(important);
3767 case CSSPropertyFlexFlow: 3825 case CSSPropertyFlexFlow:
3768 return consumeShorthandGreedily(flexFlowShorthand(), important); 3826 return consumeShorthandGreedily(flexFlowShorthand(), important);
3769 case CSSPropertyWebkitColumnRule: 3827 case CSSPropertyWebkitColumnRule:
3770 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important); 3828 return consumeShorthandGreedily(webkitColumnRuleShorthand(), important);
3771 case CSSPropertyListStyle: 3829 case CSSPropertyListStyle:
3772 return consumeShorthandGreedily(listStyleShorthand(), important); 3830 return consumeShorthandGreedily(listStyleShorthand(), important);
3831 case CSSPropertyBorderRadius: {
3832 RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[4];
3833 RefPtrWillBeRawPtr<CSSPrimitiveValue> radii2[4];
3834 if (!consumeRadii(radii, radii2, m_range, m_context.mode(), unresolvedPr operty))
3835 return false;
3836 ImplicitScope implicitScope(this);
Timothy Loh 2016/01/14 06:38:45 I think this isn't needed.
rwlbuis 2016/01/14 22:45:50 Done.
3837 addProperty(CSSPropertyBorderTopLeftRadius, CSSValuePair::create(radii[0 ].release(), radii2[0].release(), CSSValuePair::DropIdenticalValues), important) ;
3838 addProperty(CSSPropertyBorderTopRightRadius, CSSValuePair::create(radii[ 1].release(), radii2[1].release(), CSSValuePair::DropIdenticalValues), important );
3839 addProperty(CSSPropertyBorderBottomRightRadius, CSSValuePair::create(rad ii[2].release(), radii2[2].release(), CSSValuePair::DropIdenticalValues), import ant);
3840 addProperty(CSSPropertyBorderBottomLeftRadius, CSSValuePair::create(radi i[3].release(), radii2[3].release(), CSSValuePair::DropIdenticalValues), importa nt);
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