diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-01-07 10:56:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-07 09:56:02 +0000 |
commit | e42b4b793d52e756e79c8a408b3f7e99219493f5 (patch) | |
tree | 1346ec6841f8e37b00018c836a29fb227f026d41 /components/script/script_thread.rs | |
parent | 17e2ca3f013e2ff8e7d7bca08d93c6c723a2b71d (diff) | |
download | servo-e42b4b793d52e756e79c8a408b3f7e99219493f5.tar.gz servo-e42b4b793d52e756e79c8a408b3f7e99219493f5.zip |
script: Expose `NodeTraits::owner_global` / `Window::as_global_scope` (#34843)
Expose two new helpers and start using them as much as possible.
- `NodeTraits::owner_global`: which gets the `GlobalScope` that currenty
owns a `Node`. This may be different than `.global()` in the case that
the `Node` was adopted by a different `Document`.
- `Window::as_global_scope`: A helper to avoid having to cast so much
when treating a `Window` like a `GlobalScope`.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 00d2ef64f0c..5b0c201764a 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -671,7 +671,7 @@ impl ScriptThread { None => return, Some(window) => window, }; - let global = window.upcast::<GlobalScope>(); + let global = window.as_global_scope(); let trusted_global = Trusted::new(global); let sender = script_thread .senders @@ -1033,7 +1033,7 @@ impl ScriptThread { let docs = self.documents.borrow(); for (_, document) in docs.iter() { document - .window() + .owner_global() .task_manager() .cancel_all_tasks_and_ignore_future_tasks(); } @@ -1218,8 +1218,7 @@ impl ScriptThread { }, CompositorEvent::GamepadEvent(gamepad_event) => { - let global = window.upcast::<GlobalScope>(); - global.handle_gamepad_event(gamepad_event); + window.as_global_scope().handle_gamepad_event(gamepad_event); }, } } @@ -1410,7 +1409,7 @@ impl ScriptThread { // rendering update when animations are not running. let _realm = enter_realm(&*document); document - .window() + .owner_global() .task_manager() .rendering_task_source() .queue_unconditionally(task!(update_the_rendering: move || { })); @@ -2098,7 +2097,7 @@ impl ScriptThread { match msg { DevtoolScriptControlMsg::EvaluateJS(id, s, reply) => match documents.find_window(id) { Some(window) => { - let global = window.upcast::<GlobalScope>(); + let global = window.as_global_scope(); let _aes = AutoEntryScript::new(global); devtools::handle_evaluate_js(global, s, reply, can_gc) }, @@ -3697,11 +3696,8 @@ impl ScriptThread { ) { let window = self.documents.borrow().find_window(pipeline_id); if let Some(window) = window { - let entry = PerformancePaintTiming::new( - window.upcast::<GlobalScope>(), - metric_type, - metric_value, - ); + let entry = + PerformancePaintTiming::new(window.as_global_scope(), metric_type, metric_value); window .Performance() .queue_entry(entry.upcast::<PerformanceEntry>(), can_gc); |