LibWeb: Replace templated retarget function with a regular one

The templating is not necessary anywhere and was effectively just a cast
This commit is contained in:
circl 2024-07-21 15:06:05 +02:00 committed by Andrew Kaster
commit 37f93e4be1
Notes: github-actions[bot] 2024-07-21 22:02:25 +00:00
5 changed files with 49 additions and 39 deletions

View file

@ -7,42 +7,10 @@
#pragma once
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/EventTarget.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#retarget
inline EventTarget* retarget_impl(EventTarget* a, EventTarget* b)
{
// To retarget an object A against an object B, repeat these steps until they return an object:
for (;;) {
// 1. If one of the following is true then return A.
// - A is not a node
if (!is<Node>(a))
return a;
// - As root is not a shadow root
auto* a_node = verify_cast<Node>(a);
auto& a_root = a_node->root();
if (!is<ShadowRoot>(a_root))
return a;
// - B is a node and As root is a shadow-including inclusive ancestor of B
if (is<Node>(b) && a_root.is_shadow_including_inclusive_ancestor_of(verify_cast<Node>(*b)))
return a;
// 2. Set A to As roots host.
auto& a_shadow_root = verify_cast<ShadowRoot>(a_root);
a = a_shadow_root.host();
}
}
// https://dom.spec.whatwg.org/#retarget
template<typename T>
T* retarget(T* a, T* b)
{
return static_cast<T*>(retarget_impl(a, b));
}
EventTarget* retarget(EventTarget* a, EventTarget* b);
}