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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 if (calculation->category() != CalcNumber || !calculation->isInt()) | 176 if (calculation->category() != CalcNumber || !calculation->isInt()) |
| 177 return nullptr; | 177 return nullptr; |
| 178 double value = calculation->doubleValue(); | 178 double value = calculation->doubleValue(); |
| 179 if (value < minimumValue) | 179 if (value < minimumValue) |
| 180 return nullptr; | 180 return nullptr; |
| 181 return calcParser.consumeNumber(); | 181 return calcParser.consumeNumber(); |
| 182 } | 182 } |
| 183 return nullptr; | 183 return nullptr; |
| 184 } | 184 } |
| 185 | 185 |
| 186 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRan ge& range, ValueRange valueRange) | |
| 187 { | |
| 188 const CSSParserToken& token = range.peek(); | |
| 189 if (token.type() == NumberToken) { | |
| 190 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) | |
| 191 return nullptr; | |
| 192 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); | |
| 193 } | |
| 194 CalcParser calcParser(range, ValueRangeAll); | |
| 195 if (const CSSCalcValue* calculation = calcParser.value()) { | |
| 196 if (calculation->category() != CalcNumber || (valueRange == ValueRangeNo nNegative && calculation->isNegative())) | |
|
alancutter (OOO until 2018)
2015/10/02 01:54:10
I don't think calcs should be subject to parse tim
| |
| 197 return nullptr; | |
| 198 return calcParser.consumeValue(); | |
| 199 } | |
| 200 return nullptr; | |
| 201 } | |
| 202 | |
| 186 inline bool shouldAcceptUnitlessValues(double fValue, CSSParserMode cssParserMod e, UnitlessQuirk unitless) | 203 inline bool shouldAcceptUnitlessValues(double fValue, CSSParserMode cssParserMod e, UnitlessQuirk unitless) |
| 187 { | 204 { |
| 188 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units. | 205 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units. |
| 189 return !fValue // 0 can always be unitless. | 206 return !fValue // 0 can always be unitless. |
| 190 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. | 207 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. |
| 191 || (cssParserMode == HTMLQuirksMode && (unitless == UnitlessQuirk::Allow )); | 208 || (cssParserMode == HTMLQuirksMode && (unitless == UnitlessQuirk::Allow )); |
| 192 } | 209 } |
| 193 | 210 |
| 194 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ge& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk uni tless = UnitlessQuirk::Forbid) | 211 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ge& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk uni tless = UnitlessQuirk::Forbid) |
| 195 { | 212 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), CSSPrimitiveValue::UnitType::Percentage); | 262 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), CSSPrimitiveValue::UnitType::Percentage); |
| 246 } | 263 } |
| 247 CalcParser calcParser(range, valueRange); | 264 CalcParser calcParser(range, valueRange); |
| 248 if (const CSSCalcValue* calculation = calcParser.value()) { | 265 if (const CSSCalcValue* calculation = calcParser.value()) { |
| 249 if (calculation->category() == CalcLength || calculation->category() == CalcPercent || calculation->category() == CalcPercentLength) | 266 if (calculation->category() == CalcLength || calculation->category() == CalcPercent || calculation->category() == CalcPercentLength) |
| 250 return calcParser.consumeValue(); | 267 return calcParser.consumeValue(); |
| 251 } | 268 } |
| 252 return nullptr; | 269 return nullptr; |
| 253 } | 270 } |
| 254 | 271 |
| 272 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumberOrPercent(CSSParse rTokenRange& range, ValueRange valueRange) | |
| 273 { | |
| 274 const CSSParserToken& token = range.peek(); | |
| 275 if (token.type() == NumberToken) | |
| 276 return consumeNumber(range, valueRange); | |
| 277 if (token.type() == PercentageToken) { | |
| 278 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) | |
| 279 return nullptr; | |
| 280 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), CSSPrimitiveValue::UnitType::Percentage); | |
| 281 } | |
| 282 CalcParser calcParser(range, valueRange); | |
| 283 if (const CSSCalcValue* calculation = calcParser.value()) { | |
| 284 if (!(calculation->category() == CalcNumber || calculation->category() = = CalcPercent || calculation->category() == CalcPercentNumber)) | |
| 285 return nullptr; | |
| 286 if (valueRange == ValueRangeNonNegative && calculation->isNegative()) | |
| 287 return nullptr; | |
| 288 return calcParser.consumeValue(); | |
| 289 } | |
| 290 return nullptr; | |
| 291 } | |
| 292 | |
| 255 static inline bool isCSSWideKeyword(const CSSValueID& id) | 293 static inline bool isCSSWideKeyword(const CSSValueID& id) |
| 256 { | 294 { |
| 257 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; | 295 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| 258 } | 296 } |
| 259 | 297 |
| 260 // Methods for consuming non-shorthand properties starts here. | 298 // Methods for consuming non-shorthand properties starts here. |
| 261 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) | 299 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) |
| 262 { | 300 { |
| 263 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 301 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 264 if (range.peek().id() == CSSValueAuto) { | 302 if (range.peek().id() == CSSValueAuto) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 return consumeLength(range, cssParserMode, ValueRangeNonNegative); | 576 return consumeLength(range, cssParserMode, ValueRangeNonNegative); |
| 539 } | 577 } |
| 540 | 578 |
| 541 static PassRefPtrWillBeRawPtr<CSSValue> consumeFontSize(CSSParserTokenRange& ran ge, CSSParserMode cssParserMode) | 579 static PassRefPtrWillBeRawPtr<CSSValue> consumeFontSize(CSSParserTokenRange& ran ge, CSSParserMode cssParserMode) |
| 542 { | 580 { |
| 543 if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLar ger) | 581 if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLar ger) |
| 544 return consumeIdent(range); | 582 return consumeIdent(range); |
| 545 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); | 583 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); |
| 546 } | 584 } |
| 547 | 585 |
| 586 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLineHeight(CSSParserToke nRange& range, CSSParserMode cssParserMode) | |
| 587 { | |
| 588 if (range.peek().id() == CSSValueNormal) | |
| 589 return consumeIdent(range); | |
| 590 | |
| 591 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeNumberOrPercent(r ange, ValueRangeNonNegative); | |
| 592 if (!parsedValue) | |
| 593 parsedValue = consumeLengthOrPercent(range, cssParserMode, ValueRangeNon Negative); | |
| 594 | |
| 595 // The line-height property can accept both percents and numbers but additiv e opertaions are | |
| 596 // not permitted on them in calc() expressions. | |
| 597 if (parsedValue && parsedValue->isCalculatedPercentageWithNumber()) | |
| 598 return nullptr; | |
| 599 | |
| 600 return parsedValue.release(); | |
| 601 } | |
| 602 | |
| 548 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 603 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
| 549 { | 604 { |
| 550 m_range.consumeWhitespace(); | 605 m_range.consumeWhitespace(); |
| 551 switch (propId) { | 606 switch (propId) { |
| 552 case CSSPropertyWillChange: | 607 case CSSPropertyWillChange: |
| 553 return consumeWillChange(m_range); | 608 return consumeWillChange(m_range); |
| 554 case CSSPropertyPage: | 609 case CSSPropertyPage: |
| 555 return consumePage(m_range); | 610 return consumePage(m_range); |
| 556 case CSSPropertyQuotes: | 611 case CSSPropertyQuotes: |
| 557 return consumeQuotes(m_range); | 612 return consumeQuotes(m_range); |
| 558 case CSSPropertyWebkitHighlight: | 613 case CSSPropertyWebkitHighlight: |
| 559 return consumeWebkitHighlight(m_range); | 614 return consumeWebkitHighlight(m_range); |
| 560 case CSSPropertyFontVariantLigatures: | 615 case CSSPropertyFontVariantLigatures: |
| 561 return consumeFontVariantLigatures(m_range); | 616 return consumeFontVariantLigatures(m_range); |
| 562 case CSSPropertyWebkitFontFeatureSettings: | 617 case CSSPropertyWebkitFontFeatureSettings: |
| 563 return consumeFontFeatureSettings(m_range); | 618 return consumeFontFeatureSettings(m_range); |
| 564 case CSSPropertyFontVariant: | 619 case CSSPropertyFontVariant: |
| 565 return consumeFontVariant(); | 620 return consumeFontVariant(); |
| 566 case CSSPropertyFontFamily: | 621 case CSSPropertyFontFamily: |
| 567 return consumeFontFamily(m_range); | 622 return consumeFontFamily(m_range); |
| 568 case CSSPropertyFontWeight: | 623 case CSSPropertyFontWeight: |
| 569 return consumeFontWeight(m_range); | 624 return consumeFontWeight(m_range); |
| 570 case CSSPropertyLetterSpacing: | 625 case CSSPropertyLetterSpacing: |
| 571 case CSSPropertyWordSpacing: | 626 case CSSPropertyWordSpacing: |
| 572 return consumeSpacing(m_range, m_context.mode()); | 627 return consumeSpacing(m_range, m_context.mode()); |
| 573 case CSSPropertyTabSize: | 628 case CSSPropertyTabSize: |
| 574 return consumeTabSize(m_range, m_context.mode()); | 629 return consumeTabSize(m_range, m_context.mode()); |
| 575 case CSSPropertyFontSize: | 630 case CSSPropertyFontSize: |
| 576 return consumeFontSize(m_range, m_context.mode()); | 631 return consumeFontSize(m_range, m_context.mode()); |
| 632 case CSSPropertyLineHeight: | |
| 633 return consumeLineHeight(m_range, m_context.mode()); | |
| 577 default: | 634 default: |
| 578 return nullptr; | 635 return nullptr; |
| 579 } | 636 } |
| 580 } | 637 } |
| 581 | 638 |
| 582 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 639 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 583 { | 640 { |
| 584 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 641 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 585 | 642 |
| 586 do { | 643 do { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | 796 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); |
| 740 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); | 797 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); |
| 741 return true; | 798 return true; |
| 742 } | 799 } |
| 743 default: | 800 default: |
| 744 return false; | 801 return false; |
| 745 } | 802 } |
| 746 } | 803 } |
| 747 | 804 |
| 748 } // namespace blink | 805 } // namespace blink |
| OLD | NEW |