mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add DOMQuad element
This commit is contained in:
parent
338f66003e
commit
823e1b96c3
8 changed files with 178 additions and 119 deletions
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointMethods, Wrap};
|
use dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointInit, DOMPointMethods, Wrap};
|
||||||
use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
|
use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
|
@ -35,6 +35,10 @@ impl DOMPoint {
|
||||||
-> Fallible<Root<DOMPoint>> {
|
-> Fallible<Root<DOMPoint>> {
|
||||||
Ok(DOMPoint::new(global, x, y, z, w))
|
Ok(DOMPoint::new(global, x, y, z, w))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_from_init(global: GlobalRef, p: &DOMPointInit) -> Root<DOMPoint> {
|
||||||
|
DOMPoint::new(global, p.x, p.y, p.z, p.w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DOMPointMethods for DOMPoint {
|
impl DOMPointMethods for DOMPoint {
|
||||||
|
|
119
components/script/dom/domquad.rs
Normal file
119
components/script/dom/domquad.rs
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointInit, DOMPointMethods};
|
||||||
|
use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::DOMQuadBinding::{DOMQuadInit, DOMQuadMethods, Wrap};
|
||||||
|
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{DOMRectInit, DOMRectReadOnlyMethods};
|
||||||
|
use dom::bindings::error::Fallible;
|
||||||
|
use dom::bindings::global::{GlobalRef, global_root_from_reflector};
|
||||||
|
use dom::bindings::js::{Root, JS};
|
||||||
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||||
|
use dom::dompoint::DOMPoint;
|
||||||
|
use dom::domrect::DOMRect;
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#DOMQuad
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct DOMQuad {
|
||||||
|
reflector_: Reflector,
|
||||||
|
p1: JS<DOMPoint>,
|
||||||
|
p2: JS<DOMPoint>,
|
||||||
|
p3: JS<DOMPoint>,
|
||||||
|
p4: JS<DOMPoint>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DOMQuad {
|
||||||
|
fn new_inherited(p1: &DOMPoint,
|
||||||
|
p2: &DOMPoint,
|
||||||
|
p3: &DOMPoint,
|
||||||
|
p4: &DOMPoint)
|
||||||
|
-> DOMQuad {
|
||||||
|
|
||||||
|
DOMQuad {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
p1: JS::from_ref(p1),
|
||||||
|
p2: JS::from_ref(p2),
|
||||||
|
p3: JS::from_ref(p3),
|
||||||
|
p4: JS::from_ref(p4),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(global: GlobalRef,
|
||||||
|
p1: &DOMPoint,
|
||||||
|
p2: &DOMPoint,
|
||||||
|
p3: &DOMPoint,
|
||||||
|
p4: &DOMPoint) -> Root<DOMQuad> {
|
||||||
|
reflect_dom_object(box DOMQuad::new_inherited(p1, p2, p3, p4),
|
||||||
|
global,
|
||||||
|
Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn Constructor(global: GlobalRef,
|
||||||
|
p1: &DOMPointInit,
|
||||||
|
p2: &DOMPointInit,
|
||||||
|
p3: &DOMPointInit,
|
||||||
|
p4: &DOMPointInit)
|
||||||
|
-> Fallible<Root<DOMQuad>> {
|
||||||
|
Ok(DOMQuad::new(global,
|
||||||
|
&*DOMPoint::new_from_init(global, p1),
|
||||||
|
&*DOMPoint::new_from_init(global, p2),
|
||||||
|
&*DOMPoint::new_from_init(global, p3),
|
||||||
|
&*DOMPoint::new_from_init(global, p4)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-fromrect
|
||||||
|
pub fn FromRect(global: GlobalRef, other: &DOMRectInit) -> Root<DOMQuad> {
|
||||||
|
DOMQuad::new(global,
|
||||||
|
&*DOMPoint::new(global, other.x, other.y, 0f64, 1f64),
|
||||||
|
&*DOMPoint::new(global, other.x + other.width, other.y, 0f64, 1f64),
|
||||||
|
&*DOMPoint::new(global, other.x + other.width, other.y + other.height, 0f64, 1f64),
|
||||||
|
&*DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64))
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-fromquad
|
||||||
|
pub fn FromQuad(global: GlobalRef, other: &DOMQuadInit) -> Root<DOMQuad> {
|
||||||
|
DOMQuad::new(global,
|
||||||
|
&DOMPoint::new_from_init(global, &other.p1),
|
||||||
|
&DOMPoint::new_from_init(global, &other.p2),
|
||||||
|
&DOMPoint::new_from_init(global, &other.p3),
|
||||||
|
&DOMPoint::new_from_init(global, &other.p4))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DOMQuadMethods for DOMQuad {
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-p1
|
||||||
|
fn P1(&self) -> Root<DOMPoint> {
|
||||||
|
Root::from_ref(&self.p1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-p2
|
||||||
|
fn P2(&self) -> Root<DOMPoint> {
|
||||||
|
Root::from_ref(&self.p2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-p3
|
||||||
|
fn P3(&self) -> Root<DOMPoint> {
|
||||||
|
Root::from_ref(&self.p3)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-p4
|
||||||
|
fn P4(&self) -> Root<DOMPoint> {
|
||||||
|
Root::from_ref(&self.p4)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-domquad-getbounds
|
||||||
|
fn GetBounds(&self) -> Root<DOMRect> {
|
||||||
|
let left = self.p1.X().min(self.p2.X()).min(self.p3.X()).min(self.p4.X());
|
||||||
|
let top = self.p1.Y().min(self.p2.Y()).min(self.p3.Y()).min(self.p4.Y());
|
||||||
|
let right = self.p1.X().max(self.p2.X()).max(self.p3.X()).max(self.p4.X());
|
||||||
|
let bottom = self.p1.Y().max(self.p2.Y()).max(self.p3.Y()).max(self.p4.Y());
|
||||||
|
|
||||||
|
DOMRect::new(global_root_from_reflector(self).r(),
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
right - left,
|
||||||
|
bottom - top)
|
||||||
|
}
|
||||||
|
}
|
|
@ -236,6 +236,7 @@ pub mod domimplementation;
|
||||||
pub mod domparser;
|
pub mod domparser;
|
||||||
pub mod dompoint;
|
pub mod dompoint;
|
||||||
pub mod dompointreadonly;
|
pub mod dompointreadonly;
|
||||||
|
pub mod domquad;
|
||||||
pub mod domrect;
|
pub mod domrect;
|
||||||
pub mod domrectlist;
|
pub mod domrectlist;
|
||||||
pub mod domrectreadonly;
|
pub mod domrectreadonly;
|
||||||
|
|
|
@ -20,3 +20,10 @@ interface DOMPoint : DOMPointReadOnly {
|
||||||
inherit attribute unrestricted double z;
|
inherit attribute unrestricted double z;
|
||||||
inherit attribute unrestricted double w;
|
inherit attribute unrestricted double w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary DOMPointInit {
|
||||||
|
unrestricted double x = 0;
|
||||||
|
unrestricted double y = 0;
|
||||||
|
unrestricted double z = 0;
|
||||||
|
unrestricted double w = 1;
|
||||||
|
};
|
||||||
|
|
|
@ -20,10 +20,3 @@ interface DOMPointReadOnly {
|
||||||
readonly attribute unrestricted double z;
|
readonly attribute unrestricted double z;
|
||||||
readonly attribute unrestricted double w;
|
readonly attribute unrestricted double w;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary DOMPointInit {
|
|
||||||
unrestricted double x = 0;
|
|
||||||
unrestricted double y = 0;
|
|
||||||
unrestricted double z = 0;
|
|
||||||
unrestricted double w = 1;
|
|
||||||
};
|
|
||||||
|
|
33
components/script/dom/webidls/DOMQuad.webidl
Normal file
33
components/script/dom/webidls/DOMQuad.webidl
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
/*
|
||||||
|
* The origin of this IDL file is
|
||||||
|
* https://drafts.fxtf.org/geometry/#DOMQuad
|
||||||
|
*
|
||||||
|
* Copyright:
|
||||||
|
* To the extent possible under law, the editors have waived all copyright and
|
||||||
|
* related or neighboring rights to this work.
|
||||||
|
*/
|
||||||
|
|
||||||
|
[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
|
||||||
|
optional DOMPointInit p3, optional DOMPointInit p4),
|
||||||
|
/*Exposed=(Window,Worker)*/]
|
||||||
|
interface DOMQuad {
|
||||||
|
[NewObject] static DOMQuad fromRect(optional DOMRectInit other);
|
||||||
|
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
|
||||||
|
|
||||||
|
[SameObject] readonly attribute DOMPoint p1;
|
||||||
|
[SameObject] readonly attribute DOMPoint p2;
|
||||||
|
[SameObject] readonly attribute DOMPoint p3;
|
||||||
|
[SameObject] readonly attribute DOMPoint p4;
|
||||||
|
[NewObject] DOMRect getBounds();
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary DOMQuadInit {
|
||||||
|
DOMPointInit p1;
|
||||||
|
DOMPointInit p2;
|
||||||
|
DOMPointInit p3;
|
||||||
|
DOMPointInit p4;
|
||||||
|
};
|
|
@ -1,161 +1,62 @@
|
||||||
[DOMQuad-001.htm]
|
[DOMQuad-001.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
[testConstructor0]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor2]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor3]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor4]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor5]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor6]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor7]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor8]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor9]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor10]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor11]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor12]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor13]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor14]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor15]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor16]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[p1Top4Attributes0]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[p1Top4Attributes1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[boundsAttribute0]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[boundsAttribute1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor0: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor0: bounds]
|
[testConstructor0: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor5: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor5: bounds]
|
[testConstructor5: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor6: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor6: bounds]
|
[testConstructor6: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor7: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor7: bounds]
|
[testConstructor7: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor8: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor8: bounds]
|
[testConstructor8: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor9: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor9: bounds]
|
[testConstructor9: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor10: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor10: bounds]
|
[testConstructor10: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor11: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor11: bounds]
|
[testConstructor11: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor12: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor12: bounds]
|
[testConstructor12: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor13: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor13: bounds]
|
[testConstructor13: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor14: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor14: bounds]
|
[testConstructor14: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[testConstructor16: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[testConstructor16: bounds]
|
[testConstructor16: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[p1Top4Attributes0: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[p1Top4Attributes0: bounds]
|
[p1Top4Attributes0: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[p1Top4Attributes1: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[p1Top4Attributes1: bounds]
|
[p1Top4Attributes1: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[boundsAttribute0: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[boundsAttribute0: bounds]
|
[boundsAttribute0: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[boundsAttribute1: points]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[boundsAttribute1: bounds]
|
[boundsAttribute1: bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[testConstructor5: points]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[testConstructor6: points]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[testConstructor7: points]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[boundsAttribute1: points]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ var interfaceNamesInGlobalScope = [
|
||||||
"CSSStyleDeclaration",
|
"CSSStyleDeclaration",
|
||||||
"DOMPoint",
|
"DOMPoint",
|
||||||
"DOMPointReadOnly",
|
"DOMPointReadOnly",
|
||||||
|
"DOMQuad",
|
||||||
"DOMRect",
|
"DOMRect",
|
||||||
"DOMRectReadOnly",
|
"DOMRectReadOnly",
|
||||||
"Comment",
|
"Comment",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue