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.
This commit is contained in:
Till Schneidereit 2015-07-21 17:03:45 +02:00
parent 3a5e4335d7
commit b692187ca2
47 changed files with 855 additions and 28 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;
};

View file

@ -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;
};

View file

@ -1,5 +1,11 @@
skip: true
[css21_dev]
skip: false
[xhtml1]
skip: true
[xhtml1print]
skip: true
[geometry-1_dev]
skip: false
[xhtml1]
skip: true

View file

@ -1,4 +1,4 @@
[color-applies-to-001.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-002.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-003.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-004.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-005.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-006.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-013.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[color-applies-to-015.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,5 +1,5 @@
[content-177.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,4 +1,4 @@
[display-008.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[display-009.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[float-applies-to-008.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,5 +1,5 @@
[font-size-001.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-002.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-004.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-005.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-089.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-090.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-092.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-093.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-100.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-101.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[font-size-102.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,4 +1,4 @@
[inline-block-zorder-003.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[inline-formatting-context-004.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,4 +1,4 @@
[inline-formatting-context-005.htm]
type: reftest
expected:
if (os == "mac"): FAIL
if os == "mac": FAIL

View file

@ -1,5 +1,5 @@
[line-height-121.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -1,5 +1,5 @@
[line-height-127.htm]
type: reftest
expected:
if (os == "mac"): PASS
if os == "mac": PASS
FAIL

View file

@ -0,0 +1,53 @@
[DOMMatrix-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
[testConstructorIllegal0]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,41 @@
[DOMPoint-001.htm]
type: testharness
[testConstructorDictionary2undefined]
expected: FAIL
[testConstructor1]
expected: FAIL
[testConstructorDictionary0]
expected: FAIL
[testConstructorDictionary1]
expected: FAIL
[testConstructorDictionary2]
expected: FAIL
[testConstructorDictionary3]
expected: FAIL
[testConstructorDictionary4]
expected: FAIL
[testConstructorDictionary5]
expected: FAIL
[testConstructorDictionary2irregular]
expected: FAIL
[testConstructorDOMPoint]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,65 @@
[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

View file

@ -0,0 +1,44 @@
[DOMRect-001.htm]
type: testharness
[testConstructor0]
expected: FAIL
[testConstructor4]
expected: FAIL
[testConstructor5]
expected: FAIL
[testConstructorNegativeWidth]
expected: FAIL
[testConstructorNegativeHeight]
expected: FAIL
[testConstructorNegativeWidthHeight]
expected: FAIL
[testConstructorUndefined1]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorString1]
expected: FAIL
[testConstructorString2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL
[testSetReadOnlyAttributes]
expected: FAIL
[testSetAttributes]
expected: FAIL

View file

@ -0,0 +1,53 @@
[DOMMatrix-001.xht]
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
[testConstructorIllegal0]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,41 @@
[DOMPoint-001.xht]
type: testharness
[testConstructorDictionary2undefined]
expected: FAIL
[testConstructor1]
expected: FAIL
[testConstructorDictionary0]
expected: FAIL
[testConstructorDictionary1]
expected: FAIL
[testConstructorDictionary2]
expected: FAIL
[testConstructorDictionary3]
expected: FAIL
[testConstructorDictionary4]
expected: FAIL
[testConstructorDictionary5]
expected: FAIL
[testConstructorDictionary2irregular]
expected: FAIL
[testConstructorDOMPoint]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,65 @@
[DOMQuad-001.xht]
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

View file

@ -0,0 +1,44 @@
[DOMRect-001.xht]
type: testharness
[testConstructor0]
expected: FAIL
[testConstructor4]
expected: FAIL
[testConstructor5]
expected: FAIL
[testConstructorNegativeWidth]
expected: FAIL
[testConstructorNegativeHeight]
expected: FAIL
[testConstructorNegativeWidthHeight]
expected: FAIL
[testConstructorUndefined1]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorString1]
expected: FAIL
[testConstructorString2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL
[testSetReadOnlyAttributes]
expected: FAIL
[testSetAttributes]
expected: FAIL

View file

@ -0,0 +1,53 @@
[DOMMatrix-001.xht]
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
[testConstructorIllegal0]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,41 @@
[DOMPoint-001.xht]
type: testharness
[testConstructorDictionary2undefined]
expected: FAIL
[testConstructor1]
expected: FAIL
[testConstructorDictionary0]
expected: FAIL
[testConstructorDictionary1]
expected: FAIL
[testConstructorDictionary2]
expected: FAIL
[testConstructorDictionary3]
expected: FAIL
[testConstructorDictionary4]
expected: FAIL
[testConstructorDictionary5]
expected: FAIL
[testConstructorDictionary2irregular]
expected: FAIL
[testConstructorDOMPoint]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL

View file

@ -0,0 +1,65 @@
[DOMQuad-001.xht]
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

View file

@ -0,0 +1,44 @@
[DOMRect-001.xht]
type: testharness
[testConstructor0]
expected: FAIL
[testConstructor4]
expected: FAIL
[testConstructor5]
expected: FAIL
[testConstructorNegativeWidth]
expected: FAIL
[testConstructorNegativeHeight]
expected: FAIL
[testConstructorNegativeWidthHeight]
expected: FAIL
[testConstructorUndefined1]
expected: FAIL
[testConstructorUndefined2]
expected: FAIL
[testConstructorString1]
expected: FAIL
[testConstructorString2]
expected: FAIL
[testConstructorIllegal1]
expected: FAIL
[testConstructorIllegal2]
expected: FAIL
[testSetReadOnlyAttributes]
expected: FAIL
[testSetAttributes]
expected: FAIL

View file

@ -79,6 +79,8 @@ var interfaceNamesInGlobalScope = [
"CloseEvent",
"CSS",
"CSSStyleDeclaration",
"DOMPoint",
"DOMPointReadOnly",
"DOMRect",
"Comment",
"Console",