diff --git a/bridge/core/dom/events/event.d.ts b/bridge/core/dom/events/event.d.ts index aa2130c85f..349bcf9bf8 100644 --- a/bridge/core/dom/events/event.d.ts +++ b/bridge/core/dom/events/event.d.ts @@ -47,5 +47,5 @@ interface Event { [key: string]: any; - new(type: string, options?: EventInit) : Event; + new(type: string, init?: EventInit) : Event; } diff --git a/bridge/include/plugin_api/event.h b/bridge/include/plugin_api/event.h index f263412ab9..48fe667c25 100644 --- a/bridge/include/plugin_api/event.h +++ b/bridge/include/plugin_api/event.h @@ -19,18 +19,17 @@ class Event; typedef struct ScriptValueRef ScriptValueRef; enum class EventType { kEvent = 0, - kCustomEvent = 1, - kAnimationEvent = 2, - kCloseEvent = 3, - kGestureEvent = 4, - kHashchangeEvent = 5, - kIntersectionChangeEvent = 6, - kTransitionEvent = 7, - kUIEvent = 8, - kFocusEvent = 9, - kInputEvent = 10, - kMouseEvent = 11, - kPointerEvent = 12, + kAnimationEvent = 1, + kCloseEvent = 2, + kGestureEvent = 3, + kHashchangeEvent = 4, + kIntersectionChangeEvent = 5, + kTransitionEvent = 6, + kUIEvent = 7, + kFocusEvent = 8, + kInputEvent = 9, + kMouseEvent = 10, + kPointerEvent = 11, }; using PublicEventGetBubbles = int32_t (*)(Event*); using PublicEventGetCancelBubble = int32_t (*)(Event*); diff --git a/bridge/include/plugin_api/executing_context.h b/bridge/include/plugin_api/executing_context.h index a5f8945bc0..20c8a76a90 100644 --- a/bridge/include/plugin_api/executing_context.h +++ b/bridge/include/plugin_api/executing_context.h @@ -5,11 +5,23 @@ #ifndef WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ #define WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ +#include "animation_event_init.h" +#include "close_event_init.h" #include "core/native/native_function.h" #include "core/native/native_loader.h" #include "document.h" +#include "event_init.h" #include "exception_state.h" +#include "focus_event_init.h" #include "foundation/native_value.h" +#include "gesture_event_init.h" +#include "hashchange_event_init.h" +#include "input_event_init.h" +#include "intersection_change_event_init.h" +#include "mouse_event_init.h" +#include "pointer_event_init.h" +#include "transition_event_init.h" +#include "ui_event_init.h" #include "window.h" namespace webf { @@ -17,6 +29,30 @@ namespace webf { class Document; class ExecutingContext; class Window; +class UIEvent; +typedef struct UIEventPublicMethods UIEventPublicMethods; +class CustomEvent; +typedef struct CustomEventPublicMethods CustomEventPublicMethods; +class AnimationEvent; +typedef struct AnimationEventPublicMethods AnimationEventPublicMethods; +class CloseEvent; +typedef struct CloseEventPublicMethods CloseEventPublicMethods; +class FocusEvent; +typedef struct FocusEventPublicMethods FocusEventPublicMethods; +class GestureEvent; +typedef struct GestureEventPublicMethods GestureEventPublicMethods; +class HashchangeEvent; +typedef struct HashchangeEventPublicMethods HashchangeEventPublicMethods; +class InputEvent; +typedef struct InputEventPublicMethods InputEventPublicMethods; +class IntersectionChangeEvent; +typedef struct IntersectionChangeEventPublicMethods IntersectionChangeEventPublicMethods; +class MouseEvent; +typedef struct MouseEventPublicMethods MouseEventPublicMethods; +class PointerEvent; +typedef struct PointerEventPublicMethods PointerEventPublicMethods; +class TransitionEvent; +typedef struct TransitionEventPublicMethods TransitionEventPublicMethods; using PublicContextGetDocument = WebFValue (*)(ExecutingContext*); using PublicContextGetWindow = WebFValue (*)(ExecutingContext*); @@ -51,6 +87,45 @@ using PublicContextRemoveRustFutureTask = void (*)(ExecutingContext*, WebFNativeFunctionContext*, NativeLibrartMetaData*, SharedExceptionState*); +using PublicContextCreateEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateAnimationEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateAnimationEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFAnimationEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateCloseEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateCloseEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFCloseEventInit* init, ExceptionState& exception_state); + +// using PublicContextCreateCustomEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +// using PublicContextCreateCustomEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFCustomEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateFocusEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateFocusEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFFocusEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateGestureEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateGestureEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFGestureEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateHashchangeEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateHashchangeEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFHashchangeEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateInputEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateInputEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFInputEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateIntersectionChangeEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateIntersectionChangeEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFIntersectionChangeEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateMouseEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateMouseEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFMouseEventInit* init, ExceptionState& exception_state); + +using PublicContextCreatePointerEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreatePointerEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFPointerEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateTransitionEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateTransitionEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFTransitionEventInit* init, ExceptionState& exception_state); + +using PublicContextCreateUIEvent = WebFValue (*)(ExecutingContext* context, const char* type, ExceptionState& exception_state); +using PublicContextCreateUIEventWithOptions = WebFValue (*)(ExecutingContext* context, const char* type, WebFUIEventInit* init, ExceptionState& exception_state); + // Memory aligned and readable from WebF side. // Only C type member can be included in this class, any C++ type and classes can is not allowed to use here. struct ExecutingContextWebFMethods { @@ -95,6 +170,47 @@ struct ExecutingContextWebFMethods { WebFNativeFunctionContext* callback_context, NativeLibrartMetaData* meta_data, SharedExceptionState* shared_exception_state); + static void SetRunRustFutureTasks(ExecutingContext* context, + WebFNativeFunctionContext* callback_context, + SharedExceptionState* shared_exception_state); + static WebFValue CreateEvent(ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateEventWithOptions(ExecutingContext* context, const char* type, WebFEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateAnimationEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateAnimationEventWithOptions (ExecutingContext* context, const char* type, WebFAnimationEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateCloseEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateCloseEventWithOptions (ExecutingContext* context, const char* type, WebFCloseEventInit* init, ExceptionState& exception_state); + + // static WebFValue CreateCustomEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + // static WebFValue CreateCustomEventWithOptions (ExecutingContext* context, const char* type, WebFCustomEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateFocusEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateFocusEventWithOptions (ExecutingContext* context, const char* type, WebFFocusEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateGestureEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateGestureEventWithOptions (ExecutingContext* context, const char* type, WebFGestureEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateHashchangeEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateHashchangeEventWithOptions (ExecutingContext* context, const char* type, WebFHashchangeEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateInputEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateInputEventWithOptions (ExecutingContext* context, const char* type, WebFInputEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateIntersectionChangeEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateIntersectionChangeEventWithOptions (ExecutingContext* context, const char* type, WebFIntersectionChangeEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateMouseEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateMouseEventWithOptions (ExecutingContext* context, const char* type, WebFMouseEventInit* init, ExceptionState& exception_state); + + static WebFValue CreatePointerEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreatePointerEventWithOptions (ExecutingContext* context, const char* type, WebFPointerEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateTransitionEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateTransitionEventWithOptions (ExecutingContext* context, const char* type, WebFTransitionEventInit* init, ExceptionState& exception_state); + + static WebFValue CreateUIEvent (ExecutingContext* context, const char* type, ExceptionState& exception_state); + static WebFValue CreateUIEventWithOptions (ExecutingContext* context, const char* type, WebFUIEventInit* init, ExceptionState& exception_state); double version{1.0}; PublicContextGetDocument context_get_document{document}; @@ -113,6 +229,32 @@ struct ExecutingContextWebFMethods { PublicContextClearInterval context_clear_interval{ClearInterval}; PublicContextAddRustFutureTask context_add_rust_future_task{AddRustFutureTask}; PublicContextRemoveRustFutureTask context_remove_rust_future_task{RemoveRustFutureTask}; + PublicContextCreateEvent rust_context_create_event{CreateEvent}; + PublicContextCreateEventWithOptions rust_context_create_event_with_options{CreateEventWithOptions}; + PublicContextCreateAnimationEvent rust_context_create_animation_event{CreateAnimationEvent}; + PublicContextCreateAnimationEventWithOptions rust_context_create_animation_event_with_options{CreateAnimationEventWithOptions}; + PublicContextCreateCloseEvent rust_context_create_close_event{CreateCloseEvent}; + PublicContextCreateCloseEventWithOptions rust_context_create_close_event_with_options{CreateCloseEventWithOptions}; + // PublicContextCreateCustomEvent rust_context_create_custom_event{CreateCustomEvent}; + // PublicContextCreateCustomEventWithOptions rust_context_create_custom_event_with_options{CreateCustomEventWithOptions}; + PublicContextCreateFocusEvent rust_context_create_focus_event{CreateFocusEvent}; + PublicContextCreateFocusEventWithOptions rust_context_create_focus_event_with_options{CreateFocusEventWithOptions}; + PublicContextCreateGestureEvent rust_context_create_gesture_event{CreateGestureEvent}; + PublicContextCreateGestureEventWithOptions rust_context_create_gesture_event_with_options{CreateGestureEventWithOptions}; + PublicContextCreateHashchangeEvent rust_context_create_change_event{CreateHashchangeEvent}; + PublicContextCreateHashchangeEventWithOptions rust_context_create_change_event_with_options{CreateHashchangeEventWithOptions}; + PublicContextCreateInputEvent rust_context_create_input_event{CreateInputEvent}; + PublicContextCreateInputEventWithOptions rust_context_create_input_event_with_options{CreateInputEventWithOptions}; + PublicContextCreateIntersectionChangeEvent rust_context_create_intersection_change_event{CreateIntersectionChangeEvent}; + PublicContextCreateIntersectionChangeEventWithOptions rust_context_create_intersection_change_event_with_options{CreateIntersectionChangeEventWithOptions}; + PublicContextCreateMouseEvent rust_context_create_mouse_event{CreateMouseEvent}; + PublicContextCreateMouseEventWithOptions rust_context_create_mouse_event_with_options{CreateMouseEventWithOptions}; + PublicContextCreatePointerEvent rust_context_create_pointer_event{CreatePointerEvent}; + PublicContextCreatePointerEventWithOptions rust_context_create_pointer_event_with_options{CreatePointerEventWithOptions}; + PublicContextCreateTransitionEvent rust_context_create_transition_event_event{CreateTransitionEvent}; + PublicContextCreateTransitionEventWithOptions rust_context_create_transition_event_with_options{CreateTransitionEventWithOptions}; + PublicContextCreateUIEvent rust_context_create_ui_event{CreateUIEvent}; + PublicContextCreateUIEventWithOptions rust_context_create_ui_event_with_options{CreateUIEventWithOptions}; }; } // namespace webf diff --git a/bridge/include/plugin_api/focus_event_init.h b/bridge/include/plugin_api/focus_event_init.h index f01803cb83..cc0657bb9f 100644 --- a/bridge/include/plugin_api/focus_event_init.h +++ b/bridge/include/plugin_api/focus_event_init.h @@ -17,6 +17,9 @@ struct WebFFocusEventInit { double detail; WebFValue view; double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; WebFValue related_target; }; } // namespace webf diff --git a/bridge/include/plugin_api/input_event_init.h b/bridge/include/plugin_api/input_event_init.h index 5a0d73ee61..ea5b618a03 100644 --- a/bridge/include/plugin_api/input_event_init.h +++ b/bridge/include/plugin_api/input_event_init.h @@ -15,6 +15,9 @@ struct WebFInputEventInit { double detail; WebFValue view; double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; const char* input_type; const char* data; }; diff --git a/bridge/include/plugin_api/intersection_change_event_init.h b/bridge/include/plugin_api/intersection_change_event_init.h index a4097cf603..d54397dfda 100644 --- a/bridge/include/plugin_api/intersection_change_event_init.h +++ b/bridge/include/plugin_api/intersection_change_event_init.h @@ -15,6 +15,9 @@ struct WebFIntersectionChangeEventInit { double detail; WebFValue view; double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; double intersection_ratio; }; } // namespace webf diff --git a/bridge/include/plugin_api/keyboard_event_init.h b/bridge/include/plugin_api/keyboard_event_init.h index d681a3b016..cafe84263c 100644 --- a/bridge/include/plugin_api/keyboard_event_init.h +++ b/bridge/include/plugin_api/keyboard_event_init.h @@ -15,6 +15,9 @@ struct WebFKeyboardEventInit { double detail; WebFValue view; double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; int32_t alt_key; double char_code; const char* code; diff --git a/bridge/include/plugin_api/mouse_event_init.h b/bridge/include/plugin_api/mouse_event_init.h index 71e04722a4..c438eb2fa2 100644 --- a/bridge/include/plugin_api/mouse_event_init.h +++ b/bridge/include/plugin_api/mouse_event_init.h @@ -15,6 +15,9 @@ struct WebFMouseEventInit { double detail; WebFValue view; double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; }; } // namespace webf #endif // WEBF_CORE_WEBF_API_PLUGIN_API_MOUSE_EVENT_INIT_H_ diff --git a/bridge/include/plugin_api/pointer_event_init.h b/bridge/include/plugin_api/pointer_event_init.h index 0e6bd769e1..1dbb22c2c5 100644 --- a/bridge/include/plugin_api/pointer_event_init.h +++ b/bridge/include/plugin_api/pointer_event_init.h @@ -9,7 +9,15 @@ #include #include "webf_value.h" namespace webf { +typedef struct Window Window; +typedef struct WindowPublicMethods WindowPublicMethods; struct WebFPointerEventInit { + double detail; + WebFValue view; + double which; + int32_t bubbles; + int32_t cancelable; + int32_t composed; int32_t is_primary; double pointer_id; const char* pointer_type; diff --git a/bridge/rusty_webf_sys/src/dom/events/custom_event.rs b/bridge/rusty_webf_sys/src/dom/events/custom_event.rs deleted file mode 100644 index 2864232c1c..0000000000 --- a/bridge/rusty_webf_sys/src/dom/events/custom_event.rs +++ /dev/null @@ -1,120 +0,0 @@ -// Generated by WebF TSDL, don't edit this file directly. -// Generate command: node scripts/generate_binding_code.js -/* -* Copyright (C) 2022-present The WebF authors. All rights reserved. -*/ -use std::ffi::*; -use crate::*; -#[repr(C)] -pub struct CustomEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub detail: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub init_custom_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, -} -pub struct CustomEvent { - pub event: Event, - method_pointer: *const CustomEventRustMethods, -} -impl CustomEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const CustomEventRustMethods, status: *const RustValueStatus) -> CustomEvent { - unsafe { - CustomEvent { - event: Event::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.event.context() - } - pub fn detail(&self) -> ScriptValueRef { - let value = unsafe { - ((*self.method_pointer).detail)(self.ptr()) - }; - ScriptValueRef::initialize(value.value, self.context(), value.method_pointer) - } - pub fn init_custom_event(&self, type_: &str, can_bubble: bool, cancelable: bool, detail: &ScriptValueRef, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).init_custom_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(can_bubble), i32::from(cancelable), detail.ptr, exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } -} -pub trait CustomEventMethods: EventMethods { - fn detail(&self) -> ScriptValueRef; - fn init_custom_event(&self, type_: &str, can_bubble: bool, cancelable: bool, detail: &ScriptValueRef, exception_state: &ExceptionState) -> Result<(), String>; - fn as_custom_event(&self) -> &CustomEvent; -} -impl CustomEventMethods for CustomEvent { - fn detail(&self) -> ScriptValueRef { - self.detail() - } - fn init_custom_event(&self, type_: &str, can_bubble: bool, cancelable: bool, detail: &ScriptValueRef, exception_state: &ExceptionState) -> Result<(), String> { - self.init_custom_event(type_, can_bubble, cancelable, detail, exception_state) - } - fn as_custom_event(&self) -> &CustomEvent { - self - } -} -impl EventMethods for CustomEvent { - fn bubbles(&self) -> bool { - self.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.event.current_target() - } - fn default_prevented(&self) -> bool { - self.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.event.src_element() - } - fn target(&self) -> EventTarget { - self.event.target() - } - fn is_trusted(&self) -> bool { - self.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.event.time_stamp() - } - fn type_(&self) -> String { - self.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.event - } -} diff --git a/bridge/rusty_webf_sys/src/dom/events/event.rs b/bridge/rusty_webf_sys/src/dom/events/event.rs index fa9d81dd98..df5099283a 100644 --- a/bridge/rusty_webf_sys/src/dom/events/event.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event.rs @@ -8,18 +8,17 @@ use crate::*; #[repr(C)] enum EventType { Event = 0, - CustomEvent = 1, - AnimationEvent = 2, - CloseEvent = 3, - GestureEvent = 4, - HashchangeEvent = 5, - IntersectionChangeEvent = 6, - TransitionEvent = 7, - UIEvent = 8, - FocusEvent = 9, - InputEvent = 10, - MouseEvent = 11, - PointerEvent = 12, + AnimationEvent = 1, + CloseEvent = 2, + GestureEvent = 3, + HashchangeEvent = 4, + IntersectionChangeEvent = 5, + TransitionEvent = 6, + UIEvent = 7, + FocusEvent = 8, + InputEvent = 9, + MouseEvent = 10, + PointerEvent = 11, } #[repr(C)] pub struct EventRustMethods { @@ -171,16 +170,6 @@ impl Event { } Ok(()) } - pub fn as_custom_event(&self) -> Result { - let raw_ptr = unsafe { - assert!(!(*((*self).status)).disposed, "The underline C++ impl of this ptr({:?}) had been disposed", (self.method_pointer)); - ((*self.method_pointer).dynamic_to)(self.ptr, EventType::CustomEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the CustomEvent type."); - } - Ok(CustomEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const CustomEventRustMethods, raw_ptr.status)) - } pub fn as_animation_event(&self) -> Result { let raw_ptr = unsafe { assert!(!(*((*self).status)).disposed, "The underline C++ impl of this ptr({:?}) had been disposed", (self.method_pointer)); @@ -367,3 +356,25 @@ impl EventMethods for Event { self } } +impl ExecutingContext { + pub fn create_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(Event::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_event_with_options(&self, event_type: &str, options: &EventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(Event::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/dom/events/mod.rs b/bridge/rusty_webf_sys/src/dom/events/mod.rs index e95685d5e3..707dc9cba5 100644 --- a/bridge/rusty_webf_sys/src/dom/events/mod.rs +++ b/bridge/rusty_webf_sys/src/dom/events/mod.rs @@ -2,14 +2,12 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ pub mod add_event_listener_options; -pub mod custom_event; pub mod event_init; pub mod event_listener_options; pub mod event_target; pub mod event; pub use add_event_listener_options::*; -pub use custom_event::*; pub use event_init::*; pub use event_listener_options::*; pub use event_target::*; diff --git a/bridge/rusty_webf_sys/src/events/animation_event.rs b/bridge/rusty_webf_sys/src/events/animation_event.rs index 5e98383f05..f9b78111ca 100644 --- a/bridge/rusty_webf_sys/src/events/animation_event.rs +++ b/bridge/rusty_webf_sys/src/events/animation_event.rs @@ -130,3 +130,25 @@ impl EventMethods for AnimationEvent { &self.event } } +impl ExecutingContext { + pub fn create_animation_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_animation_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(AnimationEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_animation_event_with_options(&self, event_type: &str, options: &AnimationEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_animation_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(AnimationEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/close_event.rs b/bridge/rusty_webf_sys/src/events/close_event.rs index 47eb399483..714daf3729 100644 --- a/bridge/rusty_webf_sys/src/events/close_event.rs +++ b/bridge/rusty_webf_sys/src/events/close_event.rs @@ -128,3 +128,25 @@ impl EventMethods for CloseEvent { &self.event } } +impl ExecutingContext { + pub fn create_close_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_close_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(CloseEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_close_event_with_options(&self, event_type: &str, options: &CloseEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_close_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(CloseEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/focus_event.rs b/bridge/rusty_webf_sys/src/events/focus_event.rs index e2b78491e5..9606748e4d 100644 --- a/bridge/rusty_webf_sys/src/events/focus_event.rs +++ b/bridge/rusty_webf_sys/src/events/focus_event.rs @@ -118,3 +118,25 @@ impl EventMethods for FocusEvent { &self.ui_event.event } } +impl ExecutingContext { + pub fn create_focus_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_focus_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(FocusEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_focus_event_with_options(&self, event_type: &str, options: &FocusEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_focus_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(FocusEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/gesture_event.rs b/bridge/rusty_webf_sys/src/events/gesture_event.rs index 9287dc62ff..a4303f3e20 100644 --- a/bridge/rusty_webf_sys/src/events/gesture_event.rs +++ b/bridge/rusty_webf_sys/src/events/gesture_event.rs @@ -185,3 +185,25 @@ impl EventMethods for GestureEvent { &self.event } } +impl ExecutingContext { + pub fn create_gesture_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_gesture_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(GestureEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_gesture_event_with_options(&self, event_type: &str, options: &GestureEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_gesture_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(GestureEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/hashchange_event.rs b/bridge/rusty_webf_sys/src/events/hashchange_event.rs index 51d58f9bb9..33753f9e87 100644 --- a/bridge/rusty_webf_sys/src/events/hashchange_event.rs +++ b/bridge/rusty_webf_sys/src/events/hashchange_event.rs @@ -119,3 +119,25 @@ impl EventMethods for HashchangeEvent { &self.event } } +impl ExecutingContext { + pub fn create_hashchange_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_hashchange_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(HashchangeEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_hashchange_event_with_options(&self, event_type: &str, options: &HashchangeEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_hashchange_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(HashchangeEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/input_event.rs b/bridge/rusty_webf_sys/src/events/input_event.rs index 17630178e9..d729f72ba5 100644 --- a/bridge/rusty_webf_sys/src/events/input_event.rs +++ b/bridge/rusty_webf_sys/src/events/input_event.rs @@ -133,3 +133,25 @@ impl EventMethods for InputEvent { &self.ui_event.event } } +impl ExecutingContext { + pub fn create_input_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_input_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(InputEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_input_event_with_options(&self, event_type: &str, options: &InputEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_input_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(InputEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/intersection_change_event.rs b/bridge/rusty_webf_sys/src/events/intersection_change_event.rs index 149fbf398e..707e3c9954 100644 --- a/bridge/rusty_webf_sys/src/events/intersection_change_event.rs +++ b/bridge/rusty_webf_sys/src/events/intersection_change_event.rs @@ -104,3 +104,25 @@ impl EventMethods for IntersectionChangeEvent { &self.event } } +impl ExecutingContext { + pub fn create_intersection_change_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_intersection_change_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(IntersectionChangeEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_intersection_change_event_with_options(&self, event_type: &str, options: &IntersectionChangeEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_intersection_change_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(IntersectionChangeEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/mouse_event.rs b/bridge/rusty_webf_sys/src/events/mouse_event.rs index b281f6e5ab..79bb4dcdaf 100644 --- a/bridge/rusty_webf_sys/src/events/mouse_event.rs +++ b/bridge/rusty_webf_sys/src/events/mouse_event.rs @@ -151,3 +151,25 @@ impl EventMethods for MouseEvent { &self.ui_event.event } } +impl ExecutingContext { + pub fn create_mouse_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_mouse_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(MouseEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_mouse_event_with_options(&self, event_type: &str, options: &MouseEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_mouse_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(MouseEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/pointer_event.rs b/bridge/rusty_webf_sys/src/events/pointer_event.rs index c021e8acb3..b3a4523bd0 100644 --- a/bridge/rusty_webf_sys/src/events/pointer_event.rs +++ b/bridge/rusty_webf_sys/src/events/pointer_event.rs @@ -236,3 +236,25 @@ impl EventMethods for PointerEvent { &self.mouse_event.ui_event.event } } +impl ExecutingContext { + pub fn create_pointer_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_pointer_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(PointerEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_pointer_event_with_options(&self, event_type: &str, options: &PointerEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_pointer_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(PointerEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/transition_event.rs b/bridge/rusty_webf_sys/src/events/transition_event.rs index 3cfa89b813..29e757b722 100644 --- a/bridge/rusty_webf_sys/src/events/transition_event.rs +++ b/bridge/rusty_webf_sys/src/events/transition_event.rs @@ -130,3 +130,25 @@ impl EventMethods for TransitionEvent { &self.event } } +impl ExecutingContext { + pub fn create_transition_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_transition_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(TransitionEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_transition_event_with_options(&self, event_type: &str, options: &TransitionEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_transition_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(TransitionEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/events/ui_event.rs b/bridge/rusty_webf_sys/src/events/ui_event.rs index 9b007486aa..27508299c3 100644 --- a/bridge/rusty_webf_sys/src/events/ui_event.rs +++ b/bridge/rusty_webf_sys/src/events/ui_event.rs @@ -126,3 +126,25 @@ impl EventMethods for UIEvent { &self.event } } +impl ExecutingContext { + pub fn create_ui_event(&self, event_type: &str, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_ui_event)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(UIEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + pub fn create_ui_event_with_options(&self, event_type: &str, options: &UIEventInit, exception_state: &ExceptionState) -> Result { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_ui_event_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(UIEvent::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} diff --git a/bridge/rusty_webf_sys/src/executing_context.rs b/bridge/rusty_webf_sys/src/executing_context.rs index 85eba4fe82..d3ed61513f 100644 --- a/bridge/rusty_webf_sys/src/executing_context.rs +++ b/bridge/rusty_webf_sys/src/executing_context.rs @@ -25,6 +25,31 @@ pub struct ExecutingContextRustMethods { pub clear_interval: extern "C" fn(*const OpaquePtr, c_int, *const OpaquePtr), pub add_rust_future_task: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, *const NativeLibraryMetaData, *const OpaquePtr) -> c_void, pub remove_rust_future_task: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, *const NativeLibraryMetaData, *const OpaquePtr) -> c_void, + pub set_run_rust_future_tasks: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, *const OpaquePtr) -> c_void, + pub create_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const EventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_animation_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_animation_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const AnimationEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_close_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_close_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const CloseEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_focus_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_focus_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const FocusEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_gesture_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_gesture_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const GestureEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_hashchange_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_hashchange_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const HashchangeEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_input_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_input_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const InputEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_intersection_change_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_intersection_change_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const IntersectionChangeEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_mouse_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_mouse_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const MouseEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_pointer_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_pointer_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const PointerEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_transition_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_transition_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const TransitionEventInit, exception_state: *const OpaquePtr ) -> RustValue, + pub create_ui_event: extern "C" fn(*const OpaquePtr, *const c_char, exception_state: *const OpaquePtr ) -> RustValue, + pub create_ui_event_with_options: extern "C" fn(*const OpaquePtr, *const c_char, options: *const UIEventInit, exception_state: *const OpaquePtr ) -> RustValue, } pub type TimeoutCallback = Box; @@ -54,7 +79,7 @@ pub struct ExecutingContext { // The underlying pointer points to the actual implementation of ExecutionContext in the C++ world. pub ptr: *const OpaquePtr, // Methods available for export from the C++ world for use. - method_pointer: *const ExecutingContextRustMethods, + pub(crate) method_pointer: *const ExecutingContextRustMethods, pub meta_data: *const NativeLibraryMetaData, pub status: *const RustValueStatus, } diff --git a/bridge/scripts/code_generator/bin/code_generator.js b/bridge/scripts/code_generator/bin/code_generator.js index c7535f0a85..4eae05c9f4 100644 --- a/bridge/scripts/code_generator/bin/code_generator.js +++ b/bridge/scripts/code_generator/bin/code_generator.js @@ -195,7 +195,7 @@ const pluginApiList = [ 'input/touch_init.d.ts', 'events/ui_event_init.d.ts', 'dom/events/event.d.ts', - 'dom/events/custom_event.d.ts', + // 'dom/events/custom_event.d.ts', 'events/animation_event.d.ts', 'events/close_event.d.ts', 'events/focus_event.d.ts', diff --git a/bridge/scripts/code_generator/src/idl/generateHeader.ts b/bridge/scripts/code_generator/src/idl/generateHeader.ts index 1c70832a09..736c3ee781 100644 --- a/bridge/scripts/code_generator/src/idl/generateHeader.ts +++ b/bridge/scripts/code_generator/src/idl/generateHeader.ts @@ -124,4 +124,4 @@ export function generateUnionTypeHeader(unionType: ParameterType): string { }).split('\n').filter(str => { return str.trim().length > 0; }).join('\n'); -} \ No newline at end of file +} diff --git a/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/cppGen.ts b/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/cppGen.ts index ad4edce07d..602d055670 100644 --- a/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/cppGen.ts +++ b/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/cppGen.ts @@ -234,21 +234,27 @@ function generatePluginAPIHeaderFile(blob: IDLBlob, options: GenerateOptions) { dependentTypes.add(getPointerType(prop.type)); } }); - - const parentObject = ClassObject.globalClassMap[object.parent]; - - if (parentObject) { - parentObject.props.forEach(prop => { - if (isPointerType(prop.type)) { - dependentTypes.add(getPointerType(prop.type)); - } - }); + const parentObjects = [] as ClassObject[]; + + let node = object; + + while (node && node.parent) { + const parentObject = ClassObject.globalClassMap[node.parent]; + if (parentObject) { + parentObjects.push(parentObject); + parentObject.props.forEach(prop => { + if (isPointerType(prop.type)) { + dependentTypes.add(getPointerType(prop.type)); + } + }); + } + node = parentObject; } return _.template(readHeaderTemplate('dictionary'))({ className: getClassName(blob), parentClassName: object.parent, - parentObject, + parentObjects, blob: blob, object, generatePublicReturnTypeValue, @@ -302,6 +308,12 @@ function generatePluginAPISourceFile(blob: IDLBlob, options: GenerateOptions) { } }); + object.construct?.args.forEach(param => { + if (isPointerType(param.type)) { + dependentTypes.add(getPointerType(param.type)); + } + }); + const subClasses: string[] = []; function appendSubClasses(name: string) { @@ -315,6 +327,31 @@ function generatePluginAPISourceFile(blob: IDLBlob, options: GenerateOptions) { appendSubClasses(object.name); } + const dependentClasses: {[key: string]: ClassObject} = [...dependentTypes].reduce((classes, type) => { + classes[type] = ClassObject.globalClassMap[type]; + + return classes; + }, {} as {[key: string]: ClassObject}); + + for (const key in dependentClasses) { + if (key.endsWith('Options') || key.endsWith('Init')) { + const parents = [] as ClassObject[] + let node = dependentClasses[key]; + while(node && node.parent) { + node = ClassObject.globalClassMap[node.parent]; + parents.push(node); + } + + const parentsProps = parents.flatMap(object => object.props); + + for (const prop of parentsProps) { + if (!dependentClasses[key].props.includes(prop)) { + dependentClasses[key].props.push(prop); + } + } + } + } + return _.template(readSourceTemplate('interface'))({ className: getClassName(blob), parentClassName: object.parent, @@ -330,6 +367,7 @@ function generatePluginAPISourceFile(blob: IDLBlob, options: GenerateOptions) { isStringType, isAnyType, dependentTypes: Array.from(dependentTypes), + dependentClasses, subClasses: _.uniq(subClasses), options, }); diff --git a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/base.cc.tpl b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/base.cc.tpl index a48fb51977..3d542e0b55 100644 --- a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/base.cc.tpl +++ b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/base.cc.tpl @@ -9,6 +9,7 @@ #include "plugin_api/<%= blob.filename.replace('plugin_api_', '') %>.h" #include "plugin_api/event_target.h" #include "plugin_api/exception_state.h" +#include "plugin_api/executing_context.h" #include "core/dom/events/event.h" #include "core/dom/events/custom_event.h" #include "core/native/script_value_ref.h" diff --git a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/dictionary.h.tpl b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/dictionary.h.tpl index efdfaa8687..eb4637652f 100644 --- a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/dictionary.h.tpl +++ b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/dictionary.h.tpl @@ -12,17 +12,21 @@ typedef struct <%= dependentType %>PublicMethods <%= dependentType %>PublicMetho <% }); %> struct WebF<%= className %> { -<% if (parentObject?.props) { %> - <% _.forEach(parentObject.props, function(prop, index) { %> - <% if (isStringType(prop.type)) { %> + +<% _.forEach(parentObjects, function(parentObject, index) { %> + <% if (parentObject?.props) { %> + <% _.forEach(parentObject.props, function(prop, index) { %> + <% if (isStringType(prop.type)) { %> <%= generatePublicReturnTypeValue(prop.type, true) %> <%= _.snakeCase(prop.name) %>; - <% } else if (prop.readonly) { %> + <% } else if (prop.readonly) { %> const <%= generatePublicReturnTypeValue(prop.type, true) %> <%= _.snakeCase(prop.name) %>; - <% } else { %> + <% } else { %> <%= generatePublicReturnTypeValue(prop.type, true) %> <%= _.snakeCase(prop.name) %>; - <% } %> - <% }); %> -<% } %> + <% } %> + <% }); %> + <% } %> +<% }); %> + <% _.forEach(object.props, function(prop, index) { %> <% if (isStringType(prop.type)) { %> <%= generatePublicReturnTypeValue(prop.type, true) %> <%= _.snakeCase(prop.name) %>; diff --git a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.cc.tpl b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.cc.tpl index 69cfd02183..d464605df6 100644 --- a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.cc.tpl +++ b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.cc.tpl @@ -1,3 +1,6 @@ +<% if (className.endsWith('Event')) { %> +#include "include/plugin_api/<%= _.snakeCase(className) %>_init.h" +<% }%> namespace webf { <% _.forEach(object.props, function(prop, index) { %> @@ -67,5 +70,44 @@ WebFValue<<%= className %>, WebFPublicMethods> <%= className %>PublicMethods::Dy } } <% } %> +<% if (object.construct) { %> + <% if (object.construct.args.length >= 1 && object.construct.args.some(arg => arg.name === 'type')) { %> +WebFValue<<%= className %>, <%= className %>PublicMethods> ExecutingContextWebFMethods::Create<%= className %>(ExecutingContext* context, <%= object.construct.args.some(arg => arg.name === 'type') ? "const char* type": null %>, ExceptionState& exception_state) { + <% if (object.construct.args.some(arg => arg.name === 'type')) { %> + AtomicString type_atomic = AtomicString(context->ctx(), type); + <% } %> + + <%= className %>* event = <%= className %>::Create(context, <% if (object.construct.args.some(arg => arg.name === 'type')) { %>type_atomic, <% } %> exception_state); + + WebFValueStatus* status_block = event->KeepAlive(); + return WebFValue<<%= className %>, <%= className %>PublicMethods>(event, event-><%= _.camelCase(className) %>PublicMethods(), status_block); +}; + <% } %> + <% if (object.construct.args.length > 1) { %> +WebFValue<<%= className %>, <%= className %>PublicMethods> ExecutingContextWebFMethods::Create<%= className %>WithOptions(ExecutingContext* context, <%= generatePublicParametersTypeWithName(object.construct.args, true) %> ExceptionState& exception_state) { + <% if (object.construct.args.some(arg => arg.name === 'type')) { %> + AtomicString type_atomic = AtomicString(context->ctx(), type); + <% } %> + std::shared_ptr<<%= className %>Init> init_class = <%= className %>Init::Create(); + <% if(dependentClasses[className + 'Init']){ %> + <% _.forEach(dependentClasses[className + 'Init'].props, function (prop) { %> + <% if(isStringType(prop.type)) { %> + AtomicString <%=_.snakeCase(prop.name)%>_atomic = AtomicString(context->ctx(), init-><%=_.snakeCase(prop.name)%>); + init_class->set<%=_.upperFirst(prop.name)%>(<%=_.snakeCase(prop.name)%>_atomic); + <% } else if (isPointerType(prop.type)) { %> + init_class->set<%=_.upperFirst(prop.name)%>(init-><%=_.snakeCase(prop.name)%>.value); + <% } else { %> + init_class->set<%=_.upperFirst(prop.name)%>(init-><%=_.snakeCase(prop.name)%>); + <% } %> + <% }) %> + <% } %> + + <%= className %>* event = <%= className %>::Create(context, <% if (object.construct.args.some(arg => arg.name === 'type')) { %>type_atomic, init_class<% } %>, exception_state); + + WebFValueStatus* status_block = event->KeepAlive(); + return WebFValue<<%= className %>, <%= className %>PublicMethods>(event, event-><%= _.camelCase(className) %>PublicMethods(), status_block); + }; +<% } %> +<% } %> } // namespace webf diff --git a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.rs.tpl b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.rs.tpl index a7bc27575a..b3454e7fe7 100644 --- a/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.rs.tpl +++ b/bridge/scripts/code_generator/templates/idl_templates/plugin_api_templates/interface.rs.tpl @@ -282,3 +282,29 @@ impl <%= parentObject.name %>Methods for <%= className %> { } } <% }); %> + +<% if (object.construct) { %> +impl ExecutingContext { + pub fn create_<%= _.snakeCase(className) %>(&self, event_type: &str, exception_state: &ExceptionState) -> Result<<%= className %>, String> { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_<%= _.snakeCase(className) %>)(self.ptr, event_type_c_string.as_ptr(), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(<%= className %>::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } + + pub fn create_<%= _.snakeCase(className) %>_with_options(&self, event_type: &str, options: &<%= className %>Init, exception_state: &ExceptionState) -> Result<<%= className %>, String> { + let event_type_c_string = CString::new(event_type).unwrap(); + let new_event = unsafe { + ((*self.method_pointer).create_<%= _.snakeCase(className) %>_with_options)(self.ptr, event_type_c_string.as_ptr(), options, exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + return Ok(<%= className %>::initialize(new_event.value, self, new_event.method_pointer, new_event.status)); + } +} +<% } %>