Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract StyledElementInlineStylePropertyMap from StyledElement.cpp an…
…d to its own file https://bugs.webkit.org/show_bug.cgi?id=248620 Reviewed by Antoine Quint. Extract StyledElementInlineStylePropertyMap from StyledElement.cpp and to its own file. Also rename it to InlineStylePropertyMap for simplicity. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/css/typedom/InlineStylePropertyMap.cpp: Added. (WebCore::InlineStylePropertyMap::create): (WebCore::InlineStylePropertyMap::InlineStylePropertyMap): (WebCore::InlineStylePropertyMap::propertyValue const): (WebCore::InlineStylePropertyMap::customPropertyValue const): (WebCore::InlineStylePropertyMap::size const): (WebCore::InlineStylePropertyMap::entries const): (WebCore::InlineStylePropertyMap::removeProperty): (WebCore::InlineStylePropertyMap::setShorthandProperty): (WebCore::InlineStylePropertyMap::setProperty): (WebCore::InlineStylePropertyMap::setCustomProperty): (WebCore::InlineStylePropertyMap::removeCustomProperty): (WebCore::InlineStylePropertyMap::clear): (WebCore::InlineStylePropertyMap::clearElement): * Source/WebCore/css/typedom/InlineStylePropertyMap.h: Added. * Source/WebCore/dom/StyledElement.cpp: (WebCore::StyledElement::ensureAttributeStyleMap): (): Deleted. Canonical link: https://commits.webkit.org/257292@main
- Loading branch information
Showing
5 changed files
with
206 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright (C) 2021-2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "InlineStylePropertyMap.h" | ||
|
||
#include "StyledElement.h" | ||
|
||
namespace WebCore { | ||
|
||
Ref<InlineStylePropertyMap> InlineStylePropertyMap::create(StyledElement& element) | ||
{ | ||
return adoptRef(*new InlineStylePropertyMap(element)); | ||
} | ||
|
||
InlineStylePropertyMap::InlineStylePropertyMap(StyledElement& element) | ||
: m_element(&element) | ||
{ | ||
} | ||
|
||
RefPtr<CSSValue> InlineStylePropertyMap::propertyValue(CSSPropertyID propertyID) const | ||
{ | ||
if (auto* inlineStyle = m_element ? m_element->inlineStyle() : nullptr) | ||
return inlineStyle->getPropertyCSSValue(propertyID); | ||
return nullptr; | ||
} | ||
|
||
String InlineStylePropertyMap::shorthandPropertySerialization(CSSPropertyID propertyID) const | ||
{ | ||
if (auto* inlineStyle = m_element ? m_element->inlineStyle() : nullptr) | ||
return inlineStyle->getPropertyValue(propertyID); | ||
return String(); | ||
} | ||
|
||
RefPtr<CSSValue> InlineStylePropertyMap::customPropertyValue(const AtomString& property) const | ||
{ | ||
if (auto* inlineStyle = m_element ? m_element->inlineStyle() : nullptr) | ||
return inlineStyle->getCustomPropertyCSSValue(property.string()); | ||
return nullptr; | ||
} | ||
|
||
unsigned InlineStylePropertyMap::size() const | ||
{ | ||
auto* inlineStyle = m_element ? m_element->inlineStyle() : nullptr; | ||
return inlineStyle ? inlineStyle->propertyCount() : 0; | ||
} | ||
|
||
auto InlineStylePropertyMap::entries(ScriptExecutionContext* context) const -> Vector<StylePropertyMapEntry> | ||
{ | ||
if (!m_element || !context) | ||
return { }; | ||
|
||
auto& document = downcast<Document>(*context); | ||
Vector<StylePropertyMapEntry> result; | ||
auto* inlineStyle = m_element->inlineStyle(); | ||
if (!inlineStyle) | ||
return { }; | ||
|
||
result.reserveInitialCapacity(inlineStyle->propertyCount()); | ||
for (unsigned i = 0; i < inlineStyle->propertyCount(); ++i) { | ||
auto propertyReference = inlineStyle->propertyAt(i); | ||
result.uncheckedAppend(makeKeyValuePair(propertyReference.cssName(), reifyValueToVector(RefPtr<CSSValue> { propertyReference.value() }, document))); | ||
} | ||
return result; | ||
} | ||
|
||
void InlineStylePropertyMap::removeProperty(CSSPropertyID propertyID) | ||
{ | ||
if (m_element) | ||
m_element->removeInlineStyleProperty(propertyID); | ||
} | ||
|
||
bool InlineStylePropertyMap::setShorthandProperty(CSSPropertyID propertyID, const String& value) | ||
{ | ||
if (!m_element) | ||
return false; | ||
bool didFailParsing = false; | ||
bool important = false; | ||
m_element->setInlineStyleProperty(propertyID, value, important, &didFailParsing); | ||
return !didFailParsing; | ||
} | ||
|
||
bool InlineStylePropertyMap::setProperty(CSSPropertyID propertyID, Ref<CSSValue>&& value) | ||
{ | ||
if (!m_element) | ||
return false; | ||
bool didFailParsing = false; | ||
bool important = false; | ||
m_element->setInlineStyleProperty(propertyID, value->cssText(), important, &didFailParsing); | ||
return !didFailParsing; | ||
} | ||
|
||
bool InlineStylePropertyMap::setCustomProperty(Document&, const AtomString& property, Ref<CSSVariableReferenceValue>&& value) | ||
{ | ||
if (!m_element) | ||
return false; | ||
|
||
auto customPropertyValue = CSSCustomPropertyValue::createUnresolved(property, WTFMove(value)); | ||
m_element->setInlineStyleCustomProperty(WTFMove(customPropertyValue)); | ||
return true; | ||
} | ||
|
||
void InlineStylePropertyMap::removeCustomProperty(const AtomString& property) | ||
{ | ||
if (m_element) | ||
m_element->removeInlineStyleCustomProperty(property); | ||
} | ||
|
||
void InlineStylePropertyMap::clear() | ||
{ | ||
if (m_element) | ||
m_element->removeAllInlineStyleProperties(); | ||
} | ||
|
||
void InlineStylePropertyMap::clearElement() | ||
{ | ||
m_element = nullptr; | ||
} | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2021-2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "StylePropertyMap.h" | ||
|
||
namespace WebCore { | ||
|
||
class InlineStylePropertyMap final : public StylePropertyMap { | ||
public: | ||
static Ref<InlineStylePropertyMap> create(StyledElement&); | ||
|
||
RefPtr<CSSValue> propertyValue(CSSPropertyID) const final; | ||
String shorthandPropertySerialization(CSSPropertyID) const final; | ||
RefPtr<CSSValue> customPropertyValue(const AtomString& property) const final; | ||
unsigned size() const final; | ||
Vector<StylePropertyMapEntry> entries(ScriptExecutionContext*) const final; | ||
void removeProperty(CSSPropertyID) final; | ||
bool setShorthandProperty(CSSPropertyID, const String& value) final; | ||
bool setProperty(CSSPropertyID, Ref<CSSValue>&&) final; | ||
bool setCustomProperty(Document&, const AtomString& property, Ref<CSSVariableReferenceValue>&&) final; | ||
void removeCustomProperty(const AtomString& property) final; | ||
void clear() final; | ||
void clearElement() final; | ||
|
||
private: | ||
explicit InlineStylePropertyMap(StyledElement&); | ||
|
||
StyledElement* m_element; | ||
}; | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters