Skip to content

Commit

Permalink
Adopt the new NodeName enumeration more broadly in attributeChanged()…
Browse files Browse the repository at this point in the history
… overrides

https://bugs.webkit.org/show_bug.cgi?id=255466

Reviewed by Darin Adler.

Adopt the new NodeName enumeration more broadly in attributeChanged() overrides.
Switch statements are more efficient when dealing with a lot of attribute names.
It also results in nicer code.

* Source/WebCore/html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::attributeChanged):
* Source/WebCore/html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::ensureModernShadowTree):
(WebCore::HTMLAttachmentElement::setFile):
(WebCore::HTMLAttachmentElement::attributeChanged):
(WebCore::HTMLAttachmentElement::attachmentSubtitle const):
(WebCore::HTMLAttachmentElement::updateAttributes):
(WebCore::subtitleAttr): Deleted.
(WebCore::saveAttr): Deleted.
* Source/WebCore/html/HTMLAttributeNames.in:
* Source/WebCore/html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::attributeChanged):
* Source/WebCore/html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::attributeChanged):
* Source/WebCore/html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::attributeChanged):
* Source/WebCore/html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::attributeChanged):
* Source/WebCore/html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::attributeChanged):
* Source/WebCore/html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::attributeChanged):
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::attributeChanged):
* Source/WebCore/html/HTMLMetaElement.cpp:
(WebCore::HTMLMetaElement::attributeChanged):
* Source/WebCore/html/HTMLMeterElement.cpp:
(WebCore::HTMLMeterElement::attributeChanged):
* Source/WebCore/html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::attributeChanged):
* Source/WebCore/html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::attributeChanged):
* Source/WebCore/html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::attributeChanged):
* Source/WebCore/html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::attributeChanged):
* Source/WebCore/html/NumberInputType.cpp:
(WebCore::NumberInputType::attributeChanged):
* Source/WebCore/html/RangeInputType.cpp:
(WebCore::RangeInputType::attributeChanged):
* Source/WebCore/mathml/MathMLElement.cpp:
(WebCore::MathMLElement::attributeChanged):
* Source/WebCore/mathml/MathMLFractionElement.cpp:
(WebCore::MathMLFractionElement::attributeChanged):
* Source/WebCore/mathml/MathMLMathElement.cpp:
(WebCore::MathMLMathElement::attributeChanged):
* Source/WebCore/mathml/MathMLOperatorElement.cpp:
(WebCore::attributeNameToPropertyFlag):
(WebCore::MathMLOperatorElement::attributeChanged):
* Source/WebCore/mathml/MathMLPaddedElement.cpp:
(WebCore::MathMLPaddedElement::attributeChanged):
* Source/WebCore/mathml/MathMLPresentationElement.cpp:
(WebCore::MathMLPresentationElement::attributeChanged):
* Source/WebCore/mathml/MathMLSpaceElement.cpp:
(WebCore::MathMLSpaceElement::attributeChanged):
* Source/WebCore/svg/SVGAnimationElement.cpp:
(WebCore::SVGAnimationElement::attributeChanged):
* Source/WebCore/svg/SVGCircleElement.cpp:
(WebCore::SVGCircleElement::attributeChanged):
* Source/WebCore/svg/SVGComponentTransferFunctionElement.cpp:
(WebCore::SVGComponentTransferFunctionElement::attributeChanged):
* Source/WebCore/svg/SVGElement.cpp:
(WebCore::SVGElement::attributeChanged):
* Source/WebCore/svg/SVGEllipseElement.cpp:
(WebCore::SVGEllipseElement::attributeChanged):
* Source/WebCore/svg/SVGFEBlendElement.cpp:
(WebCore::SVGFEBlendElement::attributeChanged):
* Source/WebCore/svg/SVGFEColorMatrixElement.cpp:
(WebCore::SVGFEColorMatrixElement::attributeChanged):
* Source/WebCore/svg/SVGFECompositeElement.cpp:
(WebCore::SVGFECompositeElement::attributeChanged):
(WebCore::SVGFECompositeElement::setFilterEffectAttribute): Deleted.
(WebCore::SVGFECompositeElement::svgAttributeChanged): Deleted.
(WebCore::SVGFECompositeElement::createFilterEffect const): Deleted.
* Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp:
(WebCore::SVGFEConvolveMatrixElement::attributeChanged):
* Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp:
(WebCore::SVGFEDiffuseLightingElement::attributeChanged):
* Source/WebCore/svg/SVGFEDisplacementMapElement.cpp:
(WebCore::SVGFEDisplacementMapElement::attributeChanged):
* Source/WebCore/svg/SVGFEDropShadowElement.cpp:
(WebCore::SVGFEDropShadowElement::attributeChanged):
* Source/WebCore/svg/SVGFEGaussianBlurElement.cpp:
(WebCore::SVGFEGaussianBlurElement::attributeChanged):
* Source/WebCore/svg/SVGFELightElement.cpp:
(WebCore::SVGFELightElement::attributeChanged):
* Source/WebCore/svg/SVGFEMorphologyElement.cpp:
(WebCore::SVGFEMorphologyElement::attributeChanged):
(WebCore::SVGFEMorphologyElement::setFilterEffectAttribute): Deleted.
(WebCore::SVGFEMorphologyElement::svgAttributeChanged): Deleted.
(WebCore::SVGFEMorphologyElement::isIdentity const): Deleted.
(WebCore::SVGFEMorphologyElement::outsets const): Deleted.
(WebCore::SVGFEMorphologyElement::createFilterEffect const): Deleted.
* Source/WebCore/svg/SVGFEOffsetElement.cpp:
(WebCore::SVGFEOffsetElement::attributeChanged):
* Source/WebCore/svg/SVGFESpecularLightingElement.cpp:
(WebCore::SVGFESpecularLightingElement::attributeChanged):
* Source/WebCore/svg/SVGFETurbulenceElement.cpp:
(WebCore::SVGFETurbulenceElement::attributeChanged):
* Source/WebCore/svg/SVGFilterElement.cpp:
(WebCore::SVGFilterElement::attributeChanged):
* Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp:
(WebCore::SVGFilterPrimitiveStandardAttributes::attributeChanged):
* Source/WebCore/svg/SVGForeignObjectElement.cpp:
(WebCore::SVGForeignObjectElement::attributeChanged):
* Source/WebCore/svg/SVGGlyphRefElement.cpp:
(WebCore::SVGGlyphRefElement::attributeChanged):
* Source/WebCore/svg/SVGGradientElement.cpp:
(WebCore::SVGGradientElement::attributeChanged):
* Source/WebCore/svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::attributeChanged):
* Source/WebCore/svg/SVGLineElement.cpp:
(WebCore::SVGLineElement::attributeChanged):
* Source/WebCore/svg/SVGLinearGradientElement.cpp:
(WebCore::SVGLinearGradientElement::attributeChanged):
* Source/WebCore/svg/SVGMarkerElement.cpp:
(WebCore::SVGMarkerElement::attributeChanged):
* Source/WebCore/svg/SVGMaskElement.cpp:
(WebCore::SVGMaskElement::attributeChanged):
* Source/WebCore/svg/SVGPatternElement.cpp:
(WebCore::SVGPatternElement::attributeChanged):
* Source/WebCore/svg/SVGRadialGradientElement.cpp:
(WebCore::SVGRadialGradientElement::attributeChanged):
* Source/WebCore/svg/SVGRectElement.cpp:
(WebCore::SVGRectElement::attributeChanged):
* Source/WebCore/svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::attributeChanged):
* Source/WebCore/svg/SVGStyleElement.cpp:
(WebCore::SVGStyleElement::attributeChanged):
* Source/WebCore/svg/SVGTextPathElement.cpp:
(WebCore::SVGTextPathElement::attributeChanged):
* Source/WebCore/svg/SVGTextPositioningElement.cpp:
(WebCore::SVGTextPositioningElement::attributeChanged):
* Source/WebCore/svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::attributeChanged):
* Source/WebCore/svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::attributeChanged):

Canonical link: https://commits.webkit.org/262999@main
  • Loading branch information
cdumez committed Apr 15, 2023
1 parent c5b51db commit 0b09da9
Show file tree
Hide file tree
Showing 62 changed files with 945 additions and 683 deletions.
15 changes: 11 additions & 4 deletions Source/WebCore/html/HTMLAreaElement.cpp
Expand Up @@ -29,6 +29,7 @@
#include "HTMLParserIdioms.h"
#include "HitTestResult.h"
#include "LocalFrame.h"
#include "NodeName.h"
#include "Path.h"
#include "RenderImage.h"
#include "RenderView.h"
Expand All @@ -55,7 +56,8 @@ Ref<HTMLAreaElement> HTMLAreaElement::create(const QualifiedName& tagName, Docum

void HTMLAreaElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason attributeModificationReason)
{
if (name == shapeAttr) {
switch (name.nodeName()) {
case AttributeNames::shapeAttr:
if (equalLettersIgnoringASCIICase(newValue, "default"_s))
m_shape = Default;
else if (equalLettersIgnoringASCIICase(newValue, "circle"_s) || equalLettersIgnoringASCIICase(newValue, "circ"_s))
Expand All @@ -67,13 +69,18 @@ void HTMLAreaElement::attributeChanged(const QualifiedName& name, const AtomStri
m_shape = Rect;
}
invalidateCachedRegion();
} else if (name == coordsAttr) {
break;
case AttributeNames::coordsAttr:
m_coords = parseHTMLListOfOfFloatingPointNumberValues(newValue.string());
invalidateCachedRegion();
} else if (name == altAttr) {
break;
case AttributeNames::altAttr:
// Do nothing.
} else
break;
default:
HTMLAnchorElement::attributeChanged(name, oldValue, newValue, attributeModificationReason);
break;
}
}

void HTMLAreaElement::invalidateCachedRegion()
Expand Down
70 changes: 40 additions & 30 deletions Source/WebCore/html/HTMLAttachmentElement.cpp
Expand Up @@ -46,6 +46,7 @@
#include "LocalFrame.h"
#include "MIMETypeRegistry.h"
#include "MouseEvent.h"
#include "NodeName.h"
#include "RenderAttachment.h"
#include "ShadowRoot.h"
#include "SharedBuffer.h"
Expand Down Expand Up @@ -174,22 +175,12 @@ static const AtomString& attachmentSaveIconIdentifier()
return identifier;
}

static QualifiedName subtitleAttr()
{
return QualifiedName { nullAtom(), "subtitle"_s, nullAtom() };
}

static const AtomString& saveAtom()
{
static MainThreadNeverDestroyed<const AtomString> identifier("save"_s);
return identifier;
}

static QualifiedName saveAttr()
{
return QualifiedName { nullAtom(), saveAtom(), nullAtom() };
}

template <typename ElementType>
static Ref<ElementType> createContainedElement(HTMLElement& container, const AtomString& id, String&& textContent = { })
{
Expand Down Expand Up @@ -228,7 +219,7 @@ void HTMLAttachmentElement::ensureModernShadowTree(ShadowRoot& root)
};
copyAttribute(actionAttr);
copyAttribute(progressAttr);
copyAttribute(subtitleAttr());
copyAttribute(subtitleAttr);
copyAttribute(titleAttr);
copyAttribute(typeAttr);
m_innerLegacyAttachment->m_file = m_file;
Expand All @@ -253,7 +244,7 @@ void HTMLAttachmentElement::ensureModernShadowTree(ShadowRoot& root)

m_subtitleElement = createContainedElement<HTMLDivElement>(*m_informationBlock, attachmentSubtitleIdentifier(), String { attachmentSubtitleForDisplay() });

updateSaveButton(!attributeWithoutSynchronization(saveAttr()).isNull());
updateSaveButton(!attributeWithoutSynchronization(saveAttr).isNull());
}

class AttachmentSaveEventListener final : public EventListener {
Expand Down Expand Up @@ -402,11 +393,11 @@ void HTMLAttachmentElement::setFile(RefPtr<File>&& file, UpdateDisplayAttributes
if (updateAttributes == UpdateDisplayAttributes::Yes) {
if (m_file) {
setAttributeWithoutSynchronization(HTMLNames::titleAttr, AtomString { m_file->name() });
setAttributeWithoutSynchronization(subtitleAttr(), PAL::fileSizeDescription(m_file->size()));
setAttributeWithoutSynchronization(subtitleAttr, PAL::fileSizeDescription(m_file->size()));
setAttributeWithoutSynchronization(HTMLNames::typeAttr, AtomString { m_file->type() });
} else {
removeAttribute(HTMLNames::titleAttr);
removeAttribute(subtitleAttr());
removeAttribute(HTMLNames::subtitleAttr);
removeAttribute(HTMLNames::typeAttr);
}
}
Expand Down Expand Up @@ -457,36 +448,55 @@ RefPtr<HTMLImageElement> HTMLAttachmentElement::enclosingImageElement() const

void HTMLAttachmentElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason attributeModificationReason)
{
if (name == actionAttr || name == subtitleAttr() || name == titleAttr || name == typeAttr) {
switch (name.nodeName()) {
case AttributeNames::actionAttr:
case AttributeNames::subtitleAttr:
case AttributeNames::titleAttr:
case AttributeNames::typeAttr:
if (m_innerLegacyAttachment)
m_innerLegacyAttachment->setAttributeWithoutSynchronization(name, newValue);
invalidateRendering();
} else if (name == progressAttr && m_implementation == Implementation::Legacy) {
invalidateRendering();
break;
case AttributeNames::progressAttr:
if (m_implementation == Implementation::Legacy)
invalidateRendering();
break;
default:
break;
}

HTMLElement::attributeChanged(name, oldValue, newValue, attributeModificationReason);

if (name == actionAttr) {
switch (name.nodeName()) {
case AttributeNames::actionAttr:
if (m_actionTextElement)
m_actionTextElement->setTextContent(String(newValue.string()));
} else if (name == titleAttr) {
break;
case AttributeNames::titleAttr:
if (m_titleElement)
m_titleElement->setTextContent(String(newValue.string()));
} else if (name == subtitleAttr()) {
break;
case AttributeNames::subtitleAttr:
if (m_subtitleElement)
m_subtitleElement->setTextContent(String(newValue.string()));
} else if (name == progressAttr)
break;
case AttributeNames::progressAttr:
updateProgress(newValue);
else if (name == saveAttr())
break;
case AttributeNames::saveAttr:
updateSaveButton(!newValue.isNull());

break;
#if ENABLE(SERVICE_CONTROLS)
if (name == typeAttr && attachmentType() == "application/pdf"_s) {
setImageMenuEnabled(true);
ImageControlsMac::updateImageControls(*this);
}
case AttributeNames::typeAttr:
if (attachmentType() == "application/pdf"_s) {
setImageMenuEnabled(true);
ImageControlsMac::updateImageControls(*this);
}
break;
#endif
default:
break;
}
}

String HTMLAttachmentElement::attachmentTitle() const
Expand All @@ -499,7 +509,7 @@ String HTMLAttachmentElement::attachmentTitle() const

const AtomString& HTMLAttachmentElement::attachmentSubtitle() const
{
return attributeWithoutSynchronization(subtitleAttr());
return attributeWithoutSynchronization(subtitleAttr);
}

const AtomString& HTMLAttachmentElement::attachmentActionForDisplay() const
Expand Down Expand Up @@ -565,9 +575,9 @@ void HTMLAttachmentElement::updateAttributes(std::optional<uint64_t>&& newFileSi
removeAttribute(HTMLNames::typeAttr);

if (newFileSize)
setAttributeWithoutSynchronization(subtitleAttr(), PAL::fileSizeDescription(*newFileSize));
setAttributeWithoutSynchronization(subtitleAttr, PAL::fileSizeDescription(*newFileSize));
else
removeAttribute(subtitleAttr());
removeAttribute(subtitleAttr);

invalidateRendering();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/html/HTMLAttributeNames.in
Expand Up @@ -385,6 +385,7 @@ rows
rowspan
rules
sandbox
save
scheme
scope
scoped
Expand All @@ -411,6 +412,7 @@ standby
start
step
style
subtitle
summary
tabindex
tableborder
Expand Down
52 changes: 26 additions & 26 deletions Source/WebCore/html/HTMLBodyElement.cpp
Expand Up @@ -133,38 +133,38 @@ const AtomString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const

void HTMLBodyElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason attributeModificationReason)
{
if (name == vlinkAttr || name == alinkAttr || name == linkAttr) {
auto parsedColor = parseLegacyColorValue(newValue);
if (name == linkAttr) {
if (parsedColor)
document().setLinkColor(*parsedColor);
else
document().resetLinkColor();
} else if (name == vlinkAttr) {
if (parsedColor)
document().setVisitedLinkColor(*parsedColor);
else
document().resetVisitedLinkColor();
} else {
ASSERT(name == alinkAttr);
if (parsedColor)
document().setActiveLinkColor(*parsedColor);
else
document().resetActiveLinkColor();
}
switch (name.nodeName()) {
case AttributeNames::vlinkAttr:
if (auto parsedColor = parseLegacyColorValue(newValue))
document().setVisitedLinkColor(*parsedColor);
else
document().resetVisitedLinkColor();
invalidateStyleForSubtree();
return;
}

// FIXME: Emit "selectionchange" event at <input> / <textarea> elements and remove this special-case.
// https://bugs.webkit.org/show_bug.cgi?id=234348
if (name == onselectionchangeAttr) {
case AttributeNames::alinkAttr:
if (auto parsedColor = parseLegacyColorValue(newValue))
document().setActiveLinkColor(*parsedColor);
else
document().resetActiveLinkColor();
invalidateStyleForSubtree();
return;
case AttributeNames::linkAttr:
if (auto parsedColor = parseLegacyColorValue(newValue))
document().setLinkColor(*parsedColor);
else
document().resetLinkColor();
invalidateStyleForSubtree();
return;
case AttributeNames::onselectionchangeAttr:
// FIXME: Emit "selectionchange" event at <input> / <textarea> elements and remove this special-case.
// https://bugs.webkit.org/show_bug.cgi?id=234348
document().setAttributeEventListener(eventNames().selectionchangeEvent, name, newValue, mainThreadNormalWorld());
return;
default:
break;
}

auto& eventName = eventNameForWindowEventHandlerAttribute(name);
if (!eventName.isNull()) {
if (auto& eventName = eventNameForWindowEventHandlerAttribute(name); !eventName.isNull()) {
document().setWindowAttributeEventListener(eventName, name, newValue, mainThreadNormalWorld());
return;
}
Expand Down
13 changes: 10 additions & 3 deletions Source/WebCore/html/HTMLEmbedElement.cpp
Expand Up @@ -33,6 +33,7 @@
#include "HTMLParserIdioms.h"
#include "LocalFrame.h"
#include "LocalFrameView.h"
#include "NodeName.h"
#include "PluginDocument.h"
#include "RenderEmbeddedObject.h"
#include "RenderWidget.h"
Expand Down Expand Up @@ -98,23 +99,29 @@ static bool hasTypeOrSrc(const HTMLEmbedElement& embed)
void HTMLEmbedElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason attributeModificationReason)
{
HTMLPlugInImageElement::attributeChanged(name, oldValue, newValue, attributeModificationReason);
if (name == typeAttr) {
switch (name.nodeName()) {
case AttributeNames::typeAttr:
m_serviceType = newValue.string().left(newValue.find(';')).convertToASCIILowercase();
// FIXME: The only difference between this and HTMLObjectElement's corresponding
// code is that HTMLObjectElement does setNeedsWidgetUpdate(true). Consider moving
// this up to the HTMLPlugInImageElement to be shared.
if (renderer() && !hasTypeOrSrc(*this))
invalidateStyle();
} else if (name == codeAttr) {
break;
case AttributeNames::codeAttr:
m_url = stripLeadingAndTrailingHTMLSpaces(newValue);
// FIXME: Why no call to updateImageLoaderWithNewURLSoon?
// FIXME: If both code and src attributes are specified, last one parsed/changed wins. That can't be right!
} else if (name == srcAttr) {
break;
case AttributeNames::srcAttr:
m_url = stripLeadingAndTrailingHTMLSpaces(newValue);
updateImageLoaderWithNewURLSoon();
if (renderer() && !hasTypeOrSrc(*this))
invalidateStyle();
// FIXME: If both code and src attributes are specified, last one parsed/changed wins. That can't be right!
break;
default:
break;
}
}

Expand Down

0 comments on commit 0b09da9

Please sign in to comment.