Truly independent web browser
LibWeb: Implement the Event Timing processing model in Rust
Shannon Booth7add26252ac6
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/event_target.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/event_target.rsindex 85210ed822d..1ad6bf298a8 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/event_target.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/event_target.rs@@ -12,7 +12,7 @@use core::ffi::c_void;use core::ptr::NonNull;-use ak::Utf16String;+use ak::{Utf16FlyString, Utf16String};use libjs_rust::api::{FunctionObject, Gc, Object, Realm, Trace, Value};use liburl_rust::FfiOrigin;use liburl_rust::origin::Origin;@@ -88,6 +88,10 @@ unsafe extern "C" {) -> bool;fn web_bindings_event_canceled(event: *mut c_void) -> bool;fn web_bindings_event_dispatched(event: *mut c_void) -> bool;+ fn web_bindings_event_type(event: *mut c_void) -> usize;+ fn web_bindings_event_is_trusted(event: *mut c_void) -> bool;+ fn web_bindings_event_time_stamp(event: *mut c_void) -> f64;+ fn web_bindings_event_cancelable(event: *mut c_void) -> bool;fn web_bindings_initialize_event(event: *mut c_void, r#type: usize, bubbles: bool, cancelable: bool);}@@ -233,6 +237,14 @@ impl CppEventTarget {pub(crate) struct CppEvent(CppCell);impl CppEvent {+ /// # Safety+ ///+ /// `event` must be a live Event.+ pub(crate) unsafe fn from_raw(event: *mut c_void) -> Self {+ // SAFETY: The caller passes a live Event.+ Self(unsafe { CppCell::from_raw(event) })+ }+pub(crate) fn create(realm: Gc<Realm>, r#type: &str, bubbles: bool, cancelable: bool, composed: bool) -> Self {// SAFETY: The realm is live, the type is lent for the call, and LibWeb returns a live event.let event = Self(unsafe {@@ -314,6 +326,30 @@ impl CppEvent {unsafe { web_bindings_event_set_is_trusted(self.as_ptr(), is_trusted) };}+ /// https://dom.spec.whatwg.org/#dom-event-type+ pub(crate) fn r#type(&self) -> Utf16String {+ // SAFETY: The event is live, and LibWeb lends its type, which this copies.+ unsafe { Utf16FlyString::from_raw_borrowed(web_bindings_event_type(self.as_ptr())) }.into()+ }++ /// https://dom.spec.whatwg.org/#dom-event-istrusted+ pub(crate) fn is_trusted(&self) -> bool {+ // SAFETY: The event is live.+ unsafe { web_bindings_event_is_trusted(self.as_ptr()) }+ }++ /// https://dom.spec.whatwg.org/#dom-event-timestamp+ pub(crate) fn time_stamp(&self) -> f64 {+ // SAFETY: The event is live.+ unsafe { web_bindings_event_time_stamp(self.as_ptr()) }+ }++ /// https://dom.spec.whatwg.org/#dom-event-cancelable+ pub(crate) fn cancelable(&self) -> bool {+ // SAFETY: The event is live.+ unsafe { web_bindings_event_cancelable(self.as_ptr()) }+ }+/// https://dom.spec.whatwg.org/#canceled-flagpub(crate) fn canceled(&self) -> bool {// SAFETY: The event is live.diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rsindex fe5d69fd25d..e13fe6ee83b 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/global_object.rs@@ -14,7 +14,9 @@ use libjs_rust::api::{Gc, MarkedVec, Object, Realm, Trace, Vm};use crate::bindings::cpp_cell::CppCell;use crate::bindings::event_target::CppEventTarget;use crate::bindings::interface::Wrappable;+use crate::bindings::realm_data::realm_data;use crate::dom::document::CppDocument;+use crate::event_timing::event_timing::{WindowEventTimingState, WindowEventTimingStateRef};unsafe extern "C" {fn web_bindings_window_from_global_object(global_object: *mut c_void) -> *mut c_void;@@ -99,6 +101,17 @@ impl CppWindow {self.0.as_ptr()}+ // https://w3c.github.io/event-timing/#sec-modifications-HTML+ pub(crate) fn event_timing_state(&self, vm: &Vm) -> WindowEventTimingStateRef {+ let data = realm_data(vm, self.realm());+ if let Some(state) = data.event_timing_state.get() {+ return state;+ }+ let state = WindowEventTimingState::create(vm);+ data.event_timing_state.set(Some(state));+ state+ }+/// https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-realmpub(crate) fn realm(&self) -> Gc<Realm> {// SAFETY: The Window is live, and LibWeb returns its live relevant realm.diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/realm_data.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/realm_data.rsindex e10d5e781a8..ff83b6148be 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/realm_data.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/realm_data.rs@@ -17,7 +17,7 @@ use libjs_rust::api::{EmbedderCell, EmbedderClass, EmbedderValue, FunctionObjectuse crate::bindings::interface::Ref;use crate::bindings::services::web_bindings_wrapper_world;-use crate::event_timing::event_counts::EventCounts;+use crate::event_timing::event_timing::WindowEventTimingStateRef;use crate::performance_timeline::performance_timeline::PerformanceTimelineRef;use crate::web_assembly::tag::Tag;@@ -54,7 +54,7 @@ pub(crate) struct RealmData {/// https://w3c.github.io/performance-timeline/#supportedentrytypes-attributepub(crate) performance_observer_supported_entry_types: Cell<Option<Gc<Object>>>,/// https://w3c.github.io/event-timing/#sec-modifications-HTML- pub(crate) event_counts: Cell<Option<Ref<EventCounts>>>,+ pub(crate) event_timing_state: Cell<Option<WindowEventTimingStateRef>>,}static REALM_DATA_CLASS: EmbedderClass<RealmData> = EmbedderClass::new("RealmData");diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_counts.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_counts.rsindex d50c7669663..721ae0196f6 100644--- a/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_counts.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_counts.rs@@ -14,10 +14,8 @@ use libjs_rust::api::{Gc, Map, Trace, Value, Vm};use crate::bindings::CallContext;use crate::bindings::conversions::ToJs;-use crate::bindings::global_object::CppWindow;use crate::bindings::interface::{Ref, Wrappable, allocate};use crate::bindings::maplike::Maplike;-use crate::bindings::realm_data::realm_data;unsafe extern "C" {fn web_event_timing_for_each_event_type_considered_for_event_timing(@@ -38,7 +36,7 @@ impl Wrappable for EventCounts {}impl EventCounts {// https://w3c.github.io/event-timing/#sec-modifications-HTML- fn create(vm: &Vm) -> Ref<Self> {+ pub(crate) fn create(vm: &Vm) -> Ref<Self> {// Upon construction of a Performance object whose relevant global object is a Window, its eventCounts must be// initialized to a map containing 0s for all event types that the user agent supports from the list described in// Events exposed.@@ -55,7 +53,7 @@ impl EventCounts {})}- fn increment(&self, event_type: &Utf16String) {+ pub(crate) fn increment(&self, event_type: &Utf16String) {let mut entries = self.entries.borrow_mut();let entry = entries.iter_mut()@@ -82,41 +80,3 @@ impl Maplike for EventCounts {Some(entry.1.to_js(cx).expect("an unsigned long long converts to a JS value"))}}--impl CppWindow {- // https://w3c.github.io/event-timing/#sec-modifications-HTML- pub(crate) fn event_counts(&self, vm: &Vm) -> Ref<EventCounts> {- let data = realm_data(vm, self.realm());- // NB: The eventCounts of a Window are created along with its Performance object, which is when they are first- // asked for.- if let Some(event_counts) = data.event_counts.get() {- return event_counts;- }- let event_counts = EventCounts::create(vm);- data.event_counts.set(Some(event_counts));- event_counts- }-}--/// https://w3c.github.io/event-timing/#sec-modifications-HTML-///-/// # Safety-///-/// `vm` must be the live VM, `window` a live Window, and `event_type` a live Utf16FlyString of an event type considered-/// for Event Timing.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_increment_event_count(- vm: *mut c_void,- window: *mut c_void,- event_type: usize,-) {- // SAFETY: The caller passes the live VM and a live Window, and lends the fly string.- let (vm, window, event_type) = unsafe {- (- &*vm.cast::<Vm>(),- CppWindow::from_raw(window),- Utf16String::from(Utf16FlyString::from_raw_borrowed(event_type)),- )- };- window.event_counts(vm).increment(&event_type);-}diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_timing.rsnew file mode 100644index 00000000000..63c5ddb0bcf--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/event_timing.rs@@ -0,0 +1,756 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::cell::{Cell, RefCell};+use core::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::{EmbedderCell, EmbedderClass, EmbedderValue, Gc, GcRefCell, MarkedVec, Trace, Vm};++use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;+use crate::bindings::global_object::CppWindow;+use crate::bindings::interface::{Ref, cell_from_abi, cell_into_abi};+use crate::event_timing::event_counts::EventCounts;+use crate::event_timing::performance_event_timing::PerformanceEventTiming;+use crate::performance_timeline::performance_entry::AnyPerformanceEntry;+use crate::performance_timeline::performance_timeline::PerformanceTimeline;+use crate::ui_events::input_event::CppInputEvent;+use crate::ui_events::keyboard_event::CppKeyboardEvent;+use crate::ui_events::mouse_event::is_mouse_event;+use crate::ui_events::pointer_event::{CppPointerEvent, MOUSE_POINTER_ID};++unsafe extern "C" {+ fn web_event_timing_request_frame(window: *mut c_void);+ fn web_high_resolution_time_current_high_resolution_time(global_object: *mut c_void) -> f64;+}++/// https://w3c.github.io/event-timing/#sec-modifications-HTML+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct WindowEventTimingState {+ // entries to be queued, a list that stores PerformanceEventTiming objects, which will initially be empty.+ entries_to_be_queued: GcRefCell<Vec<Ref<PerformanceEventTiming>>>,+ // has dispatched input event, a boolean which is initially set to false.+ has_dispatched_input_event: Cell<bool>,+ // user interaction value, an integer which is initially set to a random integer between 100 and 10000.+ user_interaction_value: Cell<u64>,+ // pending key downs, a map of integers to PerformanceEventTimings which is initially empty.+ pending_key_downs: GcRefCell<Vec<(u32, Ref<PerformanceEventTiming>)>>,+ // pointer interaction value map, a map of integers which is initially empty.+ #[gc(untraced)]+ pointer_interaction_value_map: RefCell<Vec<(i32, u64)>>,+ // pending pointer downs, a map of integers to PerformanceEventTimings which is initially empty.+ pending_pointer_downs: GcRefCell<Vec<(i32, Ref<PerformanceEventTiming>)>>,+ // is contextmenu triggered, a boolean which is initially set to false.+ is_contextmenu_triggered: Cell<bool>,+ // eventCounts, a map with entries of the form type → numEvents.+ // NB: This is created when it is first asked for.+ event_counts: Cell<Option<Ref<EventCounts>>>,+ // interactionCount, an integer which counts the total number of distinct user interactions, for which there was a+ // unique interactionId computed via computing interactionId.+ interaction_count: Cell<u64>,+}++static WINDOW_EVENT_TIMING_STATE_CLASS: EmbedderClass<WindowEventTimingState> =+ EmbedderClass::new("WindowEventTimingState");++impl EmbedderValue for WindowEventTimingState {+ const CLASS: &'static EmbedderClass<Self> = &WINDOW_EVENT_TIMING_STATE_CLASS;+}++pub(crate) type WindowEventTimingStateRef = Gc<EmbedderCell<WindowEventTimingState>>;++impl WindowEventTimingState {+ pub(crate) fn create(vm: &Vm) -> WindowEventTimingStateRef {+ // NB: The user interaction value is initially set to a random integer between 100 and 10000.+ let mut random_bytes = [0u8; 8];+ libcrypto_rust::fill_with_random(&mut random_bytes);+ let user_interaction_value = 100 + u64::from_ne_bytes(random_bytes) % 9901;++ WINDOW_EVENT_TIMING_STATE_CLASS.allocate(vm, |_| Self {+ entries_to_be_queued: GcRefCell::default(),+ has_dispatched_input_event: Cell::new(false),+ user_interaction_value: Cell::new(user_interaction_value),+ pending_key_downs: GcRefCell::default(),+ pointer_interaction_value_map: RefCell::default(),+ pending_pointer_downs: GcRefCell::default(),+ is_contextmenu_triggered: Cell::new(false),+ event_counts: Cell::new(None),+ interaction_count: Cell::new(0),+ })+ }++ pub(crate) fn event_counts(&self, vm: &Vm) -> Ref<EventCounts> {+ if let Some(event_counts) = self.event_counts.get() {+ return event_counts;+ }+ let event_counts = EventCounts::create(vm);+ self.event_counts.set(Some(event_counts));+ event_counts+ }++ pub(crate) fn interaction_count(&self) -> u64 {+ self.interaction_count.get()+ }++ pub(crate) fn has_dispatched_input_event(&self) -> bool {+ self.has_dispatched_input_event.get()+ }++ fn take_pending_key_down(&self, vm: &Vm, code: u32) -> Option<Ref<PerformanceEventTiming>> {+ let mut pending_key_downs = self.pending_key_downs.borrow_mut(vm);+ let index = pending_key_downs.iter().position(|(key, _)| *key == code)?;+ Some(pending_key_downs.remove(index).1)+ }++ fn take_pending_pointer_down(&self, vm: &Vm, pointer_id: i32) -> Option<Ref<PerformanceEventTiming>> {+ let mut pending_pointer_downs = self.pending_pointer_downs.borrow_mut(vm);+ let index = pending_pointer_downs.iter().position(|(key, _)| *key == pointer_id)?;+ Some(pending_pointer_downs.remove(index).1)+ }++ fn pending_key_down(&self, code: u32) -> Option<Ref<PerformanceEventTiming>> {+ self.pending_key_downs+ .borrow()+ .iter()+ .find(|(key, _)| *key == code)+ .map(|(_, entry)| *entry)+ }++ fn set_pending_key_down(&self, vm: &Vm, code: u32, entry: Ref<PerformanceEventTiming>) {+ let mut pending_key_downs = self.pending_key_downs.borrow_mut(vm);+ match pending_key_downs.iter_mut().find(|(key, _)| *key == code) {+ Some(pending_key_down) => pending_key_down.1 = entry,+ None => pending_key_downs.push((code, entry)),+ }+ }++ fn pending_pointer_down(&self, pointer_id: i32) -> Option<Ref<PerformanceEventTiming>> {+ self.pending_pointer_downs+ .borrow()+ .iter()+ .find(|(key, _)| *key == pointer_id)+ .map(|(_, entry)| *entry)+ }++ fn set_pending_pointer_down(&self, vm: &Vm, pointer_id: i32, entry: Ref<PerformanceEventTiming>) {+ let mut pending_pointer_downs = self.pending_pointer_downs.borrow_mut(vm);+ match pending_pointer_downs.iter_mut().find(|(key, _)| *key == pointer_id) {+ Some(pending_pointer_down) => pending_pointer_down.1 = entry,+ None => pending_pointer_downs.push((pointer_id, entry)),+ }+ }++ fn pointer_interaction_value(&self, pointer_id: i32) -> Option<u64> {+ self.pointer_interaction_value_map+ .borrow()+ .iter()+ .find(|(key, _)| *key == pointer_id)+ .map(|(_, value)| *value)+ }++ fn set_pointer_interaction_value(&self, pointer_id: i32, value: u64) {+ let mut pointer_map = self.pointer_interaction_value_map.borrow_mut();+ match pointer_map.iter_mut().find(|(key, _)| *key == pointer_id) {+ Some(entry) => entry.1 = value,+ None => pointer_map.push((pointer_id, value)),+ }+ }++ fn remove_pointer_interaction_value(&self, pointer_id: i32) {+ self.pointer_interaction_value_map+ .borrow_mut()+ .retain(|(key, _)| *key != pointer_id);+ }+}++// https://w3c.github.io/event-timing/#increase-interaction-count+fn increase_interaction_count(state: &WindowEventTimingState) {+ // 1. Increase window's user interaction value value by a small number chosen by the user agent.+ state.user_interaction_value.set(state.user_interaction_value.get() + 7);++ // 2. Let interactionCount be window's interactionCount.+ // 3. Set interactionCount to interactionCount + 1.+ state.interaction_count.set(state.interaction_count.get() + 1);+}++// https://w3c.github.io/event-timing/#compute-interactionid+fn compute_interaction_id(vm: &Vm, event: &CppEvent, window: &CppWindow) -> u64 {+ // 1. If event's isTrusted attribute value is false, return 0.+ if !event.is_trusted() {+ return 0;+ }++ // 2. Let type be event's type attribute value.+ let r#type = event.r#type();+ // 3. If type is not one among keyup, compositionstart, input, pointercancel, pointerup, click, or contextmenu,+ // return 0.+ if ![+ "keyup",+ "compositionstart",+ "input",+ "pointercancel",+ "pointerup",+ "click",+ "contextmenu",+ ]+ .iter()+ .any(|event_type| r#type == Utf16String::from_utf8(event_type))+ {+ return 0;+ }++ // 4. Let window be event's relevant global object.+ // NB: The window is passed in by the caller.+ let state = window.event_timing_state(vm);++ // 5. Let pendingKeyDowns be window's pending key downs.+ // 6. Let pointerMap be window's pointer interaction value map.+ // 7. Let pendingPointerDowns be window's pending pointer downs.++ // 8. If type is keyup:+ if r#type == Utf16String::from_utf8("keyup") {+ let Some(keyboard_event) = CppKeyboardEvent::from_event(event) else {+ return 0;+ };++ // 1. If event's isComposing attribute value is true, return 0.+ if keyboard_event.is_composing() {+ return 0;+ }++ // 2. Let code be event's keyCode attribute value.+ let code = keyboard_event.key_code();++ // 3. If pendingKeyDowns[code] does not exist, return 0.+ // 4. Let entry be pendingKeyDowns[code].+ // 9. Remove pendingKeyDowns[code].+ let Some(entry) = state.take_pending_key_down(vm, code) else {+ return 0;+ };++ // 5. Increase interaction count on window.+ increase_interaction_count(&state);++ // 6. Let interactionId be window's user interaction value value.+ let interaction_id = state.user_interaction_value.get();++ // 7. Set entry's interactionId to interactionId.+ entry.set_interaction_id(interaction_id);++ // 8. Add entry to window's entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(entry);++ // 10. Return interactionId.+ return interaction_id;+ }++ // 9. If type is compositionstart:+ if r#type == Utf16String::from_utf8("compositionstart") {+ // 1. For each entry in the values of pendingKeyDowns:+ // 2. Clear pendingKeyDowns.+ let mut pending_key_downs = state.pending_key_downs.borrow_mut(vm);+ for (_, entry) in pending_key_downs.drain(..) {+ // 1. Append entry to window's entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(entry);+ }++ // 3. Return 0.+ return 0;+ }++ // 10. If type is input:+ if r#type == Utf16String::from_utf8("input") {+ // 1. If event is not an instance of InputEvent, return 0.+ // NOTE: This check is done to exclude Events for which the type is input but that are not about modified text+ // content.+ let Some(input_event) = CppInputEvent::from_event(event) else {+ return 0;+ };++ // 2. If event's isComposing attribute value is false, return 0.+ if !input_event.is_composing() {+ return 0;+ }++ // 3. Increase interaction count on window.+ increase_interaction_count(&state);++ // 4. Return window's user interaction value.+ return state.user_interaction_value.get();+ }++ // 11. Otherwise (type is pointercancel, pointerup, click, or contextmenu):+ // 1. Let pointerId be event's pointerId attribute value.+ // AD-HOC: We dispatch click and contextmenu events as MouseEvents rather than PointerEvents, so they have no+ // pointerId. They come from the mouse, so they use the pointerId of the mouse instead.+ let pointer_id = if let Some(pointer_event) = CppPointerEvent::from_event(event) {+ pointer_event.pointer_id()+ } else if is_mouse_event(event) {+ MOUSE_POINTER_ID+ } else {+ return 0;+ };++ // 2. If type is click:+ if r#type == Utf16String::from_utf8("click") {+ // 1. If pointerMap[pointerId] does not exist, return 0.+ // 2. Let value be pointerMap[pointerId].+ let Some(value) = state.pointer_interaction_value(pointer_id) else {+ return 0;+ };++ // 3. Remove pointerMap[pointerId].+ state.remove_pointer_interaction_value(pointer_id);++ // 4. Return value.+ return value;+ }++ // 3. Assert that type is pointerup, pointercancel, or contextmenu.+ assert!(+ r#type == Utf16String::from_utf8("pointerup")+ || r#type == Utf16String::from_utf8("pointercancel")+ || r#type == Utf16String::from_utf8("contextmenu")+ );++ // 4. If pendingPointerDowns[pointerId] does not exist:+ // 5. Let pointerDownEntry be pendingPointerDowns[pointerId].+ // 6. Assert that pointerDownEntry is a PerformanceEventTiming entry.+ // 9. Remove pendingPointerDowns[pointerId].+ let Some(pointer_down_entry) = state.take_pending_pointer_down(vm, pointer_id) else {+ // 1. If type is contextmenu, return window's user interaction value.+ if r#type == Utf16String::from_utf8("contextmenu") {+ return state.user_interaction_value.get();+ }++ // 2. If type is pointerup and window's is contextmenu triggered flag is true:+ if r#type == Utf16String::from_utf8("pointerup") && state.is_contextmenu_triggered.get() {+ // 1. Set window's is contextmenu triggered flag to false.+ state.is_contextmenu_triggered.set(false);++ // 2. Return window's user interaction value.+ return state.user_interaction_value.get();+ }++ // 3. Otherwise, return 0.+ return 0;+ };++ // 7. If type is pointerup or contextmenu:+ if r#type == Utf16String::from_utf8("pointerup") || r#type == Utf16String::from_utf8("contextmenu") {+ // 1. Increase interaction count on window.+ increase_interaction_count(&state);++ // 2. Set pointerMap[pointerId] to window's user interaction value.+ state.set_pointer_interaction_value(pointer_id, state.user_interaction_value.get());++ // 3. Set pointerDownEntry's interactionId to pointerMap[pointerId].+ pointer_down_entry.set_interaction_id(state.user_interaction_value.get());+ }++ // 8. Append pointerDownEntry to window’s entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(pointer_down_entry);++ // 10. If type is contextmenu, set window's is contextmenu triggered to true.+ if r#type == Utf16String::from_utf8("contextmenu") {+ state.is_contextmenu_triggered.set(true);+ }++ // 11. If type is pointercancel, return 0.+ if r#type == Utf16String::from_utf8("pointercancel") {+ return 0;+ }++ // 12. Return pointerMap[pointerId].+ state.pointer_interaction_value(pointer_id).unwrap_or(0)+}++// https://w3c.github.io/event-timing/#initialize-event-timing+fn initialize_event_timing(+ vm: &Vm,+ event: &CppEvent,+ processing_start: f64,+ interaction_id: u64,+) -> Ref<PerformanceEventTiming> {+ // 1. If the algorithm to determine if event should be considered for Event Timing returns false, then return null.+ // NB: The caller only initializes event timing for an event that is considered for Event Timing.++ // 2. Let timingEntry be a new PerformanceEventTiming object with event's relevant realm.+ // 3. Set timingEntry's name to event's type attribute value.+ // 4. Set timingEntry's entryType to "event".+ // 5. Set timingEntry's startTime to event's timeStamp attribute value.+ // 6. Set timingEntry's processingStart to processingStart.+ // 7. Set timingEntry's cancelable to event's cancelable attribute value.+ // 8. Set timingEntry's interactionId to interactionId.+ // 9. Return timingEntry.+ PerformanceEventTiming::create(+ vm,+ event.r#type(),+ event.time_stamp(),+ processing_start,+ event.cancelable(),+ interaction_id,+ )+}++// https://w3c.github.io/event-timing/#finalize-event-timing+fn finalize_event_timing(+ vm: &Vm,+ timing_entry: Ref<PerformanceEventTiming>,+ event: &CppEvent,+ relevant_global: &CppWindow,+ target_node: Option<CppCell>,+ target_selector: Utf16String,+ processing_end: f64,+) {+ // 1. If timingEntry is null, then return.+ // 2. Let relevantGlobal be target's relevant global object.+ // 3. If relevantGlobal does not implement Window, return.+ // NB: The caller has done these steps.+ let state = relevant_global.event_timing_state(vm);++ // 4. Set timingEntry's processingEnd to processingEnd.+ timing_entry.set_processing_end(processing_end);++ // 5. Assert that target implements Node.+ // NOTE: This assertion holds due to the types of events supported by the Event Timing API.+ // NB: Events of these types can also be dispatched at the Window or the Document, which have no element to time.++ // 6. Set timingEntry's eventTarget to target.+ // NOTE: This will set eventTarget to the last event target. So if retargeting occurs, the last target, closest to+ // the root, will be used.+ timing_entry.set_event_target(vm, target_node);++ // 7. Set timingEntry's targetSelector to the result of running the algorithm to generate a CSS selector with+ // target as input.+ timing_entry.set_target_selector(target_selector);++ // 8. If event's type attribute value is pointerdown:+ let r#type = event.r#type();+ if r#type == Utf16String::from_utf8("pointerdown") {+ // 1. Let pendingPointerDowns be relevantGlobal's pending pointer downs.+ // 2. Let pointerId be event's pointerId.+ let pointer_id = CppPointerEvent::from_event(event).map_or(0, |pointer_event| pointer_event.pointer_id());++ // 3. If pendingPointerDowns[pointerId] exists:+ if let Some(previous_pointer_down_entry) = state.pending_pointer_down(pointer_id) {+ // 1. Let previousPointerDownEntry be pendingPointerDowns[pointerId].+ // 2. Add previousPointerDownEntry to relevantGlobal's entries to be queued.+ state+ .entries_to_be_queued+ .borrow_mut(vm)+ .push(previous_pointer_down_entry);+ }++ // 4. Set pendingPointerDowns[pointerId] to timingEntry.+ state.set_pending_pointer_down(vm, pointer_id, timing_entry);++ // 5. Set relevantGlobal's is contextmenu triggered to false.+ state.is_contextmenu_triggered.set(false);+ }+ // 9. Otherwise, if event's type attribute value is keydown:+ else if let Some(keyboard_event) = CppKeyboardEvent::from_event(event)+ && r#type == Utf16String::from_utf8("keydown")+ {+ // 1. If event's isComposing attribute value is true:+ if keyboard_event.is_composing() {+ // 1. Append timingEntry to relevantGlobal's entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(timing_entry);++ // 2. Return.+ return;+ }++ // 2. Let pendingKeyDowns be relevantGlobal's pending key downs.+ // 3. Let code be event's keyCode attribute value.+ let code = keyboard_event.key_code();++ // 4. If pendingKeyDowns[code] exists:+ if let Some(previous_key_down_entry) = state.pending_key_down(code) {+ // 1. Let previousKeyDownEntry be pendingKeyDowns[code].+ // 2. If code is not 229:+ if code != 229 {+ // 1. Increase relevantGlobal's user interaction value value by a small number chosen by the user+ // agent.+ state.user_interaction_value.set(state.user_interaction_value.get() + 7);++ // 2. Set previousKeyDownEntry's interactionId to relevantGlobal's user interaction value.+ previous_key_down_entry.set_interaction_id(state.user_interaction_value.get());+ }+ // NOTE: 229 is a special case since it corresponds to IME keyboard events. Sometimes multiple of these+ // are sent by the user agent, and they do not correspond to holding a key down repeatedly.++ // 3. Add previousKeyDownEntry to relevantGlobal's entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(previous_key_down_entry);+ }++ // 5. Set pendingKeyDowns[code] to timingEntry.+ state.set_pending_key_down(vm, code, timing_entry);+ }+ // 10. Otherwise:+ else {+ // 1. Append timingEntry to relevantGlobal's entries to be queued.+ state.entries_to_be_queued.borrow_mut(vm).push(timing_entry);+ }++ // AD-HOC: The duration of the entry is set by the next rendering update, which is asked for here in case nothing+ // else asks for one.+ // SAFETY: The Window is live.+ unsafe { web_event_timing_request_frame(relevant_global.as_ptr()) };+}++// https://w3c.github.io/event-timing/#set-event-timing-entry-duration+fn set_event_timing_entry_duration(+ vm: &Vm,+ timing_entry: Ref<PerformanceEventTiming>,+ window: &CppWindow,+ rendering_timestamp: f64,+) {+ let state = window.event_timing_state(vm);++ // 1. If timingEntry's duration attribute value is nonzero, return.+ // AD-HOC: A duration that rounds to zero is a duration that has been set all the same. Otherwise, a pending+ // pointerdown or keydown entry would be given a duration again by every later rendering update until its+ // duration rounds to a nonzero value, and its event would be counted in eventCounts each time.+ if timing_entry.has_duration() {+ return;+ }++ let entry = AnyPerformanceEntry::PerformanceEventTiming(timing_entry);++ // 2. Let start be timingEntry's startTime attribute value.+ let start = entry.start_time();++ // 3. Set timingEntry's duration to a DOMHighResTimeStamp resulting from renderingTimestamp - start, with+ // granularity of 8ms or less.+ timing_entry.set_duration(((rendering_timestamp - start) / 8.0).round() * 8.0);++ // 4. Let name be timingEntry's name attribute value.+ let name = entry.name();++ // 5. Perform the following steps to update the event counts:+ // 1. Let eventCounts be window's eventCounts.+ // 2. Assert that eventCounts contains name.+ // 3. Set eventCounts[name] to eventCounts[name] + 1.+ state.event_counts(vm).increment(&name);++ // 6. If window's has dispatched input event is false, and timingEntry's interactionId is not 0, run the following+ // steps:+ if !state.has_dispatched_input_event.get() && timing_entry.interaction_id.get() != 0 {+ // 1. Let firstInputEntry be a copy of timingEntry.+ // 2. Set firstInputEntry's entryType to "first-input".+ let first_input_entry = AnyPerformanceEntry::PerformanceEventTiming(+ timing_entry.copy_with_entry_type(vm, Utf16String::from_utf8("first-input")),+ );++ // 3. Queue firstInputEntry.+ let timeline = PerformanceTimeline::of(vm, window.realm());+ timeline.queue_performance_entry(vm, &first_input_entry);+ timeline.add_performance_entry(vm, &first_input_entry, true);++ // 4. Set window's has dispatched input event to true.+ state.has_dispatched_input_event.set(true);+ }+}++fn has_pending_event_timing_entries(vm: &Vm, window: &CppWindow) -> bool {+ let state = window.event_timing_state(vm);+ if !state.entries_to_be_queued.borrow().is_empty() {+ return true;+ }+ state+ .pending_pointer_downs+ .borrow()+ .iter()+ .any(|(_, entry)| !entry.has_duration())+ || state+ .pending_key_downs+ .borrow()+ .iter()+ .any(|(_, entry)| !entry.has_duration())+}++// https://w3c.github.io/event-timing/#dispatch-pending-event-timing-entries+fn dispatch_pending_event_timing_entries(vm: &Vm, window: &CppWindow) {+ // 1. Let window be doc's relevant global object.+ let state = window.event_timing_state(vm);++ // OPTIMIZATION: There is nothing to do while no event has been timed.+ if state.entries_to_be_queued.borrow().is_empty()+ && state.pending_pointer_downs.borrow().is_empty()+ && state.pending_key_downs.borrow().is_empty()+ {+ return;+ }++ // 2. Let renderingTimestamp be the current high resolution time.+ // SAFETY: The Window's global object is live.+ let rendering_timestamp = unsafe {+ web_high_resolution_time_current_high_resolution_time(window.realm().global_object().as_ptr().cast())+ };++ // 3. For each timingEntry in window's entries to be queued:+ // 4. Set window's entries to be queued to an empty list.+ let entries_to_be_queued = MarkedVec::new(vm);+ entries_to_be_queued.extend_from_slice(&state.entries_to_be_queued.borrow());+ state.entries_to_be_queued.borrow_mut(vm).clear();+ let timeline = PerformanceTimeline::of(vm, window.realm());+ for timing_entry in entries_to_be_queued.values().iter().copied() {+ // 1. Set event timing entry duration passing timingEntry, window, and renderingTimestamp.+ set_event_timing_entry_duration(vm, timing_entry, window, rendering_timestamp);++ // 2. If timingEntry's duration attribute value is greater than or equal to 16, then queue timingEntry.+ let entry = AnyPerformanceEntry::PerformanceEventTiming(timing_entry);+ if entry.duration() >= 16.0 {+ timeline.queue_performance_entry(vm, &entry);+ timeline.add_performance_entry(vm, &entry, true);+ }+ }++ // 5. For each pendingPointerDownEntry in the values from window's pending pointer downs:+ let pending_pointer_downs = MarkedVec::new(vm);+ for (_, entry) in state.pending_pointer_downs.borrow().iter() {+ pending_pointer_downs.push(*entry);+ }+ for pending_pointer_down_entry in pending_pointer_downs.values().iter().copied() {+ // 1. Set event timing entry duration passing pendingPointerDownEntry, window, and renderingTimestamp.+ set_event_timing_entry_duration(vm, pending_pointer_down_entry, window, rendering_timestamp);+ }++ // 6. For each pendingKeyDownEntry in the values from window's pending key downs:+ let pending_key_downs = MarkedVec::new(vm);+ for (_, entry) in state.pending_key_downs.borrow().iter() {+ pending_key_downs.push(*entry);+ }+ for pending_key_down_entry in pending_key_downs.values().iter().copied() {+ // 1. Set event timing entry duration passing pendingKeyDownEntry, window, and renderingTimestamp.+ set_event_timing_entry_duration(vm, pending_key_down_entry, window, rendering_timestamp);+ }+}++/// https://w3c.github.io/event-timing/#compute-interactionid+///+/// # Safety+///+/// `vm` must be the live VM, `window` a live Window, and `event` a live Event.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_compute_interaction_id(+ vm: *mut c_void,+ window: *mut c_void,+ event: *mut c_void,+) -> u64 {+ // SAFETY: The caller passes the live VM, a live Window and a live Event.+ let (vm, window, event) = unsafe {+ (+ &*vm.cast::<Vm>(),+ CppWindow::from_raw(window),+ CppEvent::from_raw(event),+ )+ };+ compute_interaction_id(vm, &event, &window)+}++/// https://w3c.github.io/event-timing/#initialize-event-timing+///+/// # Safety+///+/// `vm` must be the live VM, and `event` a live Event.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_initialize_event_timing(+ vm: *mut c_void,+ event: *mut c_void,+ processing_start: f64,+ interaction_id: u64,+) -> *mut c_void {+ // SAFETY: The caller passes the live VM and a live Event.+ let (vm, event) = unsafe { (&*vm.cast::<Vm>(), CppEvent::from_raw(event)) };+ cell_into_abi(initialize_event_timing(vm, &event, processing_start, interaction_id))+}++/// https://w3c.github.io/event-timing/#finalize-event-timing+///+/// # Safety+///+/// `vm` must be the live VM, `timing_entry` the live cell of a PerformanceEventTiming, `relevant_global` a live Window,+/// `event` a live Event, `target_node` null or a live Node, and `target_selector` a raw+/// AK::Utf16String that C++ hands over.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_finalize_event_timing(+ vm: *mut c_void,+ timing_entry: *mut c_void,+ event: *mut c_void,+ relevant_global: *mut c_void,+ target_node: *mut c_void,+ target_selector: usize,+ processing_end: f64,+) {+ // SAFETY: The caller passes the live VM, a live entry, a live Event, a live Window and null or a live Node, and hands+ // over the selector.+ let (vm, timing_entry, event, relevant_global, target_node, target_selector) = unsafe {+ (+ &*vm.cast::<Vm>(),+ cell_from_abi::<PerformanceEventTiming>(timing_entry),+ CppEvent::from_raw(event),+ CppWindow::from_raw(relevant_global),+ (!target_node.is_null()).then(|| CppCell::from_raw(target_node)),+ Utf16String::from_raw_owned(target_selector),+ )+ };+ finalize_event_timing(+ vm,+ timing_entry,+ &event,+ &relevant_global,+ target_node,+ target_selector,+ processing_end,+ );+}++/// # Safety+///+/// `vm` must be the live VM, and `window` a live Window.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_has_pending_event_timing_entries(+ vm: *mut c_void,+ window: *mut c_void,+) -> bool {+ // SAFETY: The caller passes the live VM and a live Window.+ let (vm, window) = unsafe { (&*vm.cast::<Vm>(), CppWindow::from_raw(window)) };+ has_pending_event_timing_entries(vm, &window)+}++/// https://w3c.github.io/event-timing/#dispatch-pending-event-timing-entries+///+/// # Safety+///+/// `vm` must be the live VM, and `window` a live Window.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_dispatch_pending_event_timing_entries(+ vm: *mut c_void,+ window: *mut c_void,+) {+ // SAFETY: The caller passes the live VM and a live Window.+ let (vm, window) = unsafe { (&*vm.cast::<Vm>(), CppWindow::from_raw(window)) };+ dispatch_pending_event_timing_entries(vm, &window);+}++/// https://w3c.github.io/event-timing/#sec-modifications-HTML+///+/// # Safety+///+/// `vm` must be the live VM, and `window` a live Window.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_event_timing_has_dispatched_input_event(+ vm: *mut c_void,+ window: *mut c_void,+) -> bool {+ // SAFETY: The caller passes the live VM and a live Window.+ let (vm, window) = unsafe { (&*vm.cast::<Vm>(), CppWindow::from_raw(window)) };+ window.event_timing_state(vm).has_dispatched_input_event()+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rsindex 9bce3ad2f22..571b23da75c 100644--- a/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/mod.rs@@ -7,4 +7,9 @@//! Event Timing, https://w3c.github.io/event-timing/pub(crate) mod event_counts;+#[allow(+ clippy::module_inception,+ reason = "the module mirrors EventTiming/EventTiming.cpp, which the crate module is named after"+)]+pub(crate) mod event_timing;pub(crate) mod performance_event_timing;diff --git a/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs b/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rsindex 2b63a8e0fdf..84c33746c42 100644--- a/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/event_timing/performance_event_timing.rs@@ -8,14 +8,13 @@//! PerformanceEventTiming, https://w3c.github.io/event-timing/#sec-performance-event-timinguse core::cell::{Cell, RefCell};-use core::ffi::c_void;-use ak::{Utf16FlyString, Utf16String};+use ak::Utf16String;use libjs_rust::api::{GcRefCell, Trace, Vm};use crate::bindings::conversions::CppInterface;use crate::bindings::cpp_cell::CppCell;-use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};+use crate::bindings::interface::{Inherits, Ref, Wrappable, allocate};use crate::bindings::{CallContext, WebIdlResult};use crate::css::css_rule::wrap_cpp_cell;use crate::paint_timing::paint_timing::is_exposed_for_paint_timing;@@ -36,7 +35,7 @@ pub(crate) struct PerformanceEventTiming {event_target: GcRefCell<Option<CppCell>>,#[gc(untraced)]target_selector: RefCell<Utf16String>,- interaction_id: Cell<u64>,+ pub(crate) interaction_id: Cell<u64>,}impl Wrappable for PerformanceEventTiming {}@@ -155,132 +154,29 @@ impl PerformanceEventTiming {// 5. Otherwise, return false.entry.duration() >= min_duration}-}--/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-unsafe fn entry_from_abi(entry: *mut c_void) -> Ref<PerformanceEventTiming> {- // SAFETY: The caller passes the live cell of a PerformanceEventTiming.- unsafe { cell_from_abi(entry) }-}--/// https://w3c.github.io/event-timing/#initialize-event-timing-///-/// # Safety-///-/// `vm` must be the live VM, and `name` a raw AK::Utf16String that C++ hands over.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_create_performance_event_timing(- vm: *mut c_void,- name: usize,- start_time: f64,- processing_start: f64,- cancelable: bool,- interaction_id: u64,-) -> *mut c_void {- // SAFETY: The caller passes the live VM and hands over the string.- let (vm, name) = unsafe { (&*vm.cast::<Vm>(), Utf16String::from_raw_owned(name)) };- let entry = PerformanceEventTiming::create(vm, name, start_time, processing_start, cancelable, interaction_id);- cell_into_abi(entry)-}--/// # Safety-///-/// `vm` must be the live VM, `entry` the live cell of a PerformanceEventTiming, and `entry_type` a raw-/// AK::Utf16FlyString that C++ lends for the call.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_copy_with_entry_type(- vm: *mut c_void,- entry: *mut c_void,- entry_type: usize,-) -> *mut c_void {- // SAFETY: The caller passes the live VM and a live entry, and lends the fly string.- let (vm, entry, entry_type) = unsafe {- (- &*vm.cast::<Vm>(),- entry_from_abi(entry),- Utf16String::from(Utf16FlyString::from_raw_borrowed(entry_type)),- )- };- let copy = entry.copy_with_entry_type(vm, entry_type);- cell_into_abi(copy)-}--/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_has_duration(entry: *mut c_void) -> bool {- // SAFETY: The caller passes a live entry.- unsafe { entry_from_abi(entry) }.has_duration.get()-}-/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_set_duration(entry: *mut c_void, duration: f64) {- // SAFETY: The caller passes a live entry.- let entry = unsafe { entry_from_abi(entry) };- entry.entry.set_duration(duration);- entry.has_duration.set(true);-}+ pub(crate) fn has_duration(&self) -> bool {+ self.has_duration.get()+ }-/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_set_processing_end(entry: *mut c_void, processing_end: f64) {- // SAFETY: The caller passes a live entry.- unsafe { entry_from_abi(entry) }.processing_end.set(processing_end);-}+ pub(crate) fn set_duration(&self, duration: f64) {+ self.entry.set_duration(duration);+ self.has_duration.set(true);+ }-/// # Safety-///-/// `vm` must be the live VM, `entry` the live cell of a PerformanceEventTiming, and `event_target` null or a live Node.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_set_event_target(- vm: *mut c_void,- entry: *mut c_void,- event_target: *mut c_void,-) {- // SAFETY: The caller passes the live VM, a live entry, and null or a live Node.- let (vm, entry, event_target) = unsafe {- (- &*vm.cast::<Vm>(),- entry_from_abi(entry),- (!event_target.is_null()).then(|| CppCell::from_raw(event_target)),- )- };- *entry.event_target.borrow_mut(vm) = event_target;-}+ pub(crate) fn set_processing_end(&self, processing_end: f64) {+ self.processing_end.set(processing_end);+ }-/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming, and `target_selector` a raw AK::Utf16String that C++-/// hands over.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_set_target_selector(entry: *mut c_void, target_selector: usize) {- // SAFETY: The caller passes a live entry and hands over the string.- let (entry, target_selector) = unsafe { (entry_from_abi(entry), Utf16String::from_raw_owned(target_selector)) };- *entry.target_selector.borrow_mut() = target_selector;-}+ pub(crate) fn set_event_target(&self, vm: &Vm, event_target: Option<CppCell>) {+ *self.event_target.borrow_mut(vm) = event_target;+ }-/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_interaction_id(entry: *mut c_void) -> u64 {- // SAFETY: The caller passes a live entry.- unsafe { entry_from_abi(entry) }.interaction_id.get()-}+ pub(crate) fn set_target_selector(&self, target_selector: Utf16String) {+ *self.target_selector.borrow_mut() = target_selector;+ }-/// # Safety-///-/// `entry` must be the live cell of a PerformanceEventTiming.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_event_timing_set_interaction_id(entry: *mut c_void, interaction_id: u64) {- // SAFETY: The caller passes a live entry.- unsafe { entry_from_abi(entry) }.interaction_id.set(interaction_id);+ pub(crate) fn set_interaction_id(&self, interaction_id: u64) {+ self.interaction_id.set(interaction_id);+ }}diff --git a/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs b/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rsindex 8cbd6616278..39a797696b5 100644--- a/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/high_resolution_time/performance.rs@@ -33,7 +33,6 @@ use crate::user_timing::performance_measure::{DOMStringOrDouble, PerformanceMeasunsafe extern "C" {fn web_high_resolution_time_current_high_resolution_time(global_object: *mut c_void) -> f64;fn web_high_resolution_time_get_time_origin_timestamp(global_object: *mut c_void) -> f64;- fn web_event_timing_interaction_count(window: *mut c_void) -> u64;}pub(crate) enum DOMStringOrPerformanceMeasureOptions {@@ -121,15 +120,14 @@ impl Performance {pub(crate) fn event_counts(&self, cx: &mut CallContext) -> WebIdlResult<Ref<EventCounts>> {// The eventCounts attribute's getter returns this's relevant global object's eventCounts.let window = self.window().expect("only a Window has eventCounts");- Ok(window.event_counts(cx.vm()))+ Ok(window.event_timing_state(cx.vm()).event_counts(cx.vm()))}// https://w3c.github.io/event-timing/#dom-performance-interactioncount- pub(crate) fn interaction_count(&self, _: &mut CallContext) -> WebIdlResult<u64> {+ pub(crate) fn interaction_count(&self, cx: &mut CallContext) -> WebIdlResult<u64> {// The interactionCount attribute's getter returns this's relevant global object's interactionCount.let window = self.window().expect("only a Window has an interactionCount");- // SAFETY: The Window is live.- Ok(unsafe { web_event_timing_interaction_count(window.as_ptr()) })+ Ok(window.event_timing_state(cx.vm()).interaction_count())}// https://w3c.github.io/hr-time/#timeorigin-attributediff --git a/Libraries/LibWeb/Bindings/Rust/src/lib.rs b/Libraries/LibWeb/Bindings/Rust/src/lib.rsindex d95779f70c5..a9f80b528ef 100644--- a/Libraries/LibWeb/Bindings/Rust/src/lib.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/lib.rs@@ -244,6 +244,8 @@ pub(crate) mod storage_api;reason = "the bindings call every attribute and operation as one that can throw")]pub(crate) mod streams;+#[cfg(not(test))]+pub(crate) mod ui_events;#[cfg_attr(not(web_idl_bindings),allow(dead_code, reason = "only the generated bindings use the interfaces")diff --git a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rsindex 66d58b81a7c..27102f4dc98 100644--- a/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/performance_timeline/performance_entry.rs@@ -263,36 +263,3 @@ pub(crate) fn filter_buffer_by_name_and_type<'vm>(// 4. Return result.result}--/// https://w3c.github.io/performance-timeline/#dom-performanceentry-name-///-/// # Safety-///-/// `entry` must be the live cell of an object of an interface that inherits from PerformanceEntry.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_performance_entry_name(entry: *mut c_void) -> usize {- // SAFETY: The caller passes a live entry.- unsafe { AnyPerformanceEntry::from_abi(entry) }.name().into_raw()-}--/// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime-///-/// # Safety-///-/// As for web_rust_performance_entry_name().-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_performance_entry_start_time(entry: *mut c_void) -> f64 {- // SAFETY: The caller passes a live entry.- unsafe { AnyPerformanceEntry::from_abi(entry) }.start_time()-}--/// https://w3c.github.io/performance-timeline/#dom-performanceentry-duration-///-/// # Safety-///-/// As for web_rust_performance_entry_name().-#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_rust_performance_entry_duration(entry: *mut c_void) -> f64 {- // SAFETY: The caller passes a live entry.- unsafe { AnyPerformanceEntry::from_abi(entry) }.duration()-}diff --git a/Libraries/LibWeb/Bindings/Rust/src/ui_events/input_event.rs b/Libraries/LibWeb/Bindings/Rust/src/ui_events/input_event.rsnew file mode 100644index 00000000000..70418ac1658--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/ui_events/input_event.rs@@ -0,0 +1,37 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use libjs_rust::api::Trace;++use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;++unsafe extern "C" {+ fn web_ui_events_input_event_from_event(event: *mut c_void) -> *mut c_void;+ fn web_ui_events_input_event_is_composing(event: *mut c_void) -> bool;+}++/// https://w3c.github.io/uievents/#inputevent+#[derive(Clone, Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct CppInputEvent(CppCell);++impl CppInputEvent {+ pub(crate) fn from_event(event: &CppEvent) -> Option<Self> {+ // SAFETY: The event is live, and LibWeb returns it if it is an InputEvent.+ let event = unsafe { web_ui_events_input_event_from_event(event.as_ptr()) };+ // SAFETY: The InputEvent is live.+ (!event.is_null()).then(|| Self(unsafe { CppCell::from_raw(event) }))+ }++ /// https://w3c.github.io/uievents/#dom-inputevent-iscomposing+ pub(crate) fn is_composing(&self) -> bool {+ // SAFETY: The InputEvent is live.+ unsafe { web_ui_events_input_event_is_composing(self.0.as_ptr()) }+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/ui_events/keyboard_event.rs b/Libraries/LibWeb/Bindings/Rust/src/ui_events/keyboard_event.rsnew file mode 100644index 00000000000..774de3b89af--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/ui_events/keyboard_event.rs@@ -0,0 +1,44 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use libjs_rust::api::Trace;++use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;++unsafe extern "C" {+ fn web_ui_events_keyboard_event_from_event(event: *mut c_void) -> *mut c_void;+ fn web_ui_events_keyboard_event_is_composing(event: *mut c_void) -> bool;+ fn web_ui_events_keyboard_event_key_code(event: *mut c_void) -> u32;+}++/// https://w3c.github.io/uievents/#keyboardevent+#[derive(Clone, Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct CppKeyboardEvent(CppCell);++impl CppKeyboardEvent {+ pub(crate) fn from_event(event: &CppEvent) -> Option<Self> {+ // SAFETY: The event is live, and LibWeb returns it if it is a KeyboardEvent.+ let event = unsafe { web_ui_events_keyboard_event_from_event(event.as_ptr()) };+ // SAFETY: The KeyboardEvent is live.+ (!event.is_null()).then(|| Self(unsafe { CppCell::from_raw(event) }))+ }++ /// https://w3c.github.io/uievents/#dom-keyboardevent-iscomposing+ pub(crate) fn is_composing(&self) -> bool {+ // SAFETY: The KeyboardEvent is live.+ unsafe { web_ui_events_keyboard_event_is_composing(self.0.as_ptr()) }+ }++ /// https://w3c.github.io/uievents/#dom-keyboardevent-keycode+ pub(crate) fn key_code(&self) -> u32 {+ // SAFETY: The KeyboardEvent is live.+ unsafe { web_ui_events_keyboard_event_key_code(self.0.as_ptr()) }+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/ui_events/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/ui_events/mod.rsnew file mode 100644index 00000000000..4f6730cce3b--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/ui_events/mod.rs@@ -0,0 +1,12 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! UI Events, https://w3c.github.io/uievents/++pub(crate) mod input_event;+pub(crate) mod keyboard_event;+pub(crate) mod mouse_event;+pub(crate) mod pointer_event;diff --git a/Libraries/LibWeb/Bindings/Rust/src/ui_events/mouse_event.rs b/Libraries/LibWeb/Bindings/Rust/src/ui_events/mouse_event.rsnew file mode 100644index 00000000000..e88af31c9b1--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/ui_events/mouse_event.rs@@ -0,0 +1,19 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use crate::bindings::event_target::CppEvent;++unsafe extern "C" {+ fn web_ui_events_mouse_event_from_event(event: *mut c_void) -> *mut c_void;+}++/// https://w3c.github.io/uievents/#mouseevent+pub(crate) fn is_mouse_event(event: &CppEvent) -> bool {+ // SAFETY: The event is live, and LibWeb returns it if it is a MouseEvent.+ !unsafe { web_ui_events_mouse_event_from_event(event.as_ptr()) }.is_null()+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/ui_events/pointer_event.rs b/Libraries/LibWeb/Bindings/Rust/src/ui_events/pointer_event.rsnew file mode 100644index 00000000000..449e2dafa16--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/ui_events/pointer_event.rs@@ -0,0 +1,39 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use libjs_rust::api::Trace;++use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;++unsafe extern "C" {+ fn web_ui_events_pointer_event_from_event(event: *mut c_void) -> *mut c_void;+ fn web_ui_events_pointer_event_pointer_id(event: *mut c_void) -> i32;+}++pub(crate) const MOUSE_POINTER_ID: i32 = 0;++/// https://w3c.github.io/pointerevents/#pointerevent-interface+#[derive(Clone, Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct CppPointerEvent(CppCell);++impl CppPointerEvent {+ pub(crate) fn from_event(event: &CppEvent) -> Option<Self> {+ // SAFETY: The event is live, and LibWeb returns it if it is a PointerEvent.+ let event = unsafe { web_ui_events_pointer_event_from_event(event.as_ptr()) };+ // SAFETY: The PointerEvent is live.+ (!event.is_null()).then(|| Self(unsafe { CppCell::from_raw(event) }))+ }++ /// https://w3c.github.io/pointerevents/#dom-pointerevent-pointerid+ pub(crate) fn pointer_id(&self) -> i32 {+ // SAFETY: The PointerEvent is live.+ unsafe { web_ui_events_pointer_event_pointer_id(self.0.as_ptr()) }+ }+}diff --git a/Libraries/LibWeb/Bindings/RustEventTarget.cpp b/Libraries/LibWeb/Bindings/RustEventTarget.cppindex 8fd247f7531..bca0b13ba6f 100644--- a/Libraries/LibWeb/Bindings/RustEventTarget.cpp+++ b/Libraries/LibWeb/Bindings/RustEventTarget.cpp@@ -127,6 +127,10 @@ bool web_bindings_dispatch_event(DOM::EventTarget*, DOM::Event*);bool web_bindings_dispatch_event_with_legacy_output_did_listeners_throw_flag(DOM::EventTarget*, DOM::Event*);bool web_bindings_event_canceled(DOM::Event*);bool web_bindings_event_dispatched(DOM::Event*);+FlatPtr web_bindings_event_type(DOM::Event const*);+bool web_bindings_event_is_trusted(DOM::Event const*);+double web_bindings_event_time_stamp(DOM::Event const*);+bool web_bindings_event_cancelable(DOM::Event const*);void web_bindings_initialize_event(RustEvent*, FlatPtr type, bool bubbles, bool cancelable);}@@ -265,6 +269,26 @@ bool web_bindings_event_dispatched(DOM::Event* event)return event->dispatched();}+FlatPtr web_bindings_event_type(DOM::Event const* event)+{+ return event->type().raw_identity();+}++bool web_bindings_event_is_trusted(DOM::Event const* event)+{+ return event->is_trusted();+}++double web_bindings_event_time_stamp(DOM::Event const* event)+{+ return event->time_stamp();+}++bool web_bindings_event_cancelable(DOM::Event const* event)+{+ return event->cancelable();+}+void web_bindings_initialize_event(RustEvent* event, FlatPtr type, bool bubbles, bool cancelable){auto type_string = Utf16String::from_raw(type);diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex bbce0e1ab25..48902f300f4 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -291,7 +291,6 @@ set(SOURCESEncryptedMediaExtensions/MediaKeySystemAccess.cppEntriesAPI/FileSystemEntry.cppEventTiming/EventTiming.cpp- EventTiming/PerformanceEventTiming.cppFetch/Body.cppFetch/BodyInit.cppFetch/Engine/FetchBodyDeliveryGate.cpp@@ -728,7 +727,6 @@ set(SOURCESPainting/Scrolling.cppPainting/ScrollSnap.cppPainting/SvgPaintResources.cpp- PerformanceTimeline/PerformanceEntry.cppPermissionsAPI/Permissions.cppPermissionsAPI/PermissionStore.cppPermissionsAPI/PermissionStatus.cppdiff --git a/Libraries/LibWeb/EventTiming/EventTiming.cpp b/Libraries/LibWeb/EventTiming/EventTiming.cppindex cae7c61368e..dc2b02bdc65 100644--- a/Libraries/LibWeb/EventTiming/EventTiming.cpp+++ b/Libraries/LibWeb/EventTiming/EventTiming.cpp@@ -6,7 +6,6 @@#include <AK/HashTable.h>#include <AK/NeverDestroyed.h>-#include <AK/Random.h>#include <AK/Utf16StringBuilder.h>#include <LibJS/HostClassBuilder.h>#include <LibJS/Runtime/VM.h>@@ -19,44 +18,23 @@#include <LibWeb/HTML/EventNames.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Window.h>-#include <LibWeb/HighResolutionTime/TimeOrigin.h>#include <LibWeb/Page/Page.h>#include <LibWeb/UIEvents/EventNames.h>-#include <LibWeb/UIEvents/InputEvent.h>-#include <LibWeb/UIEvents/KeyboardEvent.h>-#include <LibWeb/UIEvents/MouseEvent.h>-#include <LibWeb/UIEvents/PointerEvent.h>namespace Web::EventTiming {extern "C" {-void web_rust_event_timing_increment_event_count(JSVM*, HTML::Window*, FlatPtr event_type);-+// Defined in Bindings/Rust/src/event_timing/event_timing.rs.+u64 web_rust_event_timing_compute_interaction_id(JSVM*, HTML::Window*, DOM::Event const*);+PerformanceEventTiming* web_rust_event_timing_initialize_event_timing(JSVM*, DOM::Event const*, double processing_start, u64 interaction_id);+void web_rust_event_timing_finalize_event_timing(JSVM*, PerformanceEventTiming*, DOM::Event const*, HTML::Window*, DOM::Node*, FlatPtr target_selector, double processing_end);+bool web_rust_event_timing_has_pending_event_timing_entries(JSVM*, HTML::Window*);+void web_rust_event_timing_dispatch_pending_event_timing_entries(JSVM*, HTML::Window*);+bool web_rust_event_timing_has_dispatched_input_event(JSVM*, HTML::Window*);++// Called by Bindings/Rust/src/event_timing.void web_event_timing_for_each_event_type_considered_for_event_timing(void* context, void (*callback)(void* context, FlatPtr event_type));-u64 web_event_timing_interaction_count(HTML::Window*);-}--WindowEventTimingState::WindowEventTimingState()- // NB: The user interaction value is initially set to a random integer between 100 and 10000.- : user_interaction_value(100 + get_random_uniform(9901))-{-}--void WindowEventTimingState::visit_edges(GC::Cell::Visitor& visitor)-{- visitor.visit(entries_to_be_queued);- for (auto& it : pending_key_downs)- visitor.visit(it.value);- for (auto& it : pending_pointer_downs)- visitor.visit(it.value);-}--extern "C" {--u64 web_event_timing_interaction_count(HTML::Window* window)-{- return window->event_timing_state().interaction_count;-}+void web_event_timing_request_frame(HTML::Window*);}static void for_each_event_type_considered_for_event_timing(Function<void(Utf16FlyString const&)> const& callback)@@ -123,6 +101,11 @@ void web_event_timing_for_each_event_type_considered_for_event_timing(void* contcallback(context, event_type.raw_identity());});}++void web_event_timing_request_frame(HTML::Window* window)+{+ window->associated_document().page().client().request_frame();+}}HTML::Window* relevant_window_of_event_target(DOM::EventTarget& target)@@ -160,204 +143,10 @@ bool is_considered_for_event_timing(DOM::Event const& event)return false;}-// https://w3c.github.io/event-timing/#increase-interaction-count-static void increase_interaction_count(WindowEventTimingState& state)-{- // 1. Increase window's user interaction value value by a small number chosen by the user agent.- state.user_interaction_value += 7;-- // 2. Let interactionCount be window's interactionCount.- // 3. Set interactionCount to interactionCount + 1.- ++state.interaction_count;-}-// https://w3c.github.io/event-timing/#compute-interactionidWebIDL::UnsignedLongLong compute_interaction_id(DOM::Event const& event, HTML::Window& window){- // 1. If event's isTrusted attribute value is false, return 0.- if (!event.is_trusted())- return 0;-- // 2. Let type be event's type attribute value.- auto const& type = event.type();-- // 3. If type is not one among keyup, compositionstart, input, pointercancel, pointerup, click, or contextmenu,- // return 0.- if (type != UIEvents::EventNames::keyup && type != UIEvents::EventNames::compositionstart && type != UIEvents::EventNames::input- && type != UIEvents::EventNames::pointercancel && type != UIEvents::EventNames::pointerup && type != UIEvents::EventNames::click- && type != UIEvents::EventNames::contextmenu)- return 0;-- // 4. Let window be event's relevant global object.- // NB: The window is passed in by the caller.- auto& state = window.event_timing_state();-- // 5. Let pendingKeyDowns be window's pending key downs.- auto& pending_key_downs = state.pending_key_downs;-- // 6. Let pointerMap be window's pointer interaction value map.- auto& pointer_map = state.pointer_interaction_value_map;-- // 7. Let pendingPointerDowns be window's pending pointer downs.- auto& pending_pointer_downs = state.pending_pointer_downs;-- // 8. If type is keyup:- if (type == UIEvents::EventNames::keyup) {- auto const* keyboard_event = as_if<UIEvents::KeyboardEvent>(event);- if (!keyboard_event)- return 0;-- // 1. If event's isComposing attribute value is true, return 0.- if (keyboard_event->is_composing())- return 0;-- // 2. Let code be event's keyCode attribute value.- auto code = keyboard_event->key_code();-- // 3. If pendingKeyDowns[code] does not exist, return 0.- auto pending_key_down = pending_key_downs.get(code);- if (!pending_key_down.has_value())- return 0;-- // 4. Let entry be pendingKeyDowns[code].- auto entry = pending_key_down.release_value();-- // 5. Increase interaction count on window.- increase_interaction_count(state);-- // 6. Let interactionId be window's user interaction value value.- auto interaction_id = state.user_interaction_value;-- // 7. Set entry's interactionId to interactionId.- entry->set_interaction_id(interaction_id);-- // 8. Add entry to window's entries to be queued.- state.entries_to_be_queued.append(entry);-- // 9. Remove pendingKeyDowns[code].- pending_key_downs.remove(code);-- // 10. Return interactionId.- return interaction_id;- }-- // 9. If type is compositionstart:- if (type == UIEvents::EventNames::compositionstart) {- // 1. For each entry in the values of pendingKeyDowns:- for (auto& it : pending_key_downs) {- // 1. Append entry to window's entries to be queued.- state.entries_to_be_queued.append(it.value);- }-- // 2. Clear pendingKeyDowns.- pending_key_downs.clear();-- // 3. Return 0.- return 0;- }-- // 10. If type is input:- if (type == UIEvents::EventNames::input) {- // 1. If event is not an instance of InputEvent, return 0.- // NOTE: This check is done to exclude Events for which the type is input but that are not about modified text- // content.- auto const* input_event = as_if<UIEvents::InputEvent>(event);- if (!input_event)- return 0;-- // 2. If event's isComposing attribute value is false, return 0.- if (!input_event->is_composing())- return 0;-- // 3. Increase interaction count on window.- increase_interaction_count(state);-- // 4. Return window's user interaction value.- return state.user_interaction_value;- }-- // 11. Otherwise (type is pointercancel, pointerup, click, or contextmenu):- // 1. Let pointerId be event's pointerId attribute value.- // AD-HOC: We dispatch click and contextmenu events as MouseEvents rather than PointerEvents, so they have no- // pointerId. They come from the mouse, so they use the pointerId of the mouse instead.- WebIDL::Long pointer_id = 0;- if (auto const* pointer_event = as_if<UIEvents::PointerEvent>(event))- pointer_id = pointer_event->pointer_id();- else if (is<UIEvents::MouseEvent>(event))- pointer_id = UIEvents::mouse_pointer_id;- else- return 0;-- // 2. If type is click:- if (type == UIEvents::EventNames::click) {- // 1. If pointerMap[pointerId] does not exist, return 0.- auto value = pointer_map.get(pointer_id);- if (!value.has_value())- return 0;-- // 2. Let value be pointerMap[pointerId].- // 3. Remove pointerMap[pointerId].- pointer_map.remove(pointer_id);-- // 4. Return value.- return *value;- }-- // 3. Assert that type is pointerup, pointercancel, or contextmenu.- VERIFY(type == UIEvents::EventNames::pointerup || type == UIEvents::EventNames::pointercancel || type == UIEvents::EventNames::contextmenu);-- // 4. If pendingPointerDowns[pointerId] does not exist:- auto pending_pointer_down = pending_pointer_downs.get(pointer_id);- if (!pending_pointer_down.has_value()) {- // 1. If type is contextmenu, return window's user interaction value.- if (type == UIEvents::EventNames::contextmenu)- return state.user_interaction_value;-- // 2. If type is pointerup and window's is contextmenu triggered flag is true:- if (type == UIEvents::EventNames::pointerup && state.is_contextmenu_triggered) {- // 1. Set window's is contextmenu triggered flag to false.- state.is_contextmenu_triggered = false;-- // 2. Return window's user interaction value.- return state.user_interaction_value;- }-- // 3. Otherwise, return 0.- return 0;- }-- // 5. Let pointerDownEntry be pendingPointerDowns[pointerId].- // 6. Assert that pointerDownEntry is a PerformanceEventTiming entry.- auto pointer_down_entry = pending_pointer_down.release_value();-- // 7. If type is pointerup or contextmenu:- if (type == UIEvents::EventNames::pointerup || type == UIEvents::EventNames::contextmenu) {- // 1. Increase interaction count on window.- increase_interaction_count(state);-- // 2. Set pointerMap[pointerId] to window's user interaction value.- pointer_map.set(pointer_id, state.user_interaction_value);-- // 3. Set pointerDownEntry's interactionId to pointerMap[pointerId].- pointer_down_entry->set_interaction_id(state.user_interaction_value);- }-- // 8. Append pointerDownEntry to window’s entries to be queued.- state.entries_to_be_queued.append(pointer_down_entry);-- // 9. Remove pendingPointerDowns[pointerId].- pending_pointer_downs.remove(pointer_id);-- // 10. If type is contextmenu, set window's is contextmenu triggered to true.- if (type == UIEvents::EventNames::contextmenu)- state.is_contextmenu_triggered = true;-- // 11. If type is pointercancel, return 0.- if (type == UIEvents::EventNames::pointercancel)- return 0;-- // 12. Return pointerMap[pointerId].- return pointer_map.get(pointer_id).value_or(0);+ return web_rust_event_timing_compute_interaction_id(JS::HostABI::vm_to_abi(JS::VM::the()), &window, &event);}// https://w3c.github.io/event-timing/#initialize-event-timing@@ -367,15 +156,7 @@ GC::Ptr<PerformanceEventTiming> initialize_event_timing(DOM::Event const& event,if (!is_considered_for_event_timing(event))return nullptr;- // 2. Let timingEntry be a new PerformanceEventTiming object with event's relevant realm.- // 3. Set timingEntry's name to event's type attribute value.- // 4. Set timingEntry's entryType to "event".- // 5. Set timingEntry's startTime to event's timeStamp attribute value.- // 6. Set timingEntry's processingStart to processingStart.- // 7. Set timingEntry's cancelable to event's cancelable attribute value.- // 8. Set timingEntry's interactionId to interactionId.- // 9. Return timingEntry.- return PerformanceEventTiming::create(event, processing_start, interaction_id);+ return web_rust_event_timing_initialize_event_timing(JS::HostABI::vm_to_abi(JS::VM::the()), &event, processing_start, interaction_id);}// https://w3c.github.io/event-timing/#generate-a-css-selector@@ -424,139 +205,15 @@ void finalize_event_timing(GC::Ptr<PerformanceEventTiming> timing_entry, DOM::Evauto* relevant_global = relevant_window_of_event_target(target);if (!relevant_global)return;- auto& state = relevant_global->event_timing_state();-- // 4. Set timingEntry's processingEnd to processingEnd.- timing_entry->set_processing_end(processing_end);-- // 5. Assert that target implements Node.- // NOTE: This assertion holds due to the types of events supported by the Event Timing API.- // NB: Events of these types can also be dispatched at the Window or the Document, which have no element to time.- auto* target_node = as_if<DOM::Node>(target);-- // 6. Set timingEntry's eventTarget to target.- // NOTE: This will set eventTarget to the last event target. So if retargeting occurs, the last target, closest to- // the root, will be used.- timing_entry->set_event_target(target_node);-- // 7. Set timingEntry's targetSelector to the result of running the algorithm to generate a CSS selector with- // target as input.- timing_entry->set_target_selector(generate_a_css_selector(target));-- // 8. If event's type attribute value is pointerdown:- if (event.type() == UIEvents::EventNames::pointerdown) {- // 1. Let pendingPointerDowns be relevantGlobal's pending pointer downs.- auto& pending_pointer_downs = state.pending_pointer_downs;-- // 2. Let pointerId be event's pointerId.- auto const* pointer_event = as_if<UIEvents::PointerEvent>(event);- auto pointer_id = pointer_event ? pointer_event->pointer_id() : 0;-- // 3. If pendingPointerDowns[pointerId] exists:- if (auto previous_pointer_down_entry = pending_pointer_downs.get(pointer_id); previous_pointer_down_entry.has_value()) {- // 1. Let previousPointerDownEntry be pendingPointerDowns[pointerId].- // 2. Add previousPointerDownEntry to relevantGlobal's entries to be queued.- state.entries_to_be_queued.append(*previous_pointer_down_entry);- }-- // 4. Set pendingPointerDowns[pointerId] to timingEntry.- pending_pointer_downs.set(pointer_id, *timing_entry);-- // 5. Set relevantGlobal's is contextmenu triggered to false.- state.is_contextmenu_triggered = false;- }- // 9. Otherwise, if event's type attribute value is keydown:- else if (auto const* keyboard_event = as_if<UIEvents::KeyboardEvent>(event); keyboard_event && event.type() == UIEvents::EventNames::keydown) {- // 1. If event's isComposing attribute value is true:- if (keyboard_event->is_composing()) {- // 1. Append timingEntry to relevantGlobal's entries to be queued.- state.entries_to_be_queued.append(*timing_entry);-- // 2. Return.- return;- }-- // 2. Let pendingKeyDowns be relevantGlobal's pending key downs.- auto& pending_key_downs = state.pending_key_downs;-- // 3. Let code be event's keyCode attribute value.- auto code = keyboard_event->key_code();-- // 4. If pendingKeyDowns[code] exists:- if (auto previous_key_down_entry = pending_key_downs.get(code); previous_key_down_entry.has_value()) {- // 1. Let previousKeyDownEntry be pendingKeyDowns[code].- // 2. If code is not 229:- if (code != 229) {- // 1. Increase relevantGlobal's user interaction value value by a small number chosen by the user- // agent.- state.user_interaction_value += 7;-- // 2. Set previousKeyDownEntry's interactionId to relevantGlobal's user interaction value.- (*previous_key_down_entry)->set_interaction_id(state.user_interaction_value);- }- // NOTE: 229 is a special case since it corresponds to IME keyboard events. Sometimes multiple of these- // are sent by the user agent, and they do not correspond to holding a key down repeatedly.-- // 3. Add previousKeyDownEntry to relevantGlobal's entries to be queued.- state.entries_to_be_queued.append(*previous_key_down_entry);- }-- // 5. Set pendingKeyDowns[code] to timingEntry.- pending_key_downs.set(code, *timing_entry);- }- // 10. Otherwise:- else {- // 1. Append timingEntry to relevantGlobal's entries to be queued.- state.entries_to_be_queued.append(*timing_entry);- }- // AD-HOC: The duration of the entry is set by the next rendering update, which is asked for here in case nothing- // else asks for one.- relevant_global->associated_document().page().client().request_frame();-}--// https://w3c.github.io/event-timing/#set-event-timing-entry-duration-static void set_event_timing_entry_duration(PerformanceEventTiming& timing_entry, HTML::Window& window, HighResolutionTime::DOMHighResTimeStamp rendering_timestamp)-{- auto& state = window.event_timing_state();-- // 1. If timingEntry's duration attribute value is nonzero, return.- // AD-HOC: A duration that rounds to zero is a duration that has been set all the same. Otherwise, a pending- // pointerdown or keydown entry would be given a duration again by every later rendering update until its- // duration rounds to a nonzero value, and its event would be counted in eventCounts each time.- if (timing_entry.has_duration())- return;-- // 2. Let start be timingEntry's startTime attribute value.- auto start = timing_entry.start_time();-- // 3. Set timingEntry's duration to a DOMHighResTimeStamp resulting from renderingTimestamp - start, with- // granularity of 8ms or less.- timing_entry.set_duration(round((rendering_timestamp - start) / 8) * 8);-- // 4. Let name be timingEntry's name attribute value.- Utf16FlyString name { timing_entry.name() };-- // 5. Perform the following steps to update the event counts:- // 1. Let eventCounts be window's eventCounts.- // 2. Assert that eventCounts contains name.- // 3. Set eventCounts[name] to eventCounts[name] + 1.- web_rust_event_timing_increment_event_count(JS::HostABI::vm_to_abi(JS::VM::the()), &window, name.raw_identity());-- // 6. If window's has dispatched input event is false, and timingEntry's interactionId is not 0, run the following- // steps:- if (!state.has_dispatched_input_event && timing_entry.interaction_id() != 0) {- // 1. Let firstInputEntry be a copy of timingEntry.- // 2. Set firstInputEntry's entryType to "first-input".- auto first_input_entry = timing_entry.copy_with_entry_type("first-input"_utf16_fly_string);-- // 3. Queue firstInputEntry.- window.queue_performance_entry(first_input_entry);- window.add_performance_entry(first_input_entry, HTML::WindowOrWorkerGlobalScopeMixin::CheckIfPerformanceBufferIsFull::Yes);-- // 4. Set window's has dispatched input event to true.- state.has_dispatched_input_event = true;- }+ web_rust_event_timing_finalize_event_timing(+ JS::HostABI::vm_to_abi(JS::VM::the()),+ timing_entry.ptr(),+ &event,+ relevant_global,+ as_if<DOM::Node>(target),+ generate_a_css_selector(target).into_raw(),+ processing_end);}bool has_pending_event_timing_entries(DOM::Document const& document)@@ -564,11 +221,7 @@ bool has_pending_event_timing_entries(DOM::Document const& document)auto window = document.window();if (!window)return false;- auto& state = window->event_timing_state();- if (!state.entries_to_be_queued.is_empty())- return true;- auto has_no_duration = [](auto const& it) { return !it.value->has_duration(); };- return any_of(state.pending_pointer_downs, has_no_duration) || any_of(state.pending_key_downs, has_no_duration);+ return web_rust_event_timing_has_pending_event_timing_entries(JS::HostABI::vm_to_abi(JS::VM::the()), window.ptr());}// https://w3c.github.io/event-timing/#dispatch-pending-event-timing-entries@@ -576,41 +229,12 @@ void dispatch_pending_event_timing_entries(DOM::Document& document){// 1. Let window be doc's relevant global object.auto& window = HTML::relevant_window(document);- auto& state = window.event_timing_state();-- // OPTIMIZATION: There is nothing to do while no event has been timed.- if (state.entries_to_be_queued.is_empty() && state.pending_pointer_downs.is_empty() && state.pending_key_downs.is_empty())- return;-- // 2. Let renderingTimestamp be the current high resolution time.- auto rendering_timestamp = HighResolutionTime::current_high_resolution_time(HTML::relevant_global_object(window));-- // 3. For each timingEntry in window's entries to be queued:- for (auto& timing_entry : state.entries_to_be_queued) {- // 1. Set event timing entry duration passing timingEntry, window, and renderingTimestamp.- set_event_timing_entry_duration(timing_entry, window, rendering_timestamp);-- // 2. If timingEntry's duration attribute value is greater than or equal to 16, then queue timingEntry.- if (timing_entry->duration() >= 16) {- window.queue_performance_entry(timing_entry);- window.add_performance_entry(timing_entry, HTML::WindowOrWorkerGlobalScopeMixin::CheckIfPerformanceBufferIsFull::Yes);- }- }-- // 4. Set window's entries to be queued to an empty list.- state.entries_to_be_queued.clear();-- // 5. For each pendingPointerDownEntry in the values from window's pending pointer downs:- for (auto& it : state.pending_pointer_downs) {- // 1. Set event timing entry duration passing pendingPointerDownEntry, window, and renderingTimestamp.- set_event_timing_entry_duration(it.value, window, rendering_timestamp);- }+ web_rust_event_timing_dispatch_pending_event_timing_entries(JS::HostABI::vm_to_abi(JS::VM::the()), &window);+}- // 6. For each pendingKeyDownEntry in the values from window's pending key downs:- for (auto& it : state.pending_key_downs) {- // 1. Set event timing entry duration passing pendingKeyDownEntry, window, and renderingTimestamp.- set_event_timing_entry_duration(it.value, window, rendering_timestamp);- }+bool has_dispatched_input_event(HTML::Window& window)+{+ return web_rust_event_timing_has_dispatched_input_event(JS::HostABI::vm_to_abi(JS::VM::the()), &window);}}diff --git a/Libraries/LibWeb/EventTiming/EventTiming.h b/Libraries/LibWeb/EventTiming/EventTiming.hindex 06eb16cd28d..e87b1252e9a 100644--- a/Libraries/LibWeb/EventTiming/EventTiming.h+++ b/Libraries/LibWeb/EventTiming/EventTiming.h@@ -6,8 +6,6 @@#pragma once-#include <AK/HashMap.h>-#include <AK/Vector.h>#include <LibGC/Ptr.h>#include <LibWeb/Forward.h>#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>@@ -15,39 +13,6 @@namespace Web::EventTiming {-// https://w3c.github.io/event-timing/#sec-modifications-HTML-// Each Window has the following associated concepts:-struct WindowEventTimingState {- // entries to be queued, a list that stores PerformanceEventTiming objects, which will initially be empty.- Vector<GC::Ref<PerformanceEventTiming>> entries_to_be_queued;-- // has dispatched input event, a boolean which is initially set to false.- bool has_dispatched_input_event { false };-- // user interaction value, an integer which is initially set to a random integer between 100 and 10000.- u64 user_interaction_value { 0 };-- // pending key downs, a map of integers to PerformanceEventTimings which is initially empty.- HashMap<u32, GC::Ref<PerformanceEventTiming>> pending_key_downs;-- // pointer interaction value map, a map of integers which is initially empty.- HashMap<WebIDL::Long, u64> pointer_interaction_value_map;-- // pending pointer downs, a map of integers to PerformanceEventTimings which is initially empty.- HashMap<WebIDL::Long, GC::Ref<PerformanceEventTiming>> pending_pointer_downs;-- // is contextmenu triggered, a boolean which is initially set to false.- bool is_contextmenu_triggered { false };-- // interactionCount, an integer which counts the total number of distinct user interactions, for which there was a- // unique interactionId computed via computing interactionId.- u64 interaction_count { 0 };-- WindowEventTimingState();-- void visit_edges(GC::Cell::Visitor&);-};-// NB: The relevant global object of the given event target, if it is a Window. Only nodes and windows are the targets// of events that are timed.HTML::Window* relevant_window_of_event_target(DOM::EventTarget&);@@ -71,4 +36,7 @@ void dispatch_pending_event_timing_entries(DOM::Document&);// queue, or the duration and event count of a pending pointerdown or keydown it would set.bool has_pending_event_timing_entries(DOM::Document const&);+// https://w3c.github.io/event-timing/#sec-modifications-HTML+bool has_dispatched_input_event(HTML::Window&);+}diff --git a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cppdeleted file mode 100644index 503da99cb79..00000000000--- a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp+++ /dev/null@@ -1,80 +0,0 @@-/*- * Copyright (c) 2024, Noah Bright <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibJS/HostClassBuilder.h>-#include <LibJS/Runtime/VM.h>-#include <LibWeb/DOM/Event.h>-#include <LibWeb/DOM/Node.h>-#include <LibWeb/EventTiming/PerformanceEventTiming.h>--namespace Web::EventTiming {--extern "C" {-// Defined in Bindings/Rust/src/event_timing/performance_event_timing.rs.-PerformanceEventTiming* web_rust_event_timing_create_performance_event_timing(JSVM*, FlatPtr name, double start_time, double processing_start, bool cancelable, u64 interaction_id);-PerformanceEventTiming* web_rust_event_timing_copy_with_entry_type(JSVM*, PerformanceEventTiming const*, FlatPtr entry_type);-bool web_rust_event_timing_has_duration(PerformanceEventTiming const*);-void web_rust_event_timing_set_duration(PerformanceEventTiming*, double duration);-void web_rust_event_timing_set_processing_end(PerformanceEventTiming*, double processing_end);-void web_rust_event_timing_set_event_target(JSVM*, PerformanceEventTiming*, DOM::Node*);-void web_rust_event_timing_set_target_selector(PerformanceEventTiming*, FlatPtr target_selector);-u64 web_rust_event_timing_interaction_id(PerformanceEventTiming const*);-void web_rust_event_timing_set_interaction_id(PerformanceEventTiming*, u64 interaction_id);-}--// https://w3c.github.io/event-timing/#initialize-event-timing-GC::Ref<PerformanceEventTiming> PerformanceEventTiming::create(DOM::Event const& event, HighResolutionTime::DOMHighResTimeStamp processing_start, WebIDL::UnsignedLongLong interaction_id)-{- return *web_rust_event_timing_create_performance_event_timing(- JS::HostABI::vm_to_abi(JS::VM::the()),- Utf16String::from_utf16(event.type().view()).into_raw(),- event.time_stamp(),- processing_start,- event.cancelable(),- interaction_id);-}--GC::Ref<PerformanceEventTiming> PerformanceEventTiming::copy_with_entry_type(Utf16FlyString const& entry_type) const-{- return *web_rust_event_timing_copy_with_entry_type(JS::HostABI::vm_to_abi(JS::VM::the()), this, entry_type.raw_identity());-}--bool PerformanceEventTiming::has_duration() const-{- return web_rust_event_timing_has_duration(this);-}--void PerformanceEventTiming::set_duration(HighResolutionTime::DOMHighResTimeStamp duration)-{- web_rust_event_timing_set_duration(this, duration);-}--void PerformanceEventTiming::set_processing_end(HighResolutionTime::DOMHighResTimeStamp processing_end)-{- web_rust_event_timing_set_processing_end(this, processing_end);-}--void PerformanceEventTiming::set_event_target(GC::Ptr<DOM::Node> event_target)-{- web_rust_event_timing_set_event_target(JS::HostABI::vm_to_abi(JS::VM::the()), this, event_target.ptr());-}--void PerformanceEventTiming::set_target_selector(Utf16String target_selector)-{- web_rust_event_timing_set_target_selector(this, move(target_selector).into_raw());-}--WebIDL::UnsignedLongLong PerformanceEventTiming::interaction_id() const-{- return web_rust_event_timing_interaction_id(this);-}--void PerformanceEventTiming::set_interaction_id(WebIDL::UnsignedLongLong interaction_id)-{- web_rust_event_timing_set_interaction_id(this, interaction_id);-}--}diff --git a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.hindex 25a9bd7de34..0c04e8aa2f1 100644--- a/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h+++ b/Libraries/LibWeb/EventTiming/PerformanceEventTiming.h@@ -6,31 +6,14 @@#pragma once-#include <AK/Utf16FlyString.h>#include <LibWeb/Bindings/PerformanceEventTiming.h>-#include <LibWeb/Forward.h>#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>-#include <LibWebCommon/WebIDL/Types.h>namespace Web::EventTiming {// https://w3c.github.io/event-timing/#sec-performance-event-timingclass PerformanceEventTiming final : public PerformanceTimeline::PerformanceEntry {WEB_RUST_INTERFACE(PerformanceEventTiming, performance_event_timing)--public:- static GC::Ref<PerformanceEventTiming> create(DOM::Event const&, HighResolutionTime::DOMHighResTimeStamp processing_start, WebIDL::UnsignedLongLong interaction_id);-- // A copy of this entry, with the given entry type.- GC::Ref<PerformanceEventTiming> copy_with_entry_type(Utf16FlyString const& entry_type) const;-- bool has_duration() const;- void set_duration(HighResolutionTime::DOMHighResTimeStamp);- void set_processing_end(HighResolutionTime::DOMHighResTimeStamp);- void set_event_target(GC::Ptr<DOM::Node>);- void set_target_selector(Utf16String);- WebIDL::UnsignedLongLong interaction_id() const;- void set_interaction_id(WebIDL::UnsignedLongLong);};}diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 21987c63489..6e0a6d3b283 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -567,7 +567,6 @@ class FileSystemEntry;namespace Web::EventTiming {class PerformanceEventTiming;-struct WindowEventTimingState;}diff --git a/Libraries/LibWeb/HTML/VisibilityStateEntry.h b/Libraries/LibWeb/HTML/VisibilityStateEntry.hindex 037a76a0cae..3d2c9908271 100644--- a/Libraries/LibWeb/HTML/VisibilityStateEntry.h+++ b/Libraries/LibWeb/HTML/VisibilityStateEntry.h@@ -9,6 +9,7 @@#include <LibWeb/Bindings/VisibilityStateEntry.h>#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>#include <LibWebCommon/HTML/VisibilityState.h>+#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>namespace Web::HTML {diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cppindex 1dfcad5e0bc..c566b40afc9 100644--- a/Libraries/LibWeb/HTML/Window.cpp+++ b/Libraries/LibWeb/HTML/Window.cpp@@ -386,7 +386,6 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)visitor.visit(m_statusbar);visitor.visit(m_toolbar);visitor.visit(m_external);- m_event_timing_state.visit_edges(visitor);}void Window::finalize()diff --git a/Libraries/LibWeb/HTML/Window.h b/Libraries/LibWeb/HTML/Window.hindex 551b3878975..1f3f33e3432 100644--- a/Libraries/LibWeb/HTML/Window.h+++ b/Libraries/LibWeb/HTML/Window.h@@ -21,7 +21,6 @@#include <LibWeb/Bindings/Forward.h>#include <LibWeb/Bindings/IdleRequest.h>#include <LibWeb/DOM/EventTarget.h>-#include <LibWeb/EventTiming/EventTiming.h>#include <LibWeb/Export.h>#include <LibWeb/Forward.h>#include <LibWeb/HTML/BarProp.h>@@ -318,8 +317,6 @@ public:static void for_each_active(Function<IterationDecision(Window&)> callback);- EventTiming::WindowEventTimingState& event_timing_state() { return m_event_timing_state; }-// https://w3c.github.io/largest-contentful-paint/#has-dispatched-scroll-eventbool has_dispatched_scroll_event() const { return m_has_dispatched_scroll_event; }void set_has_dispatched_scroll_event() { m_has_dispatched_scroll_event = true; }@@ -411,8 +408,6 @@ private:// https://html.spec.whatwg.org/multipage/obsolete.html#dom-externalGC::Ptr<External> m_external;- EventTiming::WindowEventTimingState m_event_timing_state;-// https://w3c.github.io/largest-contentful-paint/#has-dispatched-scroll-event// Each Window has has dispatched scroll event, a boolean which is initially set to false.bool m_has_dispatched_scroll_event { false };diff --git a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cppindex 8b7d8eae5dc..fe6484206f7 100644--- a/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp+++ b/Libraries/LibWeb/LargestContentfulPaint/LargestContentfulPaint.cpp@@ -9,6 +9,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>#include <LibWeb/DOM/Text.h>+#include <LibWeb/EventTiming/EventTiming.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Window.h>@@ -322,7 +323,7 @@ void report_largest_contentful_paint(DOM::Document& document, PaintTiming::Paintauto& window = HTML::relevant_window(document);// 2. If either of window's has dispatched scroll event or has dispatched input event is true, return.- if (window.has_dispatched_scroll_event() || window.event_timing_state().has_dispatched_input_event)+ if (window.has_dispatched_scroll_event() || EventTiming::has_dispatched_input_event(window))return;// 3. Let newCandidate be the result of computing a new largest contentful paint candidate given document,diff --git a/Libraries/LibWeb/PaintTiming/PaintTiming.cpp b/Libraries/LibWeb/PaintTiming/PaintTiming.cppindex 11219ac8e74..6f1685ae136 100644--- a/Libraries/LibWeb/PaintTiming/PaintTiming.cpp+++ b/Libraries/LibWeb/PaintTiming/PaintTiming.cpp@@ -15,6 +15,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>#include <LibWeb/DOM/Text.h>+#include <LibWeb/EventTiming/EventTiming.h>#include <LibWeb/HTML/DecodedImageData.h>#include <LibWeb/HTML/HTMLCanvasElement.h>#include <LibWeb/HTML/HTMLInputElement.h>@@ -394,7 +395,7 @@ static bool tracks_painted_images_and_text(DOM::Document& document)auto window = document.window();if (!window)return false;- return !window->has_dispatched_scroll_event() && !window->event_timing_state().has_dispatched_input_event;+ return !window->has_dispatched_scroll_event() && !EventTiming::has_dispatched_input_event(*window);}// https://w3c.github.io/paint-timing/#process-an-image-that-finished-loadingdiff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cppdeleted file mode 100644index 0b709fbffed..00000000000--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp+++ /dev/null@@ -1,33 +0,0 @@-/*- * Copyright (c) 2023, Luke Wilde <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>--namespace Web::PerformanceTimeline {--extern "C" {-// Defined in Bindings/Rust/src/performance_timeline/performance_entry.rs.-FlatPtr web_rust_performance_entry_name(PerformanceEntry const*);-double web_rust_performance_entry_start_time(PerformanceEntry const*);-double web_rust_performance_entry_duration(PerformanceEntry const*);-}--Utf16String PerformanceEntry::name() const-{- return Utf16String::adopt_raw(web_rust_performance_entry_name(this));-}--HighResolutionTime::DOMHighResTimeStamp PerformanceEntry::start_time() const-{- return web_rust_performance_entry_start_time(this);-}--HighResolutionTime::DOMHighResTimeStamp PerformanceEntry::duration() const-{- return web_rust_performance_entry_duration(this);-}--}diff --git a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.hindex 9df46943b50..cca990fe807 100644--- a/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h+++ b/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.h@@ -6,11 +6,9 @@#pragma once-#include <AK/Utf16String.h>#include <LibWeb/Bindings/PerformanceEntry.h>#include <LibWeb/Bindings/RustInterface.h>#include <LibWeb/Export.h>-#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>namespace Web::PerformanceTimeline {@@ -18,11 +16,6 @@ namespace Web::PerformanceTimeline {// The C++ side of a PerformanceEntry, which is implemented in Rust (Libraries/LibWeb/Bindings/Rust/src).class WEB_API PerformanceEntry : public Bindings::RustInterfaceCell {WEB_RUST_INTERFACE(PerformanceEntry, performance_entry)--public:- Utf16String name() const;- HighResolutionTime::DOMHighResTimeStamp start_time() const;- HighResolutionTime::DOMHighResTimeStamp duration() const;};}diff --git a/Libraries/LibWeb/UIEvents/InputEvent.cpp b/Libraries/LibWeb/UIEvents/InputEvent.cppindex ee6ca06a06b..31e130979bb 100644--- a/Libraries/LibWeb/UIEvents/InputEvent.cpp+++ b/Libraries/LibWeb/UIEvents/InputEvent.cpp@@ -92,4 +92,19 @@ ReadonlySpan<GC::Ref<DOM::StaticRange>> InputEvent::get_target_ranges() constreturn m_target_ranges;}+extern "C" {+InputEvent const* web_ui_events_input_event_from_event(DOM::Event const*);+bool web_ui_events_input_event_is_composing(InputEvent const*);++InputEvent const* web_ui_events_input_event_from_event(DOM::Event const* event)+{+ return as_if<InputEvent>(event);+}++bool web_ui_events_input_event_is_composing(InputEvent const* event)+{+ return event->is_composing();+}+}+}diff --git a/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp b/Libraries/LibWeb/UIEvents/KeyboardEvent.cppindex 0f633fb7739..13f303a7f55 100644--- a/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp+++ b/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp@@ -851,4 +851,25 @@ KeyboardEvent::KeyboardEvent(Utf16FlyString const& event_name, KeyboardEventInitKeyboardEvent::~KeyboardEvent() = default;+extern "C" {+KeyboardEvent const* web_ui_events_keyboard_event_from_event(DOM::Event const*);+bool web_ui_events_keyboard_event_is_composing(KeyboardEvent const*);+u32 web_ui_events_keyboard_event_key_code(KeyboardEvent const*);++KeyboardEvent const* web_ui_events_keyboard_event_from_event(DOM::Event const* event)+{+ return as_if<KeyboardEvent>(event);+}++bool web_ui_events_keyboard_event_is_composing(KeyboardEvent const* event)+{+ return event->is_composing();+}++u32 web_ui_events_keyboard_event_key_code(KeyboardEvent const* event)+{+ return event->key_code();+}+}+}diff --git a/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Libraries/LibWeb/UIEvents/MouseEvent.cppindex 69f42535043..b575ec62e2d 100644--- a/Libraries/LibWeb/UIEvents/MouseEvent.cpp+++ b/Libraries/LibWeb/UIEvents/MouseEvent.cpp@@ -320,4 +320,13 @@ WebIDL::ExceptionOr<GC::Ref<MouseEvent>> MouseEvent::create_from_platform_event(return event;}+extern "C" {+MouseEvent const* web_ui_events_mouse_event_from_event(DOM::Event const*);++MouseEvent const* web_ui_events_mouse_event_from_event(DOM::Event const* event)+{+ return as_if<MouseEvent>(event);+}+}+}diff --git a/Libraries/LibWeb/UIEvents/PointerEvent.cpp b/Libraries/LibWeb/UIEvents/PointerEvent.cppindex 4c351ae26a7..21aa4b405ce 100644--- a/Libraries/LibWeb/UIEvents/PointerEvent.cpp+++ b/Libraries/LibWeb/UIEvents/PointerEvent.cpp@@ -379,4 +379,19 @@ WebIDL::ExceptionOr<GC::Ref<PointerEvent>> PointerEvent::create_for_constructor(return create(Utf16FlyString::from_utf16(event_name.utf16_view()), move(options), event_init.client_x, event_init.client_y, event_init.client_x, event_init.client_y, time_stamp);}+extern "C" {+PointerEvent const* web_ui_events_pointer_event_from_event(DOM::Event const*);+WebIDL::Long web_ui_events_pointer_event_pointer_id(PointerEvent const*);++PointerEvent const* web_ui_events_pointer_event_from_event(DOM::Event const* event)+{+ return as_if<PointerEvent>(event);+}++WebIDL::Long web_ui_events_pointer_event_pointer_id(PointerEvent const* event)+{+ return event->pointer_id();+}+}+}