diff options
author | Till Schneidereit <till@tillschneidereit.net> | 2015-07-21 17:03:45 +0200 |
---|---|---|
committer | Till Schneidereit <till@tillschneidereit.net> | 2015-07-23 19:09:36 +0200 |
commit | b692187ca242fbbac7a49ab97c93b8b0f83165d7 (patch) | |
tree | 248cdc3b43f6929bf5a326f0cde22947eedd7f48 /components/script | |
parent | 3a5e4335d7ff993a859bc5876243423fe4936441 (diff) | |
download | servo-b692187ca242fbbac7a49ab97c93b8b0f83165d7.tar.gz servo-b692187ca242fbbac7a49ab97c93b8b0f83165d7.zip |
Implement DOMPoint and DOMPointReadOnly
Passes some but not all WPT tests. One failure is caused by an issue in codegen for the `DOMPointInit` dictionary, the others by outdated tests: Gecko implements an old version of the spec that overloaded the `DOMPoint` constructor to optionally take an object as the first argument, and made `DOMPointReadOnly` non-constructible.
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/dompoint.rs | 69 | ||||
-rw-r--r-- | components/script/dom/dompointreadonly.rs | 88 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 2 | ||||
-rw-r--r-- | components/script/dom/webidls/DOMPoint.webidl | 22 | ||||
-rw-r--r-- | components/script/dom/webidls/DOMPointReadOnly.webidl | 29 |
5 files changed, 210 insertions, 0 deletions
diff --git a/components/script/dom/dompoint.rs b/components/script/dom/dompoint.rs new file mode 100644 index 00000000000..9e392da03db --- /dev/null +++ b/components/script/dom/dompoint.rs @@ -0,0 +1,69 @@ +/* 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::{DOMPointMethods, Wrap}; +use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods; +use dom::bindings::error::Fallible; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::Root; +use dom::bindings::utils::reflect_dom_object; +use dom::dompointreadonly::{DOMPointReadOnly, DOMPointWriteMethods}; + +// http://dev.w3.org/fxtf/geometry/Overview.html#dompoint +#[dom_struct] +pub struct DOMPoint { + point: DOMPointReadOnly +} + +impl DOMPoint { + fn new_inherited(x: f64, y: f64, z: f64, w: f64) -> DOMPoint { + DOMPoint { + point: DOMPointReadOnly::new_inherited(x, y, z, w), + } + } + + pub fn new(global: GlobalRef, x: f64, y: f64, z: f64, w: f64) -> Root<DOMPoint> { + reflect_dom_object(box DOMPoint::new_inherited(x, y, z, w), global, Wrap) + } + + pub fn Constructor(global: GlobalRef, + x: f64, y: f64, z: f64, w: f64) -> Fallible<Root<DOMPoint>> { + Ok(DOMPoint::new(global, x, y, z, w)) + } +} + +impl<'a> DOMPointMethods for &'a DOMPoint { + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x + fn X(self) -> f64 { + self.point.X() + } + fn SetX(self, value: f64) { + self.point.SetX(value); + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-y + fn Y(self) -> f64 { + self.point.Y() + } + fn SetY(self, value: f64) { + self.point.SetY(value); + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-z + fn Z(self) -> f64 { + self.point.Z() + } + fn SetZ(self, value: f64) { + self.point.SetZ(value); + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-w + fn W(self) -> f64 { + self.point.W() + } + fn SetW(self, value: f64) { + self.point.SetW(value); + } +} + diff --git a/components/script/dom/dompointreadonly.rs b/components/script/dom/dompointreadonly.rs new file mode 100644 index 00000000000..c6f40dfa7ef --- /dev/null +++ b/components/script/dom/dompointreadonly.rs @@ -0,0 +1,88 @@ +/* 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::DOMPointReadOnlyBinding::{DOMPointReadOnlyMethods, Wrap}; +use dom::bindings::error::Fallible; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::Root; +use dom::bindings::utils::{Reflector, reflect_dom_object}; +use std::cell::Cell; + +// http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly +#[dom_struct] +pub struct DOMPointReadOnly { + reflector_: Reflector, + x: Cell<f64>, + y: Cell<f64>, + z: Cell<f64>, + w: Cell<f64>, +} + +impl DOMPointReadOnly { + pub fn new_inherited(x: f64, y: f64, z: f64, w: f64) -> DOMPointReadOnly { + DOMPointReadOnly { + x: Cell::new(x), + y: Cell::new(y), + z: Cell::new(z), + w: Cell::new(w), + reflector_: Reflector::new(), + } + } + + pub fn new(global: GlobalRef, x: f64, y: f64, z: f64, w: f64) -> Root<DOMPointReadOnly> { + reflect_dom_object(box DOMPointReadOnly::new_inherited(x, y, z, w), global, Wrap) + } + + pub fn Constructor(global: GlobalRef, + x: f64, y: f64, z: f64, w: f64) -> Fallible<Root<DOMPointReadOnly>> { + Ok(DOMPointReadOnly::new(global, x, y, z, w)) + } +} + +impl<'a> DOMPointReadOnlyMethods for &'a DOMPointReadOnly { + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x + fn X(self) -> f64 { + self.x.get() + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-y + fn Y(self) -> f64 { + self.y.get() + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-z + fn Z(self) -> f64 { + self.z.get() + } + + // http://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-w + fn W(self) -> f64 { + self.w.get() + } +} + +pub trait DOMPointWriteMethods { + fn SetX(self, value: f64); + fn SetY(self, value: f64); + fn SetZ(self, value: f64); + fn SetW(self, value: f64); +} + +impl<'a> DOMPointWriteMethods for &'a DOMPointReadOnly { + fn SetX(self, value: f64) { + self.x.set(value); + } + + fn SetY(self, value: f64) { + self.y.set(value); + } + + fn SetZ(self, value: f64) { + self.z.set(value); + } + + fn SetW(self, value: f64) { + self.w.set(value); + } +} diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 88695f8cc04..d3294cb184b 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -190,6 +190,8 @@ pub mod canvasrenderingcontext2d; pub mod characterdata; pub mod css; pub mod cssstyledeclaration; +pub mod dompoint; +pub mod dompointreadonly; pub mod domrect; pub mod domrectlist; pub mod domstringmap; diff --git a/components/script/dom/webidls/DOMPoint.webidl b/components/script/dom/webidls/DOMPoint.webidl new file mode 100644 index 00000000000..6903ff99458 --- /dev/null +++ b/components/script/dom/webidls/DOMPoint.webidl @@ -0,0 +1,22 @@ +/* -*- 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 + * http://dev.w3.org/fxtf/geometry/ + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// http://dev.w3.org/fxtf/geometry/Overview.html#dompoint +[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, + optional unrestricted double z = 0, optional unrestricted double w = 1), + /*Exposed=(Window,Worker)*/] +interface DOMPoint : DOMPointReadOnly { + inherit attribute unrestricted double x; + inherit attribute unrestricted double y; + inherit attribute unrestricted double z; + inherit attribute unrestricted double w; +}; diff --git a/components/script/dom/webidls/DOMPointReadOnly.webidl b/components/script/dom/webidls/DOMPointReadOnly.webidl new file mode 100644 index 00000000000..6bff491a58c --- /dev/null +++ b/components/script/dom/webidls/DOMPointReadOnly.webidl @@ -0,0 +1,29 @@ +/* -*- 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 + * http://dev.w3.org/fxtf/geometry/ + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly +[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, + optional unrestricted double z = 0, optional unrestricted double w = 1), + /*Exposed=(Window,Worker)*/] +interface DOMPointReadOnly { + readonly attribute unrestricted double x; + readonly attribute unrestricted double y; + 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; +}; |