/* * Copyright (c) 2020, Luke Wilde * Copyright (c) 2024, circl * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Web::DOM { // https://dom.spec.whatwg.org/#retarget EventTarget* retarget(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(a)) return a; // - A’s root is not a shadow root auto* a_node = as(a); auto& a_root = a_node->root(); if (!is(a_root)) return a; // - B is a node and A’s root is a shadow-including inclusive ancestor of B if (is(b) && a_root.is_shadow_including_inclusive_ancestor_of(as(*b))) return a; // 2. Set A to A’s root’s host. auto& a_shadow_root = as(a_root); a = a_shadow_root.host(); } } }