Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8882 - GuillaumeGomez:dom_quad, r=nox
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
Showing
8 changed files
with
174 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
115
tests/wpt/metadata-css/geometry-1_dev/html/DOMQuad-001.htm.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters