| 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 "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
| 9 #include "core/css/CSSBasicShapeValues.h" | 9 #include "core/css/CSSBasicShapeValues.h" |
| 10 #include "core/css/CSSBorderImage.h" | 10 #include "core/css/CSSBorderImage.h" |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 792 |
| 793 return true; | 793 return true; |
| 794 } | 794 } |
| 795 | 795 |
| 796 static CSSValue* ConsumeBorderWidth(CSSParserTokenRange& range, | 796 static CSSValue* ConsumeBorderWidth(CSSParserTokenRange& range, |
| 797 CSSParserMode css_parser_mode, | 797 CSSParserMode css_parser_mode, |
| 798 UnitlessQuirk unitless) { | 798 UnitlessQuirk unitless) { |
| 799 return ConsumeLineWidth(range, css_parser_mode, unitless); | 799 return ConsumeLineWidth(range, css_parser_mode, unitless); |
| 800 } | 800 } |
| 801 | 801 |
| 802 static bool ConsumeTranslate3d(CSSParserTokenRange& args, | |
| 803 CSSParserMode css_parser_mode, | |
| 804 CSSFunctionValue*& transform_value) { | |
| 805 unsigned number_of_arguments = 2; | |
| 806 CSSValue* parsed_value = nullptr; | |
| 807 do { | |
| 808 parsed_value = | |
| 809 ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeAll); | |
| 810 if (!parsed_value) | |
| 811 return false; | |
| 812 transform_value->Append(*parsed_value); | |
| 813 if (!ConsumeCommaIncludingWhitespace(args)) | |
| 814 return false; | |
| 815 } while (--number_of_arguments); | |
| 816 parsed_value = ConsumeLength(args, css_parser_mode, kValueRangeAll); | |
| 817 if (!parsed_value) | |
| 818 return false; | |
| 819 transform_value->Append(*parsed_value); | |
| 820 return true; | |
| 821 } | |
| 822 | |
| 823 static bool ConsumeNumbers(CSSParserTokenRange& args, | |
| 824 CSSFunctionValue*& transform_value, | |
| 825 unsigned number_of_arguments) { | |
| 826 do { | |
| 827 CSSValue* parsed_value = ConsumeNumber(args, kValueRangeAll); | |
| 828 if (!parsed_value) | |
| 829 return false; | |
| 830 transform_value->Append(*parsed_value); | |
| 831 if (--number_of_arguments && !ConsumeCommaIncludingWhitespace(args)) | |
| 832 return false; | |
| 833 } while (number_of_arguments); | |
| 834 return true; | |
| 835 } | |
| 836 | |
| 837 static bool ConsumePerspective(CSSParserTokenRange& args, | |
| 838 const CSSParserContext* context, | |
| 839 CSSFunctionValue*& transform_value, | |
| 840 bool use_legacy_parsing) { | |
| 841 CSSPrimitiveValue* parsed_value = | |
| 842 ConsumeLength(args, context->Mode(), kValueRangeNonNegative); | |
| 843 if (!parsed_value && use_legacy_parsing) { | |
| 844 double perspective; | |
| 845 if (!ConsumeNumberRaw(args, perspective) || perspective < 0) | |
| 846 return false; | |
| 847 context->Count(UseCounter::kUnitlessPerspectiveInTransformProperty); | |
| 848 parsed_value = CSSPrimitiveValue::Create( | |
| 849 perspective, CSSPrimitiveValue::UnitType::kPixels); | |
| 850 } | |
| 851 if (!parsed_value) | |
| 852 return false; | |
| 853 transform_value->Append(*parsed_value); | |
| 854 return true; | |
| 855 } | |
| 856 | |
| 857 static CSSValue* ConsumeTransformValue(CSSParserTokenRange& range, | |
| 858 const CSSParserContext* context, | |
| 859 bool use_legacy_parsing) { | |
| 860 CSSValueID function_id = range.Peek().FunctionId(); | |
| 861 if (function_id == CSSValueInvalid) | |
| 862 return nullptr; | |
| 863 CSSParserTokenRange args = ConsumeFunction(range); | |
| 864 if (args.AtEnd()) | |
| 865 return nullptr; | |
| 866 CSSFunctionValue* transform_value = CSSFunctionValue::Create(function_id); | |
| 867 CSSValue* parsed_value = nullptr; | |
| 868 switch (function_id) { | |
| 869 case CSSValueRotate: | |
| 870 case CSSValueRotateX: | |
| 871 case CSSValueRotateY: | |
| 872 case CSSValueRotateZ: | |
| 873 case CSSValueSkewX: | |
| 874 case CSSValueSkewY: | |
| 875 case CSSValueSkew: | |
| 876 parsed_value = ConsumeAngle(args); | |
| 877 if (!parsed_value) | |
| 878 return nullptr; | |
| 879 if (function_id == CSSValueSkew && | |
| 880 ConsumeCommaIncludingWhitespace(args)) { | |
| 881 transform_value->Append(*parsed_value); | |
| 882 parsed_value = ConsumeAngle(args); | |
| 883 if (!parsed_value) | |
| 884 return nullptr; | |
| 885 } | |
| 886 break; | |
| 887 case CSSValueScaleX: | |
| 888 case CSSValueScaleY: | |
| 889 case CSSValueScaleZ: | |
| 890 case CSSValueScale: | |
| 891 parsed_value = ConsumeNumber(args, kValueRangeAll); | |
| 892 if (!parsed_value) | |
| 893 return nullptr; | |
| 894 if (function_id == CSSValueScale && | |
| 895 ConsumeCommaIncludingWhitespace(args)) { | |
| 896 transform_value->Append(*parsed_value); | |
| 897 parsed_value = ConsumeNumber(args, kValueRangeAll); | |
| 898 if (!parsed_value) | |
| 899 return nullptr; | |
| 900 } | |
| 901 break; | |
| 902 case CSSValuePerspective: | |
| 903 if (!ConsumePerspective(args, context, transform_value, | |
| 904 use_legacy_parsing)) | |
| 905 return nullptr; | |
| 906 break; | |
| 907 case CSSValueTranslateX: | |
| 908 case CSSValueTranslateY: | |
| 909 case CSSValueTranslate: | |
| 910 parsed_value = | |
| 911 ConsumeLengthOrPercent(args, context->Mode(), kValueRangeAll); | |
| 912 if (!parsed_value) | |
| 913 return nullptr; | |
| 914 if (function_id == CSSValueTranslate && | |
| 915 ConsumeCommaIncludingWhitespace(args)) { | |
| 916 transform_value->Append(*parsed_value); | |
| 917 parsed_value = | |
| 918 ConsumeLengthOrPercent(args, context->Mode(), kValueRangeAll); | |
| 919 if (!parsed_value) | |
| 920 return nullptr; | |
| 921 } | |
| 922 break; | |
| 923 case CSSValueTranslateZ: | |
| 924 parsed_value = ConsumeLength(args, context->Mode(), kValueRangeAll); | |
| 925 break; | |
| 926 case CSSValueMatrix: | |
| 927 case CSSValueMatrix3d: | |
| 928 if (!ConsumeNumbers(args, transform_value, | |
| 929 (function_id == CSSValueMatrix3d) ? 16 : 6)) | |
| 930 return nullptr; | |
| 931 break; | |
| 932 case CSSValueScale3d: | |
| 933 if (!ConsumeNumbers(args, transform_value, 3)) | |
| 934 return nullptr; | |
| 935 break; | |
| 936 case CSSValueRotate3d: | |
| 937 if (!ConsumeNumbers(args, transform_value, 3) || | |
| 938 !ConsumeCommaIncludingWhitespace(args)) | |
| 939 return nullptr; | |
| 940 parsed_value = ConsumeAngle(args); | |
| 941 if (!parsed_value) | |
| 942 return nullptr; | |
| 943 break; | |
| 944 case CSSValueTranslate3d: | |
| 945 if (!ConsumeTranslate3d(args, context->Mode(), transform_value)) | |
| 946 return nullptr; | |
| 947 break; | |
| 948 default: | |
| 949 return nullptr; | |
| 950 } | |
| 951 if (parsed_value) | |
| 952 transform_value->Append(*parsed_value); | |
| 953 if (!args.AtEnd()) | |
| 954 return nullptr; | |
| 955 return transform_value; | |
| 956 } | |
| 957 | |
| 958 static CSSValue* ConsumeTransform(CSSParserTokenRange& range, | |
| 959 const CSSParserContext* context, | |
| 960 bool use_legacy_parsing) { | |
| 961 if (range.Peek().Id() == CSSValueNone) | |
| 962 return ConsumeIdent(range); | |
| 963 | |
| 964 CSSValueList* list = CSSValueList::CreateSpaceSeparated(); | |
| 965 do { | |
| 966 CSSValue* parsed_transform_value = | |
| 967 ConsumeTransformValue(range, context, use_legacy_parsing); | |
| 968 if (!parsed_transform_value) | |
| 969 return nullptr; | |
| 970 list->Append(*parsed_transform_value); | |
| 971 } while (!range.AtEnd()); | |
| 972 | |
| 973 return list; | |
| 974 } | |
| 975 | |
| 976 static CSSValue* ConsumeNoneOrURI(CSSParserTokenRange& range, | 802 static CSSValue* ConsumeNoneOrURI(CSSParserTokenRange& range, |
| 977 const CSSParserContext* context) { | 803 const CSSParserContext* context) { |
| 978 if (range.Peek().Id() == CSSValueNone) | 804 if (range.Peek().Id() == CSSValueNone) |
| 979 return ConsumeIdent(range); | 805 return ConsumeIdent(range); |
| 980 return ConsumeUrl(range, context); | 806 return ConsumeUrl(range, context); |
| 981 } | 807 } |
| 982 | 808 |
| 983 static CSSValue* ConsumePerspective(CSSParserTokenRange& range, | 809 static CSSValue* ConsumePerspective(CSSParserTokenRange& range, |
| 984 const CSSParserContext* context, | 810 const CSSParserContext* context, |
| 985 CSSPropertyID unresolved_property) { | 811 CSSPropertyID unresolved_property) { |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1952 case CSSPropertyOffsetPath: | 1778 case CSSPropertyOffsetPath: |
| 1953 return ConsumeOffsetPath( | 1779 return ConsumeOffsetPath( |
| 1954 range_, context_, | 1780 range_, context_, |
| 1955 current_shorthand == CSSPropertyMotion || | 1781 current_shorthand == CSSPropertyMotion || |
| 1956 unresolved_property == CSSPropertyAliasMotionPath); | 1782 unresolved_property == CSSPropertyAliasMotionPath); |
| 1957 case CSSPropertyOffsetDistance: | 1783 case CSSPropertyOffsetDistance: |
| 1958 return ConsumeLengthOrPercent(range_, context_->Mode(), kValueRangeAll); | 1784 return ConsumeLengthOrPercent(range_, context_->Mode(), kValueRangeAll); |
| 1959 case CSSPropertyOffsetRotate: | 1785 case CSSPropertyOffsetRotate: |
| 1960 case CSSPropertyOffsetRotation: | 1786 case CSSPropertyOffsetRotation: |
| 1961 return ConsumeOffsetRotate(range_); | 1787 return ConsumeOffsetRotate(range_); |
| 1962 case CSSPropertyTransform: | |
| 1963 return ConsumeTransform( | |
| 1964 range_, context_, | |
| 1965 unresolved_property == CSSPropertyAliasWebkitTransform); | |
| 1966 case CSSPropertyWebkitTransformOriginX: | 1788 case CSSPropertyWebkitTransformOriginX: |
| 1967 case CSSPropertyWebkitPerspectiveOriginX: | 1789 case CSSPropertyWebkitPerspectiveOriginX: |
| 1968 return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueLeft, | 1790 return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueLeft, |
| 1969 CSSValueRight>( | 1791 CSSValueRight>( |
| 1970 range_, context_->Mode()); | 1792 range_, context_->Mode()); |
| 1971 case CSSPropertyWebkitTransformOriginY: | 1793 case CSSPropertyWebkitTransformOriginY: |
| 1972 case CSSPropertyWebkitPerspectiveOriginY: | 1794 case CSSPropertyWebkitPerspectiveOriginY: |
| 1973 return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueTop, | 1795 return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueTop, |
| 1974 CSSValueBottom>( | 1796 CSSValueBottom>( |
| 1975 range_, context_->Mode()); | 1797 range_, context_->Mode()); |
| (...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 case CSSPropertyPlaceItems: | 3458 case CSSPropertyPlaceItems: |
| 3637 return ConsumePlaceItemsShorthand(important); | 3459 return ConsumePlaceItemsShorthand(important); |
| 3638 case CSSPropertyPlaceSelf: | 3460 case CSSPropertyPlaceSelf: |
| 3639 return ConsumePlaceSelfShorthand(important); | 3461 return ConsumePlaceSelfShorthand(important); |
| 3640 default: | 3462 default: |
| 3641 return false; | 3463 return false; |
| 3642 } | 3464 } |
| 3643 } | 3465 } |
| 3644 | 3466 |
| 3645 } // namespace blink | 3467 } // namespace blink |
| OLD | NEW |