Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 2860283003: Refactored out property specific logic in ConsumeBorderImageSlice. (Closed)
Patch Set: fixed bug - argument order Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 CSSIdentifierValue* horizontal = ConsumeBorderImageRepeatKeyword(range); 808 CSSIdentifierValue* horizontal = ConsumeBorderImageRepeatKeyword(range);
809 if (!horizontal) 809 if (!horizontal)
810 return nullptr; 810 return nullptr;
811 CSSIdentifierValue* vertical = ConsumeBorderImageRepeatKeyword(range); 811 CSSIdentifierValue* vertical = ConsumeBorderImageRepeatKeyword(range);
812 if (!vertical) 812 if (!vertical)
813 vertical = horizontal; 813 vertical = horizontal;
814 return CSSValuePair::Create(horizontal, vertical, 814 return CSSValuePair::Create(horizontal, vertical,
815 CSSValuePair::kDropIdenticalValues); 815 CSSValuePair::kDropIdenticalValues);
816 } 816 }
817 817
818 static CSSValue* ConsumeBorderImageSlice(CSSPropertyID property, 818 static CSSValue* ConsumeBorderImageSlice(CSSParserTokenRange& range,
819 CSSParserTokenRange& range) { 819 bool default_fill) {
820 bool fill = ConsumeIdent<CSSValueFill>(range); 820 bool fill = ConsumeIdent<CSSValueFill>(range);
821 CSSValue* slices[4] = {0}; 821 CSSValue* slices[4] = {0};
822 822
823 for (size_t index = 0; index < 4; ++index) { 823 for (size_t index = 0; index < 4; ++index) {
824 CSSPrimitiveValue* value = ConsumePercent(range, kValueRangeNonNegative); 824 CSSPrimitiveValue* value = ConsumePercent(range, kValueRangeNonNegative);
825 if (!value) 825 if (!value)
826 value = ConsumeNumber(range, kValueRangeNonNegative); 826 value = ConsumeNumber(range, kValueRangeNonNegative);
827 if (!value) 827 if (!value)
828 break; 828 break;
829 slices[index] = value; 829 slices[index] = value;
830 } 830 }
831 if (!slices[0]) 831 if (!slices[0])
832 return nullptr; 832 return nullptr;
833 if (ConsumeIdent<CSSValueFill>(range)) { 833 if (ConsumeIdent<CSSValueFill>(range)) {
834 if (fill) 834 if (fill)
835 return nullptr; 835 return nullptr;
836 fill = true; 836 fill = true;
837 } 837 }
838 Complete4Sides(slices); 838 Complete4Sides(slices);
839 // FIXME: For backwards compatibility, -webkit-border-image, 839 if (default_fill)
840 // -webkit-mask-box-image and -webkit-box-reflect have to do a fill by
841 // default.
842 // FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-image?
843 // Probably just have to leave them filling...
844 if (property == CSSPropertyWebkitBorderImage ||
845 property == CSSPropertyWebkitMaskBoxImage ||
846 property == CSSPropertyWebkitBoxReflect)
847 fill = true; 840 fill = true;
848 return CSSBorderImageSliceValue::Create( 841 return CSSBorderImageSliceValue::Create(
849 CSSQuadValue::Create(slices[0], slices[1], slices[2], slices[3], 842 CSSQuadValue::Create(slices[0], slices[1], slices[2], slices[3],
850 CSSQuadValue::kSerializeAsQuad), 843 CSSQuadValue::kSerializeAsQuad),
851 fill); 844 fill);
852 } 845 }
853 846
854 static CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange& range) { 847 static CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange& range) {
855 CSSValue* outsets[4] = {0}; 848 CSSValue* outsets[4] = {0};
856 849
(...skipping 29 matching lines...) Expand all
886 break; 879 break;
887 widths[index] = value; 880 widths[index] = value;
888 } 881 }
889 if (!widths[0]) 882 if (!widths[0])
890 return nullptr; 883 return nullptr;
891 Complete4Sides(widths); 884 Complete4Sides(widths);
892 return CSSQuadValue::Create(widths[0], widths[1], widths[2], widths[3], 885 return CSSQuadValue::Create(widths[0], widths[1], widths[2], widths[3],
893 CSSQuadValue::kSerializeAsQuad); 886 CSSQuadValue::kSerializeAsQuad);
894 } 887 }
895 888
896 static bool ConsumeBorderImageComponents(CSSPropertyID property, 889 static bool ConsumeBorderImageComponents(CSSParserTokenRange& range,
897 CSSParserTokenRange& range,
898 const CSSParserContext* context, 890 const CSSParserContext* context,
899 CSSValue*& source, 891 CSSValue*& source,
900 CSSValue*& slice, 892 CSSValue*& slice,
901 CSSValue*& width, 893 CSSValue*& width,
902 CSSValue*& outset, 894 CSSValue*& outset,
903 CSSValue*& repeat) { 895 CSSValue*& repeat,
896 bool default_fill) {
904 do { 897 do {
905 if (!source) { 898 if (!source) {
906 source = ConsumeImageOrNone(range, context); 899 source = ConsumeImageOrNone(range, context);
907 if (source) 900 if (source)
908 continue; 901 continue;
909 } 902 }
910 if (!repeat) { 903 if (!repeat) {
911 repeat = ConsumeBorderImageRepeat(range); 904 repeat = ConsumeBorderImageRepeat(range);
912 if (repeat) 905 if (repeat)
913 continue; 906 continue;
914 } 907 }
915 if (!slice) { 908 if (!slice) {
916 slice = ConsumeBorderImageSlice(property, range); 909 slice = ConsumeBorderImageSlice(range, default_fill);
917 if (slice) { 910 if (slice) {
918 DCHECK(!width); 911 DCHECK(!width);
919 DCHECK(!outset); 912 DCHECK(!outset);
920 if (ConsumeSlashIncludingWhitespace(range)) { 913 if (ConsumeSlashIncludingWhitespace(range)) {
921 width = ConsumeBorderImageWidth(range); 914 width = ConsumeBorderImageWidth(range);
922 if (ConsumeSlashIncludingWhitespace(range)) { 915 if (ConsumeSlashIncludingWhitespace(range)) {
923 outset = ConsumeBorderImageOutset(range); 916 outset = ConsumeBorderImageOutset(range);
924 if (!outset) 917 if (!outset)
925 return false; 918 return false;
926 } else if (!width) { 919 } else if (!width) {
927 return false; 920 return false;
928 } 921 }
929 } 922 }
930 } else { 923 } else {
931 return false; 924 return false;
932 } 925 }
933 } else { 926 } else {
934 return false; 927 return false;
935 } 928 }
936 } while (!range.AtEnd()); 929 } while (!range.AtEnd());
937 return true; 930 return true;
938 } 931 }
939 932
940 static CSSValue* ConsumeWebkitBorderImage(CSSPropertyID property, 933 static CSSValue* ConsumeWebkitBorderImage(CSSParserTokenRange& range,
941 CSSParserTokenRange& range,
942 const CSSParserContext* context) { 934 const CSSParserContext* context) {
943 CSSValue* source = nullptr; 935 CSSValue* source = nullptr;
944 CSSValue* slice = nullptr; 936 CSSValue* slice = nullptr;
945 CSSValue* width = nullptr; 937 CSSValue* width = nullptr;
946 CSSValue* outset = nullptr; 938 CSSValue* outset = nullptr;
947 CSSValue* repeat = nullptr; 939 CSSValue* repeat = nullptr;
948 if (ConsumeBorderImageComponents(property, range, context, source, slice, 940 if (ConsumeBorderImageComponents(range, context, source, slice, width, outset,
949 width, outset, repeat)) 941 repeat, true /* default_fill */))
950 return CreateBorderImageValue(source, slice, width, outset, repeat); 942 return CreateBorderImageValue(source, slice, width, outset, repeat);
951 return nullptr; 943 return nullptr;
952 } 944 }
953 945
954 static CSSValue* ConsumeReflect(CSSParserTokenRange& range, 946 static CSSValue* ConsumeReflect(CSSParserTokenRange& range,
955 const CSSParserContext* context) { 947 const CSSParserContext* context) {
956 CSSIdentifierValue* direction = 948 CSSIdentifierValue* direction =
957 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>( 949 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(
958 range); 950 range);
959 if (!direction) 951 if (!direction)
960 return nullptr; 952 return nullptr;
961 953
962 CSSPrimitiveValue* offset = nullptr; 954 CSSPrimitiveValue* offset = nullptr;
963 if (range.AtEnd()) { 955 if (range.AtEnd()) {
964 offset = CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kPixels); 956 offset = CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kPixels);
965 } else { 957 } else {
966 offset = ConsumeLengthOrPercent(range, context->Mode(), kValueRangeAll, 958 offset = ConsumeLengthOrPercent(range, context->Mode(), kValueRangeAll,
967 UnitlessQuirk::kForbid); 959 UnitlessQuirk::kForbid);
968 if (!offset) 960 if (!offset)
969 return nullptr; 961 return nullptr;
970 } 962 }
971 963
972 CSSValue* mask = nullptr; 964 CSSValue* mask = nullptr;
973 if (!range.AtEnd()) { 965 if (!range.AtEnd()) {
974 mask = 966 mask = ConsumeWebkitBorderImage(range, context);
975 ConsumeWebkitBorderImage(CSSPropertyWebkitBoxReflect, range, context);
976 if (!mask) 967 if (!mask)
977 return nullptr; 968 return nullptr;
978 } 969 }
979 return CSSReflectValue::Create(direction, offset, mask); 970 return CSSReflectValue::Create(direction, offset, mask);
980 } 971 }
981 972
982 static CSSValue* ConsumeBackgroundBlendMode(CSSParserTokenRange& range) { 973 static CSSValue* ConsumeBackgroundBlendMode(CSSParserTokenRange& range) {
983 CSSValueID id = range.Peek().Id(); 974 CSSValueID id = range.Peek().Id();
984 if (id == CSSValueNormal || id == CSSValueOverlay || 975 if (id == CSSValueNormal || id == CSSValueOverlay ||
985 (id >= CSSValueMultiply && id <= CSSValueLuminosity)) 976 (id >= CSSValueMultiply && id <= CSSValueLuminosity))
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 case CSSPropertyPerspective: 1770 case CSSPropertyPerspective:
1780 return ConsumePerspective(range_, context_, unresolved_property); 1771 return ConsumePerspective(range_, context_, unresolved_property);
1781 case CSSPropertyScrollSnapPointsX: 1772 case CSSPropertyScrollSnapPointsX:
1782 case CSSPropertyScrollSnapPointsY: 1773 case CSSPropertyScrollSnapPointsY:
1783 return ConsumeScrollSnapPoints(range_, context_->Mode()); 1774 return ConsumeScrollSnapPoints(range_, context_->Mode());
1784 case CSSPropertyBorderImageRepeat: 1775 case CSSPropertyBorderImageRepeat:
1785 case CSSPropertyWebkitMaskBoxImageRepeat: 1776 case CSSPropertyWebkitMaskBoxImageRepeat:
1786 return ConsumeBorderImageRepeat(range_); 1777 return ConsumeBorderImageRepeat(range_);
1787 case CSSPropertyBorderImageSlice: 1778 case CSSPropertyBorderImageSlice:
1788 case CSSPropertyWebkitMaskBoxImageSlice: 1779 case CSSPropertyWebkitMaskBoxImageSlice:
1789 return ConsumeBorderImageSlice(property, range_); 1780 return ConsumeBorderImageSlice(range_, false /* default_fill */);
1790 case CSSPropertyBorderImageOutset: 1781 case CSSPropertyBorderImageOutset:
1791 case CSSPropertyWebkitMaskBoxImageOutset: 1782 case CSSPropertyWebkitMaskBoxImageOutset:
1792 return ConsumeBorderImageOutset(range_); 1783 return ConsumeBorderImageOutset(range_);
1793 case CSSPropertyBorderImageWidth: 1784 case CSSPropertyBorderImageWidth:
1794 case CSSPropertyWebkitMaskBoxImageWidth: 1785 case CSSPropertyWebkitMaskBoxImageWidth:
1795 return ConsumeBorderImageWidth(range_); 1786 return ConsumeBorderImageWidth(range_);
1796 case CSSPropertyWebkitBorderImage: 1787 case CSSPropertyWebkitBorderImage:
1797 return ConsumeWebkitBorderImage(property, range_, context_); 1788 return ConsumeWebkitBorderImage(range_, context_);
1798 case CSSPropertyWebkitBoxReflect: 1789 case CSSPropertyWebkitBoxReflect:
1799 return ConsumeReflect(range_, context_); 1790 return ConsumeReflect(range_, context_);
1800 case CSSPropertyBackgroundAttachment: 1791 case CSSPropertyBackgroundAttachment:
1801 case CSSPropertyBackgroundBlendMode: 1792 case CSSPropertyBackgroundBlendMode:
1802 case CSSPropertyBackgroundClip: 1793 case CSSPropertyBackgroundClip:
1803 case CSSPropertyBackgroundImage: 1794 case CSSPropertyBackgroundImage:
1804 case CSSPropertyBackgroundOrigin: 1795 case CSSPropertyBackgroundOrigin:
1805 case CSSPropertyBackgroundPositionX: 1796 case CSSPropertyBackgroundPositionX:
1806 case CSSPropertyBackgroundPositionY: 1797 case CSSPropertyBackgroundPositionY:
1807 case CSSPropertyBackgroundSize: 1798 case CSSPropertyBackgroundSize:
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 left = right; 2475 left = right;
2485 2476
2486 AddProperty(longhands[0], shorthand.id(), *top, important); 2477 AddProperty(longhands[0], shorthand.id(), *top, important);
2487 AddProperty(longhands[1], shorthand.id(), *right, important); 2478 AddProperty(longhands[1], shorthand.id(), *right, important);
2488 AddProperty(longhands[2], shorthand.id(), *bottom, important); 2479 AddProperty(longhands[2], shorthand.id(), *bottom, important);
2489 AddProperty(longhands[3], shorthand.id(), *left, important); 2480 AddProperty(longhands[3], shorthand.id(), *left, important);
2490 2481
2491 return range_.AtEnd(); 2482 return range_.AtEnd();
2492 } 2483 }
2493 2484
2485 // TODO(crbug.com/668012): refactor out property specific logic from this method
2486 // and remove CSSPropetyID argument
2494 bool CSSPropertyParser::ConsumeBorderImage(CSSPropertyID property, 2487 bool CSSPropertyParser::ConsumeBorderImage(CSSPropertyID property,
2488 bool default_fill,
2495 bool important) { 2489 bool important) {
2496 CSSValue* source = nullptr; 2490 CSSValue* source = nullptr;
2497 CSSValue* slice = nullptr; 2491 CSSValue* slice = nullptr;
2498 CSSValue* width = nullptr; 2492 CSSValue* width = nullptr;
2499 CSSValue* outset = nullptr; 2493 CSSValue* outset = nullptr;
2500 CSSValue* repeat = nullptr; 2494 CSSValue* repeat = nullptr;
2501 if (ConsumeBorderImageComponents(property, range_, context_, source, slice, 2495 if (ConsumeBorderImageComponents(range_, context_, source, slice, width,
2502 width, outset, repeat)) { 2496 outset, repeat, default_fill)) {
2503 switch (property) { 2497 switch (property) {
2504 case CSSPropertyWebkitMaskBoxImage: 2498 case CSSPropertyWebkitMaskBoxImage:
2505 AddProperty(CSSPropertyWebkitMaskBoxImageSource, 2499 AddProperty(CSSPropertyWebkitMaskBoxImageSource,
2506 CSSPropertyWebkitMaskBoxImage, 2500 CSSPropertyWebkitMaskBoxImage,
2507 source ? *source : *CSSInitialValue::Create(), important); 2501 source ? *source : *CSSInitialValue::Create(), important);
2508 AddProperty(CSSPropertyWebkitMaskBoxImageSlice, 2502 AddProperty(CSSPropertyWebkitMaskBoxImageSlice,
2509 CSSPropertyWebkitMaskBoxImage, 2503 CSSPropertyWebkitMaskBoxImage,
2510 slice ? *slice : *CSSInitialValue::Create(), important); 2504 slice ? *slice : *CSSInitialValue::Create(), important);
2511 AddProperty(CSSPropertyWebkitMaskBoxImageWidth, 2505 AddProperty(CSSPropertyWebkitMaskBoxImageWidth,
2512 CSSPropertyWebkitMaskBoxImage, 2506 CSSPropertyWebkitMaskBoxImage,
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 return ConsumeShorthandGreedily(borderTopShorthand(), important); 3325 return ConsumeShorthandGreedily(borderTopShorthand(), important);
3332 case CSSPropertyBorderRight: 3326 case CSSPropertyBorderRight:
3333 return ConsumeShorthandGreedily(borderRightShorthand(), important); 3327 return ConsumeShorthandGreedily(borderRightShorthand(), important);
3334 case CSSPropertyBorderBottom: 3328 case CSSPropertyBorderBottom:
3335 return ConsumeShorthandGreedily(borderBottomShorthand(), important); 3329 return ConsumeShorthandGreedily(borderBottomShorthand(), important);
3336 case CSSPropertyBorderLeft: 3330 case CSSPropertyBorderLeft:
3337 return ConsumeShorthandGreedily(borderLeftShorthand(), important); 3331 return ConsumeShorthandGreedily(borderLeftShorthand(), important);
3338 case CSSPropertyBorder: 3332 case CSSPropertyBorder:
3339 return ConsumeBorder(important); 3333 return ConsumeBorder(important);
3340 case CSSPropertyBorderImage: 3334 case CSSPropertyBorderImage:
3335 return ConsumeBorderImage(property, false /* default_fill */, important);
3341 case CSSPropertyWebkitMaskBoxImage: 3336 case CSSPropertyWebkitMaskBoxImage:
3342 return ConsumeBorderImage(property, important); 3337 return ConsumeBorderImage(property, true /* default_fill */, important);
3343 case CSSPropertyPageBreakAfter: 3338 case CSSPropertyPageBreakAfter:
3344 case CSSPropertyPageBreakBefore: 3339 case CSSPropertyPageBreakBefore:
3345 case CSSPropertyPageBreakInside: 3340 case CSSPropertyPageBreakInside:
3346 case CSSPropertyWebkitColumnBreakAfter: 3341 case CSSPropertyWebkitColumnBreakAfter:
3347 case CSSPropertyWebkitColumnBreakBefore: 3342 case CSSPropertyWebkitColumnBreakBefore:
3348 case CSSPropertyWebkitColumnBreakInside: 3343 case CSSPropertyWebkitColumnBreakInside:
3349 return ConsumeLegacyBreakProperty(property, important); 3344 return ConsumeLegacyBreakProperty(property, important);
3350 case CSSPropertyWebkitMaskPosition: 3345 case CSSPropertyWebkitMaskPosition:
3351 case CSSPropertyBackgroundPosition: { 3346 case CSSPropertyBackgroundPosition: {
3352 CSSValue* result_x = nullptr; 3347 CSSValue* result_x = nullptr;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3418 case CSSPropertyPlaceItems: 3413 case CSSPropertyPlaceItems:
3419 return ConsumePlaceItemsShorthand(important); 3414 return ConsumePlaceItemsShorthand(important);
3420 case CSSPropertyPlaceSelf: 3415 case CSSPropertyPlaceSelf:
3421 return ConsumePlaceSelfShorthand(important); 3416 return ConsumePlaceSelfShorthand(important);
3422 default: 3417 default:
3423 return false; 3418 return false;
3424 } 3419 }
3425 } 3420 }
3426 3421
3427 } // namespace blink 3422 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698