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 // TODO(rwlbuis) Calcs should not be subject to parse time range checks. | |
197 // spec: https://drafts.csswg.org/css-values-3/#calc-range | |
198 if (calculation->category() != CalcNumber || (valueRange == ValueRangeNo nNegative && calculation->isNegative())) | |
199 return nullptr; | |
200 return calcParser.consumeValue(); | |
alancutter (OOO until 2018)
2015/10/02 03:50:10
Last minute catch, this should be consumeNumber().
| |
201 } | |
202 return nullptr; | |
203 } | |
204 | |
186 inline bool shouldAcceptUnitlessValues(double fValue, CSSParserMode cssParserMod e, UnitlessQuirk unitless) | 205 inline bool shouldAcceptUnitlessValues(double fValue, CSSParserMode cssParserMod e, UnitlessQuirk unitless) |
187 { | 206 { |
188 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units. | 207 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units. |
189 return !fValue // 0 can always be unitless. | 208 return !fValue // 0 can always be unitless. |
190 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. | 209 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. |
191 || (cssParserMode == HTMLQuirksMode && (unitless == UnitlessQuirk::Allow )); | 210 || (cssParserMode == HTMLQuirksMode && (unitless == UnitlessQuirk::Allow )); |
192 } | 211 } |
193 | 212 |
194 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ge& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk uni tless = UnitlessQuirk::Forbid) | 213 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan ge& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk uni tless = UnitlessQuirk::Forbid) |
195 { | 214 { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 return consumeLength(range, cssParserMode, ValueRangeNonNegative); | 557 return consumeLength(range, cssParserMode, ValueRangeNonNegative); |
539 } | 558 } |
540 | 559 |
541 static PassRefPtrWillBeRawPtr<CSSValue> consumeFontSize(CSSParserTokenRange& ran ge, CSSParserMode cssParserMode) | 560 static PassRefPtrWillBeRawPtr<CSSValue> consumeFontSize(CSSParserTokenRange& ran ge, CSSParserMode cssParserMode) |
542 { | 561 { |
543 if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLar ger) | 562 if (range.peek().id() >= CSSValueXxSmall && range.peek().id() <= CSSValueLar ger) |
544 return consumeIdent(range); | 563 return consumeIdent(range); |
545 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); | 564 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); |
546 } | 565 } |
547 | 566 |
567 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLineHeight(CSSParserToke nRange& range, CSSParserMode cssParserMode) | |
568 { | |
569 if (range.peek().id() == CSSValueNormal) | |
570 return consumeIdent(range); | |
571 | |
572 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineHeight = consumeNumber(range, Valu eRangeNonNegative); | |
573 if (lineHeight) | |
574 return lineHeight; | |
575 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); | |
576 } | |
577 | |
548 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 578 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
549 { | 579 { |
550 m_range.consumeWhitespace(); | 580 m_range.consumeWhitespace(); |
551 switch (propId) { | 581 switch (propId) { |
552 case CSSPropertyWillChange: | 582 case CSSPropertyWillChange: |
553 return consumeWillChange(m_range); | 583 return consumeWillChange(m_range); |
554 case CSSPropertyPage: | 584 case CSSPropertyPage: |
555 return consumePage(m_range); | 585 return consumePage(m_range); |
556 case CSSPropertyQuotes: | 586 case CSSPropertyQuotes: |
557 return consumeQuotes(m_range); | 587 return consumeQuotes(m_range); |
558 case CSSPropertyWebkitHighlight: | 588 case CSSPropertyWebkitHighlight: |
559 return consumeWebkitHighlight(m_range); | 589 return consumeWebkitHighlight(m_range); |
560 case CSSPropertyFontVariantLigatures: | 590 case CSSPropertyFontVariantLigatures: |
561 return consumeFontVariantLigatures(m_range); | 591 return consumeFontVariantLigatures(m_range); |
562 case CSSPropertyWebkitFontFeatureSettings: | 592 case CSSPropertyWebkitFontFeatureSettings: |
563 return consumeFontFeatureSettings(m_range); | 593 return consumeFontFeatureSettings(m_range); |
564 case CSSPropertyFontVariant: | 594 case CSSPropertyFontVariant: |
565 return consumeFontVariant(); | 595 return consumeFontVariant(); |
566 case CSSPropertyFontFamily: | 596 case CSSPropertyFontFamily: |
567 return consumeFontFamily(m_range); | 597 return consumeFontFamily(m_range); |
568 case CSSPropertyFontWeight: | 598 case CSSPropertyFontWeight: |
569 return consumeFontWeight(m_range); | 599 return consumeFontWeight(m_range); |
570 case CSSPropertyLetterSpacing: | 600 case CSSPropertyLetterSpacing: |
571 case CSSPropertyWordSpacing: | 601 case CSSPropertyWordSpacing: |
572 return consumeSpacing(m_range, m_context.mode()); | 602 return consumeSpacing(m_range, m_context.mode()); |
573 case CSSPropertyTabSize: | 603 case CSSPropertyTabSize: |
574 return consumeTabSize(m_range, m_context.mode()); | 604 return consumeTabSize(m_range, m_context.mode()); |
575 case CSSPropertyFontSize: | 605 case CSSPropertyFontSize: |
576 return consumeFontSize(m_range, m_context.mode()); | 606 return consumeFontSize(m_range, m_context.mode()); |
607 case CSSPropertyLineHeight: | |
608 return consumeLineHeight(m_range, m_context.mode()); | |
577 default: | 609 default: |
578 return nullptr; | 610 return nullptr; |
579 } | 611 } |
580 } | 612 } |
581 | 613 |
582 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 614 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
583 { | 615 { |
584 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 616 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
585 | 617 |
586 do { | 618 do { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | 771 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); |
740 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); | 772 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); |
741 return true; | 773 return true; |
742 } | 774 } |
743 default: | 775 default: |
744 return false; | 776 return false; |
745 } | 777 } |
746 } | 778 } |
747 | 779 |
748 } // namespace blink | 780 } // namespace blink |
OLD | NEW |