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