mirror of
https://github.com/servo/servo.git
synced 2025-08-26 07:38:21 +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
|
@ -4168,7 +4168,7 @@ where
|
|||
source_browsing_context,
|
||||
target_origin: origin,
|
||||
source_origin,
|
||||
data,
|
||||
data: Box::new(data),
|
||||
};
|
||||
let result = match self.pipelines.get(&pipeline_id) {
|
||||
Some(pipeline) => pipeline.event_loop.send(msg),
|
||||
|
|
|
@ -10,13 +10,14 @@ use std::os::raw;
|
|||
use std::ptr;
|
||||
|
||||
use base::id::{
|
||||
BlobId, DomExceptionId, DomPointId, ImageBitmapId, Index, MessagePortId, NamespaceIndex,
|
||||
OffscreenCanvasId, PipelineNamespaceId, QuotaExceededErrorId,
|
||||
BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId, Index,
|
||||
MessagePortId, NamespaceIndex, OffscreenCanvasId, PipelineNamespaceId, QuotaExceededErrorId,
|
||||
};
|
||||
use constellation_traits::{
|
||||
BlobImpl, DomException, DomPoint, MessagePortImpl, Serializable as SerializableInterface,
|
||||
SerializableImageBitmap, SerializableQuotaExceededError, StructuredSerializedData,
|
||||
TransferableOffscreenCanvas, Transferrable as TransferrableInterface, TransformStreamData,
|
||||
BlobImpl, DomException, DomMatrix, DomPoint, DomQuad, DomRect, MessagePortImpl,
|
||||
Serializable as SerializableInterface, SerializableImageBitmap, SerializableQuotaExceededError,
|
||||
StructuredSerializedData, TransferableOffscreenCanvas, Transferrable as TransferrableInterface,
|
||||
TransformStreamData,
|
||||
};
|
||||
use js::gc::RootedVec;
|
||||
use js::glue::{
|
||||
|
@ -49,7 +50,10 @@ use crate::dom::imagebitmap::ImageBitmap;
|
|||
use crate::dom::messageport::MessagePort;
|
||||
use crate::dom::offscreencanvas::OffscreenCanvas;
|
||||
use crate::dom::readablestream::ReadableStream;
|
||||
use crate::dom::types::{DOMException, QuotaExceededError, TransformStream};
|
||||
use crate::dom::types::{
|
||||
DOMException, DOMMatrix, DOMMatrixReadOnly, DOMQuad, DOMRect, DOMRectReadOnly,
|
||||
QuotaExceededError, TransformStream,
|
||||
};
|
||||
use crate::dom::writablestream::WritableStream;
|
||||
use crate::realms::{AlreadyInRealm, InRealm, enter_realm};
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
||||
|
@ -74,6 +78,11 @@ pub(super) enum StructuredCloneTags {
|
|||
ImageBitmap = 0xFFFF800A,
|
||||
OffscreenCanvas = 0xFFFF800B,
|
||||
QuotaExceededError = 0xFFFF800C,
|
||||
DomRect = 0xFFFF800D,
|
||||
DomRectReadOnly = 0xFFFF800E,
|
||||
DomQuad = 0xFFFF800F,
|
||||
DomMatrix = 0xFFFF8010,
|
||||
DomMatrixReadOnly = 0xFFFF8011,
|
||||
Max = 0xFFFFFFFF,
|
||||
}
|
||||
|
||||
|
@ -81,8 +90,13 @@ impl From<SerializableInterface> for StructuredCloneTags {
|
|||
fn from(v: SerializableInterface) -> Self {
|
||||
match v {
|
||||
SerializableInterface::Blob => StructuredCloneTags::DomBlob,
|
||||
SerializableInterface::DomPointReadOnly => StructuredCloneTags::DomPointReadOnly,
|
||||
SerializableInterface::DomPoint => StructuredCloneTags::DomPoint,
|
||||
SerializableInterface::DomPointReadOnly => StructuredCloneTags::DomPointReadOnly,
|
||||
SerializableInterface::DomRect => StructuredCloneTags::DomRect,
|
||||
SerializableInterface::DomRectReadOnly => StructuredCloneTags::DomRectReadOnly,
|
||||
SerializableInterface::DomQuad => StructuredCloneTags::DomQuad,
|
||||
SerializableInterface::DomMatrix => StructuredCloneTags::DomMatrix,
|
||||
SerializableInterface::DomMatrixReadOnly => StructuredCloneTags::DomMatrixReadOnly,
|
||||
SerializableInterface::DomException => StructuredCloneTags::DomException,
|
||||
SerializableInterface::ImageBitmap => StructuredCloneTags::ImageBitmap,
|
||||
SerializableInterface::QuotaExceededError => StructuredCloneTags::QuotaExceededError,
|
||||
|
@ -113,8 +127,13 @@ fn reader_for_type(
|
|||
) -> *mut JSObject {
|
||||
match val {
|
||||
SerializableInterface::Blob => read_object::<Blob>,
|
||||
SerializableInterface::DomPointReadOnly => read_object::<DOMPointReadOnly>,
|
||||
SerializableInterface::DomPoint => read_object::<DOMPoint>,
|
||||
SerializableInterface::DomPointReadOnly => read_object::<DOMPointReadOnly>,
|
||||
SerializableInterface::DomRect => read_object::<DOMRect>,
|
||||
SerializableInterface::DomRectReadOnly => read_object::<DOMRectReadOnly>,
|
||||
SerializableInterface::DomQuad => read_object::<DOMQuad>,
|
||||
SerializableInterface::DomMatrix => read_object::<DOMMatrix>,
|
||||
SerializableInterface::DomMatrixReadOnly => read_object::<DOMMatrixReadOnly>,
|
||||
SerializableInterface::DomException => read_object::<DOMException>,
|
||||
SerializableInterface::ImageBitmap => read_object::<ImageBitmap>,
|
||||
SerializableInterface::QuotaExceededError => read_object::<QuotaExceededError>,
|
||||
|
@ -258,8 +277,13 @@ type SerializeOperation = unsafe fn(
|
|||
fn serialize_for_type(val: SerializableInterface) -> SerializeOperation {
|
||||
match val {
|
||||
SerializableInterface::Blob => try_serialize::<Blob>,
|
||||
SerializableInterface::DomPointReadOnly => try_serialize::<DOMPointReadOnly>,
|
||||
SerializableInterface::DomPoint => try_serialize::<DOMPoint>,
|
||||
SerializableInterface::DomPointReadOnly => try_serialize::<DOMPointReadOnly>,
|
||||
SerializableInterface::DomRect => try_serialize::<DOMRect>,
|
||||
SerializableInterface::DomRectReadOnly => try_serialize::<DOMRectReadOnly>,
|
||||
SerializableInterface::DomQuad => try_serialize::<DOMQuad>,
|
||||
SerializableInterface::DomMatrix => try_serialize::<DOMMatrix>,
|
||||
SerializableInterface::DomMatrixReadOnly => try_serialize::<DOMMatrixReadOnly>,
|
||||
SerializableInterface::DomException => try_serialize::<DOMException>,
|
||||
SerializableInterface::ImageBitmap => try_serialize::<ImageBitmap>,
|
||||
SerializableInterface::QuotaExceededError => try_serialize::<QuotaExceededError>,
|
||||
|
@ -572,6 +596,12 @@ pub(crate) struct StructuredDataReader<'a> {
|
|||
pub(crate) blob_impls: Option<HashMap<BlobId, BlobImpl>>,
|
||||
/// A map of serialized points.
|
||||
pub(crate) points: Option<HashMap<DomPointId, DomPoint>>,
|
||||
/// A map of serialized rects.
|
||||
pub(crate) rects: Option<HashMap<DomRectId, DomRect>>,
|
||||
/// A map of serialized quads.
|
||||
pub(crate) quads: Option<HashMap<DomQuadId, DomQuad>>,
|
||||
/// A map of serialized matrices.
|
||||
pub(crate) matrices: Option<HashMap<DomMatrixId, DomMatrix>>,
|
||||
/// A map of serialized exceptions.
|
||||
pub(crate) exceptions: Option<HashMap<DomExceptionId, DomException>>,
|
||||
/// A map of serialized quota exceeded errors.
|
||||
|
@ -597,6 +627,12 @@ pub(crate) struct StructuredDataWriter {
|
|||
pub(crate) transform_streams_port: Option<HashMap<MessagePortId, TransformStreamData>>,
|
||||
/// Serialized points.
|
||||
pub(crate) points: Option<HashMap<DomPointId, DomPoint>>,
|
||||
/// Serialized rects.
|
||||
pub(crate) rects: Option<HashMap<DomRectId, DomRect>>,
|
||||
/// Serialized quads.
|
||||
pub(crate) quads: Option<HashMap<DomQuadId, DomQuad>>,
|
||||
/// Serialized matrices.
|
||||
pub(crate) matrices: Option<HashMap<DomMatrixId, DomMatrix>>,
|
||||
/// Serialized exceptions.
|
||||
pub(crate) exceptions: Option<HashMap<DomExceptionId, DomException>>,
|
||||
/// Serialized quota exceeded errors.
|
||||
|
@ -665,6 +701,9 @@ pub(crate) fn write(
|
|||
ports: sc_writer.ports.take(),
|
||||
transform_streams: sc_writer.transform_streams_port.take(),
|
||||
points: sc_writer.points.take(),
|
||||
rects: sc_writer.rects.take(),
|
||||
quads: sc_writer.quads.take(),
|
||||
matrices: sc_writer.matrices.take(),
|
||||
exceptions: sc_writer.exceptions.take(),
|
||||
quota_exceeded_errors: sc_writer.quota_exceeded_errors.take(),
|
||||
blobs: sc_writer.blobs.take(),
|
||||
|
@ -694,6 +733,9 @@ pub(crate) fn read(
|
|||
transform_streams_port_impls: data.transform_streams.take(),
|
||||
blob_impls: data.blobs.take(),
|
||||
points: data.points.take(),
|
||||
rects: data.rects.take(),
|
||||
quads: data.quads.take(),
|
||||
matrices: data.matrices.take(),
|
||||
exceptions: data.exceptions.take(),
|
||||
quota_exceeded_errors: data.quota_exceeded_errors.take(),
|
||||
image_bitmaps: data.image_bitmaps.take(),
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{DomMatrixId, DomMatrixIndex};
|
||||
use constellation_traits::DomMatrix;
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::default::Transform3D;
|
||||
use js::rust::{CustomAutoRooterGuard, HandleObject};
|
||||
|
@ -15,6 +19,8 @@ use crate::dom::bindings::error::Fallible;
|
|||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::dommatrixreadonly::{
|
||||
DOMMatrixReadOnly, dommatrixinit_to_matrix, entries_to_matrix, transform_to_matrix,
|
||||
};
|
||||
|
@ -472,3 +478,86 @@ impl DOMMatrixMethods<crate::DomTypeHolder> for DOMMatrix {
|
|||
DomRoot::from_ref(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serializable for DOMMatrix {
|
||||
type Index = DomMatrixIndex;
|
||||
type Data = DomMatrix;
|
||||
|
||||
fn serialize(&self) -> Result<(DomMatrixId, Self::Data), ()> {
|
||||
let serialized = if self.parent.is2D() {
|
||||
DomMatrix {
|
||||
matrix: Transform3D::new(
|
||||
self.M11(),
|
||||
self.M12(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
self.M21(),
|
||||
self.M22(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
self.M41(),
|
||||
self.M42(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
),
|
||||
is_2d: true,
|
||||
}
|
||||
} else {
|
||||
DomMatrix {
|
||||
matrix: *self.parent.matrix(),
|
||||
is_2d: false,
|
||||
}
|
||||
};
|
||||
Ok((DomMatrixId::new(), serialized))
|
||||
}
|
||||
|
||||
fn deserialize(
|
||||
owner: &GlobalScope,
|
||||
serialized: Self::Data,
|
||||
can_gc: CanGc,
|
||||
) -> Result<DomRoot<Self>, ()>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if serialized.is_2d {
|
||||
Ok(Self::new(
|
||||
owner,
|
||||
true,
|
||||
Transform3D::new(
|
||||
serialized.matrix.m11,
|
||||
serialized.matrix.m12,
|
||||
0.0,
|
||||
0.0,
|
||||
serialized.matrix.m21,
|
||||
serialized.matrix.m22,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
serialized.matrix.m41,
|
||||
serialized.matrix.m42,
|
||||
0.0,
|
||||
1.0,
|
||||
),
|
||||
can_gc,
|
||||
))
|
||||
} else {
|
||||
Ok(Self::new(owner, false, serialized.matrix, can_gc))
|
||||
}
|
||||
}
|
||||
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<DomMatrixId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.matrices,
|
||||
StructuredData::Writer(writer) => &mut writer.matrices,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashMap;
|
||||
use std::{f64, ptr};
|
||||
|
||||
use base::id::{DomMatrixId, DomMatrixIndex};
|
||||
use constellation_traits::DomMatrix;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::Angle;
|
||||
|
@ -30,7 +33,9 @@ use crate::dom::bindings::error::Fallible;
|
|||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::dommatrix::DOMMatrix;
|
||||
use crate::dom::dompoint::DOMPoint;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -924,6 +929,89 @@ impl DOMMatrixReadOnlyMethods<crate::DomTypeHolder> for DOMMatrixReadOnly {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serializable for DOMMatrixReadOnly {
|
||||
type Index = DomMatrixIndex;
|
||||
type Data = DomMatrix;
|
||||
|
||||
fn serialize(&self) -> Result<(DomMatrixId, Self::Data), ()> {
|
||||
let serialized = if self.is2D() {
|
||||
DomMatrix {
|
||||
matrix: Transform3D::new(
|
||||
self.M11(),
|
||||
self.M12(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
self.M21(),
|
||||
self.M22(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
self.M41(),
|
||||
self.M42(),
|
||||
f64::NAN,
|
||||
f64::NAN,
|
||||
),
|
||||
is_2d: true,
|
||||
}
|
||||
} else {
|
||||
DomMatrix {
|
||||
matrix: *self.matrix(),
|
||||
is_2d: false,
|
||||
}
|
||||
};
|
||||
Ok((DomMatrixId::new(), serialized))
|
||||
}
|
||||
|
||||
fn deserialize(
|
||||
owner: &GlobalScope,
|
||||
serialized: Self::Data,
|
||||
can_gc: CanGc,
|
||||
) -> Result<DomRoot<Self>, ()>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if serialized.is_2d {
|
||||
Ok(Self::new(
|
||||
owner,
|
||||
true,
|
||||
Transform3D::new(
|
||||
serialized.matrix.m11,
|
||||
serialized.matrix.m12,
|
||||
0.0,
|
||||
0.0,
|
||||
serialized.matrix.m21,
|
||||
serialized.matrix.m22,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
serialized.matrix.m41,
|
||||
serialized.matrix.m42,
|
||||
0.0,
|
||||
1.0,
|
||||
),
|
||||
can_gc,
|
||||
))
|
||||
} else {
|
||||
Ok(Self::new(owner, false, serialized.matrix, can_gc))
|
||||
}
|
||||
}
|
||||
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<DomMatrixId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.matrices,
|
||||
StructuredData::Writer(writer) => &mut writer.matrices,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly-numbersequence
|
||||
pub(crate) fn entries_to_matrix(entries: &[f64]) -> Fallible<(bool, Transform3D<f64>)> {
|
||||
if let Ok(array) = entries.try_into() {
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{DomQuadId, DomQuadIndex};
|
||||
use constellation_traits::{DomPoint, DomQuad};
|
||||
use dom_struct::dom_struct;
|
||||
use js::rust::HandleObject;
|
||||
|
||||
|
@ -11,6 +15,8 @@ use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectInit
|
|||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::dompoint::DOMPoint;
|
||||
use crate::dom::domrect::DOMRect;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -203,3 +209,56 @@ impl DOMQuadMethods<crate::DomTypeHolder> for DOMQuad {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serializable for DOMQuad {
|
||||
type Index = DomQuadIndex;
|
||||
type Data = DomQuad;
|
||||
|
||||
fn serialize(&self) -> Result<(DomQuadId, Self::Data), ()> {
|
||||
let make_point = |src: DomRoot<DOMPoint>| -> DomPoint {
|
||||
DomPoint {
|
||||
x: src.X(),
|
||||
y: src.Y(),
|
||||
z: src.Z(),
|
||||
w: src.W(),
|
||||
}
|
||||
};
|
||||
let serialized = DomQuad {
|
||||
p1: make_point(self.P1()),
|
||||
p2: make_point(self.P2()),
|
||||
p3: make_point(self.P3()),
|
||||
p4: make_point(self.P4()),
|
||||
};
|
||||
Ok((DomQuadId::new(), serialized))
|
||||
}
|
||||
|
||||
fn deserialize(
|
||||
owner: &GlobalScope,
|
||||
serialized: Self::Data,
|
||||
can_gc: CanGc,
|
||||
) -> Result<DomRoot<Self>, ()>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let make_point = |src: DomPoint| -> DomRoot<DOMPoint> {
|
||||
DOMPoint::new(owner, src.x, src.y, src.z, src.w, can_gc)
|
||||
};
|
||||
Ok(Self::new(
|
||||
owner,
|
||||
&make_point(serialized.p1),
|
||||
&make_point(serialized.p2),
|
||||
&make_point(serialized.p3),
|
||||
&make_point(serialized.p4),
|
||||
can_gc,
|
||||
))
|
||||
}
|
||||
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<DomQuadId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.quads,
|
||||
StructuredData::Writer(writer) => &mut writer.quads,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{DomRectId, DomRectIndex};
|
||||
use constellation_traits::DomRect;
|
||||
use dom_struct::dom_struct;
|
||||
use js::rust::HandleObject;
|
||||
|
||||
|
@ -12,6 +16,8 @@ use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{
|
|||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::domrectreadonly::{DOMRectReadOnly, create_a_domrectreadonly_from_the_dictionary};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
@ -121,3 +127,45 @@ impl DOMRectMethods<crate::DomTypeHolder> for DOMRect {
|
|||
self.rect.set_height(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl Serializable for DOMRect {
|
||||
type Index = DomRectIndex;
|
||||
type Data = DomRect;
|
||||
|
||||
fn serialize(&self) -> Result<(DomRectId, Self::Data), ()> {
|
||||
let serialized = DomRect {
|
||||
x: self.X(),
|
||||
y: self.Y(),
|
||||
width: self.Width(),
|
||||
height: self.Height(),
|
||||
};
|
||||
Ok((DomRectId::new(), serialized))
|
||||
}
|
||||
|
||||
fn deserialize(
|
||||
owner: &GlobalScope,
|
||||
serialized: Self::Data,
|
||||
can_gc: CanGc,
|
||||
) -> Result<DomRoot<Self>, ()>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok(Self::new(
|
||||
owner,
|
||||
serialized.x,
|
||||
serialized.y,
|
||||
serialized.width,
|
||||
serialized.height,
|
||||
can_gc,
|
||||
))
|
||||
}
|
||||
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<DomRectId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.rects,
|
||||
StructuredData::Writer(writer) => &mut writer.rects,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{DomRectId, DomRectIndex};
|
||||
use constellation_traits::DomRect;
|
||||
use dom_struct::dom_struct;
|
||||
use js::rust::HandleObject;
|
||||
|
||||
|
@ -15,6 +18,8 @@ use crate::dom::bindings::reflector::{
|
|||
Reflector, reflect_dom_object, reflect_dom_object_with_proto,
|
||||
};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
|
@ -196,3 +201,48 @@ pub(super) fn create_a_domrectreadonly_from_the_dictionary(other: &DOMRectInit)
|
|||
height: Cell::new(other.height),
|
||||
}
|
||||
}
|
||||
|
||||
type Type = DomRectId;
|
||||
|
||||
impl Serializable for DOMRectReadOnly {
|
||||
type Index = DomRectIndex;
|
||||
type Data = DomRect;
|
||||
|
||||
fn serialize(&self) -> Result<(DomRectId, Self::Data), ()> {
|
||||
let serialized = DomRect {
|
||||
x: self.X(),
|
||||
y: self.Y(),
|
||||
width: self.Width(),
|
||||
height: self.Height(),
|
||||
};
|
||||
Ok((DomRectId::new(), serialized))
|
||||
}
|
||||
|
||||
fn deserialize(
|
||||
owner: &GlobalScope,
|
||||
serialized: Self::Data,
|
||||
can_gc: CanGc,
|
||||
) -> Result<DomRoot<Self>, ()>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok(Self::new(
|
||||
owner,
|
||||
None,
|
||||
serialized.x,
|
||||
serialized.y,
|
||||
serialized.width,
|
||||
serialized.height,
|
||||
can_gc,
|
||||
))
|
||||
}
|
||||
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<Type, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.rects,
|
||||
StructuredData::Writer(writer) => &mut writer.rects,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1773,7 +1773,7 @@ impl ScriptThread {
|
|||
source_browsing_context,
|
||||
origin,
|
||||
source_origin,
|
||||
data,
|
||||
*data,
|
||||
),
|
||||
ScriptThreadMessage::UpdatePipelineId(
|
||||
parent_pipeline_id,
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
// https://drafts.fxtf.org/geometry/#dommatrix
|
||||
|
||||
[Exposed=(Window,Worker,PaintWorklet),
|
||||
LegacyWindowAlias=(SVGMatrix,WebKitCSSMatrix)]
|
||||
LegacyWindowAlias=(SVGMatrix,WebKitCSSMatrix),
|
||||
Serializable]
|
||||
interface DOMMatrix : DOMMatrixReadOnly {
|
||||
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
* related or neighboring rights to this work.
|
||||
*/
|
||||
|
||||
[Exposed=(Window,Worker,PaintWorklet)]
|
||||
[Exposed=(Window,Worker,PaintWorklet),
|
||||
Serializable]
|
||||
interface DOMMatrixReadOnly {
|
||||
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
* related or neighboring rights to this work.
|
||||
*/
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
[Exposed=(Window,Worker),
|
||||
Serializable]
|
||||
interface DOMQuad {
|
||||
[Throws] constructor(optional DOMPointInit p1 = {}, optional DOMPointInit p2 = {},
|
||||
optional DOMPointInit p3 = {}, optional DOMPointInit p4 = {});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// https://drafts.fxtf.org/geometry/#domrect
|
||||
|
||||
[Exposed=(Window,Worker),
|
||||
/*Serializable,*/
|
||||
Serializable,
|
||||
LegacyWindowAlias=SVGRect]
|
||||
interface DOMRect : DOMRectReadOnly {
|
||||
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// https://drafts.fxtf.org/geometry/#domrect
|
||||
|
||||
[Exposed=(Window,Worker),
|
||||
/*Serializable*/]
|
||||
Serializable]
|
||||
interface DOMRectReadOnly {
|
||||
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
|
||||
optional unrestricted double width = 0, optional unrestricted double height = 0);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
[structured-serialization.html]
|
||||
[DOMRectReadOnly clone: basic]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly clone: custom property]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly clone: throwing getters]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly clone: non-initial values]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect clone: basic]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect clone: custom property]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect clone: throwing getters]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect clone: non-initial values]
|
||||
expected: FAIL
|
||||
|
||||
[DOMQuad clone: basic]
|
||||
expected: FAIL
|
||||
|
||||
[DOMQuad clone: custom property]
|
||||
expected: FAIL
|
||||
|
||||
[DOMQuad clone: throwing getters]
|
||||
expected: FAIL
|
||||
|
||||
[DOMQuad clone: non-initial values]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrixReadOnly clone: basic]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrixReadOnly clone: custom property]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrixReadOnly clone: throwing getters]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrixReadOnly clone: non-initial values (2d)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrixReadOnly clone: non-initial values (3d)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrix clone: basic]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrix clone: custom property]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrix clone: throwing getters]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrix clone: non-initial values (2d)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMMatrix clone: non-initial values (3d)]
|
||||
expected: FAIL
|
|
@ -1,4 +1,3 @@
|
|||
[same-origin-grand-child-iframe.sub.html]
|
||||
expected: TIMEOUT
|
||||
[rootBounds in a same-origin iframe in the case where there is a cross-origin iframe in between the top document and the same origin iframe]
|
||||
expected: TIMEOUT
|
||||
expected: FAIL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue