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

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

Issue 1449213002: Parse flex/flex-flow shorthands in CSSPropertyParser with CSSParserTokens (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 case CSSPropertyOpacity: 742 case CSSPropertyOpacity:
743 case CSSPropertyWebkitBoxFlex: 743 case CSSPropertyWebkitBoxFlex:
744 validPrimitive = validUnit(value, FNumber); 744 validPrimitive = validUnit(value, FNumber);
745 break; 745 break;
746 case CSSPropertyWebkitBoxFlexGroup: 746 case CSSPropertyWebkitBoxFlexGroup:
747 validPrimitive = validUnit(value, FInteger | FNonNeg); 747 validPrimitive = validUnit(value, FInteger | FNonNeg);
748 break; 748 break;
749 case CSSPropertyWebkitBoxOrdinalGroup: 749 case CSSPropertyWebkitBoxOrdinalGroup:
750 validPrimitive = validUnit(value, FInteger | FNonNeg) && value->fValue; 750 validPrimitive = validUnit(value, FInteger | FNonNeg) && value->fValue;
751 break; 751 break;
752 case CSSPropertyFlex: {
753 ShorthandScope scope(this, propId);
754 if (id == CSSValueNone) {
755 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(0, CSSPr imitiveValue::UnitType::Number), important);
756 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(0, CSS PrimitiveValue::UnitType::Number), important);
757 addProperty(CSSPropertyFlexBasis, cssValuePool().createIdentifierVal ue(CSSValueAuto), important);
758 return true;
759 }
760 return parseFlex(m_valueList, important);
761 }
762 case CSSPropertyFlexBasis:
763 // FIXME: Support intrinsic dimensions too.
764 if (id == CSSValueAuto)
765 validPrimitive = true;
766 else
767 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
768 break;
769 case CSSPropertyFlexGrow:
770 case CSSPropertyFlexShrink:
771 validPrimitive = validUnit(value, FNumber | FNonNeg);
772 break;
773 case CSSPropertyOrder: 752 case CSSPropertyOrder:
774 validPrimitive = validUnit(value, FInteger); 753 validPrimitive = validUnit(value, FInteger);
775 break; 754 break;
776 case CSSPropertyTransformOrigin: { 755 case CSSPropertyTransformOrigin: {
777 RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin(); 756 RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin();
778 if (!list) 757 if (!list)
779 return false; 758 return false;
780 // These values are added to match gecko serialization. 759 // These values are added to match gecko serialization.
781 if (list->length() == 1) 760 if (list->length() == 1)
782 list->append(cssValuePool().createValue(50, CSSPrimitiveValue::UnitT ype::Percentage)); 761 list->append(cssValuePool().createValue(50, CSSPrimitiveValue::UnitT ype::Percentage));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 return parse4Values(propId, borderWidthShorthand().properties(), importa nt); 972 return parse4Values(propId, borderWidthShorthand().properties(), importa nt);
994 case CSSPropertyBorderStyle: 973 case CSSPropertyBorderStyle:
995 // <border-style>{1,4} | inherit 974 // <border-style>{1,4} | inherit
996 return parse4Values(propId, borderStyleShorthand().properties(), importa nt); 975 return parse4Values(propId, borderStyleShorthand().properties(), importa nt);
997 case CSSPropertyMargin: 976 case CSSPropertyMargin:
998 // <margin-width>{1,4} | inherit 977 // <margin-width>{1,4} | inherit
999 return parse4Values(propId, marginShorthand().properties(), important); 978 return parse4Values(propId, marginShorthand().properties(), important);
1000 case CSSPropertyPadding: 979 case CSSPropertyPadding:
1001 // <padding-width>{1,4} | inherit 980 // <padding-width>{1,4} | inherit
1002 return parse4Values(propId, paddingShorthand().properties(), important); 981 return parse4Values(propId, paddingShorthand().properties(), important);
1003 case CSSPropertyFlexFlow:
1004 return parseShorthand(propId, flexFlowShorthand(), important);
1005 case CSSPropertyListStyle: 982 case CSSPropertyListStyle:
1006 return parseShorthand(propId, listStyleShorthand(), important); 983 return parseShorthand(propId, listStyleShorthand(), important);
1007 case CSSPropertyWebkitColumnRule: 984 case CSSPropertyWebkitColumnRule:
1008 return parseShorthand(propId, webkitColumnRuleShorthand(), important); 985 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
1009 case CSSPropertyInvalid: 986 case CSSPropertyInvalid:
1010 return false; 987 return false;
1011 // CSS Text Layout Module Level 3: Vertical writing support 988 // CSS Text Layout Module Level 3: Vertical writing support
1012 case CSSPropertyWebkitTextOrientation: 989 case CSSPropertyWebkitTextOrientation:
1013 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right. 990 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right.
1014 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright) 991 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 case CSSPropertyFill: 1147 case CSSPropertyFill:
1171 case CSSPropertyStroke: 1148 case CSSPropertyStroke:
1172 case CSSPropertyStopColor: 1149 case CSSPropertyStopColor:
1173 case CSSPropertyFloodColor: 1150 case CSSPropertyFloodColor:
1174 case CSSPropertyLightingColor: 1151 case CSSPropertyLightingColor:
1175 case CSSPropertyPaintOrder: 1152 case CSSPropertyPaintOrder:
1176 case CSSPropertyMarker: 1153 case CSSPropertyMarker:
1177 case CSSPropertyMarkerStart: 1154 case CSSPropertyMarkerStart:
1178 case CSSPropertyMarkerMid: 1155 case CSSPropertyMarkerMid:
1179 case CSSPropertyMarkerEnd: 1156 case CSSPropertyMarkerEnd:
1157 case CSSPropertyFlex:
1158 case CSSPropertyFlexBasis:
1159 case CSSPropertyFlexGrow:
1160 case CSSPropertyFlexShrink:
1161 case CSSPropertyFlexFlow:
1180 validPrimitive = false; 1162 validPrimitive = false;
1181 break; 1163 break;
1182 1164
1183 case CSSPropertyScrollSnapPointsX: 1165 case CSSPropertyScrollSnapPointsX:
1184 case CSSPropertyScrollSnapPointsY: 1166 case CSSPropertyScrollSnapPointsY:
1185 parsedValue = parseScrollSnapPoints(); 1167 parsedValue = parseScrollSnapPoints();
1186 break; 1168 break;
1187 case CSSPropertyScrollSnapCoordinate: 1169 case CSSPropertyScrollSnapCoordinate:
1188 parsedValue = parseScrollSnapCoordinate(); 1170 parsedValue = parseScrollSnapCoordinate();
1189 break; 1171 break;
(...skipping 2663 matching lines...) Expand 10 before | Expand all | Expand 10 after
3853 val = m_valueList->next(); 3835 val = m_valueList->next();
3854 if (val) { 3836 if (val) {
3855 mask = parseBorderImage(CSSPropertyWebkitBoxReflect); 3837 mask = parseBorderImage(CSSPropertyWebkitBoxReflect);
3856 if (!mask) 3838 if (!mask)
3857 return nullptr; 3839 return nullptr;
3858 } 3840 }
3859 3841
3860 return CSSReflectValue::create(direction.release(), offset.release(), mask.r elease()); 3842 return CSSReflectValue::create(direction.release(), offset.release(), mask.r elease());
3861 } 3843 }
3862 3844
3863 static bool isFlexBasisMiddleArg(double flexGrow, double flexShrink, double unse tValue, int argSize)
3864 {
3865 return flexGrow != unsetValue && flexShrink == unsetValue && argSize == 3;
3866 }
3867
3868 bool CSSPropertyParser::parseFlex(CSSParserValueList* args, bool important)
3869 {
3870 if (!args || !args->size() || args->size() > 3)
3871 return false;
3872 static const double unsetValue = -1;
3873 double flexGrow = unsetValue;
3874 double flexShrink = unsetValue;
3875 RefPtrWillBeRawPtr<CSSPrimitiveValue> flexBasis = nullptr;
3876
3877 while (CSSParserValue* arg = args->current()) {
3878 if (validUnit(arg, FNumber | FNonNeg)) {
3879 if (flexGrow == unsetValue)
3880 flexGrow = arg->fValue;
3881 else if (flexShrink == unsetValue)
3882 flexShrink = arg->fValue;
3883 else if (!arg->fValue) {
3884 // flex only allows a basis of 0 (sans units) if flex-grow and f lex-shrink values have already been set.
3885 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::Uni tType::Pixels);
3886 } else {
3887 // We only allow 3 numbers without units if the last value is 0. E.g., flex:1 1 1 is invalid.
3888 return false;
3889 }
3890 } else if (!flexBasis && (arg->id == CSSValueAuto || validUnit(arg, FLen gth | FPercent | FNonNeg)) && !isFlexBasisMiddleArg(flexGrow, flexShrink, unsetV alue, args->size()))
3891 flexBasis = parseValidPrimitive(arg->id, arg);
3892 else {
3893 // Not a valid arg for flex.
3894 return false;
3895 }
3896 args->next();
3897 }
3898
3899 if (flexGrow == unsetValue)
3900 flexGrow = 1;
3901 if (flexShrink == unsetValue)
3902 flexShrink = 1;
3903 if (!flexBasis)
3904 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::P ercentage);
3905
3906 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(f lexGrow), CSSPrimitiveValue::UnitType::Number), important);
3907 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float> (flexShrink), CSSPrimitiveValue::UnitType::Number), important);
3908 addProperty(CSSPropertyFlexBasis, flexBasis, important);
3909 return true;
3910 }
3911
3912 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parsePosition(CSSParserValue List* valueList) 3845 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parsePosition(CSSParserValue List* valueList)
3913 { 3846 {
3914 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr; 3847 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
3915 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; 3848 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
3916 parseFillPosition(valueList, xValue, yValue); 3849 parseFillPosition(valueList, xValue, yValue);
3917 if (!xValue || !yValue) 3850 if (!xValue || !yValue)
3918 return nullptr; 3851 return nullptr;
3919 return CSSValuePair::create(xValue.release(), yValue.release(), CSSValuePair ::KeepIdenticalValues); 3852 return CSSValuePair::create(xValue.release(), yValue.release(), CSSValuePair ::KeepIdenticalValues);
3920 } 3853 }
3921 3854
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after
5574 value = m_valueList->current(); 5507 value = m_valueList->current();
5575 if (commaConsumed && !value) 5508 if (commaConsumed && !value)
5576 return nullptr; 5509 return nullptr;
5577 } 5510 }
5578 if (!validPrimitive) 5511 if (!validPrimitive)
5579 return nullptr; 5512 return nullptr;
5580 return ret.release(); 5513 return ret.release();
5581 } 5514 }
5582 5515
5583 } // namespace blink 5516 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698