diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-04-06 00:13:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-05 22:13:29 +0000 |
commit | 6031a12fd1fa4aee8368e0b3dc0cb792caac56bc (patch) | |
tree | cc91327012041a24bd1b71c7768660a2efbe862f /components/shared/embedder/lib.rs | |
parent | a67409fb253b3cb6dd1adbaf9d3cad47941f4993 (diff) | |
download | servo-6031a12fd1fa4aee8368e0b3dc0cb792caac56bc.tar.gz servo-6031a12fd1fa4aee8368e0b3dc0cb792caac56bc.zip |
Move `ScriptToConstellationMsg` to `constellation_traits` (#36364)
This is the last big change necessary to create the
`constellation_traits` crate. This moves the data structure for messages
that originate from the `ScriptThread` and are sent to the
`Contellation` to `constellation_traits`, effectively splitting
`script_traits` in half. Before, `script_traits` was responsible for
exposing the API of both the `ScriptThread` and the `Constellation` to
the rest of Servo.
- Data structures that are used by `ScriptToConstellationMsg` are moved
to `constellation_traits`. The dependency graph looks a bit like this:
`script_layout_interface` depends on `script_traits` depends on
`constellation_traits` depends on `embedder_traits`.
- Data structures that are used in the embedding layer
(`UntrustedNodeAddress`, `CompositorHitTestResult`, `TouchEventResult`
and `AnimationState`) are moved to embedder_traits, to avoid a
dependency cycle between `webrender_traits` and
`constellation_traits`.
- Types dealing with MessagePorts and serialization are moved to
`constellation_traits::message_port`.
Testing: This is covered by existing tests as it just moves types
around.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/shared/embedder/lib.rs')
-rw-r--r-- | components/shared/embedder/lib.rs | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/components/shared/embedder/lib.rs b/components/shared/embedder/lib.rs index 67ccd9887ae..85dd4bf3af9 100644 --- a/components/shared/embedder/lib.rs +++ b/components/shared/embedder/lib.rs @@ -13,21 +13,23 @@ pub mod resources; pub mod user_content_manager; mod webdriver; +use std::ffi::c_void; use std::fmt::{Debug, Error, Formatter}; use std::path::PathBuf; use std::sync::Arc; -use base::id::{PipelineId, WebViewId}; +use base::id::{PipelineId, ScrollTreeNodeId, WebViewId}; use crossbeam_channel::Sender; use euclid::{Scale, Size2D}; use http::{HeaderMap, Method, StatusCode}; use ipc_channel::ipc::IpcSender; pub use keyboard_types::{KeyboardEvent, Modifiers}; use log::warn; +use malloc_size_of::malloc_size_of_is_0; use malloc_size_of_derive::MallocSizeOf; use num_derive::FromPrimitive; use pixels::Image; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use servo_url::ServoUrl; use strum_macros::IntoStaticStr; use style_traits::CSSPixel; @@ -705,3 +707,85 @@ impl From<SelectElementOption> for SelectElementOptionOrOptgroup { Self::Option(value) } } + +/// The address of a node. Layout sends these back. They must be validated via +/// `from_untrusted_node_address` before they can be used, because we do not trust layout. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub struct UntrustedNodeAddress(pub *const c_void); + +malloc_size_of_is_0!(UntrustedNodeAddress); + +#[allow(unsafe_code)] +unsafe impl Send for UntrustedNodeAddress {} + +impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress { + fn from(o: style_traits::dom::OpaqueNode) -> Self { + UntrustedNodeAddress(o.0 as *const c_void) + } +} + +impl Serialize for UntrustedNodeAddress { + fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> { + (self.0 as usize).serialize(s) + } +} + +impl<'de> Deserialize<'de> for UntrustedNodeAddress { + fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> { + let value: usize = Deserialize::deserialize(d)?; + Ok(UntrustedNodeAddress::from_id(value)) + } +} + +impl UntrustedNodeAddress { + /// Creates an `UntrustedNodeAddress` from the given pointer address value. + #[inline] + pub fn from_id(id: usize) -> UntrustedNodeAddress { + UntrustedNodeAddress(id as *const c_void) + } +} + +/// The result of a hit test in the compositor. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct CompositorHitTestResult { + /// The pipeline id of the resulting item. + pub pipeline_id: PipelineId, + + /// The hit test point in the item's viewport. + pub point_in_viewport: euclid::default::Point2D<f32>, + + /// The hit test point relative to the item itself. + pub point_relative_to_item: euclid::default::Point2D<f32>, + + /// The node address of the hit test result. + pub node: UntrustedNodeAddress, + + /// The cursor that should be used when hovering the item hit by the hit test. + pub cursor: Option<Cursor>, + + /// The scroll tree node associated with this hit test item. + pub scroll_tree_node: ScrollTreeNodeId, +} + +/// Whether the default action for a touch event was prevented by web content +#[derive(Debug, Deserialize, Serialize)] +pub enum TouchEventResult { + /// Allowed by web content + DefaultAllowed(TouchSequenceId, TouchEventType), + /// Prevented by web content + DefaultPrevented(TouchSequenceId, TouchEventType), +} + +/// For a given pipeline, whether any animations are currently running +/// and any animation callbacks are queued +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub enum AnimationState { + /// Animations are active but no callbacks are queued + AnimationsPresent, + /// Animations are active and callbacks are queued + AnimationCallbacksPresent, + /// No animations are active and no callbacks are queued + NoAnimationsPresent, + /// No animations are active but callbacks are queued + NoAnimationCallbacksPresent, +} |