Skip to content

Commit

Permalink
Adopt more smart pointers in mathml
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274388

Reviewed by Sihui Liu.

Adopt more smart pointers in mathml based on the
[alpha.webkit.UncountedLocalVarsChecker] warning.

* Source/WebCore/mathml/MathMLAnnotationElement.cpp:
(WebCore::MathMLAnnotationElement::attributeChanged):
* Source/WebCore/mathml/MathMLElement.cpp:
(WebCore::MathMLElement::defaultEventHandler):
* Source/WebCore/mathml/MathMLRowElement.cpp:
(WebCore::MathMLRowElement::childrenChanged):
* Source/WebCore/mathml/MathMLSelectElement.cpp:
(WebCore::MathMLSelectElement::MathMLSelectElement):
(WebCore::MathMLSelectElement::getSelectedActionChild):
(WebCore::MathMLSelectElement::getSelectedSemanticsChild):

Canonical link: https://commits.webkit.org/279070@main
  • Loading branch information
rwlbuis committed May 21, 2024
1 parent 828ba37 commit 71b00c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/mathml/MathMLAnnotationElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool MathMLAnnotationElement::childShouldCreateRenderer(const Node& child) const
void MathMLAnnotationElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason reason)
{
if (name == MathMLNames::srcAttr || name == MathMLNames::encodingAttr) {
auto* parent = parentElement();
RefPtr parent = parentElement();
if (is<MathMLElement>(parent) && parent->hasTagName(semanticsTag))
downcast<MathMLElement>(*parent).updateSelectedChild();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/mathml/MathMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ void MathMLElement::defaultEventHandler(Event& event)
if (MouseEvent::canTriggerActivationBehavior(event)) {
const auto& href = attributeWithoutSynchronization(hrefAttr);
event.setDefaultHandled();
if (auto* frame = document().frame())
frame->loader().changeLocation(document().completeURL(href), selfTargetFrameName(), &event, ReferrerPolicy::EmptyString, document().shouldOpenExternalURLsPolicyToPropagate());
if (RefPtr frame = document().frame())
frame->checkedLoader()->changeLocation(document().completeURL(href), selfTargetFrameName(), &event, ReferrerPolicy::EmptyString, document().shouldOpenExternalURLsPolicyToPropagate());
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/mathml/MathMLRowElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Ref<MathMLRowElement> MathMLRowElement::create(const QualifiedName& tagName, Doc

void MathMLRowElement::childrenChanged(const ChildChange& change)
{
for (auto child = firstChild(); child; child = child->nextSibling()) {
for (RefPtr child = firstChild(); child; child = child->nextSibling()) {
if (child->hasTagName(moTag))
static_cast<MathMLOperatorElement*>(child)->setOperatorFormDirty();
static_cast<MathMLOperatorElement*>(child.get())->setOperatorFormDirty();
}

MathMLPresentationElement::childrenChanged(change);
Expand Down
19 changes: 10 additions & 9 deletions Source/WebCore/mathml/MathMLSelectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ using namespace MathMLNames;

MathMLSelectElement::MathMLSelectElement(const QualifiedName& tagName, Document& document)
: MathMLRowElement(tagName, document)
, m_selectedChild(nullptr)
{
}

Expand Down Expand Up @@ -134,9 +133,9 @@ Element* MathMLSelectElement::getSelectedActionChild()
{
ASSERT(hasTagName(mactionTag));

auto* child = firstElementChild();
RefPtr child = firstElementChild();
if (!child)
return child;
return nullptr;

// The value of the actiontype attribute is case-sensitive.
auto& actiontype = attributeWithoutSynchronization(MathMLNames::actiontypeAttr);
Expand All @@ -148,17 +147,19 @@ Element* MathMLSelectElement::getSelectedActionChild()
{ }
} else {
// For the "toggle" action type or any unknown action type, we rely on the value of the selection attribute to determine the visible child.
getSelectedActionChildAndIndex(child);
Element* selectedChild;
getSelectedActionChildAndIndex(selectedChild);
child = selectedChild;
}

return child;
return child.get();
}

Element* MathMLSelectElement::getSelectedSemanticsChild()
{
ASSERT(hasTagName(semanticsTag));

auto* child = firstElementChild();
RefPtr child = firstElementChild();
if (!child)
return nullptr;

Expand All @@ -167,7 +168,7 @@ Element* MathMLSelectElement::getSelectedSemanticsChild()
child = child->nextElementSibling();
} else if (!downcast<MathMLElement>(*child).isSemanticAnnotation()) {
// The first child is a presentation MathML but not an annotation, so we can just display it.
return child;
return child.get();
}
// Otherwise, the first child is an <annotation> or <annotation-xml> element. This is invalid, but some people use this syntax so we take care of this case too and start the search from this first child.

Expand All @@ -180,7 +181,7 @@ Element* MathMLSelectElement::getSelectedSemanticsChild()
if (child->hasAttributeWithoutSynchronization(MathMLNames::srcAttr))
continue;
// Otherwise, we assume it is a text annotation that can always be displayed and we stop here.
return child;
return child.get();
}

if (child->hasTagName(MathMLNames::annotation_xmlTag)) {
Expand All @@ -190,7 +191,7 @@ Element* MathMLSelectElement::getSelectedSemanticsChild()
// If the <annotation-xml> element has an encoding attribute describing presentation MathML, SVG or HTML we assume the content can be displayed and we stop here.
auto& value = child->attributeWithoutSynchronization(MathMLNames::encodingAttr);
if (isMathMLEncoding(value) || isSVGEncoding(value) || isHTMLEncoding(value))
return child;
return child.get();
}
}

Expand Down

0 comments on commit 71b00c9

Please sign in to comment.