script: Add an initial command and commandfor attribute implementation (#41237)

Initial command and commandfor attribute implementation

Testing: Covered by WPTs

Signed-off-by: Luke Warlow <lwarlow@igalia.com>
This commit is contained in:
Luke Warlow
2026-02-25 21:40:39 +00:00
committed by GitHub
parent d5c82150e0
commit 035b5d60f4
13 changed files with 337 additions and 250 deletions

View File

@@ -4,6 +4,7 @@
use html5ever::LocalName;
use js::context::JSContext;
use script_bindings::root::DomRoot;
use script_bindings::script_runtime::CanGc;
use style::attr::AttrValue;
@@ -59,6 +60,8 @@ use crate::dom::html::htmltemplateelement::HTMLTemplateElement;
use crate::dom::html::htmltextareaelement::HTMLTextAreaElement;
use crate::dom::html::htmltitleelement::HTMLTitleElement;
use crate::dom::html::htmlvideoelement::HTMLVideoElement;
use crate::dom::htmlbuttonelement::CommandState;
use crate::dom::htmldialogelement::HTMLDialogElement;
use crate::dom::node::{BindContext, ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
use crate::dom::shadowroot::ShadowRoot;
use crate::dom::svg::svgelement::SVGElement;
@@ -138,6 +141,23 @@ pub(crate) trait VirtualMethods {
}
}
/// <https://html.spec.whatwg.org/multipage/#is-valid-command-steps>
fn is_valid_command_steps(&self, command: CommandState) -> bool {
self.super_type()
.is_some_and(|super_type| super_type.is_valid_command_steps(command))
}
/// <https://html.spec.whatwg.org/multipage/#command-steps>
fn command_steps(
&self,
button: DomRoot<HTMLButtonElement>,
command: CommandState,
can_gc: CanGc,
) -> bool {
self.super_type()
.is_some_and(|super_type| super_type.command_steps(button, command, can_gc))
}
/// <https://dom.spec.whatwg.org/#concept-node-adopt-ext>
fn adopting_steps(&self, old_doc: &Document, can_gc: CanGc) {
if let Some(s) = self.super_type() {
@@ -194,6 +214,9 @@ pub(crate) fn vtable_for(node: &Node) -> &dyn VirtualMethods {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLDetailsElement)) => {
node.downcast::<HTMLDetailsElement>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLDialogElement)) => {
node.downcast::<HTMLDialogElement>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFieldSetElement)) => {
node.downcast::<HTMLFieldSetElement>().unwrap() as &dyn VirtualMethods
},