script: Include constructors and static methods in generated DOM traits (#33665)

* Add all constructors, special operations, and static methods to generated DOM interface traits.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Move all constructors and static methods defined in bare impl blocks inside FooMethods trait impls.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Add missing doc links.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-10-07 21:51:58 -04:00 committed by GitHub
parent 946fa9cdee
commit 7d931e673a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
133 changed files with 1479 additions and 1438 deletions

View file

@ -82,43 +82,6 @@ impl HTMLOptionElement {
)
}
// https://html.spec.whatwg.org/multipage/#dom-option
#[allow(non_snake_case)]
pub fn Option(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
text: DOMString,
value: Option<DOMString>,
default_selected: bool,
selected: bool,
) -> Fallible<DomRoot<HTMLOptionElement>> {
let element = Element::create(
QualName::new(None, ns!(html), local_name!("option")),
None,
&window.Document(),
ElementCreator::ScriptCreated,
CustomElementCreationMode::Synchronous,
proto,
can_gc,
);
let option = DomRoot::downcast::<HTMLOptionElement>(element).unwrap();
if !text.is_empty() {
option.upcast::<Node>().SetTextContent(Some(text))
}
if let Some(val) = value {
option.SetValue(val)
}
option.SetDefaultSelected(default_selected);
option.set_selectedness(selected);
option.update_select_validity();
Ok(option)
}
pub fn set_selectedness(&self, selected: bool) {
self.selectedness.set(selected);
}
@ -210,6 +173,42 @@ fn collect_text(element: &Element, value: &mut String) {
}
impl HTMLOptionElementMethods for HTMLOptionElement {
// https://html.spec.whatwg.org/multipage/#dom-option
fn Option(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
text: DOMString,
value: Option<DOMString>,
default_selected: bool,
selected: bool,
) -> Fallible<DomRoot<HTMLOptionElement>> {
let element = Element::create(
QualName::new(None, ns!(html), local_name!("option")),
None,
&window.Document(),
ElementCreator::ScriptCreated,
CustomElementCreationMode::Synchronous,
proto,
can_gc,
);
let option = DomRoot::downcast::<HTMLOptionElement>(element).unwrap();
if !text.is_empty() {
option.upcast::<Node>().SetTextContent(Some(text))
}
if let Some(val) = value {
option.SetValue(val)
}
option.SetDefaultSelected(default_selected);
option.set_selectedness(selected);
option.update_select_validity();
Ok(option)
}
// https://html.spec.whatwg.org/multipage/#dom-option-disabled
make_bool_getter!(Disabled, "disabled");