aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2015-12-08 00:40:31 +0100
committerggomez <ggomez@ggo.ifr.lan>2015-12-18 17:37:10 +0100
commit823e1b96c3bd61c458f6ef91e2695c88f5312e09 (patch)
treefc24ceef96bc2b4a4b5a8c2a69d9f33fbc8985ec
parent338f66003e78250ce141584e87190661249c5589 (diff)
downloadservo-823e1b96c3bd61c458f6ef91e2695c88f5312e09.tar.gz
servo-823e1b96c3bd61c458f6ef91e2695c88f5312e09.zip
Add DOMQuad element
-rw-r--r--components/script/dom/dompoint.rs6
-rw-r--r--components/script/dom/domquad.rs119
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webidls/DOMPoint.webidl7
-rw-r--r--components/script/dom/webidls/DOMPointReadOnly.webidl7
-rw-r--r--components/script/dom/webidls/DOMQuad.webidl33
-rw-r--r--tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini115
-rw-r--r--tests/wpt/mozilla/tests/mozilla/interfaces.html1
8 files changed, 174 insertions, 115 deletions
diff --git a/components/script/dom/dompoint.rs b/components/script/dom/dompoint.rs
index e654b56c730..906a30ea617 100644
--- a/components/script/dom/dompoint.rs
+++ b/components/script/dom/dompoint.rs
@@ -2,7 +2,7 @@
* 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::{DOMPointMethods, Wrap};
+use dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointInit, DOMPointMethods, Wrap};
use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
@@ -35,6 +35,10 @@ impl DOMPoint {
-> Fallible<Root<DOMPoint>> {
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 {
diff --git a/components/script/dom/domquad.rs b/components/script/dom/domquad.rs
new file mode 100644
index 00000000000..bdbc45737ba
--- /dev/null
+++ b/components/script/dom/domquad.rs
@@ -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)
+ }
+}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 5e4c5609735..dedbcff986a 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -236,6 +236,7 @@ pub mod domimplementation;
pub mod domparser;
pub mod dompoint;
pub mod dompointreadonly;
+pub mod domquad;
pub mod domrect;
pub mod domrectlist;
pub mod domrectreadonly;
diff --git a/components/script/dom/webidls/DOMPoint.webidl b/components/script/dom/webidls/DOMPoint.webidl
index f3b9d8cd3c5..b8fc78d571f 100644
--- a/components/script/dom/webidls/DOMPoint.webidl
+++ b/components/script/dom/webidls/DOMPoint.webidl
@@ -20,3 +20,10 @@ interface DOMPoint : DOMPointReadOnly {
inherit attribute unrestricted double z;
inherit attribute unrestricted double w;
};
+
+dictionary DOMPointInit {
+ unrestricted double x = 0;
+ unrestricted double y = 0;
+ unrestricted double z = 0;
+ unrestricted double w = 1;
+};
diff --git a/components/script/dom/webidls/DOMPointReadOnly.webidl b/components/script/dom/webidls/DOMPointReadOnly.webidl
index cab781a2f97..021d129f132 100644
--- a/components/script/dom/webidls/DOMPointReadOnly.webidl
+++ b/components/script/dom/webidls/DOMPointReadOnly.webidl
@@ -20,10 +20,3 @@ interface DOMPointReadOnly {
readonly attribute unrestricted double z;
readonly attribute unrestricted double w;
};
-
-dictionary DOMPointInit {
- unrestricted double x = 0;
- unrestricted double y = 0;
- unrestricted double z = 0;
- unrestricted double w = 1;
-};
diff --git a/components/script/dom/webidls/DOMQuad.webidl b/components/script/dom/webidls/DOMQuad.webidl
new file mode 100644
index 00000000000..0f3f11fac41
--- /dev/null
+++ b/components/script/dom/webidls/DOMQuad.webidl
@@ -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;
+};
diff --git a/tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini b/tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini
index 6cebe3a3ea3..bd13dfe7b40 100644
--- a/tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini
+++ b/tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini
@@ -1,161 +1,62 @@
[DOMQuad-001.htm]
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]
expected: FAIL
- [testConstructor5: points]
- expected: FAIL
-
[testConstructor5: bounds]
expected: FAIL
- [testConstructor6: points]
- expected: FAIL
-
[testConstructor6: bounds]
expected: FAIL
- [testConstructor7: points]
- expected: FAIL
-
[testConstructor7: bounds]
expected: FAIL
- [testConstructor8: points]
- expected: FAIL
-
[testConstructor8: bounds]
expected: FAIL
- [testConstructor9: points]
- expected: FAIL
-
[testConstructor9: bounds]
expected: FAIL
- [testConstructor10: points]
- expected: FAIL
-
[testConstructor10: bounds]
expected: FAIL
- [testConstructor11: points]
- expected: FAIL
-
[testConstructor11: bounds]
expected: FAIL
- [testConstructor12: points]
- expected: FAIL
-
[testConstructor12: bounds]
expected: FAIL
- [testConstructor13: points]
- expected: FAIL
-
[testConstructor13: bounds]
expected: FAIL
- [testConstructor14: points]
- expected: FAIL
-
[testConstructor14: bounds]
expected: FAIL
- [testConstructor16: points]
- expected: FAIL
-
[testConstructor16: bounds]
expected: FAIL
- [p1Top4Attributes0: points]
+ [p1Top4Attributes0: bounds]
expected: FAIL
- [p1Top4Attributes0: bounds]
+ [p1Top4Attributes1: bounds]
expected: FAIL
- [p1Top4Attributes1: points]
+ [boundsAttribute0: bounds]
expected: FAIL
- [p1Top4Attributes1: bounds]
+ [boundsAttribute1: bounds]
expected: FAIL
- [boundsAttribute0: points]
+ [testConstructor5: points]
expected: FAIL
- [boundsAttribute0: bounds]
+ [testConstructor6: points]
expected: FAIL
- [boundsAttribute1: points]
+ [testConstructor7: points]
expected: FAIL
- [boundsAttribute1: bounds]
+ [boundsAttribute1: points]
expected: FAIL
diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.html b/tests/wpt/mozilla/tests/mozilla/interfaces.html
index 9197cafb539..abf00decb61 100644
--- a/tests/wpt/mozilla/tests/mozilla/interfaces.html
+++ b/tests/wpt/mozilla/tests/mozilla/interfaces.html
@@ -81,6 +81,7 @@ var interfaceNamesInGlobalScope = [
"CSSStyleDeclaration",
"DOMPoint",
"DOMPointReadOnly",
+ "DOMQuad",
"DOMRect",
"DOMRectReadOnly",
"Comment",