mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
Make DOM geometry structs serializable (#38828)
Makes the following DOM geometry structs serializable: - `DOMRect` - `DOMRectReadOnly` - `DOMQuad` - `DOMMatrix` - `DOMMatrixReadOnly` Testing: Covered by WPT (`css/geometry/structured-serialization.html`). --------- Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
This commit is contained in:
parent
e00f39d827
commit
39f3ce7a2e
19 changed files with 529 additions and 89 deletions
|
@ -366,6 +366,12 @@ namespace_id! {BlobId, BlobIndex, "Blob"}
|
|||
|
||||
namespace_id! {DomPointId, DomPointIndex, "DomPoint"}
|
||||
|
||||
namespace_id! {DomRectId, DomRectIndex, "DomRect"}
|
||||
|
||||
namespace_id! {DomQuadId, DomQuadIndex, "DomQuad"}
|
||||
|
||||
namespace_id! {DomMatrixId, DomMatrixIndex, "DomMatrix"}
|
||||
|
||||
namespace_id! {DomExceptionId, DomExceptionIndex, "DomException"}
|
||||
|
||||
namespace_id! {QuotaExceededErrorId, QuotaExceededErrorIndex, "QuotaExceededError"}
|
||||
|
|
|
@ -11,8 +11,8 @@ mod transferable;
|
|||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{
|
||||
BlobId, DomExceptionId, DomPointId, ImageBitmapId, MessagePortId, OffscreenCanvasId,
|
||||
QuotaExceededErrorId,
|
||||
BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId,
|
||||
MessagePortId, OffscreenCanvasId, QuotaExceededErrorId,
|
||||
};
|
||||
use log::warn;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
|
@ -31,6 +31,12 @@ pub struct StructuredSerializedData {
|
|||
pub blobs: Option<HashMap<BlobId, BlobImpl>>,
|
||||
/// Serialized point objects.
|
||||
pub points: Option<HashMap<DomPointId, DomPoint>>,
|
||||
/// Serialized rect objects.
|
||||
pub rects: Option<HashMap<DomRectId, DomRect>>,
|
||||
/// Serialized quad objects.
|
||||
pub quads: Option<HashMap<DomQuadId, DomQuad>>,
|
||||
/// Serialized matrix objects.
|
||||
pub matrices: Option<HashMap<DomMatrixId, DomMatrix>>,
|
||||
/// Serialized exception objects.
|
||||
pub exceptions: Option<HashMap<DomExceptionId, DomException>>,
|
||||
/// Serialized quota exceeded errors.
|
||||
|
|
|
@ -11,7 +11,11 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId, QuotaExceededErrorId};
|
||||
use base::id::{
|
||||
BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId,
|
||||
QuotaExceededErrorId,
|
||||
};
|
||||
use euclid::default::Transform3D;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use net_traits::filemanager_thread::RelativePos;
|
||||
use pixels::Snapshot;
|
||||
|
@ -49,6 +53,16 @@ pub enum Serializable {
|
|||
DomPoint,
|
||||
/// The `DOMPointReadOnly` interface.
|
||||
DomPointReadOnly,
|
||||
/// The `DOMRect` interface.
|
||||
DomRect,
|
||||
/// The `DOMRectReadOnly` interface.
|
||||
DomRectReadOnly,
|
||||
/// The `DOMQuad` interface.
|
||||
DomQuad,
|
||||
/// The `DOMMatrix` interface.
|
||||
DomMatrix,
|
||||
/// The `DOMMatrixReadOnly` interface.
|
||||
DomMatrixReadOnly,
|
||||
/// The `QuotaExceededError` interface.
|
||||
QuotaExceededError,
|
||||
/// The `DOMException` interface.
|
||||
|
@ -63,10 +77,17 @@ impl Serializable {
|
|||
) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) {
|
||||
match self {
|
||||
Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>,
|
||||
Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
|
||||
Serializable::DomPointReadOnly => {
|
||||
StructuredSerializedData::clone_all_of_type::<DomPoint>
|
||||
},
|
||||
Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
|
||||
Serializable::DomRect => StructuredSerializedData::clone_all_of_type::<DomRect>,
|
||||
Serializable::DomRectReadOnly => StructuredSerializedData::clone_all_of_type::<DomRect>,
|
||||
Serializable::DomQuad => StructuredSerializedData::clone_all_of_type::<DomQuad>,
|
||||
Serializable::DomMatrix => StructuredSerializedData::clone_all_of_type::<DomMatrix>,
|
||||
Serializable::DomMatrixReadOnly => {
|
||||
StructuredSerializedData::clone_all_of_type::<DomMatrix>
|
||||
},
|
||||
Serializable::DomException => {
|
||||
StructuredSerializedData::clone_all_of_type::<DomException>
|
||||
},
|
||||
|
@ -300,6 +321,101 @@ impl BroadcastClone for DomPoint {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
/// A serializable version of the DOMRect/DOMRectReadOnly interface.
|
||||
pub struct DomRect {
|
||||
/// The x coordinate.
|
||||
pub x: f64,
|
||||
/// The y coordinate.
|
||||
pub y: f64,
|
||||
/// The width.
|
||||
pub width: f64,
|
||||
/// The height.
|
||||
pub height: f64,
|
||||
}
|
||||
|
||||
impl BroadcastClone for DomRect {
|
||||
type Id = DomRectId;
|
||||
|
||||
fn source(
|
||||
data: &StructuredSerializedData,
|
||||
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&data.rects
|
||||
}
|
||||
|
||||
fn destination(
|
||||
data: &mut StructuredSerializedData,
|
||||
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&mut data.rects
|
||||
}
|
||||
|
||||
fn clone_for_broadcast(&self) -> Option<Self> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
/// A serializable version of the DOMQuad interface.
|
||||
pub struct DomQuad {
|
||||
/// The first point.
|
||||
pub p1: DomPoint,
|
||||
/// The second point.
|
||||
pub p2: DomPoint,
|
||||
/// The third point.
|
||||
pub p3: DomPoint,
|
||||
/// The fourth point.
|
||||
pub p4: DomPoint,
|
||||
}
|
||||
|
||||
impl BroadcastClone for DomQuad {
|
||||
type Id = DomQuadId;
|
||||
|
||||
fn source(
|
||||
data: &StructuredSerializedData,
|
||||
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&data.quads
|
||||
}
|
||||
|
||||
fn destination(
|
||||
data: &mut StructuredSerializedData,
|
||||
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&mut data.quads
|
||||
}
|
||||
|
||||
fn clone_for_broadcast(&self) -> Option<Self> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
/// A serializable version of the DOMMatrix/DOMMatrixReadOnly interface.
|
||||
pub struct DomMatrix {
|
||||
/// The matrix.
|
||||
pub matrix: Transform3D<f64>,
|
||||
/// Whether this matrix represents a 2D transformation.
|
||||
pub is_2d: bool,
|
||||
}
|
||||
|
||||
impl BroadcastClone for DomMatrix {
|
||||
type Id = DomMatrixId;
|
||||
|
||||
fn source(
|
||||
data: &StructuredSerializedData,
|
||||
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&data.matrices
|
||||
}
|
||||
|
||||
fn destination(
|
||||
data: &mut StructuredSerializedData,
|
||||
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
|
||||
&mut data.matrices
|
||||
}
|
||||
|
||||
fn clone_for_broadcast(&self) -> Option<Self> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
/// A serializable version of the DOMException interface.
|
||||
pub struct DomException {
|
||||
|
|
|
@ -182,7 +182,7 @@ pub enum ScriptThreadMessage {
|
|||
/// <https://html.spec.whatwg.org/multipage/#dom-messageevent-origin>
|
||||
source_origin: ImmutableOrigin,
|
||||
/// The data to be posted.
|
||||
data: StructuredSerializedData,
|
||||
data: Box<StructuredSerializedData>,
|
||||
},
|
||||
/// Updates the current pipeline ID of a given iframe.
|
||||
/// First PipelineId is for the parent, second is the new PipelineId for the frame.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue