mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29: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
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue