mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb/HTML: Update cloning steps to current spec algorithms
Reflects the changes in https://github.com/whatwg/html/pull/10859 I've also added missing calls to the Base::cloned() method, and modified a couple of spec links to point to the multipage version. I took the liberty to fix a spec typo, and submitted a PR for it: https://github.com/whatwg/html/pull/10892
This commit is contained in:
parent
172d5f6987
commit
2e96ba11e4
Notes:
github-actions[bot]
2025-01-05 21:12:56 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/2e96ba11e43 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3150 Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 26 additions and 18 deletions
|
@ -1660,9 +1660,11 @@ void HTMLInputElement::apply_presentational_hints(GC::Ref<CSS::CascadedPropertie
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-input-element%3Aconcept-node-clone-ext
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::cloned(DOM::Node& copy, bool)
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::cloned(DOM::Node& copy, bool subtree)
|
||||
{
|
||||
// The cloning steps for input elements must propagate the value, dirty value flag, checkedness, and dirty checkedness flag from the node being cloned to the copy.
|
||||
TRY(Base::cloned(copy, subtree));
|
||||
|
||||
// The cloning steps for input elements given node, copy, and subtree are to propagate the value, dirty value flag, checkedness, and dirty checkedness flag from node to copy.
|
||||
auto& input_clone = verify_cast<HTMLInputElement>(copy);
|
||||
input_clone.m_value = m_value;
|
||||
input_clone.m_dirty_value = m_dirty_value;
|
||||
|
|
|
@ -56,7 +56,7 @@ void HTMLOrSVGElement<ElementBase>::blur()
|
|||
// User agents may selectively or uniformly ignore calls to this method for usability reasons.
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
|
||||
template<typename ElementBase>
|
||||
void HTMLOrSVGElement<ElementBase>::attribute_changed(FlyString const& local_name, Optional<String> const&, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
||||
{
|
||||
|
@ -76,17 +76,17 @@ void HTMLOrSVGElement<ElementBase>::attribute_changed(FlyString const& local_nam
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
|
||||
template<typename ElementBase>
|
||||
WebIDL::ExceptionOr<void> HTMLOrSVGElement<ElementBase>::cloned(DOM::Node& copy, bool)
|
||||
{
|
||||
// The cloning steps for elements that include HTMLOrSVGElement must set the
|
||||
// [[CryptographicNonce]] slot on the copy to the value of the slot on the element being cloned.
|
||||
// The cloning steps for elements that include HTMLOrSVGElement given node, copy, and subtree
|
||||
// are to set copy's [[CryptographicNonce]] to node's [[CryptographicNonce]].
|
||||
static_cast<ElementBase&>(copy).m_cryptographic_nonce = m_cryptographic_nonce;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
|
||||
template<typename ElementBase>
|
||||
void HTMLOrSVGElement<ElementBase>::inserted()
|
||||
{
|
||||
|
|
|
@ -46,20 +46,24 @@ void HTMLTemplateElement::adopted_from(DOM::Document&)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext
|
||||
WebIDL::ExceptionOr<void> HTMLTemplateElement::cloned(Node& copy, bool clone_children)
|
||||
WebIDL::ExceptionOr<void> HTMLTemplateElement::cloned(Node& copy, bool subtree)
|
||||
{
|
||||
// 1. If the clone children flag is not set in the calling clone algorithm, return.
|
||||
if (!clone_children)
|
||||
TRY(Base::cloned(copy, subtree));
|
||||
|
||||
// The cloning steps for template elements given node, copy, and subtree are:
|
||||
|
||||
// 1. If subtree is false, then return.
|
||||
if (!subtree)
|
||||
return {};
|
||||
|
||||
// 2. Let copied contents be the result of cloning all the children of node's template contents,
|
||||
// with document set to copy's template contents's node document, and with the clone children flag set.
|
||||
// 3. Append copied contents to copy's template contents.
|
||||
auto& template_clone = verify_cast<HTMLTemplateElement>(copy);
|
||||
// 2. For each child of node's template contents's children, in tree order:
|
||||
// clone a node given child with document set to copy's template contents's node document,
|
||||
// subtree set to true, and parent set to copy's template contents.
|
||||
auto& template_copy = verify_cast<HTMLTemplateElement>(copy);
|
||||
for (auto child = content()->first_child(); child; child = child->next_sibling()) {
|
||||
auto cloned_child = TRY(child->clone_node(&template_clone.content()->document(), true));
|
||||
TRY(template_clone.content()->append_child(cloned_child));
|
||||
TRY(child->clone_node(&template_copy.content()->document(), true, template_copy.content()));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -136,9 +136,11 @@ void HTMLTextAreaElement::clear_algorithm()
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-node-clone-ext
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool)
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool subtree)
|
||||
{
|
||||
// The cloning steps for textarea elements must propagate the raw value and dirty value flag from the node being cloned to the copy.
|
||||
TRY(Base::cloned(copy, subtree));
|
||||
|
||||
// The cloning steps for textarea elements given node, copy, and subtree are to propagate the raw value and dirty value flag from node to copy.
|
||||
auto& textarea_copy = verify_cast<HTMLTextAreaElement>(copy);
|
||||
textarea_copy.m_raw_value = m_raw_value;
|
||||
textarea_copy.m_dirty_value = m_dirty_value;
|
||||
|
|
Loading…
Add table
Reference in a new issue