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

@ -148,8 +148,18 @@ impl KeyboardEvent {
ev
}
#[allow(non_snake_case)]
pub fn Constructor(
pub fn key(&self) -> Key {
self.typed_key.borrow().clone()
}
pub fn modifiers(&self) -> Modifiers {
self.modifiers.get()
}
}
impl KeyboardEventMethods for KeyboardEvent {
/// <https://w3c.github.io/uievents/#dom-keyboardevent-keyboardevent>
fn Constructor(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
@ -182,19 +192,7 @@ impl KeyboardEvent {
*event.key.borrow_mut() = init.key.clone();
Ok(event)
}
}
impl KeyboardEvent {
pub fn key(&self) -> Key {
self.typed_key.borrow().clone()
}
pub fn modifiers(&self) -> Modifiers {
self.modifiers.get()
}
}
impl KeyboardEventMethods for KeyboardEvent {
// https://w3c.github.io/uievents/#widl-KeyboardEvent-initKeyboardEvent
fn InitKeyboardEvent(
&self,
@ -219,52 +217,52 @@ impl KeyboardEventMethods for KeyboardEvent {
self.repeat.set(repeat);
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-key
/// <https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent>
fn Key(&self) -> DOMString {
self.key.borrow().clone()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-code
/// <https://w3c.github.io/uievents/#dom-keyboardevent-code>
fn Code(&self) -> DOMString {
self.code.borrow().clone()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-location
/// <https://w3c.github.io/uievents/#dom-keyboardevent-location>
fn Location(&self) -> u32 {
self.location.get()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-ctrlKey
/// <https://w3c.github.io/uievents/#dom-keyboardevent-ctrlkey>
fn CtrlKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::CONTROL)
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-shiftKey
/// <https://w3c.github.io/uievents/#dom-keyboardevent-shiftkey>
fn ShiftKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::SHIFT)
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-altKey
/// <https://w3c.github.io/uievents/#dom-keyboardevent-altkey>
fn AltKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::ALT)
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-metaKey
/// <https://w3c.github.io/uievents/#dom-keyboardevent-metakey>
fn MetaKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::META)
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-repeat
/// <https://w3c.github.io/uievents/#dom-keyboardevent-repeat>
fn Repeat(&self) -> bool {
self.repeat.get()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-isComposing
/// <https://w3c.github.io/uievents/#dom-keyboardevent-iscomposing>
fn IsComposing(&self) -> bool {
self.is_composing.get()
}
// https://w3c.github.io/uievents/#dom-keyboardevent-getmodifierstate
/// <https://w3c.github.io/uievents/#dom-keyboardevent-getmodifierstate>
fn GetModifierState(&self, key_arg: DOMString) -> bool {
self.modifiers.get().contains(match &*key_arg {
"Alt" => Modifiers::ALT,
@ -283,17 +281,17 @@ impl KeyboardEventMethods for KeyboardEvent {
})
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-charCode
/// <https://w3c.github.io/uievents/#dom-keyboardevent-charcode>
fn CharCode(&self) -> u32 {
self.char_code.get()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-keyCode
/// <https://w3c.github.io/uievents/#dom-keyboardevent-keycode>
fn KeyCode(&self) -> u32 {
self.key_code.get()
}
// https://w3c.github.io/uievents/#widl-KeyboardEvent-which
/// <https://w3c.github.io/uievents/#dom-uievent-which>
fn Which(&self) -> u32 {
if self.char_code.get() != 0 {
self.char_code.get()
@ -302,7 +300,7 @@ impl KeyboardEventMethods for KeyboardEvent {
}
}
// https://dom.spec.whatwg.org/#dom-event-istrusted
/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
fn IsTrusted(&self) -> bool {
self.uievent.IsTrusted()
}