OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/properties/CSSPropertyBackgroundComponentUtils.h" |
| 6 |
| 7 #include "core/css/CSSValueList.h" |
| 8 #include "core/css/CSSValuePair.h" |
| 9 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 10 #include "core/css/properties/CSSPropertyPositionUtils.h" |
| 11 #include "platform/RuntimeEnabledFeatures.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 namespace { |
| 16 |
| 17 static CSSValue* consumeBackgroundBlendMode(CSSParserTokenRange& range) { |
| 18 CSSValueID id = range.peek().id(); |
| 19 if (id == CSSValueNormal || id == CSSValueOverlay || |
| 20 (id >= CSSValueMultiply && id <= CSSValueLuminosity)) |
| 21 return CSSPropertyParserHelpers::consumeIdent(range); |
| 22 return nullptr; |
| 23 } |
| 24 |
| 25 CSSValue* consumeBackgroundAttachment(CSSParserTokenRange& range) { |
| 26 return CSSPropertyParserHelpers::consumeIdent<CSSValueScroll, CSSValueFixed, |
| 27 CSSValueLocal>(range); |
| 28 } |
| 29 |
| 30 CSSValue* consumeBackgroundBox(CSSParserTokenRange& range) { |
| 31 return CSSPropertyParserHelpers::consumeIdent< |
| 32 CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBox>(range); |
| 33 } |
| 34 |
| 35 CSSValue* consumeBackgroundComposite(CSSParserTokenRange& range) { |
| 36 return CSSPropertyParserHelpers::consumeIdentRange(range, CSSValueClear, |
| 37 CSSValuePlusLighter); |
| 38 } |
| 39 |
| 40 CSSValue* consumeMaskSourceType(CSSParserTokenRange& range) { |
| 41 DCHECK(RuntimeEnabledFeatures::cssMaskSourceTypeEnabled()); |
| 42 return CSSPropertyParserHelpers::consumeIdent<CSSValueAuto, CSSValueAlpha, |
| 43 CSSValueLuminance>(range); |
| 44 } |
| 45 |
| 46 CSSValue* consumePrefixedBackgroundBox(CSSPropertyID property, |
| 47 CSSParserTokenRange& range, |
| 48 const CSSParserContext* context) { |
| 49 // The values 'border', 'padding' and 'content' are deprecated and do not |
| 50 // apply to the version of the property that has the -webkit- prefix removed. |
| 51 if (CSSValue* value = CSSPropertyParserHelpers::consumeIdentRange( |
| 52 range, CSSValueBorder, CSSValuePaddingBox)) |
| 53 return value; |
| 54 if ((property == CSSPropertyWebkitBackgroundClip || |
| 55 property == CSSPropertyWebkitMaskClip) && |
| 56 range.peek().id() == CSSValueText) |
| 57 return CSSPropertyParserHelpers::consumeIdent(range); |
| 58 return nullptr; |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 |
| 63 CSSValue* CSSPropertyBackgroundComponentUtils::consumeBackgroundSize( |
| 64 CSSPropertyID unresolvedProperty, |
| 65 CSSParserTokenRange& range, |
| 66 CSSParserMode cssParserMode) { |
| 67 if (CSSPropertyParserHelpers::identMatches<CSSValueContain, CSSValueCover>( |
| 68 range.peek().id())) |
| 69 return CSSPropertyParserHelpers::consumeIdent(range); |
| 70 |
| 71 CSSValue* horizontal = |
| 72 CSSPropertyParserHelpers::consumeIdent<CSSValueAuto>(range); |
| 73 if (!horizontal) { |
| 74 horizontal = CSSPropertyParserHelpers::consumeLengthOrPercent( |
| 75 range, cssParserMode, ValueRangeAll, |
| 76 CSSPropertyParserHelpers::UnitlessQuirk::Forbid); |
| 77 } |
| 78 |
| 79 CSSValue* vertical = nullptr; |
| 80 if (!range.atEnd()) { |
| 81 if (range.peek().id() == CSSValueAuto) { |
| 82 // `auto' is the default |
| 83 range.consumeIncludingWhitespace(); |
| 84 } else { |
| 85 vertical = CSSPropertyParserHelpers::consumeLengthOrPercent( |
| 86 range, cssParserMode, ValueRangeAll, |
| 87 CSSPropertyParserHelpers::UnitlessQuirk::Forbid); |
| 88 } |
| 89 } else if (unresolvedProperty == CSSPropertyAliasWebkitBackgroundSize) { |
| 90 // Legacy syntax: "-webkit-background-size: 10px" is equivalent to |
| 91 // "background-size: 10px 10px". |
| 92 vertical = horizontal; |
| 93 } |
| 94 if (!vertical) |
| 95 return horizontal; |
| 96 return CSSValuePair::create(horizontal, vertical, |
| 97 CSSValuePair::KeepIdenticalValues); |
| 98 } |
| 99 |
| 100 void CSSPropertyBackgroundComponentUtils::addBackgroundValue(CSSValue*& list, |
| 101 CSSValue* value) { |
| 102 if (list) { |
| 103 if (!list->isBaseValueList()) { |
| 104 CSSValue* firstValue = list; |
| 105 list = CSSValueList::createCommaSeparated(); |
| 106 toCSSValueList(list)->append(*firstValue); |
| 107 } |
| 108 toCSSValueList(list)->append(*value); |
| 109 } else { |
| 110 // To conserve memory we don't actually wrap a single value in a list. |
| 111 list = value; |
| 112 } |
| 113 } |
| 114 |
| 115 CSSValue* CSSPropertyBackgroundComponentUtils::consumeBackgroundComponent( |
| 116 CSSPropertyID unresolvedProperty, |
| 117 CSSParserTokenRange& range, |
| 118 const CSSParserContext* context) { |
| 119 switch (unresolvedProperty) { |
| 120 case CSSPropertyBackgroundClip: |
| 121 return consumeBackgroundBox(range); |
| 122 case CSSPropertyBackgroundBlendMode: |
| 123 return consumeBackgroundBlendMode(range); |
| 124 case CSSPropertyBackgroundAttachment: |
| 125 return consumeBackgroundAttachment(range); |
| 126 case CSSPropertyBackgroundOrigin: |
| 127 return consumeBackgroundBox(range); |
| 128 case CSSPropertyWebkitMaskComposite: |
| 129 return consumeBackgroundComposite(range); |
| 130 case CSSPropertyMaskSourceType: |
| 131 return consumeMaskSourceType(range); |
| 132 case CSSPropertyWebkitBackgroundClip: |
| 133 case CSSPropertyWebkitBackgroundOrigin: |
| 134 case CSSPropertyWebkitMaskClip: |
| 135 case CSSPropertyWebkitMaskOrigin: |
| 136 return consumePrefixedBackgroundBox(unresolvedProperty, range, context); |
| 137 case CSSPropertyBackgroundImage: |
| 138 case CSSPropertyWebkitMaskImage: |
| 139 return CSSPropertyParserHelpers::consumeImageOrNone(range, context); |
| 140 case CSSPropertyBackgroundPositionX: |
| 141 case CSSPropertyWebkitMaskPositionX: |
| 142 return CSSPropertyPositionUtils::consumePositionLonghand<CSSValueLeft, |
| 143 CSSValueRight>( |
| 144 range, context->mode()); |
| 145 case CSSPropertyBackgroundPositionY: |
| 146 case CSSPropertyWebkitMaskPositionY: |
| 147 return CSSPropertyPositionUtils::consumePositionLonghand<CSSValueTop, |
| 148 CSSValueBottom>( |
| 149 range, context->mode()); |
| 150 case CSSPropertyBackgroundSize: |
| 151 case CSSPropertyAliasWebkitBackgroundSize: |
| 152 case CSSPropertyWebkitMaskSize: |
| 153 return consumeBackgroundSize(unresolvedProperty, range, context->mode()); |
| 154 case CSSPropertyBackgroundColor: |
| 155 return CSSPropertyParserHelpers::consumeColor(range, context->mode()); |
| 156 default: |
| 157 break; |
| 158 }; |
| 159 return nullptr; |
| 160 } |
| 161 |
| 162 } // namespace blink |
OLD | NEW |