Support arbitrary protos when wrapping DOM objects with constructors.

This commit is contained in:
Josh Matthews 2023-05-28 22:43:55 -04:00
parent d9600ff50f
commit dbff26bce0
197 changed files with 2028 additions and 586 deletions

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEvent
use crate::dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::reflect_dom_object2;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
@ -16,6 +16,7 @@ use crate::dom::uievent::UIEvent;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use keyboard_types::{Key, Modifiers};
use js::rust::HandleObject;
use std::cell::Cell;
unsafe_no_jsmanaged_fields!(Key);
@ -52,7 +53,11 @@ impl KeyboardEvent {
}
pub fn new_uninitialized(window: &Window) -> DomRoot<KeyboardEvent> {
reflect_dom_object(Box::new(KeyboardEvent::new_inherited()), window)
Self::new_uninitialized_with_proto(window, None)
}
fn new_uninitialized_with_proto(window: &Window, proto: Option<HandleObject>) -> DomRoot<KeyboardEvent> {
reflect_dom_object2(Box::new(KeyboardEvent::new_inherited()), window, proto)
}
pub fn new(
@ -61,6 +66,42 @@ impl KeyboardEvent {
can_bubble: bool,
cancelable: bool,
view: Option<&Window>,
detail: i32,
key: Key,
code: DOMString,
location: u32,
repeat: bool,
is_composing: bool,
modifiers: Modifiers,
char_code: u32,
key_code: u32,
) -> DomRoot<KeyboardEvent> {
Self::new_with_proto(
window,
None,
type_,
can_bubble,
cancelable,
view,
detail,
key,
code,
location,
repeat,
is_composing,
modifiers,
char_code,
key_code,
)
}
fn new_with_proto(
window: &Window,
proto: Option<HandleObject>,
type_: DOMString,
can_bubble: bool,
cancelable: bool,
view: Option<&Window>,
_detail: i32,
key: Key,
code: DOMString,
@ -71,7 +112,7 @@ impl KeyboardEvent {
char_code: u32,
key_code: u32,
) -> DomRoot<KeyboardEvent> {
let ev = KeyboardEvent::new_uninitialized(window);
let ev = KeyboardEvent::new_uninitialized_with_proto(window, proto);
ev.InitKeyboardEvent(
type_,
can_bubble,
@ -95,6 +136,7 @@ impl KeyboardEvent {
#[allow(non_snake_case)]
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
type_: DOMString,
init: &KeyboardEventBinding::KeyboardEventInit,
) -> Fallible<DomRoot<KeyboardEvent>> {
@ -103,8 +145,9 @@ impl KeyboardEvent {
modifiers.set(Modifiers::ALT, init.parent.altKey);
modifiers.set(Modifiers::SHIFT, init.parent.shiftKey);
modifiers.set(Modifiers::META, init.parent.metaKey);
let event = KeyboardEvent::new(
let event = KeyboardEvent::new_with_proto(
window,
proto,
type_,
init.parent.parent.parent.bubbles,
init.parent.parent.parent.cancelable,