From f17229e1ad274d521765f2f5843880b7b8660452 Mon Sep 17 00:00:00 2001 From: "AzureAD\\JiaxunWei" Date: Thu, 14 Nov 2024 09:23:12 +0100 Subject: [PATCH 01/19] WIP: native_value --- bridge/core/api/executing_context.cc | 68 ++ bridge/core/frame/module_callback.cc | 42 +- bridge/core/frame/module_callback.h | 58 +- bridge/core/frame/module_listener.cc | 42 +- bridge/core/frame/module_listener.h | 68 +- bridge/core/frame/module_manager.cc | 81 ++- bridge/core/frame/module_manager.h | 8 +- bridge/core/page.cc | 615 +++++++++--------- bridge/foundation/native_value.h | 22 - bridge/foundation/rust_readable.cc | 5 +- bridge/include/plugin_api/executing_context.h | 34 + bridge/rusty_webf_sys/Cargo.toml | 4 +- .../rusty_webf_sys/src/executing_context.rs | 33 + bridge/rusty_webf_sys/src/lib.rs | 2 + bridge/rusty_webf_sys/src/memory_utils.rs | 14 +- bridge/rusty_webf_sys/src/native_value.rs | 150 +++++ webf/example/rust_builder/rust/src/lib.rs | 16 +- 17 files changed, 786 insertions(+), 476 deletions(-) create mode 100644 bridge/rusty_webf_sys/src/native_value.rs diff --git a/bridge/core/api/executing_context.cc b/bridge/core/api/executing_context.cc index c189ca8607..6054e00e36 100644 --- a/bridge/core/api/executing_context.cc +++ b/bridge/core/api/executing_context.cc @@ -9,6 +9,8 @@ #include "core/executing_context.h" #include "core/frame/window.h" #include "core/frame/window_or_worker_global_scope.h" +#include "core/frame/module_manager.h" +#include "foundation/native_value_converter.h" namespace webf { @@ -32,6 +34,72 @@ void ExecutingContextWebFMethods::FinishRecordingUIOperations(webf::ExecutingCon context->uiCommandBuffer()->AddCommand(UICommand::kFinishRecordingCommand, nullptr, nullptr, nullptr, false); } +NativeValue ExecutingContextWebFMethods::WebFInvokeModule(ExecutingContext* context, + const char* module_name, + const char* method, + SharedExceptionState* shared_exception_state) { + AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); + AtomicString method_atomic = webf::AtomicString(context->ctx(), method); + + ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, shared_exception_state->exception_state); + NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); + + if (shared_exception_state->exception_state.HasException()) { + return Native_NewNull(); + } + + return return_result; +} + +NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParams(ExecutingContext* context, + const char* module_name, + const char* method, + NativeValue* params, + SharedExceptionState* shared_exception_state) { + AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); + AtomicString method_atomic = webf::AtomicString(context->ctx(), method); + + if (params->tag == NativeTag::TAG_LIST) { + NativeValue* ptr = static_cast(params->u.ptr); + auto value_xxx = NativeValueConverter::FromNativeValue(*ptr); + WEBF_LOG(VERBOSE) << "Value: " << value_xxx; + } + + ScriptValue params_value = ScriptValue(context->ctx(), *params); + + ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, params_value, shared_exception_state->exception_state); + NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); + + if (shared_exception_state->exception_state.HasException()) { + return Native_NewNull(); + } + + return return_result; +} + +NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParamsAndCallback(ExecutingContext* context, + const char* module_name, + const char* method, + NativeValue* params, + WebFNativeFunctionContext* callback_context, + SharedExceptionState* shared_exception_state) { + AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); + AtomicString method_atomic = webf::AtomicString(context->ctx(), method); + + ScriptValue params_value = ScriptValue(context->ctx(), *params); + + auto callback_impl = WebFNativeFunction::Create(callback_context, shared_exception_state); + + ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, params_value, callback_impl, shared_exception_state->exception_state); + NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); + + if (shared_exception_state->exception_state.HasException()) { + return Native_NewNull(); + } + + return return_result; +} + int32_t ExecutingContextWebFMethods::SetTimeout(ExecutingContext* context, WebFNativeFunctionContext* callback_context, int32_t timeout, diff --git a/bridge/core/frame/module_callback.cc b/bridge/core/frame/module_callback.cc index c05b11d52a..0557e90e21 100644 --- a/bridge/core/frame/module_callback.cc +++ b/bridge/core/frame/module_callback.cc @@ -1,21 +1,21 @@ -/* - * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ -#include "module_callback.h" - -#include - -namespace webf { - -std::shared_ptr ModuleCallback::Create(const std::shared_ptr& function) { - return std::make_shared(function); -} - -ModuleCallback::ModuleCallback(std::shared_ptr function) : function_(std::move(function)) {} - -std::shared_ptr ModuleCallback::value() { - return function_; -} - -} // namespace webf +/* + * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ +#include "module_callback.h" + +#include + +namespace webf { + +std::shared_ptr ModuleCallback::Create(const std::shared_ptr& function) { + return std::make_shared(function); +} + +ModuleCallback::ModuleCallback(std::shared_ptr function) : function_(std::move(function)) {} + +std::shared_ptr ModuleCallback::value() { + return function_; +} + +} // namespace webf diff --git a/bridge/core/frame/module_callback.h b/bridge/core/frame/module_callback.h index 7e7fbc4d7a..20e6e1e771 100644 --- a/bridge/core/frame/module_callback.h +++ b/bridge/core/frame/module_callback.h @@ -1,29 +1,29 @@ -/* - * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ -#ifndef BRIDGE_MODULE_CALLBACK_H -#define BRIDGE_MODULE_CALLBACK_H - -#include -#include "bindings/qjs/qjs_function.h" - -namespace webf { - -// ModuleCallback is an asynchronous callback function, usually from the 4th parameter of `webf.invokeModule` -// function. When the asynchronous operation on the Dart side ends, the callback is will called and to return to the JS -// executing environment. -class ModuleCallback { - public: - static std::shared_ptr Create(const std::shared_ptr& function); - explicit ModuleCallback(std::shared_ptr function); - - std::shared_ptr value(); - - private: - std::shared_ptr function_{nullptr}; -}; - -} // namespace webf - -#endif // BRIDGE_MODULE_CALLBACK_H +/* + * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ +#ifndef BRIDGE_MODULE_CALLBACK_H +#define BRIDGE_MODULE_CALLBACK_H + +#include +#include "bindings/qjs/qjs_function.h" + +namespace webf { + +// ModuleCallback is an asynchronous callback function, usually from the 4th parameter of `webf.invokeModule` +// function. When the asynchronous operation on the Dart side ends, the callback is will called and to return to the JS +// executing environment. +class ModuleCallback { + public: + static std::shared_ptr Create(const std::shared_ptr& function); + explicit ModuleCallback(std::shared_ptr function); + + std::shared_ptr value(); + + private: + std::shared_ptr function_{nullptr}; +}; + +} // namespace webf + +#endif // BRIDGE_MODULE_CALLBACK_H diff --git a/bridge/core/frame/module_listener.cc b/bridge/core/frame/module_listener.cc index 7ac104e7a6..570cf03bae 100644 --- a/bridge/core/frame/module_listener.cc +++ b/bridge/core/frame/module_listener.cc @@ -1,21 +1,21 @@ -/* - * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ -#include "module_listener.h" - -#include - -namespace webf { - -std::shared_ptr ModuleListener::Create(const std::shared_ptr& function) { - return std::make_shared(function); -} - -ModuleListener::ModuleListener(std::shared_ptr function) : function_(std::move(function)) {} - -const std::shared_ptr& ModuleListener::value() { - return function_; -} - -} // namespace webf +/* + * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ +#include "module_listener.h" + +#include + +namespace webf { + +std::shared_ptr ModuleListener::Create(const std::shared_ptr& function) { + return std::make_shared(function); +} + +ModuleListener::ModuleListener(std::shared_ptr function) : function_(std::move(function)) {} + +const std::shared_ptr& ModuleListener::value() { + return function_; +} + +} // namespace webf diff --git a/bridge/core/frame/module_listener.h b/bridge/core/frame/module_listener.h index d4e2afa15b..53b0de14eb 100644 --- a/bridge/core/frame/module_listener.h +++ b/bridge/core/frame/module_listener.h @@ -1,34 +1,34 @@ -/* - * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ -#ifndef BRIDGE_MODULE_LISTENER_H -#define BRIDGE_MODULE_LISTENER_H - -#include "bindings/qjs/qjs_function.h" - -namespace webf { - -class ModuleContextCoordinator; -class ModuleListenerContainer; - -// ModuleListener is an persistent callback function. Registered from user with `webf.addModuleListener` method. -// When module event triggered at dart side, All module listener will be invoked and let user to dispatch further -// operations. -class ModuleListener { - public: - static std::shared_ptr Create(const std::shared_ptr& function); - explicit ModuleListener(std::shared_ptr function); - - const std::shared_ptr& value(); - - private: - std::shared_ptr function_{nullptr}; - - friend ModuleListenerContainer; - friend ModuleContextCoordinator; -}; - -} // namespace webf - -#endif // BRIDGE_MODULE_LISTENER_H +/* + * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ +#ifndef BRIDGE_MODULE_LISTENER_H +#define BRIDGE_MODULE_LISTENER_H + +#include "bindings/qjs/qjs_function.h" + +namespace webf { + +class ModuleContextCoordinator; +class ModuleListenerContainer; + +// ModuleListener is an persistent callback function. Registered from user with `webf.addModuleListener` method. +// When module event triggered at dart side, All module listener will be invoked and let user to dispatch further +// operations. +class ModuleListener { + public: + static std::shared_ptr Create(const std::shared_ptr& function); + explicit ModuleListener(std::shared_ptr function); + + const std::shared_ptr& value(); + + private: + std::shared_ptr function_{nullptr}; + + friend ModuleListenerContainer; + friend ModuleContextCoordinator; +}; + +} // namespace webf + +#endif // BRIDGE_MODULE_LISTENER_H diff --git a/bridge/core/frame/module_manager.cc b/bridge/core/frame/module_manager.cc index 9384b7dd09..70d04aa07a 100644 --- a/bridge/core/frame/module_manager.cc +++ b/bridge/core/frame/module_manager.cc @@ -33,42 +33,57 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, if (ctx == nullptr) return nullptr; - context->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); - context->dartIsolateContext()->profiler()->StartTrackSteps("handleInvokeModuleTransientCallback"); - - ExceptionState exception_state; - - NativeValue* return_value = nullptr; - if (errmsg != nullptr) { - ScriptValue error_object = ScriptValue::CreateErrorObject(ctx, errmsg); - ScriptValue arguments[] = {error_object}; - ScriptValue result = moduleContext->callback->value()->Invoke(ctx, ScriptValue::Empty(ctx), 1, arguments); - if (result.IsException()) { - context->HandleException(&result); + auto callback_value = moduleContext->callback->value(); + + if (auto* callback = DynamicTo(callback_value.get())) { + context->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); + context->dartIsolateContext()->profiler()->StartTrackSteps("handleInvokeModuleTransientCallback"); + + ExceptionState exception_state; + + NativeValue* return_value = nullptr; + if (errmsg != nullptr) { + ScriptValue error_object = ScriptValue::CreateErrorObject(ctx, errmsg); + ScriptValue arguments[] = {error_object}; + ScriptValue result = callback->Invoke(ctx, ScriptValue::Empty(ctx), 1, arguments); + if (result.IsException()) { + context->HandleException(&result); + } + NativeValue native_result = result.ToNative(ctx, exception_state); + return_value = static_cast(malloc(sizeof(NativeValue))); + memcpy(return_value, &native_result, sizeof(NativeValue)); + } else { + ScriptValue arguments[] = {ScriptValue::Empty(ctx), ScriptValue(ctx, *extra_data)}; + ScriptValue result = callback->Invoke(ctx, ScriptValue::Empty(ctx), 2, arguments); + if (result.IsException()) { + context->HandleException(&result); + } + NativeValue native_result = result.ToNative(ctx, exception_state); + return_value = static_cast(malloc(sizeof(NativeValue))); + memcpy(return_value, &native_result, sizeof(NativeValue)); } - NativeValue native_result = result.ToNative(ctx, exception_state); - return_value = static_cast(malloc(sizeof(NativeValue))); - memcpy(return_value, &native_result, sizeof(NativeValue)); - } else { - ScriptValue arguments[] = {ScriptValue::Empty(ctx), ScriptValue(ctx, *extra_data)}; - ScriptValue result = moduleContext->callback->value()->Invoke(ctx, ScriptValue::Empty(ctx), 2, arguments); - if (result.IsException()) { - context->HandleException(&result); - } - NativeValue native_result = result.ToNative(ctx, exception_state); - return_value = static_cast(malloc(sizeof(NativeValue))); - memcpy(return_value, &native_result, sizeof(NativeValue)); - } - context->dartIsolateContext()->profiler()->FinishTrackSteps(); - context->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); + context->dartIsolateContext()->profiler()->FinishTrackSteps(); + context->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); - if (exception_state.HasException()) { - context->HandleException(exception_state); - return nullptr; + if (exception_state.HasException()) { + context->HandleException(exception_state); + return nullptr; + } + + return return_value; + } else if (auto* callback = DynamicTo(callback_value.get())) { + if (errmsg != nullptr) { + NativeValue error_object = Native_NewCString(errmsg); + callback->Invoke(context, 1, &error_object); + } else { + NativeValue* params = new NativeValue[2]; + params[0] = Native_NewNull(); + params[1] = *extra_data; + callback->Invoke(context, 2, params); + } } - return return_value; } static void ReturnResultToDart(Dart_PersistentHandle persistent_handle, @@ -134,7 +149,7 @@ ScriptValue ModuleManager::__webf_invoke_module__(ExecutingContext* context, const AtomicString& module_name, const AtomicString& method, ScriptValue& params_value, - const std::shared_ptr& callback, + const std::shared_ptr& callback, ExceptionState& exception) { NativeValue params = params_value.ToNative(context->ctx(), exception); @@ -190,7 +205,7 @@ NativeValue* ModuleManager::__webf_invoke_module__(ExecutingContext* context, void ModuleManager::__webf_add_module_listener__(ExecutingContext* context, const AtomicString& module_name, - const std::shared_ptr& handler, + const std::shared_ptr& handler, ExceptionState& exception) { auto listener = ModuleListener::Create(handler); context->ModuleListeners()->AddModuleListener(module_name, listener); diff --git a/bridge/core/frame/module_manager.h b/bridge/core/frame/module_manager.h index 5276dd68ed..bad40cf9a2 100644 --- a/bridge/core/frame/module_manager.h +++ b/bridge/core/frame/module_manager.h @@ -7,7 +7,7 @@ #include "bindings/qjs/atomic_string.h" #include "bindings/qjs/exception_state.h" -#include "bindings/qjs/qjs_function.h" +#include "foundation/function.h" #include "module_callback.h" #include @@ -37,17 +37,17 @@ class ModuleManager { const AtomicString& module_name, const AtomicString& method, ScriptValue& params_value, - const std::shared_ptr& callback, + const std::shared_ptr& callback, ExceptionState& exception); static NativeValue* __webf_invoke_module__(ExecutingContext* context, const AtomicString& module_name, const AtomicString& method, NativeValue& params_value, - const std::shared_ptr& callback, + const std::shared_ptr& callback, ExceptionState& exception); static void __webf_add_module_listener__(ExecutingContext* context, const AtomicString& module_name, - const std::shared_ptr& handler, + const std::shared_ptr& handler, ExceptionState& exception); static void __webf_remove_module_listener__(ExecutingContext* context, const AtomicString& module_name, diff --git a/bridge/core/page.cc b/bridge/core/page.cc index 6d04460dfd..f99fc30963 100644 --- a/bridge/core/page.cc +++ b/bridge/core/page.cc @@ -1,300 +1,319 @@ -/* - * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ -#include -#include - -#include "bindings/qjs/atomic_string.h" -#include "bindings/qjs/binding_initializer.h" -#include "core/dart_methods.h" -#include "core/dom/document.h" -#include "core/frame/window.h" -#include "core/html/html_html_element.h" -#include "core/html/parser/html_parser.h" -#include "event_factory.h" -#include "foundation/logging.h" -#include "foundation/native_value_converter.h" -#include "page.h" -#include "polyfill.h" - -namespace webf { - -ConsoleMessageHandler WebFPage::consoleMessageHandler{nullptr}; - -WebFPage::WebFPage(DartIsolateContext* dart_isolate_context, - bool is_dedicated, - size_t sync_buffer_size, - double context_id, - const JSExceptionHandler& handler) - : ownerThreadId(std::this_thread::get_id()), dart_isolate_context_(dart_isolate_context) { - context_ = new ExecutingContext( - dart_isolate_context, is_dedicated, sync_buffer_size, context_id, - [](ExecutingContext* context, const char* message) { - WEBF_LOG(ERROR) << message << std::endl; - if (context->IsContextValid()) { - context->dartMethodPtr()->onJSError(context->isDedicated(), context->contextId(), message); - } - }, - this); -} - -bool WebFPage::parseHTML(const char* code, size_t length) { - if (!context_->IsContextValid()) - return false; - - { - MemberMutationScope scope{context_}; - - auto document_element = context_->document()->documentElement(); - if (!document_element) { - return false; +/* + * Copyright (C) 2019-2022 The Kraken authors. All rights reserved. + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ +#include +#include + +#include "bindings/qjs/atomic_string.h" +#include "bindings/qjs/binding_initializer.h" +#include "core/dart_methods.h" +#include "core/dom/document.h" +#include "core/frame/window.h" +#include "core/html/html_html_element.h" +#include "core/html/parser/html_parser.h" +#include "event_factory.h" +#include "foundation/logging.h" +#include "foundation/native_value_converter.h" +#include "page.h" +#include "polyfill.h" + +namespace webf { + +ConsoleMessageHandler WebFPage::consoleMessageHandler{nullptr}; + +WebFPage::WebFPage(DartIsolateContext* dart_isolate_context, + bool is_dedicated, + size_t sync_buffer_size, + double context_id, + const JSExceptionHandler& handler) + : ownerThreadId(std::this_thread::get_id()), dart_isolate_context_(dart_isolate_context) { + context_ = new ExecutingContext( + dart_isolate_context, is_dedicated, sync_buffer_size, context_id, + [](ExecutingContext* context, const char* message) { + WEBF_LOG(ERROR) << message << std::endl; + if (context->IsContextValid()) { + context->dartMethodPtr()->onJSError(context->isDedicated(), context->contextId(), message); + } + }, + this); +} + +bool WebFPage::parseHTML(const char* code, size_t length) { + if (!context_->IsContextValid()) + return false; + + { + MemberMutationScope scope{context_}; + + auto document_element = context_->document()->documentElement(); + if (!document_element) { + return false; + } + + context_->dartIsolateContext()->profiler()->StartTrackSteps("HTMLParser::parseHTML"); + HTMLParser::parseHTML(code, length, context_->document()->documentElement()); + context_->dartIsolateContext()->profiler()->FinishTrackSteps(); + } + + context_->uiCommandBuffer()->AddCommand(UICommand::kFinishRecordingCommand, nullptr, nullptr, nullptr); + + return true; +} + +NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, + const char* eventType, + void* ptr, + NativeValue* extra) { + if (!context_->IsContextValid()) + return nullptr; + + MemberMutationScope scope{context_}; + + JSContext* ctx = context_->ctx(); + Event* event = nullptr; + if (ptr != nullptr) { + std::string type = std::string(eventType); + auto* raw_event = static_cast(ptr); + event = EventFactory::Create(context_, AtomicString(ctx, type), raw_event); + delete raw_event; + } + + ScriptValue extraObject = ScriptValue(ctx, const_cast(*extra)); + AtomicString module_name = AtomicString( + ctx, std::unique_ptr(reinterpret_cast(native_module_name))); + auto listener = context_->ModuleListeners()->listener(module_name); + + if (listener == nullptr) { + return nullptr; + } + + auto callback_value = listener->value(); + if (auto* callback = DynamicTo(callback_value.get())) { + ScriptValue arguments[] = {event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx), extraObject}; + ScriptValue result = callback->Invoke(ctx, ScriptValue::Empty(ctx), 2, arguments); + if (result.IsException()) { + context_->HandleException(&result); + return nullptr; + } + + ExceptionState exception_state; + auto* return_value = static_cast(malloc(sizeof(NativeValue))); + NativeValue tmp = result.ToNative(ctx, exception_state); + if (exception_state.HasException()) { + context_->HandleException(exception_state); + return nullptr; + } + + memcpy(return_value, &tmp, sizeof(NativeValue)); + return return_value; + } else if (auto* callback = DynamicTo(callback_value.get())) { + NativeValue* params = new NativeValue[2]; + + ExceptionState exception_state; + ScriptValue eventValue = event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx); + params[0] = eventValue.ToNative(ctx, exception_state); + params[1] = *extra; + + + if (exception_state.HasException()) { + context_->HandleException(exception_state); + return nullptr; } - - context_->dartIsolateContext()->profiler()->StartTrackSteps("HTMLParser::parseHTML"); - HTMLParser::parseHTML(code, length, context_->document()->documentElement()); - context_->dartIsolateContext()->profiler()->FinishTrackSteps(); + + callback->Invoke(context_, 2, params); + return nullptr; } - - context_->uiCommandBuffer()->AddCommand(UICommand::kFinishRecordingCommand, nullptr, nullptr, nullptr); - - return true; -} - -NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, - const char* eventType, - void* ptr, - NativeValue* extra) { - if (!context_->IsContextValid()) - return nullptr; - - MemberMutationScope scope{context_}; - - JSContext* ctx = context_->ctx(); - Event* event = nullptr; - if (ptr != nullptr) { - std::string type = std::string(eventType); - auto* raw_event = static_cast(ptr); - event = EventFactory::Create(context_, AtomicString(ctx, type), raw_event); - delete raw_event; - } - - ScriptValue extraObject = ScriptValue(ctx, const_cast(*extra)); - AtomicString module_name = AtomicString( - ctx, std::unique_ptr(reinterpret_cast(native_module_name))); - auto listener = context_->ModuleListeners()->listener(module_name); - - if (listener == nullptr) { - return nullptr; - } - - ScriptValue arguments[] = {event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx), extraObject}; - ScriptValue result = listener->value()->Invoke(ctx, ScriptValue::Empty(ctx), 2, arguments); - if (result.IsException()) { - context_->HandleException(&result); - return nullptr; - } - - ExceptionState exception_state; - auto* return_value = static_cast(malloc(sizeof(NativeValue))); - NativeValue tmp = result.ToNative(ctx, exception_state); - if (exception_state.HasException()) { - context_->HandleException(exception_state); - return nullptr; - } - - memcpy(return_value, &tmp, sizeof(NativeValue)); - return return_value; -} - -bool WebFPage::evaluateScript(const char* script, - uint64_t script_len, - uint8_t** parsed_bytecodes, - uint64_t* bytecode_len, - const char* url, - int startLine) { - if (!context_->IsContextValid()) - return false; - return context_->EvaluateJavaScript(script, script_len, parsed_bytecodes, bytecode_len, url, startLine); -} - -void WebFPage::evaluateScript(const char* script, size_t length, const char* url, int startLine) { - if (!context_->IsContextValid()) - return; - context_->EvaluateJavaScript(script, length, url, startLine); -} - -uint8_t* WebFPage::dumpByteCode(const char* script, size_t length, const char* url, uint64_t* byteLength) { - if (!context_->IsContextValid()) - return nullptr; - return context_->DumpByteCode(script, static_cast(length), url, byteLength); -} - -bool WebFPage::evaluateByteCode(uint8_t* bytes, size_t byteLength) { - if (!context_->IsContextValid()) - return false; - return context_->EvaluateByteCode(bytes, byteLength); -} - -std::thread::id WebFPage::currentThread() const { - return ownerThreadId; -} - -WebFPage::~WebFPage() { -#if IS_TEST - if (disposeCallback != nullptr) { - disposeCallback(this); - } -#endif - delete context_; -} - -void WebFPage::reportError(const char* errmsg) { - handler_(context_, errmsg); -} - -static void ReturnEvaluateScriptsInternal(Dart_PersistentHandle persistent_handle, - EvaluateQuickjsByteCodeCallback result_callback, - bool is_success) { - Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); - result_callback(handle, is_success ? 1 : 0); - Dart_DeletePersistentHandle_DL(persistent_handle); -} - -void WebFPage::EvaluateScriptsInternal(void* page_, - const char* code, - uint64_t code_len, - uint8_t** parsed_bytecodes, - uint64_t* bytecode_len, - const char* bundleFilename, - int32_t startLine, - int64_t profile_id, - Dart_Handle persistent_handle, - EvaluateScriptsCallback result_callback) { - auto page = reinterpret_cast(page_); - assert(std::this_thread::get_id() == page->currentThread()); - - page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); - - bool is_success = page->evaluateScript(code, code_len, parsed_bytecodes, bytecode_len, bundleFilename, startLine); - - page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); - - page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateScriptsInternal, - persistent_handle, result_callback, is_success); -} - -static void ReturnEvaluateQuickjsByteCodeResultToDart(Dart_PersistentHandle persistent_handle, - EvaluateQuickjsByteCodeCallback result_callback, - bool is_success) { - Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); - result_callback(handle, is_success ? 1 : 0); - Dart_DeletePersistentHandle_DL(persistent_handle); -} - -void WebFPage::EvaluateQuickjsByteCodeInternal(void* page_, - uint8_t* bytes, - int32_t byteLen, - int64_t profile_id, - Dart_PersistentHandle persistent_handle, - EvaluateQuickjsByteCodeCallback result_callback) { - auto page = reinterpret_cast(page_); - assert(std::this_thread::get_id() == page->currentThread()); - - page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); - - bool is_success = page->evaluateByteCode(bytes, byteLen); - - page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); - - page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateQuickjsByteCodeResultToDart, - persistent_handle, result_callback, is_success); -} - -static void ReturnParseHTMLToDart(Dart_PersistentHandle persistent_handle, ParseHTMLCallback result_callback) { - Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); - result_callback(handle); - Dart_DeletePersistentHandle_DL(persistent_handle); -} - -void WebFPage::ParseHTMLInternal(void* page_, - char* code, - int32_t length, - int64_t profile_id, - Dart_PersistentHandle dart_handle, - ParseHTMLCallback result_callback) { - auto page = reinterpret_cast(page_); - assert(std::this_thread::get_id() == page->currentThread()); - - page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); - - page->parseHTML(code, length); - dart_free(code); - - page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); - - page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnParseHTMLToDart, dart_handle, - result_callback); -} - -static void ReturnInvokeEventResultToDart(Dart_Handle persistent_handle, - InvokeModuleEventCallback result_callback, - webf::NativeValue* result) { - Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); - result_callback(handle, result); - Dart_DeletePersistentHandle_DL(persistent_handle); -} - -void WebFPage::InvokeModuleEventInternal(void* page_, - void* module_name, - const char* eventType, - void* event, - void* extra, - Dart_Handle persistent_handle, - InvokeModuleEventCallback result_callback) { - auto page = reinterpret_cast(page_); - auto dart_isolate_context = page->executingContext()->dartIsolateContext(); - assert(std::this_thread::get_id() == page->currentThread()); - - page->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); - - auto* result = page->invokeModuleEvent(reinterpret_cast(module_name), eventType, event, - reinterpret_cast(extra)); - - page->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); - - dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnInvokeEventResultToDart, persistent_handle, - result_callback, result); -} - -static void ReturnDumpByteCodeResultToDart(Dart_Handle persistent_handle, DumpQuickjsByteCodeCallback result_callback) { - Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); - result_callback(handle); - Dart_DeletePersistentHandle_DL(persistent_handle); -} - -void WebFPage::DumpQuickJsByteCodeInternal(void* page_, - int64_t profile_id, - const char* code, - int32_t code_len, - uint8_t** parsed_bytecodes, - uint64_t* bytecode_len, - const char* url, - Dart_PersistentHandle persistent_handle, - DumpQuickjsByteCodeCallback result_callback) { - auto page = reinterpret_cast(page_); - auto dart_isolate_context = page->executingContext()->dartIsolateContext(); - - dart_isolate_context->profiler()->StartTrackEvaluation(profile_id); - - assert(std::this_thread::get_id() == page->currentThread()); - uint8_t* bytes = page->dumpByteCode(code, code_len, url, bytecode_len); - *parsed_bytecodes = bytes; - - dart_isolate_context->profiler()->FinishTrackEvaluation(profile_id); - - dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnDumpByteCodeResultToDart, persistent_handle, - result_callback); -} - -} // namespace webf +} + +bool WebFPage::evaluateScript(const char* script, + uint64_t script_len, + uint8_t** parsed_bytecodes, + uint64_t* bytecode_len, + const char* url, + int startLine) { + if (!context_->IsContextValid()) + return false; + return context_->EvaluateJavaScript(script, script_len, parsed_bytecodes, bytecode_len, url, startLine); +} + +void WebFPage::evaluateScript(const char* script, size_t length, const char* url, int startLine) { + if (!context_->IsContextValid()) + return; + context_->EvaluateJavaScript(script, length, url, startLine); +} + +uint8_t* WebFPage::dumpByteCode(const char* script, size_t length, const char* url, uint64_t* byteLength) { + if (!context_->IsContextValid()) + return nullptr; + return context_->DumpByteCode(script, static_cast(length), url, byteLength); +} + +bool WebFPage::evaluateByteCode(uint8_t* bytes, size_t byteLength) { + if (!context_->IsContextValid()) + return false; + return context_->EvaluateByteCode(bytes, byteLength); +} + +std::thread::id WebFPage::currentThread() const { + return ownerThreadId; +} + +WebFPage::~WebFPage() { +#if IS_TEST + if (disposeCallback != nullptr) { + disposeCallback(this); + } +#endif + delete context_; +} + +void WebFPage::reportError(const char* errmsg) { + handler_(context_, errmsg); +} + +static void ReturnEvaluateScriptsInternal(Dart_PersistentHandle persistent_handle, + EvaluateQuickjsByteCodeCallback result_callback, + bool is_success) { + Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); + result_callback(handle, is_success ? 1 : 0); + Dart_DeletePersistentHandle_DL(persistent_handle); +} + +void WebFPage::EvaluateScriptsInternal(void* page_, + const char* code, + uint64_t code_len, + uint8_t** parsed_bytecodes, + uint64_t* bytecode_len, + const char* bundleFilename, + int32_t startLine, + int64_t profile_id, + Dart_Handle persistent_handle, + EvaluateScriptsCallback result_callback) { + auto page = reinterpret_cast(page_); + assert(std::this_thread::get_id() == page->currentThread()); + + page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); + + bool is_success = page->evaluateScript(code, code_len, parsed_bytecodes, bytecode_len, bundleFilename, startLine); + + page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); + + page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateScriptsInternal, + persistent_handle, result_callback, is_success); +} + +static void ReturnEvaluateQuickjsByteCodeResultToDart(Dart_PersistentHandle persistent_handle, + EvaluateQuickjsByteCodeCallback result_callback, + bool is_success) { + Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); + result_callback(handle, is_success ? 1 : 0); + Dart_DeletePersistentHandle_DL(persistent_handle); +} + +void WebFPage::EvaluateQuickjsByteCodeInternal(void* page_, + uint8_t* bytes, + int32_t byteLen, + int64_t profile_id, + Dart_PersistentHandle persistent_handle, + EvaluateQuickjsByteCodeCallback result_callback) { + auto page = reinterpret_cast(page_); + assert(std::this_thread::get_id() == page->currentThread()); + + page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); + + bool is_success = page->evaluateByteCode(bytes, byteLen); + + page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); + + page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateQuickjsByteCodeResultToDart, + persistent_handle, result_callback, is_success); +} + +static void ReturnParseHTMLToDart(Dart_PersistentHandle persistent_handle, ParseHTMLCallback result_callback) { + Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); + result_callback(handle); + Dart_DeletePersistentHandle_DL(persistent_handle); +} + +void WebFPage::ParseHTMLInternal(void* page_, + char* code, + int32_t length, + int64_t profile_id, + Dart_PersistentHandle dart_handle, + ParseHTMLCallback result_callback) { + auto page = reinterpret_cast(page_); + assert(std::this_thread::get_id() == page->currentThread()); + + page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); + + page->parseHTML(code, length); + dart_free(code); + + page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); + + page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnParseHTMLToDart, dart_handle, + result_callback); +} + +static void ReturnInvokeEventResultToDart(Dart_Handle persistent_handle, + InvokeModuleEventCallback result_callback, + webf::NativeValue* result) { + Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); + result_callback(handle, result); + Dart_DeletePersistentHandle_DL(persistent_handle); +} + +void WebFPage::InvokeModuleEventInternal(void* page_, + void* module_name, + const char* eventType, + void* event, + void* extra, + Dart_Handle persistent_handle, + InvokeModuleEventCallback result_callback) { + auto page = reinterpret_cast(page_); + auto dart_isolate_context = page->executingContext()->dartIsolateContext(); + assert(std::this_thread::get_id() == page->currentThread()); + + page->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); + + auto* result = page->invokeModuleEvent(reinterpret_cast(module_name), eventType, event, + reinterpret_cast(extra)); + + page->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); + + dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnInvokeEventResultToDart, persistent_handle, + result_callback, result); +} + +static void ReturnDumpByteCodeResultToDart(Dart_Handle persistent_handle, DumpQuickjsByteCodeCallback result_callback) { + Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle); + result_callback(handle); + Dart_DeletePersistentHandle_DL(persistent_handle); +} + +void WebFPage::DumpQuickJsByteCodeInternal(void* page_, + int64_t profile_id, + const char* code, + int32_t code_len, + uint8_t** parsed_bytecodes, + uint64_t* bytecode_len, + const char* url, + Dart_PersistentHandle persistent_handle, + DumpQuickjsByteCodeCallback result_callback) { + auto page = reinterpret_cast(page_); + auto dart_isolate_context = page->executingContext()->dartIsolateContext(); + + dart_isolate_context->profiler()->StartTrackEvaluation(profile_id); + + assert(std::this_thread::get_id() == page->currentThread()); + uint8_t* bytes = page->dumpByteCode(code, code_len, url, bytecode_len); + *parsed_bytecodes = bytes; + + dart_isolate_context->profiler()->FinishTrackEvaluation(profile_id); + + dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnDumpByteCodeResultToDart, persistent_handle, + result_callback); +} + +} // namespace webf diff --git a/bridge/foundation/native_value.h b/bridge/foundation/native_value.h index be7ffdd164..c55499a8d0 100644 --- a/bridge/foundation/native_value.h +++ b/bridge/foundation/native_value.h @@ -46,28 +46,6 @@ struct NativeValue : public DartReadable { int32_t tag; }; -struct NativeFunctionContext; - -using CallNativeFunction = void (*)(NativeFunctionContext* functionContext, - int32_t argc, - NativeValue* argv, - NativeValue* returnValue); - -static void call_native_function(NativeFunctionContext* functionContext, - int32_t argc, - NativeValue* argv, - NativeValue* returnValue); - -struct NativeFunctionContext { - CallNativeFunction call; - NativeFunctionContext(ExecutingContext* context, JSValue callback); - ~NativeFunctionContext(); - JSValue m_callback{JS_NULL}; - ExecutingContext* m_context{nullptr}; - JSContext* m_ctx{nullptr}; - list_head link; -}; - NativeValue Native_NewNull(); NativeValue Native_NewString(SharedNativeString* string); NativeValue Native_NewCString(const std::string& string); diff --git a/bridge/foundation/rust_readable.cc b/bridge/foundation/rust_readable.cc index 8fcb9d21ce..7e00eba7b2 100644 --- a/bridge/foundation/rust_readable.cc +++ b/bridge/foundation/rust_readable.cc @@ -14,7 +14,7 @@ namespace webf { void* RustReadable::operator new(std::size_t size) { #if defined(_WIN32) - return HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, size); + return CoTaskMemAlloc(size); #else return malloc(size); #endif @@ -22,8 +22,9 @@ void* RustReadable::operator new(std::size_t size) { void RustReadable::operator delete(void* memory) noexcept { #if defined(_WIN32) - HeapFree(GetProcessHeap(), 0, memory); + return CoTaskMemFree(memory); #else + return free(memory); #endif } diff --git a/bridge/include/plugin_api/executing_context.h b/bridge/include/plugin_api/executing_context.h index 9eeebffe91..152065b7bb 100644 --- a/bridge/include/plugin_api/executing_context.h +++ b/bridge/include/plugin_api/executing_context.h @@ -5,6 +5,7 @@ #ifndef WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ #define WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ +#include "foundation/native_value.h" #include "core/native/native_function.h" #include "document.h" #include "exception_state.h" @@ -20,6 +21,21 @@ using PublicContextGetDocument = WebFValue (*)( using PublicContextGetWindow = WebFValue (*)(ExecutingContext*); using PublicContextGetExceptionState = WebFValue (*)(); using PublicFinishRecordingUIOperations = void (*)(ExecutingContext* context); +using PublicWebFInvokeModule = NativeValue (*)(ExecutingContext*, + const char*, + const char*, + SharedExceptionState*); +using PublicWebFInvokeModuleWithParams = NativeValue (*)(ExecutingContext*, + const char*, + const char*, + NativeValue*, + SharedExceptionState*); +using PublicWebFInvokeModuleWithParamsAndCallback = NativeValue (*)(ExecutingContext*, + const char*, + const char*, + NativeValue*, + WebFNativeFunctionContext*, + SharedExceptionState*); using PublicContextSetTimeout = int32_t (*)(ExecutingContext*, WebFNativeFunctionContext*, int32_t, @@ -38,6 +54,21 @@ struct ExecutingContextWebFMethods { static WebFValue window(ExecutingContext* context); static WebFValue CreateExceptionState(); static void FinishRecordingUIOperations(ExecutingContext* context); + static NativeValue WebFInvokeModule(ExecutingContext* context, + const char* module_name, + const char* method, + SharedExceptionState* shared_exception_state); + static NativeValue WebFInvokeModuleWithParams(ExecutingContext* context, + const char* module_name, + const char* method, + NativeValue* params, + SharedExceptionState* shared_exception_state); + static NativeValue WebFInvokeModuleWithParamsAndCallback(ExecutingContext* context, + const char* module_name, + const char* method, + NativeValue* params, + WebFNativeFunctionContext* callback_context, + SharedExceptionState* shared_exception_state); static int32_t SetTimeout(ExecutingContext* context, WebFNativeFunctionContext* callback_context, int32_t timeout, @@ -56,6 +87,9 @@ struct ExecutingContextWebFMethods { PublicContextGetWindow context_get_window{window}; PublicContextGetExceptionState context_get_exception_state{CreateExceptionState}; PublicFinishRecordingUIOperations context_finish_recording_ui_operations{FinishRecordingUIOperations}; + PublicWebFInvokeModule context_webf_invoke_module{WebFInvokeModule}; + PublicWebFInvokeModuleWithParams context_webf_invoke_module_with_params{WebFInvokeModuleWithParams}; + PublicWebFInvokeModuleWithParamsAndCallback context_webf_invoke_module_with_params_and_callback{WebFInvokeModuleWithParamsAndCallback}; PublicContextSetTimeout context_set_timeout{SetTimeout}; PublicContextSetInterval context_set_interval{SetInterval}; PublicContextClearTimeout context_clear_timeout{ClearTimeout}; diff --git a/bridge/rusty_webf_sys/Cargo.toml b/bridge/rusty_webf_sys/Cargo.toml index 4fe851bce0..633aca08d0 100644 --- a/bridge/rusty_webf_sys/Cargo.toml +++ b/bridge/rusty_webf_sys/Cargo.toml @@ -15,5 +15,5 @@ libc = "0.2.0" [dependencies.windows] version = "0.58.0" features = [ - "Win32_System_Memory" -] \ No newline at end of file + "Win32_System_Com", +] diff --git a/bridge/rusty_webf_sys/src/executing_context.rs b/bridge/rusty_webf_sys/src/executing_context.rs index 82253e7ca8..608069f992 100644 --- a/bridge/rusty_webf_sys/src/executing_context.rs +++ b/bridge/rusty_webf_sys/src/executing_context.rs @@ -3,6 +3,8 @@ */ use std::ffi::*; +use native_value::NativeValue; + use crate::*; #[repr(C)] @@ -12,6 +14,9 @@ pub struct ExecutingContextRustMethods { pub get_window: extern "C" fn(*const OpaquePtr) -> RustValue, pub create_exception_state: extern "C" fn() -> RustValue, pub finish_recording_ui_operations: extern "C" fn(executing_context: *const OpaquePtr) -> c_void, + pub webf_invoke_module: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, exception_state: *const OpaquePtr) -> NativeValue, + pub webf_invoke_module_with_params: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, params: *const NativeValue, exception_state: *const OpaquePtr) -> NativeValue, + pub webf_invoke_module_with_params_and_callback: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, params: *const NativeValue, exception_state: *const OpaquePtr) -> NativeValue, pub set_timeout: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, c_int, *const OpaquePtr) -> c_int, pub set_interval: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, c_int, *const OpaquePtr) -> c_int, pub clear_timeout: extern "C" fn(*const OpaquePtr, c_int, *const OpaquePtr), @@ -81,6 +86,34 @@ impl ExecutingContext { ExceptionState::initialize(result.value, result.method_pointer) } + pub fn webf_invoke_module(&self, module_name: &str, method: &str, exception_state: &ExceptionState) -> Result { + let module_name = CString::new(module_name).unwrap(); + let method = CString::new(method).unwrap(); + let result = unsafe { + ((*self.method_pointer).webf_invoke_module)(self.ptr, module_name.as_ptr(), method.as_ptr(), exception_state.ptr) + }; + + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + + Ok(result) + } + + pub fn webf_invoke_module_with_params(&self, module_name: &str, method: &str, params: &NativeValue, exception_state: &ExceptionState) -> Result { + let module_name = CString::new(module_name).unwrap(); + let method = CString::new(method).unwrap(); + let result = unsafe { + ((*self.method_pointer).webf_invoke_module_with_params)(self.ptr, module_name.as_ptr(), method.as_ptr(), params, exception_state.ptr) + }; + + if exception_state.has_exception() { + return Err(exception_state.stringify(self)); + } + + Ok(result) + } + pub fn set_timeout_with_callback(&self, callback: TimeoutCallback, exception_state: &ExceptionState) -> Result { self.set_timeout_with_callback_and_timeout(callback, 0, exception_state) } diff --git a/bridge/rusty_webf_sys/src/lib.rs b/bridge/rusty_webf_sys/src/lib.rs index ca4ac50867..8f1e0413c7 100644 --- a/bridge/rusty_webf_sys/src/lib.rs +++ b/bridge/rusty_webf_sys/src/lib.rs @@ -52,6 +52,7 @@ pub mod ui_event_init; pub mod webf_event_listener; pub mod webf_function; mod memory_utils; +pub mod native_value; pub use executing_context::*; pub use document::*; @@ -101,6 +102,7 @@ pub use transition_event_init::*; pub use ui_event_init::*; pub use webf_event_listener::*; pub use webf_function::*; +pub use native_value::*; #[repr(C)] pub struct OpaquePtr; diff --git a/bridge/rusty_webf_sys/src/memory_utils.rs b/bridge/rusty_webf_sys/src/memory_utils.rs index 22a447eb2d..9e354067d7 100644 --- a/bridge/rusty_webf_sys/src/memory_utils.rs +++ b/bridge/rusty_webf_sys/src/memory_utils.rs @@ -1,21 +1,17 @@ -#[cfg(target_os = "windows")] -use windows::Win32; -use libc; use crate::OpaquePtr; +use libc; +#[cfg(target_os = "windows")] +use windows::Win32::System::Com::CoTaskMemFree; pub fn safe_free_cpp_ptr(ptr: *const T) { unsafe { if cfg!(target_os = "windows") { #[cfg(target_os = "windows")] { - Win32::System::Memory::HeapFree( - Win32::System::Memory::GetProcessHeap().unwrap(), - Win32::System::Memory::HEAP_FLAGS(0), - Option::from(ptr as *const libc::c_void) - ).expect("Failed to call HeapFree"); + CoTaskMemFree(Option::from(ptr as *const libc::c_void)); } } else { libc::free(ptr.cast_mut() as *mut libc::c_void); } } -} \ No newline at end of file +} diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs new file mode 100644 index 0000000000..69dd45ac1b --- /dev/null +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -0,0 +1,150 @@ +use std::ffi::*; +use std::mem; +#[cfg(target_os = "windows")] +use windows::Win32::System::Com::{CoTaskMemAlloc, CoTaskMemFree}; + +use crate::memory_utils::safe_free_cpp_ptr; + +#[repr(C)] +pub enum NativeTag { + TagString = 0, + TagInt = 1, + TagBool = 2, + TagNull = 3, + TagFloat64 = 4, + TagJson = 5, + TagList = 6, + TagPointer = 7, + TagFunction = 8, + TagAsyncFunction = 9, + TagUint8Bytes = 10, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub union ValueField { + pub int64: i64, + pub float64: f64, + pub ptr: *mut c_void, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct NativeValue { + pub u: ValueField, + pub uint32: u32, + pub tag: i32, +} + +#[repr(C)] +pub struct SharedNativeString { + pub string_: *mut u16, + pub length_: u32, +} + +impl NativeValue { + pub fn new() -> Self { + let size = mem::size_of::(); + + #[cfg(target_os = "windows")] + let ptr = unsafe { CoTaskMemAlloc(size) }; + + #[cfg(not(target_os = "windows"))] + let ptr = unsafe { libc::malloc(size) }; + + let ptr = ptr as *mut NativeValue; + let value = unsafe { ptr.read() }; + value + } + + pub fn new_string(val: &str) -> Self { + let len = val.len(); + let size = len * mem::size_of::(); + + #[cfg(target_os = "windows")] + let ptr = unsafe { CoTaskMemAlloc(size) }; + + #[cfg(not(target_os = "windows"))] + let ptr = unsafe { libc::malloc(size) }; + + let ptr = ptr as *mut u16; + + for (i, c) in val.encode_utf16().enumerate() { + unsafe { + ptr.add(i).write(c); + } + } + + let mut value = Self::new(); + value.tag = NativeTag::TagString as i32; + value.u.ptr = ptr as *mut c_void; + value.uint32 = len as u32; + value + } + + pub fn to_string(&self) -> String { + let ptr = unsafe { + self.u.ptr as *mut SharedNativeString + }; + let string_struct = unsafe { ptr.read() }; + let slice = unsafe { std::slice::from_raw_parts(string_struct.string_, string_struct.length_.try_into().unwrap()) }; + String::from_utf16_lossy(slice) + } + + pub fn new_null() -> Self { + let mut value = Self::new(); + value.tag = NativeTag::TagNull as i32; + value.u.int64 = 0; + value.uint32 = 0; + value + } + + pub fn new_float64(val: f64) -> Self { + let mut value = Self::new(); + value.tag = NativeTag::TagFloat64 as i32; + value.u.float64 = val; + value.uint32 = 0; + value + } + + pub fn new_bool(val: bool) -> Self { + let mut value = Self::new(); + value.tag = NativeTag::TagBool as i32; + value.u.int64 = if val { 1 } else { 0 }; + value.uint32 = 0; + value + } + + pub fn new_int64(val: i64) -> Self { + let mut value = Self::new(); + value.tag = NativeTag::TagInt as i32; + value.u.int64 = val; + value.uint32 = 0; + value + } + + pub fn new_list(values: Vec) -> Self { + let size = values.len(); + let array_size = size * mem::size_of::(); + + #[cfg(target_os = "windows")] + let array_ptr = unsafe { CoTaskMemAlloc(array_size) }; + + #[cfg(not(target_os = "windows"))] + let array_ptr = unsafe { libc::malloc(array_size) }; + + let array_ptr = array_ptr as *mut NativeValue; + + for (i, val) in values.iter().enumerate() { + unsafe { + array_ptr.add(i).write(*val); + } + } + + let mut value = Self::new(); + value.tag = NativeTag::TagList as i32; + value.u.ptr = array_ptr as *mut c_void; + value.uint32 = size as u32; + value + } +} diff --git a/webf/example/rust_builder/rust/src/lib.rs b/webf/example/rust_builder/rust/src/lib.rs index 5fd63f752d..b30c9cfa1d 100644 --- a/webf/example/rust_builder/rust/src/lib.rs +++ b/webf/example/rust_builder/rust/src/lib.rs @@ -1,7 +1,7 @@ use std::ffi::{c_void, CString}; use webf_sys::event::Event; use webf_sys::executing_context::ExecutingContextRustMethods; -use webf_sys::{element, initialize_webf_api, AddEventListenerOptions, EventMethods, EventTargetMethods, RustValue}; +use webf_sys::{element, initialize_webf_api, AddEventListenerOptions, EventMethods, EventTargetMethods, NativeValue, RustValue}; use webf_sys::element::Element; use webf_sys::node::NodeMethods; @@ -12,6 +12,20 @@ pub extern "C" fn init_webf_app(handle: RustValue) let exception_state = context.create_exception_state(); let document = context.document(); + let param1 = NativeValue::new_bool(true); + let param2 = NativeValue::new_bool(true); + let param3 = NativeValue::new_bool(true); + let param4 = NativeValue::new_bool(true); + + let params_vec = vec![param1, param2, param3, param4]; + let params = NativeValue::new_list(params_vec); + + let ua_string = context.webf_invoke_module_with_params("Navigator", "getUserAgent", ¶ms, &exception_state).unwrap(); + + let ua_string = ua_string.to_string(); + + println!("User Agent: {}", ua_string); + let timer_callback = Box::new(move || { println!("Timer Callback"); }); From 43f2005c7c55015482cca18a7ad00d3ddd7aae76 Mon Sep 17 00:00:00 2001 From: andycall Date: Sat, 23 Nov 2024 23:14:40 +0800 Subject: [PATCH 02/19] fix: fix crashed due to windows malloc. --- bridge/foundation/dart_readable.cc | 9 ++++++ bridge/foundation/dart_readable.h | 50 ++++++++++++++++-------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/bridge/foundation/dart_readable.cc b/bridge/foundation/dart_readable.cc index 07f76e650a..73801a83b2 100644 --- a/bridge/foundation/dart_readable.cc +++ b/bridge/foundation/dart_readable.cc @@ -32,8 +32,17 @@ void* DartReadable::operator new(std::size_t size) { return dart_malloc(size); } +void* DartReadable::operator new[](std::size_t size) { + return dart_malloc(size); +} + void DartReadable::operator delete(void* memory) noexcept { dart_free(memory); } +void DartReadable::operator delete[](void* memory) noexcept { + dart_free(memory); +} + + } // namespace webf diff --git a/bridge/foundation/dart_readable.h b/bridge/foundation/dart_readable.h index 636c810487..fcc58bdc8c 100644 --- a/bridge/foundation/dart_readable.h +++ b/bridge/foundation/dart_readable.h @@ -1,24 +1,26 @@ -/* - * Copyright (C) 2022-present The WebF authors. All rights reserved. - */ - -#ifndef WEBF_DART_READABLE_H -#define WEBF_DART_READABLE_H - -#include - -namespace webf { - -void* dart_malloc(std::size_t size); -void dart_free(void* ptr); - -// Shared C struct which can be read by dart through Dart FFI. -struct DartReadable { - // Dart FFI use ole32 as it's allocator, we need to override the default allocator to compact with Dart FFI. - static void* operator new(std::size_t size); - static void operator delete(void* memory) noexcept; -}; - -} // namespace webf - -#endif // WEBF_DART_READABLE_H +/* + * Copyright (C) 2022-present The WebF authors. All rights reserved. + */ + +#ifndef WEBF_DART_READABLE_H +#define WEBF_DART_READABLE_H + +#include + +namespace webf { + +void* dart_malloc(std::size_t size); +void dart_free(void* ptr); + +// Shared C struct which can be read by dart through Dart FFI. +struct DartReadable { + // Dart FFI use ole32 as it's allocator, we need to override the default allocator to compact with Dart FFI. + static void* operator new(std::size_t size); + static void* operator new[](std::size_t size); + static void operator delete(void* memory) noexcept; + static void operator delete[](void* memory) noexcept; +}; + +} // namespace webf + +#endif // WEBF_DART_READABLE_H From 86df9c99dae1cef71cea3cc3e6956072f9cdf43c Mon Sep 17 00:00:00 2001 From: "AzureAD\\JiaxunWei" Date: Sun, 1 Dec 2024 18:53:37 +0800 Subject: [PATCH 03/19] feat: native value support in rust --- bridge/core/api/executing_context.cc | 18 ++++-------------- bridge/core/frame/module_manager.cc | 10 +++++----- bridge/rusty_webf_sys/src/native_value.rs | 12 ++++++++++++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bridge/core/api/executing_context.cc b/bridge/core/api/executing_context.cc index 6054e00e36..1c71554082 100644 --- a/bridge/core/api/executing_context.cc +++ b/bridge/core/api/executing_context.cc @@ -59,21 +59,13 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParams(ExecutingCon AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); AtomicString method_atomic = webf::AtomicString(context->ctx(), method); - if (params->tag == NativeTag::TAG_LIST) { - NativeValue* ptr = static_cast(params->u.ptr); - auto value_xxx = NativeValueConverter::FromNativeValue(*ptr); - WEBF_LOG(VERBOSE) << "Value: " << value_xxx; - } - - ScriptValue params_value = ScriptValue(context->ctx(), *params); - - ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, params_value, shared_exception_state->exception_state); - NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); + const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, nullptr, shared_exception_state->exception_state); if (shared_exception_state->exception_state.HasException()) { return Native_NewNull(); } + NativeValue return_result = *result; return return_result; } @@ -86,17 +78,15 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParamsAndCallback(E AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); AtomicString method_atomic = webf::AtomicString(context->ctx(), method); - ScriptValue params_value = ScriptValue(context->ctx(), *params); - auto callback_impl = WebFNativeFunction::Create(callback_context, shared_exception_state); - ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, params_value, callback_impl, shared_exception_state->exception_state); - NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); + const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, callback_impl, shared_exception_state->exception_state); if (shared_exception_state->exception_state.HasException()) { return Native_NewNull(); } + NativeValue return_result = *result; return return_result; } diff --git a/bridge/core/frame/module_manager.cc b/bridge/core/frame/module_manager.cc index 70d04aa07a..9890f17e26 100644 --- a/bridge/core/frame/module_manager.cc +++ b/bridge/core/frame/module_manager.cc @@ -163,11 +163,11 @@ ScriptValue ModuleManager::__webf_invoke_module__(ExecutingContext* context, return return_value; } NativeValue* ModuleManager::__webf_invoke_module__(ExecutingContext* context, - const AtomicString& module_name, - const AtomicString& method, - NativeValue& params, - const std::shared_ptr& callback, - ExceptionState& exception) { + const AtomicString& module_name, + const AtomicString& method, + NativeValue& params, + const std::shared_ptr& callback, + ExceptionState& exception) { if (exception.HasException()) { return nullptr; } diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index 69dd45ac1b..607af7602d 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -147,4 +147,16 @@ impl NativeValue { value.uint32 = size as u32; value } + + pub fn to_list(&self) -> Vec { + let mut values = Vec::new(); + let ptr = unsafe { + self.u.ptr as *mut NativeValue + }; + for i in 0..self.uint32 { + let val = unsafe { ptr.add(i).read() }; + values.push(val); + } + values + } } From 697c3a778f1165b9e82a0ca7d5a4d9beffd120b5 Mon Sep 17 00:00:00 2001 From: "AzureAD\\JiaxunWei" Date: Sun, 1 Dec 2024 20:09:01 +0800 Subject: [PATCH 04/19] feat: update rs code gen path --- .../src/{ => dom}/character_data.rs | 0 .../rusty_webf_sys/src/{ => dom}/comment.rs | 0 .../src/{ => dom}/container_node.rs | 0 .../rusty_webf_sys/src/{ => dom}/document.rs | 0 .../src/{ => dom}/document_fragment.rs | 0 .../rusty_webf_sys/src/{ => dom}/element.rs | 0 .../events}/add_event_listener_options.rs | 26 +- .../src/{ => dom/events}/custom_event.rs | 240 +++--- .../src/{ => dom/events}/event.rs | 736 +++++++++--------- .../src/{ => dom/events}/event_init.rs | 26 +- .../events}/event_listener_options.rs | 22 +- .../src/{ => dom/events}/event_target.rs | 0 bridge/rusty_webf_sys/src/dom/events/mod.rs | 16 + bridge/rusty_webf_sys/src/dom/mod.rs | 26 + bridge/rusty_webf_sys/src/{ => dom}/node.rs | 0 .../src/{ => dom}/scroll_options.rs | 22 +- .../src/{ => dom}/scroll_to_options.rs | 26 +- bridge/rusty_webf_sys/src/{ => dom}/text.rs | 0 .../src/{ => events}/animation_event.rs | 260 +++---- .../src/{ => events}/animation_event_init.rs | 32 +- .../src/{ => events}/close_event.rs | 258 +++--- .../src/{ => events}/close_event_init.rs | 32 +- .../src/{ => events}/focus_event.rs | 240 +++--- .../src/{ => events}/focus_event_init.rs | 28 +- .../src/{ => events}/gesture_event.rs | 370 ++++----- .../src/{ => events}/gesture_event_init.rs | 42 +- .../src/{ => events}/hashchange_event.rs | 238 +++--- .../src/{ => events}/hashchange_event_init.rs | 30 +- .../src/{ => events}/input_event.rs | 266 +++---- .../src/{ => events}/input_event_init.rs | 30 +- .../{ => events}/intersection_change_event.rs | 212 ++--- .../intersection_change_event_init.rs | 28 +- .../src/{ => events}/keyboard_event_init.rs | 48 +- bridge/rusty_webf_sys/src/events/mod.rs | 50 ++ .../src/{ => events}/mouse_event.rs | 306 ++++---- .../src/{ => events}/mouse_event_init.rs | 26 +- .../src/{ => events}/pointer_event.rs | 474 +++++------ .../src/{ => events}/pointer_event_init.rs | 40 +- .../src/{ => events}/transition_event.rs | 260 +++---- .../src/{ => events}/transition_event_init.rs | 32 +- .../src/{ => events}/ui_event.rs | 256 +++--- .../src/{ => events}/ui_event_init.rs | 32 +- bridge/rusty_webf_sys/src/frame/mod.rs | 6 + .../rusty_webf_sys/src/{ => frame}/window.rs | 0 .../src/{ => html}/html_element.rs | 0 bridge/rusty_webf_sys/src/html/mod.rs | 6 + bridge/rusty_webf_sys/src/input/mod.rs | 6 + .../src/{ => input}/touch_init.rs | 44 +- bridge/rusty_webf_sys/src/lib.rs | 107 +-- bridge/rusty_webf_sys/src/native_value.rs | 3 +- .../code_generator/bin/code_generator.js | 9 +- 51 files changed, 2477 insertions(+), 2434 deletions(-) rename bridge/rusty_webf_sys/src/{ => dom}/character_data.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/comment.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/container_node.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/document.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/document_fragment.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/element.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom/events}/add_event_listener_options.rs (96%) rename bridge/rusty_webf_sys/src/{ => dom/events}/custom_event.rs (97%) rename bridge/rusty_webf_sys/src/{ => dom/events}/event.rs (97%) rename bridge/rusty_webf_sys/src/{ => dom/events}/event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => dom/events}/event_listener_options.rs (96%) rename bridge/rusty_webf_sys/src/{ => dom/events}/event_target.rs (100%) create mode 100644 bridge/rusty_webf_sys/src/dom/events/mod.rs create mode 100644 bridge/rusty_webf_sys/src/dom/mod.rs rename bridge/rusty_webf_sys/src/{ => dom}/node.rs (100%) rename bridge/rusty_webf_sys/src/{ => dom}/scroll_options.rs (96%) rename bridge/rusty_webf_sys/src/{ => dom}/scroll_to_options.rs (96%) rename bridge/rusty_webf_sys/src/{ => dom}/text.rs (100%) rename bridge/rusty_webf_sys/src/{ => events}/animation_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/animation_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/close_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/close_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/focus_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/focus_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/gesture_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/gesture_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/hashchange_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/hashchange_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/input_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/input_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/intersection_change_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/intersection_change_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/keyboard_event_init.rs (96%) create mode 100644 bridge/rusty_webf_sys/src/events/mod.rs rename bridge/rusty_webf_sys/src/{ => events}/mouse_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/mouse_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/pointer_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/pointer_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/transition_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/transition_event_init.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/ui_event.rs (96%) rename bridge/rusty_webf_sys/src/{ => events}/ui_event_init.rs (96%) create mode 100644 bridge/rusty_webf_sys/src/frame/mod.rs rename bridge/rusty_webf_sys/src/{ => frame}/window.rs (100%) rename bridge/rusty_webf_sys/src/{ => html}/html_element.rs (100%) create mode 100644 bridge/rusty_webf_sys/src/html/mod.rs create mode 100644 bridge/rusty_webf_sys/src/input/mod.rs rename bridge/rusty_webf_sys/src/{ => input}/touch_init.rs (96%) diff --git a/bridge/rusty_webf_sys/src/character_data.rs b/bridge/rusty_webf_sys/src/dom/character_data.rs similarity index 100% rename from bridge/rusty_webf_sys/src/character_data.rs rename to bridge/rusty_webf_sys/src/dom/character_data.rs diff --git a/bridge/rusty_webf_sys/src/comment.rs b/bridge/rusty_webf_sys/src/dom/comment.rs similarity index 100% rename from bridge/rusty_webf_sys/src/comment.rs rename to bridge/rusty_webf_sys/src/dom/comment.rs diff --git a/bridge/rusty_webf_sys/src/container_node.rs b/bridge/rusty_webf_sys/src/dom/container_node.rs similarity index 100% rename from bridge/rusty_webf_sys/src/container_node.rs rename to bridge/rusty_webf_sys/src/dom/container_node.rs diff --git a/bridge/rusty_webf_sys/src/document.rs b/bridge/rusty_webf_sys/src/dom/document.rs similarity index 100% rename from bridge/rusty_webf_sys/src/document.rs rename to bridge/rusty_webf_sys/src/dom/document.rs diff --git a/bridge/rusty_webf_sys/src/document_fragment.rs b/bridge/rusty_webf_sys/src/dom/document_fragment.rs similarity index 100% rename from bridge/rusty_webf_sys/src/document_fragment.rs rename to bridge/rusty_webf_sys/src/dom/document_fragment.rs diff --git a/bridge/rusty_webf_sys/src/element.rs b/bridge/rusty_webf_sys/src/dom/element.rs similarity index 100% rename from bridge/rusty_webf_sys/src/element.rs rename to bridge/rusty_webf_sys/src/dom/element.rs diff --git a/bridge/rusty_webf_sys/src/add_event_listener_options.rs b/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs similarity index 96% rename from bridge/rusty_webf_sys/src/add_event_listener_options.rs rename to bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs index 7196c60be2..ec70ec4e59 100644 --- a/bridge/rusty_webf_sys/src/add_event_listener_options.rs +++ b/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs @@ -1,13 +1,13 @@ -// 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 AddEventListenerOptions { - pub capture: i32, - pub passive: i32, - pub once: i32, -} +// 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 AddEventListenerOptions { + pub capture: i32, + pub passive: i32, + pub once: i32, +} diff --git a/bridge/rusty_webf_sys/src/custom_event.rs b/bridge/rusty_webf_sys/src/dom/events/custom_event.rs similarity index 97% rename from bridge/rusty_webf_sys/src/custom_event.rs rename to bridge/rusty_webf_sys/src/dom/events/custom_event.rs index 2864232c1c..3262ecc3ee 100644 --- a/bridge/rusty_webf_sys/src/custom_event.rs +++ b/bridge/rusty_webf_sys/src/dom/events/custom_event.rs @@ -1,120 +1,120 @@ -// 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 - } -} +// 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/event.rs b/bridge/rusty_webf_sys/src/dom/events/event.rs similarity index 97% rename from bridge/rusty_webf_sys/src/event.rs rename to bridge/rusty_webf_sys/src/dom/events/event.rs index fa9d81dd98..04065802d6 100644 --- a/bridge/rusty_webf_sys/src/event.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event.rs @@ -1,369 +1,369 @@ -// 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)] -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, -} -#[repr(C)] -pub struct EventRustMethods { - pub version: c_double, - pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: i32, exception_state: *const OpaquePtr) -> bool, - pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub current_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub src_element: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub time_stamp: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub type_: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, exception_state: *const OpaquePtr) -> c_void, - pub prevent_default: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub stop_immediate_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub stop_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub release: extern "C" fn(ptr: *const OpaquePtr) -> c_void, - pub dynamic_to: extern "C" fn(ptr: *const OpaquePtr, type_: EventType) -> RustValue, -} -pub struct Event { - pub ptr: *const OpaquePtr, - context: *const ExecutingContext, - method_pointer: *const EventRustMethods, - status: *const RustValueStatus -} -impl Event { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const EventRustMethods, status: *const RustValueStatus) -> Event { - Event { - ptr, - context, - method_pointer, - status - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ptr - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - assert!(!self.context.is_null(), "Context PTR must not be null"); - unsafe { &*self.context } - } - pub fn bubbles(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).bubbles)(self.ptr()) - }; - value != 0 - } - pub fn cancel_bubble(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).cancel_bubble)(self.ptr()) - }; - value != 0 - } - pub fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).set_cancel_bubble)(self.ptr(), i32::from(value), exception_state.ptr) - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn cancelable(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).cancelable)(self.ptr()) - }; - value != 0 - } - pub fn current_target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).current_target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn default_prevented(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).default_prevented)(self.ptr()) - }; - value != 0 - } - pub fn src_element(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).src_element)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn is_trusted(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).is_trusted)(self.ptr()) - }; - value != 0 - } - pub fn time_stamp(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).time_stamp)(self.ptr()) - }; - value - } - pub fn type_(&self) -> String { - let value = unsafe { - ((*self.method_pointer).type_)(self.ptr()) - }; +// 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)] +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, +} +#[repr(C)] +pub struct EventRustMethods { + pub version: c_double, + pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: i32, exception_state: *const OpaquePtr) -> bool, + pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub current_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub src_element: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub time_stamp: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub type_: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, exception_state: *const OpaquePtr) -> c_void, + pub prevent_default: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub stop_immediate_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub stop_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub release: extern "C" fn(ptr: *const OpaquePtr) -> c_void, + pub dynamic_to: extern "C" fn(ptr: *const OpaquePtr, type_: EventType) -> RustValue, +} +pub struct Event { + pub ptr: *const OpaquePtr, + context: *const ExecutingContext, + method_pointer: *const EventRustMethods, + status: *const RustValueStatus +} +impl Event { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const EventRustMethods, status: *const RustValueStatus) -> Event { + Event { + ptr, + context, + method_pointer, + status + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ptr + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + pub fn bubbles(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).bubbles)(self.ptr()) + }; + value != 0 + } + pub fn cancel_bubble(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).cancel_bubble)(self.ptr()) + }; + value != 0 + } + pub fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).set_cancel_bubble)(self.ptr(), i32::from(value), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn cancelable(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).cancelable)(self.ptr()) + }; + value != 0 + } + pub fn current_target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).current_target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn default_prevented(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).default_prevented)(self.ptr()) + }; + value != 0 + } + pub fn src_element(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).src_element)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn is_trusted(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).is_trusted)(self.ptr()) + }; + value != 0 + } + pub fn time_stamp(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).time_stamp)(self.ptr()) + }; + value + } + pub fn type_(&self) -> String { + let value = unsafe { + ((*self.method_pointer).type_)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(bubbles), i32::from(cancelable), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).prevent_default)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).stop_immediate_propagation)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).stop_propagation)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - 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)); - ((*self.method_pointer).dynamic_to)(self.ptr, EventType::AnimationEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the AnimationEvent type."); - } - Ok(AnimationEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const AnimationEventRustMethods, raw_ptr.status)) - } - pub fn as_close_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::CloseEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the CloseEvent type."); - } - Ok(CloseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const CloseEventRustMethods, raw_ptr.status)) - } - pub fn as_gesture_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::GestureEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the GestureEvent type."); - } - Ok(GestureEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const GestureEventRustMethods, raw_ptr.status)) - } - pub fn as_hashchange_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::HashchangeEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the HashchangeEvent type."); - } - Ok(HashchangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const HashchangeEventRustMethods, raw_ptr.status)) - } - pub fn as_intersection_change_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::IntersectionChangeEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the IntersectionChangeEvent type."); - } - Ok(IntersectionChangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const IntersectionChangeEventRustMethods, raw_ptr.status)) - } - pub fn as_transition_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::TransitionEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the TransitionEvent type."); - } - Ok(TransitionEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const TransitionEventRustMethods, raw_ptr.status)) - } - pub fn as_ui_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::UIEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the UIEvent type."); - } - Ok(UIEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const UIEventRustMethods, raw_ptr.status)) - } - pub fn as_focus_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::FocusEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the FocusEvent type."); - } - Ok(FocusEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const FocusEventRustMethods, raw_ptr.status)) - } - pub fn as_input_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::InputEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the InputEvent type."); - } - Ok(InputEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const InputEventRustMethods, raw_ptr.status)) - } - pub fn as_mouse_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::MouseEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the MouseEvent type."); - } - Ok(MouseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const MouseEventRustMethods, raw_ptr.status)) - } - pub fn as_pointer_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::PointerEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the PointerEvent type."); - } - Ok(PointerEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const PointerEventRustMethods, raw_ptr.status)) - } -} -impl Drop for Event { - fn drop(&mut self) { - unsafe { - ((*self.method_pointer).release)(self.ptr()); - } - } -} -pub trait EventMethods { - fn bubbles(&self) -> bool; - fn cancel_bubble(&self) -> bool; - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String>; - fn cancelable(&self) -> bool; - fn current_target(&self) -> EventTarget; - fn default_prevented(&self) -> bool; - fn src_element(&self) -> EventTarget; - fn target(&self) -> EventTarget; - fn is_trusted(&self) -> bool; - fn time_stamp(&self) -> f64; - fn type_(&self) -> String; - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String>; - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn as_event(&self) -> &Event; -} -impl EventMethods for Event { - fn bubbles(&self) -> bool { - self.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.cancelable() - } - fn current_target(&self) -> EventTarget { - self.current_target() - } - fn default_prevented(&self) -> bool { - self.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.src_element() - } - fn target(&self) -> EventTarget { - self.target() - } - fn is_trusted(&self) -> bool { - self.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.time_stamp() - } - fn type_(&self) -> String { - self.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - self - } -} + value.to_str().unwrap().to_string() + } + pub fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(bubbles), i32::from(cancelable), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).prevent_default)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).stop_immediate_propagation)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).stop_propagation)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + 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)); + ((*self.method_pointer).dynamic_to)(self.ptr, EventType::AnimationEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the AnimationEvent type."); + } + Ok(AnimationEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const AnimationEventRustMethods, raw_ptr.status)) + } + pub fn as_close_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::CloseEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the CloseEvent type."); + } + Ok(CloseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const CloseEventRustMethods, raw_ptr.status)) + } + pub fn as_gesture_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::GestureEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the GestureEvent type."); + } + Ok(GestureEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const GestureEventRustMethods, raw_ptr.status)) + } + pub fn as_hashchange_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::HashchangeEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the HashchangeEvent type."); + } + Ok(HashchangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const HashchangeEventRustMethods, raw_ptr.status)) + } + pub fn as_intersection_change_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::IntersectionChangeEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the IntersectionChangeEvent type."); + } + Ok(IntersectionChangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const IntersectionChangeEventRustMethods, raw_ptr.status)) + } + pub fn as_transition_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::TransitionEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the TransitionEvent type."); + } + Ok(TransitionEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const TransitionEventRustMethods, raw_ptr.status)) + } + pub fn as_ui_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::UIEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the UIEvent type."); + } + Ok(UIEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const UIEventRustMethods, raw_ptr.status)) + } + pub fn as_focus_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::FocusEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the FocusEvent type."); + } + Ok(FocusEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const FocusEventRustMethods, raw_ptr.status)) + } + pub fn as_input_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::InputEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the InputEvent type."); + } + Ok(InputEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const InputEventRustMethods, raw_ptr.status)) + } + pub fn as_mouse_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::MouseEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the MouseEvent type."); + } + Ok(MouseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const MouseEventRustMethods, raw_ptr.status)) + } + pub fn as_pointer_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::PointerEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the PointerEvent type."); + } + Ok(PointerEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const PointerEventRustMethods, raw_ptr.status)) + } +} +impl Drop for Event { + fn drop(&mut self) { + unsafe { + ((*self.method_pointer).release)(self.ptr()); + } + } +} +pub trait EventMethods { + fn bubbles(&self) -> bool; + fn cancel_bubble(&self) -> bool; + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String>; + fn cancelable(&self) -> bool; + fn current_target(&self) -> EventTarget; + fn default_prevented(&self) -> bool; + fn src_element(&self) -> EventTarget; + fn target(&self) -> EventTarget; + fn is_trusted(&self) -> bool; + fn time_stamp(&self) -> f64; + fn type_(&self) -> String; + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String>; + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn as_event(&self) -> &Event; +} +impl EventMethods for Event { + fn bubbles(&self) -> bool { + self.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.cancelable() + } + fn current_target(&self) -> EventTarget { + self.current_target() + } + fn default_prevented(&self) -> bool { + self.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.src_element() + } + fn target(&self) -> EventTarget { + self.target() + } + fn is_trusted(&self) -> bool { + self.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.time_stamp() + } + fn type_(&self) -> String { + self.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + self + } +} diff --git a/bridge/rusty_webf_sys/src/event_init.rs b/bridge/rusty_webf_sys/src/dom/events/event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/event_init.rs rename to bridge/rusty_webf_sys/src/dom/events/event_init.rs index 07ce0f7bc5..9eadc8ea99 100644 --- a/bridge/rusty_webf_sys/src/event_init.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event_init.rs @@ -1,13 +1,13 @@ -// 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 EventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, -} +// 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 EventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, +} diff --git a/bridge/rusty_webf_sys/src/event_listener_options.rs b/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs similarity index 96% rename from bridge/rusty_webf_sys/src/event_listener_options.rs rename to bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs index f5fc1a4152..cd4253e0c5 100644 --- a/bridge/rusty_webf_sys/src/event_listener_options.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs @@ -1,11 +1,11 @@ -// 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 EventListenerOptions { - pub capture: i32, -} +// 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 EventListenerOptions { + pub capture: i32, +} diff --git a/bridge/rusty_webf_sys/src/event_target.rs b/bridge/rusty_webf_sys/src/dom/events/event_target.rs similarity index 100% rename from bridge/rusty_webf_sys/src/event_target.rs rename to bridge/rusty_webf_sys/src/dom/events/event_target.rs diff --git a/bridge/rusty_webf_sys/src/dom/events/mod.rs b/bridge/rusty_webf_sys/src/dom/events/mod.rs new file mode 100644 index 0000000000..e95685d5e3 --- /dev/null +++ b/bridge/rusty_webf_sys/src/dom/events/mod.rs @@ -0,0 +1,16 @@ +/* +* 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::*; +pub use event::*; diff --git a/bridge/rusty_webf_sys/src/dom/mod.rs b/bridge/rusty_webf_sys/src/dom/mod.rs new file mode 100644 index 0000000000..e7e42e4a7b --- /dev/null +++ b/bridge/rusty_webf_sys/src/dom/mod.rs @@ -0,0 +1,26 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod events; +pub mod character_data; +pub mod comment; +pub mod container_node; +pub mod document_fragment; +pub mod document; +pub mod element; +pub mod node; +pub mod scroll_options; +pub mod scroll_to_options; +pub mod text; + +pub use events::*; +pub use character_data::*; +pub use comment::*; +pub use container_node::*; +pub use document_fragment::*; +pub use document::*; +pub use element::*; +pub use node::*; +pub use scroll_options::*; +pub use scroll_to_options::*; +pub use text::*; diff --git a/bridge/rusty_webf_sys/src/node.rs b/bridge/rusty_webf_sys/src/dom/node.rs similarity index 100% rename from bridge/rusty_webf_sys/src/node.rs rename to bridge/rusty_webf_sys/src/dom/node.rs diff --git a/bridge/rusty_webf_sys/src/scroll_options.rs b/bridge/rusty_webf_sys/src/dom/scroll_options.rs similarity index 96% rename from bridge/rusty_webf_sys/src/scroll_options.rs rename to bridge/rusty_webf_sys/src/dom/scroll_options.rs index a28d104213..644ebd1fb2 100644 --- a/bridge/rusty_webf_sys/src/scroll_options.rs +++ b/bridge/rusty_webf_sys/src/dom/scroll_options.rs @@ -1,11 +1,11 @@ -// 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 ScrollOptions { - pub behavior: *const c_char, -} +// 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 ScrollOptions { + pub behavior: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/scroll_to_options.rs b/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs similarity index 96% rename from bridge/rusty_webf_sys/src/scroll_to_options.rs rename to bridge/rusty_webf_sys/src/dom/scroll_to_options.rs index 9fee3ebd57..cbf4dcbb5f 100644 --- a/bridge/rusty_webf_sys/src/scroll_to_options.rs +++ b/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs @@ -1,13 +1,13 @@ -// 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 ScrollToOptions { - pub behavior: *const c_char, - pub top: c_double, - pub left: c_double, -} +// 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 ScrollToOptions { + pub behavior: *const c_char, + pub top: c_double, + pub left: c_double, +} diff --git a/bridge/rusty_webf_sys/src/text.rs b/bridge/rusty_webf_sys/src/dom/text.rs similarity index 100% rename from bridge/rusty_webf_sys/src/text.rs rename to bridge/rusty_webf_sys/src/dom/text.rs diff --git a/bridge/rusty_webf_sys/src/animation_event.rs b/bridge/rusty_webf_sys/src/events/animation_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/animation_event.rs rename to bridge/rusty_webf_sys/src/events/animation_event.rs index 5e98383f05..6c641cfca3 100644 --- a/bridge/rusty_webf_sys/src/animation_event.rs +++ b/bridge/rusty_webf_sys/src/events/animation_event.rs @@ -1,132 +1,132 @@ -// 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 AnimationEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct AnimationEvent { - pub event: Event, - method_pointer: *const AnimationEventRustMethods, -} -impl AnimationEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const AnimationEventRustMethods, status: *const RustValueStatus) -> AnimationEvent { - unsafe { - AnimationEvent { - 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 animation_name(&self) -> String { - let value = unsafe { - ((*self.method_pointer).animation_name)(self.ptr()) - }; +// 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 AnimationEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct AnimationEvent { + pub event: Event, + method_pointer: *const AnimationEventRustMethods, +} +impl AnimationEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const AnimationEventRustMethods, status: *const RustValueStatus) -> AnimationEvent { + unsafe { + AnimationEvent { + 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 animation_name(&self) -> String { + let value = unsafe { + ((*self.method_pointer).animation_name)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn elapsed_time(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).elapsed_time)(self.ptr()) - }; - value - } - pub fn pseudo_element(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pseudo_element)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn elapsed_time(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).elapsed_time)(self.ptr()) + }; + value + } + pub fn pseudo_element(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pseudo_element)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait AnimationEventMethods: EventMethods { - fn animation_name(&self) -> String; - fn elapsed_time(&self) -> f64; - fn pseudo_element(&self) -> String; - fn as_animation_event(&self) -> &AnimationEvent; -} -impl AnimationEventMethods for AnimationEvent { - fn animation_name(&self) -> String { - self.animation_name() - } - fn elapsed_time(&self) -> f64 { - self.elapsed_time() - } - fn pseudo_element(&self) -> String { - self.pseudo_element() - } - fn as_animation_event(&self) -> &AnimationEvent { - self - } -} -impl EventMethods for AnimationEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait AnimationEventMethods: EventMethods { + fn animation_name(&self) -> String; + fn elapsed_time(&self) -> f64; + fn pseudo_element(&self) -> String; + fn as_animation_event(&self) -> &AnimationEvent; +} +impl AnimationEventMethods for AnimationEvent { + fn animation_name(&self) -> String { + self.animation_name() + } + fn elapsed_time(&self) -> f64 { + self.elapsed_time() + } + fn pseudo_element(&self) -> String { + self.pseudo_element() + } + fn as_animation_event(&self) -> &AnimationEvent { + self + } +} +impl EventMethods for AnimationEvent { + 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/animation_event_init.rs b/bridge/rusty_webf_sys/src/events/animation_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/animation_event_init.rs rename to bridge/rusty_webf_sys/src/events/animation_event_init.rs index 41fc67c884..6b5ed09f8a 100644 --- a/bridge/rusty_webf_sys/src/animation_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/animation_event_init.rs @@ -1,16 +1,16 @@ -// 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 AnimationEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub animation_name: *const c_char, - pub elapsed_time: c_double, - pub pseudo_element: *const c_char, -} +// 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 AnimationEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub animation_name: *const c_char, + pub elapsed_time: c_double, + pub pseudo_element: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/close_event.rs b/bridge/rusty_webf_sys/src/events/close_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/close_event.rs rename to bridge/rusty_webf_sys/src/events/close_event.rs index 47eb399483..89572a9f80 100644 --- a/bridge/rusty_webf_sys/src/close_event.rs +++ b/bridge/rusty_webf_sys/src/events/close_event.rs @@ -1,130 +1,130 @@ -// 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 CloseEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub code: extern "C" fn(ptr: *const OpaquePtr) -> i64, - pub reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub was_clean: extern "C" fn(ptr: *const OpaquePtr) -> i32, -} -pub struct CloseEvent { - pub event: Event, - method_pointer: *const CloseEventRustMethods, -} -impl CloseEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const CloseEventRustMethods, status: *const RustValueStatus) -> CloseEvent { - unsafe { - CloseEvent { - 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 code(&self) -> i64 { - let value = unsafe { - ((*self.method_pointer).code)(self.ptr()) - }; - value - } - pub fn reason(&self) -> String { - let value = unsafe { - ((*self.method_pointer).reason)(self.ptr()) - }; +// 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 CloseEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub code: extern "C" fn(ptr: *const OpaquePtr) -> i64, + pub reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub was_clean: extern "C" fn(ptr: *const OpaquePtr) -> i32, +} +pub struct CloseEvent { + pub event: Event, + method_pointer: *const CloseEventRustMethods, +} +impl CloseEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const CloseEventRustMethods, status: *const RustValueStatus) -> CloseEvent { + unsafe { + CloseEvent { + 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 code(&self) -> i64 { + let value = unsafe { + ((*self.method_pointer).code)(self.ptr()) + }; + value + } + pub fn reason(&self) -> String { + let value = unsafe { + ((*self.method_pointer).reason)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn was_clean(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).was_clean)(self.ptr()) - }; - value != 0 - } -} -pub trait CloseEventMethods: EventMethods { - fn code(&self) -> i64; - fn reason(&self) -> String; - fn was_clean(&self) -> bool; - fn as_close_event(&self) -> &CloseEvent; -} -impl CloseEventMethods for CloseEvent { - fn code(&self) -> i64 { - self.code() - } - fn reason(&self) -> String { - self.reason() - } - fn was_clean(&self) -> bool { - self.was_clean() - } - fn as_close_event(&self) -> &CloseEvent { - self - } -} -impl EventMethods for CloseEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } + pub fn was_clean(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).was_clean)(self.ptr()) + }; + value != 0 + } +} +pub trait CloseEventMethods: EventMethods { + fn code(&self) -> i64; + fn reason(&self) -> String; + fn was_clean(&self) -> bool; + fn as_close_event(&self) -> &CloseEvent; +} +impl CloseEventMethods for CloseEvent { + fn code(&self) -> i64 { + self.code() + } + fn reason(&self) -> String { + self.reason() + } + fn was_clean(&self) -> bool { + self.was_clean() + } + fn as_close_event(&self) -> &CloseEvent { + self + } +} +impl EventMethods for CloseEvent { + 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/close_event_init.rs b/bridge/rusty_webf_sys/src/events/close_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/close_event_init.rs rename to bridge/rusty_webf_sys/src/events/close_event_init.rs index 998cbec348..d51b063c39 100644 --- a/bridge/rusty_webf_sys/src/close_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/close_event_init.rs @@ -1,16 +1,16 @@ -// 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 CloseEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub code: i64, - pub reason: *const c_char, - pub was_clean: i32, -} +// 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 CloseEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub code: i64, + pub reason: *const c_char, + pub was_clean: i32, +} diff --git a/bridge/rusty_webf_sys/src/focus_event.rs b/bridge/rusty_webf_sys/src/events/focus_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/focus_event.rs rename to bridge/rusty_webf_sys/src/events/focus_event.rs index e2b78491e5..b1a9af3b4a 100644 --- a/bridge/rusty_webf_sys/src/focus_event.rs +++ b/bridge/rusty_webf_sys/src/events/focus_event.rs @@ -1,120 +1,120 @@ -// 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 FocusEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub related_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, -} -pub struct FocusEvent { - pub ui_event: UIEvent, - method_pointer: *const FocusEventRustMethods, -} -impl FocusEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const FocusEventRustMethods, status: *const RustValueStatus) -> FocusEvent { - unsafe { - FocusEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn related_target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).related_target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } -} -pub trait FocusEventMethods: UIEventMethods { - fn related_target(&self) -> EventTarget; - fn as_focus_event(&self) -> &FocusEvent; -} -impl FocusEventMethods for FocusEvent { - fn related_target(&self) -> EventTarget { - self.related_target() - } - fn as_focus_event(&self) -> &FocusEvent { - self - } -} -impl UIEventMethods for FocusEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for FocusEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} +// 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 FocusEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub related_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, +} +pub struct FocusEvent { + pub ui_event: UIEvent, + method_pointer: *const FocusEventRustMethods, +} +impl FocusEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const FocusEventRustMethods, status: *const RustValueStatus) -> FocusEvent { + unsafe { + FocusEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn related_target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).related_target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } +} +pub trait FocusEventMethods: UIEventMethods { + fn related_target(&self) -> EventTarget; + fn as_focus_event(&self) -> &FocusEvent; +} +impl FocusEventMethods for FocusEvent { + fn related_target(&self) -> EventTarget { + self.related_target() + } + fn as_focus_event(&self) -> &FocusEvent { + self + } +} +impl UIEventMethods for FocusEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for FocusEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/focus_event_init.rs b/bridge/rusty_webf_sys/src/events/focus_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/focus_event_init.rs rename to bridge/rusty_webf_sys/src/events/focus_event_init.rs index 7210d9029d..07a00f24b4 100644 --- a/bridge/rusty_webf_sys/src/focus_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/focus_event_init.rs @@ -1,14 +1,14 @@ -// 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 FocusEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub related_target: RustValue, -} +// 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 FocusEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub related_target: RustValue, +} diff --git a/bridge/rusty_webf_sys/src/gesture_event.rs b/bridge/rusty_webf_sys/src/events/gesture_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/gesture_event.rs rename to bridge/rusty_webf_sys/src/events/gesture_event.rs index 9287dc62ff..e6a166c27a 100644 --- a/bridge/rusty_webf_sys/src/gesture_event.rs +++ b/bridge/rusty_webf_sys/src/events/gesture_event.rs @@ -1,187 +1,187 @@ -// 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 GestureEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub delta_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub delta_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub velocity_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub velocity_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub scale: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub rotation: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct GestureEvent { - pub event: Event, - method_pointer: *const GestureEventRustMethods, -} -impl GestureEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const GestureEventRustMethods, status: *const RustValueStatus) -> GestureEvent { - unsafe { - GestureEvent { - 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 state(&self) -> String { - let value = unsafe { - ((*self.method_pointer).state)(self.ptr()) - }; +// 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 GestureEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub delta_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub delta_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub velocity_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub velocity_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub scale: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub rotation: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct GestureEvent { + pub event: Event, + method_pointer: *const GestureEventRustMethods, +} +impl GestureEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const GestureEventRustMethods, status: *const RustValueStatus) -> GestureEvent { + unsafe { + GestureEvent { + 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 state(&self) -> String { + let value = unsafe { + ((*self.method_pointer).state)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn direction(&self) -> String { - let value = unsafe { - ((*self.method_pointer).direction)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn direction(&self) -> String { + let value = unsafe { + ((*self.method_pointer).direction)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn delta_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).delta_x)(self.ptr()) - }; - value - } - pub fn delta_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).delta_y)(self.ptr()) - }; - value - } - pub fn velocity_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).velocity_x)(self.ptr()) - }; - value - } - pub fn velocity_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).velocity_y)(self.ptr()) - }; - value - } - pub fn scale(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).scale)(self.ptr()) - }; - value - } - pub fn rotation(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).rotation)(self.ptr()) - }; - value - } -} -pub trait GestureEventMethods: EventMethods { - fn state(&self) -> String; - fn direction(&self) -> String; - fn delta_x(&self) -> f64; - fn delta_y(&self) -> f64; - fn velocity_x(&self) -> f64; - fn velocity_y(&self) -> f64; - fn scale(&self) -> f64; - fn rotation(&self) -> f64; - fn as_gesture_event(&self) -> &GestureEvent; -} -impl GestureEventMethods for GestureEvent { - fn state(&self) -> String { - self.state() - } - fn direction(&self) -> String { - self.direction() - } - fn delta_x(&self) -> f64 { - self.delta_x() - } - fn delta_y(&self) -> f64 { - self.delta_y() - } - fn velocity_x(&self) -> f64 { - self.velocity_x() - } - fn velocity_y(&self) -> f64 { - self.velocity_y() - } - fn scale(&self) -> f64 { - self.scale() - } - fn rotation(&self) -> f64 { - self.rotation() - } - fn as_gesture_event(&self) -> &GestureEvent { - self - } -} -impl EventMethods for GestureEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } + pub fn delta_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).delta_x)(self.ptr()) + }; + value + } + pub fn delta_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).delta_y)(self.ptr()) + }; + value + } + pub fn velocity_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).velocity_x)(self.ptr()) + }; + value + } + pub fn velocity_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).velocity_y)(self.ptr()) + }; + value + } + pub fn scale(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).scale)(self.ptr()) + }; + value + } + pub fn rotation(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).rotation)(self.ptr()) + }; + value + } +} +pub trait GestureEventMethods: EventMethods { + fn state(&self) -> String; + fn direction(&self) -> String; + fn delta_x(&self) -> f64; + fn delta_y(&self) -> f64; + fn velocity_x(&self) -> f64; + fn velocity_y(&self) -> f64; + fn scale(&self) -> f64; + fn rotation(&self) -> f64; + fn as_gesture_event(&self) -> &GestureEvent; +} +impl GestureEventMethods for GestureEvent { + fn state(&self) -> String { + self.state() + } + fn direction(&self) -> String { + self.direction() + } + fn delta_x(&self) -> f64 { + self.delta_x() + } + fn delta_y(&self) -> f64 { + self.delta_y() + } + fn velocity_x(&self) -> f64 { + self.velocity_x() + } + fn velocity_y(&self) -> f64 { + self.velocity_y() + } + fn scale(&self) -> f64 { + self.scale() + } + fn rotation(&self) -> f64 { + self.rotation() + } + fn as_gesture_event(&self) -> &GestureEvent { + self + } +} +impl EventMethods for GestureEvent { + 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/gesture_event_init.rs b/bridge/rusty_webf_sys/src/events/gesture_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/gesture_event_init.rs rename to bridge/rusty_webf_sys/src/events/gesture_event_init.rs index 29d5519ae1..09e02b851a 100644 --- a/bridge/rusty_webf_sys/src/gesture_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/gesture_event_init.rs @@ -1,21 +1,21 @@ -// 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 GestureEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub state: *const c_char, - pub direction: *const c_char, - pub delta_x: c_double, - pub delta_y: c_double, - pub velocity_x: c_double, - pub velocity_y: c_double, - pub scale: c_double, - pub rotation: c_double, -} +// 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 GestureEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub state: *const c_char, + pub direction: *const c_char, + pub delta_x: c_double, + pub delta_y: c_double, + pub velocity_x: c_double, + pub velocity_y: c_double, + pub scale: c_double, + pub rotation: c_double, +} diff --git a/bridge/rusty_webf_sys/src/hashchange_event.rs b/bridge/rusty_webf_sys/src/events/hashchange_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/hashchange_event.rs rename to bridge/rusty_webf_sys/src/events/hashchange_event.rs index 51d58f9bb9..e57853e8b2 100644 --- a/bridge/rusty_webf_sys/src/hashchange_event.rs +++ b/bridge/rusty_webf_sys/src/events/hashchange_event.rs @@ -1,121 +1,121 @@ -// 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 HashchangeEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct HashchangeEvent { - pub event: Event, - method_pointer: *const HashchangeEventRustMethods, -} -impl HashchangeEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const HashchangeEventRustMethods, status: *const RustValueStatus) -> HashchangeEvent { - unsafe { - HashchangeEvent { - 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 new_url(&self) -> String { - let value = unsafe { - ((*self.method_pointer).new_url)(self.ptr()) - }; +// 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 HashchangeEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct HashchangeEvent { + pub event: Event, + method_pointer: *const HashchangeEventRustMethods, +} +impl HashchangeEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const HashchangeEventRustMethods, status: *const RustValueStatus) -> HashchangeEvent { + unsafe { + HashchangeEvent { + 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 new_url(&self) -> String { + let value = unsafe { + ((*self.method_pointer).new_url)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn old_url(&self) -> String { - let value = unsafe { - ((*self.method_pointer).old_url)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn old_url(&self) -> String { + let value = unsafe { + ((*self.method_pointer).old_url)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait HashchangeEventMethods: EventMethods { - fn new_url(&self) -> String; - fn old_url(&self) -> String; - fn as_hashchange_event(&self) -> &HashchangeEvent; -} -impl HashchangeEventMethods for HashchangeEvent { - fn new_url(&self) -> String { - self.new_url() - } - fn old_url(&self) -> String { - self.old_url() - } - fn as_hashchange_event(&self) -> &HashchangeEvent { - self - } -} -impl EventMethods for HashchangeEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait HashchangeEventMethods: EventMethods { + fn new_url(&self) -> String; + fn old_url(&self) -> String; + fn as_hashchange_event(&self) -> &HashchangeEvent; +} +impl HashchangeEventMethods for HashchangeEvent { + fn new_url(&self) -> String { + self.new_url() + } + fn old_url(&self) -> String { + self.old_url() + } + fn as_hashchange_event(&self) -> &HashchangeEvent { + self + } +} +impl EventMethods for HashchangeEvent { + 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/hashchange_event_init.rs b/bridge/rusty_webf_sys/src/events/hashchange_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/hashchange_event_init.rs rename to bridge/rusty_webf_sys/src/events/hashchange_event_init.rs index 79de869114..5f89ecdccb 100644 --- a/bridge/rusty_webf_sys/src/hashchange_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/hashchange_event_init.rs @@ -1,15 +1,15 @@ -// 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 HashchangeEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub old_url: *const c_char, - pub new_url: *const c_char, -} +// 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 HashchangeEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub old_url: *const c_char, + pub new_url: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/input_event.rs b/bridge/rusty_webf_sys/src/events/input_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/input_event.rs rename to bridge/rusty_webf_sys/src/events/input_event.rs index 17630178e9..5ed168feb7 100644 --- a/bridge/rusty_webf_sys/src/input_event.rs +++ b/bridge/rusty_webf_sys/src/events/input_event.rs @@ -1,135 +1,135 @@ -// 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 InputEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct InputEvent { - pub ui_event: UIEvent, - method_pointer: *const InputEventRustMethods, -} -impl InputEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const InputEventRustMethods, status: *const RustValueStatus) -> InputEvent { - unsafe { - InputEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn input_type(&self) -> String { - let value = unsafe { - ((*self.method_pointer).input_type)(self.ptr()) - }; +// 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 InputEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct InputEvent { + pub ui_event: UIEvent, + method_pointer: *const InputEventRustMethods, +} +impl InputEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const InputEventRustMethods, status: *const RustValueStatus) -> InputEvent { + unsafe { + InputEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn input_type(&self) -> String { + let value = unsafe { + ((*self.method_pointer).input_type)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn data(&self) -> String { - let value = unsafe { - ((*self.method_pointer).data)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn data(&self) -> String { + let value = unsafe { + ((*self.method_pointer).data)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait InputEventMethods: UIEventMethods { - fn input_type(&self) -> String; - fn data(&self) -> String; - fn as_input_event(&self) -> &InputEvent; -} -impl InputEventMethods for InputEvent { - fn input_type(&self) -> String { - self.input_type() - } - fn data(&self) -> String { - self.data() - } - fn as_input_event(&self) -> &InputEvent { - self - } -} -impl UIEventMethods for InputEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for InputEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} + value.to_str().unwrap().to_string() + } +} +pub trait InputEventMethods: UIEventMethods { + fn input_type(&self) -> String; + fn data(&self) -> String; + fn as_input_event(&self) -> &InputEvent; +} +impl InputEventMethods for InputEvent { + fn input_type(&self) -> String { + self.input_type() + } + fn data(&self) -> String { + self.data() + } + fn as_input_event(&self) -> &InputEvent { + self + } +} +impl UIEventMethods for InputEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for InputEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/input_event_init.rs b/bridge/rusty_webf_sys/src/events/input_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/input_event_init.rs rename to bridge/rusty_webf_sys/src/events/input_event_init.rs index 9c85bc478a..3e094c36c3 100644 --- a/bridge/rusty_webf_sys/src/input_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/input_event_init.rs @@ -1,15 +1,15 @@ -// 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 InputEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub input_type: *const c_char, - pub data: *const c_char, -} +// 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 InputEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub input_type: *const c_char, + pub data: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/intersection_change_event.rs b/bridge/rusty_webf_sys/src/events/intersection_change_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/intersection_change_event.rs rename to bridge/rusty_webf_sys/src/events/intersection_change_event.rs index 149fbf398e..bb5cd2e061 100644 --- a/bridge/rusty_webf_sys/src/intersection_change_event.rs +++ b/bridge/rusty_webf_sys/src/events/intersection_change_event.rs @@ -1,106 +1,106 @@ -// 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 IntersectionChangeEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub intersection_ratio: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct IntersectionChangeEvent { - pub event: Event, - method_pointer: *const IntersectionChangeEventRustMethods, -} -impl IntersectionChangeEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const IntersectionChangeEventRustMethods, status: *const RustValueStatus) -> IntersectionChangeEvent { - unsafe { - IntersectionChangeEvent { - 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 intersection_ratio(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).intersection_ratio)(self.ptr()) - }; - value - } -} -pub trait IntersectionChangeEventMethods: EventMethods { - fn intersection_ratio(&self) -> f64; - fn as_intersection_change_event(&self) -> &IntersectionChangeEvent; -} -impl IntersectionChangeEventMethods for IntersectionChangeEvent { - fn intersection_ratio(&self) -> f64 { - self.intersection_ratio() - } - fn as_intersection_change_event(&self) -> &IntersectionChangeEvent { - self - } -} -impl EventMethods for IntersectionChangeEvent { - 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 - } -} +// 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 IntersectionChangeEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub intersection_ratio: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct IntersectionChangeEvent { + pub event: Event, + method_pointer: *const IntersectionChangeEventRustMethods, +} +impl IntersectionChangeEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const IntersectionChangeEventRustMethods, status: *const RustValueStatus) -> IntersectionChangeEvent { + unsafe { + IntersectionChangeEvent { + 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 intersection_ratio(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).intersection_ratio)(self.ptr()) + }; + value + } +} +pub trait IntersectionChangeEventMethods: EventMethods { + fn intersection_ratio(&self) -> f64; + fn as_intersection_change_event(&self) -> &IntersectionChangeEvent; +} +impl IntersectionChangeEventMethods for IntersectionChangeEvent { + fn intersection_ratio(&self) -> f64 { + self.intersection_ratio() + } + fn as_intersection_change_event(&self) -> &IntersectionChangeEvent { + self + } +} +impl EventMethods for IntersectionChangeEvent { + 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/intersection_change_event_init.rs b/bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/intersection_change_event_init.rs rename to bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs index f426f2e45e..d7a78f7870 100644 --- a/bridge/rusty_webf_sys/src/intersection_change_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs @@ -1,14 +1,14 @@ -// 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 IntersectionChangeEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub intersection_ratio: c_double, -} +// 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 IntersectionChangeEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub intersection_ratio: c_double, +} diff --git a/bridge/rusty_webf_sys/src/keyboard_event_init.rs b/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/keyboard_event_init.rs rename to bridge/rusty_webf_sys/src/events/keyboard_event_init.rs index 2f793ce90a..ade7831f14 100644 --- a/bridge/rusty_webf_sys/src/keyboard_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs @@ -1,24 +1,24 @@ -// 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 KeyboardEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub alt_key: i32, - pub char_code: c_double, - pub code: *const c_char, - pub ctrl_key: i32, - pub is_composing: i32, - pub key: *const c_char, - pub key_code: c_double, - pub location: c_double, - pub meta_key: i32, - pub repeat: i32, - pub shift_key: i32, -} +// 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 KeyboardEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub alt_key: i32, + pub char_code: c_double, + pub code: *const c_char, + pub ctrl_key: i32, + pub is_composing: i32, + pub key: *const c_char, + pub key_code: c_double, + pub location: c_double, + pub meta_key: i32, + pub repeat: i32, + pub shift_key: i32, +} diff --git a/bridge/rusty_webf_sys/src/events/mod.rs b/bridge/rusty_webf_sys/src/events/mod.rs new file mode 100644 index 0000000000..a854e34648 --- /dev/null +++ b/bridge/rusty_webf_sys/src/events/mod.rs @@ -0,0 +1,50 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod animation_event_init; +pub mod animation_event; +pub mod close_event_init; +pub mod close_event; +pub mod focus_event_init; +pub mod focus_event; +pub mod gesture_event_init; +pub mod gesture_event; +pub mod hashchange_event_init; +pub mod hashchange_event; +pub mod input_event_init; +pub mod input_event; +pub mod intersection_change_event_init; +pub mod intersection_change_event; +pub mod keyboard_event_init; +pub mod mouse_event_init; +pub mod mouse_event; +pub mod pointer_event_init; +pub mod pointer_event; +pub mod transition_event_init; +pub mod transition_event; +pub mod ui_event_init; +pub mod ui_event; + +pub use animation_event_init::*; +pub use animation_event::*; +pub use close_event_init::*; +pub use close_event::*; +pub use focus_event_init::*; +pub use focus_event::*; +pub use gesture_event_init::*; +pub use gesture_event::*; +pub use hashchange_event_init::*; +pub use hashchange_event::*; +pub use input_event_init::*; +pub use input_event::*; +pub use intersection_change_event_init::*; +pub use intersection_change_event::*; +pub use keyboard_event_init::*; +pub use mouse_event_init::*; +pub use mouse_event::*; +pub use pointer_event_init::*; +pub use pointer_event::*; +pub use transition_event_init::*; +pub use transition_event::*; +pub use ui_event_init::*; +pub use ui_event::*; diff --git a/bridge/rusty_webf_sys/src/mouse_event.rs b/bridge/rusty_webf_sys/src/events/mouse_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/mouse_event.rs rename to bridge/rusty_webf_sys/src/events/mouse_event.rs index b281f6e5ab..a7986e44cc 100644 --- a/bridge/rusty_webf_sys/src/mouse_event.rs +++ b/bridge/rusty_webf_sys/src/events/mouse_event.rs @@ -1,153 +1,153 @@ -// 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 MouseEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub client_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub client_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub offset_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub offset_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct MouseEvent { - pub ui_event: UIEvent, - method_pointer: *const MouseEventRustMethods, -} -impl MouseEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const MouseEventRustMethods, status: *const RustValueStatus) -> MouseEvent { - unsafe { - MouseEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn client_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).client_x)(self.ptr()) - }; - value - } - pub fn client_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).client_y)(self.ptr()) - }; - value - } - pub fn offset_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).offset_x)(self.ptr()) - }; - value - } - pub fn offset_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).offset_y)(self.ptr()) - }; - value - } -} -pub trait MouseEventMethods: UIEventMethods { - fn client_x(&self) -> f64; - fn client_y(&self) -> f64; - fn offset_x(&self) -> f64; - fn offset_y(&self) -> f64; - fn as_mouse_event(&self) -> &MouseEvent; -} -impl MouseEventMethods for MouseEvent { - fn client_x(&self) -> f64 { - self.client_x() - } - fn client_y(&self) -> f64 { - self.client_y() - } - fn offset_x(&self) -> f64 { - self.offset_x() - } - fn offset_y(&self) -> f64 { - self.offset_y() - } - fn as_mouse_event(&self) -> &MouseEvent { - self - } -} -impl UIEventMethods for MouseEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for MouseEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} +// 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 MouseEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub client_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub client_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub offset_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub offset_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct MouseEvent { + pub ui_event: UIEvent, + method_pointer: *const MouseEventRustMethods, +} +impl MouseEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const MouseEventRustMethods, status: *const RustValueStatus) -> MouseEvent { + unsafe { + MouseEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn client_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).client_x)(self.ptr()) + }; + value + } + pub fn client_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).client_y)(self.ptr()) + }; + value + } + pub fn offset_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).offset_x)(self.ptr()) + }; + value + } + pub fn offset_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).offset_y)(self.ptr()) + }; + value + } +} +pub trait MouseEventMethods: UIEventMethods { + fn client_x(&self) -> f64; + fn client_y(&self) -> f64; + fn offset_x(&self) -> f64; + fn offset_y(&self) -> f64; + fn as_mouse_event(&self) -> &MouseEvent; +} +impl MouseEventMethods for MouseEvent { + fn client_x(&self) -> f64 { + self.client_x() + } + fn client_y(&self) -> f64 { + self.client_y() + } + fn offset_x(&self) -> f64 { + self.offset_x() + } + fn offset_y(&self) -> f64 { + self.offset_y() + } + fn as_mouse_event(&self) -> &MouseEvent { + self + } +} +impl UIEventMethods for MouseEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for MouseEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/mouse_event_init.rs b/bridge/rusty_webf_sys/src/events/mouse_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/mouse_event_init.rs rename to bridge/rusty_webf_sys/src/events/mouse_event_init.rs index d2619818a4..56f0d81a10 100644 --- a/bridge/rusty_webf_sys/src/mouse_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/mouse_event_init.rs @@ -1,13 +1,13 @@ -// 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 MouseEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, -} +// 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 MouseEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, +} diff --git a/bridge/rusty_webf_sys/src/pointer_event.rs b/bridge/rusty_webf_sys/src/events/pointer_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/pointer_event.rs rename to bridge/rusty_webf_sys/src/events/pointer_event.rs index c021e8acb3..262e3169a6 100644 --- a/bridge/rusty_webf_sys/src/pointer_event.rs +++ b/bridge/rusty_webf_sys/src/events/pointer_event.rs @@ -1,238 +1,238 @@ -// 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 PointerEventRustMethods { - pub version: c_double, - pub mouse_event: MouseEventRustMethods, - pub height: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub is_primary: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub pointer_id: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tangential_pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tilt_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tilt_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub twist: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub width: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct PointerEvent { - pub mouse_event: MouseEvent, - method_pointer: *const PointerEventRustMethods, -} -impl PointerEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const PointerEventRustMethods, status: *const RustValueStatus) -> PointerEvent { - unsafe { - PointerEvent { - mouse_event: MouseEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().mouse_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.mouse_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.mouse_event.context() - } - pub fn height(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).height)(self.ptr()) - }; - value - } - pub fn is_primary(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).is_primary)(self.ptr()) - }; - value != 0 - } - pub fn pointer_id(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).pointer_id)(self.ptr()) - }; - value - } - pub fn pointer_type(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pointer_type)(self.ptr()) - }; +// 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 PointerEventRustMethods { + pub version: c_double, + pub mouse_event: MouseEventRustMethods, + pub height: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub is_primary: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub pointer_id: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tangential_pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tilt_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tilt_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub twist: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub width: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct PointerEvent { + pub mouse_event: MouseEvent, + method_pointer: *const PointerEventRustMethods, +} +impl PointerEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const PointerEventRustMethods, status: *const RustValueStatus) -> PointerEvent { + unsafe { + PointerEvent { + mouse_event: MouseEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().mouse_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.mouse_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.mouse_event.context() + } + pub fn height(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).height)(self.ptr()) + }; + value + } + pub fn is_primary(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).is_primary)(self.ptr()) + }; + value != 0 + } + pub fn pointer_id(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).pointer_id)(self.ptr()) + }; + value + } + pub fn pointer_type(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pointer_type)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn pressure(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).pressure)(self.ptr()) - }; - value - } - pub fn tangential_pressure(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tangential_pressure)(self.ptr()) - }; - value - } - pub fn tilt_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tilt_x)(self.ptr()) - }; - value - } - pub fn tilt_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tilt_y)(self.ptr()) - }; - value - } - pub fn twist(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).twist)(self.ptr()) - }; - value - } - pub fn width(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).width)(self.ptr()) - }; - value - } -} -pub trait PointerEventMethods: MouseEventMethods { - fn height(&self) -> f64; - fn is_primary(&self) -> bool; - fn pointer_id(&self) -> f64; - fn pointer_type(&self) -> String; - fn pressure(&self) -> f64; - fn tangential_pressure(&self) -> f64; - fn tilt_x(&self) -> f64; - fn tilt_y(&self) -> f64; - fn twist(&self) -> f64; - fn width(&self) -> f64; - fn as_pointer_event(&self) -> &PointerEvent; -} -impl PointerEventMethods for PointerEvent { - fn height(&self) -> f64 { - self.height() - } - fn is_primary(&self) -> bool { - self.is_primary() - } - fn pointer_id(&self) -> f64 { - self.pointer_id() - } - fn pointer_type(&self) -> String { - self.pointer_type() - } - fn pressure(&self) -> f64 { - self.pressure() - } - fn tangential_pressure(&self) -> f64 { - self.tangential_pressure() - } - fn tilt_x(&self) -> f64 { - self.tilt_x() - } - fn tilt_y(&self) -> f64 { - self.tilt_y() - } - fn twist(&self) -> f64 { - self.twist() - } - fn width(&self) -> f64 { - self.width() - } - fn as_pointer_event(&self) -> &PointerEvent { - self - } -} -impl MouseEventMethods for PointerEvent { - fn client_x(&self) -> f64 { - self.mouse_event.client_x() - } - fn client_y(&self) -> f64 { - self.mouse_event.client_y() - } - fn offset_x(&self) -> f64 { - self.mouse_event.offset_x() - } - fn offset_y(&self) -> f64 { - self.mouse_event.offset_y() - } - fn as_mouse_event(&self) -> &MouseEvent { - &self.mouse_event - } -} -impl UIEventMethods for PointerEvent { - fn detail(&self) -> f64 { - self.mouse_event.ui_event.detail() - } - fn view(&self) -> Window { - self.mouse_event.ui_event.view() - } - fn which(&self) -> f64 { - self.mouse_event.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.mouse_event.ui_event - } -} -impl EventMethods for PointerEvent { - fn bubbles(&self) -> bool { - self.mouse_event.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.mouse_event.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.mouse_event.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.mouse_event.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.mouse_event.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.mouse_event.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.mouse_event.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.mouse_event.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.mouse_event.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.mouse_event.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.mouse_event.ui_event.event - } -} + value.to_str().unwrap().to_string() + } + pub fn pressure(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).pressure)(self.ptr()) + }; + value + } + pub fn tangential_pressure(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tangential_pressure)(self.ptr()) + }; + value + } + pub fn tilt_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tilt_x)(self.ptr()) + }; + value + } + pub fn tilt_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tilt_y)(self.ptr()) + }; + value + } + pub fn twist(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).twist)(self.ptr()) + }; + value + } + pub fn width(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).width)(self.ptr()) + }; + value + } +} +pub trait PointerEventMethods: MouseEventMethods { + fn height(&self) -> f64; + fn is_primary(&self) -> bool; + fn pointer_id(&self) -> f64; + fn pointer_type(&self) -> String; + fn pressure(&self) -> f64; + fn tangential_pressure(&self) -> f64; + fn tilt_x(&self) -> f64; + fn tilt_y(&self) -> f64; + fn twist(&self) -> f64; + fn width(&self) -> f64; + fn as_pointer_event(&self) -> &PointerEvent; +} +impl PointerEventMethods for PointerEvent { + fn height(&self) -> f64 { + self.height() + } + fn is_primary(&self) -> bool { + self.is_primary() + } + fn pointer_id(&self) -> f64 { + self.pointer_id() + } + fn pointer_type(&self) -> String { + self.pointer_type() + } + fn pressure(&self) -> f64 { + self.pressure() + } + fn tangential_pressure(&self) -> f64 { + self.tangential_pressure() + } + fn tilt_x(&self) -> f64 { + self.tilt_x() + } + fn tilt_y(&self) -> f64 { + self.tilt_y() + } + fn twist(&self) -> f64 { + self.twist() + } + fn width(&self) -> f64 { + self.width() + } + fn as_pointer_event(&self) -> &PointerEvent { + self + } +} +impl MouseEventMethods for PointerEvent { + fn client_x(&self) -> f64 { + self.mouse_event.client_x() + } + fn client_y(&self) -> f64 { + self.mouse_event.client_y() + } + fn offset_x(&self) -> f64 { + self.mouse_event.offset_x() + } + fn offset_y(&self) -> f64 { + self.mouse_event.offset_y() + } + fn as_mouse_event(&self) -> &MouseEvent { + &self.mouse_event + } +} +impl UIEventMethods for PointerEvent { + fn detail(&self) -> f64 { + self.mouse_event.ui_event.detail() + } + fn view(&self) -> Window { + self.mouse_event.ui_event.view() + } + fn which(&self) -> f64 { + self.mouse_event.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.mouse_event.ui_event + } +} +impl EventMethods for PointerEvent { + fn bubbles(&self) -> bool { + self.mouse_event.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.mouse_event.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.mouse_event.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.mouse_event.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.mouse_event.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.mouse_event.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.mouse_event.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.mouse_event.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.mouse_event.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.mouse_event.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.mouse_event.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/pointer_event_init.rs b/bridge/rusty_webf_sys/src/events/pointer_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/pointer_event_init.rs rename to bridge/rusty_webf_sys/src/events/pointer_event_init.rs index d76286ad77..8b4bd24cf1 100644 --- a/bridge/rusty_webf_sys/src/pointer_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/pointer_event_init.rs @@ -1,20 +1,20 @@ -// 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 PointerEventInit { - pub is_primary: i32, - pub pointer_id: c_double, - pub pointer_type: *const c_char, - pub pressure: c_double, - pub tangential_pressure: c_double, - pub tilt_x: c_double, - pub tilt_y: c_double, - pub twist: c_double, - pub width: c_double, - pub height: c_double, -} +// 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 PointerEventInit { + pub is_primary: i32, + pub pointer_id: c_double, + pub pointer_type: *const c_char, + pub pressure: c_double, + pub tangential_pressure: c_double, + pub tilt_x: c_double, + pub tilt_y: c_double, + pub twist: c_double, + pub width: c_double, + pub height: c_double, +} diff --git a/bridge/rusty_webf_sys/src/transition_event.rs b/bridge/rusty_webf_sys/src/events/transition_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/transition_event.rs rename to bridge/rusty_webf_sys/src/events/transition_event.rs index 3cfa89b813..315e6eb42a 100644 --- a/bridge/rusty_webf_sys/src/transition_event.rs +++ b/bridge/rusty_webf_sys/src/events/transition_event.rs @@ -1,132 +1,132 @@ -// 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 TransitionEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct TransitionEvent { - pub event: Event, - method_pointer: *const TransitionEventRustMethods, -} -impl TransitionEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const TransitionEventRustMethods, status: *const RustValueStatus) -> TransitionEvent { - unsafe { - TransitionEvent { - 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 elapsed_time(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).elapsed_time)(self.ptr()) - }; - value - } - pub fn property_name(&self) -> String { - let value = unsafe { - ((*self.method_pointer).property_name)(self.ptr()) - }; +// 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 TransitionEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct TransitionEvent { + pub event: Event, + method_pointer: *const TransitionEventRustMethods, +} +impl TransitionEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const TransitionEventRustMethods, status: *const RustValueStatus) -> TransitionEvent { + unsafe { + TransitionEvent { + 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 elapsed_time(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).elapsed_time)(self.ptr()) + }; + value + } + pub fn property_name(&self) -> String { + let value = unsafe { + ((*self.method_pointer).property_name)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn pseudo_element(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pseudo_element)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn pseudo_element(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pseudo_element)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait TransitionEventMethods: EventMethods { - fn elapsed_time(&self) -> f64; - fn property_name(&self) -> String; - fn pseudo_element(&self) -> String; - fn as_transition_event(&self) -> &TransitionEvent; -} -impl TransitionEventMethods for TransitionEvent { - fn elapsed_time(&self) -> f64 { - self.elapsed_time() - } - fn property_name(&self) -> String { - self.property_name() - } - fn pseudo_element(&self) -> String { - self.pseudo_element() - } - fn as_transition_event(&self) -> &TransitionEvent { - self - } -} -impl EventMethods for TransitionEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait TransitionEventMethods: EventMethods { + fn elapsed_time(&self) -> f64; + fn property_name(&self) -> String; + fn pseudo_element(&self) -> String; + fn as_transition_event(&self) -> &TransitionEvent; +} +impl TransitionEventMethods for TransitionEvent { + fn elapsed_time(&self) -> f64 { + self.elapsed_time() + } + fn property_name(&self) -> String { + self.property_name() + } + fn pseudo_element(&self) -> String { + self.pseudo_element() + } + fn as_transition_event(&self) -> &TransitionEvent { + self + } +} +impl EventMethods for TransitionEvent { + 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/transition_event_init.rs b/bridge/rusty_webf_sys/src/events/transition_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/transition_event_init.rs rename to bridge/rusty_webf_sys/src/events/transition_event_init.rs index 1929805a54..109a3eaa6f 100644 --- a/bridge/rusty_webf_sys/src/transition_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/transition_event_init.rs @@ -1,16 +1,16 @@ -// 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 TransitionEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub elapsed_time: c_double, - pub property_name: *const c_char, - pub pseudo_element: *const c_char, -} +// 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 TransitionEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub elapsed_time: c_double, + pub property_name: *const c_char, + pub pseudo_element: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/ui_event.rs b/bridge/rusty_webf_sys/src/events/ui_event.rs similarity index 96% rename from bridge/rusty_webf_sys/src/ui_event.rs rename to bridge/rusty_webf_sys/src/events/ui_event.rs index 9b007486aa..b1450d222b 100644 --- a/bridge/rusty_webf_sys/src/ui_event.rs +++ b/bridge/rusty_webf_sys/src/events/ui_event.rs @@ -1,128 +1,128 @@ -// 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 UIEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub detail: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub view: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub which: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct UIEvent { - pub event: Event, - method_pointer: *const UIEventRustMethods, -} -impl UIEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const UIEventRustMethods, status: *const RustValueStatus) -> UIEvent { - unsafe { - UIEvent { - 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) -> f64 { - let value = unsafe { - ((*self.method_pointer).detail)(self.ptr()) - }; - value - } - pub fn view(&self) -> Window { - let value = unsafe { - ((*self.method_pointer).view)(self.ptr()) - }; - Window::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn which(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).which)(self.ptr()) - }; - value - } -} -pub trait UIEventMethods: EventMethods { - fn detail(&self) -> f64; - fn view(&self) -> Window; - fn which(&self) -> f64; - fn as_ui_event(&self) -> &UIEvent; -} -impl UIEventMethods for UIEvent { - fn detail(&self) -> f64 { - self.detail() - } - fn view(&self) -> Window { - self.view() - } - fn which(&self) -> f64 { - self.which() - } - fn as_ui_event(&self) -> &UIEvent { - self - } -} -impl EventMethods for UIEvent { - 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 - } -} +// 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 UIEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub detail: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub view: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub which: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct UIEvent { + pub event: Event, + method_pointer: *const UIEventRustMethods, +} +impl UIEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const UIEventRustMethods, status: *const RustValueStatus) -> UIEvent { + unsafe { + UIEvent { + 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) -> f64 { + let value = unsafe { + ((*self.method_pointer).detail)(self.ptr()) + }; + value + } + pub fn view(&self) -> Window { + let value = unsafe { + ((*self.method_pointer).view)(self.ptr()) + }; + Window::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn which(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).which)(self.ptr()) + }; + value + } +} +pub trait UIEventMethods: EventMethods { + fn detail(&self) -> f64; + fn view(&self) -> Window; + fn which(&self) -> f64; + fn as_ui_event(&self) -> &UIEvent; +} +impl UIEventMethods for UIEvent { + fn detail(&self) -> f64 { + self.detail() + } + fn view(&self) -> Window { + self.view() + } + fn which(&self) -> f64 { + self.which() + } + fn as_ui_event(&self) -> &UIEvent { + self + } +} +impl EventMethods for UIEvent { + 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/ui_event_init.rs b/bridge/rusty_webf_sys/src/events/ui_event_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/ui_event_init.rs rename to bridge/rusty_webf_sys/src/events/ui_event_init.rs index bad73efe5e..df50c26a95 100644 --- a/bridge/rusty_webf_sys/src/ui_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/ui_event_init.rs @@ -1,16 +1,16 @@ -// 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 UIEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub detail: c_double, - pub view: RustValue, - pub which: c_double, -} +// 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 UIEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub detail: c_double, + pub view: RustValue, + pub which: c_double, +} diff --git a/bridge/rusty_webf_sys/src/frame/mod.rs b/bridge/rusty_webf_sys/src/frame/mod.rs new file mode 100644 index 0000000000..7f61155649 --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/mod.rs @@ -0,0 +1,6 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod window; + +pub use window::*; diff --git a/bridge/rusty_webf_sys/src/window.rs b/bridge/rusty_webf_sys/src/frame/window.rs similarity index 100% rename from bridge/rusty_webf_sys/src/window.rs rename to bridge/rusty_webf_sys/src/frame/window.rs diff --git a/bridge/rusty_webf_sys/src/html_element.rs b/bridge/rusty_webf_sys/src/html/html_element.rs similarity index 100% rename from bridge/rusty_webf_sys/src/html_element.rs rename to bridge/rusty_webf_sys/src/html/html_element.rs diff --git a/bridge/rusty_webf_sys/src/html/mod.rs b/bridge/rusty_webf_sys/src/html/mod.rs new file mode 100644 index 0000000000..26b1fcaacb --- /dev/null +++ b/bridge/rusty_webf_sys/src/html/mod.rs @@ -0,0 +1,6 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod html_element; + +pub use html_element::*; diff --git a/bridge/rusty_webf_sys/src/input/mod.rs b/bridge/rusty_webf_sys/src/input/mod.rs new file mode 100644 index 0000000000..fb13bed837 --- /dev/null +++ b/bridge/rusty_webf_sys/src/input/mod.rs @@ -0,0 +1,6 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod touch_init; + +pub use touch_init::*; diff --git a/bridge/rusty_webf_sys/src/touch_init.rs b/bridge/rusty_webf_sys/src/input/touch_init.rs similarity index 96% rename from bridge/rusty_webf_sys/src/touch_init.rs rename to bridge/rusty_webf_sys/src/input/touch_init.rs index de06dd9b8f..8dcef7521e 100644 --- a/bridge/rusty_webf_sys/src/touch_init.rs +++ b/bridge/rusty_webf_sys/src/input/touch_init.rs @@ -1,22 +1,22 @@ -// 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 TouchInit { - pub identifier: c_double, - pub target: RustValue, - pub client_x: c_double, - pub client_y: c_double, - pub screen_x: c_double, - pub screen_y: c_double, - pub page_x: c_double, - pub page_y: c_double, - pub radius_x: c_double, - pub radius_y: c_double, - pub rotation_angle: c_double, - pub force: c_double, -} +// 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 TouchInit { + pub identifier: c_double, + pub target: RustValue, + pub client_x: c_double, + pub client_y: c_double, + pub screen_x: c_double, + pub screen_y: c_double, + pub page_x: c_double, + pub page_y: c_double, + pub radius_x: c_double, + pub radius_y: c_double, + pub rotation_angle: c_double, + pub force: c_double, +} diff --git a/bridge/rusty_webf_sys/src/lib.rs b/bridge/rusty_webf_sys/src/lib.rs index 8f1e0413c7..2c3c8543ea 100644 --- a/bridge/rusty_webf_sys/src/lib.rs +++ b/bridge/rusty_webf_sys/src/lib.rs @@ -4,105 +4,34 @@ #![allow(unused)] use crate::executing_context::{ExecutingContext, ExecutingContextRustMethods}; -pub mod executing_context; -pub mod document; -pub mod window; -pub mod element; -pub mod document_fragment; -pub mod node; -pub mod event_target; -pub mod event; -pub mod animation_event; -pub mod close_event; -pub mod focus_event; -pub mod gesture_event; -pub mod hashchange_event; -pub mod input_event; -pub mod intersection_change_event; -pub mod mouse_event; -pub mod pointer_event; -pub mod transition_event; -pub mod ui_event; -pub mod container_node; +pub mod dom; +pub mod events; +pub mod frame; +pub mod html; +pub mod input; + pub mod exception_state; -pub mod text; -pub mod comment; -pub mod character_data; -pub mod html_element; +pub mod executing_context; +mod memory_utils; +pub mod native_value; pub mod script_value_ref; -pub mod custom_event; -pub mod add_event_listener_options; -pub mod animation_event_init; -pub mod close_event_init; -pub mod event_init; -pub mod event_listener_options; -pub mod focus_event_init; -pub mod gesture_event_init; -pub mod hashchange_event_init; -pub mod input_event_init; -pub mod intersection_change_event_init; -pub mod keyboard_event_init; -pub mod mouse_event_init; -pub mod pointer_event_init; -pub mod scroll_options; -pub mod scroll_to_options; -pub mod touch_init; -pub mod transition_event_init; -pub mod ui_event_init; pub mod webf_event_listener; pub mod webf_function; -mod memory_utils; -pub mod native_value; -pub use executing_context::*; -pub use document::*; -pub use window::*; -pub use element::*; -pub use document_fragment::*; -pub use node::*; -pub use event_target::*; -pub use event::*; -pub use animation_event::*; -pub use close_event::*; -pub use focus_event::*; -pub use gesture_event::*; -pub use hashchange_event::*; -pub use input_event::*; -pub use intersection_change_event::*; -pub use mouse_event::*; -pub use pointer_event::*; -pub use transition_event::*; -pub use ui_event::*; -pub use container_node::*; +pub use dom::*; +pub use events::*; +pub use frame::*; +pub use html::*; +pub use input::*; + pub use exception_state::*; pub use executing_context::*; -pub use text::*; -pub use comment::*; -pub use character_data::*; -pub use html_element::*; +pub use native_value::*; pub use script_value_ref::*; -pub use custom_event::*; -pub use add_event_listener_options::*; -pub use animation_event_init::*; -pub use close_event_init::*; -pub use event_init::*; -pub use event_listener_options::*; -pub use focus_event_init::*; -pub use gesture_event_init::*; -pub use hashchange_event_init::*; -pub use input_event_init::*; -pub use intersection_change_event_init::*; -pub use keyboard_event_init::*; -pub use mouse_event_init::*; -pub use pointer_event_init::*; -pub use scroll_options::*; -pub use scroll_to_options::*; -pub use touch_init::*; -pub use transition_event_init::*; -pub use ui_event_init::*; pub use webf_event_listener::*; pub use webf_function::*; -pub use native_value::*; + + #[repr(C)] pub struct OpaquePtr; diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index 607af7602d..faf34c3a4d 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -154,7 +154,8 @@ impl NativeValue { self.u.ptr as *mut NativeValue }; for i in 0..self.uint32 { - let val = unsafe { ptr.add(i).read() }; + let offset = i.try_into().unwrap(); + let val = unsafe { ptr.add(offset).read() }; values.push(val); } values diff --git a/bridge/scripts/code_generator/bin/code_generator.js b/bridge/scripts/code_generator/bin/code_generator.js index 13a4198132..c7535f0a85 100644 --- a/bridge/scripts/code_generator/bin/code_generator.js +++ b/bridge/scripts/code_generator/bin/code_generator.js @@ -277,12 +277,15 @@ function genRustCodeFromTypeDefine() { for (let i = 0; i < blobs.length; i ++) { let b = blobs[i]; let result = generateRustSource(b); + const folders = b.source.replace(source, '').replace(b.filename + '.d.ts', '').split(path.sep) + .filter(f => f !== '').join(path.sep); + const rsDist = path.join(b.dist, '../rusty_webf_sys/src', folders); - if (!fs.existsSync(b.dist)) { - fs.mkdirSync(b.dist, {recursive: true}); + if (!fs.existsSync(rsDist)) { + fs.mkdirSync(rsDist, {recursive: true}); } - let genFilePath = path.join(b.dist, '../rusty_webf_sys/src', b.filename); + let genFilePath = path.join(rsDist, b.filename); wirteFileIfChanged(genFilePath + '.rs', result); } From 2711fd256d69f7ef7e9b9882abbdb0ad267213e2 Mon Sep 17 00:00:00 2001 From: "AzureAD\\JiaxunWei" Date: Sun, 1 Dec 2024 21:04:49 +0800 Subject: [PATCH 05/19] feat: add navigator --- .../rusty_webf_sys/src/executing_context.rs | 4 ++ bridge/rusty_webf_sys/src/frame/mod.rs | 2 + bridge/rusty_webf_sys/src/frame/navigator.rs | 58 +++++++++++++++++++ bridge/rusty_webf_sys/src/lib.rs | 2 - webf/example/rust_builder/rust/src/lib.rs | 28 ++++----- 5 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 bridge/rusty_webf_sys/src/frame/navigator.rs diff --git a/bridge/rusty_webf_sys/src/executing_context.rs b/bridge/rusty_webf_sys/src/executing_context.rs index 608069f992..eadf53cd6e 100644 --- a/bridge/rusty_webf_sys/src/executing_context.rs +++ b/bridge/rusty_webf_sys/src/executing_context.rs @@ -79,6 +79,10 @@ impl ExecutingContext { return Document::initialize::(result.value, self, result.method_pointer, result.status); } + pub fn navigator(&self) -> Navigator { + Navigator::initialize(self) + } + pub fn create_exception_state(&self) -> ExceptionState { let result = unsafe { ((*self.method_pointer).create_exception_state)() diff --git a/bridge/rusty_webf_sys/src/frame/mod.rs b/bridge/rusty_webf_sys/src/frame/mod.rs index 7f61155649..636ff722b6 100644 --- a/bridge/rusty_webf_sys/src/frame/mod.rs +++ b/bridge/rusty_webf_sys/src/frame/mod.rs @@ -1,6 +1,8 @@ /* * Copyright (C) 2022-present The WebF authors. All rights reserved. */ +pub mod navigator; pub mod window; +pub use navigator::*; pub use window::*; diff --git a/bridge/rusty_webf_sys/src/frame/navigator.rs b/bridge/rusty_webf_sys/src/frame/navigator.rs new file mode 100644 index 0000000000..8927947bd7 --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/navigator.rs @@ -0,0 +1,58 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ + +use crate::*; + +pub struct Navigator { + context: *const ExecutingContext, +} + +impl Navigator { + pub fn initialize(context: *const ExecutingContext) -> Navigator { + Navigator { + context + } + } + + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + + pub fn user_agent(&self, exception_state: &ExceptionState) -> String { + let ua_string = self.context().webf_invoke_module("Navigator", "getUserAgent", exception_state).unwrap(); + ua_string.to_string() + } + + pub fn platform(&self, exception_state: &ExceptionState) -> String { + let platform_string = self.context().webf_invoke_module("Navigator", "getPlatform", exception_state).unwrap(); + platform_string.to_string() + } + + pub fn language(&self, exception_state: &ExceptionState) -> String { + let language_string = self.context().webf_invoke_module("Navigator", "getLanguage", exception_state).unwrap(); + language_string.to_string() + } + + pub fn languages(&self, exception_state: &ExceptionState) -> String { + let languages_string = self.context().webf_invoke_module("Navigator", "getLanguages", exception_state).unwrap(); + languages_string.to_string() + } + + pub fn app_name(&self, exception_state: &ExceptionState) -> String { + let app_name_string = self.context().webf_invoke_module("Navigator", "getAppName", exception_state).unwrap(); + app_name_string.to_string() + } + + pub fn app_version(&self, exception_state: &ExceptionState) -> String { + let app_version_string = self.context().webf_invoke_module("Navigator", "getAppVersion", exception_state).unwrap(); + app_version_string.to_string() + } + + pub fn hardware_concurrency(&self, exception_state: &ExceptionState) -> i32 { + let hardware_concurrency = self.context().webf_invoke_module("Navigator", "getHardwareConcurrency", exception_state).unwrap(); + let concurrency_string = hardware_concurrency.to_string(); + i32::from_str_radix(&concurrency_string, 10).unwrap() + } +} diff --git a/bridge/rusty_webf_sys/src/lib.rs b/bridge/rusty_webf_sys/src/lib.rs index 2c3c8543ea..a6cb187f0d 100644 --- a/bridge/rusty_webf_sys/src/lib.rs +++ b/bridge/rusty_webf_sys/src/lib.rs @@ -31,8 +31,6 @@ pub use script_value_ref::*; pub use webf_event_listener::*; pub use webf_function::*; - - #[repr(C)] pub struct OpaquePtr; diff --git a/webf/example/rust_builder/rust/src/lib.rs b/webf/example/rust_builder/rust/src/lib.rs index b30c9cfa1d..5b08a39ab4 100644 --- a/webf/example/rust_builder/rust/src/lib.rs +++ b/webf/example/rust_builder/rust/src/lib.rs @@ -1,7 +1,7 @@ use std::ffi::{c_void, CString}; use webf_sys::event::Event; use webf_sys::executing_context::ExecutingContextRustMethods; -use webf_sys::{element, initialize_webf_api, AddEventListenerOptions, EventMethods, EventTargetMethods, NativeValue, RustValue}; +use webf_sys::{element, initialize_webf_api, navigator, AddEventListenerOptions, EventMethods, EventTargetMethods, NativeValue, RustValue}; use webf_sys::element::Element; use webf_sys::node::NodeMethods; @@ -11,20 +11,20 @@ pub extern "C" fn init_webf_app(handle: RustValue) println!("Context created"); let exception_state = context.create_exception_state(); let document = context.document(); - - let param1 = NativeValue::new_bool(true); - let param2 = NativeValue::new_bool(true); - let param3 = NativeValue::new_bool(true); - let param4 = NativeValue::new_bool(true); - - let params_vec = vec![param1, param2, param3, param4]; - let params = NativeValue::new_list(params_vec); - - let ua_string = context.webf_invoke_module_with_params("Navigator", "getUserAgent", ¶ms, &exception_state).unwrap(); - - let ua_string = ua_string.to_string(); - + let navigator = context.navigator(); + + let ua_string = navigator.user_agent(&exception_state); + let platform = navigator.platform(&exception_state); + let language = navigator.language(&exception_state); + let app_name = navigator.app_name(&exception_state); + let app_version = navigator.app_version(&exception_state); + let hardware_concurrency = navigator.hardware_concurrency(&exception_state); println!("User Agent: {}", ua_string); + println!("Platform: {}", platform); + println!("Language: {}", language); + println!("App Name: {}", app_name); + println!("App Version: {}", app_version); + println!("Hardware Concurrency: {}", hardware_concurrency); let timer_callback = Box::new(move || { println!("Timer Callback"); From b6beb5953ccd86d3da32e3610dfbdccc92cfd16d Mon Sep 17 00:00:00 2001 From: Andy Dong Date: Mon, 2 Dec 2024 16:37:36 +0800 Subject: [PATCH 06/19] Update code_linter.yml --- .github/workflows/code_linter.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/code_linter.yml b/.github/workflows/code_linter.yml index 78624cbc20..a3c2cfe311 100644 --- a/.github/workflows/code_linter.yml +++ b/.github/workflows/code_linter.yml @@ -50,11 +50,9 @@ jobs: extensions: 'h,cc,c' clangFormatVersion: 12 inplace: True - - uses: EndBug/add-and-commit@v4 + - uses: EndBug/add-and-commit@v9 with: author_name: openwebf-bot author_email: openwebf@openwebf.com message: 'Committing clang-format changes' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 8dd6a679f0e28152cca3bb836bdbfcb3dfd4df77 Mon Sep 17 00:00:00 2001 From: Andy Dong Date: Mon, 2 Dec 2024 17:06:56 +0800 Subject: [PATCH 07/19] Update code_linter.yml --- .github/workflows/code_linter.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code_linter.yml b/.github/workflows/code_linter.yml index a3c2cfe311..d4eafc1c58 100644 --- a/.github/workflows/code_linter.yml +++ b/.github/workflows/code_linter.yml @@ -52,7 +52,7 @@ jobs: inplace: True - uses: EndBug/add-and-commit@v9 with: - author_name: openwebf-bot - author_email: openwebf@openwebf.com - message: 'Committing clang-format changes' + default_author: github_actions + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From fb49b58cd8ed69fe7a77d1b4c4873c7ec8b4777e Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:07:48 +0000 Subject: [PATCH 08/19] Commit from GitHub Actions (Run Code Linter) --- bridge/core/api/executing_context.cc | 32 +++++++----- bridge/core/frame/module_manager.cc | 11 ++-- bridge/core/page.cc | 15 +++--- bridge/foundation/dart_readable.cc | 1 - bridge/include/plugin_api/executing_context.h | 51 +++++++++---------- 5 files changed, 53 insertions(+), 57 deletions(-) diff --git a/bridge/core/api/executing_context.cc b/bridge/core/api/executing_context.cc index 1c71554082..265540ea09 100644 --- a/bridge/core/api/executing_context.cc +++ b/bridge/core/api/executing_context.cc @@ -7,9 +7,9 @@ #include "core/api/exception_state.h" #include "core/dom/document.h" #include "core/executing_context.h" +#include "core/frame/module_manager.h" #include "core/frame/window.h" #include "core/frame/window_or_worker_global_scope.h" -#include "core/frame/module_manager.h" #include "foundation/native_value_converter.h" namespace webf { @@ -41,7 +41,8 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModule(ExecutingContext* cont AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); AtomicString method_atomic = webf::AtomicString(context->ctx(), method); - ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, shared_exception_state->exception_state); + ScriptValue result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, + shared_exception_state->exception_state); NativeValue return_result = result.ToNative(context->ctx(), shared_exception_state->exception_state); if (shared_exception_state->exception_state.HasException()) { @@ -52,14 +53,15 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModule(ExecutingContext* cont } NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParams(ExecutingContext* context, - const char* module_name, - const char* method, - NativeValue* params, - SharedExceptionState* shared_exception_state) { + const char* module_name, + const char* method, + NativeValue* params, + SharedExceptionState* shared_exception_state) { AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); AtomicString method_atomic = webf::AtomicString(context->ctx(), method); - const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, nullptr, shared_exception_state->exception_state); + const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, + nullptr, shared_exception_state->exception_state); if (shared_exception_state->exception_state.HasException()) { return Native_NewNull(); @@ -69,18 +71,20 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParams(ExecutingCon return return_result; } -NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParamsAndCallback(ExecutingContext* context, - const char* module_name, - const char* method, - NativeValue* params, - WebFNativeFunctionContext* callback_context, - SharedExceptionState* shared_exception_state) { +NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParamsAndCallback( + ExecutingContext* context, + const char* module_name, + const char* method, + NativeValue* params, + WebFNativeFunctionContext* callback_context, + SharedExceptionState* shared_exception_state) { AtomicString module_name_atomic = AtomicString(context->ctx(), module_name); AtomicString method_atomic = webf::AtomicString(context->ctx(), method); auto callback_impl = WebFNativeFunction::Create(callback_context, shared_exception_state); - const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, callback_impl, shared_exception_state->exception_state); + const NativeValue* result = ModuleManager::__webf_invoke_module__( + context, module_name_atomic, method_atomic, *params, callback_impl, shared_exception_state->exception_state); if (shared_exception_state->exception_state.HasException()) { return Native_NewNull(); diff --git a/bridge/core/frame/module_manager.cc b/bridge/core/frame/module_manager.cc index 9890f17e26..27ac883205 100644 --- a/bridge/core/frame/module_manager.cc +++ b/bridge/core/frame/module_manager.cc @@ -83,7 +83,6 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, callback->Invoke(context, 2, params); } } - } static void ReturnResultToDart(Dart_PersistentHandle persistent_handle, @@ -163,11 +162,11 @@ ScriptValue ModuleManager::__webf_invoke_module__(ExecutingContext* context, return return_value; } NativeValue* ModuleManager::__webf_invoke_module__(ExecutingContext* context, - const AtomicString& module_name, - const AtomicString& method, - NativeValue& params, - const std::shared_ptr& callback, - ExceptionState& exception) { + const AtomicString& module_name, + const AtomicString& method, + NativeValue& params, + const std::shared_ptr& callback, + ExceptionState& exception) { if (exception.HasException()) { return nullptr; } diff --git a/bridge/core/page.cc b/bridge/core/page.cc index f99fc30963..d84054aee9 100644 --- a/bridge/core/page.cc +++ b/bridge/core/page.cc @@ -87,7 +87,7 @@ NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, if (listener == nullptr) { return nullptr; } - + auto callback_value = listener->value(); if (auto* callback = DynamicTo(callback_value.get())) { ScriptValue arguments[] = {event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx), extraObject}; @@ -108,22 +108,21 @@ NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, memcpy(return_value, &tmp, sizeof(NativeValue)); return return_value; } else if (auto* callback = DynamicTo(callback_value.get())) { - NativeValue* params = new NativeValue[2]; - + NativeValue* params = new NativeValue[2]; + ExceptionState exception_state; ScriptValue eventValue = event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx); params[0] = eventValue.ToNative(ctx, exception_state); - params[1] = *extra; - - + params[1] = *extra; + if (exception_state.HasException()) { context_->HandleException(exception_state); return nullptr; - } + } callback->Invoke(context_, 2, params); return nullptr; - } + } } bool WebFPage::evaluateScript(const char* script, diff --git a/bridge/foundation/dart_readable.cc b/bridge/foundation/dart_readable.cc index 73801a83b2..9b475e552d 100644 --- a/bridge/foundation/dart_readable.cc +++ b/bridge/foundation/dart_readable.cc @@ -44,5 +44,4 @@ void DartReadable::operator delete[](void* memory) noexcept { dart_free(memory); } - } // namespace webf diff --git a/bridge/include/plugin_api/executing_context.h b/bridge/include/plugin_api/executing_context.h index 152065b7bb..b4ce30b3d3 100644 --- a/bridge/include/plugin_api/executing_context.h +++ b/bridge/include/plugin_api/executing_context.h @@ -5,10 +5,10 @@ #ifndef WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ #define WEBF_CORE_RUST_API_EXECUTING_CONTEXT_H_ -#include "foundation/native_value.h" #include "core/native/native_function.h" #include "document.h" #include "exception_state.h" +#include "foundation/native_value.h" #include "window.h" namespace webf { @@ -21,21 +21,15 @@ using PublicContextGetDocument = WebFValue (*)( using PublicContextGetWindow = WebFValue (*)(ExecutingContext*); using PublicContextGetExceptionState = WebFValue (*)(); using PublicFinishRecordingUIOperations = void (*)(ExecutingContext* context); -using PublicWebFInvokeModule = NativeValue (*)(ExecutingContext*, - const char*, - const char*, - SharedExceptionState*); -using PublicWebFInvokeModuleWithParams = NativeValue (*)(ExecutingContext*, - const char*, - const char*, - NativeValue*, - SharedExceptionState*); +using PublicWebFInvokeModule = NativeValue (*)(ExecutingContext*, const char*, const char*, SharedExceptionState*); +using PublicWebFInvokeModuleWithParams = + NativeValue (*)(ExecutingContext*, const char*, const char*, NativeValue*, SharedExceptionState*); using PublicWebFInvokeModuleWithParamsAndCallback = NativeValue (*)(ExecutingContext*, - const char*, - const char*, - NativeValue*, - WebFNativeFunctionContext*, - SharedExceptionState*); + const char*, + const char*, + NativeValue*, + WebFNativeFunctionContext*, + SharedExceptionState*); using PublicContextSetTimeout = int32_t (*)(ExecutingContext*, WebFNativeFunctionContext*, int32_t, @@ -55,20 +49,20 @@ struct ExecutingContextWebFMethods { static WebFValue CreateExceptionState(); static void FinishRecordingUIOperations(ExecutingContext* context); static NativeValue WebFInvokeModule(ExecutingContext* context, - const char* module_name, - const char* method, - SharedExceptionState* shared_exception_state); + const char* module_name, + const char* method, + SharedExceptionState* shared_exception_state); static NativeValue WebFInvokeModuleWithParams(ExecutingContext* context, - const char* module_name, - const char* method, - NativeValue* params, - SharedExceptionState* shared_exception_state); + const char* module_name, + const char* method, + NativeValue* params, + SharedExceptionState* shared_exception_state); static NativeValue WebFInvokeModuleWithParamsAndCallback(ExecutingContext* context, - const char* module_name, - const char* method, - NativeValue* params, - WebFNativeFunctionContext* callback_context, - SharedExceptionState* shared_exception_state); + const char* module_name, + const char* method, + NativeValue* params, + WebFNativeFunctionContext* callback_context, + SharedExceptionState* shared_exception_state); static int32_t SetTimeout(ExecutingContext* context, WebFNativeFunctionContext* callback_context, int32_t timeout, @@ -89,7 +83,8 @@ struct ExecutingContextWebFMethods { PublicFinishRecordingUIOperations context_finish_recording_ui_operations{FinishRecordingUIOperations}; PublicWebFInvokeModule context_webf_invoke_module{WebFInvokeModule}; PublicWebFInvokeModuleWithParams context_webf_invoke_module_with_params{WebFInvokeModuleWithParams}; - PublicWebFInvokeModuleWithParamsAndCallback context_webf_invoke_module_with_params_and_callback{WebFInvokeModuleWithParamsAndCallback}; + PublicWebFInvokeModuleWithParamsAndCallback context_webf_invoke_module_with_params_and_callback{ + WebFInvokeModuleWithParamsAndCallback}; PublicContextSetTimeout context_set_timeout{SetTimeout}; PublicContextSetInterval context_set_interval{SetInterval}; PublicContextClearTimeout context_clear_timeout{ClearTimeout}; From fa636445a757865ee9652e8549532d208bca0404 Mon Sep 17 00:00:00 2001 From: Jiaxun Wei Date: Sat, 7 Dec 2024 16:41:20 +0800 Subject: [PATCH 09/19] feat: support storage --- bridge/core/api/executing_context.cc | 8 +- bridge/core/frame/module_manager.cc | 7 +- bridge/include/plugin_api/executing_context.h | 3 + .../rusty_webf_sys/src/executing_context.rs | 57 +++++++++++- .../rusty_webf_sys/src/frame/async_storage.rs | 72 +++++++++++++++ .../src/frame/legacy/location.rs | 88 +++++++++++++++++++ bridge/rusty_webf_sys/src/frame/legacy/mod.rs | 6 ++ bridge/rusty_webf_sys/src/frame/mod.rs | 6 ++ bridge/rusty_webf_sys/src/frame/storage.rs | 79 +++++++++++++++++ bridge/rusty_webf_sys/src/lib.rs | 1 - bridge/rusty_webf_sys/src/native_value.rs | 56 ++++++++++-- bridge/rusty_webf_sys/src/webf_function.rs | 6 +- webf/example/rust_builder/rust/src/lib.rs | 52 ++++++++++- 13 files changed, 423 insertions(+), 18 deletions(-) create mode 100644 bridge/rusty_webf_sys/src/frame/async_storage.rs create mode 100644 bridge/rusty_webf_sys/src/frame/legacy/location.rs create mode 100644 bridge/rusty_webf_sys/src/frame/legacy/mod.rs create mode 100644 bridge/rusty_webf_sys/src/frame/storage.rs diff --git a/bridge/core/api/executing_context.cc b/bridge/core/api/executing_context.cc index 265540ea09..4e28e7ad86 100644 --- a/bridge/core/api/executing_context.cc +++ b/bridge/core/api/executing_context.cc @@ -7,6 +7,7 @@ #include "core/api/exception_state.h" #include "core/dom/document.h" #include "core/executing_context.h" +#include "core/frame/legacy/location.h" #include "core/frame/module_manager.h" #include "core/frame/window.h" #include "core/frame/window_or_worker_global_scope.h" @@ -63,7 +64,7 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParams(ExecutingCon const NativeValue* result = ModuleManager::__webf_invoke_module__(context, module_name_atomic, method_atomic, *params, nullptr, shared_exception_state->exception_state); - if (shared_exception_state->exception_state.HasException()) { + if (shared_exception_state->exception_state.HasException() || result == nullptr) { return Native_NewNull(); } @@ -94,6 +95,11 @@ NativeValue ExecutingContextWebFMethods::WebFInvokeModuleWithParamsAndCallback( return return_result; } +void ExecutingContextWebFMethods::WebFLocationReload(ExecutingContext* context, + SharedExceptionState* shared_exception_state) { + Location::__webf_location_reload__(context, shared_exception_state->exception_state); +} + int32_t ExecutingContextWebFMethods::SetTimeout(ExecutingContext* context, WebFNativeFunctionContext* callback_context, int32_t timeout, diff --git a/bridge/core/frame/module_manager.cc b/bridge/core/frame/module_manager.cc index 27ac883205..10d9d6bdd5 100644 --- a/bridge/core/frame/module_manager.cc +++ b/bridge/core/frame/module_manager.cc @@ -73,15 +73,20 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, return return_value; } else if (auto* callback = DynamicTo(callback_value.get())) { + context->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); + context->dartIsolateContext()->profiler()->StartTrackSteps("handleInvokeModuleTransientCallback"); if (errmsg != nullptr) { NativeValue error_object = Native_NewCString(errmsg); callback->Invoke(context, 1, &error_object); } else { - NativeValue* params = new NativeValue[2]; + auto params = new NativeValue[2]; params[0] = Native_NewNull(); params[1] = *extra_data; callback->Invoke(context, 2, params); } + context->dartIsolateContext()->profiler()->FinishTrackSteps(); + context->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); + return nullptr; } } diff --git a/bridge/include/plugin_api/executing_context.h b/bridge/include/plugin_api/executing_context.h index b4ce30b3d3..ac39e43886 100644 --- a/bridge/include/plugin_api/executing_context.h +++ b/bridge/include/plugin_api/executing_context.h @@ -30,6 +30,7 @@ using PublicWebFInvokeModuleWithParamsAndCallback = NativeValue (*)(ExecutingCon NativeValue*, WebFNativeFunctionContext*, SharedExceptionState*); +using PublicWebFLocationReload = void (*)(ExecutingContext*, SharedExceptionState*); using PublicContextSetTimeout = int32_t (*)(ExecutingContext*, WebFNativeFunctionContext*, int32_t, @@ -63,6 +64,7 @@ struct ExecutingContextWebFMethods { NativeValue* params, WebFNativeFunctionContext* callback_context, SharedExceptionState* shared_exception_state); + static void WebFLocationReload(ExecutingContext* context, SharedExceptionState* shared_exception_state); static int32_t SetTimeout(ExecutingContext* context, WebFNativeFunctionContext* callback_context, int32_t timeout, @@ -85,6 +87,7 @@ struct ExecutingContextWebFMethods { PublicWebFInvokeModuleWithParams context_webf_invoke_module_with_params{WebFInvokeModuleWithParams}; PublicWebFInvokeModuleWithParamsAndCallback context_webf_invoke_module_with_params_and_callback{ WebFInvokeModuleWithParamsAndCallback}; + PublicWebFLocationReload context_webf_location_reload{WebFLocationReload}; PublicContextSetTimeout context_set_timeout{SetTimeout}; PublicContextSetInterval context_set_interval{SetInterval}; PublicContextClearTimeout context_clear_timeout{ClearTimeout}; diff --git a/bridge/rusty_webf_sys/src/executing_context.rs b/bridge/rusty_webf_sys/src/executing_context.rs index eadf53cd6e..c6191d68dc 100644 --- a/bridge/rusty_webf_sys/src/executing_context.rs +++ b/bridge/rusty_webf_sys/src/executing_context.rs @@ -13,10 +13,11 @@ pub struct ExecutingContextRustMethods { pub get_document: extern "C" fn(*const OpaquePtr) -> RustValue, pub get_window: extern "C" fn(*const OpaquePtr) -> RustValue, pub create_exception_state: extern "C" fn() -> RustValue, - pub finish_recording_ui_operations: extern "C" fn(executing_context: *const OpaquePtr) -> c_void, - pub webf_invoke_module: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, exception_state: *const OpaquePtr) -> NativeValue, - pub webf_invoke_module_with_params: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, params: *const NativeValue, exception_state: *const OpaquePtr) -> NativeValue, - pub webf_invoke_module_with_params_and_callback: extern "C" fn(executing_context: *const OpaquePtr, module_name: *const c_char, method: *const c_char, params: *const NativeValue, exception_state: *const OpaquePtr) -> NativeValue, + pub finish_recording_ui_operations: extern "C" fn(*const OpaquePtr) -> c_void, + pub webf_invoke_module: extern "C" fn(*const OpaquePtr, *const c_char, *const c_char, *const OpaquePtr) -> NativeValue, + pub webf_invoke_module_with_params: extern "C" fn(*const OpaquePtr, *const c_char, *const c_char, *const NativeValue, *const OpaquePtr) -> NativeValue, + pub webf_invoke_module_with_params_and_callback: extern "C" fn(*const OpaquePtr, *const c_char, *const c_char, *const NativeValue, *const WebFNativeFunctionContext, *const OpaquePtr) -> NativeValue, + pub webf_location_reload: extern "C" fn(*const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, pub set_timeout: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, c_int, *const OpaquePtr) -> c_int, pub set_interval: extern "C" fn(*const OpaquePtr, *const WebFNativeFunctionContext, c_int, *const OpaquePtr) -> c_int, pub clear_timeout: extern "C" fn(*const OpaquePtr, c_int, *const OpaquePtr), @@ -83,6 +84,18 @@ impl ExecutingContext { Navigator::initialize(self) } + pub fn async_storage(&self) -> AsyncStorage { + AsyncStorage::initialize(self) + } + + pub fn local_storage(&self) -> Storage { + Storage::initialize(self, "LocalStorage") + } + + pub fn session_storage(&self) -> Storage { + Storage::initialize(self, "SessionStorage") + } + pub fn create_exception_state(&self) -> ExceptionState { let result = unsafe { ((*self.method_pointer).create_exception_state)() @@ -118,6 +131,42 @@ impl ExecutingContext { Ok(result) } + pub fn webf_invoke_module_with_params_and_callback(&self, module_name: &str, method: &str, params: &NativeValue, callback: WebFNativeFunction, exception_state: &ExceptionState) -> Result { + let module_name = CString::new(module_name).unwrap(); + let method = CString::new(method).unwrap(); + + let callback_data = Box::new(WebFNativeFunctionContextData { + func: callback, + }); + let callback_context_data_ptr = Box::into_raw(callback_data); + let callback_context = Box::new(WebFNativeFunctionContext { + callback: invoke_webf_native_function, + free_ptr: release_webf_native_function, + ptr: callback_context_data_ptr, + }); + let callback_context_ptr = Box::into_raw(callback_context); + + let result = unsafe { + (((*self.method_pointer).webf_invoke_module_with_params_and_callback))(self.ptr, module_name.as_ptr(), method.as_ptr(), params, callback_context_ptr, exception_state.ptr) + }; + + if exception_state.has_exception() { + unsafe { + let _ = Box::from_raw(callback_context_ptr); + let _ = Box::from_raw(callback_context_data_ptr); + } + return Err(exception_state.stringify(self)); + } + + Ok(result) + } + + pub fn webf_location_reload(&self, exception_state: &ExceptionState) { + unsafe { + ((*self.method_pointer).webf_location_reload)(self.ptr, exception_state.ptr); + } + } + pub fn set_timeout_with_callback(&self, callback: TimeoutCallback, exception_state: &ExceptionState) -> Result { self.set_timeout_with_callback_and_timeout(callback, 0, exception_state) } diff --git a/bridge/rusty_webf_sys/src/frame/async_storage.rs b/bridge/rusty_webf_sys/src/frame/async_storage.rs new file mode 100644 index 0000000000..a83d4c430b --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/async_storage.rs @@ -0,0 +1,72 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ + +use crate::*; + +pub type GetItemCallback = Box, String>)>; +pub type SetItemCallback = Box, String>)>; + +pub struct AsyncStorage { + context: *const ExecutingContext, +} + +impl AsyncStorage { + pub fn initialize(context: *const ExecutingContext) -> AsyncStorage { + AsyncStorage { + context, + } + } + + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + + pub fn get_item(&self, key: &str, callback: GetItemCallback, exception_state: &ExceptionState) { + let key_string = NativeValue::new_string(key); + let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { + if argc == 1 { + let error_string = unsafe { *argv }; + let error_string = error_string.to_string(); + callback(Err(error_string)); + return; + } + if argc == 2 { + let item_string = unsafe { *argv.wrapping_add(1) }; + if item_string.is_null() { + callback(Ok(None)); + return; + } + let item_string = item_string.to_string(); + callback(Ok(Some(item_string))); + return; + } + println!("Invalid argument count for timeout callback"); + }); + self.context().webf_invoke_module_with_params_and_callback("AsyncStorage", "getItem", &key_string, general_callback, exception_state).unwrap(); + } + + pub fn set_item(&self, key: &str, value: &str, callback: SetItemCallback, exception_state: &ExceptionState) { + let key_string = NativeValue::new_string(key); + let value_string = NativeValue::new_string(value); + let params_vec = vec![key_string, value_string]; + let params = NativeValue::new_list(params_vec); + let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { + if argc == 1 { + let error_string = unsafe { *argv }; + let error_string = error_string.to_string(); + callback(Err(error_string)); + return; + } + if argc == 2 { + let result = unsafe { *argv.wrapping_add(1) }; + let result = result.to_string(); + callback(Ok(Some(result))); + return; + } + println!("Invalid argument count for timeout callback"); + }); + self.context().webf_invoke_module_with_params_and_callback("AsyncStorage", "setItem", ¶ms, general_callback, exception_state).unwrap(); + } +} diff --git a/bridge/rusty_webf_sys/src/frame/legacy/location.rs b/bridge/rusty_webf_sys/src/frame/legacy/location.rs new file mode 100644 index 0000000000..a83935449e --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/legacy/location.rs @@ -0,0 +1,88 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ + +use std::ffi::*; +use crate::*; + +pub struct Location { + context: *const ExecutingContext, +} + +impl Location { + pub fn initialize(context: *const ExecutingContext) -> Location { + Location { + context + } + } + + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + + pub fn href(&self, exception_state: &ExceptionState) -> String { + let href_string = self.context().webf_invoke_module("Location", "href", exception_state).unwrap(); + href_string.to_string() + } + + pub fn set_href(&self, href: &str, exception_state: &ExceptionState) { + let href_string_native_value = NativeValue::new_string(href); + self.context().webf_invoke_module_with_params("Navigation", "goTo", &href_string_native_value, exception_state); + } + + pub fn origin(&self, exception_state: &ExceptionState) -> String { + let origin_string = self.context().webf_invoke_module("Location", "origin", exception_state).unwrap(); + origin_string.to_string() + } + + pub fn protocol(&self, exception_state: &ExceptionState) -> String { + let protocol_string = self.context().webf_invoke_module("Location", "protocol", exception_state).unwrap(); + protocol_string.to_string() + } + + pub fn host(&self, exception_state: &ExceptionState) -> String { + let host_string = self.context().webf_invoke_module("Location", "host", exception_state).unwrap(); + host_string.to_string() + } + + pub fn hostname(&self, exception_state: &ExceptionState) -> String { + let hostname_string = self.context().webf_invoke_module("Location", "hostname", exception_state).unwrap(); + hostname_string.to_string() + } + + pub fn port(&self, exception_state: &ExceptionState) -> String { + let port_string = self.context().webf_invoke_module("Location", "port", exception_state).unwrap(); + port_string.to_string() + } + + pub fn pathname(&self, exception_state: &ExceptionState) -> String { + let pathname_string = self.context().webf_invoke_module("Location", "pathname", exception_state).unwrap(); + pathname_string.to_string() + } + + pub fn search(&self, exception_state: &ExceptionState) -> String { + let search_string = self.context().webf_invoke_module("Location", "search", exception_state).unwrap(); + search_string.to_string() + } + + pub fn hash(&self, exception_state: &ExceptionState) -> String { + let hash_string = self.context().webf_invoke_module("Location", "hash", exception_state).unwrap(); + hash_string.to_string() + } + + pub fn assign(&self, url: &str, exception_state: &ExceptionState) { + let url_string_native_value = NativeValue::new_string(url); + self.context().webf_invoke_module_with_params("Navigation", "goTo", &url_string_native_value, exception_state); + } + + pub fn reload(&self, exception_state: &ExceptionState) { + self.context().webf_location_reload(exception_state); + } + + pub fn replace(&self, url: &str, exception_state: &ExceptionState) { + let url_string_native_value = NativeValue::new_string(url); + self.context().webf_invoke_module_with_params("Navigation", "goTo", &url_string_native_value, exception_state); + } + +} diff --git a/bridge/rusty_webf_sys/src/frame/legacy/mod.rs b/bridge/rusty_webf_sys/src/frame/legacy/mod.rs new file mode 100644 index 0000000000..fb9dc8a223 --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/legacy/mod.rs @@ -0,0 +1,6 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ +pub mod location; + +pub use location::*; diff --git a/bridge/rusty_webf_sys/src/frame/mod.rs b/bridge/rusty_webf_sys/src/frame/mod.rs index 636ff722b6..f4de0700cc 100644 --- a/bridge/rusty_webf_sys/src/frame/mod.rs +++ b/bridge/rusty_webf_sys/src/frame/mod.rs @@ -1,8 +1,14 @@ /* * Copyright (C) 2022-present The WebF authors. All rights reserved. */ +pub mod async_storage; pub mod navigator; pub mod window; +pub mod storage; +pub mod legacy; +pub use async_storage::*; pub use navigator::*; pub use window::*; +pub use storage::*; +pub use legacy::*; diff --git a/bridge/rusty_webf_sys/src/frame/storage.rs b/bridge/rusty_webf_sys/src/frame/storage.rs new file mode 100644 index 0000000000..be86479701 --- /dev/null +++ b/bridge/rusty_webf_sys/src/frame/storage.rs @@ -0,0 +1,79 @@ +/* +* Copyright (C) 2022-present The WebF authors. All rights reserved. +*/ + +use crate::*; + +pub struct Storage { + context: *const ExecutingContext, + module_name: String, +} + +impl Storage { + pub fn initialize(context: *const ExecutingContext, module_name: &str) -> Storage { + Storage { + context, + module_name: module_name.to_string(), + } + } + + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + + pub fn get_item(&self, key: &str, exception_state: &ExceptionState) -> Result, String> { + let key_string = NativeValue::new_string(key); + let item_string = self.context().webf_invoke_module_with_params(&self.module_name, "getItem", &key_string, exception_state).unwrap(); + + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + + if item_string.is_null() { + return Ok(None); + } + Ok(Some(item_string.to_string())) + } + + pub fn set_item(&self, key: &str, value: &str, exception_state: &ExceptionState) -> Result<(), String> { + let key_string = NativeValue::new_string(key); + let value_string = NativeValue::new_string(value); + let params_vec = vec![key_string, value_string]; + let params = NativeValue::new_list(params_vec); + + self.context().webf_invoke_module_with_params(&self.module_name, "setItem", ¶ms, exception_state); + + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + + Ok(()) + } + + pub fn remove_item(&self, key: &str, exception_state: &ExceptionState) { + let key_string = NativeValue::new_string(key); + self.context().webf_invoke_module_with_params(&self.module_name, "removeItem", &key_string, exception_state); + } + + pub fn clear(&self, exception_state: &ExceptionState) { + self.context().webf_invoke_module(&self.module_name, "clear", exception_state); + } + + pub fn key(&self, index: u32, exception_state: &ExceptionState) -> String { + let index_string = NativeValue::new_int64(index.into()); + let key_string = self.context().webf_invoke_module_with_params(&self.module_name, "key", &index_string, exception_state).unwrap(); + key_string.to_string() + } + + pub fn get_all_keys(&self, exception_state: &ExceptionState) -> Vec { + let result = self.context().webf_invoke_module(&self.module_name, "_getAllKeys", exception_state).unwrap(); + let result = result.to_list().iter().map(|item| item.to_string()).collect::>(); + result + } + + pub fn length(&self, exception_state: &ExceptionState) -> i64 { + let length = self.context().webf_invoke_module(&self.module_name, "length", exception_state).unwrap(); + length.to_int64() + } +} diff --git a/bridge/rusty_webf_sys/src/lib.rs b/bridge/rusty_webf_sys/src/lib.rs index a6cb187f0d..781e5de3d1 100644 --- a/bridge/rusty_webf_sys/src/lib.rs +++ b/bridge/rusty_webf_sys/src/lib.rs @@ -2,7 +2,6 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ #![allow(unused)] -use crate::executing_context::{ExecutingContext, ExecutingContextRustMethods}; pub mod dom; pub mod events; diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index faf34c3a4d..f8496ce9d2 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -5,6 +5,12 @@ use windows::Win32::System::Com::{CoTaskMemAlloc, CoTaskMemFree}; use crate::memory_utils::safe_free_cpp_ptr; +#[repr(C)] +pub struct SharedNativeString { + pub string_: *mut u16, + pub length_: u32, +} + #[repr(C)] pub enum NativeTag { TagString = 0, @@ -36,12 +42,6 @@ pub struct NativeValue { pub tag: i32, } -#[repr(C)] -pub struct SharedNativeString { - pub string_: *mut u16, - pub length_: u32, -} - impl NativeValue { pub fn new() -> Self { let size = mem::size_of::(); @@ -68,16 +68,36 @@ impl NativeValue { let ptr = unsafe { libc::malloc(size) }; let ptr = ptr as *mut u16; + let mut length = 0; for (i, c) in val.encode_utf16().enumerate() { + length = i + 1; unsafe { ptr.add(i).write(c); } } + let mut shared_string = SharedNativeString { + string_: ptr, + length_: length as u32, + }; + + let shared_string_size = mem::size_of::(); + + #[cfg(target_os = "windows")] + let shared_string_ptr = unsafe { CoTaskMemAlloc(shared_string_size) }; + + #[cfg(not(target_os = "windows"))] + let shared_string_ptr = unsafe { libc::malloc(shared_string_size) }; + + let shared_string_ptr = shared_string_ptr as *mut SharedNativeString; + unsafe { + shared_string_ptr.write(shared_string); + } + let mut value = Self::new(); value.tag = NativeTag::TagString as i32; - value.u.ptr = ptr as *mut c_void; + value.u.ptr = shared_string_ptr as *mut c_void; value.uint32 = len as u32; value } @@ -99,6 +119,10 @@ impl NativeValue { value } + pub fn is_null(&self) -> bool { + self.tag == NativeTag::TagNull as i32 + } + pub fn new_float64(val: f64) -> Self { let mut value = Self::new(); value.tag = NativeTag::TagFloat64 as i32; @@ -107,6 +131,12 @@ impl NativeValue { value } + pub fn to_float64(&self) -> f64 { + unsafe { + self.u.float64 + } + } + pub fn new_bool(val: bool) -> Self { let mut value = Self::new(); value.tag = NativeTag::TagBool as i32; @@ -115,6 +145,12 @@ impl NativeValue { value } + pub fn to_bool(&self) -> bool { + unsafe { + self.u.int64 != 0 + } + } + pub fn new_int64(val: i64) -> Self { let mut value = Self::new(); value.tag = NativeTag::TagInt as i32; @@ -123,6 +159,12 @@ impl NativeValue { value } + pub fn to_int64(&self) -> i64 { + unsafe { + self.u.int64 + } + } + pub fn new_list(values: Vec) -> Self { let size = values.len(); let array_size = size * mem::size_of::(); diff --git a/bridge/rusty_webf_sys/src/webf_function.rs b/bridge/rusty_webf_sys/src/webf_function.rs index be8ea330aa..3c1f7c230f 100644 --- a/bridge/rusty_webf_sys/src/webf_function.rs +++ b/bridge/rusty_webf_sys/src/webf_function.rs @@ -4,7 +4,7 @@ use std::ffi::*; use crate::*; -pub type WebFNativeFunction = Box; +pub type WebFNativeFunction = Box; pub struct WebFNativeFunctionContextData { pub func: WebFNativeFunction, @@ -20,7 +20,7 @@ impl Drop for WebFNativeFunctionContextData { pub struct WebFNativeFunctionContext { pub callback: extern "C" fn(callback_context: *const OpaquePtr, argc: c_int, - argv: *const OpaquePtr, + argv: *const NativeValue, exception_state: *const OpaquePtr) -> *const c_void, pub free_ptr: extern "C" fn(callback_context: *const OpaquePtr) -> *const c_void, pub ptr: *const WebFNativeFunctionContextData, @@ -29,7 +29,7 @@ pub struct WebFNativeFunctionContext { pub extern "C" fn invoke_webf_native_function( callback_context_ptr: *const OpaquePtr, argc: c_int, - argv: *const OpaquePtr, + argv: *const NativeValue, exception_state: *const OpaquePtr, ) -> *const c_void { let callback_context = unsafe { diff --git a/webf/example/rust_builder/rust/src/lib.rs b/webf/example/rust_builder/rust/src/lib.rs index 5b08a39ab4..ed7bb1ebf7 100644 --- a/webf/example/rust_builder/rust/src/lib.rs +++ b/webf/example/rust_builder/rust/src/lib.rs @@ -1,7 +1,7 @@ use std::ffi::{c_void, CString}; use webf_sys::event::Event; use webf_sys::executing_context::ExecutingContextRustMethods; -use webf_sys::{element, initialize_webf_api, navigator, AddEventListenerOptions, EventMethods, EventTargetMethods, NativeValue, RustValue}; +use webf_sys::{async_storage, element, initialize_webf_api, navigator, AddEventListenerOptions, EventMethods, EventTargetMethods, NativeValue, RustValue}; use webf_sys::element::Element; use webf_sys::node::NodeMethods; @@ -26,6 +26,56 @@ pub extern "C" fn init_webf_app(handle: RustValue) println!("App Version: {}", app_version); println!("Hardware Concurrency: {}", hardware_concurrency); + let local_storage = context.local_storage(); + + let result = local_storage.set_item("test", "test2", &exception_state); + + match result { + Ok(_) => { + println!("Local Storage Set Item Success"); + }, + Err(err) => { + println!("Local Storage Set Item Failed: {:?}", err); + } + } + + println!("Local Storage value for \"a\": {:?}", local_storage.get_item("a", &exception_state)); + println!("Local Storage Keys: {:?}", local_storage.get_all_keys(&exception_state)); + println!("Local Storage Length: {:?}", local_storage.length(&exception_state)); + println!("Local Storage value for \"test\": {:?}", local_storage.get_item("test", &exception_state)); + + local_storage.clear(&exception_state); + + let async_storage_1 = context.async_storage(); + + let async_storage_set_item_callback = Box::new(|value: Result, String>| { + match value { + Ok(value) => { + println!("Async Storage Set Item Success: {:?}", value); + }, + Err(err) => { + println!("Async Storage Set Item Failed: {:?}", err); + } + } + }); + + async_storage_1.set_item("a", "b", async_storage_set_item_callback, &exception_state); + + let async_storage_2 = context.async_storage(); + + let async_storage_get_item_callback = Box::new(|value: Result, String>| { + match value { + Ok(value) => { + println!("Async Storage Get Item Success: {:?}", value); + }, + Err(err) => { + println!("Async Storage Get Item Failed: {:?}", err); + } + } + }); + + async_storage_2.get_item("a", async_storage_get_item_callback, &exception_state); + let timer_callback = Box::new(move || { println!("Timer Callback"); }); From 272526a5ebcb42f0dc45e47cd770c9d4e24d20e6 Mon Sep 17 00:00:00 2001 From: Jiaxun Wei Date: Sat, 14 Dec 2024 19:25:19 +0800 Subject: [PATCH 10/19] feat: add return value for webf function --- bridge/core/frame/module_manager.cc | 16 ++++++++---- bridge/core/native/native_function.h | 6 ++--- .../rusty_webf_sys/src/executing_context.rs | 6 +++-- .../rusty_webf_sys/src/frame/async_storage.rs | 24 +++++++++-------- bridge/rusty_webf_sys/src/native_value.rs | 26 ++++++++++++++++--- bridge/rusty_webf_sys/src/webf_function.rs | 10 +++---- 6 files changed, 58 insertions(+), 30 deletions(-) diff --git a/bridge/core/frame/module_manager.cc b/bridge/core/frame/module_manager.cc index 10d9d6bdd5..f1051ffab7 100644 --- a/bridge/core/frame/module_manager.cc +++ b/bridge/core/frame/module_manager.cc @@ -50,7 +50,7 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, context->HandleException(&result); } NativeValue native_result = result.ToNative(ctx, exception_state); - return_value = static_cast(malloc(sizeof(NativeValue))); + return_value = static_cast(dart_malloc(sizeof(NativeValue))); memcpy(return_value, &native_result, sizeof(NativeValue)); } else { ScriptValue arguments[] = {ScriptValue::Empty(ctx), ScriptValue(ctx, *extra_data)}; @@ -59,7 +59,7 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, context->HandleException(&result); } NativeValue native_result = result.ToNative(ctx, exception_state); - return_value = static_cast(malloc(sizeof(NativeValue))); + return_value = static_cast(dart_malloc(sizeof(NativeValue))); memcpy(return_value, &native_result, sizeof(NativeValue)); } @@ -75,18 +75,24 @@ NativeValue* handleInvokeModuleTransientCallback(void* ptr, } else if (auto* callback = DynamicTo(callback_value.get())) { context->dartIsolateContext()->profiler()->StartTrackAsyncEvaluation(); context->dartIsolateContext()->profiler()->StartTrackSteps("handleInvokeModuleTransientCallback"); + + NativeValue* return_value = nullptr; if (errmsg != nullptr) { NativeValue error_object = Native_NewCString(errmsg); - callback->Invoke(context, 1, &error_object); + NativeValue native_result = callback->Invoke(context, 1, &error_object); + return_value = static_cast(dart_malloc(sizeof(NativeValue))); + memcpy(return_value, &native_result, sizeof(NativeValue)); } else { auto params = new NativeValue[2]; params[0] = Native_NewNull(); params[1] = *extra_data; - callback->Invoke(context, 2, params); + NativeValue native_result = callback->Invoke(context, 2, params); + return_value = static_cast(dart_malloc(sizeof(NativeValue))); + memcpy(return_value, &native_result, sizeof(NativeValue)); } context->dartIsolateContext()->profiler()->FinishTrackSteps(); context->dartIsolateContext()->profiler()->FinishTrackAsyncEvaluation(); - return nullptr; + return return_value; } } diff --git a/bridge/core/native/native_function.h b/bridge/core/native/native_function.h index a108d81332..e54099785c 100644 --- a/bridge/core/native/native_function.h +++ b/bridge/core/native/native_function.h @@ -15,7 +15,7 @@ namespace webf { class SharedExceptionState; typedef struct WebFNativeFunctionContext WebFNativeFunctionContext; -using WebFNativeFunctionCallback = void (*)(WebFNativeFunctionContext* callback_context, +using WebFNativeFunctionCallback = NativeValue (*)(WebFNativeFunctionContext* callback_context, int32_t argc, NativeValue* argv, SharedExceptionState* shared_exception_state); @@ -44,8 +44,8 @@ class WebFNativeFunction : public Function { bool IsWebFNativeFunction() const override { return true; } - void Invoke(ExecutingContext* context, int32_t argc, NativeValue* argv) { - callback_context_->callback(callback_context_, argc, argv, shared_exception_state_); + NativeValue Invoke(ExecutingContext* context, int32_t argc, NativeValue* argv) { + return callback_context_->callback(callback_context_, argc, argv, shared_exception_state_); } private: diff --git a/bridge/rusty_webf_sys/src/executing_context.rs b/bridge/rusty_webf_sys/src/executing_context.rs index c6191d68dc..4a43a8851d 100644 --- a/bridge/rusty_webf_sys/src/executing_context.rs +++ b/bridge/rusty_webf_sys/src/executing_context.rs @@ -175,9 +175,10 @@ impl ExecutingContext { let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { if argc != 0 { println!("Invalid argument count for timeout callback"); - return; + return NativeValue::new_null(); } callback(); + NativeValue::new_null() }); let callback_data = Box::new(WebFNativeFunctionContextData { @@ -214,9 +215,10 @@ impl ExecutingContext { let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { if argc != 0 { println!("Invalid argument count for interval callback"); - return; + return NativeValue::new_null(); } callback(); + NativeValue::new_null() }); let callback_data = Box::new(WebFNativeFunctionContextData { diff --git a/bridge/rusty_webf_sys/src/frame/async_storage.rs b/bridge/rusty_webf_sys/src/frame/async_storage.rs index a83d4c430b..aa6eb50446 100644 --- a/bridge/rusty_webf_sys/src/frame/async_storage.rs +++ b/bridge/rusty_webf_sys/src/frame/async_storage.rs @@ -27,22 +27,23 @@ impl AsyncStorage { let key_string = NativeValue::new_string(key); let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { if argc == 1 { - let error_string = unsafe { *argv }; + let error_string = unsafe { (*argv).clone() }; let error_string = error_string.to_string(); callback(Err(error_string)); - return; + return NativeValue::new_null(); } if argc == 2 { - let item_string = unsafe { *argv.wrapping_add(1) }; + let item_string = unsafe { (*argv.wrapping_add(1)).clone() }; if item_string.is_null() { callback(Ok(None)); - return; + return NativeValue::new_null(); } let item_string = item_string.to_string(); callback(Ok(Some(item_string))); - return; + return NativeValue::new_null(); } - println!("Invalid argument count for timeout callback"); + println!("Invalid argument count for async storage callback"); + NativeValue::new_null() }); self.context().webf_invoke_module_with_params_and_callback("AsyncStorage", "getItem", &key_string, general_callback, exception_state).unwrap(); } @@ -54,18 +55,19 @@ impl AsyncStorage { let params = NativeValue::new_list(params_vec); let general_callback: WebFNativeFunction = Box::new(move |argc, argv| { if argc == 1 { - let error_string = unsafe { *argv }; + let error_string = unsafe { (*argv).clone() }; let error_string = error_string.to_string(); callback(Err(error_string)); - return; + return NativeValue::new_null(); } if argc == 2 { - let result = unsafe { *argv.wrapping_add(1) }; + let result = unsafe { (*argv.wrapping_add(1)).clone() }; let result = result.to_string(); callback(Ok(Some(result))); - return; + return NativeValue::new_null(); } - println!("Invalid argument count for timeout callback"); + println!("Invalid argument count for async storage callback"); + NativeValue::new_null() }); self.context().webf_invoke_module_with_params_and_callback("AsyncStorage", "setItem", ¶ms, general_callback, exception_state).unwrap(); } diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index f8496ce9d2..04580db2af 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -27,7 +27,7 @@ pub enum NativeTag { } #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Copy, Clone)] pub union ValueField { pub int64: i64, pub float64: f64, @@ -35,7 +35,7 @@ pub union ValueField { } #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct NativeValue { pub u: ValueField, pub uint32: u32, @@ -179,7 +179,7 @@ impl NativeValue { for (i, val) in values.iter().enumerate() { unsafe { - array_ptr.add(i).write(*val); + array_ptr.add(i).write(val.clone()); } } @@ -203,3 +203,23 @@ impl NativeValue { values } } + +impl Drop for NativeValue { + fn drop(&mut self) { + if self.tag == NativeTag::TagString as i32 { + println!("Drop NativeValue string: {}", self.to_string()); + } else if self.tag == NativeTag::TagList as i32 { + println!("Drop NativeValue list"); + let ptr = unsafe { + self.u.ptr as *mut NativeValue + }; + for i in 0..self.uint32 { + let offset = i.try_into().unwrap(); + let val = unsafe { ptr.add(offset).read() }; + drop(val); + } + } else { + println!("Drop NativeValue: {:?}", self.tag); + } + } +} diff --git a/bridge/rusty_webf_sys/src/webf_function.rs b/bridge/rusty_webf_sys/src/webf_function.rs index 3c1f7c230f..e39af4ee0d 100644 --- a/bridge/rusty_webf_sys/src/webf_function.rs +++ b/bridge/rusty_webf_sys/src/webf_function.rs @@ -4,7 +4,7 @@ use std::ffi::*; use crate::*; -pub type WebFNativeFunction = Box; +pub type WebFNativeFunction = Box NativeValue>; pub struct WebFNativeFunctionContextData { pub func: WebFNativeFunction, @@ -21,7 +21,7 @@ pub struct WebFNativeFunctionContext { pub callback: extern "C" fn(callback_context: *const OpaquePtr, argc: c_int, argv: *const NativeValue, - exception_state: *const OpaquePtr) -> *const c_void, + exception_state: *const OpaquePtr) -> NativeValue, pub free_ptr: extern "C" fn(callback_context: *const OpaquePtr) -> *const c_void, pub ptr: *const WebFNativeFunctionContextData, } @@ -31,7 +31,7 @@ pub extern "C" fn invoke_webf_native_function( argc: c_int, argv: *const NativeValue, exception_state: *const OpaquePtr, -) -> *const c_void { +) -> NativeValue { let callback_context = unsafe { &(*(callback_context_ptr as *mut WebFNativeFunctionContext)) }; @@ -41,10 +41,8 @@ pub extern "C" fn invoke_webf_native_function( unsafe { let func = &(*callback_context_data).func; - func(argc, argv); + func(argc, argv) } - - std::ptr::null() } pub extern "C" fn release_webf_native_function(callback_context_ptr: *const OpaquePtr) -> *const c_void { From def7c1ff68546bbb1404b66aaa5ad6511284bc84 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:28:10 +0000 Subject: [PATCH 11/19] Commit from GitHub Actions (Run Code Linter) --- bridge/core/native/native_function.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridge/core/native/native_function.h b/bridge/core/native/native_function.h index e54099785c..15a50b79d1 100644 --- a/bridge/core/native/native_function.h +++ b/bridge/core/native/native_function.h @@ -16,9 +16,9 @@ class SharedExceptionState; typedef struct WebFNativeFunctionContext WebFNativeFunctionContext; using WebFNativeFunctionCallback = NativeValue (*)(WebFNativeFunctionContext* callback_context, - int32_t argc, - NativeValue* argv, - SharedExceptionState* shared_exception_state); + int32_t argc, + NativeValue* argv, + SharedExceptionState* shared_exception_state); using WebFNativeFunctionFreePtrFn = void (*)(WebFNativeFunctionContext* callback_context); struct WebFNativeFunctionContext : public RustReadable { From af797fda85c894df416144fdfa3625ccb28be054 Mon Sep 17 00:00:00 2001 From: Jiaxun Wei Date: Sat, 14 Dec 2024 19:43:41 +0800 Subject: [PATCH 12/19] fix: enable return value for module listener --- bridge/core/page.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bridge/core/page.cc b/bridge/core/page.cc index d84054aee9..5880f01bb3 100644 --- a/bridge/core/page.cc +++ b/bridge/core/page.cc @@ -98,7 +98,7 @@ NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, } ExceptionState exception_state; - auto* return_value = static_cast(malloc(sizeof(NativeValue))); + auto* return_value = static_cast(dart_malloc(sizeof(NativeValue))); NativeValue tmp = result.ToNative(ctx, exception_state); if (exception_state.HasException()) { context_->HandleException(exception_state); @@ -108,8 +108,7 @@ NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, memcpy(return_value, &tmp, sizeof(NativeValue)); return return_value; } else if (auto* callback = DynamicTo(callback_value.get())) { - NativeValue* params = new NativeValue[2]; - + auto* params = new NativeValue[2]; ExceptionState exception_state; ScriptValue eventValue = event != nullptr ? event->ToValue() : ScriptValue::Empty(ctx); params[0] = eventValue.ToNative(ctx, exception_state); @@ -120,8 +119,10 @@ NativeValue* WebFPage::invokeModuleEvent(SharedNativeString* native_module_name, return nullptr; } - callback->Invoke(context_, 2, params); - return nullptr; + NativeValue tmp = callback->Invoke(context_, 2, params); + auto* return_value = static_cast(dart_malloc(sizeof(NativeValue))); + memcpy(return_value, &tmp, sizeof(NativeValue)); + return return_value; } } From 3154021551d3d80b78be79f06bf1a36ef2918b08 Mon Sep 17 00:00:00 2001 From: Jiaxun Wei Date: Sat, 21 Dec 2024 15:49:05 +0800 Subject: [PATCH 13/19] feat: add needed is methods --- bridge/rusty_webf_sys/src/native_value.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index 04580db2af..1e206fab0c 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -102,6 +102,10 @@ impl NativeValue { value } + pub fn is_string(&self) -> bool { + self.tag == NativeTag::TagString as i32 + } + pub fn to_string(&self) -> String { let ptr = unsafe { self.u.ptr as *mut SharedNativeString @@ -131,6 +135,10 @@ impl NativeValue { value } + pub fn is_float64(&self) -> bool { + self.tag == NativeTag::TagFloat64 as i32 + } + pub fn to_float64(&self) -> f64 { unsafe { self.u.float64 @@ -145,6 +153,10 @@ impl NativeValue { value } + pub fn is_bool(&self) -> bool { + self.tag == NativeTag::TagBool as i32 + } + pub fn to_bool(&self) -> bool { unsafe { self.u.int64 != 0 @@ -159,6 +171,10 @@ impl NativeValue { value } + pub fn is_int64(&self) -> bool { + self.tag == NativeTag::TagInt as i32 + } + pub fn to_int64(&self) -> i64 { unsafe { self.u.int64 @@ -190,6 +206,10 @@ impl NativeValue { value } + pub fn is_list(&self) -> bool { + self.tag == NativeTag::TagList as i32 + } + pub fn to_list(&self) -> Vec { let mut values = Vec::new(); let ptr = unsafe { From cd2abedeaa98ff8db77c42c0ca80e8c4b17d70f7 Mon Sep 17 00:00:00 2001 From: LeuisKen Date: Sat, 21 Dec 2024 15:53:58 +0800 Subject: [PATCH 14/19] feat: crlf to lf --- .../dom/events/add_event_listener_options.rs | 26 +- .../src/dom/events/custom_event.rs | 240 +++--- bridge/rusty_webf_sys/src/dom/events/event.rs | 736 +++++++++--------- .../src/dom/events/event_init.rs | 26 +- .../src/dom/events/event_listener_options.rs | 22 +- .../rusty_webf_sys/src/dom/scroll_options.rs | 22 +- .../src/dom/scroll_to_options.rs | 26 +- .../src/events/animation_event.rs | 260 +++---- .../src/events/animation_event_init.rs | 32 +- .../rusty_webf_sys/src/events/close_event.rs | 258 +++--- .../src/events/close_event_init.rs | 32 +- .../rusty_webf_sys/src/events/focus_event.rs | 240 +++--- .../src/events/focus_event_init.rs | 28 +- .../src/events/gesture_event.rs | 370 ++++----- .../src/events/gesture_event_init.rs | 42 +- .../src/events/hashchange_event.rs | 238 +++--- .../src/events/hashchange_event_init.rs | 30 +- .../rusty_webf_sys/src/events/input_event.rs | 266 +++---- .../src/events/input_event_init.rs | 30 +- .../src/events/intersection_change_event.rs | 212 ++--- .../events/intersection_change_event_init.rs | 28 +- .../src/events/keyboard_event_init.rs | 48 +- .../rusty_webf_sys/src/events/mouse_event.rs | 306 ++++---- .../src/events/mouse_event_init.rs | 26 +- .../src/events/pointer_event.rs | 474 +++++------ .../src/events/pointer_event_init.rs | 40 +- .../src/events/transition_event.rs | 260 +++---- .../src/events/transition_event_init.rs | 32 +- bridge/rusty_webf_sys/src/events/ui_event.rs | 256 +++--- .../src/events/ui_event_init.rs | 32 +- bridge/rusty_webf_sys/src/input/touch_init.rs | 44 +- 31 files changed, 2341 insertions(+), 2341 deletions(-) diff --git a/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs b/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs index ec70ec4e59..7196c60be2 100644 --- a/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs +++ b/bridge/rusty_webf_sys/src/dom/events/add_event_listener_options.rs @@ -1,13 +1,13 @@ -// 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 AddEventListenerOptions { - pub capture: i32, - pub passive: i32, - pub once: i32, -} +// 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 AddEventListenerOptions { + pub capture: i32, + pub passive: i32, + pub once: i32, +} diff --git a/bridge/rusty_webf_sys/src/dom/events/custom_event.rs b/bridge/rusty_webf_sys/src/dom/events/custom_event.rs index 3262ecc3ee..2864232c1c 100644 --- a/bridge/rusty_webf_sys/src/dom/events/custom_event.rs +++ b/bridge/rusty_webf_sys/src/dom/events/custom_event.rs @@ -1,120 +1,120 @@ -// 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 - } -} +// 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 04065802d6..fa9d81dd98 100644 --- a/bridge/rusty_webf_sys/src/dom/events/event.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event.rs @@ -1,369 +1,369 @@ -// 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)] -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, -} -#[repr(C)] -pub struct EventRustMethods { - pub version: c_double, - pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: i32, exception_state: *const OpaquePtr) -> bool, - pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub current_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub src_element: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub time_stamp: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub type_: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, exception_state: *const OpaquePtr) -> c_void, - pub prevent_default: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub stop_immediate_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub stop_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, - pub release: extern "C" fn(ptr: *const OpaquePtr) -> c_void, - pub dynamic_to: extern "C" fn(ptr: *const OpaquePtr, type_: EventType) -> RustValue, -} -pub struct Event { - pub ptr: *const OpaquePtr, - context: *const ExecutingContext, - method_pointer: *const EventRustMethods, - status: *const RustValueStatus -} -impl Event { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const EventRustMethods, status: *const RustValueStatus) -> Event { - Event { - ptr, - context, - method_pointer, - status - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ptr - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - assert!(!self.context.is_null(), "Context PTR must not be null"); - unsafe { &*self.context } - } - pub fn bubbles(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).bubbles)(self.ptr()) - }; - value != 0 - } - pub fn cancel_bubble(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).cancel_bubble)(self.ptr()) - }; - value != 0 - } - pub fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).set_cancel_bubble)(self.ptr(), i32::from(value), exception_state.ptr) - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn cancelable(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).cancelable)(self.ptr()) - }; - value != 0 - } - pub fn current_target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).current_target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn default_prevented(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).default_prevented)(self.ptr()) - }; - value != 0 - } - pub fn src_element(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).src_element)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn is_trusted(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).is_trusted)(self.ptr()) - }; - value != 0 - } - pub fn time_stamp(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).time_stamp)(self.ptr()) - }; - value - } - pub fn type_(&self) -> String { - let value = unsafe { - ((*self.method_pointer).type_)(self.ptr()) - }; +// 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)] +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, +} +#[repr(C)] +pub struct EventRustMethods { + pub version: c_double, + pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: i32, exception_state: *const OpaquePtr) -> bool, + pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub current_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub src_element: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub time_stamp: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub type_: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, exception_state: *const OpaquePtr) -> c_void, + pub prevent_default: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub stop_immediate_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub stop_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub release: extern "C" fn(ptr: *const OpaquePtr) -> c_void, + pub dynamic_to: extern "C" fn(ptr: *const OpaquePtr, type_: EventType) -> RustValue, +} +pub struct Event { + pub ptr: *const OpaquePtr, + context: *const ExecutingContext, + method_pointer: *const EventRustMethods, + status: *const RustValueStatus +} +impl Event { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const EventRustMethods, status: *const RustValueStatus) -> Event { + Event { + ptr, + context, + method_pointer, + status + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ptr + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + assert!(!self.context.is_null(), "Context PTR must not be null"); + unsafe { &*self.context } + } + pub fn bubbles(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).bubbles)(self.ptr()) + }; + value != 0 + } + pub fn cancel_bubble(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).cancel_bubble)(self.ptr()) + }; + value != 0 + } + pub fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).set_cancel_bubble)(self.ptr(), i32::from(value), exception_state.ptr) + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn cancelable(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).cancelable)(self.ptr()) + }; + value != 0 + } + pub fn current_target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).current_target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn default_prevented(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).default_prevented)(self.ptr()) + }; + value != 0 + } + pub fn src_element(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).src_element)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn is_trusted(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).is_trusted)(self.ptr()) + }; + value != 0 + } + pub fn time_stamp(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).time_stamp)(self.ptr()) + }; + value + } + pub fn type_(&self) -> String { + let value = unsafe { + ((*self.method_pointer).type_)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(bubbles), i32::from(cancelable), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).prevent_default)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).stop_immediate_propagation)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - Ok(()) - } - pub fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - unsafe { - ((*self.method_pointer).stop_propagation)(self.ptr(), exception_state.ptr); - }; - if exception_state.has_exception() { - return Err(exception_state.stringify(self.context())); - } - 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)); - ((*self.method_pointer).dynamic_to)(self.ptr, EventType::AnimationEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the AnimationEvent type."); - } - Ok(AnimationEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const AnimationEventRustMethods, raw_ptr.status)) - } - pub fn as_close_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::CloseEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the CloseEvent type."); - } - Ok(CloseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const CloseEventRustMethods, raw_ptr.status)) - } - pub fn as_gesture_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::GestureEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the GestureEvent type."); - } - Ok(GestureEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const GestureEventRustMethods, raw_ptr.status)) - } - pub fn as_hashchange_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::HashchangeEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the HashchangeEvent type."); - } - Ok(HashchangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const HashchangeEventRustMethods, raw_ptr.status)) - } - pub fn as_intersection_change_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::IntersectionChangeEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the IntersectionChangeEvent type."); - } - Ok(IntersectionChangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const IntersectionChangeEventRustMethods, raw_ptr.status)) - } - pub fn as_transition_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::TransitionEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the TransitionEvent type."); - } - Ok(TransitionEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const TransitionEventRustMethods, raw_ptr.status)) - } - pub fn as_ui_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::UIEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the UIEvent type."); - } - Ok(UIEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const UIEventRustMethods, raw_ptr.status)) - } - pub fn as_focus_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::FocusEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the FocusEvent type."); - } - Ok(FocusEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const FocusEventRustMethods, raw_ptr.status)) - } - pub fn as_input_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::InputEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the InputEvent type."); - } - Ok(InputEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const InputEventRustMethods, raw_ptr.status)) - } - pub fn as_mouse_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::MouseEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the MouseEvent type."); - } - Ok(MouseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const MouseEventRustMethods, raw_ptr.status)) - } - pub fn as_pointer_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::PointerEvent) - }; - if (raw_ptr.value == std::ptr::null()) { - return Err("The type value of Event does not belong to the PointerEvent type."); - } - Ok(PointerEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const PointerEventRustMethods, raw_ptr.status)) - } -} -impl Drop for Event { - fn drop(&mut self) { - unsafe { - ((*self.method_pointer).release)(self.ptr()); - } - } -} -pub trait EventMethods { - fn bubbles(&self) -> bool; - fn cancel_bubble(&self) -> bool; - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String>; - fn cancelable(&self) -> bool; - fn current_target(&self) -> EventTarget; - fn default_prevented(&self) -> bool; - fn src_element(&self) -> EventTarget; - fn target(&self) -> EventTarget; - fn is_trusted(&self) -> bool; - fn time_stamp(&self) -> f64; - fn type_(&self) -> String; - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String>; - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; - fn as_event(&self) -> &Event; -} -impl EventMethods for Event { - fn bubbles(&self) -> bool { - self.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.cancelable() - } - fn current_target(&self) -> EventTarget { - self.current_target() - } - fn default_prevented(&self) -> bool { - self.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.src_element() - } - fn target(&self) -> EventTarget { - self.target() - } - fn is_trusted(&self) -> bool { - self.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.time_stamp() - } - fn type_(&self) -> String { - self.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - self - } -} + value.to_str().unwrap().to_string() + } + pub fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(bubbles), i32::from(cancelable), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).prevent_default)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).stop_immediate_propagation)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + Ok(()) + } + pub fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + unsafe { + ((*self.method_pointer).stop_propagation)(self.ptr(), exception_state.ptr); + }; + if exception_state.has_exception() { + return Err(exception_state.stringify(self.context())); + } + 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)); + ((*self.method_pointer).dynamic_to)(self.ptr, EventType::AnimationEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the AnimationEvent type."); + } + Ok(AnimationEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const AnimationEventRustMethods, raw_ptr.status)) + } + pub fn as_close_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::CloseEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the CloseEvent type."); + } + Ok(CloseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const CloseEventRustMethods, raw_ptr.status)) + } + pub fn as_gesture_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::GestureEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the GestureEvent type."); + } + Ok(GestureEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const GestureEventRustMethods, raw_ptr.status)) + } + pub fn as_hashchange_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::HashchangeEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the HashchangeEvent type."); + } + Ok(HashchangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const HashchangeEventRustMethods, raw_ptr.status)) + } + pub fn as_intersection_change_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::IntersectionChangeEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the IntersectionChangeEvent type."); + } + Ok(IntersectionChangeEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const IntersectionChangeEventRustMethods, raw_ptr.status)) + } + pub fn as_transition_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::TransitionEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the TransitionEvent type."); + } + Ok(TransitionEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const TransitionEventRustMethods, raw_ptr.status)) + } + pub fn as_ui_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::UIEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the UIEvent type."); + } + Ok(UIEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const UIEventRustMethods, raw_ptr.status)) + } + pub fn as_focus_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::FocusEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the FocusEvent type."); + } + Ok(FocusEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const FocusEventRustMethods, raw_ptr.status)) + } + pub fn as_input_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::InputEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the InputEvent type."); + } + Ok(InputEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const InputEventRustMethods, raw_ptr.status)) + } + pub fn as_mouse_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::MouseEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the MouseEvent type."); + } + Ok(MouseEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const MouseEventRustMethods, raw_ptr.status)) + } + pub fn as_pointer_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::PointerEvent) + }; + if (raw_ptr.value == std::ptr::null()) { + return Err("The type value of Event does not belong to the PointerEvent type."); + } + Ok(PointerEvent::initialize(raw_ptr.value, self.context, raw_ptr.method_pointer as *const PointerEventRustMethods, raw_ptr.status)) + } +} +impl Drop for Event { + fn drop(&mut self) { + unsafe { + ((*self.method_pointer).release)(self.ptr()); + } + } +} +pub trait EventMethods { + fn bubbles(&self) -> bool; + fn cancel_bubble(&self) -> bool; + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String>; + fn cancelable(&self) -> bool; + fn current_target(&self) -> EventTarget; + fn default_prevented(&self) -> bool; + fn src_element(&self) -> EventTarget; + fn target(&self) -> EventTarget; + fn is_trusted(&self) -> bool; + fn time_stamp(&self) -> f64; + fn type_(&self) -> String; + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String>; + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String>; + fn as_event(&self) -> &Event; +} +impl EventMethods for Event { + fn bubbles(&self) -> bool { + self.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.cancelable() + } + fn current_target(&self) -> EventTarget { + self.current_target() + } + fn default_prevented(&self) -> bool { + self.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.src_element() + } + fn target(&self) -> EventTarget { + self.target() + } + fn is_trusted(&self) -> bool { + self.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.time_stamp() + } + fn type_(&self) -> String { + self.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + self + } +} diff --git a/bridge/rusty_webf_sys/src/dom/events/event_init.rs b/bridge/rusty_webf_sys/src/dom/events/event_init.rs index 9eadc8ea99..07ce0f7bc5 100644 --- a/bridge/rusty_webf_sys/src/dom/events/event_init.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event_init.rs @@ -1,13 +1,13 @@ -// 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 EventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, -} +// 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 EventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, +} diff --git a/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs b/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs index cd4253e0c5..f5fc1a4152 100644 --- a/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs +++ b/bridge/rusty_webf_sys/src/dom/events/event_listener_options.rs @@ -1,11 +1,11 @@ -// 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 EventListenerOptions { - pub capture: i32, -} +// 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 EventListenerOptions { + pub capture: i32, +} diff --git a/bridge/rusty_webf_sys/src/dom/scroll_options.rs b/bridge/rusty_webf_sys/src/dom/scroll_options.rs index 644ebd1fb2..a28d104213 100644 --- a/bridge/rusty_webf_sys/src/dom/scroll_options.rs +++ b/bridge/rusty_webf_sys/src/dom/scroll_options.rs @@ -1,11 +1,11 @@ -// 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 ScrollOptions { - pub behavior: *const c_char, -} +// 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 ScrollOptions { + pub behavior: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs b/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs index cbf4dcbb5f..9fee3ebd57 100644 --- a/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs +++ b/bridge/rusty_webf_sys/src/dom/scroll_to_options.rs @@ -1,13 +1,13 @@ -// 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 ScrollToOptions { - pub behavior: *const c_char, - pub top: c_double, - pub left: c_double, -} +// 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 ScrollToOptions { + pub behavior: *const c_char, + pub top: c_double, + pub left: c_double, +} diff --git a/bridge/rusty_webf_sys/src/events/animation_event.rs b/bridge/rusty_webf_sys/src/events/animation_event.rs index 6c641cfca3..5e98383f05 100644 --- a/bridge/rusty_webf_sys/src/events/animation_event.rs +++ b/bridge/rusty_webf_sys/src/events/animation_event.rs @@ -1,132 +1,132 @@ -// 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 AnimationEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct AnimationEvent { - pub event: Event, - method_pointer: *const AnimationEventRustMethods, -} -impl AnimationEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const AnimationEventRustMethods, status: *const RustValueStatus) -> AnimationEvent { - unsafe { - AnimationEvent { - 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 animation_name(&self) -> String { - let value = unsafe { - ((*self.method_pointer).animation_name)(self.ptr()) - }; +// 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 AnimationEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_animation_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct AnimationEvent { + pub event: Event, + method_pointer: *const AnimationEventRustMethods, +} +impl AnimationEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const AnimationEventRustMethods, status: *const RustValueStatus) -> AnimationEvent { + unsafe { + AnimationEvent { + 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 animation_name(&self) -> String { + let value = unsafe { + ((*self.method_pointer).animation_name)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn elapsed_time(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).elapsed_time)(self.ptr()) - }; - value - } - pub fn pseudo_element(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pseudo_element)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn elapsed_time(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).elapsed_time)(self.ptr()) + }; + value + } + pub fn pseudo_element(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pseudo_element)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait AnimationEventMethods: EventMethods { - fn animation_name(&self) -> String; - fn elapsed_time(&self) -> f64; - fn pseudo_element(&self) -> String; - fn as_animation_event(&self) -> &AnimationEvent; -} -impl AnimationEventMethods for AnimationEvent { - fn animation_name(&self) -> String { - self.animation_name() - } - fn elapsed_time(&self) -> f64 { - self.elapsed_time() - } - fn pseudo_element(&self) -> String { - self.pseudo_element() - } - fn as_animation_event(&self) -> &AnimationEvent { - self - } -} -impl EventMethods for AnimationEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait AnimationEventMethods: EventMethods { + fn animation_name(&self) -> String; + fn elapsed_time(&self) -> f64; + fn pseudo_element(&self) -> String; + fn as_animation_event(&self) -> &AnimationEvent; +} +impl AnimationEventMethods for AnimationEvent { + fn animation_name(&self) -> String { + self.animation_name() + } + fn elapsed_time(&self) -> f64 { + self.elapsed_time() + } + fn pseudo_element(&self) -> String { + self.pseudo_element() + } + fn as_animation_event(&self) -> &AnimationEvent { + self + } +} +impl EventMethods for AnimationEvent { + 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/events/animation_event_init.rs b/bridge/rusty_webf_sys/src/events/animation_event_init.rs index 6b5ed09f8a..41fc67c884 100644 --- a/bridge/rusty_webf_sys/src/events/animation_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/animation_event_init.rs @@ -1,16 +1,16 @@ -// 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 AnimationEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub animation_name: *const c_char, - pub elapsed_time: c_double, - pub pseudo_element: *const c_char, -} +// 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 AnimationEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub animation_name: *const c_char, + pub elapsed_time: c_double, + pub pseudo_element: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/events/close_event.rs b/bridge/rusty_webf_sys/src/events/close_event.rs index 89572a9f80..47eb399483 100644 --- a/bridge/rusty_webf_sys/src/events/close_event.rs +++ b/bridge/rusty_webf_sys/src/events/close_event.rs @@ -1,130 +1,130 @@ -// 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 CloseEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub code: extern "C" fn(ptr: *const OpaquePtr) -> i64, - pub reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub was_clean: extern "C" fn(ptr: *const OpaquePtr) -> i32, -} -pub struct CloseEvent { - pub event: Event, - method_pointer: *const CloseEventRustMethods, -} -impl CloseEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const CloseEventRustMethods, status: *const RustValueStatus) -> CloseEvent { - unsafe { - CloseEvent { - 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 code(&self) -> i64 { - let value = unsafe { - ((*self.method_pointer).code)(self.ptr()) - }; - value - } - pub fn reason(&self) -> String { - let value = unsafe { - ((*self.method_pointer).reason)(self.ptr()) - }; +// 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 CloseEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub code: extern "C" fn(ptr: *const OpaquePtr) -> i64, + pub reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_reason: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub was_clean: extern "C" fn(ptr: *const OpaquePtr) -> i32, +} +pub struct CloseEvent { + pub event: Event, + method_pointer: *const CloseEventRustMethods, +} +impl CloseEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const CloseEventRustMethods, status: *const RustValueStatus) -> CloseEvent { + unsafe { + CloseEvent { + 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 code(&self) -> i64 { + let value = unsafe { + ((*self.method_pointer).code)(self.ptr()) + }; + value + } + pub fn reason(&self) -> String { + let value = unsafe { + ((*self.method_pointer).reason)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn was_clean(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).was_clean)(self.ptr()) - }; - value != 0 - } -} -pub trait CloseEventMethods: EventMethods { - fn code(&self) -> i64; - fn reason(&self) -> String; - fn was_clean(&self) -> bool; - fn as_close_event(&self) -> &CloseEvent; -} -impl CloseEventMethods for CloseEvent { - fn code(&self) -> i64 { - self.code() - } - fn reason(&self) -> String { - self.reason() - } - fn was_clean(&self) -> bool { - self.was_clean() - } - fn as_close_event(&self) -> &CloseEvent { - self - } -} -impl EventMethods for CloseEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } + pub fn was_clean(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).was_clean)(self.ptr()) + }; + value != 0 + } +} +pub trait CloseEventMethods: EventMethods { + fn code(&self) -> i64; + fn reason(&self) -> String; + fn was_clean(&self) -> bool; + fn as_close_event(&self) -> &CloseEvent; +} +impl CloseEventMethods for CloseEvent { + fn code(&self) -> i64 { + self.code() + } + fn reason(&self) -> String { + self.reason() + } + fn was_clean(&self) -> bool { + self.was_clean() + } + fn as_close_event(&self) -> &CloseEvent { + self + } +} +impl EventMethods for CloseEvent { + 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/events/close_event_init.rs b/bridge/rusty_webf_sys/src/events/close_event_init.rs index d51b063c39..998cbec348 100644 --- a/bridge/rusty_webf_sys/src/events/close_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/close_event_init.rs @@ -1,16 +1,16 @@ -// 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 CloseEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub code: i64, - pub reason: *const c_char, - pub was_clean: i32, -} +// 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 CloseEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub code: i64, + pub reason: *const c_char, + pub was_clean: i32, +} diff --git a/bridge/rusty_webf_sys/src/events/focus_event.rs b/bridge/rusty_webf_sys/src/events/focus_event.rs index b1a9af3b4a..e2b78491e5 100644 --- a/bridge/rusty_webf_sys/src/events/focus_event.rs +++ b/bridge/rusty_webf_sys/src/events/focus_event.rs @@ -1,120 +1,120 @@ -// 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 FocusEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub related_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, -} -pub struct FocusEvent { - pub ui_event: UIEvent, - method_pointer: *const FocusEventRustMethods, -} -impl FocusEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const FocusEventRustMethods, status: *const RustValueStatus) -> FocusEvent { - unsafe { - FocusEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn related_target(&self) -> EventTarget { - let value = unsafe { - ((*self.method_pointer).related_target)(self.ptr()) - }; - EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) - } -} -pub trait FocusEventMethods: UIEventMethods { - fn related_target(&self) -> EventTarget; - fn as_focus_event(&self) -> &FocusEvent; -} -impl FocusEventMethods for FocusEvent { - fn related_target(&self) -> EventTarget { - self.related_target() - } - fn as_focus_event(&self) -> &FocusEvent { - self - } -} -impl UIEventMethods for FocusEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for FocusEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} +// 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 FocusEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub related_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, +} +pub struct FocusEvent { + pub ui_event: UIEvent, + method_pointer: *const FocusEventRustMethods, +} +impl FocusEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const FocusEventRustMethods, status: *const RustValueStatus) -> FocusEvent { + unsafe { + FocusEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn related_target(&self) -> EventTarget { + let value = unsafe { + ((*self.method_pointer).related_target)(self.ptr()) + }; + EventTarget::initialize(value.value, self.context(), value.method_pointer, value.status) + } +} +pub trait FocusEventMethods: UIEventMethods { + fn related_target(&self) -> EventTarget; + fn as_focus_event(&self) -> &FocusEvent; +} +impl FocusEventMethods for FocusEvent { + fn related_target(&self) -> EventTarget { + self.related_target() + } + fn as_focus_event(&self) -> &FocusEvent { + self + } +} +impl UIEventMethods for FocusEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for FocusEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/events/focus_event_init.rs b/bridge/rusty_webf_sys/src/events/focus_event_init.rs index 07a00f24b4..7210d9029d 100644 --- a/bridge/rusty_webf_sys/src/events/focus_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/focus_event_init.rs @@ -1,14 +1,14 @@ -// 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 FocusEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub related_target: RustValue, -} +// 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 FocusEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub related_target: RustValue, +} diff --git a/bridge/rusty_webf_sys/src/events/gesture_event.rs b/bridge/rusty_webf_sys/src/events/gesture_event.rs index e6a166c27a..9287dc62ff 100644 --- a/bridge/rusty_webf_sys/src/events/gesture_event.rs +++ b/bridge/rusty_webf_sys/src/events/gesture_event.rs @@ -1,187 +1,187 @@ -// 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 GestureEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub delta_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub delta_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub velocity_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub velocity_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub scale: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub rotation: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct GestureEvent { - pub event: Event, - method_pointer: *const GestureEventRustMethods, -} -impl GestureEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const GestureEventRustMethods, status: *const RustValueStatus) -> GestureEvent { - unsafe { - GestureEvent { - 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 state(&self) -> String { - let value = unsafe { - ((*self.method_pointer).state)(self.ptr()) - }; +// 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 GestureEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_state: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_direction: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub delta_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub delta_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub velocity_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub velocity_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub scale: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub rotation: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct GestureEvent { + pub event: Event, + method_pointer: *const GestureEventRustMethods, +} +impl GestureEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const GestureEventRustMethods, status: *const RustValueStatus) -> GestureEvent { + unsafe { + GestureEvent { + 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 state(&self) -> String { + let value = unsafe { + ((*self.method_pointer).state)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn direction(&self) -> String { - let value = unsafe { - ((*self.method_pointer).direction)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn direction(&self) -> String { + let value = unsafe { + ((*self.method_pointer).direction)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn delta_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).delta_x)(self.ptr()) - }; - value - } - pub fn delta_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).delta_y)(self.ptr()) - }; - value - } - pub fn velocity_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).velocity_x)(self.ptr()) - }; - value - } - pub fn velocity_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).velocity_y)(self.ptr()) - }; - value - } - pub fn scale(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).scale)(self.ptr()) - }; - value - } - pub fn rotation(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).rotation)(self.ptr()) - }; - value - } -} -pub trait GestureEventMethods: EventMethods { - fn state(&self) -> String; - fn direction(&self) -> String; - fn delta_x(&self) -> f64; - fn delta_y(&self) -> f64; - fn velocity_x(&self) -> f64; - fn velocity_y(&self) -> f64; - fn scale(&self) -> f64; - fn rotation(&self) -> f64; - fn as_gesture_event(&self) -> &GestureEvent; -} -impl GestureEventMethods for GestureEvent { - fn state(&self) -> String { - self.state() - } - fn direction(&self) -> String { - self.direction() - } - fn delta_x(&self) -> f64 { - self.delta_x() - } - fn delta_y(&self) -> f64 { - self.delta_y() - } - fn velocity_x(&self) -> f64 { - self.velocity_x() - } - fn velocity_y(&self) -> f64 { - self.velocity_y() - } - fn scale(&self) -> f64 { - self.scale() - } - fn rotation(&self) -> f64 { - self.rotation() - } - fn as_gesture_event(&self) -> &GestureEvent { - self - } -} -impl EventMethods for GestureEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } + pub fn delta_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).delta_x)(self.ptr()) + }; + value + } + pub fn delta_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).delta_y)(self.ptr()) + }; + value + } + pub fn velocity_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).velocity_x)(self.ptr()) + }; + value + } + pub fn velocity_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).velocity_y)(self.ptr()) + }; + value + } + pub fn scale(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).scale)(self.ptr()) + }; + value + } + pub fn rotation(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).rotation)(self.ptr()) + }; + value + } +} +pub trait GestureEventMethods: EventMethods { + fn state(&self) -> String; + fn direction(&self) -> String; + fn delta_x(&self) -> f64; + fn delta_y(&self) -> f64; + fn velocity_x(&self) -> f64; + fn velocity_y(&self) -> f64; + fn scale(&self) -> f64; + fn rotation(&self) -> f64; + fn as_gesture_event(&self) -> &GestureEvent; +} +impl GestureEventMethods for GestureEvent { + fn state(&self) -> String { + self.state() + } + fn direction(&self) -> String { + self.direction() + } + fn delta_x(&self) -> f64 { + self.delta_x() + } + fn delta_y(&self) -> f64 { + self.delta_y() + } + fn velocity_x(&self) -> f64 { + self.velocity_x() + } + fn velocity_y(&self) -> f64 { + self.velocity_y() + } + fn scale(&self) -> f64 { + self.scale() + } + fn rotation(&self) -> f64 { + self.rotation() + } + fn as_gesture_event(&self) -> &GestureEvent { + self + } +} +impl EventMethods for GestureEvent { + 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/events/gesture_event_init.rs b/bridge/rusty_webf_sys/src/events/gesture_event_init.rs index 09e02b851a..29d5519ae1 100644 --- a/bridge/rusty_webf_sys/src/events/gesture_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/gesture_event_init.rs @@ -1,21 +1,21 @@ -// 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 GestureEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub state: *const c_char, - pub direction: *const c_char, - pub delta_x: c_double, - pub delta_y: c_double, - pub velocity_x: c_double, - pub velocity_y: c_double, - pub scale: c_double, - pub rotation: c_double, -} +// 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 GestureEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub state: *const c_char, + pub direction: *const c_char, + pub delta_x: c_double, + pub delta_y: c_double, + pub velocity_x: c_double, + pub velocity_y: c_double, + pub scale: c_double, + pub rotation: c_double, +} diff --git a/bridge/rusty_webf_sys/src/events/hashchange_event.rs b/bridge/rusty_webf_sys/src/events/hashchange_event.rs index e57853e8b2..51d58f9bb9 100644 --- a/bridge/rusty_webf_sys/src/events/hashchange_event.rs +++ b/bridge/rusty_webf_sys/src/events/hashchange_event.rs @@ -1,121 +1,121 @@ -// 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 HashchangeEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct HashchangeEvent { - pub event: Event, - method_pointer: *const HashchangeEventRustMethods, -} -impl HashchangeEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const HashchangeEventRustMethods, status: *const RustValueStatus) -> HashchangeEvent { - unsafe { - HashchangeEvent { - 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 new_url(&self) -> String { - let value = unsafe { - ((*self.method_pointer).new_url)(self.ptr()) - }; +// 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 HashchangeEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_new_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_old_url: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct HashchangeEvent { + pub event: Event, + method_pointer: *const HashchangeEventRustMethods, +} +impl HashchangeEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const HashchangeEventRustMethods, status: *const RustValueStatus) -> HashchangeEvent { + unsafe { + HashchangeEvent { + 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 new_url(&self) -> String { + let value = unsafe { + ((*self.method_pointer).new_url)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn old_url(&self) -> String { - let value = unsafe { - ((*self.method_pointer).old_url)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn old_url(&self) -> String { + let value = unsafe { + ((*self.method_pointer).old_url)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait HashchangeEventMethods: EventMethods { - fn new_url(&self) -> String; - fn old_url(&self) -> String; - fn as_hashchange_event(&self) -> &HashchangeEvent; -} -impl HashchangeEventMethods for HashchangeEvent { - fn new_url(&self) -> String { - self.new_url() - } - fn old_url(&self) -> String { - self.old_url() - } - fn as_hashchange_event(&self) -> &HashchangeEvent { - self - } -} -impl EventMethods for HashchangeEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait HashchangeEventMethods: EventMethods { + fn new_url(&self) -> String; + fn old_url(&self) -> String; + fn as_hashchange_event(&self) -> &HashchangeEvent; +} +impl HashchangeEventMethods for HashchangeEvent { + fn new_url(&self) -> String { + self.new_url() + } + fn old_url(&self) -> String { + self.old_url() + } + fn as_hashchange_event(&self) -> &HashchangeEvent { + self + } +} +impl EventMethods for HashchangeEvent { + 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/events/hashchange_event_init.rs b/bridge/rusty_webf_sys/src/events/hashchange_event_init.rs index 5f89ecdccb..79de869114 100644 --- a/bridge/rusty_webf_sys/src/events/hashchange_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/hashchange_event_init.rs @@ -1,15 +1,15 @@ -// 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 HashchangeEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub old_url: *const c_char, - pub new_url: *const c_char, -} +// 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 HashchangeEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub old_url: *const c_char, + pub new_url: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/events/input_event.rs b/bridge/rusty_webf_sys/src/events/input_event.rs index 5ed168feb7..17630178e9 100644 --- a/bridge/rusty_webf_sys/src/events/input_event.rs +++ b/bridge/rusty_webf_sys/src/events/input_event.rs @@ -1,135 +1,135 @@ -// 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 InputEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct InputEvent { - pub ui_event: UIEvent, - method_pointer: *const InputEventRustMethods, -} -impl InputEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const InputEventRustMethods, status: *const RustValueStatus) -> InputEvent { - unsafe { - InputEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn input_type(&self) -> String { - let value = unsafe { - ((*self.method_pointer).input_type)(self.ptr()) - }; +// 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 InputEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_input_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_data: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct InputEvent { + pub ui_event: UIEvent, + method_pointer: *const InputEventRustMethods, +} +impl InputEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const InputEventRustMethods, status: *const RustValueStatus) -> InputEvent { + unsafe { + InputEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn input_type(&self) -> String { + let value = unsafe { + ((*self.method_pointer).input_type)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn data(&self) -> String { - let value = unsafe { - ((*self.method_pointer).data)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn data(&self) -> String { + let value = unsafe { + ((*self.method_pointer).data)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait InputEventMethods: UIEventMethods { - fn input_type(&self) -> String; - fn data(&self) -> String; - fn as_input_event(&self) -> &InputEvent; -} -impl InputEventMethods for InputEvent { - fn input_type(&self) -> String { - self.input_type() - } - fn data(&self) -> String { - self.data() - } - fn as_input_event(&self) -> &InputEvent { - self - } -} -impl UIEventMethods for InputEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for InputEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} + value.to_str().unwrap().to_string() + } +} +pub trait InputEventMethods: UIEventMethods { + fn input_type(&self) -> String; + fn data(&self) -> String; + fn as_input_event(&self) -> &InputEvent; +} +impl InputEventMethods for InputEvent { + fn input_type(&self) -> String { + self.input_type() + } + fn data(&self) -> String { + self.data() + } + fn as_input_event(&self) -> &InputEvent { + self + } +} +impl UIEventMethods for InputEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for InputEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/events/input_event_init.rs b/bridge/rusty_webf_sys/src/events/input_event_init.rs index 3e094c36c3..9c85bc478a 100644 --- a/bridge/rusty_webf_sys/src/events/input_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/input_event_init.rs @@ -1,15 +1,15 @@ -// 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 InputEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub input_type: *const c_char, - pub data: *const c_char, -} +// 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 InputEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub input_type: *const c_char, + pub data: *const c_char, +} 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 bb5cd2e061..149fbf398e 100644 --- a/bridge/rusty_webf_sys/src/events/intersection_change_event.rs +++ b/bridge/rusty_webf_sys/src/events/intersection_change_event.rs @@ -1,106 +1,106 @@ -// 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 IntersectionChangeEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub intersection_ratio: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct IntersectionChangeEvent { - pub event: Event, - method_pointer: *const IntersectionChangeEventRustMethods, -} -impl IntersectionChangeEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const IntersectionChangeEventRustMethods, status: *const RustValueStatus) -> IntersectionChangeEvent { - unsafe { - IntersectionChangeEvent { - 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 intersection_ratio(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).intersection_ratio)(self.ptr()) - }; - value - } -} -pub trait IntersectionChangeEventMethods: EventMethods { - fn intersection_ratio(&self) -> f64; - fn as_intersection_change_event(&self) -> &IntersectionChangeEvent; -} -impl IntersectionChangeEventMethods for IntersectionChangeEvent { - fn intersection_ratio(&self) -> f64 { - self.intersection_ratio() - } - fn as_intersection_change_event(&self) -> &IntersectionChangeEvent { - self - } -} -impl EventMethods for IntersectionChangeEvent { - 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 - } -} +// 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 IntersectionChangeEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub intersection_ratio: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct IntersectionChangeEvent { + pub event: Event, + method_pointer: *const IntersectionChangeEventRustMethods, +} +impl IntersectionChangeEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const IntersectionChangeEventRustMethods, status: *const RustValueStatus) -> IntersectionChangeEvent { + unsafe { + IntersectionChangeEvent { + 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 intersection_ratio(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).intersection_ratio)(self.ptr()) + }; + value + } +} +pub trait IntersectionChangeEventMethods: EventMethods { + fn intersection_ratio(&self) -> f64; + fn as_intersection_change_event(&self) -> &IntersectionChangeEvent; +} +impl IntersectionChangeEventMethods for IntersectionChangeEvent { + fn intersection_ratio(&self) -> f64 { + self.intersection_ratio() + } + fn as_intersection_change_event(&self) -> &IntersectionChangeEvent { + self + } +} +impl EventMethods for IntersectionChangeEvent { + 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/events/intersection_change_event_init.rs b/bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs index d7a78f7870..f426f2e45e 100644 --- a/bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/intersection_change_event_init.rs @@ -1,14 +1,14 @@ -// 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 IntersectionChangeEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub intersection_ratio: c_double, -} +// 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 IntersectionChangeEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub intersection_ratio: c_double, +} diff --git a/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs b/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs index ade7831f14..2f793ce90a 100644 --- a/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/keyboard_event_init.rs @@ -1,24 +1,24 @@ -// 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 KeyboardEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, - pub alt_key: i32, - pub char_code: c_double, - pub code: *const c_char, - pub ctrl_key: i32, - pub is_composing: i32, - pub key: *const c_char, - pub key_code: c_double, - pub location: c_double, - pub meta_key: i32, - pub repeat: i32, - pub shift_key: i32, -} +// 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 KeyboardEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, + pub alt_key: i32, + pub char_code: c_double, + pub code: *const c_char, + pub ctrl_key: i32, + pub is_composing: i32, + pub key: *const c_char, + pub key_code: c_double, + pub location: c_double, + pub meta_key: i32, + pub repeat: i32, + pub shift_key: i32, +} diff --git a/bridge/rusty_webf_sys/src/events/mouse_event.rs b/bridge/rusty_webf_sys/src/events/mouse_event.rs index a7986e44cc..b281f6e5ab 100644 --- a/bridge/rusty_webf_sys/src/events/mouse_event.rs +++ b/bridge/rusty_webf_sys/src/events/mouse_event.rs @@ -1,153 +1,153 @@ -// 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 MouseEventRustMethods { - pub version: c_double, - pub ui_event: UIEventRustMethods, - pub client_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub client_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub offset_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub offset_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct MouseEvent { - pub ui_event: UIEvent, - method_pointer: *const MouseEventRustMethods, -} -impl MouseEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const MouseEventRustMethods, status: *const RustValueStatus) -> MouseEvent { - unsafe { - MouseEvent { - ui_event: UIEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().ui_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.ui_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.ui_event.context() - } - pub fn client_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).client_x)(self.ptr()) - }; - value - } - pub fn client_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).client_y)(self.ptr()) - }; - value - } - pub fn offset_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).offset_x)(self.ptr()) - }; - value - } - pub fn offset_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).offset_y)(self.ptr()) - }; - value - } -} -pub trait MouseEventMethods: UIEventMethods { - fn client_x(&self) -> f64; - fn client_y(&self) -> f64; - fn offset_x(&self) -> f64; - fn offset_y(&self) -> f64; - fn as_mouse_event(&self) -> &MouseEvent; -} -impl MouseEventMethods for MouseEvent { - fn client_x(&self) -> f64 { - self.client_x() - } - fn client_y(&self) -> f64 { - self.client_y() - } - fn offset_x(&self) -> f64 { - self.offset_x() - } - fn offset_y(&self) -> f64 { - self.offset_y() - } - fn as_mouse_event(&self) -> &MouseEvent { - self - } -} -impl UIEventMethods for MouseEvent { - fn detail(&self) -> f64 { - self.ui_event.detail() - } - fn view(&self) -> Window { - self.ui_event.view() - } - fn which(&self) -> f64 { - self.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.ui_event - } -} -impl EventMethods for MouseEvent { - fn bubbles(&self) -> bool { - self.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.ui_event.event - } -} +// 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 MouseEventRustMethods { + pub version: c_double, + pub ui_event: UIEventRustMethods, + pub client_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub client_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub offset_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub offset_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct MouseEvent { + pub ui_event: UIEvent, + method_pointer: *const MouseEventRustMethods, +} +impl MouseEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const MouseEventRustMethods, status: *const RustValueStatus) -> MouseEvent { + unsafe { + MouseEvent { + ui_event: UIEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().ui_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.ui_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.ui_event.context() + } + pub fn client_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).client_x)(self.ptr()) + }; + value + } + pub fn client_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).client_y)(self.ptr()) + }; + value + } + pub fn offset_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).offset_x)(self.ptr()) + }; + value + } + pub fn offset_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).offset_y)(self.ptr()) + }; + value + } +} +pub trait MouseEventMethods: UIEventMethods { + fn client_x(&self) -> f64; + fn client_y(&self) -> f64; + fn offset_x(&self) -> f64; + fn offset_y(&self) -> f64; + fn as_mouse_event(&self) -> &MouseEvent; +} +impl MouseEventMethods for MouseEvent { + fn client_x(&self) -> f64 { + self.client_x() + } + fn client_y(&self) -> f64 { + self.client_y() + } + fn offset_x(&self) -> f64 { + self.offset_x() + } + fn offset_y(&self) -> f64 { + self.offset_y() + } + fn as_mouse_event(&self) -> &MouseEvent { + self + } +} +impl UIEventMethods for MouseEvent { + fn detail(&self) -> f64 { + self.ui_event.detail() + } + fn view(&self) -> Window { + self.ui_event.view() + } + fn which(&self) -> f64 { + self.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.ui_event + } +} +impl EventMethods for MouseEvent { + fn bubbles(&self) -> bool { + self.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/events/mouse_event_init.rs b/bridge/rusty_webf_sys/src/events/mouse_event_init.rs index 56f0d81a10..d2619818a4 100644 --- a/bridge/rusty_webf_sys/src/events/mouse_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/mouse_event_init.rs @@ -1,13 +1,13 @@ -// 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 MouseEventInit { - pub detail: c_double, - pub view: RustValue, - pub which: c_double, -} +// 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 MouseEventInit { + pub detail: c_double, + pub view: RustValue, + pub which: c_double, +} diff --git a/bridge/rusty_webf_sys/src/events/pointer_event.rs b/bridge/rusty_webf_sys/src/events/pointer_event.rs index 262e3169a6..c021e8acb3 100644 --- a/bridge/rusty_webf_sys/src/events/pointer_event.rs +++ b/bridge/rusty_webf_sys/src/events/pointer_event.rs @@ -1,238 +1,238 @@ -// 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 PointerEventRustMethods { - pub version: c_double, - pub mouse_event: MouseEventRustMethods, - pub height: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub is_primary: extern "C" fn(ptr: *const OpaquePtr) -> i32, - pub pointer_id: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tangential_pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tilt_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub tilt_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub twist: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub width: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct PointerEvent { - pub mouse_event: MouseEvent, - method_pointer: *const PointerEventRustMethods, -} -impl PointerEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const PointerEventRustMethods, status: *const RustValueStatus) -> PointerEvent { - unsafe { - PointerEvent { - mouse_event: MouseEvent::initialize( - ptr, - context, - &(method_pointer).as_ref().unwrap().mouse_event, - status, - ), - method_pointer, - } - } - } - pub fn ptr(&self) -> *const OpaquePtr { - self.mouse_event.ptr() - } - pub fn context<'a>(&self) -> &'a ExecutingContext { - self.mouse_event.context() - } - pub fn height(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).height)(self.ptr()) - }; - value - } - pub fn is_primary(&self) -> bool { - let value = unsafe { - ((*self.method_pointer).is_primary)(self.ptr()) - }; - value != 0 - } - pub fn pointer_id(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).pointer_id)(self.ptr()) - }; - value - } - pub fn pointer_type(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pointer_type)(self.ptr()) - }; +// 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 PointerEventRustMethods { + pub version: c_double, + pub mouse_event: MouseEventRustMethods, + pub height: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub is_primary: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub pointer_id: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pointer_type: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tangential_pressure: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tilt_x: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub tilt_y: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub twist: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub width: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct PointerEvent { + pub mouse_event: MouseEvent, + method_pointer: *const PointerEventRustMethods, +} +impl PointerEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const PointerEventRustMethods, status: *const RustValueStatus) -> PointerEvent { + unsafe { + PointerEvent { + mouse_event: MouseEvent::initialize( + ptr, + context, + &(method_pointer).as_ref().unwrap().mouse_event, + status, + ), + method_pointer, + } + } + } + pub fn ptr(&self) -> *const OpaquePtr { + self.mouse_event.ptr() + } + pub fn context<'a>(&self) -> &'a ExecutingContext { + self.mouse_event.context() + } + pub fn height(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).height)(self.ptr()) + }; + value + } + pub fn is_primary(&self) -> bool { + let value = unsafe { + ((*self.method_pointer).is_primary)(self.ptr()) + }; + value != 0 + } + pub fn pointer_id(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).pointer_id)(self.ptr()) + }; + value + } + pub fn pointer_type(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pointer_type)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn pressure(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).pressure)(self.ptr()) - }; - value - } - pub fn tangential_pressure(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tangential_pressure)(self.ptr()) - }; - value - } - pub fn tilt_x(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tilt_x)(self.ptr()) - }; - value - } - pub fn tilt_y(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).tilt_y)(self.ptr()) - }; - value - } - pub fn twist(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).twist)(self.ptr()) - }; - value - } - pub fn width(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).width)(self.ptr()) - }; - value - } -} -pub trait PointerEventMethods: MouseEventMethods { - fn height(&self) -> f64; - fn is_primary(&self) -> bool; - fn pointer_id(&self) -> f64; - fn pointer_type(&self) -> String; - fn pressure(&self) -> f64; - fn tangential_pressure(&self) -> f64; - fn tilt_x(&self) -> f64; - fn tilt_y(&self) -> f64; - fn twist(&self) -> f64; - fn width(&self) -> f64; - fn as_pointer_event(&self) -> &PointerEvent; -} -impl PointerEventMethods for PointerEvent { - fn height(&self) -> f64 { - self.height() - } - fn is_primary(&self) -> bool { - self.is_primary() - } - fn pointer_id(&self) -> f64 { - self.pointer_id() - } - fn pointer_type(&self) -> String { - self.pointer_type() - } - fn pressure(&self) -> f64 { - self.pressure() - } - fn tangential_pressure(&self) -> f64 { - self.tangential_pressure() - } - fn tilt_x(&self) -> f64 { - self.tilt_x() - } - fn tilt_y(&self) -> f64 { - self.tilt_y() - } - fn twist(&self) -> f64 { - self.twist() - } - fn width(&self) -> f64 { - self.width() - } - fn as_pointer_event(&self) -> &PointerEvent { - self - } -} -impl MouseEventMethods for PointerEvent { - fn client_x(&self) -> f64 { - self.mouse_event.client_x() - } - fn client_y(&self) -> f64 { - self.mouse_event.client_y() - } - fn offset_x(&self) -> f64 { - self.mouse_event.offset_x() - } - fn offset_y(&self) -> f64 { - self.mouse_event.offset_y() - } - fn as_mouse_event(&self) -> &MouseEvent { - &self.mouse_event - } -} -impl UIEventMethods for PointerEvent { - fn detail(&self) -> f64 { - self.mouse_event.ui_event.detail() - } - fn view(&self) -> Window { - self.mouse_event.ui_event.view() - } - fn which(&self) -> f64 { - self.mouse_event.ui_event.which() - } - fn as_ui_event(&self) -> &UIEvent { - &self.mouse_event.ui_event - } -} -impl EventMethods for PointerEvent { - fn bubbles(&self) -> bool { - self.mouse_event.ui_event.event.bubbles() - } - fn cancel_bubble(&self) -> bool { - self.mouse_event.ui_event.event.cancel_bubble() - } - fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.set_cancel_bubble(value, exception_state) - } - fn cancelable(&self) -> bool { - self.mouse_event.ui_event.event.cancelable() - } - fn current_target(&self) -> EventTarget { - self.mouse_event.ui_event.event.current_target() - } - fn default_prevented(&self) -> bool { - self.mouse_event.ui_event.event.default_prevented() - } - fn src_element(&self) -> EventTarget { - self.mouse_event.ui_event.event.src_element() - } - fn target(&self) -> EventTarget { - self.mouse_event.ui_event.event.target() - } - fn is_trusted(&self) -> bool { - self.mouse_event.ui_event.event.is_trusted() - } - fn time_stamp(&self) -> f64 { - self.mouse_event.ui_event.event.time_stamp() - } - fn type_(&self) -> String { - self.mouse_event.ui_event.event.type_() - } - fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) - } - fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.prevent_default(exception_state) - } - fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.stop_immediate_propagation(exception_state) - } - fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { - self.mouse_event.ui_event.event.stop_propagation(exception_state) - } - fn as_event(&self) -> &Event { - &self.mouse_event.ui_event.event - } -} + value.to_str().unwrap().to_string() + } + pub fn pressure(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).pressure)(self.ptr()) + }; + value + } + pub fn tangential_pressure(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tangential_pressure)(self.ptr()) + }; + value + } + pub fn tilt_x(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tilt_x)(self.ptr()) + }; + value + } + pub fn tilt_y(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).tilt_y)(self.ptr()) + }; + value + } + pub fn twist(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).twist)(self.ptr()) + }; + value + } + pub fn width(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).width)(self.ptr()) + }; + value + } +} +pub trait PointerEventMethods: MouseEventMethods { + fn height(&self) -> f64; + fn is_primary(&self) -> bool; + fn pointer_id(&self) -> f64; + fn pointer_type(&self) -> String; + fn pressure(&self) -> f64; + fn tangential_pressure(&self) -> f64; + fn tilt_x(&self) -> f64; + fn tilt_y(&self) -> f64; + fn twist(&self) -> f64; + fn width(&self) -> f64; + fn as_pointer_event(&self) -> &PointerEvent; +} +impl PointerEventMethods for PointerEvent { + fn height(&self) -> f64 { + self.height() + } + fn is_primary(&self) -> bool { + self.is_primary() + } + fn pointer_id(&self) -> f64 { + self.pointer_id() + } + fn pointer_type(&self) -> String { + self.pointer_type() + } + fn pressure(&self) -> f64 { + self.pressure() + } + fn tangential_pressure(&self) -> f64 { + self.tangential_pressure() + } + fn tilt_x(&self) -> f64 { + self.tilt_x() + } + fn tilt_y(&self) -> f64 { + self.tilt_y() + } + fn twist(&self) -> f64 { + self.twist() + } + fn width(&self) -> f64 { + self.width() + } + fn as_pointer_event(&self) -> &PointerEvent { + self + } +} +impl MouseEventMethods for PointerEvent { + fn client_x(&self) -> f64 { + self.mouse_event.client_x() + } + fn client_y(&self) -> f64 { + self.mouse_event.client_y() + } + fn offset_x(&self) -> f64 { + self.mouse_event.offset_x() + } + fn offset_y(&self) -> f64 { + self.mouse_event.offset_y() + } + fn as_mouse_event(&self) -> &MouseEvent { + &self.mouse_event + } +} +impl UIEventMethods for PointerEvent { + fn detail(&self) -> f64 { + self.mouse_event.ui_event.detail() + } + fn view(&self) -> Window { + self.mouse_event.ui_event.view() + } + fn which(&self) -> f64 { + self.mouse_event.ui_event.which() + } + fn as_ui_event(&self) -> &UIEvent { + &self.mouse_event.ui_event + } +} +impl EventMethods for PointerEvent { + fn bubbles(&self) -> bool { + self.mouse_event.ui_event.event.bubbles() + } + fn cancel_bubble(&self) -> bool { + self.mouse_event.ui_event.event.cancel_bubble() + } + fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.set_cancel_bubble(value, exception_state) + } + fn cancelable(&self) -> bool { + self.mouse_event.ui_event.event.cancelable() + } + fn current_target(&self) -> EventTarget { + self.mouse_event.ui_event.event.current_target() + } + fn default_prevented(&self) -> bool { + self.mouse_event.ui_event.event.default_prevented() + } + fn src_element(&self) -> EventTarget { + self.mouse_event.ui_event.event.src_element() + } + fn target(&self) -> EventTarget { + self.mouse_event.ui_event.event.target() + } + fn is_trusted(&self) -> bool { + self.mouse_event.ui_event.event.is_trusted() + } + fn time_stamp(&self) -> f64 { + self.mouse_event.ui_event.event.time_stamp() + } + fn type_(&self) -> String { + self.mouse_event.ui_event.event.type_() + } + fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.init_event(type_, bubbles, cancelable, exception_state) + } + fn prevent_default(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.prevent_default(exception_state) + } + fn stop_immediate_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.stop_immediate_propagation(exception_state) + } + fn stop_propagation(&self, exception_state: &ExceptionState) -> Result<(), String> { + self.mouse_event.ui_event.event.stop_propagation(exception_state) + } + fn as_event(&self) -> &Event { + &self.mouse_event.ui_event.event + } +} diff --git a/bridge/rusty_webf_sys/src/events/pointer_event_init.rs b/bridge/rusty_webf_sys/src/events/pointer_event_init.rs index 8b4bd24cf1..d76286ad77 100644 --- a/bridge/rusty_webf_sys/src/events/pointer_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/pointer_event_init.rs @@ -1,20 +1,20 @@ -// 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 PointerEventInit { - pub is_primary: i32, - pub pointer_id: c_double, - pub pointer_type: *const c_char, - pub pressure: c_double, - pub tangential_pressure: c_double, - pub tilt_x: c_double, - pub tilt_y: c_double, - pub twist: c_double, - pub width: c_double, - pub height: c_double, -} +// 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 PointerEventInit { + pub is_primary: i32, + pub pointer_id: c_double, + pub pointer_type: *const c_char, + pub pressure: c_double, + pub tangential_pressure: c_double, + pub tilt_x: c_double, + pub tilt_y: c_double, + pub twist: c_double, + pub width: c_double, + pub height: c_double, +} diff --git a/bridge/rusty_webf_sys/src/events/transition_event.rs b/bridge/rusty_webf_sys/src/events/transition_event.rs index 315e6eb42a..3cfa89b813 100644 --- a/bridge/rusty_webf_sys/src/events/transition_event.rs +++ b/bridge/rusty_webf_sys/src/events/transition_event.rs @@ -1,132 +1,132 @@ -// 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 TransitionEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, -} -pub struct TransitionEvent { - pub event: Event, - method_pointer: *const TransitionEventRustMethods, -} -impl TransitionEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const TransitionEventRustMethods, status: *const RustValueStatus) -> TransitionEvent { - unsafe { - TransitionEvent { - 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 elapsed_time(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).elapsed_time)(self.ptr()) - }; - value - } - pub fn property_name(&self) -> String { - let value = unsafe { - ((*self.method_pointer).property_name)(self.ptr()) - }; +// 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 TransitionEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub elapsed_time: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_property_name: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, + pub dup_pseudo_element: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, +} +pub struct TransitionEvent { + pub event: Event, + method_pointer: *const TransitionEventRustMethods, +} +impl TransitionEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const TransitionEventRustMethods, status: *const RustValueStatus) -> TransitionEvent { + unsafe { + TransitionEvent { + 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 elapsed_time(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).elapsed_time)(self.ptr()) + }; + value + } + pub fn property_name(&self) -> String { + let value = unsafe { + ((*self.method_pointer).property_name)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } - pub fn pseudo_element(&self) -> String { - let value = unsafe { - ((*self.method_pointer).pseudo_element)(self.ptr()) - }; + value.to_str().unwrap().to_string() + } + pub fn pseudo_element(&self) -> String { + let value = unsafe { + ((*self.method_pointer).pseudo_element)(self.ptr()) + }; let value = unsafe { std::ffi::CStr::from_ptr(value) }; - value.to_str().unwrap().to_string() - } -} -pub trait TransitionEventMethods: EventMethods { - fn elapsed_time(&self) -> f64; - fn property_name(&self) -> String; - fn pseudo_element(&self) -> String; - fn as_transition_event(&self) -> &TransitionEvent; -} -impl TransitionEventMethods for TransitionEvent { - fn elapsed_time(&self) -> f64 { - self.elapsed_time() - } - fn property_name(&self) -> String { - self.property_name() - } - fn pseudo_element(&self) -> String { - self.pseudo_element() - } - fn as_transition_event(&self) -> &TransitionEvent { - self - } -} -impl EventMethods for TransitionEvent { - 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 - } -} + value.to_str().unwrap().to_string() + } +} +pub trait TransitionEventMethods: EventMethods { + fn elapsed_time(&self) -> f64; + fn property_name(&self) -> String; + fn pseudo_element(&self) -> String; + fn as_transition_event(&self) -> &TransitionEvent; +} +impl TransitionEventMethods for TransitionEvent { + fn elapsed_time(&self) -> f64 { + self.elapsed_time() + } + fn property_name(&self) -> String { + self.property_name() + } + fn pseudo_element(&self) -> String { + self.pseudo_element() + } + fn as_transition_event(&self) -> &TransitionEvent { + self + } +} +impl EventMethods for TransitionEvent { + 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/events/transition_event_init.rs b/bridge/rusty_webf_sys/src/events/transition_event_init.rs index 109a3eaa6f..1929805a54 100644 --- a/bridge/rusty_webf_sys/src/events/transition_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/transition_event_init.rs @@ -1,16 +1,16 @@ -// 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 TransitionEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub elapsed_time: c_double, - pub property_name: *const c_char, - pub pseudo_element: *const c_char, -} +// 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 TransitionEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub elapsed_time: c_double, + pub property_name: *const c_char, + pub pseudo_element: *const c_char, +} diff --git a/bridge/rusty_webf_sys/src/events/ui_event.rs b/bridge/rusty_webf_sys/src/events/ui_event.rs index b1450d222b..9b007486aa 100644 --- a/bridge/rusty_webf_sys/src/events/ui_event.rs +++ b/bridge/rusty_webf_sys/src/events/ui_event.rs @@ -1,128 +1,128 @@ -// 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 UIEventRustMethods { - pub version: c_double, - pub event: EventRustMethods, - pub detail: extern "C" fn(ptr: *const OpaquePtr) -> c_double, - pub view: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub which: extern "C" fn(ptr: *const OpaquePtr) -> c_double, -} -pub struct UIEvent { - pub event: Event, - method_pointer: *const UIEventRustMethods, -} -impl UIEvent { - pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const UIEventRustMethods, status: *const RustValueStatus) -> UIEvent { - unsafe { - UIEvent { - 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) -> f64 { - let value = unsafe { - ((*self.method_pointer).detail)(self.ptr()) - }; - value - } - pub fn view(&self) -> Window { - let value = unsafe { - ((*self.method_pointer).view)(self.ptr()) - }; - Window::initialize(value.value, self.context(), value.method_pointer, value.status) - } - pub fn which(&self) -> f64 { - let value = unsafe { - ((*self.method_pointer).which)(self.ptr()) - }; - value - } -} -pub trait UIEventMethods: EventMethods { - fn detail(&self) -> f64; - fn view(&self) -> Window; - fn which(&self) -> f64; - fn as_ui_event(&self) -> &UIEvent; -} -impl UIEventMethods for UIEvent { - fn detail(&self) -> f64 { - self.detail() - } - fn view(&self) -> Window { - self.view() - } - fn which(&self) -> f64 { - self.which() - } - fn as_ui_event(&self) -> &UIEvent { - self - } -} -impl EventMethods for UIEvent { - 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 - } -} +// 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 UIEventRustMethods { + pub version: c_double, + pub event: EventRustMethods, + pub detail: extern "C" fn(ptr: *const OpaquePtr) -> c_double, + pub view: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, + pub which: extern "C" fn(ptr: *const OpaquePtr) -> c_double, +} +pub struct UIEvent { + pub event: Event, + method_pointer: *const UIEventRustMethods, +} +impl UIEvent { + pub fn initialize(ptr: *const OpaquePtr, context: *const ExecutingContext, method_pointer: *const UIEventRustMethods, status: *const RustValueStatus) -> UIEvent { + unsafe { + UIEvent { + 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) -> f64 { + let value = unsafe { + ((*self.method_pointer).detail)(self.ptr()) + }; + value + } + pub fn view(&self) -> Window { + let value = unsafe { + ((*self.method_pointer).view)(self.ptr()) + }; + Window::initialize(value.value, self.context(), value.method_pointer, value.status) + } + pub fn which(&self) -> f64 { + let value = unsafe { + ((*self.method_pointer).which)(self.ptr()) + }; + value + } +} +pub trait UIEventMethods: EventMethods { + fn detail(&self) -> f64; + fn view(&self) -> Window; + fn which(&self) -> f64; + fn as_ui_event(&self) -> &UIEvent; +} +impl UIEventMethods for UIEvent { + fn detail(&self) -> f64 { + self.detail() + } + fn view(&self) -> Window { + self.view() + } + fn which(&self) -> f64 { + self.which() + } + fn as_ui_event(&self) -> &UIEvent { + self + } +} +impl EventMethods for UIEvent { + 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/events/ui_event_init.rs b/bridge/rusty_webf_sys/src/events/ui_event_init.rs index df50c26a95..bad73efe5e 100644 --- a/bridge/rusty_webf_sys/src/events/ui_event_init.rs +++ b/bridge/rusty_webf_sys/src/events/ui_event_init.rs @@ -1,16 +1,16 @@ -// 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 UIEventInit { - pub bubbles: i32, - pub cancelable: i32, - pub composed: i32, - pub detail: c_double, - pub view: RustValue, - pub which: c_double, -} +// 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 UIEventInit { + pub bubbles: i32, + pub cancelable: i32, + pub composed: i32, + pub detail: c_double, + pub view: RustValue, + pub which: c_double, +} diff --git a/bridge/rusty_webf_sys/src/input/touch_init.rs b/bridge/rusty_webf_sys/src/input/touch_init.rs index 8dcef7521e..de06dd9b8f 100644 --- a/bridge/rusty_webf_sys/src/input/touch_init.rs +++ b/bridge/rusty_webf_sys/src/input/touch_init.rs @@ -1,22 +1,22 @@ -// 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 TouchInit { - pub identifier: c_double, - pub target: RustValue, - pub client_x: c_double, - pub client_y: c_double, - pub screen_x: c_double, - pub screen_y: c_double, - pub page_x: c_double, - pub page_y: c_double, - pub radius_x: c_double, - pub radius_y: c_double, - pub rotation_angle: c_double, - pub force: c_double, -} +// 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 TouchInit { + pub identifier: c_double, + pub target: RustValue, + pub client_x: c_double, + pub client_y: c_double, + pub screen_x: c_double, + pub screen_y: c_double, + pub page_x: c_double, + pub page_y: c_double, + pub radius_x: c_double, + pub radius_y: c_double, + pub rotation_angle: c_double, + pub force: c_double, +} From 9d1b2cacd6b3de334756a39a8c4d3b0d0fb156a3 Mon Sep 17 00:00:00 2001 From: Jiaxun Wei Date: Sat, 21 Dec 2024 16:35:36 +0800 Subject: [PATCH 15/19] fix: release heap string --- bridge/rusty_webf_sys/src/native_value.rs | 32 ++++++++--------------- webf/example/rust_builder/rust/src/lib.rs | 12 +-------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/bridge/rusty_webf_sys/src/native_value.rs b/bridge/rusty_webf_sys/src/native_value.rs index 1e206fab0c..dc6bbd2b42 100644 --- a/bridge/rusty_webf_sys/src/native_value.rs +++ b/bridge/rusty_webf_sys/src/native_value.rs @@ -57,8 +57,7 @@ impl NativeValue { value } - pub fn new_string(val: &str) -> Self { - let len = val.len(); + fn create_string_ptr(val: &str, len: usize) -> *mut SharedNativeString { let size = len * mem::size_of::(); #[cfg(target_os = "windows")] @@ -68,10 +67,8 @@ impl NativeValue { let ptr = unsafe { libc::malloc(size) }; let ptr = ptr as *mut u16; - let mut length = 0; for (i, c) in val.encode_utf16().enumerate() { - length = i + 1; unsafe { ptr.add(i).write(c); } @@ -79,7 +76,7 @@ impl NativeValue { let mut shared_string = SharedNativeString { string_: ptr, - length_: length as u32, + length_: len as u32, }; let shared_string_size = mem::size_of::(); @@ -95,6 +92,12 @@ impl NativeValue { shared_string_ptr.write(shared_string); } + shared_string_ptr + } + + pub fn new_string(val: &str) -> Self { + let len = val.len(); + let shared_string_ptr = Self::create_string_ptr(val, len); let mut value = Self::new(); value.tag = NativeTag::TagString as i32; value.u.ptr = shared_string_ptr as *mut c_void; @@ -194,8 +197,9 @@ impl NativeValue { let array_ptr = array_ptr as *mut NativeValue; for (i, val) in values.iter().enumerate() { + let mut value = val.clone(); unsafe { - array_ptr.add(i).write(val.clone()); + array_ptr.add(i).write(value); } } @@ -226,20 +230,6 @@ impl NativeValue { impl Drop for NativeValue { fn drop(&mut self) { - if self.tag == NativeTag::TagString as i32 { - println!("Drop NativeValue string: {}", self.to_string()); - } else if self.tag == NativeTag::TagList as i32 { - println!("Drop NativeValue list"); - let ptr = unsafe { - self.u.ptr as *mut NativeValue - }; - for i in 0..self.uint32 { - let offset = i.try_into().unwrap(); - let val = unsafe { ptr.add(offset).read() }; - drop(val); - } - } else { - println!("Drop NativeValue: {:?}", self.tag); - } + // no need to drop inner structure, it will be freed by the dart side } } diff --git a/webf/example/rust_builder/rust/src/lib.rs b/webf/example/rust_builder/rust/src/lib.rs index ed7bb1ebf7..95a96dfce7 100644 --- a/webf/example/rust_builder/rust/src/lib.rs +++ b/webf/example/rust_builder/rust/src/lib.rs @@ -14,17 +14,7 @@ pub extern "C" fn init_webf_app(handle: RustValue) let navigator = context.navigator(); let ua_string = navigator.user_agent(&exception_state); - let platform = navigator.platform(&exception_state); - let language = navigator.language(&exception_state); - let app_name = navigator.app_name(&exception_state); - let app_version = navigator.app_version(&exception_state); - let hardware_concurrency = navigator.hardware_concurrency(&exception_state); println!("User Agent: {}", ua_string); - println!("Platform: {}", platform); - println!("Language: {}", language); - println!("App Name: {}", app_name); - println!("App Version: {}", app_version); - println!("Hardware Concurrency: {}", hardware_concurrency); let local_storage = context.local_storage(); @@ -80,7 +70,7 @@ pub extern "C" fn init_webf_app(handle: RustValue) println!("Timer Callback"); }); - context.set_interval_with_callback_and_timeout(timer_callback, 1000, &exception_state).unwrap(); + context.set_timeout_with_callback_and_timeout(timer_callback, 1000, &exception_state).unwrap(); let click_event = document.create_event("custom_click", &exception_state).unwrap(); document.dispatch_event(&click_event, &exception_state); From bf66131acd842f620239f3ee057152b2cecf0aed Mon Sep 17 00:00:00 2001 From: andycall Date: Fri, 27 Dec 2024 23:02:03 +0800 Subject: [PATCH 16/19] fix: fix code linter workflow --- .github/workflows/code_linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_linter.yml b/.github/workflows/code_linter.yml index d4eafc1c58..b7b06c3b4d 100644 --- a/.github/workflows/code_linter.yml +++ b/.github/workflows/code_linter.yml @@ -8,7 +8,7 @@ on: jobs: cppcheck: - runs-on: macos-12 + runs-on: macos-14 name: Cppcheck steps: - uses: actions/checkout@v3 From 0f832dc42d31d7815daa70b0b9cae1488db3aa6b Mon Sep 17 00:00:00 2001 From: andycall Date: Fri, 27 Dec 2024 23:03:31 +0800 Subject: [PATCH 17/19] fix: fix linux build --- bridge/foundation/ui_command_strategy.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/bridge/foundation/ui_command_strategy.cc b/bridge/foundation/ui_command_strategy.cc index 8fddd6ca32..1cce5ff4f3 100644 --- a/bridge/foundation/ui_command_strategy.cc +++ b/bridge/foundation/ui_command_strategy.cc @@ -2,6 +2,7 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ +#include #include "ui_command_strategy.h" #include #include "core/binding_object.h" From bfc1851102520c87f817302b796639fb5532746a Mon Sep 17 00:00:00 2001 From: andycall Date: Sat, 28 Dec 2024 01:03:20 +0800 Subject: [PATCH 18/19] fix: fix linux build --- bridge/core/dart_isolate_context.cc | 1 + bridge/core/dom/space_split_string.h | 1 + bridge/foundation/ui_command_strategy.cc | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bridge/core/dart_isolate_context.cc b/bridge/core/dart_isolate_context.cc index 3787b1e533..a5b2e29c53 100644 --- a/bridge/core/dart_isolate_context.cc +++ b/bridge/core/dart_isolate_context.cc @@ -2,6 +2,7 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ +#include #include "dart_isolate_context.h" #include #include "defined_properties_initializer.h" diff --git a/bridge/core/dom/space_split_string.h b/bridge/core/dom/space_split_string.h index 154053dfbe..f7843a5ee4 100644 --- a/bridge/core/dom/space_split_string.h +++ b/bridge/core/dom/space_split_string.h @@ -5,6 +5,7 @@ #ifndef WEBF_CORE_DOM_SPACE_SPLIT_STRING_H_ #define WEBF_CORE_DOM_SPACE_SPLIT_STRING_H_ +#include #include #include #include "bindings/qjs/atomic_string.h" diff --git a/bridge/foundation/ui_command_strategy.cc b/bridge/foundation/ui_command_strategy.cc index 1cce5ff4f3..ddb56edace 100644 --- a/bridge/foundation/ui_command_strategy.cc +++ b/bridge/foundation/ui_command_strategy.cc @@ -2,9 +2,9 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ -#include #include "ui_command_strategy.h" #include +#include #include "core/binding_object.h" #include "logging.h" #include "shared_ui_command.h" From 9a8899004dccf152bc6073eceed47080e91e65c4 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:04:08 +0000 Subject: [PATCH 19/19] Commit from GitHub Actions (Run Code Linter) --- bridge/core/dart_isolate_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge/core/dart_isolate_context.cc b/bridge/core/dart_isolate_context.cc index a5b2e29c53..198b7166e2 100644 --- a/bridge/core/dart_isolate_context.cc +++ b/bridge/core/dart_isolate_context.cc @@ -2,8 +2,8 @@ * Copyright (C) 2022-present The WebF authors. All rights reserved. */ -#include #include "dart_isolate_context.h" +#include #include #include "defined_properties_initializer.h" #include "event_factory.h"