Skip to content

Commit

Permalink
More dynamicDowncast<Element> adoption in markup and LocalDOMWindow
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268226

Reviewed by Chris Dumez.

* Source/WebCore/editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::traverseNodesForSerialization):
(WebCore::styleFromMatchedRulesAndInlineDecl):
* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::collectMatchingElementsInFlatTree):
(WebCore::LocalDOMWindow::matchingElementInFlatTree):

Canonical link: https://commits.webkit.org/273623@main
  • Loading branch information
annevk committed Jan 28, 2024
1 parent 952a84d commit 43145a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
11 changes: 6 additions & 5 deletions Source/WebCore/editing/markup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ RefPtr<Node> StyledMarkupAccumulator::traverseNodesForSerialization(Node& startN
return false;
}

bool isDisplayContents = is<Element>(node) && downcast<Element>(node).hasDisplayContents();
RefPtr element = dynamicDowncast<Element>(node);
bool isDisplayContents = element && element->hasDisplayContents();
if (!node.renderer() && !isDisplayContents && !enclosingElementWithTag(firstPositionInOrBeforeNode(&node), selectTag))
return false;

Expand Down Expand Up @@ -916,12 +917,12 @@ static bool needInterchangeNewlineAfter(const VisiblePosition& v)

static RefPtr<EditingStyle> styleFromMatchedRulesAndInlineDecl(Node& node)
{
if (!is<HTMLElement>(node))
RefPtr element = dynamicDowncast<HTMLElement>(node);
if (!element)
return nullptr;

Ref element = downcast<HTMLElement>(node);
auto style = EditingStyle::create(element->inlineStyle());
style->mergeStyleFromRules(element);
Ref style = EditingStyle::create(element->inlineStyle());
style->mergeStyleFromRules(*element);
return style;
}

Expand Down
18 changes: 10 additions & 8 deletions Source/WebCore/page/LocalDOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,16 @@ ExceptionOr<Ref<NodeList>> LocalDOMWindow::collectMatchingElementsInFlatTree(Nod
if (queryOrException.hasException())
return queryOrException.releaseException();

if (!is<ContainerNode>(scope))
RefPtr scopeContainer = dynamicDowncast<ContainerNode>(scope);
if (!scopeContainer)
return Ref<NodeList> { StaticElementList::create() };

SelectorQuery& query = queryOrException.releaseReturnValue();

Vector<Ref<Element>> result;
for (auto& node : composedTreeDescendants(downcast<ContainerNode>(scope))) {
if (is<Element>(node) && query.matches(downcast<Element>(node)) && !node.isInUserAgentShadowTree())
result.append(downcast<Element>(node));
for (auto& node : composedTreeDescendants(*scopeContainer)) {
if (RefPtr element = dynamicDowncast<Element>(node); element && query.matches(*element) && !node.isInUserAgentShadowTree())
result.append(element.releaseNonNull());
}

return Ref<NodeList> { StaticElementList::create(WTFMove(result)) };
Expand All @@ -652,14 +653,15 @@ ExceptionOr<RefPtr<Element>> LocalDOMWindow::matchingElementInFlatTree(Node& sco
if (queryOrException.hasException())
return queryOrException.releaseException();

if (!is<ContainerNode>(scope))
RefPtr scopeContainer = dynamicDowncast<ContainerNode>(scope);
if (!scopeContainer)
return RefPtr<Element> { nullptr };

SelectorQuery& query = queryOrException.releaseReturnValue();

for (auto& node : composedTreeDescendants(downcast<ContainerNode>(scope))) {
if (is<Element>(node) && query.matches(downcast<Element>(node)) && !node.isInUserAgentShadowTree())
return &downcast<Element>(node);
for (auto& node : composedTreeDescendants(*scopeContainer)) {
if (RefPtr element = dynamicDowncast<Element>(node); element && query.matches(*element) && !node.isInUserAgentShadowTree())
return element;
}

return RefPtr<Element> { nullptr };
Expand Down

0 comments on commit 43145a2

Please sign in to comment.