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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 CSSParserValueList valueList(range); | 41 CSSParserValueList valueList(range); |
| 42 if (!valueList.size()) | 42 if (!valueList.size()) |
| 43 return false; // Parser error | 43 return false; // Parser error |
| 44 CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleT ype); | 44 CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleT ype); |
| 45 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); | 45 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
| 46 bool parseSuccess; | 46 bool parseSuccess; |
| 47 | 47 |
| 48 if (ruleType == StyleRule::Viewport) { | 48 if (ruleType == StyleRule::Viewport) { |
| 49 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee tBehavior(context.mode())) | 49 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee tBehavior(context.mode())) |
| 50 && parser.parseViewportProperty(resolvedProperty, important); | 50 && parser.parseViewportDescriptor(resolvedProperty, important); |
| 51 } else if (ruleType == StyleRule::FontFace) { | 51 } else if (ruleType == StyleRule::FontFace) { |
| 52 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); | 52 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); |
| 53 } else { | 53 } else { |
| 54 parseSuccess = parser.parseValue(unresolvedProperty, important); | 54 parseSuccess = parser.parseValue(unresolvedProperty, important); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // This doesn't count UA style sheets | 57 // This doesn't count UA style sheets |
| 58 if (parseSuccess && context.useCounter()) | 58 if (parseSuccess && context.useCounter()) |
| 59 context.useCounter()->count(context, unresolvedProperty); | 59 context.useCounter()->count(context, unresolvedProperty); |
| 60 | 60 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 CalcParser calcParser(range, ValueRangeAll); | 288 CalcParser calcParser(range, ValueRangeAll); |
| 289 if (const CSSCalcValue* calculation = calcParser.value()) { | 289 if (const CSSCalcValue* calculation = calcParser.value()) { |
| 290 if (calculation->category() == CalcAngle) | 290 if (calculation->category() == CalcAngle) |
| 291 return calcParser.consumeValue(); | 291 return calcParser.consumeValue(); |
| 292 } | 292 } |
| 293 return nullptr; | 293 return nullptr; |
| 294 } | 294 } |
| 295 | 295 |
| 296 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRa nge& range, ValueRange valueRange) | |
|
Timothy Loh
2015/10/07 00:18:33
Probably makes more sense if this is before consum
rwlbuis
2015/10/07 23:08:53
Done.
| |
| 297 { | |
| 298 const CSSParserToken& token = range.peek(); | |
| 299 if (token.type() == PercentageToken) { | |
| 300 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) | |
| 301 return nullptr; | |
| 302 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), CSSPrimitiveValue::UnitType::Percentage); | |
| 303 } | |
| 304 CalcParser calcParser(range, valueRange); | |
| 305 if (const CSSCalcValue* calculation = calcParser.value()) { | |
| 306 if (calculation->category() == CalcPercent) | |
| 307 return calcParser.consumeValue(); | |
| 308 } | |
| 309 return nullptr; | |
| 310 } | |
| 311 | |
| 296 static inline bool isCSSWideKeyword(const CSSValueID& id) | 312 static inline bool isCSSWideKeyword(const CSSValueID& id) |
| 297 { | 313 { |
| 298 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; | 314 return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| 299 } | 315 } |
| 300 | 316 |
| 301 // Methods for consuming non-shorthand properties starts here. | 317 // Methods for consuming non-shorthand properties starts here. |
| 302 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) | 318 static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& r ange) |
| 303 { | 319 { |
| 304 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 320 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 305 if (range.peek().id() == CSSValueAuto) { | 321 if (range.peek().id() == CSSValueAuto) { |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 break; | 793 break; |
| 778 } | 794 } |
| 779 | 795 |
| 780 if (!parsedValue || !m_range.atEnd()) | 796 if (!parsedValue || !m_range.atEnd()) |
| 781 return false; | 797 return false; |
| 782 | 798 |
| 783 addProperty(propId, parsedValue.release(), false); | 799 addProperty(propId, parsedValue.release(), false); |
| 784 return true; | 800 return true; |
| 785 } | 801 } |
| 786 | 802 |
| 803 static PassRefPtrWillBeRawPtr<CSSValue> consumeViewportLonghand(CSSParserTokenRa nge& range, CSSPropertyID propId, CSSParserMode cssParserMode) | |
|
Timothy Loh
2015/10/07 00:18:33
consumeSingleViewportDescriptor (or something bett
rwlbuis
2015/10/07 23:08:53
Done.
| |
| 804 { | |
| 805 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; | |
| 806 CSSValueID id = range.peek().id(); | |
| 807 switch (propId) { | |
| 808 case CSSPropertyMinWidth: | |
| 809 case CSSPropertyMaxWidth: | |
| 810 case CSSPropertyMinHeight: | |
| 811 case CSSPropertyMaxHeight: | |
| 812 if (id == CSSValueAuto || id == CSSValueInternalExtendToZoom) | |
| 813 parsedValue = consumeIdent(range); | |
|
Timothy Loh
2015/10/07 00:18:33
return consumeIdent(range); and so on for the rest
rwlbuis
2015/10/07 23:08:53
Yeah much better :) Done.
| |
| 814 else | |
| 815 parsedValue = consumeLengthOrPercent(range, cssParserMode, ValueRang eNonNegative); | |
| 816 break; | |
| 817 case CSSPropertyMinZoom: | |
| 818 case CSSPropertyMaxZoom: | |
| 819 case CSSPropertyZoom: | |
| 820 if (id == CSSValueAuto) { | |
| 821 parsedValue = consumeIdent(range); | |
| 822 } else { | |
| 823 parsedValue = consumeNumber(range, ValueRangeNonNegative); | |
| 824 if (!parsedValue) | |
| 825 parsedValue = consumePercent(range, ValueRangeNonNegative); | |
| 826 } | |
| 827 break; | |
| 828 case CSSPropertyUserZoom: | |
| 829 if (id == CSSValueZoom || id == CSSValueFixed) | |
| 830 parsedValue = consumeIdent(range); | |
| 831 break; | |
| 832 case CSSPropertyOrientation: | |
| 833 if (id == CSSValueAuto || id == CSSValuePortrait || id == CSSValueLandsc ape) | |
| 834 parsedValue = consumeIdent(range); | |
| 835 default: | |
| 836 break; | |
| 837 } | |
| 838 | |
| 839 return parsedValue; | |
| 840 } | |
| 841 | |
| 842 bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId, bool impor tant) | |
| 843 { | |
| 844 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode())); | |
| 845 | |
| 846 m_range.consumeWhitespace(); | |
| 847 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; | |
| 848 | |
| 849 switch (propId) { | |
| 850 case CSSPropertyWidth: { | |
|
Timothy Loh
2015/10/07 00:18:33
I think there's an assertion in addProperty that c
rwlbuis
2015/10/07 23:08:53
Done.
| |
| 851 RefPtrWillBeRawPtr<CSSValue> minWidth = consumeViewportLonghand(m_range, CSSPropertyMinWidth, m_context.mode()); | |
| 852 if (!minWidth) | |
| 853 return false; | |
| 854 addProperty(CSSPropertyMinWidth, minWidth, important); | |
|
Timothy Loh
2015/10/07 00:18:33
I think this would be slightly nicer as:
RefPtrWi
rwlbuis
2015/10/07 23:08:53
Done.
| |
| 855 if (m_range.atEnd()) { | |
| 856 addProperty(CSSPropertyMaxWidth, minWidth, important); | |
| 857 return true; | |
| 858 } | |
| 859 RefPtrWillBeRawPtr<CSSValue> maxWidth = consumeViewportLonghand(m_range, CSSPropertyMaxWidth, m_context.mode()); | |
| 860 if (!maxWidth || !m_range.atEnd()) | |
| 861 return false; | |
| 862 addProperty(CSSPropertyMaxWidth, maxWidth, important); | |
| 863 return true; | |
| 864 } | |
| 865 case CSSPropertyHeight: { | |
| 866 RefPtrWillBeRawPtr<CSSValue> minHeight = consumeViewportLonghand(m_range , CSSPropertyMinHeight, m_context.mode()); | |
| 867 if (!minHeight) | |
| 868 return false; | |
| 869 addProperty(CSSPropertyMinHeight, minHeight, important); | |
| 870 if (m_range.atEnd()) { | |
| 871 addProperty(CSSPropertyMaxHeight, minHeight, important); | |
| 872 return true; | |
| 873 } | |
| 874 RefPtrWillBeRawPtr<CSSValue> maxHeight = consumeViewportLonghand(m_range , CSSPropertyMaxHeight, m_context.mode()); | |
| 875 if (!maxHeight || !m_range.atEnd()) | |
| 876 return false; | |
| 877 addProperty(CSSPropertyMaxHeight, maxHeight, important); | |
| 878 return true; | |
| 879 } | |
| 880 case CSSPropertyMinWidth: | |
| 881 case CSSPropertyMaxWidth: | |
| 882 case CSSPropertyMinHeight: | |
| 883 case CSSPropertyMaxHeight: | |
| 884 case CSSPropertyMinZoom: | |
| 885 case CSSPropertyMaxZoom: | |
| 886 case CSSPropertyZoom: | |
| 887 case CSSPropertyUserZoom: | |
| 888 case CSSPropertyOrientation: | |
| 889 default: | |
|
Timothy Loh
2015/10/07 00:18:33
How about return false in this default and ASSERT_
rwlbuis
2015/10/07 23:08:52
Done.
| |
| 890 parsedValue = consumeViewportLonghand(m_range, propId, m_context.mode()) ; | |
| 891 break; | |
| 892 } | |
| 893 | |
| 894 if (!parsedValue || !m_range.atEnd()) | |
| 895 return false; | |
| 896 | |
| 897 addProperty(propId, parsedValue.release(), important); | |
| 898 return true; | |
| 899 } | |
| 900 | |
| 787 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) | 901 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
| 788 { | 902 { |
| 789 m_range.consumeWhitespace(); | 903 m_range.consumeWhitespace(); |
| 790 switch (propId) { | 904 switch (propId) { |
| 791 case CSSPropertyWebkitMarginCollapse: { | 905 case CSSPropertyWebkitMarginCollapse: { |
| 792 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 906 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
| 793 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) | 907 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) |
| 794 return false; | 908 return false; |
| 795 RefPtrWillBeRawPtr<CSSValue> beforeCollapse = cssValuePool().createIdent ifierValue(id); | 909 RefPtrWillBeRawPtr<CSSValue> beforeCollapse = cssValuePool().createIdent ifierValue(id); |
| 796 addProperty(CSSPropertyWebkitMarginBeforeCollapse, beforeCollapse, impor tant); | 910 addProperty(CSSPropertyWebkitMarginBeforeCollapse, beforeCollapse, impor tant); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 825 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | 939 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); |
| 826 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); | 940 addProperty(CSSPropertyOverflowY, overflowYValue.release(), important); |
| 827 return true; | 941 return true; |
| 828 } | 942 } |
| 829 default: | 943 default: |
| 830 return false; | 944 return false; |
| 831 } | 945 } |
| 832 } | 946 } |
| 833 | 947 |
| 834 } // namespace blink | 948 } // namespace blink |
| OLD | NEW |