| OLD | NEW |
| 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 case CSSPropertyBorderRadius: | 991 case CSSPropertyBorderRadius: |
| 992 case CSSPropertyAliasWebkitBorderRadius: | 992 case CSSPropertyAliasWebkitBorderRadius: |
| 993 return parseBorderRadius(unresolvedProperty, important); | 993 return parseBorderRadius(unresolvedProperty, important); |
| 994 case CSSPropertyOutlineOffset: | 994 case CSSPropertyOutlineOffset: |
| 995 validPrimitive = validUnit(value, FLength); | 995 validPrimitive = validUnit(value, FLength); |
| 996 break; | 996 break; |
| 997 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS
3, so treat as CSS3 | 997 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS
3, so treat as CSS3 |
| 998 case CSSPropertyBoxShadow: | 998 case CSSPropertyBoxShadow: |
| 999 if (id == CSSValueNone) | 999 if (id == CSSValueNone) |
| 1000 validPrimitive = true; | 1000 validPrimitive = true; |
| 1001 else { | 1001 else |
| 1002 RefPtrWillBeRawPtr<CSSValueList> shadowValueList = parseShadow(m_val
ueList, propId); | 1002 parsedValue = parseShadow(m_valueList, propId); |
| 1003 if (shadowValueList) { | |
| 1004 addProperty(propId, shadowValueList.release(), important); | |
| 1005 m_valueList->next(); | |
| 1006 return true; | |
| 1007 } | |
| 1008 return false; | |
| 1009 } | |
| 1010 break; | 1003 break; |
| 1011 case CSSPropertyWebkitBoxReflect: | 1004 case CSSPropertyWebkitBoxReflect: |
| 1012 if (id == CSSValueNone) | 1005 if (id == CSSValueNone) |
| 1013 validPrimitive = true; | 1006 validPrimitive = true; |
| 1014 else | 1007 else |
| 1015 parsedValue = parseReflect(); | 1008 parsedValue = parseReflect(); |
| 1016 break; | 1009 break; |
| 1017 case CSSPropertyFontSizeAdjust: // none | <number> | 1010 case CSSPropertyFontSizeAdjust: // none | <number> |
| 1018 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled()); | 1011 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled()); |
| 1019 validPrimitive = (id == CSSValueNone) ? true : validUnit(value, FNumber
| FNonNeg); | 1012 validPrimitive = (id == CSSValueNone) ? true : validUnit(value, FNumber
| FNonNeg); |
| (...skipping 4089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5109 return false; | 5102 return false; |
| 5110 result = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValue
s[2], colorValues[3]); | 5103 result = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValue
s[2], colorValues[3]); |
| 5111 } else { | 5104 } else { |
| 5112 return false; | 5105 return false; |
| 5113 } | 5106 } |
| 5114 } | 5107 } |
| 5115 | 5108 |
| 5116 return true; | 5109 return true; |
| 5117 } | 5110 } |
| 5118 | 5111 |
| 5119 // This class tracks parsing state for shadow values. If it goes out of scope (
e.g., due to an early return) | 5112 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseShadow(CSSParserVal
ueList* valueList, CSSPropertyID propID) |
| 5120 // without the allowBreak bit being set, then it will clean up all of the object
s and destroy them. | 5113 { |
| 5121 class ShadowParseContext { | 5114 RefPtrWillBeRawPtr<CSSValueList> shadowValueList = CSSValueList::createComma
Separated(); |
| 5122 STACK_ALLOCATED(); | 5115 const bool isBoxShadowProperty = propID == CSSPropertyBoxShadow; |
| 5123 public: | 5116 while (RefPtrWillBeRawPtr<CSSShadowValue> shadowValue = parseSingleShadow(va
lueList, isBoxShadowProperty, isBoxShadowProperty)) { |
| 5124 ShadowParseContext(CSSPropertyID prop) | 5117 shadowValueList->append(shadowValue); |
| 5125 : property(prop) | 5118 if (!valueList->current()) |
| 5126 , allowX(true) | 5119 break; |
| 5127 , allowY(false) | 5120 if (!consumeComma(valueList)) |
| 5128 , allowBlur(false) | 5121 return nullptr; |
| 5129 , allowSpread(false) | |
| 5130 , allowColor(true) | |
| 5131 , allowStyle(prop == CSSPropertyBoxShadow) | |
| 5132 , allowBreak(true) | |
| 5133 { | |
| 5134 } | 5122 } |
| 5123 if (shadowValueList->length() == 0) |
| 5124 return nullptr; |
| 5125 return shadowValueList; |
| 5126 } |
| 5135 | 5127 |
| 5136 bool allowLength() { return allowX || allowY || allowBlur || allowSpread; } | 5128 PassRefPtrWillBeRawPtr<CSSShadowValue> CSSPropertyParser::parseSingleShadow(CSSP
arserValueList* valueList, bool allowInset, bool allowSpread) |
| 5129 { |
| 5130 RefPtrWillBeMember<CSSPrimitiveValue> style; |
| 5131 RefPtrWillBeMember<CSSPrimitiveValue> color; |
| 5132 Vector<RefPtrWillBeRawPtr<CSSPrimitiveValue>, 4> lengths; |
| 5137 | 5133 |
| 5138 void commitValue() | 5134 CSSParserValue* val = valueList->current(); |
| 5139 { | 5135 if (!val) |
| 5140 // Handle the ,, case gracefully by doing nothing. | 5136 return nullptr; |
| 5141 if (x || y || blur || spread || color || style) { | 5137 if (val->id == CSSValueInset) { |
| 5142 if (!values) | 5138 if (!allowInset) |
| 5143 values = CSSValueList::createCommaSeparated(); | 5139 return nullptr; |
| 5140 style = cssValuePool().createIdentifierValue(val->id); |
| 5141 val = valueList->next(); |
| 5142 if (!val) |
| 5143 return nullptr; |
| 5144 } |
| 5145 if ((color = parseColor(val))) |
| 5146 val = valueList->next(); |
| 5144 | 5147 |
| 5145 // Construct the current shadow value and add it to the list. | 5148 if (!val || !validUnit(val, FLength, HTMLStandardMode)) |
| 5146 values->append(CSSShadowValue::create(x.release(), y.release(), blur
.release(), spread.release(), style.release(), color.release())); | 5149 return nullptr; |
| 5150 lengths.append(createPrimitiveNumericValue(val)); |
| 5151 val = valueList->next(); |
| 5152 |
| 5153 if (!val || !validUnit(val, FLength, HTMLStandardMode)) |
| 5154 return nullptr; |
| 5155 lengths.append(createPrimitiveNumericValue(val)); |
| 5156 val = valueList->next(); |
| 5157 |
| 5158 if (val && validUnit(val, FLength, HTMLStandardMode)) { |
| 5159 // Blur radius must be non-negative. |
| 5160 if (m_parsedCalculation ? m_parsedCalculation->isNegative() : !validUnit
(val, FLength | FNonNeg, HTMLStandardMode)) { |
| 5161 m_parsedCalculation.release(); |
| 5162 return nullptr; |
| 5147 } | 5163 } |
| 5148 | 5164 lengths.append(createPrimitiveNumericValue(val)); |
| 5149 // Now reset for the next shadow value. | 5165 val = valueList->next(); |
| 5150 x = nullptr; | 5166 if (val && validUnit(val, FLength, HTMLStandardMode)) { |
| 5151 y = nullptr; | 5167 if (!allowSpread) |
| 5152 blur = nullptr; | 5168 return nullptr; |
| 5153 spread = nullptr; | 5169 lengths.append(createPrimitiveNumericValue(val)); |
| 5154 style = nullptr; | 5170 val = valueList->next(); |
| 5155 color = nullptr; | |
| 5156 | |
| 5157 allowX = true; | |
| 5158 allowColor = true; | |
| 5159 allowBreak = true; | |
| 5160 allowY = false; | |
| 5161 allowBlur = false; | |
| 5162 allowSpread = false; | |
| 5163 allowStyle = property == CSSPropertyBoxShadow; | |
| 5164 } | |
| 5165 | |
| 5166 void commitLength(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) | |
| 5167 { | |
| 5168 if (allowX) { | |
| 5169 x = val; | |
| 5170 allowX = false; | |
| 5171 allowY = true; | |
| 5172 allowColor = false; | |
| 5173 allowStyle = false; | |
| 5174 allowBreak = false; | |
| 5175 } else if (allowY) { | |
| 5176 y = val; | |
| 5177 allowY = false; | |
| 5178 allowBlur = true; | |
| 5179 allowColor = true; | |
| 5180 allowStyle = property == CSSPropertyBoxShadow; | |
| 5181 allowBreak = true; | |
| 5182 } else if (allowBlur) { | |
| 5183 blur = val; | |
| 5184 allowBlur = false; | |
| 5185 allowSpread = property == CSSPropertyBoxShadow; | |
| 5186 } else if (allowSpread) { | |
| 5187 spread = val; | |
| 5188 allowSpread = false; | |
| 5189 } | 5171 } |
| 5190 } | 5172 } |
| 5191 | 5173 |
| 5192 void commitColor(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) | 5174 if (val) { |
| 5193 { | 5175 if (RefPtrWillBeMember<CSSPrimitiveValue> colorValue = parseColor(val))
{ |
| 5194 color = val; | 5176 if (color) |
| 5195 allowColor = false; | 5177 return nullptr; |
| 5196 if (allowX) { | 5178 color = colorValue; |
| 5197 allowStyle = false; | 5179 val = valueList->next(); |
| 5198 allowBreak = false; | 5180 } |
| 5199 } else { | 5181 if (val && val->id == CSSValueInset) { |
| 5200 allowBlur = false; | 5182 if (!allowInset || style) |
| 5201 allowSpread = false; | 5183 return nullptr; |
| 5202 allowStyle = property == CSSPropertyBoxShadow; | 5184 style = cssValuePool().createIdentifierValue(val->id); |
| 5185 val = valueList->next(); |
| 5203 } | 5186 } |
| 5204 } | 5187 } |
| 5205 | 5188 unsigned lengthsSeen = lengths.size(); |
| 5206 void commitStyle(CSSParserValue* v) | 5189 return CSSShadowValue::create(lengths.at(0), lengths.at(1), |
| 5207 { | 5190 lengthsSeen > 2 ? lengths.at(2) : nullptr, |
| 5208 style = cssValuePool().createIdentifierValue(v->id); | 5191 lengthsSeen > 3 ? lengths.at(3) : nullptr, |
| 5209 allowStyle = false; | 5192 style.release(), color.release()); |
| 5210 if (allowX) | |
| 5211 allowBreak = false; | |
| 5212 else { | |
| 5213 allowBlur = false; | |
| 5214 allowSpread = false; | |
| 5215 allowColor = false; | |
| 5216 } | |
| 5217 } | |
| 5218 | |
| 5219 CSSPropertyID property; | |
| 5220 | |
| 5221 RefPtrWillBeMember<CSSValueList> values; | |
| 5222 RefPtrWillBeMember<CSSPrimitiveValue> x; | |
| 5223 RefPtrWillBeMember<CSSPrimitiveValue> y; | |
| 5224 RefPtrWillBeMember<CSSPrimitiveValue> blur; | |
| 5225 RefPtrWillBeMember<CSSPrimitiveValue> spread; | |
| 5226 RefPtrWillBeMember<CSSPrimitiveValue> style; | |
| 5227 RefPtrWillBeMember<CSSPrimitiveValue> color; | |
| 5228 | |
| 5229 bool allowX; | |
| 5230 bool allowY; | |
| 5231 bool allowBlur; | |
| 5232 bool allowSpread; | |
| 5233 bool allowColor; | |
| 5234 bool allowStyle; // inset or not. | |
| 5235 bool allowBreak; | |
| 5236 }; | |
| 5237 | |
| 5238 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseShadow(CSSParserVal
ueList* valueList, CSSPropertyID propId) | |
| 5239 { | |
| 5240 ShadowParseContext context(propId); | |
| 5241 for (CSSParserValue* val = valueList->current(); val; val = valueList->next(
)) { | |
| 5242 // Check for a comma break first. | |
| 5243 if (val->m_unit == CSSParserValue::Operator) { | |
| 5244 if (val->iValue != ',' || !context.allowBreak) { | |
| 5245 // Other operators aren't legal or we aren't done with the curre
nt shadow | |
| 5246 // value. Treat as invalid. | |
| 5247 return nullptr; | |
| 5248 } | |
| 5249 // The value is good. Commit it. | |
| 5250 context.commitValue(); | |
| 5251 } else if (validUnit(val, FLength, HTMLStandardMode)) { | |
| 5252 // We required a length and didn't get one. Invalid. | |
| 5253 if (!context.allowLength()) | |
| 5254 return nullptr; | |
| 5255 | |
| 5256 // Blur radius must be non-negative. | |
| 5257 if (context.allowBlur && (m_parsedCalculation ? m_parsedCalculation-
>isNegative() : !validUnit(val, FLength | FNonNeg, HTMLStandardMode))) | |
| 5258 return nullptr; | |
| 5259 | |
| 5260 // A length is allowed here. Construct the value and add it. | |
| 5261 RefPtrWillBeRawPtr<CSSPrimitiveValue> length = createPrimitiveNumeri
cValue(val); | |
| 5262 context.commitLength(length.release()); | |
| 5263 } else if (val->id == CSSValueInset) { | |
| 5264 if (!context.allowStyle) | |
| 5265 return nullptr; | |
| 5266 | |
| 5267 context.commitStyle(val); | |
| 5268 } else { | |
| 5269 if (!context.allowColor) | |
| 5270 return nullptr; | |
| 5271 | |
| 5272 // The only other type of value that's ok is a color value. | |
| 5273 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedColor = parseColor(val); | |
| 5274 if (!parsedColor) | |
| 5275 return nullptr; | |
| 5276 | |
| 5277 context.commitColor(parsedColor.release()); | |
| 5278 } | |
| 5279 } | |
| 5280 | |
| 5281 if (context.allowBreak) { | |
| 5282 context.commitValue(); | |
| 5283 if (context.values && context.values->length()) | |
| 5284 return context.values.release(); | |
| 5285 } | |
| 5286 | |
| 5287 return nullptr; | |
| 5288 } | 5193 } |
| 5289 | 5194 |
| 5290 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseReflect() | 5195 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseReflect() |
| 5291 { | 5196 { |
| 5292 // box-reflect: <direction> <offset> <mask> | 5197 // box-reflect: <direction> <offset> <mask> |
| 5293 | 5198 |
| 5294 // Direction comes first. | 5199 // Direction comes first. |
| 5295 CSSParserValue* val = m_valueList->current(); | 5200 CSSParserValue* val = m_valueList->current(); |
| 5296 RefPtrWillBeRawPtr<CSSPrimitiveValue> direction = nullptr; | 5201 RefPtrWillBeRawPtr<CSSPrimitiveValue> direction = nullptr; |
| 5297 switch (val->id) { | 5202 switch (val->id) { |
| (...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6925 CSSParserValue* argument = args->current(); | 6830 CSSParserValue* argument = args->current(); |
| 6926 if (!validUnit(argument, FLength | FNonNeg, HTMLStandardMode)) | 6831 if (!validUnit(argument, FLength | FNonNeg, HTMLStandardMode)) |
| 6927 return nullptr; | 6832 return nullptr; |
| 6928 | 6833 |
| 6929 filterValue->append(createPrimitiveNumericValue(argument)); | 6834 filterValue->append(createPrimitiveNumericValue(argument)); |
| 6930 } | 6835 } |
| 6931 break; | 6836 break; |
| 6932 } | 6837 } |
| 6933 case CSSValueDropShadow: { | 6838 case CSSValueDropShadow: { |
| 6934 // drop-shadow() takes a single shadow. | 6839 // drop-shadow() takes a single shadow. |
| 6935 RefPtrWillBeRawPtr<CSSValueList> shadowValueList = parseShadow(args, CSS
PropertyWebkitFilter); | 6840 RefPtrWillBeRawPtr<CSSShadowValue> shadowValue = parseSingleShadow(args,
false, true); |
| 6936 if (!shadowValueList || shadowValueList->length() != 1) | 6841 if (!shadowValue) |
| 6937 return nullptr; | 6842 return nullptr; |
| 6938 | 6843 filterValue->append(shadowValue.release()); |
| 6939 filterValue->append((shadowValueList.release())->item(0)); | |
| 6940 break; | 6844 break; |
| 6941 } | 6845 } |
| 6942 default: | 6846 default: |
| 6943 return nullptr; | 6847 return nullptr; |
| 6944 } | 6848 } |
| 6945 return filterValue.release(); | 6849 return filterValue.release(); |
| 6946 } | 6850 } |
| 6947 | 6851 |
| 6948 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFilter() | 6852 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFilter() |
| 6949 { | 6853 { |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8037 } | 7941 } |
| 8038 } | 7942 } |
| 8039 | 7943 |
| 8040 if (!list->length()) | 7944 if (!list->length()) |
| 8041 return nullptr; | 7945 return nullptr; |
| 8042 | 7946 |
| 8043 return list.release(); | 7947 return list.release(); |
| 8044 } | 7948 } |
| 8045 | 7949 |
| 8046 } // namespace blink | 7950 } // namespace blink |
| OLD | NEW |