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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 CSSIdentifierValue* horizontal = ConsumeBorderImageRepeatKeyword(range); | 833 CSSIdentifierValue* horizontal = ConsumeBorderImageRepeatKeyword(range); |
834 if (!horizontal) | 834 if (!horizontal) |
835 return nullptr; | 835 return nullptr; |
836 CSSIdentifierValue* vertical = ConsumeBorderImageRepeatKeyword(range); | 836 CSSIdentifierValue* vertical = ConsumeBorderImageRepeatKeyword(range); |
837 if (!vertical) | 837 if (!vertical) |
838 vertical = horizontal; | 838 vertical = horizontal; |
839 return CSSValuePair::Create(horizontal, vertical, | 839 return CSSValuePair::Create(horizontal, vertical, |
840 CSSValuePair::kDropIdenticalValues); | 840 CSSValuePair::kDropIdenticalValues); |
841 } | 841 } |
842 | 842 |
843 static CSSValue* ConsumeBorderImageSlice(CSSPropertyID property, | 843 static CSSValue* ConsumeBorderImageSlice(CSSParserTokenRange& range, |
844 CSSParserTokenRange& range) { | 844 bool default_fill) { |
845 bool fill = ConsumeIdent<CSSValueFill>(range); | 845 bool fill = ConsumeIdent<CSSValueFill>(range); |
846 CSSValue* slices[4] = {0}; | 846 CSSValue* slices[4] = {0}; |
847 | 847 |
848 for (size_t index = 0; index < 4; ++index) { | 848 for (size_t index = 0; index < 4; ++index) { |
849 CSSPrimitiveValue* value = ConsumePercent(range, kValueRangeNonNegative); | 849 CSSPrimitiveValue* value = ConsumePercent(range, kValueRangeNonNegative); |
850 if (!value) | 850 if (!value) |
851 value = ConsumeNumber(range, kValueRangeNonNegative); | 851 value = ConsumeNumber(range, kValueRangeNonNegative); |
852 if (!value) | 852 if (!value) |
853 break; | 853 break; |
854 slices[index] = value; | 854 slices[index] = value; |
855 } | 855 } |
856 if (!slices[0]) | 856 if (!slices[0]) |
857 return nullptr; | 857 return nullptr; |
858 if (ConsumeIdent<CSSValueFill>(range)) { | 858 if (ConsumeIdent<CSSValueFill>(range)) { |
859 if (fill) | 859 if (fill) |
860 return nullptr; | 860 return nullptr; |
861 fill = true; | 861 fill = true; |
862 } | 862 } |
863 Complete4Sides(slices); | 863 Complete4Sides(slices); |
864 // FIXME: For backwards compatibility, -webkit-border-image, | 864 if (default_fill) |
865 // -webkit-mask-box-image and -webkit-box-reflect have to do a fill by | |
866 // default. | |
867 // FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-image? | |
868 // Probably just have to leave them filling... | |
869 if (property == CSSPropertyWebkitBorderImage || | |
870 property == CSSPropertyWebkitMaskBoxImage || | |
871 property == CSSPropertyWebkitBoxReflect) | |
872 fill = true; | 865 fill = true; |
873 return CSSBorderImageSliceValue::Create( | 866 return CSSBorderImageSliceValue::Create( |
874 CSSQuadValue::Create(slices[0], slices[1], slices[2], slices[3], | 867 CSSQuadValue::Create(slices[0], slices[1], slices[2], slices[3], |
875 CSSQuadValue::kSerializeAsQuad), | 868 CSSQuadValue::kSerializeAsQuad), |
876 fill); | 869 fill); |
877 } | 870 } |
878 | 871 |
879 static CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange& range) { | 872 static CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange& range) { |
880 CSSValue* outsets[4] = {0}; | 873 CSSValue* outsets[4] = {0}; |
881 | 874 |
(...skipping 29 matching lines...) Expand all Loading... | |
911 break; | 904 break; |
912 widths[index] = value; | 905 widths[index] = value; |
913 } | 906 } |
914 if (!widths[0]) | 907 if (!widths[0]) |
915 return nullptr; | 908 return nullptr; |
916 Complete4Sides(widths); | 909 Complete4Sides(widths); |
917 return CSSQuadValue::Create(widths[0], widths[1], widths[2], widths[3], | 910 return CSSQuadValue::Create(widths[0], widths[1], widths[2], widths[3], |
918 CSSQuadValue::kSerializeAsQuad); | 911 CSSQuadValue::kSerializeAsQuad); |
919 } | 912 } |
920 | 913 |
921 static bool ConsumeBorderImageComponents(CSSPropertyID property, | 914 static bool ConsumeBorderImageComponents(CSSParserTokenRange& range, |
922 CSSParserTokenRange& range, | |
923 const CSSParserContext* context, | 915 const CSSParserContext* context, |
924 CSSValue*& source, | 916 CSSValue*& source, |
925 CSSValue*& slice, | 917 CSSValue*& slice, |
926 CSSValue*& width, | 918 CSSValue*& width, |
927 CSSValue*& outset, | 919 CSSValue*& outset, |
928 CSSValue*& repeat) { | 920 CSSValue*& repeat, |
921 bool default_fill) { | |
929 do { | 922 do { |
930 if (!source) { | 923 if (!source) { |
931 source = ConsumeImageOrNone(range, context); | 924 source = ConsumeImageOrNone(range, context); |
932 if (source) | 925 if (source) |
933 continue; | 926 continue; |
934 } | 927 } |
935 if (!repeat) { | 928 if (!repeat) { |
936 repeat = ConsumeBorderImageRepeat(range); | 929 repeat = ConsumeBorderImageRepeat(range); |
937 if (repeat) | 930 if (repeat) |
938 continue; | 931 continue; |
939 } | 932 } |
940 if (!slice) { | 933 if (!slice) { |
941 slice = ConsumeBorderImageSlice(property, range); | 934 slice = ConsumeBorderImageSlice(range, default_fill); |
942 if (slice) { | 935 if (slice) { |
943 DCHECK(!width); | 936 DCHECK(!width); |
944 DCHECK(!outset); | 937 DCHECK(!outset); |
945 if (ConsumeSlashIncludingWhitespace(range)) { | 938 if (ConsumeSlashIncludingWhitespace(range)) { |
946 width = ConsumeBorderImageWidth(range); | 939 width = ConsumeBorderImageWidth(range); |
947 if (ConsumeSlashIncludingWhitespace(range)) { | 940 if (ConsumeSlashIncludingWhitespace(range)) { |
948 outset = ConsumeBorderImageOutset(range); | 941 outset = ConsumeBorderImageOutset(range); |
949 if (!outset) | 942 if (!outset) |
950 return false; | 943 return false; |
951 } else if (!width) { | 944 } else if (!width) { |
952 return false; | 945 return false; |
953 } | 946 } |
954 } | 947 } |
955 } else { | 948 } else { |
956 return false; | 949 return false; |
957 } | 950 } |
958 } else { | 951 } else { |
959 return false; | 952 return false; |
960 } | 953 } |
961 } while (!range.AtEnd()); | 954 } while (!range.AtEnd()); |
962 return true; | 955 return true; |
963 } | 956 } |
964 | 957 |
965 static CSSValue* ConsumeWebkitBorderImage(CSSPropertyID property, | 958 static CSSValue* ConsumeWebkitBorderImage(CSSParserTokenRange& range, |
966 CSSParserTokenRange& range, | |
967 const CSSParserContext* context) { | 959 const CSSParserContext* context) { |
968 CSSValue* source = nullptr; | 960 CSSValue* source = nullptr; |
969 CSSValue* slice = nullptr; | 961 CSSValue* slice = nullptr; |
970 CSSValue* width = nullptr; | 962 CSSValue* width = nullptr; |
971 CSSValue* outset = nullptr; | 963 CSSValue* outset = nullptr; |
972 CSSValue* repeat = nullptr; | 964 CSSValue* repeat = nullptr; |
973 if (ConsumeBorderImageComponents(property, range, context, source, slice, | 965 if (ConsumeBorderImageComponents(range, context, source, slice, width, outset, |
974 width, outset, repeat)) | 966 repeat, true)) |
suzyh_UTC10 (ex-contributor)
2017/05/05 05:47:12
I'd suggest following this sort of protocol here:
Bugs Nash
2017/05/05 06:23:55
Done
| |
975 return CreateBorderImageValue(source, slice, width, outset, repeat); | 967 return CreateBorderImageValue(source, slice, width, outset, repeat); |
976 return nullptr; | 968 return nullptr; |
977 } | 969 } |
978 | 970 |
979 static CSSValue* ConsumeReflect(CSSParserTokenRange& range, | 971 static CSSValue* ConsumeReflect(CSSParserTokenRange& range, |
980 const CSSParserContext* context) { | 972 const CSSParserContext* context) { |
981 CSSIdentifierValue* direction = | 973 CSSIdentifierValue* direction = |
982 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>( | 974 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>( |
983 range); | 975 range); |
984 if (!direction) | 976 if (!direction) |
985 return nullptr; | 977 return nullptr; |
986 | 978 |
987 CSSPrimitiveValue* offset = nullptr; | 979 CSSPrimitiveValue* offset = nullptr; |
988 if (range.AtEnd()) { | 980 if (range.AtEnd()) { |
989 offset = CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kPixels); | 981 offset = CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kPixels); |
990 } else { | 982 } else { |
991 offset = ConsumeLengthOrPercent(range, context->Mode(), kValueRangeAll, | 983 offset = ConsumeLengthOrPercent(range, context->Mode(), kValueRangeAll, |
992 UnitlessQuirk::kForbid); | 984 UnitlessQuirk::kForbid); |
993 if (!offset) | 985 if (!offset) |
994 return nullptr; | 986 return nullptr; |
995 } | 987 } |
996 | 988 |
997 CSSValue* mask = nullptr; | 989 CSSValue* mask = nullptr; |
998 if (!range.AtEnd()) { | 990 if (!range.AtEnd()) { |
999 mask = | 991 mask = ConsumeWebkitBorderImage(range, context); |
1000 ConsumeWebkitBorderImage(CSSPropertyWebkitBoxReflect, range, context); | |
1001 if (!mask) | 992 if (!mask) |
1002 return nullptr; | 993 return nullptr; |
1003 } | 994 } |
1004 return CSSReflectValue::Create(direction, offset, mask); | 995 return CSSReflectValue::Create(direction, offset, mask); |
1005 } | 996 } |
1006 | 997 |
1007 static CSSValue* ConsumeBackgroundBlendMode(CSSParserTokenRange& range) { | 998 static CSSValue* ConsumeBackgroundBlendMode(CSSParserTokenRange& range) { |
1008 CSSValueID id = range.Peek().Id(); | 999 CSSValueID id = range.Peek().Id(); |
1009 if (id == CSSValueNormal || id == CSSValueOverlay || | 1000 if (id == CSSValueNormal || id == CSSValueOverlay || |
1010 (id >= CSSValueMultiply && id <= CSSValueLuminosity)) | 1001 (id >= CSSValueMultiply && id <= CSSValueLuminosity)) |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 case CSSPropertyPerspective: | 1779 case CSSPropertyPerspective: |
1789 return ConsumePerspective(range_, context_, unresolved_property); | 1780 return ConsumePerspective(range_, context_, unresolved_property); |
1790 case CSSPropertyScrollSnapPointsX: | 1781 case CSSPropertyScrollSnapPointsX: |
1791 case CSSPropertyScrollSnapPointsY: | 1782 case CSSPropertyScrollSnapPointsY: |
1792 return ConsumeScrollSnapPoints(range_, context_->Mode()); | 1783 return ConsumeScrollSnapPoints(range_, context_->Mode()); |
1793 case CSSPropertyBorderImageRepeat: | 1784 case CSSPropertyBorderImageRepeat: |
1794 case CSSPropertyWebkitMaskBoxImageRepeat: | 1785 case CSSPropertyWebkitMaskBoxImageRepeat: |
1795 return ConsumeBorderImageRepeat(range_); | 1786 return ConsumeBorderImageRepeat(range_); |
1796 case CSSPropertyBorderImageSlice: | 1787 case CSSPropertyBorderImageSlice: |
1797 case CSSPropertyWebkitMaskBoxImageSlice: | 1788 case CSSPropertyWebkitMaskBoxImageSlice: |
1798 return ConsumeBorderImageSlice(property, range_); | 1789 return ConsumeBorderImageSlice(range_, false); |
1799 case CSSPropertyBorderImageOutset: | 1790 case CSSPropertyBorderImageOutset: |
1800 case CSSPropertyWebkitMaskBoxImageOutset: | 1791 case CSSPropertyWebkitMaskBoxImageOutset: |
1801 return ConsumeBorderImageOutset(range_); | 1792 return ConsumeBorderImageOutset(range_); |
1802 case CSSPropertyBorderImageWidth: | 1793 case CSSPropertyBorderImageWidth: |
1803 case CSSPropertyWebkitMaskBoxImageWidth: | 1794 case CSSPropertyWebkitMaskBoxImageWidth: |
1804 return ConsumeBorderImageWidth(range_); | 1795 return ConsumeBorderImageWidth(range_); |
1805 case CSSPropertyWebkitBorderImage: | 1796 case CSSPropertyWebkitBorderImage: |
1806 return ConsumeWebkitBorderImage(property, range_, context_); | 1797 return ConsumeWebkitBorderImage(range_, context_); |
1807 case CSSPropertyWebkitBoxReflect: | 1798 case CSSPropertyWebkitBoxReflect: |
1808 return ConsumeReflect(range_, context_); | 1799 return ConsumeReflect(range_, context_); |
1809 case CSSPropertyBackgroundAttachment: | 1800 case CSSPropertyBackgroundAttachment: |
1810 case CSSPropertyBackgroundBlendMode: | 1801 case CSSPropertyBackgroundBlendMode: |
1811 case CSSPropertyBackgroundClip: | 1802 case CSSPropertyBackgroundClip: |
1812 case CSSPropertyBackgroundImage: | 1803 case CSSPropertyBackgroundImage: |
1813 case CSSPropertyBackgroundOrigin: | 1804 case CSSPropertyBackgroundOrigin: |
1814 case CSSPropertyBackgroundPositionX: | 1805 case CSSPropertyBackgroundPositionX: |
1815 case CSSPropertyBackgroundPositionY: | 1806 case CSSPropertyBackgroundPositionY: |
1816 case CSSPropertyBackgroundSize: | 1807 case CSSPropertyBackgroundSize: |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2493 left = right; | 2484 left = right; |
2494 | 2485 |
2495 AddProperty(longhands[0], shorthand.id(), *top, important); | 2486 AddProperty(longhands[0], shorthand.id(), *top, important); |
2496 AddProperty(longhands[1], shorthand.id(), *right, important); | 2487 AddProperty(longhands[1], shorthand.id(), *right, important); |
2497 AddProperty(longhands[2], shorthand.id(), *bottom, important); | 2488 AddProperty(longhands[2], shorthand.id(), *bottom, important); |
2498 AddProperty(longhands[3], shorthand.id(), *left, important); | 2489 AddProperty(longhands[3], shorthand.id(), *left, important); |
2499 | 2490 |
2500 return range_.AtEnd(); | 2491 return range_.AtEnd(); |
2501 } | 2492 } |
2502 | 2493 |
2494 // TODO(bugsnash): refactor out property specific logic from this method | |
suzyh_UTC10 (ex-contributor)
2017/05/05 05:47:12
Consider referring to a particular bug in the TODO
Bugs Nash
2017/05/05 06:23:55
Done
| |
2495 // and remove CSSPropetyID argument | |
2503 bool CSSPropertyParser::ConsumeBorderImage(CSSPropertyID property, | 2496 bool CSSPropertyParser::ConsumeBorderImage(CSSPropertyID property, |
2497 bool default_fill, | |
2504 bool important) { | 2498 bool important) { |
2505 CSSValue* source = nullptr; | 2499 CSSValue* source = nullptr; |
2506 CSSValue* slice = nullptr; | 2500 CSSValue* slice = nullptr; |
2507 CSSValue* width = nullptr; | 2501 CSSValue* width = nullptr; |
2508 CSSValue* outset = nullptr; | 2502 CSSValue* outset = nullptr; |
2509 CSSValue* repeat = nullptr; | 2503 CSSValue* repeat = nullptr; |
2510 if (ConsumeBorderImageComponents(property, range_, context_, source, slice, | 2504 if (ConsumeBorderImageComponents(range_, context_, source, slice, width, |
2511 width, outset, repeat)) { | 2505 outset, repeat, default_fill)) { |
2512 switch (property) { | 2506 switch (property) { |
2513 case CSSPropertyWebkitMaskBoxImage: | 2507 case CSSPropertyWebkitMaskBoxImage: |
2514 AddProperty(CSSPropertyWebkitMaskBoxImageSource, | 2508 AddProperty(CSSPropertyWebkitMaskBoxImageSource, |
2515 CSSPropertyWebkitMaskBoxImage, | 2509 CSSPropertyWebkitMaskBoxImage, |
2516 source ? *source : *CSSInitialValue::Create(), important); | 2510 source ? *source : *CSSInitialValue::Create(), important); |
2517 AddProperty(CSSPropertyWebkitMaskBoxImageSlice, | 2511 AddProperty(CSSPropertyWebkitMaskBoxImageSlice, |
2518 CSSPropertyWebkitMaskBoxImage, | 2512 CSSPropertyWebkitMaskBoxImage, |
2519 slice ? *slice : *CSSInitialValue::Create(), important); | 2513 slice ? *slice : *CSSInitialValue::Create(), important); |
2520 AddProperty(CSSPropertyWebkitMaskBoxImageWidth, | 2514 AddProperty(CSSPropertyWebkitMaskBoxImageWidth, |
2521 CSSPropertyWebkitMaskBoxImage, | 2515 CSSPropertyWebkitMaskBoxImage, |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3340 return ConsumeShorthandGreedily(borderTopShorthand(), important); | 3334 return ConsumeShorthandGreedily(borderTopShorthand(), important); |
3341 case CSSPropertyBorderRight: | 3335 case CSSPropertyBorderRight: |
3342 return ConsumeShorthandGreedily(borderRightShorthand(), important); | 3336 return ConsumeShorthandGreedily(borderRightShorthand(), important); |
3343 case CSSPropertyBorderBottom: | 3337 case CSSPropertyBorderBottom: |
3344 return ConsumeShorthandGreedily(borderBottomShorthand(), important); | 3338 return ConsumeShorthandGreedily(borderBottomShorthand(), important); |
3345 case CSSPropertyBorderLeft: | 3339 case CSSPropertyBorderLeft: |
3346 return ConsumeShorthandGreedily(borderLeftShorthand(), important); | 3340 return ConsumeShorthandGreedily(borderLeftShorthand(), important); |
3347 case CSSPropertyBorder: | 3341 case CSSPropertyBorder: |
3348 return ConsumeBorder(important); | 3342 return ConsumeBorder(important); |
3349 case CSSPropertyBorderImage: | 3343 case CSSPropertyBorderImage: |
3344 return ConsumeBorderImage(property, important, false); | |
3350 case CSSPropertyWebkitMaskBoxImage: | 3345 case CSSPropertyWebkitMaskBoxImage: |
3351 return ConsumeBorderImage(property, important); | 3346 return ConsumeBorderImage(property, important, true); |
3352 case CSSPropertyPageBreakAfter: | 3347 case CSSPropertyPageBreakAfter: |
3353 case CSSPropertyPageBreakBefore: | 3348 case CSSPropertyPageBreakBefore: |
3354 case CSSPropertyPageBreakInside: | 3349 case CSSPropertyPageBreakInside: |
3355 case CSSPropertyWebkitColumnBreakAfter: | 3350 case CSSPropertyWebkitColumnBreakAfter: |
3356 case CSSPropertyWebkitColumnBreakBefore: | 3351 case CSSPropertyWebkitColumnBreakBefore: |
3357 case CSSPropertyWebkitColumnBreakInside: | 3352 case CSSPropertyWebkitColumnBreakInside: |
3358 return ConsumeLegacyBreakProperty(property, important); | 3353 return ConsumeLegacyBreakProperty(property, important); |
3359 case CSSPropertyWebkitMaskPosition: | 3354 case CSSPropertyWebkitMaskPosition: |
3360 case CSSPropertyBackgroundPosition: { | 3355 case CSSPropertyBackgroundPosition: { |
3361 CSSValue* result_x = nullptr; | 3356 CSSValue* result_x = nullptr; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3427 case CSSPropertyPlaceItems: | 3422 case CSSPropertyPlaceItems: |
3428 return ConsumePlaceItemsShorthand(important); | 3423 return ConsumePlaceItemsShorthand(important); |
3429 case CSSPropertyPlaceSelf: | 3424 case CSSPropertyPlaceSelf: |
3430 return ConsumePlaceSelfShorthand(important); | 3425 return ConsumePlaceSelfShorthand(important); |
3431 default: | 3426 default: |
3432 return false; | 3427 return false; |
3433 } | 3428 } |
3434 } | 3429 } |
3435 | 3430 |
3436 } // namespace blink | 3431 } // namespace blink |
OLD | NEW |