From 9e839b24384ba08e26976bfbcef86cb36e46bba3 Mon Sep 17 00:00:00 2001 From: Matthieu Dubet Date: Wed, 24 Jul 2024 19:32:07 -0700 Subject: [PATCH] [CSS] Use strongly-typed IsImportant instead of bool https://bugs.webkit.org/show_bug.cgi?id=276974 rdar://132359273 Reviewed by Tim Nguyen. * Source/WebCore/animation/KeyframeEffect.cpp: (WebCore::processIterableKeyframes): (WebCore::processPropertyIndexedKeyframes): * Source/WebCore/animation/WebAnimation.cpp: (WebCore::WebAnimation::commitStyles): * Source/WebCore/css/CSSComputedStyleDeclaration.cpp: (WebCore::CSSComputedStyleDeclaration::setPropertyInternal): * Source/WebCore/css/CSSComputedStyleDeclaration.h: * Source/WebCore/css/CSSProperty.h: (WebCore::StylePropertyMetadata::StylePropertyMetadata): (WebCore::CSSProperty::CSSProperty): * Source/WebCore/css/CSSStyleDeclaration.cpp: (WebCore::CSSStyleDeclaration::setPropertyValueForCamelCasedIDLAttribute): (WebCore::CSSStyleDeclaration::setPropertyValueForWebKitCasedIDLAttribute): (WebCore::CSSStyleDeclaration::setPropertyValueForDashedIDLAttribute): (WebCore::CSSStyleDeclaration::setPropertyValueForEpubCasedIDLAttribute): (WebCore::CSSStyleDeclaration::setCssFloat): * Source/WebCore/css/CSSStyleDeclaration.h: * Source/WebCore/css/ComputedStyleExtractor.cpp: (WebCore::ComputedStyleExtractor::copyProperties const): * Source/WebCore/css/DOMCSSNamespace.cpp: (WebCore::DOMCSSNamespace::supports): * Source/WebCore/css/DOMMatrixReadOnly.cpp: (WebCore::DOMMatrixReadOnly::parseStringIntoAbstractMatrix): * Source/WebCore/css/MutableStyleProperties.cpp: (WebCore::MutableStyleProperties::setProperty): (WebCore::MutableStyleProperties::setCustomProperty): * Source/WebCore/css/MutableStyleProperties.h: * Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp: (WebCore::PropertySetCSSStyleDeclaration::setProperty): (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal): * Source/WebCore/css/PropertySetCSSStyleDeclaration.h: * Source/WebCore/css/StyleProperties.cpp: (WebCore::StyleProperties::propertyIsImportant const): (WebCore::StyleProperties::copyProperties const): * Source/WebCore/css/StyleProperties.h: (WebCore::StyleProperties::PropertyReference::toCSSProperty const): * Source/WebCore/css/parser/CSSParser.cpp: (WebCore::CSSParser::parseValue): (WebCore::CSSParser::parseCustomPropertyValue): * Source/WebCore/css/parser/CSSParser.h: * Source/WebCore/css/parser/CSSParserImpl.cpp: (WebCore::CSSParserImpl::parseValue): (WebCore::CSSParserImpl::parseCustomPropertyValue): (WebCore::filterProperties): (WebCore::createStyleProperties): (WebCore::CSSParserImpl::parseDeclarationList): (WebCore::CSSParserImpl::consumeTrailingImportantAndWhitespace): (WebCore::CSSParserImpl::consumeDeclaration): (WebCore::CSSParserImpl::consumeCustomPropertyValue): (WebCore::CSSParserImpl::consumeDeclarationValue): * Source/WebCore/css/parser/CSSParserImpl.h: * Source/WebCore/css/parser/CSSPropertyParser.cpp: (WebCore::CSSPropertyParser::addProperty): * Source/WebCore/css/typedom/CSSStyleValueFactory.cpp: (WebCore::CSSStyleValueFactory::extractCSSValue): (WebCore::CSSStyleValueFactory::extractShorthandCSSValues): * Source/WebCore/css/typedom/DeclaredStylePropertyMap.cpp: (WebCore::DeclaredStylePropertyMap::setShorthandProperty): (WebCore::DeclaredStylePropertyMap::setProperty): (WebCore::DeclaredStylePropertyMap::setCustomProperty): * Source/WebCore/css/typedom/InlineStylePropertyMap.cpp: (WebCore::InlineStylePropertyMap::setShorthandProperty): (WebCore::InlineStylePropertyMap::setProperty): * Source/WebCore/dom/StyledElement.cpp: (WebCore::StyledElement::setInlineStyleProperty): (WebCore::StyledElement::setInlineStyleCustomProperty): (WebCore::StyledElement::addPropertyToPresentationalHintStyle): * Source/WebCore/dom/StyledElement.h: * Source/WebCore/editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange): * Source/WebCore/editing/EditingStyle.cpp: (WebCore::EditingStyle::setProperty): (WebCore::EditingStyle::extractAndRemoveTextDirection): (WebCore::EditingStyle::collapseTextDecorationProperties): (WebCore::EditingStyle::conflictsWithInlineStyleOfElement const): (WebCore::EditingStyle::mergeStyle): (WebCore::EditingStyle::forceInline): (WebCore::EditingStyle::convertPositionStyle): (WebCore::setTextDecorationProperty): * Source/WebCore/editing/EditingStyle.h: * Source/WebCore/editing/Editor.cpp: (WebCore::Editor::setBaseWritingDirection): * Source/WebCore/editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline): * Source/WebCore/html/AttachmentAssociatedElement.cpp: (WebCore::AttachmentAssociatedElement::setAttachmentElement): * Source/WebCore/html/ColorInputType.cpp: (WebCore::ColorInputType::updateColorSwatch): * Source/WebCore/html/TextFieldInputType.cpp: (WebCore::TextFieldInputType::createShadowSubtree): (WebCore::TextFieldInputType::createDataListDropdownIndicator): (WebCore::TextFieldInputType::capsLockStateMayHaveChanged): (WebCore::TextFieldInputType::updateAutoFillButton): (WebCore::TextFieldInputType::dataListMayHaveChanged): * Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp: (WebCore::MediaControlTextTrackContainerElement::updateTextStrokeStyle): * Source/WebCore/html/shadow/TextPlaceholderElement.cpp: * Source/WebCore/html/track/VTTCue.cpp: (WebCore::VTTCueBox::applyCSSProperties): * Source/WebCore/page/DragController.cpp: (WebCore::DragController::concludeEditDrag): * Source/WebCore/style/PropertyCascade.cpp: (WebCore::Style::PropertyCascade::addMatch): (WebCore::Style::PropertyCascade::addNormalMatches): (WebCore::Style::PropertyCascade::addImportantMatches): * Source/WebCore/style/PropertyCascade.h: * Source/WebCore/svg/properties/SVGAttributeAnimator.cpp: (WebCore::SVGAttributeAnimator::applyAnimatedStylePropertyChange): Canonical link: https://commits.webkit.org/281329@main --- Source/WebCore/animation/KeyframeEffect.cpp | 8 ++-- Source/WebCore/animation/WebAnimation.cpp | 4 +- .../css/CSSComputedStyleDeclaration.cpp | 2 +- .../WebCore/css/CSSComputedStyleDeclaration.h | 2 +- Source/WebCore/css/CSSProperty.h | 20 +++++---- Source/WebCore/css/CSSStyleDeclaration.cpp | 10 ++--- Source/WebCore/css/CSSStyleDeclaration.h | 4 +- Source/WebCore/css/ComputedStyleExtractor.cpp | 2 +- Source/WebCore/css/DOMCSSNamespace.cpp | 5 +-- Source/WebCore/css/DOMMatrixReadOnly.cpp | 2 +- Source/WebCore/css/MutableStyleProperties.cpp | 12 +++--- Source/WebCore/css/MutableStyleProperties.h | 10 ++--- .../css/PropertySetCSSStyleDeclaration.cpp | 8 ++-- .../css/PropertySetCSSStyleDeclaration.h | 2 +- Source/WebCore/css/StyleProperties.cpp | 2 +- Source/WebCore/css/StyleProperties.h | 2 +- Source/WebCore/css/parser/CSSParser.cpp | 6 +-- Source/WebCore/css/parser/CSSParser.h | 7 ++-- Source/WebCore/css/parser/CSSParserImpl.cpp | 39 +++++++++--------- Source/WebCore/css/parser/CSSParserImpl.h | 10 ++--- .../WebCore/css/parser/CSSPropertyParser.cpp | 4 +- .../css/typedom/CSSStyleValueFactory.cpp | 6 +-- .../css/typedom/DeclaredStylePropertyMap.cpp | 9 ++-- .../css/typedom/InlineStylePropertyMap.cpp | 6 +-- Source/WebCore/dom/StyledElement.cpp | 22 +++++----- Source/WebCore/dom/StyledElement.h | 15 +++---- Source/WebCore/editing/ApplyStyleCommand.cpp | 2 +- Source/WebCore/editing/EditingStyle.cpp | 41 +++++++++++-------- Source/WebCore/editing/EditingStyle.h | 3 +- Source/WebCore/editing/Editor.cpp | 2 +- .../editing/ReplaceSelectionCommand.cpp | 4 +- .../html/AttachmentAssociatedElement.cpp | 2 +- Source/WebCore/html/ColorInputType.cpp | 2 +- Source/WebCore/html/TextFieldInputType.cpp | 12 +++--- .../MediaControlTextTrackContainerElement.cpp | 2 +- .../html/shadow/TextPlaceholderElement.cpp | 6 +-- Source/WebCore/html/track/VTTCue.cpp | 4 +- Source/WebCore/page/DragController.cpp | 2 +- Source/WebCore/style/PropertyCascade.cpp | 8 ++-- Source/WebCore/style/PropertyCascade.h | 2 +- .../svg/properties/SVGAttributeAnimator.cpp | 2 +- 41 files changed, 158 insertions(+), 155 deletions(-) diff --git a/Source/WebCore/animation/KeyframeEffect.cpp b/Source/WebCore/animation/KeyframeEffect.cpp index 27e0b0a724858..7807b03e6b9d8 100644 --- a/Source/WebCore/animation/KeyframeEffect.cpp +++ b/Source/WebCore/animation/KeyframeEffect.cpp @@ -380,9 +380,9 @@ static inline ExceptionOr processIterableKeyframes(JSGlobalObject& lexical auto stringValue = propertyAndValue.values[0]; if (cssPropertyId == CSSPropertyCustom) { auto customProperty = propertyAndValue.customProperty; - if (keyframeOutput.style->setCustomProperty(customProperty, stringValue, false, parserContext)) + if (keyframeOutput.style->setCustomProperty(customProperty, stringValue, parserContext)) keyframeOutput.customStyleStrings.set(customProperty, stringValue); - } else if (keyframeOutput.style->setProperty(cssPropertyId, stringValue, false, parserContext)) + } else if (keyframeOutput.style->setProperty(cssPropertyId, stringValue, parserContext)) keyframeOutput.styleStrings.set(cssPropertyId, stringValue); } @@ -422,9 +422,9 @@ static inline ExceptionOr processPropertyIndexedKeyframes(JSGlobalObject& // 2. Add the property-value pair, property name → v, to k. if (propertyName == CSSPropertyCustom) { auto customProperty = m.customProperty; - if (k.style->setCustomProperty(customProperty, v, false, parserContext)) + if (k.style->setCustomProperty(customProperty, v, parserContext)) k.customStyleStrings.set(customProperty, v); - } else if (k.style->setProperty(propertyName, v, false, parserContext)) + } else if (k.style->setProperty(propertyName, v, parserContext)) k.styleStrings.set(propertyName, v); // 3. Append k to property keyframes. propertyKeyframes.append(WTFMove(k)); diff --git a/Source/WebCore/animation/WebAnimation.cpp b/Source/WebCore/animation/WebAnimation.cpp index 76349c226a158..341bc48434008 100644 --- a/Source/WebCore/animation/WebAnimation.cpp +++ b/Source/WebCore/animation/WebAnimation.cpp @@ -1609,12 +1609,12 @@ ExceptionOr WebAnimation::commitStyles() return WTF::switchOn(property, [&] (CSSPropertyID propertyId) { if (auto cssValue = computedStyleExtractor.valueForPropertyInStyle(*animatedStyle, propertyId, nullptr, ComputedStyleExtractor::PropertyValueType::Computed)) - return inlineStyle->setProperty(propertyId, cssValue->cssText(), false, { styledElement->document() }); + return inlineStyle->setProperty(propertyId, cssValue->cssText(), { styledElement->document() }); return false; }, [&] (const AtomString& customProperty) { if (auto cssValue = computedStyleExtractor.customPropertyValue(customProperty)) - return inlineStyle->setCustomProperty(customProperty, cssValue->cssText(), false, { styledElement->document() }); + return inlineStyle->setCustomProperty(customProperty, cssValue->cssText(), { styledElement->document() }); return false; } ); diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp index 37732ef755c14..375b50accd747 100644 --- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp +++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp @@ -267,7 +267,7 @@ String CSSComputedStyleDeclaration::getPropertyValueInternal(CSSPropertyID prope return getPropertyValue(propertyID); } -ExceptionOr CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID, const String&, bool) +ExceptionOr CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID, const String&, IsImportant) { return Exception { ExceptionCode::NoModificationAllowedError }; } diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.h b/Source/WebCore/css/CSSComputedStyleDeclaration.h index e4d2fd18509a8..5c23c21b9764c 100644 --- a/Source/WebCore/css/CSSComputedStyleDeclaration.h +++ b/Source/WebCore/css/CSSComputedStyleDeclaration.h @@ -70,7 +70,7 @@ class CSSComputedStyleDeclaration final : public CSSStyleDeclaration, public Ref String cssText() const final; ExceptionOr setCssText(const String&) final; String getPropertyValueInternal(CSSPropertyID) final; - ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, bool important) final; + ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, IsImportant) final; Ref copyProperties() const final; RefPtr getPropertyCSSValue(CSSPropertyID, ComputedStyleExtractor::UpdateLayout = ComputedStyleExtractor::UpdateLayout::Yes) const; diff --git a/Source/WebCore/css/CSSProperty.h b/Source/WebCore/css/CSSProperty.h index fe43008e1cfcb..cd0ec17e8e153 100644 --- a/Source/WebCore/css/CSSProperty.h +++ b/Source/WebCore/css/CSSProperty.h @@ -31,12 +31,14 @@ namespace WebCore { class CSSValueList; +enum class IsImportant : bool { No, Yes }; + struct StylePropertyMetadata { - StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited) + StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, IsImportant important, bool implicit, bool inherited) : m_propertyID(propertyID) , m_isSetFromShorthand(isSetFromShorthand) , m_indexInShorthandsVector(indexInShorthandsVector) - , m_important(important) + , m_important(important == IsImportant::Yes) , m_implicit(implicit) , m_inherited(inherited) { @@ -48,17 +50,17 @@ struct StylePropertyMetadata { friend bool operator==(const StylePropertyMetadata&, const StylePropertyMetadata&) = default; - uint16_t m_propertyID : 10; - uint16_t m_isSetFromShorthand : 1; - uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector. - uint16_t m_important : 1; - uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand. - uint16_t m_inherited : 1; + unsigned m_propertyID : 10; + unsigned m_isSetFromShorthand : 1; + unsigned m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector. + unsigned m_important : 1; + unsigned m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand. + unsigned m_inherited : 1; }; class CSSProperty { public: - CSSProperty(CSSPropertyID propertyID, RefPtr&& value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false) + CSSProperty(CSSPropertyID propertyID, RefPtr&& value, IsImportant important = IsImportant::No, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false) : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID)) , m_value(WTFMove(value)) { diff --git a/Source/WebCore/css/CSSStyleDeclaration.cpp b/Source/WebCore/css/CSSStyleDeclaration.cpp index 41f002e26ba63..de93e0a3a62ab 100644 --- a/Source/WebCore/css/CSSStyleDeclaration.cpp +++ b/Source/WebCore/css/CSSStyleDeclaration.cpp @@ -261,7 +261,7 @@ ExceptionOr CSSStyleDeclaration::setPropertyValueForCamelCasedIDLAttribute { auto propertyID = lookupCSSPropertyFromIDLAttribute(attribute); ASSERT_WITH_MESSAGE(propertyID != CSSPropertyInvalid, "Invalid attribute: %s", attribute.string().utf8().data()); - return setPropertyInternal(propertyID, value, false); + return setPropertyInternal(propertyID, value, IsImportant::No); } String CSSStyleDeclaration::propertyValueForWebKitCasedIDLAttribute(const AtomString& attribute) @@ -275,7 +275,7 @@ ExceptionOr CSSStyleDeclaration::setPropertyValueForWebKitCasedIDLAttribut { auto propertyID = lookupCSSPropertyFromIDLAttribute(attribute); ASSERT_WITH_MESSAGE(propertyID != CSSPropertyInvalid, "Invalid attribute: %s", attribute.string().utf8().data()); - return setPropertyInternal(propertyID, value, false); + return setPropertyInternal(propertyID, value, IsImportant::No); } String CSSStyleDeclaration::propertyValueForDashedIDLAttribute(const AtomString& attribute) @@ -289,7 +289,7 @@ ExceptionOr CSSStyleDeclaration::setPropertyValueForDashedIDLAttribute(con { auto propertyID = lookupCSSPropertyFromIDLAttribute(attribute); ASSERT_WITH_MESSAGE(propertyID != CSSPropertyInvalid, "Invalid attribute: %s", attribute.string().utf8().data()); - return setPropertyInternal(propertyID, value, false); + return setPropertyInternal(propertyID, value, IsImportant::No); } String CSSStyleDeclaration::propertyValueForEpubCasedIDLAttribute(const AtomString& attribute) @@ -303,7 +303,7 @@ ExceptionOr CSSStyleDeclaration::setPropertyValueForEpubCasedIDLAttribute( { auto propertyID = lookupCSSPropertyFromIDLAttribute(attribute); ASSERT_WITH_MESSAGE(propertyID != CSSPropertyInvalid, "Invalid attribute: %s", attribute.string().utf8().data()); - return setPropertyInternal(propertyID, value, false); + return setPropertyInternal(propertyID, value, IsImportant::No); } String CSSStyleDeclaration::cssFloat() @@ -313,7 +313,7 @@ String CSSStyleDeclaration::cssFloat() ExceptionOr CSSStyleDeclaration::setCssFloat(const String& value) { - return setPropertyInternal(CSSPropertyFloat, value, false /* important */); + return setPropertyInternal(CSSPropertyFloat, value, IsImportant::No); } } diff --git a/Source/WebCore/css/CSSStyleDeclaration.h b/Source/WebCore/css/CSSStyleDeclaration.h index 677a8ae24220b..705f882c67b32 100644 --- a/Source/WebCore/css/CSSStyleDeclaration.h +++ b/Source/WebCore/css/CSSStyleDeclaration.h @@ -20,6 +20,7 @@ #pragma once +#include "CSSProperty.h" #include "CSSPropertyNames.h" #include "ExceptionOr.h" #include "ScriptWrappable.h" @@ -27,7 +28,6 @@ namespace WebCore { -class CSSProperty; class CSSRule; class CSSStyleSheet; class CSSValue; @@ -67,7 +67,7 @@ class CSSStyleDeclaration : public ScriptWrappable, public CanMakeSingleThreadWe // CSSPropertyID versions of the CSSOM functions to support bindings and editing. // Use the non-virtual methods in the concrete subclasses when possible. virtual String getPropertyValueInternal(CSSPropertyID) = 0; - virtual ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, bool important) = 0; + virtual ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, IsImportant) = 0; virtual Ref copyProperties() const = 0; diff --git a/Source/WebCore/css/ComputedStyleExtractor.cpp b/Source/WebCore/css/ComputedStyleExtractor.cpp index 14ff69befeed7..0a1206b3bc178 100644 --- a/Source/WebCore/css/ComputedStyleExtractor.cpp +++ b/Source/WebCore/css/ComputedStyleExtractor.cpp @@ -4893,7 +4893,7 @@ Ref ComputedStyleExtractor::copyProperties(std::span std::optional { if (auto value = propertyValue(property)) - return CSSProperty(property, WTFMove(value), false); + return CSSProperty(property, WTFMove(value)); return std::nullopt; }); return MutableStyleProperties::create(WTFMove(vector)); diff --git a/Source/WebCore/css/DOMCSSNamespace.cpp b/Source/WebCore/css/DOMCSSNamespace.cpp index 66ba4aa8b9a07..ff94e6cc4ece1 100644 --- a/Source/WebCore/css/DOMCSSNamespace.cpp +++ b/Source/WebCore/css/DOMCSSNamespace.cpp @@ -53,8 +53,7 @@ bool DOMCSSNamespace::supports(Document& document, const String& property, const CSSPropertyID propertyID = cssPropertyID(propertyNameWithoutWhitespace); if (propertyID == CSSPropertyInvalid && isCustomPropertyName(propertyNameWithoutWhitespace)) { auto dummyStyle = MutableStyleProperties::create(); - constexpr bool importance = false; - return CSSParser::parseCustomPropertyValue(dummyStyle, AtomString { propertyNameWithoutWhitespace }, value, importance, parserContext) != CSSParser::ParseResult::Error; + return CSSParser::parseCustomPropertyValue(dummyStyle, AtomString { propertyNameWithoutWhitespace }, value, IsImportant::No, parserContext) != CSSParser::ParseResult::Error; } if (!isExposed(propertyID, &document.settings())) @@ -70,7 +69,7 @@ bool DOMCSSNamespace::supports(Document& document, const String& property, const return false; auto dummyStyle = MutableStyleProperties::create(); - return CSSParser::parseValue(dummyStyle, propertyID, value, false, parserContext) != CSSParser::ParseResult::Error; + return CSSParser::parseValue(dummyStyle, propertyID, value, IsImportant::No, parserContext) != CSSParser::ParseResult::Error; } bool DOMCSSNamespace::supports(Document& document, const String& conditionText) diff --git a/Source/WebCore/css/DOMMatrixReadOnly.cpp b/Source/WebCore/css/DOMMatrixReadOnly.cpp index 6a3e366a0c021..442eb8ac5d59e 100644 --- a/Source/WebCore/css/DOMMatrixReadOnly.cpp +++ b/Source/WebCore/css/DOMMatrixReadOnly.cpp @@ -228,7 +228,7 @@ ExceptionOr DOMMatrixReadOnly::parseStringInt return AbstractMatrix { }; auto styleDeclaration = MutableStyleProperties::create(); - if (CSSParser::parseValue(styleDeclaration, CSSPropertyTransform, string, true, HTMLStandardMode) == CSSParser::ParseResult::Error) + if (CSSParser::parseValue(styleDeclaration, CSSPropertyTransform, string, IsImportant::Yes, HTMLStandardMode) == CSSParser::ParseResult::Error) return Exception { ExceptionCode::SyntaxError }; // Convert to TransformOperations. This can fail if a property requires style (i.e., param uses 'ems' or 'exs') diff --git a/Source/WebCore/css/MutableStyleProperties.cpp b/Source/WebCore/css/MutableStyleProperties.cpp index e2ad6ea104db9..c490fdb67d527 100644 --- a/Source/WebCore/css/MutableStyleProperties.cpp +++ b/Source/WebCore/css/MutableStyleProperties.cpp @@ -141,7 +141,7 @@ bool MutableStyleProperties::removeCustomProperty(const String& propertyName, St return removePropertyAtIndex(findCustomPropertyIndex(propertyName), returnText); } -bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, bool important, CSSParserContext parserContext, bool* didFailParsing) +bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, CSSParserContext parserContext, IsImportant important, bool* didFailParsing) { if (!isExposed(propertyID, &parserContext.propertySettings) && !isInternal(propertyID)) { // Allow internal properties as we use them to handle certain DOM-exposed values @@ -163,13 +163,13 @@ bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& return parseResult == CSSParser::ParseResult::Changed; } -bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, bool important, bool* didFailParsing) +bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, const String& value, IsImportant important, bool* didFailParsing) { CSSParserContext parserContext(cssParserMode()); - return setProperty(propertyID, value, important, parserContext, didFailParsing); + return setProperty(propertyID, value, parserContext, important, didFailParsing); } -bool MutableStyleProperties::setCustomProperty(const String& propertyName, const String& value, bool important, CSSParserContext parserContext) +bool MutableStyleProperties::setCustomProperty(const String& propertyName, const String& value, CSSParserContext parserContext, IsImportant important) { // Setting the value to an empty string just removes the property in both IE and Gecko. // Setting it to null seems to produce less consistent results, but we treat it just the same. @@ -182,7 +182,7 @@ bool MutableStyleProperties::setCustomProperty(const String& propertyName, const return CSSParser::parseCustomPropertyValue(*this, AtomString { propertyName }, value, important, parserContext) == CSSParser::ParseResult::Changed; } -void MutableStyleProperties::setProperty(CSSPropertyID propertyID, RefPtr&& value, bool important) +void MutableStyleProperties::setProperty(CSSPropertyID propertyID, RefPtr&& value, IsImportant important) { if (isLonghand(propertyID)) { setProperty(CSSProperty(propertyID, WTFMove(value), important)); @@ -235,7 +235,7 @@ bool MutableStyleProperties::setProperty(const CSSProperty& property, CSSPropert return true; } -bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, CSSValueID identifier, bool important) +bool MutableStyleProperties::setProperty(CSSPropertyID propertyID, CSSValueID identifier, IsImportant important) { ASSERT(isLonghand(propertyID)); return setProperty(CSSProperty(propertyID, CSSPrimitiveValue::create(identifier), important)); diff --git a/Source/WebCore/css/MutableStyleProperties.h b/Source/WebCore/css/MutableStyleProperties.h index a99f29daf2436..1ceba6d84f7f2 100644 --- a/Source/WebCore/css/MutableStyleProperties.h +++ b/Source/WebCore/css/MutableStyleProperties.h @@ -63,12 +63,12 @@ class MutableStyleProperties final : public StyleProperties { bool addParsedProperty(const CSSProperty&); // These expand shorthand properties into multiple properties. - bool setProperty(CSSPropertyID, const String& value, bool important, CSSParserContext, bool* didFailParsing = nullptr); - bool setProperty(CSSPropertyID, const String& value, bool important = false, bool* didFailParsing = nullptr); - void setProperty(CSSPropertyID, RefPtr&&, bool important = false); + bool setProperty(CSSPropertyID, const String& value, CSSParserContext, IsImportant = IsImportant::No, bool* didFailParsing = nullptr); + bool setProperty(CSSPropertyID, const String& value, IsImportant = IsImportant::No, bool* didFailParsing = nullptr); + void setProperty(CSSPropertyID, RefPtr&&, IsImportant = IsImportant::No); // These do not. FIXME: This is too messy, we can do better. - bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = false); + bool setProperty(CSSPropertyID, CSSValueID identifier, IsImportant = IsImportant::No); bool setProperty(const CSSProperty&, CSSProperty* slot = nullptr); bool removeProperty(CSSPropertyID, String* returnText = nullptr); @@ -86,7 +86,7 @@ class MutableStyleProperties final : public StyleProperties { int findCustomPropertyIndex(StringView propertyName) const; // Methods for querying and altering CSS custom properties. - bool setCustomProperty(const String& propertyName, const String& value, bool important, CSSParserContext); + bool setCustomProperty(const String& propertyName, const String& value, CSSParserContext, IsImportant = IsImportant::No); bool removeCustomProperty(const String& propertyName, String* returnText = nullptr); private: diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp index 5096918f81541..29638593f7e2d 100644 --- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp +++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp @@ -167,9 +167,9 @@ ExceptionOr PropertySetCSSStyleDeclaration::setProperty(const String& prop bool changed; if (UNLIKELY(propertyID == CSSPropertyCustom)) - changed = m_propertySet->setCustomProperty(propertyName, value, important, cssParserContext()); + changed = m_propertySet->setCustomProperty(propertyName, value, cssParserContext(), important ? IsImportant::Yes : IsImportant::No); else - changed = m_propertySet->setProperty(propertyID, value, important, cssParserContext()); + changed = m_propertySet->setProperty(propertyID, value, cssParserContext(), important ? IsImportant::Yes : IsImportant::No); didMutate(changed ? MutationType::PropertyChanged : MutationType::NoChanges); @@ -217,7 +217,7 @@ String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID pr return { }; } -ExceptionOr PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important) +ExceptionOr PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, IsImportant important) { StyleAttributeMutationScope mutationScope { parentElement() }; if (!willMutate()) @@ -226,7 +226,7 @@ ExceptionOr PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropert if (!isExposed(propertyID)) return { }; - if (m_propertySet->setProperty(propertyID, value, important, cssParserContext())) { + if (m_propertySet->setProperty(propertyID, value, cssParserContext(), important)) { didMutate(MutationType::PropertyChanged); mutationScope.enqueueMutationRecord(); } else diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.h b/Source/WebCore/css/PropertySetCSSStyleDeclaration.h index c50811a7bc1f7..0f830970978df 100644 --- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.h +++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.h @@ -79,7 +79,7 @@ class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration { String cssText() const final; ExceptionOr setCssText(const String&) final; String getPropertyValueInternal(CSSPropertyID) final; - ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, bool important) final; + ExceptionOr setPropertyInternal(CSSPropertyID, const String& value, IsImportant) final; Ref copyProperties() const final; bool isExposed(CSSPropertyID) const; diff --git a/Source/WebCore/css/StyleProperties.cpp b/Source/WebCore/css/StyleProperties.cpp index f11bd466f43a6..a00c925651e5f 100644 --- a/Source/WebCore/css/StyleProperties.cpp +++ b/Source/WebCore/css/StyleProperties.cpp @@ -396,7 +396,7 @@ Ref StyleProperties::copyProperties(std::span std::optional { if (auto value = getPropertyCSSValue(property)) - return CSSProperty(property, WTFMove(value), false); + return CSSProperty(property, WTFMove(value)); return std::nullopt; }); return MutableStyleProperties::create(WTFMove(vector)); diff --git a/Source/WebCore/css/StyleProperties.h b/Source/WebCore/css/StyleProperties.h index e61a99d448185..257bd31857e35 100644 --- a/Source/WebCore/css/StyleProperties.h +++ b/Source/WebCore/css/StyleProperties.h @@ -63,7 +63,7 @@ class StyleProperties : public RefCounted { CSSValue* value() { return const_cast(m_value); } // FIXME: Remove this. - CSSProperty toCSSProperty() const { return CSSProperty(id(), const_cast(m_value), isImportant(), m_metadata.m_isSetFromShorthand, m_metadata.m_indexInShorthandsVector, isImplicit()); } + CSSProperty toCSSProperty() const { return CSSProperty(id(), const_cast(m_value), isImportant() ? IsImportant::Yes : IsImportant::No, m_metadata.m_isSetFromShorthand, m_metadata.m_indexInShorthandsVector, isImplicit()); } private: const StylePropertyMetadata& m_metadata; diff --git a/Source/WebCore/css/parser/CSSParser.cpp b/Source/WebCore/css/parser/CSSParser.cpp index e14033d5b8080..787a94971b0d6 100644 --- a/Source/WebCore/css/parser/CSSParser.cpp +++ b/Source/WebCore/css/parser/CSSParser.cpp @@ -141,7 +141,7 @@ RefPtr CSSParser::parseSingleValue(CSSPropertyID propertyID, const Str return CSSPropertyParser::parseSingleValue(propertyID, tokenizer.tokenRange(), context); } -CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context) +CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, IsImportant important, const CSSParserContext& context) { ASSERT(!string.isEmpty()); if (RefPtr value = CSSParserFastPaths::maybeParseValue(propertyID, string, context)) @@ -150,12 +150,12 @@ CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration return parser.parseValue(declaration, propertyID, string, important); } -CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomString& propertyName, const String& string, bool important, const CSSParserContext& context) +CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomString& propertyName, const String& string, IsImportant important, const CSSParserContext& context) { return CSSParserImpl::parseCustomPropertyValue(declaration, propertyName, string, important, context); } -CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important) +CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, IsImportant important) { return CSSParserImpl::parseValue(declaration, propertyID, string, important, m_context); } diff --git a/Source/WebCore/css/parser/CSSParser.h b/Source/WebCore/css/parser/CSSParser.h index b132ba33ffd3c..7f8519d911b7b 100644 --- a/Source/WebCore/css/parser/CSSParser.h +++ b/Source/WebCore/css/parser/CSSParser.h @@ -24,6 +24,7 @@ #include "CSSParserContext.h" #include "CSSParserEnum.h" +#include "CSSProperty.h" #include "CSSSelectorParser.h" #include "CSSValue.h" #include "ColorTypes.h" @@ -65,8 +66,8 @@ class CSSParser { static void parseSheetForInspector(const CSSParserContext&, StyleSheetContents&, const String&, CSSParserObserver&); static void parseDeclarationForInspector(const CSSParserContext&, const String&, CSSParserObserver&); - static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&); - static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, bool important, const CSSParserContext&); + static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, IsImportant, const CSSParserContext&); + static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, IsImportant, const CSSParserContext&); static RefPtr parseSingleValue(CSSPropertyID, const String&, const CSSParserContext& = strictCSSParserContext()); @@ -83,7 +84,7 @@ class CSSParser { static std::optional> parseHexColor(StringView); private: - ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important); + ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, IsImportant); CSSParserContext m_context; }; diff --git a/Source/WebCore/css/parser/CSSParserImpl.cpp b/Source/WebCore/css/parser/CSSParserImpl.cpp index e64e92a3700bc..60cc4e28bbd3b 100644 --- a/Source/WebCore/css/parser/CSSParserImpl.cpp +++ b/Source/WebCore/css/parser/CSSParserImpl.cpp @@ -68,6 +68,7 @@ #include "StyleRule.h" #include "StyleRuleImport.h" #include "StyleSheetContents.h" +#include "css/CSSProperty.h" #include #include #include @@ -124,7 +125,7 @@ CSSParserImpl::CSSParserImpl(const CSSParserContext& context, const String& stri { } -CSSParser::ParseResult CSSParserImpl::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context) +CSSParser::ParseResult CSSParserImpl::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, IsImportant important, const CSSParserContext& context) { CSSParserImpl parser(context, string); auto ruleType = context.enclosingRuleType.value_or(StyleRuleType::Style); @@ -134,7 +135,7 @@ CSSParser::ParseResult CSSParserImpl::parseValue(MutableStyleProperties& declara return declaration.addParsedProperties(parser.topContext().m_parsedProperties) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged; } -CSSParser::ParseResult CSSParserImpl::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomString& propertyName, const String& string, bool important, const CSSParserContext& context) +CSSParser::ParseResult CSSParserImpl::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomString& propertyName, const String& string, IsImportant important, const CSSParserContext& context) { CSSParserImpl parser(context, string); @@ -148,12 +149,12 @@ CSSParser::ParseResult CSSParserImpl::parseCustomPropertyValue(MutableStylePrope return declaration.addParsedProperties(parser.topContext().m_parsedProperties) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged; } -static inline void filterProperties(bool important, const ParsedPropertyVector& input, ParsedPropertyVector& output, size_t& unusedEntries, std::bitset& seenProperties, HashSet& seenCustomProperties) +static inline void filterProperties(IsImportant important, const ParsedPropertyVector& input, ParsedPropertyVector& output, size_t& unusedEntries, std::bitset& seenProperties, HashSet& seenCustomProperties) { // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. for (size_t i = input.size(); i--;) { const CSSProperty& property = input[i]; - if (property.isImportant() != important) + if ((property.isImportant() && important == IsImportant::No) || (!property.isImportant() && important == IsImportant::Yes)) continue; const unsigned propertyIDIndex = property.id() - firstCSSProperty; @@ -181,8 +182,8 @@ static Ref createStyleProperties(ParsedPropertyVector& ParsedPropertyVector results(unusedEntries); HashSet seenCustomProperties; - filterProperties(true, parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); - filterProperties(false, parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); + filterProperties(IsImportant::Yes, parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); + filterProperties(IsImportant::No, parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); Ref result = ImmutableStyleProperties::createDeduplicating(results.data() + unusedEntries, results.size() - unusedEntries, mode); parsedProperties.clear(); @@ -211,8 +212,8 @@ bool CSSParserImpl::parseDeclarationList(MutableStyleProperties* declaration, co size_t unusedEntries = parser.topContext().m_parsedProperties.size(); ParsedPropertyVector results(unusedEntries); HashSet seenCustomProperties; - filterProperties(true, parser.topContext().m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); - filterProperties(false, parser.topContext().m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); + filterProperties(IsImportant::Yes, parser.topContext().m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); + filterProperties(IsImportant::No, parser.topContext().m_parsedProperties, results, unusedEntries, seenProperties, seenCustomProperties); if (unusedEntries) results.remove(0, unusedEntries); return declaration->addParsedProperties(results); @@ -1488,23 +1489,23 @@ void CSSParserImpl::consumeStyleBlock(CSSParserTokenRange range, StyleRuleType r consumeBlockContent(range, ruleType, OnlyDeclarations::No, isParsingStyleDeclarationsInRuleList); } -bool CSSParserImpl::consumeTrailingImportantAndWhitespace(CSSParserTokenRange& range) +IsImportant CSSParserImpl::consumeTrailingImportantAndWhitespace(CSSParserTokenRange& range) { range.trimTrailingWhitespace(); if (range.size() < 2) - return false; + return IsImportant::No; auto removeImportantRange = range; if (auto& last = removeImportantRange.consumeLast(); last.type() != IdentToken || !equalLettersIgnoringASCIICase(last.value(), "important"_s)) - return false; + return IsImportant::No; removeImportantRange.trimTrailingWhitespace(); if (auto& last = removeImportantRange.consumeLast(); last.type() != DelimiterToken || last.delimiter() != '!') - return false; + return IsImportant::No; removeImportantRange.trimTrailingWhitespace(); range = removeImportantRange; - return true; + return IsImportant::Yes; } // https://drafts.csswg.org/css-syntax/#consume-declaration @@ -1520,7 +1521,7 @@ bool CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRuleType range.consumeWhitespace(); - bool important = consumeTrailingImportantAndWhitespace(range); + auto important = consumeTrailingImportantAndWhitespace(range); const size_t oldPropertiesCount = topContext().m_parsedProperties.size(); auto didParseNewProperties = [&] { @@ -1535,7 +1536,7 @@ bool CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRuleType consumeCustomPropertyValue(range, variableName, important); } - if (important && (ruleType == StyleRuleType::FontFace || ruleType == StyleRuleType::Keyframe || ruleType == StyleRuleType::CounterStyle || ruleType == StyleRuleType::FontPaletteValues)) + if (important == IsImportant::Yes && (ruleType == StyleRuleType::FontFace || ruleType == StyleRuleType::Keyframe || ruleType == StyleRuleType::CounterStyle || ruleType == StyleRuleType::FontPaletteValues)) return didParseNewProperties(); if (propertyID != CSSPropertyInvalid) @@ -1544,13 +1545,13 @@ bool CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRuleType if (m_observerWrapper && (ruleType == StyleRuleType::Style || ruleType == StyleRuleType::Keyframe)) { m_observerWrapper->observer().observeProperty( m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOffset(rangeCopy), - important, didParseNewProperties()); + important == IsImportant::Yes, didParseNewProperties()); } return didParseNewProperties(); } -void CSSParserImpl::consumeCustomPropertyValue(CSSParserTokenRange range, const AtomString& variableName, bool important) +void CSSParserImpl::consumeCustomPropertyValue(CSSParserTokenRange range, const AtomString& variableName, IsImportant important) { if (range.atEnd()) topContext().m_parsedProperties.append(CSSProperty(CSSPropertyCustom, CSSCustomPropertyValue::createEmpty(variableName), important)); @@ -1558,9 +1559,9 @@ void CSSParserImpl::consumeCustomPropertyValue(CSSParserTokenRange range, const topContext().m_parsedProperties.append(CSSProperty(CSSPropertyCustom, WTFMove(value), important)); } -void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID propertyID, bool important, StyleRuleType ruleType) +void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID propertyID, IsImportant important, StyleRuleType ruleType) { - CSSPropertyParser::parseValue(propertyID, important, range, m_context, topContext().m_parsedProperties, ruleType); + CSSPropertyParser::parseValue(propertyID, important == IsImportant::Yes, range, m_context, topContext().m_parsedProperties, ruleType); } Vector CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenRange range) diff --git a/Source/WebCore/css/parser/CSSParserImpl.h b/Source/WebCore/css/parser/CSSParserImpl.h index cb5ebcaba212f..aa0ace0c3f01b 100644 --- a/Source/WebCore/css/parser/CSSParserImpl.h +++ b/Source/WebCore/css/parser/CSSParserImpl.h @@ -91,8 +91,8 @@ class CSSParserImpl { NoRules, // For parsing at-rules inside declaration lists (without nesting support) }; - static CSSParser::ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&); - static CSSParser::ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, bool important, const CSSParserContext&); + static CSSParser::ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, IsImportant, const CSSParserContext&); + static CSSParser::ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, IsImportant, const CSSParserContext&); static Ref parseInlineStyleDeclaration(const String&, const Element&); static bool parseDeclarationList(MutableStyleProperties*, const String&, const CSSParserContext&); static RefPtr parseRule(const String&, const CSSParserContext&, StyleSheetContents*, AllowedRules, CSSParserEnum::IsNestedContext = CSSParserEnum::IsNestedContext::No); @@ -110,7 +110,7 @@ class CSSParserImpl { static void parseDeclarationListForInspector(const String&, const CSSParserContext&, CSSParserObserver&); static void parseStyleSheetForInspector(const String&, const CSSParserContext&, StyleSheetContents&, CSSParserObserver&); - static bool consumeTrailingImportantAndWhitespace(CSSParserTokenRange&); + static IsImportant consumeTrailingImportantAndWhitespace(CSSParserTokenRange&); CSSTokenizer* tokenizer() const { return m_tokenizer.get(); } @@ -174,8 +174,8 @@ class CSSParserImpl { void consumeDeclarationList(CSSParserTokenRange, StyleRuleType); void consumeStyleBlock(CSSParserTokenRange, StyleRuleType, ParsingStyleDeclarationsInRuleList = ParsingStyleDeclarationsInRuleList::No); bool consumeDeclaration(CSSParserTokenRange, StyleRuleType); - void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, bool important, StyleRuleType); - void consumeCustomPropertyValue(CSSParserTokenRange, const AtomString& propertyName, bool important); + void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, IsImportant, StyleRuleType); + void consumeCustomPropertyValue(CSSParserTokenRange, const AtomString& propertyName, IsImportant); static Vector consumeKeyframeKeyList(CSSParserTokenRange); diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp index df8f8315dadd4..c4d0212fd3b43 100644 --- a/Source/WebCore/css/parser/CSSPropertyParser.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp @@ -192,10 +192,10 @@ void CSSPropertyParser::addProperty(CSSPropertyID property, CSSPropertyID curren ASSERT(isExposed(property, &m_context.propertySettings) || setFromShorthand || isInternal(property)); if (value && !value->isImplicitInitialValue()) - m_parsedProperties->append(CSSProperty(property, WTFMove(value), important, setFromShorthand, shorthandIndex, implicit)); + m_parsedProperties->append(CSSProperty(property, WTFMove(value), important ? IsImportant::Yes : IsImportant::No, setFromShorthand, shorthandIndex, implicit)); else { ASSERT(setFromShorthand); - m_parsedProperties->append(CSSProperty(property, Ref { CSSPrimitiveValue::implicitInitialValue() }, important, setFromShorthand, shorthandIndex, true)); + m_parsedProperties->append(CSSProperty(property, Ref { CSSPrimitiveValue::implicitInitialValue() }, important ? IsImportant::Yes : IsImportant::No, setFromShorthand, shorthandIndex, true)); } } diff --git a/Source/WebCore/css/typedom/CSSStyleValueFactory.cpp b/Source/WebCore/css/typedom/CSSStyleValueFactory.cpp index 55075eb063547..d6604fc07c853 100644 --- a/Source/WebCore/css/typedom/CSSStyleValueFactory.cpp +++ b/Source/WebCore/css/typedom/CSSStyleValueFactory.cpp @@ -73,8 +73,7 @@ ExceptionOr> CSSStyleValueFactory::extractCSSValue(const CSSPro { auto styleDeclaration = MutableStyleProperties::create(); - constexpr bool important = true; - CSSParser::ParseResult parseResult = CSSParser::parseValue(styleDeclaration, propertyID, cssText, important, parserContext); + CSSParser::ParseResult parseResult = CSSParser::parseValue(styleDeclaration, propertyID, cssText, IsImportant::Yes, parserContext); if (parseResult == CSSParser::ParseResult::Error) return Exception { ExceptionCode::TypeError, makeString(cssText, " cannot be parsed."_s) }; @@ -86,8 +85,7 @@ ExceptionOr> CSSStyleValueFactory::extractShorthandCSSValu { auto styleDeclaration = MutableStyleProperties::create(); - constexpr bool important = true; - CSSParser::ParseResult parseResult = CSSParser::parseValue(styleDeclaration, propertyID, cssText, important, parserContext); + CSSParser::ParseResult parseResult = CSSParser::parseValue(styleDeclaration, propertyID, cssText, IsImportant::Yes, parserContext); if (parseResult == CSSParser::ParseResult::Error) return Exception { ExceptionCode::TypeError, makeString(cssText, " cannot be parsed."_s) }; diff --git a/Source/WebCore/css/typedom/DeclaredStylePropertyMap.cpp b/Source/WebCore/css/typedom/DeclaredStylePropertyMap.cpp index 06b37318d4d69..865891b3df40d 100644 --- a/Source/WebCore/css/typedom/DeclaredStylePropertyMap.cpp +++ b/Source/WebCore/css/typedom/DeclaredStylePropertyMap.cpp @@ -102,8 +102,7 @@ bool DeclaredStylePropertyMap::setShorthandProperty(CSSPropertyID propertyID, co CSSStyleSheet::RuleMutationScope mutationScope(m_ownerRule.get()); bool didFailParsing = false; - bool important = false; - styleRule->mutableProperties().setProperty(propertyID, value, important, &didFailParsing); + styleRule->mutableProperties().setProperty(propertyID, value, IsImportant::No, &didFailParsing); return !didFailParsing; } @@ -115,8 +114,7 @@ bool DeclaredStylePropertyMap::setProperty(CSSPropertyID propertyID, RefmutableProperties().setProperty(propertyID, value->cssText(), important, &didFailParsing); + styleRule->mutableProperties().setProperty(propertyID, value->cssText(), IsImportant::No, &didFailParsing); return !didFailParsing; } @@ -127,9 +125,8 @@ bool DeclaredStylePropertyMap::setCustomProperty(Document&, const AtomString& pr return false; CSSStyleSheet::RuleMutationScope mutationScope(m_ownerRule.get()); - bool important = false; auto customPropertyValue = CSSCustomPropertyValue::createUnresolved(property, WTFMove(value)); - styleRule->mutableProperties().addParsedProperty(CSSProperty(CSSPropertyCustom, WTFMove(customPropertyValue), important)); + styleRule->mutableProperties().addParsedProperty(CSSProperty(CSSPropertyCustom, WTFMove(customPropertyValue))); return true; } diff --git a/Source/WebCore/css/typedom/InlineStylePropertyMap.cpp b/Source/WebCore/css/typedom/InlineStylePropertyMap.cpp index b2c92db541137..8ddfebf178db1 100644 --- a/Source/WebCore/css/typedom/InlineStylePropertyMap.cpp +++ b/Source/WebCore/css/typedom/InlineStylePropertyMap.cpp @@ -101,8 +101,7 @@ bool InlineStylePropertyMap::setShorthandProperty(CSSPropertyID propertyID, cons return false; StyleAttributeMutationScope mutationScope { m_element.get() }; bool didFailParsing = false; - bool important = false; - m_element->setInlineStyleProperty(propertyID, value, important, &didFailParsing); + m_element->setInlineStyleProperty(propertyID, value, IsImportant::No, &didFailParsing); if (!didFailParsing) mutationScope.enqueueMutationRecord(); return !didFailParsing; @@ -114,10 +113,9 @@ bool InlineStylePropertyMap::setProperty(CSSPropertyID propertyID, Ref return false; StyleAttributeMutationScope mutationScope { m_element.get() }; bool didFailParsing = false; - bool important = false; // FIXME: We should be able to validate CSSValues without having to serialize to text and go through the // parser. This is inefficient. - m_element->setInlineStyleProperty(propertyID, value->cssText(), important, &didFailParsing); + m_element->setInlineStyleProperty(propertyID, value->cssText(), IsImportant::No, &didFailParsing); if (!didFailParsing) { m_element->setInlineStyleProperty(propertyID, WTFMove(value)); mutationScope.enqueueMutationRecord(); diff --git a/Source/WebCore/dom/StyledElement.cpp b/Source/WebCore/dom/StyledElement.cpp index 363260cdedb56..ac43cdb2bf015 100644 --- a/Source/WebCore/dom/StyledElement.cpp +++ b/Source/WebCore/dom/StyledElement.cpp @@ -208,51 +208,51 @@ void StyledElement::inlineStyleChanged() InspectorInstrumentation::didInvalidateStyleAttr(*this); } -bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, CSSValueID identifier, bool important) +bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, CSSValueID identifier, IsImportant important) { ensureMutableInlineStyle().setProperty(propertyID, CSSPrimitiveValue::create(identifier), important); inlineStyleChanged(); return true; } -bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, CSSPropertyID identifier, bool important) +bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, CSSPropertyID identifier, IsImportant important) { ensureMutableInlineStyle().setProperty(propertyID, CSSPrimitiveValue::create(identifier), important); inlineStyleChanged(); return true; } -bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, double value, CSSUnitType unit, bool important) +bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, double value, CSSUnitType unit, IsImportant important) { ensureMutableInlineStyle().setProperty(propertyID, CSSPrimitiveValue::create(value, unit), important); inlineStyleChanged(); return true; } -bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, Ref&& value, bool important) +bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, Ref&& value, IsImportant important) { ensureMutableInlineStyle().setProperty(propertyID, WTFMove(value), important); inlineStyleChanged(); return true; } -bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, bool important, bool* didFailParsing) +bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, IsImportant important, bool* didFailParsing) { - bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, important, CSSParserContext(document()), didFailParsing); + bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, CSSParserContext(document()), important, didFailParsing); if (changes) inlineStyleChanged(); return changes; } -bool StyledElement::setInlineStyleCustomProperty(const AtomString& property, const String& value, bool important) +bool StyledElement::setInlineStyleCustomProperty(const AtomString& property, const String& value, IsImportant important) { - bool changes = ensureMutableInlineStyle().setCustomProperty(property.string(), value, important, CSSParserContext(document())); + bool changes = ensureMutableInlineStyle().setCustomProperty(property.string(), value, CSSParserContext(document()), important); if (changes) inlineStyleChanged(); return changes; } -bool StyledElement::setInlineStyleCustomProperty(Ref&& customPropertyValue, bool important) +bool StyledElement::setInlineStyleCustomProperty(Ref&& customPropertyValue, IsImportant important) { ensureMutableInlineStyle().addParsedProperty(CSSProperty(CSSPropertyCustom, WTFMove(customPropertyValue), important)); inlineStyleChanged(); @@ -377,12 +377,12 @@ void StyledElement::addPropertyToPresentationalHintStyle(MutableStyleProperties& void StyledElement::addPropertyToPresentationalHintStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value) { - style.setProperty(propertyID, value, false, CSSParserContext(document())); + style.setProperty(propertyID, value, CSSParserContext(document())); } void StyledElement::addPropertyToPresentationalHintStyle(MutableStyleProperties& style, CSSPropertyID propertyID, RefPtr&& value) { - style.setProperty(propertyID, WTFMove(value), false); + style.setProperty(propertyID, WTFMove(value)); } } diff --git a/Source/WebCore/dom/StyledElement.h b/Source/WebCore/dom/StyledElement.h index 7dc7015afed17..e0ecd57b7b71a 100644 --- a/Source/WebCore/dom/StyledElement.h +++ b/Source/WebCore/dom/StyledElement.h @@ -25,6 +25,7 @@ #pragma once #include "CSSPrimitiveValue.h" +#include "CSSProperty.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "Element.h" @@ -50,13 +51,13 @@ class StyledElement : public Element { const StyleProperties* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : nullptr; } RefPtr protectedInlineStyle() const; - bool setInlineStyleProperty(CSSPropertyID, CSSValueID identifier, bool important = false); - bool setInlineStyleProperty(CSSPropertyID, CSSPropertyID identifier, bool important = false); - WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, double value, CSSUnitType, bool important = false); - WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false, bool* didFailParsing = nullptr); - bool setInlineStyleCustomProperty(const AtomString& property, const String& value, bool important = false); - bool setInlineStyleCustomProperty(Ref&&, bool important = false); - bool setInlineStyleProperty(CSSPropertyID, Ref&&, bool important = false); + bool setInlineStyleProperty(CSSPropertyID, CSSValueID identifier, IsImportant = IsImportant::No); + bool setInlineStyleProperty(CSSPropertyID, CSSPropertyID identifier, IsImportant = IsImportant::No); + WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, double value, CSSUnitType, IsImportant = IsImportant::No); + WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, const String& value, IsImportant = IsImportant::No, bool* didFailParsing = nullptr); + bool setInlineStyleCustomProperty(const AtomString& property, const String& value, IsImportant = IsImportant::No); + bool setInlineStyleCustomProperty(Ref&&, IsImportant = IsImportant::No); + bool setInlineStyleProperty(CSSPropertyID, Ref&&, IsImportant = IsImportant::No); bool removeInlineStyleProperty(CSSPropertyID); bool removeInlineStyleCustomProperty(const AtomString&); void removeAllInlineStyleProperties(); diff --git a/Source/WebCore/editing/ApplyStyleCommand.cpp b/Source/WebCore/editing/ApplyStyleCommand.cpp index f7cf1b5928a55..9e9c80e22e646 100644 --- a/Source/WebCore/editing/ApplyStyleCommand.cpp +++ b/Source/WebCore/editing/ApplyStyleCommand.cpp @@ -414,7 +414,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style) currentFontSize = computedFontSize(node.get()); } if (currentFontSize != desiredFontSize) { - inlineStyle->setProperty(CSSPropertyFontSize, CSSPrimitiveValue::create(desiredFontSize, CSSUnitType::CSS_PX), false); + inlineStyle->setProperty(CSSPropertyFontSize, CSSPrimitiveValue::create(desiredFontSize, CSSUnitType::CSS_PX)); setNodeAttribute(*element, styleAttr, inlineStyle->asTextAtom()); } if (inlineStyle->isEmpty()) { diff --git a/Source/WebCore/editing/EditingStyle.cpp b/Source/WebCore/editing/EditingStyle.cpp index 2f62353c3f1ec..31d64037113bd 100644 --- a/Source/WebCore/editing/EditingStyle.cpp +++ b/Source/WebCore/editing/EditingStyle.cpp @@ -574,7 +574,7 @@ void EditingStyle::removeTextFillAndStrokeColorsIfNeeded(const RenderStyle* rend m_mutableStyle->removeProperty(CSSPropertyWebkitTextStrokeColor); } -void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bool important) +void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, IsImportant important) { if (!m_mutableStyle) m_mutableStyle = MutableStyleProperties::create(); @@ -776,9 +776,9 @@ Ref EditingStyle::extractAndRemoveTextDirection() { auto textDirection = EditingStyle::create(); textDirection->m_mutableStyle = MutableStyleProperties::create(); - textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi)); + textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi) ? IsImportant::Yes : IsImportant::No); textDirection->m_mutableStyle->setProperty(CSSPropertyDirection, m_mutableStyle->getPropertyValue(CSSPropertyDirection), - m_mutableStyle->propertyIsImportant(CSSPropertyDirection)); + static_cast(m_mutableStyle->propertyIsImportant(CSSPropertyDirection))); m_mutableStyle->removeProperty(CSSPropertyUnicodeBidi); m_mutableStyle->removeProperty(CSSPropertyDirection); @@ -827,7 +827,7 @@ void EditingStyle::collapseTextDecorationProperties() return; if (textDecorationsInEffect->isValueList()) - m_mutableStyle->setProperty(CSSPropertyTextDecorationLine, textDecorationsInEffect->cssText(), m_mutableStyle->propertyIsImportant(CSSPropertyTextDecorationLine)); + m_mutableStyle->setProperty(CSSPropertyTextDecorationLine, textDecorationsInEffect->cssText(), m_mutableStyle->propertyIsImportant(CSSPropertyTextDecorationLine) ? IsImportant::Yes : IsImportant::No); else m_mutableStyle->removeProperty(CSSPropertyTextDecorationLine); m_mutableStyle->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); @@ -944,7 +944,7 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement& element, Ref else newInlineStyle->setProperty(CSSPropertyTextDecorationLine, CSSValueList::createSpaceSeparated(WTFMove(newValueList))); if (extractedStyle) { - bool isImportant = inlineStyle->propertyIsImportant(CSSPropertyTextDecorationLine); + auto isImportant = inlineStyle->propertyIsImportant(CSSPropertyTextDecorationLine) ? IsImportant::Yes : IsImportant::No; extractedStyle->setProperty(CSSPropertyTextDecorationLine, CSSValueList::createSpaceSeparated(extractedValueList)->cssText(), isImportant); } } @@ -966,8 +966,10 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement& element, Ref return true; conflicts = true; newInlineStyle->removeProperty(CSSPropertyTextDecorationLine); - if (extractedStyle) - extractedStyle->setProperty(CSSPropertyTextDecorationLine, inlineStyle->getPropertyValue(CSSPropertyTextDecorationLine), inlineStyle->propertyIsImportant(CSSPropertyTextDecorationLine)); + if (extractedStyle) { + auto isImportant = inlineStyle->propertyIsImportant(CSSPropertyTextDecorationLine) ? IsImportant::Yes : IsImportant::No; + extractedStyle->setProperty(CSSPropertyTextDecorationLine, inlineStyle->getPropertyValue(CSSPropertyTextDecorationLine), isImportant); + } } if (!inlineStyle->getPropertyCSSValue(propertyID)) @@ -978,8 +980,10 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement& element, Ref return true; conflicts = true; newInlineStyle->removeProperty(CSSPropertyDirection); - if (extractedStyle) - extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValue(propertyID), inlineStyle->propertyIsImportant(propertyID)); + if (extractedStyle) { + auto isImportant = inlineStyle->propertyIsImportant(propertyID) ? IsImportant::Yes : IsImportant::No; + extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValue(propertyID), isImportant); + } } if (!newInlineStyle) @@ -987,8 +991,10 @@ bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement& element, Ref conflicts = true; newInlineStyle->removeProperty(propertyID); - if (extractedStyle) - extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValue(propertyID), inlineStyle->propertyIsImportant(propertyID)); + if (extractedStyle) { + auto isImportant = inlineStyle->propertyIsImportant(propertyID) ? IsImportant::Yes : IsImportant::No; + extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValue(propertyID), isImportant); + } } return conflicts; @@ -1331,7 +1337,7 @@ void EditingStyle::mergeStyle(const StyleProperties* style, CSSPropertyOverrideM if (auto* valueList = dynamicDowncast(*value)) { auto newValue = valueList->copyValues(); mergeTextDecorationValues(newValue, *propertyValueList); - m_mutableStyle->setProperty(property.id(), CSSValueList::createSpaceSeparated(WTFMove(newValue)), property.isImportant()); + m_mutableStyle->setProperty(property.id(), CSSValueList::createSpaceSeparated(WTFMove(newValue)), property.isImportant() ? IsImportant::Yes : IsImportant::No); continue; } value = nullptr; // text-decoration: none is equivalent to not having the property. @@ -1339,7 +1345,7 @@ void EditingStyle::mergeStyle(const StyleProperties* style, CSSPropertyOverrideM } if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) - m_mutableStyle->setProperty(property.id(), property.value(), property.isImportant()); + m_mutableStyle->setProperty(property.id(), property.value(), property.isImportant() ? IsImportant::Yes : IsImportant::No); } int oldFontSizeDelta = m_fontSizeDelta; @@ -1518,8 +1524,7 @@ void EditingStyle::forceInline() { if (!m_mutableStyle) m_mutableStyle = MutableStyleProperties::create(); - const bool propertyIsImportant = true; - m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsImportant); + m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, IsImportant::Yes); } void EditingStyle::addDisplayContents() @@ -1536,12 +1541,12 @@ bool EditingStyle::convertPositionStyle() RefPtr sticky = CSSPrimitiveValue::create(CSSValueSticky); if (m_mutableStyle->propertyMatches(CSSPropertyPosition, sticky.get())) { - m_mutableStyle->setProperty(CSSPropertyPosition, CSSPrimitiveValue::create(CSSValueStatic), m_mutableStyle->propertyIsImportant(CSSPropertyPosition)); + m_mutableStyle->setProperty(CSSPropertyPosition, CSSPrimitiveValue::create(CSSValueStatic), m_mutableStyle->propertyIsImportant(CSSPropertyPosition) ? IsImportant::Yes : IsImportant::No); return false; } RefPtr fixed = CSSPrimitiveValue::create(CSSValueFixed); if (m_mutableStyle->propertyMatches(CSSPropertyPosition, fixed.get())) { - m_mutableStyle->setProperty(CSSPropertyPosition, CSSPrimitiveValue::create(CSSValueAbsolute), m_mutableStyle->propertyIsImportant(CSSPropertyPosition)); + m_mutableStyle->setProperty(CSSPropertyPosition, CSSPrimitiveValue::create(CSSValueAbsolute), m_mutableStyle->propertyIsImportant(CSSPropertyPosition) ? IsImportant::Yes : IsImportant::No); return true; } RefPtr absolute = CSSPrimitiveValue::create(CSSValueAbsolute); @@ -1831,7 +1836,7 @@ bool StyleChange::operator==(const StyleChange& other) static void setTextDecorationProperty(MutableStyleProperties& style, const CSSValueList& newTextDecoration, CSSPropertyID propertyID) { if (newTextDecoration.length()) - style.setProperty(propertyID, newTextDecoration.cssText(), style.propertyIsImportant(propertyID)); + style.setProperty(propertyID, newTextDecoration.cssText(), style.propertyIsImportant(propertyID) ? IsImportant::Yes : IsImportant::No); else { // text-decoration: none is redundant since it does not remove any text decorations. style.removeProperty(propertyID); diff --git a/Source/WebCore/editing/EditingStyle.h b/Source/WebCore/editing/EditingStyle.h index 1399ea63d8e06..2f0a893fe557b 100644 --- a/Source/WebCore/editing/EditingStyle.h +++ b/Source/WebCore/editing/EditingStyle.h @@ -31,6 +31,7 @@ #pragma once +#include "CSSProperty.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "WritingDirection.h" @@ -180,7 +181,7 @@ class EditingStyle : public RefCounted { EditingStyle(CSSPropertyID, CSSValueID); void init(Node*, PropertiesToInclude); void removeTextFillAndStrokeColorsIfNeeded(const RenderStyle*); - void setProperty(CSSPropertyID, const String& value, bool important = false); + void setProperty(CSSPropertyID, const String& value, IsImportant = IsImportant::No); void extractFontSizeDelta(); template TriState triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties) const; bool conflictsWithInlineStyleOfElement(StyledElement&, RefPtr* newInlineStyle, EditingStyle* extractedStyle) const; diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp index 8f3c2c00f3d0d..ef6a9c840bca7 100644 --- a/Source/WebCore/editing/Editor.cpp +++ b/Source/WebCore/editing/Editor.cpp @@ -2060,7 +2060,7 @@ void Editor::setBaseWritingDirection(WritingDirection direction) } auto style = MutableStyleProperties::create(); - style->setProperty(CSSPropertyDirection, direction == WritingDirection::LeftToRight ? "ltr"_s : direction == WritingDirection::RightToLeft ? "rtl"_s : "inherit"_s, false); + style->setProperty(CSSPropertyDirection, direction == WritingDirection::LeftToRight ? "ltr"_s : direction == WritingDirection::RightToLeft ? "rtl"_s : "inherit"_s); applyParagraphStyleToSelection(style.ptr(), EditAction::SetBlockWritingDirection); } diff --git a/Source/WebCore/editing/ReplaceSelectionCommand.cpp b/Source/WebCore/editing/ReplaceSelectionCommand.cpp index 37d5782d3c839..d9002c9f7388e 100644 --- a/Source/WebCore/editing/ReplaceSelectionCommand.cpp +++ b/Source/WebCore/editing/ReplaceSelectionCommand.cpp @@ -725,9 +725,9 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert // Mutate using the CSSOM wrapper so we get the same event behavior as a script. if (isBlock(*element)) - element->cssomStyle().setPropertyInternal(CSSPropertyDisplay, "inline"_s, false); + element->cssomStyle().setPropertyInternal(CSSPropertyDisplay, "inline"_s, IsImportant::No); if (element->renderer() && element->renderer()->style().isFloating()) - element->cssomStyle().setPropertyInternal(CSSPropertyFloat, noneAtom(), false); + element->cssomStyle().setPropertyInternal(CSSPropertyFloat, noneAtom(), IsImportant::No); } } } diff --git a/Source/WebCore/html/AttachmentAssociatedElement.cpp b/Source/WebCore/html/AttachmentAssociatedElement.cpp index ab870f8faa573..763c26210aed8 100644 --- a/Source/WebCore/html/AttachmentAssociatedElement.cpp +++ b/Source/WebCore/html/AttachmentAssociatedElement.cpp @@ -41,7 +41,7 @@ void AttachmentAssociatedElement::setAttachmentElement(Refremove(); - attachment->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true); + attachment->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, IsImportant::Yes); asHTMLElement().ensureUserAgentShadowRoot().appendChild(WTFMove(attachment)); } diff --git a/Source/WebCore/html/ColorInputType.cpp b/Source/WebCore/html/ColorInputType.cpp index d6cad73f53828..71805feb683a8 100644 --- a/Source/WebCore/html/ColorInputType.cpp +++ b/Source/WebCore/html/ColorInputType.cpp @@ -277,7 +277,7 @@ void ColorInputType::updateColorSwatch() return; ASSERT(element()); - colorSwatch->setInlineStyleProperty(CSSPropertyBackgroundColor, element()->value(), false); + colorSwatch->setInlineStyleProperty(CSSPropertyBackgroundColor, element()->value()); } HTMLElement* ColorInputType::shadowColorSwatch() const diff --git a/Source/WebCore/html/TextFieldInputType.cpp b/Source/WebCore/html/TextFieldInputType.cpp index 3ca05ac7bde64..7bfa3f436a7a8 100644 --- a/Source/WebCore/html/TextFieldInputType.cpp +++ b/Source/WebCore/html/TextFieldInputType.cpp @@ -381,7 +381,7 @@ void TextFieldInputType::createShadowSubtree() capsLockIndicator->setUserAgentPart(UserAgentParts::webkitCapsLockIndicator()); bool shouldDrawCapsLockIndicator = this->shouldDrawCapsLockIndicator(); - capsLockIndicator->setInlineStyleProperty(CSSPropertyDisplay, shouldDrawCapsLockIndicator ? CSSValueBlock : CSSValueNone, true); + capsLockIndicator->setInlineStyleProperty(CSSPropertyDisplay, shouldDrawCapsLockIndicator ? CSSValueBlock : CSSValueNone, IsImportant::Yes); } updateAutoFillButton(); @@ -493,7 +493,7 @@ void TextFieldInputType::createDataListDropdownIndicator() m_dataListDropdownIndicator = DataListButtonElement::create(element()->document(), *this); m_container->appendChild(*m_dataListDropdownIndicator); m_dataListDropdownIndicator->setUserAgentPart(UserAgentParts::webkitListButton()); - m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true); + m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, IsImportant::Yes); } #endif // ENABLE(DATALIST_ELEMENT) @@ -799,7 +799,7 @@ void TextFieldInputType::capsLockStateMayHaveChanged() return; bool shouldDrawCapsLockIndicator = this->shouldDrawCapsLockIndicator(); - m_capsLockIndicator->setInlineStyleProperty(CSSPropertyDisplay, shouldDrawCapsLockIndicator ? CSSValueBlock : CSSValueNone, true); + m_capsLockIndicator->setInlineStyleProperty(CSSPropertyDisplay, shouldDrawCapsLockIndicator ? CSSValueBlock : CSSValueNone, IsImportant::Yes); } bool TextFieldInputType::shouldDrawAutoFillButton() const @@ -900,12 +900,12 @@ void TextFieldInputType::updateAutoFillButton() m_autoFillButton->setAttributeWithoutSynchronization(aria_labelAttr, AtomString { autoFillButtonTypeToAccessibilityLabel(autoFillButtonType) }); m_autoFillButton->setTextContent(autoFillButtonTypeToAutoFillButtonText(autoFillButtonType)); } - m_autoFillButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock, true); + m_autoFillButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock, IsImportant::Yes); return; } if (m_autoFillButton) - m_autoFillButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true); + m_autoFillButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, IsImportant::Yes); } #if ENABLE(DATALIST_ELEMENT) @@ -921,7 +921,7 @@ void TextFieldInputType::dataListMayHaveChanged() createDataListDropdownIndicator(); if (!element()) return; - m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, true); + m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, IsImportant::Yes); if (element()->list() && element()->focused()) displaySuggestions(DataListSuggestionActivationType::DataListMayHaveChanged); } diff --git a/Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp b/Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp index 24bca085f7273..3dd3bc099c302 100644 --- a/Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp +++ b/Source/WebCore/html/shadow/MediaControlTextTrackContainerElement.cpp @@ -291,7 +291,7 @@ void MediaControlTextTrackContainerElement::updateTextStrokeStyle() // FIXME: find a way to set this property in the stylesheet like the other user style preferences, see . if (document().page()->group().ensureCaptionPreferences().captionStrokeWidthForFont(m_fontSize, language, strokeWidth, important)) - setInlineStyleProperty(CSSPropertyStrokeWidth, strokeWidth, CSSUnitType::CSS_PX, important); + setInlineStyleProperty(CSSPropertyStrokeWidth, strokeWidth, CSSUnitType::CSS_PX, important ? IsImportant::Yes : IsImportant::No); } void MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded() diff --git a/Source/WebCore/html/shadow/TextPlaceholderElement.cpp b/Source/WebCore/html/shadow/TextPlaceholderElement.cpp index 5136e8098c1c4..a21741e87e19b 100644 --- a/Source/WebCore/html/shadow/TextPlaceholderElement.cpp +++ b/Source/WebCore/html/shadow/TextPlaceholderElement.cpp @@ -43,9 +43,9 @@ TextPlaceholderElement::TextPlaceholderElement(Document& document, const LayoutS : HTMLDivElement { HTMLNames::divTag, document } { // FIXME: Move to User Agent stylesheet. See . - setInlineStyleProperty(CSSPropertyDisplay, size.width() ? CSSValueInlineBlock : CSSValueBlock, false); - setInlineStyleProperty(CSSPropertyVerticalAlign, CSSValueTop, false); - setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden, true); + setInlineStyleProperty(CSSPropertyDisplay, size.width() ? CSSValueInlineBlock : CSSValueBlock); + setInlineStyleProperty(CSSPropertyVerticalAlign, CSSValueTop); + setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden, IsImportant::Yes); setInlineStyleProperty(CSSPropertyWidth, size.width(), CSSUnitType::CSS_PX); setInlineStyleProperty(CSSPropertyHeight, size.height(), CSSUnitType::CSS_PX); } diff --git a/Source/WebCore/html/track/VTTCue.cpp b/Source/WebCore/html/track/VTTCue.cpp index e30c1553cfc78..fd954260f65d6 100644 --- a/Source/WebCore/html/track/VTTCue.cpp +++ b/Source/WebCore/html/track/VTTCue.cpp @@ -207,7 +207,7 @@ void VTTCueBox::applyCSSProperties() // is not a true viewport, but it is a container, so they serve the same purpose. // the 'writing-mode' property must be set to writing-mode - setInlineStyleProperty(CSSPropertyWritingMode, cue->getCSSWritingMode(), false); + setInlineStyleProperty(CSSPropertyWritingMode, cue->getCSSWritingMode()); // the 'top' property must be set to top std::visit(WTF::makeVisitor([&] (double top) { @@ -256,7 +256,7 @@ void VTTCueBox::applyCSSProperties() // The font shorthand property on the (root) list of WebVTT Node Objects // must be set to 5vh sans-serif. [CSS-VALUES] // NOTE: We use 'cqh' rather than 'vh' as the video element is not a proper viewport. - setInlineStyleProperty(CSSPropertyFontSize, cue->fontSize(), CSSUnitType::CSS_CQMIN, cue->fontSizeIsImportant()); + setInlineStyleProperty(CSSPropertyFontSize, cue->fontSize(), CSSUnitType::CSS_CQMIN, cue->fontSizeIsImportant() ? IsImportant::Yes : IsImportant::No); if (!cue->snapToLines()) { setInlineStyleProperty(CSSPropertyWhiteSpaceCollapse, CSSValuePreserve); diff --git a/Source/WebCore/page/DragController.cpp b/Source/WebCore/page/DragController.cpp index 28bd5b342d9e9..05a0b8bbfbd95 100644 --- a/Source/WebCore/page/DragController.cpp +++ b/Source/WebCore/page/DragController.cpp @@ -591,7 +591,7 @@ bool DragController::concludeEditDrag(const DragData& dragData) if (!innerRange) return false; Ref style = MutableStyleProperties::create(); - style->setProperty(CSSPropertyColor, serializationForHTML(color), false); + style->setProperty(CSSPropertyColor, serializationForHTML(color)); if (!innerFrame->checkedEditor()->shouldApplyStyle(style, *innerRange)) return false; client().willPerformDragDestinationAction(DragDestinationAction::Edit, dragData); diff --git a/Source/WebCore/style/PropertyCascade.cpp b/Source/WebCore/style/PropertyCascade.cpp index d76f129f0f0b6..b8b9c8b84efdf 100644 --- a/Source/WebCore/style/PropertyCascade.cpp +++ b/Source/WebCore/style/PropertyCascade.cpp @@ -181,7 +181,7 @@ const PropertyCascade::Property* PropertyCascade::lastDeferredPropertyResolvingR return nullptr; } -bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool important) +bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, IsImportant important) { auto includePropertiesForRollback = [&] { if (m_rollbackScope && matchedProperties.styleScopeOrdinal > *m_rollbackScope) @@ -204,7 +204,7 @@ bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, Casca for (auto current : matchedProperties.properties.get()) { if (current.isImportant()) hasImportantProperties = true; - if (important != current.isImportant()) + if ((important == IsImportant::No && current.isImportant()) || (important == IsImportant::Yes && !current.isImportant())) continue; auto propertyID = current.id(); @@ -316,7 +316,7 @@ bool PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel) { bool hasImportant = false; for (auto& matchedDeclarations : declarationsForCascadeLevel(m_matchResult, cascadeLevel)) - hasImportant |= addMatch(matchedDeclarations, cascadeLevel, false); + hasImportant |= addMatch(matchedDeclarations, cascadeLevel, IsImportant::No); return hasImportant; } @@ -372,7 +372,7 @@ void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel) } for (auto& match : importantMatches) - addMatch(matchedDeclarations[match.index], cascadeLevel, true); + addMatch(matchedDeclarations[match.index], cascadeLevel, IsImportant::Yes); } void PropertyCascade::sortDeferredPropertyIDs() diff --git a/Source/WebCore/style/PropertyCascade.h b/Source/WebCore/style/PropertyCascade.h index c98345471b844..b7e06fd125540 100644 --- a/Source/WebCore/style/PropertyCascade.h +++ b/Source/WebCore/style/PropertyCascade.h @@ -91,7 +91,7 @@ class PropertyCascade { void buildCascade(); bool addNormalMatches(CascadeLevel); void addImportantMatches(CascadeLevel); - bool addMatch(const MatchedProperties&, CascadeLevel, bool important); + bool addMatch(const MatchedProperties&, CascadeLevel, IsImportant); bool shouldApplyAfterAnimation(const StyleProperties::PropertyReference&); void set(CSSPropertyID, CSSValue&, const MatchedProperties&, CascadeLevel); diff --git a/Source/WebCore/svg/properties/SVGAttributeAnimator.cpp b/Source/WebCore/svg/properties/SVGAttributeAnimator.cpp index 9d7d7beb82a60..e1ee21bacc19d 100644 --- a/Source/WebCore/svg/properties/SVGAttributeAnimator.cpp +++ b/Source/WebCore/svg/properties/SVGAttributeAnimator.cpp @@ -49,7 +49,7 @@ void SVGAttributeAnimator::applyAnimatedStylePropertyChange(SVGElement& element, ASSERT(!element.deletionHasBegun()); ASSERT(id != CSSPropertyInvalid); - if (!element.ensureAnimatedSMILStyleProperties().setProperty(id, value, false)) + if (!element.ensureAnimatedSMILStyleProperties().setProperty(id, value)) return; element.invalidateStyle(); }