Skip to content

Commit

Permalink
Auto merge of #8882 - GuillaumeGomez:dom_quad, r=nox
Browse files Browse the repository at this point in the history
Add DOMQuad element

cc  @nox

Part of #8821

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8882)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 18, 2015
2 parents 6764cf0 + 823e1b9 commit 6ba4ef2
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 115 deletions.
6 changes: 5 additions & 1 deletion components/script/dom/dompoint.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
119 changes: 119 additions & 0 deletions 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)
}
}
1 change: 1 addition & 0 deletions components/script/dom/mod.rs
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions components/script/dom/webidls/DOMPoint.webidl
Expand Up @@ -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;
};
7 changes: 0 additions & 7 deletions components/script/dom/webidls/DOMPointReadOnly.webidl
Expand Up @@ -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;
};
33 changes: 33 additions & 0 deletions 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;
};
115 changes: 8 additions & 107 deletions 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

1 change: 1 addition & 0 deletions tests/wpt/mozilla/tests/mozilla/interfaces.html
Expand Up @@ -81,6 +81,7 @@
"CSSStyleDeclaration",
"DOMPoint",
"DOMPointReadOnly",
"DOMQuad",
"DOMRect",
"DOMRectReadOnly",
"Comment",
Expand Down

0 comments on commit 6ba4ef2

Please sign in to comment.