Changeset 285837 in webkit
- Timestamp:
- Nov 15, 2021 2:41:10 PM (8 months ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
css/parser/CSSPropertyParser.cpp (modified) (10 diffs)
-
css/parser/CSSPropertyParser.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r285827 r285837 1 2021-11-15 Kiet Ho <tho22@apple.com> 2 3 Add helper to add CSS property with implicit default 4 https://bugs.webkit.org/show_bug.cgi?id=233108 5 6 Reviewed by Myles C. Maxfield. 7 8 Add a helper in CSSPropertyParser to add a property with implicit default. This helper 9 accepts a RefPtr<> value and a Ref<> default. If the value is a null pointer, the 10 default is added, and the implicit flag is set. Otherwise, the value is added. This is 11 useful for parsing shorthands, because the CSS spec requires that missing value be 12 set to its default value, and WebCore additionally requires the implicit flag to be set. 13 This helper handles both of them. 14 15 No functional changes; no tests needed. 16 17 * css/parser/CSSPropertyParser.cpp: 18 (WebCore::CSSPropertyParser::addPropertyWithImplicitDefault): 19 (WebCore::CSSPropertyParser::consumeTransformOrigin): 20 (WebCore::CSSPropertyParser::consumeFont): 21 (WebCore::CSSPropertyParser::consumeFontVariantShorthand): 22 (WebCore::CSSPropertyParser::consumeColumns): 23 (WebCore::CSSPropertyParser::consumeShorthandGreedily): 24 (WebCore::CSSPropertyParser::consumeBorderImage): 25 * css/parser/CSSPropertyParser.h: 26 1 27 2021-11-15 Antti Koivisto <antti@apple.com> 2 28 -
trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp
r285822 r285837 225 225 } 226 226 227 void CSSPropertyParser::addPropertyWithImplicitDefault(CSSPropertyID property, CSSPropertyID currentShorthand, RefPtr<CSSValue>&& value, Ref<CSSValue>&& implicitDefault, bool important) 228 { 229 if (value) 230 addProperty(property, currentShorthand, value.releaseNonNull(), important, false); 231 else 232 addProperty(property, currentShorthand, WTFMove(implicitDefault), important, true); 233 } 234 227 235 void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID property, Ref<CSSValue>&& value, bool important) 228 236 { … … 356 364 bool atEnd = m_range.atEnd(); 357 365 auto resultZ = consumeLength(m_range, m_context.mode, ValueRange::All); 358 bool hasZ = resultZ; 359 if ((!hasZ && !atEnd) || !m_range.atEnd()) 366 if ((!resultZ && !atEnd) || !m_range.atEnd()) 360 367 return false; 361 368 addProperty(CSSPropertyTransformOriginX, CSSPropertyTransformOrigin, WTFMove(resultXY->x), important); 362 369 addProperty(CSSPropertyTransformOriginY, CSSPropertyTransformOrigin, WTFMove(resultXY->y), important); 363 addProperty (CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ ? resultZ.releaseNonNull() : CSSValuePool::singleton().createValue(0, CSSUnitType::CSS_PX), important, !hasZ);370 addPropertyWithImplicitDefault(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ, CSSValuePool::singleton().createValue(0, CSSUnitType::CSS_PX), important); 364 371 365 372 return true; … … 5022 5029 return false; 5023 5030 } 5031 5024 5032 // Optional font-style, font-variant, font-stretch and font-weight. 5025 5033 RefPtr<CSSFontStyleValue> fontStyle; … … 5058 5066 return false; 5059 5067 5060 bool hasStyle = fontStyle; 5061 bool hasVariant = fontVariantCaps; 5062 bool hasWeight = fontWeight; 5063 bool hasStretch = fontStretch; 5064 5065 if (!fontStyle) 5066 fontStyle = CSSFontStyleValue::create(CSSValuePool::singleton().createIdentifierValue(CSSValueNormal)); 5067 5068 addProperty(CSSPropertyFontStyle, CSSPropertyFont, fontStyle.releaseNonNull(), important, !hasStyle); 5069 addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, fontVariantCaps ? fontVariantCaps.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasVariant); 5068 auto& valuePool = CSSValuePool::singleton(); 5069 5070 addPropertyWithImplicitDefault(CSSPropertyFontStyle, CSSPropertyFont, fontStyle, CSSFontStyleValue::create(valuePool.createIdentifierValue(CSSValueNormal)), important); 5071 addPropertyWithImplicitDefault(CSSPropertyFontVariantCaps, CSSPropertyFont, fontVariantCaps, valuePool.createIdentifierValue(CSSValueNormal), important); 5070 5072 /* 5071 5073 // FIXME-NEWPARSER: What do we do with these? They aren't part of our fontShorthand(). … … 5074 5076 */ 5075 5077 5076 addProperty (CSSPropertyFontWeight, CSSPropertyFont, fontWeight ? fontWeight.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasWeight);5077 addProperty (CSSPropertyFontStretch, CSSPropertyFont, fontStretch ? fontStretch.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasStretch);5078 addPropertyWithImplicitDefault(CSSPropertyFontWeight, CSSPropertyFont, fontWeight, valuePool.createIdentifierValue(CSSValueNormal), important); 5079 addPropertyWithImplicitDefault(CSSPropertyFontStretch, CSSPropertyFont, fontStretch, valuePool.createIdentifierValue(CSSValueNormal), important); 5078 5080 5079 5081 // Now a font size _must_ come. … … 5082 5084 return false; 5083 5085 5084 addProperty(CSSPropertyFontSize, CSSPropertyFont, *fontSize, important); 5085 5086 addProperty(CSSPropertyFontSize, CSSPropertyFont, fontSize.releaseNonNull(), important); 5087 5088 RefPtr<CSSPrimitiveValue> lineHeight; 5086 5089 if (consumeSlashIncludingWhitespace(m_range)) { 5087 RefPtr<CSSPrimitiveValue>lineHeight = consumeLineHeight(m_range, m_context.mode);5090 lineHeight = consumeLineHeight(m_range, m_context.mode); 5088 5091 if (!lineHeight) 5089 5092 return false; 5090 addProperty(CSSPropertyLineHeight, CSSPropertyFont, lineHeight.releaseNonNull(), important); 5091 } else 5092 addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true); 5093 } 5094 addPropertyWithImplicitDefault(CSSPropertyLineHeight, CSSPropertyFont, lineHeight, valuePool.createIdentifierValue(CSSValueNormal), important); 5093 5095 5094 5096 // Font family must come now. … … 5168 5170 addProperty(CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, ligaturesParser.finalizeValue().releaseNonNull(), important, implicitLigatures); 5169 5171 addProperty(CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, numericParser.finalizeValue().releaseNonNull(), important, implicitNumeric); 5170 bool implicitCaps = !capsValue; 5171 addProperty(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, capsValue ? capsValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitCaps); 5172 bool implicitAlternates = !alternatesValue; 5173 addProperty(CSSPropertyFontVariantAlternates, CSSPropertyFontVariant, alternatesValue ? alternatesValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitAlternates); 5174 bool implicitPosition = !positionValue; 5175 addProperty(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, positionValue ? positionValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitPosition); 5176 5177 bool implicitEastAsian = !eastAsianValue; 5178 if (!eastAsianValue) 5179 eastAsianValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal); 5180 addProperty(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, eastAsianValue.releaseNonNull(), important, implicitEastAsian); 5181 5172 5173 auto& valuePool = CSSValuePool::singleton(); 5174 addPropertyWithImplicitDefault(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, capsValue, valuePool.createIdentifierValue(CSSValueNormal), important); 5175 addPropertyWithImplicitDefault(CSSPropertyFontVariantAlternates, CSSPropertyFontVariant, alternatesValue, valuePool.createIdentifierValue(CSSValueNormal), important); 5176 addPropertyWithImplicitDefault(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, positionValue, valuePool.createIdentifierValue(CSSValueNormal), important); 5177 addPropertyWithImplicitDefault(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, WTFMove(eastAsianValue), valuePool.createIdentifierValue(CSSValueNormal), important); 5178 5182 5179 return true; 5183 5180 } … … 5226 5223 if (!m_range.atEnd()) 5227 5224 return false; 5228 5225 5229 5226 // Any unassigned property at this point will become implicit 'auto'. 5230 5227 if (columnWidth) … … 5262 5259 5263 5260 for (size_t i = 0; i < shorthand.length(); ++i) { 5264 if (longhands[i]) 5265 addProperty(shorthandProperties[i], shorthand.id(), longhands[i].releaseNonNull(), important); 5266 else 5267 addProperty(shorthandProperties[i], shorthand.id(), CSSValuePool::singleton().createImplicitInitialValue(), important); 5261 addPropertyWithImplicitDefault(shorthandProperties[i], shorthand.id(), WTFMove(longhands[i]), CSSValuePool::singleton().createImplicitInitialValue(), important); 5268 5262 } 5269 5263 return true; … … 5425 5419 5426 5420 if (consumeBorderImageComponents(property, m_range, m_context, source, slice, width, outset, repeat)) { 5427 if (!source) 5428 source = CSSValuePool::singleton().createImplicitInitialValue(); 5429 if (!slice) 5430 slice = CSSValuePool::singleton().createImplicitInitialValue(); 5431 if (!width) 5432 width = CSSValuePool::singleton().createImplicitInitialValue(); 5433 if (!outset) 5434 outset = CSSValuePool::singleton().createImplicitInitialValue(); 5435 if (!repeat) 5436 repeat = CSSValuePool::singleton().createImplicitInitialValue(); 5421 auto& valuePool = CSSValuePool::singleton(); 5437 5422 switch (property) { 5438 5423 case CSSPropertyWebkitMaskBoxImage: 5439 addProperty (CSSPropertyWebkitMaskBoxImageSource, CSSPropertyWebkitMaskBoxImage, source.releaseNonNull(), important);5440 addProperty (CSSPropertyWebkitMaskBoxImageSlice, CSSPropertyWebkitMaskBoxImage, slice.releaseNonNull(), important);5441 addProperty (CSSPropertyWebkitMaskBoxImageWidth, CSSPropertyWebkitMaskBoxImage, width.releaseNonNull(), important);5442 addProperty (CSSPropertyWebkitMaskBoxImageOutset, CSSPropertyWebkitMaskBoxImage, outset.releaseNonNull(), important);5443 addProperty (CSSPropertyWebkitMaskBoxImageRepeat, CSSPropertyWebkitMaskBoxImage, repeat.releaseNonNull(), important);5424 addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageSource, CSSPropertyWebkitMaskBoxImage, WTFMove(source), valuePool.createImplicitInitialValue(), important); 5425 addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageSlice, CSSPropertyWebkitMaskBoxImage, WTFMove(slice), valuePool.createImplicitInitialValue(), important); 5426 addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageWidth, CSSPropertyWebkitMaskBoxImage, WTFMove(width), valuePool.createImplicitInitialValue(), important); 5427 addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageOutset, CSSPropertyWebkitMaskBoxImage, WTFMove(outset), valuePool.createImplicitInitialValue(), important); 5428 addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageRepeat, CSSPropertyWebkitMaskBoxImage, WTFMove(repeat), valuePool.createImplicitInitialValue(), important); 5444 5429 return true; 5445 5430 case CSSPropertyBorderImage: 5446 addProperty (CSSPropertyBorderImageSource, CSSPropertyBorderImage, source.releaseNonNull(), important);5447 addProperty (CSSPropertyBorderImageSlice, CSSPropertyBorderImage, slice.releaseNonNull(), important);5448 addProperty (CSSPropertyBorderImageWidth, CSSPropertyBorderImage, width.releaseNonNull(), important);5449 addProperty (CSSPropertyBorderImageOutset, CSSPropertyBorderImage, outset.releaseNonNull(), important);5450 addProperty (CSSPropertyBorderImageRepeat, CSSPropertyBorderImage, repeat.releaseNonNull(), important);5431 addPropertyWithImplicitDefault(CSSPropertyBorderImageSource, CSSPropertyBorderImage, WTFMove(source), valuePool.createImplicitInitialValue(), important); 5432 addPropertyWithImplicitDefault(CSSPropertyBorderImageSlice, CSSPropertyBorderImage, WTFMove(slice), valuePool.createImplicitInitialValue(), important); 5433 addPropertyWithImplicitDefault(CSSPropertyBorderImageWidth, CSSPropertyBorderImage, WTFMove(width), valuePool.createImplicitInitialValue(), important); 5434 addPropertyWithImplicitDefault(CSSPropertyBorderImageOutset, CSSPropertyBorderImage, WTFMove(outset), valuePool.createImplicitInitialValue(), important); 5435 addPropertyWithImplicitDefault(CSSPropertyBorderImageRepeat, CSSPropertyBorderImage, WTFMove(repeat), valuePool.createImplicitInitialValue(), important); 5451 5436 return true; 5452 5437 default: -
trunk/Source/WebCore/css/parser/CSSPropertyParser.h
r282806 r285837 78 78 79 79 void addProperty(CSSPropertyID, CSSPropertyID, Ref<CSSValue>&&, bool important, bool implicit = false); 80 void addPropertyWithImplicitDefault(CSSPropertyID, CSSPropertyID, RefPtr<CSSValue>&&, Ref<CSSValue>&& implicitDefault, bool important); 80 81 void addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&&, bool); 81 82
Note: See TracChangeset
for help on using the changeset viewer.