Chromium Code Reviews| 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/CSSValuePool.h" | 10 #include "core/css/CSSValuePool.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return cssValuePool().createValue(range.consumeIncludingWhitespace().value() , CSSPrimitiveValue::UnitType::CustomIdentifier); | 84 return cssValuePool().createValue(range.consumeIncludingWhitespace().value() , CSSPrimitiveValue::UnitType::CustomIdentifier); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeString(CSSParserTokenRan ge& range) | 87 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeString(CSSParserTokenRan ge& range) |
| 88 { | 88 { |
| 89 if (range.peek().type() != StringToken) | 89 if (range.peek().type() != StringToken) |
| 90 return nullptr; | 90 return nullptr; |
| 91 return cssValuePool().createValue(range.consumeIncludingWhitespace().value() , CSSPrimitiveValue::UnitType::String); | 91 return cssValuePool().createValue(range.consumeIncludingWhitespace().value() , CSSPrimitiveValue::UnitType::String); |
| 92 } | 92 } |
| 93 | 93 |
| 94 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumericValue(CSSParserTo kenRange& range, CSSPropertyParser::Units unitflags, CSSParserMode cssParserMode ) | |
| 95 { | |
| 96 CSSParserToken numericToken = range.peek(); | |
|
Timothy Loh
2015/09/22 13:54:25
const CSSParserToken& :-)
I really ought to make
| |
| 97 if (unitflags & CSSPropertyParser::FNonNeg && numericToken.numericValue() < 0) | |
|
Timothy Loh
2015/09/22 13:54:25
numericValue() isn't set up to work for non-numeri
| |
| 98 return nullptr; | |
| 99 bool validNumber = false; | |
| 100 switch (numericToken.unitType()) { | |
| 101 case CSSPrimitiveValue::UnitType::Number: | |
|
Timothy Loh
2015/09/22 13:54:25
IMO we should do this as:
if (token.type() == Num
| |
| 102 if (unitflags & CSSPropertyParser::FNumber) { | |
| 103 validNumber = true; | |
| 104 } else if (shouldAcceptUnitLessValues(numericToken.numericValue(), unitf lags, cssParserMode)) { | |
| 105 numericToken.setUnitType((unitflags & CSSPropertyParser::FLength) ? CSSPrimitiveValue::UnitType::Pixels : CSSPrimitiveValue::UnitType::Degrees); | |
| 106 validNumber = true; | |
| 107 } else if ((unitflags & CSSPropertyParser::FInteger) && numericToken.num ericValueType() == IntegerValueType) { | |
| 108 validNumber = true; | |
| 109 } else if ((unitflags & CSSPropertyParser::FPositiveInteger) && numericT oken.numericValueType() == IntegerValueType && numericToken.numericValue() > 0) { | |
| 110 validNumber = true; | |
| 111 } | |
| 112 break; | |
| 113 case CSSPrimitiveValue::UnitType::Percentage: | |
| 114 validNumber = unitflags & CSSPropertyParser::FPercent; | |
| 115 break; | |
| 116 case CSSPrimitiveValue::UnitType::QuirkyEms: | |
| 117 if (cssParserMode != UASheetMode) | |
| 118 return nullptr; | |
| 119 /* fallthrough intentional */ | |
| 120 case CSSPrimitiveValue::UnitType::Ems: | |
| 121 case CSSPrimitiveValue::UnitType::Rems: | |
| 122 case CSSPrimitiveValue::UnitType::Chs: | |
| 123 case CSSPrimitiveValue::UnitType::Exs: | |
| 124 case CSSPrimitiveValue::UnitType::Pixels: | |
| 125 case CSSPrimitiveValue::UnitType::Centimeters: | |
| 126 case CSSPrimitiveValue::UnitType::Millimeters: | |
| 127 case CSSPrimitiveValue::UnitType::Inches: | |
| 128 case CSSPrimitiveValue::UnitType::Points: | |
| 129 case CSSPrimitiveValue::UnitType::Picas: | |
| 130 case CSSPrimitiveValue::UnitType::ViewportWidth: | |
| 131 case CSSPrimitiveValue::UnitType::ViewportHeight: | |
| 132 case CSSPrimitiveValue::UnitType::ViewportMin: | |
| 133 case CSSPrimitiveValue::UnitType::ViewportMax: | |
| 134 validNumber = unitflags & CSSPropertyParser::FLength; | |
| 135 break; | |
| 136 case CSSPrimitiveValue::UnitType::Milliseconds: | |
| 137 case CSSPrimitiveValue::UnitType::Seconds: | |
| 138 validNumber = unitflags & CSSPropertyParser::FTime; | |
| 139 break; | |
| 140 case CSSPrimitiveValue::UnitType::Degrees: | |
| 141 case CSSPrimitiveValue::UnitType::Radians: | |
| 142 case CSSPrimitiveValue::UnitType::Gradians: | |
| 143 case CSSPrimitiveValue::UnitType::Turns: | |
| 144 validNumber = unitflags & CSSPropertyParser::FAngle; | |
| 145 break; | |
| 146 case CSSPrimitiveValue::UnitType::DotsPerPixel: | |
| 147 case CSSPrimitiveValue::UnitType::DotsPerInch: | |
| 148 case CSSPrimitiveValue::UnitType::DotsPerCentimeter: | |
| 149 validNumber = unitflags & CSSPropertyParser::FResolution; | |
|
Timothy Loh
2015/09/22 13:54:25
No point adding this if we don't have any properti
| |
| 150 break; | |
| 151 default: | |
| 152 return nullptr; | |
| 153 } | |
| 154 if (validNumber) | |
| 155 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), numericToken.unitType()); | |
| 156 return nullptr; | |
| 157 } | |
| 158 | |
| 94 // Methods for consuming non-shorthand properties starts here. | 159 // Methods for consuming non-shorthand properties starts here. |
| 95 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) | 160 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) |
| 96 { | 161 { |
| 97 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 162 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 98 if (range.peek().id() == CSSValueAuto) { | 163 if (range.peek().id() == CSSValueAuto) { |
| 99 // FIXME: This will be read back as an empty string instead of auto | 164 // FIXME: This will be read back as an empty string instead of auto |
| 100 return values.release(); | 165 return values.release(); |
| 101 } | 166 } |
| 102 | 167 |
| 103 // Every comma-separated list of identifiers is a valid will-change value, | 168 // Every comma-separated list of identifiers is a valid will-change value, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 break; | 276 break; |
| 212 default: | 277 default: |
| 213 return nullptr; | 278 return nullptr; |
| 214 } | 279 } |
| 215 ligatureValues->append(consumeIdent(range)); | 280 ligatureValues->append(consumeIdent(range)); |
| 216 } while (!range.atEnd()); | 281 } while (!range.atEnd()); |
| 217 | 282 |
| 218 return ligatureValues.release(); | 283 return ligatureValues.release(); |
| 219 } | 284 } |
| 220 | 285 |
| 286 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::consumeSpacing(CSSParserToke nRange& range) | |
| 287 { | |
| 288 if (range.peek().id() == CSSValueNormal) | |
| 289 return consumeIdent(range); | |
| 290 return consumeNumericValue(range, FLength | FUnitlessQuirk, m_context.mode() ); | |
| 291 } | |
| 292 | |
| 221 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 293 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
| 222 { | 294 { |
| 223 m_range.consumeWhitespace(); | 295 m_range.consumeWhitespace(); |
| 224 switch (propId) { | 296 switch (propId) { |
| 225 case CSSPropertyWillChange: | 297 case CSSPropertyWillChange: |
| 226 return consumeWillChange(m_range); | 298 return consumeWillChange(m_range); |
| 227 case CSSPropertyPage: | 299 case CSSPropertyPage: |
| 228 return consumePage(m_range); | 300 return consumePage(m_range); |
| 229 case CSSPropertyQuotes: | 301 case CSSPropertyQuotes: |
| 230 return consumeQuotes(m_range); | 302 return consumeQuotes(m_range); |
| 231 case CSSPropertyWebkitHighlight: | 303 case CSSPropertyWebkitHighlight: |
| 232 return consumeWebkitHighlight(m_range); | 304 return consumeWebkitHighlight(m_range); |
| 233 case CSSPropertyFontVariantLigatures: | 305 case CSSPropertyFontVariantLigatures: |
| 234 return consumeFontVariantLigatures(m_range); | 306 return consumeFontVariantLigatures(m_range); |
| 307 case CSSPropertyLetterSpacing: | |
| 308 case CSSPropertyWordSpacing: | |
| 309 return consumeSpacing(m_range); | |
| 235 default: | 310 default: |
| 236 return nullptr; | 311 return nullptr; |
| 237 } | 312 } |
| 238 } | 313 } |
| 239 | 314 |
| 240 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) | 315 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
| 241 { | 316 { |
| 242 m_range.consumeWhitespace(); | 317 m_range.consumeWhitespace(); |
| 243 switch (propId) { | 318 switch (propId) { |
| 244 case CSSPropertyWebkitMarginCollapse: { | 319 case CSSPropertyWebkitMarginCollapse: { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | 353 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); |
| 279 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); | 354 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); |
| 280 return true; | 355 return true; |
| 281 } | 356 } |
| 282 default: | 357 default: |
| 283 return false; | 358 return false; |
| 284 } | 359 } |
| 285 } | 360 } |
| 286 | 361 |
| 287 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |