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/CSSFontFaceSrcValue.h" | 10 #include "core/css/CSSFontFaceSrcValue.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 119 |
| 120 static CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) | 120 static CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) |
| 121 { | 121 { |
| 122 ASSERT(range.peek().type() == FunctionToken); | 122 ASSERT(range.peek().type() == FunctionToken); |
| 123 CSSParserTokenRange contents = range.consumeBlock(); | 123 CSSParserTokenRange contents = range.consumeBlock(); |
| 124 range.consumeWhitespace(); | 124 range.consumeWhitespace(); |
| 125 contents.consumeWhitespace(); | 125 contents.consumeWhitespace(); |
| 126 return contents; | 126 return contents; |
| 127 } | 127 } |
| 128 | 128 |
| 129 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa nge& range, CSSParserMode cssParserMode, double minimumValue = std::numeric_limi ts<int>::min()) | |
| 130 { | |
| 131 const CSSParserToken& token = range.peek(); | |
| 132 if (token.type() == NumberToken) { | |
| 133 if (token.numericValueType() == NumberValueType || token.numericValue() < static_cast<double>(minimumValue)) | |
|
alancutter (OOO until 2018)
2015/09/28 23:40:04
No need to cast.
| |
| 134 return nullptr; | |
| 135 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); | |
| 136 } | |
| 137 if (token.functionId() == CSSValueCalc || token.functionId() == CSSValueWebk itCalc) { | |
| 138 RefPtrWillBeRawPtr<CSSCalcValue> calculation = CSSCalcValue::create(cons umeFunction(range), ValueRangeAll); | |
| 139 if (!calculation || calculation->category() != CalcNumber || !calculatio n->isInt()) | |
| 140 return nullptr; | |
| 141 double value = calculation->doubleValue(); | |
| 142 if (value < minimumValue) | |
| 143 return nullptr; | |
|
alancutter (OOO until 2018)
2015/09/28 23:40:04
calc()s are special and clamp to the allowed range
| |
| 144 return CSSPrimitiveValue::create(calculation.release()); | |
| 145 } | |
| 146 return nullptr; | |
| 147 } | |
| 148 | |
| 149 inline bool shouldAcceptUnitLessValues(double fValue, CSSParserMode cssParserMod e) | |
| 150 { | |
| 151 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units. | |
| 152 return !fValue // 0 can always be unitless. | |
| 153 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. | |
| 154 || cssParserMode == HTMLQuirksMode; | |
| 155 } | |
| 156 | |
| 157 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ge& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk uni tless = UnitlessQuirk::Forbid) | |
| 158 { | |
| 159 const CSSParserToken& token = range.peek(); | |
| 160 if (token.type() == DimensionToken) { | |
| 161 bool validNumber = false; | |
| 162 switch (token.unitType()) { | |
| 163 case CSSPrimitiveValue::UnitType::QuirkyEms: | |
| 164 if (cssParserMode != UASheetMode) | |
| 165 return nullptr; | |
| 166 /* fallthrough intentional */ | |
| 167 case CSSPrimitiveValue::UnitType::Ems: | |
| 168 case CSSPrimitiveValue::UnitType::Rems: | |
| 169 case CSSPrimitiveValue::UnitType::Chs: | |
| 170 case CSSPrimitiveValue::UnitType::Exs: | |
| 171 case CSSPrimitiveValue::UnitType::Pixels: | |
| 172 case CSSPrimitiveValue::UnitType::Centimeters: | |
| 173 case CSSPrimitiveValue::UnitType::Millimeters: | |
| 174 case CSSPrimitiveValue::UnitType::Inches: | |
| 175 case CSSPrimitiveValue::UnitType::Points: | |
| 176 case CSSPrimitiveValue::UnitType::Picas: | |
| 177 case CSSPrimitiveValue::UnitType::ViewportWidth: | |
| 178 case CSSPrimitiveValue::UnitType::ViewportHeight: | |
| 179 case CSSPrimitiveValue::UnitType::ViewportMin: | |
| 180 case CSSPrimitiveValue::UnitType::ViewportMax: | |
| 181 validNumber = true; | |
| 182 break; | |
| 183 default: | |
| 184 break; | |
| 185 } | |
| 186 if (!validNumber || (valueRange == ValueRangeNonNegative && token.numeri cValue() < 0)) | |
| 187 return nullptr; | |
| 188 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); | |
| 189 } | |
| 190 if (token.type() == NumberToken) { | |
| 191 if (unitless == UnitlessQuirk::Forbid || !shouldAcceptUnitLessValues(tok en.numericValue(), cssParserMode) | |
| 192 || (valueRange == ValueRangeNonNegative && token.numericValue() < 0) ) | |
| 193 return nullptr; | |
| 194 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), CSSPrimitiveValue::UnitType::Pixels); | |
| 195 } | |
| 196 if (token.functionId() == CSSValueCalc || token.functionId() == CSSValueWebk itCalc) { | |
| 197 RefPtrWillBeRawPtr<CSSCalcValue> calculation = CSSCalcValue::create(cons umeFunction(range), valueRange); | |
| 198 if (!calculation || calculation->category() != CalcLength) | |
| 199 return nullptr; | |
| 200 return CSSPrimitiveValue::create(calculation.release()); | |
| 201 } | |
| 202 return nullptr; | |
| 203 } | |
| 204 | |
| 129 static inline bool isCSSWideKeyword(const CSSValueID& id) | 205 static inline bool isCSSWideKeyword(const CSSValueID& id) |
| 130 { | 206 { |
| 131 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; | 207 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| 132 } | 208 } |
| 133 | 209 |
| 134 // Methods for consuming non-shorthand properties starts here. | 210 // Methods for consuming non-shorthand properties starts here. |
| 135 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) | 211 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) |
| 136 { | 212 { |
| 137 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 213 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 138 if (range.peek().id() == CSSValueAuto) { | 214 if (range.peek().id() == CSSValueAuto) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 list->append(parsedValue); | 465 list->append(parsedValue); |
| 390 } else if ((parsedValue = consumeFamilyName(range))) { | 466 } else if ((parsedValue = consumeFamilyName(range))) { |
| 391 list->append(parsedValue); | 467 list->append(parsedValue); |
| 392 } else { | 468 } else { |
| 393 return nullptr; | 469 return nullptr; |
| 394 } | 470 } |
| 395 } while (consumeCommaIncludingWhitespace(range)); | 471 } while (consumeCommaIncludingWhitespace(range)); |
| 396 return list.release(); | 472 return list.release(); |
| 397 } | 473 } |
| 398 | 474 |
| 475 static PassRefPtrWillBeRawPtr<CSSValue> consumeSpacing(CSSParserTokenRange& rang e, CSSParserMode cssParserMode) | |
| 476 { | |
| 477 if (range.peek().id() == CSSValueNormal) | |
| 478 return consumeIdent(range); | |
| 479 // TODO(timloh): Don't allow unitless values, and allow <percentage>s in wor d-spacing. | |
| 480 return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::All ow); | |
| 481 } | |
| 482 | |
| 483 static PassRefPtrWillBeRawPtr<CSSValue> consumeTabSize(CSSParserTokenRange& rang e, CSSParserMode cssParserMode) | |
| 484 { | |
| 485 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeInteger(range, cs sParserMode, 0); | |
| 486 if (parsedValue) | |
| 487 return parsedValue; | |
| 488 return consumeLength(range, cssParserMode, ValueRangeNonNegative); | |
| 489 } | |
| 490 | |
| 399 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 491 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
| 400 { | 492 { |
| 401 m_range.consumeWhitespace(); | 493 m_range.consumeWhitespace(); |
| 402 switch (propId) { | 494 switch (propId) { |
| 403 case CSSPropertyWillChange: | 495 case CSSPropertyWillChange: |
| 404 return consumeWillChange(m_range); | 496 return consumeWillChange(m_range); |
| 405 case CSSPropertyPage: | 497 case CSSPropertyPage: |
| 406 return consumePage(m_range); | 498 return consumePage(m_range); |
| 407 case CSSPropertyQuotes: | 499 case CSSPropertyQuotes: |
| 408 return consumeQuotes(m_range); | 500 return consumeQuotes(m_range); |
| 409 case CSSPropertyWebkitHighlight: | 501 case CSSPropertyWebkitHighlight: |
| 410 return consumeWebkitHighlight(m_range); | 502 return consumeWebkitHighlight(m_range); |
| 411 case CSSPropertyFontVariantLigatures: | 503 case CSSPropertyFontVariantLigatures: |
| 412 return consumeFontVariantLigatures(m_range); | 504 return consumeFontVariantLigatures(m_range); |
| 413 case CSSPropertyWebkitFontFeatureSettings: | 505 case CSSPropertyWebkitFontFeatureSettings: |
| 414 return consumeFontFeatureSettings(m_range); | 506 return consumeFontFeatureSettings(m_range); |
| 415 case CSSPropertyFontVariant: | 507 case CSSPropertyFontVariant: |
| 416 return consumeFontVariant(); | 508 return consumeFontVariant(); |
| 417 case CSSPropertyFontFamily: | 509 case CSSPropertyFontFamily: |
| 418 return consumeFontFamily(m_range); | 510 return consumeFontFamily(m_range); |
| 419 case CSSPropertyFontWeight: | 511 case CSSPropertyFontWeight: |
| 420 return consumeFontWeight(m_range); | 512 return consumeFontWeight(m_range); |
| 513 case CSSPropertyLetterSpacing: | |
| 514 case CSSPropertyWordSpacing: | |
| 515 return consumeSpacing(m_range, m_context.mode()); | |
| 516 case CSSPropertyTabSize: | |
| 517 return consumeTabSize(m_range, m_context.mode()); | |
| 421 default: | 518 default: |
| 422 return nullptr; | 519 return nullptr; |
| 423 } | 520 } |
| 424 } | 521 } |
| 425 | 522 |
| 426 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 523 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 427 { | 524 { |
| 428 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 525 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 429 | 526 |
| 430 do { | 527 do { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | 680 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); |
| 584 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); | 681 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); |
| 585 return true; | 682 return true; |
| 586 } | 683 } |
| 587 default: | 684 default: |
| 588 return false; | 685 return false; |
| 589 } | 686 } |
| 590 } | 687 } |
| 591 | 688 |
| 592 } // namespace blink | 689 } // namespace blink |
| OLD | NEW |