mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
These interfaces were renamed in the specification, in order to use them in other contexts than the getClientRects and getBoundingClientRect methods.
This commit is contained in:
parent
7d9908d23e
commit
f400cf49c3
10 changed files with 53 additions and 54 deletions
|
@ -2,8 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::ClientRectBinding;
|
use dom::bindings::codegen::Bindings::DOMRectBinding;
|
||||||
use dom::bindings::codegen::Bindings::ClientRectBinding::ClientRectMethods;
|
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||||
use dom::bindings::global::Window;
|
use dom::bindings::global::Window;
|
||||||
use dom::bindings::js::{JSRef, Temporary};
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
@ -11,7 +11,7 @@ use dom::window::Window;
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct ClientRect {
|
pub struct DOMRect {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
top: f32,
|
top: f32,
|
||||||
bottom: f32,
|
bottom: f32,
|
||||||
|
@ -19,10 +19,10 @@ pub struct ClientRect {
|
||||||
right: f32,
|
right: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientRect {
|
impl DOMRect {
|
||||||
pub fn new_inherited(top: Au, bottom: Au,
|
pub fn new_inherited(top: Au, bottom: Au,
|
||||||
left: Au, right: Au) -> ClientRect {
|
left: Au, right: Au) -> DOMRect {
|
||||||
ClientRect {
|
DOMRect {
|
||||||
top: top.to_nearest_px() as f32,
|
top: top.to_nearest_px() as f32,
|
||||||
bottom: bottom.to_nearest_px() as f32,
|
bottom: bottom.to_nearest_px() as f32,
|
||||||
left: left.to_nearest_px() as f32,
|
left: left.to_nearest_px() as f32,
|
||||||
|
@ -33,13 +33,13 @@ impl ClientRect {
|
||||||
|
|
||||||
pub fn new(window: &JSRef<Window>,
|
pub fn new(window: &JSRef<Window>,
|
||||||
top: Au, bottom: Au,
|
top: Au, bottom: Au,
|
||||||
left: Au, right: Au) -> Temporary<ClientRect> {
|
left: Au, right: Au) -> Temporary<DOMRect> {
|
||||||
let rect = ClientRect::new_inherited(top, bottom, left, right);
|
let rect = DOMRect::new_inherited(top, bottom, left, right);
|
||||||
reflect_dom_object(box rect, &Window(*window), ClientRectBinding::Wrap)
|
reflect_dom_object(box rect, &Window(*window), DOMRectBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClientRectMethods for JSRef<'a, ClientRect> {
|
impl<'a> DOMRectMethods for JSRef<'a, DOMRect> {
|
||||||
fn Top(&self) -> f32 {
|
fn Top(&self) -> f32 {
|
||||||
self.top
|
self.top
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ impl<'a> ClientRectMethods for JSRef<'a, ClientRect> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflectable for ClientRect {
|
impl Reflectable for DOMRect {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
&self.reflector_
|
&self.reflector_
|
||||||
}
|
}
|
|
@ -2,26 +2,26 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::ClientRectListBinding;
|
use dom::bindings::codegen::Bindings::DOMRectListBinding;
|
||||||
use dom::bindings::codegen::Bindings::ClientRectListBinding::ClientRectListMethods;
|
use dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods;
|
||||||
use dom::bindings::global::Window;
|
use dom::bindings::global::Window;
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::clientrect::ClientRect;
|
use dom::domrect::DOMRect;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct ClientRectList {
|
pub struct DOMRectList {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
rects: Vec<JS<ClientRect>>,
|
rects: Vec<JS<DOMRect>>,
|
||||||
window: JS<Window>,
|
window: JS<Window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientRectList {
|
impl DOMRectList {
|
||||||
pub fn new_inherited(window: &JSRef<Window>,
|
pub fn new_inherited(window: &JSRef<Window>,
|
||||||
rects: Vec<JSRef<ClientRect>>) -> ClientRectList {
|
rects: Vec<JSRef<DOMRect>>) -> DOMRectList {
|
||||||
let rects = rects.iter().map(|rect| JS::from_rooted(rect)).collect();
|
let rects = rects.iter().map(|rect| JS::from_rooted(rect)).collect();
|
||||||
ClientRectList {
|
DOMRectList {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
rects: rects,
|
rects: rects,
|
||||||
window: JS::from_rooted(window),
|
window: JS::from_rooted(window),
|
||||||
|
@ -29,18 +29,18 @@ impl ClientRectList {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &JSRef<Window>,
|
pub fn new(window: &JSRef<Window>,
|
||||||
rects: Vec<JSRef<ClientRect>>) -> Temporary<ClientRectList> {
|
rects: Vec<JSRef<DOMRect>>) -> Temporary<DOMRectList> {
|
||||||
reflect_dom_object(box ClientRectList::new_inherited(window, rects),
|
reflect_dom_object(box DOMRectList::new_inherited(window, rects),
|
||||||
&Window(*window), ClientRectListBinding::Wrap)
|
&Window(*window), DOMRectListBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> {
|
impl<'a> DOMRectListMethods for JSRef<'a, DOMRectList> {
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
self.rects.len() as u32
|
self.rects.len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Item(&self, index: u32) -> Option<Temporary<ClientRect>> {
|
fn Item(&self, index: u32) -> Option<Temporary<DOMRect>> {
|
||||||
let rects = &self.rects;
|
let rects = &self.rects;
|
||||||
if index < rects.len() as u32 {
|
if index < rects.len() as u32 {
|
||||||
Some(Temporary::new(rects[index as uint].clone()))
|
Some(Temporary::new(rects[index as uint].clone()))
|
||||||
|
@ -49,13 +49,13 @@ impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<ClientRect>> {
|
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<DOMRect>> {
|
||||||
*found = index < self.rects.len() as u32;
|
*found = index < self.rects.len() as u32;
|
||||||
self.Item(index)
|
self.Item(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflectable for ClientRectList {
|
impl Reflectable for DOMRectList {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
&self.reflector_
|
&self.reflector_
|
||||||
}
|
}
|
|
@ -18,8 +18,8 @@ use dom::bindings::trace::Traceable;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter, Syntax};
|
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter, Syntax};
|
||||||
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
|
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
|
||||||
use dom::clientrect::ClientRect;
|
use dom::domrect::DOMRect;
|
||||||
use dom::clientrectlist::ClientRectList;
|
use dom::domrectlist::DOMRectList;
|
||||||
use dom::document::{Document, DocumentHelpers};
|
use dom::document::{Document, DocumentHelpers};
|
||||||
use dom::domtokenlist::DOMTokenList;
|
use dom::domtokenlist::DOMTokenList;
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
|
@ -711,12 +711,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects
|
// http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects
|
||||||
fn GetClientRects(&self) -> Temporary<ClientRectList> {
|
fn GetClientRects(&self) -> Temporary<DOMRectList> {
|
||||||
let win = window_from_node(self).root();
|
let win = window_from_node(self).root();
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
let rects = node.get_content_boxes();
|
let rects = node.get_content_boxes();
|
||||||
let rects: Vec<Root<ClientRect>> = rects.iter().map(|r| {
|
let rects: Vec<Root<DOMRect>> = rects.iter().map(|r| {
|
||||||
ClientRect::new(
|
DOMRect::new(
|
||||||
&*win,
|
&*win,
|
||||||
r.origin.y,
|
r.origin.y,
|
||||||
r.origin.y + r.size.height,
|
r.origin.y + r.size.height,
|
||||||
|
@ -724,15 +724,15 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
r.origin.x + r.size.width).root()
|
r.origin.x + r.size.width).root()
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
ClientRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect())
|
DOMRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
|
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
|
||||||
fn GetBoundingClientRect(&self) -> Temporary<ClientRect> {
|
fn GetBoundingClientRect(&self) -> Temporary<DOMRect> {
|
||||||
let win = window_from_node(self).root();
|
let win = window_from_node(self).root();
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
let rect = node.get_bounding_content_box();
|
let rect = node.get_bounding_content_box();
|
||||||
ClientRect::new(
|
DOMRect::new(
|
||||||
&*win,
|
&*win,
|
||||||
rect.origin.y,
|
rect.origin.y,
|
||||||
rect.origin.y + rect.size.height,
|
rect.origin.y + rect.size.height,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
/* -*- 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
|
/* 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,
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
*/
|
|
||||||
|
|
||||||
interface ClientRect {
|
// http://dev.w3.org/fxtf/geometry/#DOMRect
|
||||||
|
interface DOMRect {
|
||||||
readonly attribute float top;
|
readonly attribute float top;
|
||||||
readonly attribute float right;
|
readonly attribute float right;
|
||||||
readonly attribute float bottom;
|
readonly attribute float bottom;
|
|
@ -1,10 +1,12 @@
|
||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
/* -*- 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
|
/* 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,
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
*/
|
|
||||||
|
|
||||||
interface ClientRectList {
|
// http://dev.w3.org/fxtf/geometry/#DOMRectList
|
||||||
|
[NoInterfaceObject/*,
|
||||||
|
ArrayClass*/]
|
||||||
|
interface DOMRectList {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
getter ClientRect? item(unsigned long index);
|
getter DOMRect? item(unsigned long index);
|
||||||
};
|
};
|
|
@ -54,8 +54,8 @@ interface Element : Node {
|
||||||
|
|
||||||
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface
|
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface
|
||||||
partial interface Element {
|
partial interface Element {
|
||||||
ClientRectList getClientRects();
|
DOMRectList getClientRects();
|
||||||
ClientRect getBoundingClientRect();
|
DOMRect getBoundingClientRect();
|
||||||
};
|
};
|
||||||
|
|
||||||
// http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
|
// http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
|
||||||
|
|
|
@ -80,8 +80,8 @@ pub mod dom {
|
||||||
pub mod browsercontext;
|
pub mod browsercontext;
|
||||||
pub mod canvasrenderingcontext2d;
|
pub mod canvasrenderingcontext2d;
|
||||||
pub mod characterdata;
|
pub mod characterdata;
|
||||||
pub mod clientrect;
|
pub mod domrect;
|
||||||
pub mod clientrectlist;
|
pub mod domrectlist;
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod console;
|
pub mod console;
|
||||||
pub mod customevent;
|
pub mod customevent;
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
<script>
|
<script>
|
||||||
var rect = window.document.head.getBoundingClientRect();
|
var rect = window.document.head.getBoundingClientRect();
|
||||||
var rects = window.document.head.getClientRects();
|
var rects = window.document.head.getClientRects();
|
||||||
is_a(rect, ClientRect);
|
is_a(rect, DOMRect);
|
||||||
is(rect.top, 0);
|
is(rect.top, 0);
|
||||||
is(rect.bottom, 0);
|
is(rect.bottom, 0);
|
||||||
is(rect.left, 0);
|
is(rect.left, 0);
|
||||||
is(rect.right, 0);
|
is(rect.right, 0);
|
||||||
is(rect.width, 0);
|
is(rect.width, 0);
|
||||||
is(rect.height, 0);
|
is(rect.height, 0);
|
||||||
is_a(rects, ClientRectList);
|
|
||||||
is(rects.length, 0);
|
is(rects.length, 0);
|
||||||
finish();
|
finish();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
<head>
|
<head>
|
||||||
<script src="harness.js"></script>
|
<script src="harness.js"></script>
|
||||||
<script>
|
<script>
|
||||||
is_function(ClientRect, "ClientRect");
|
is_function(DOMRect, "DOMRect");
|
||||||
is_function(ClientRectList, "ClientRectList");
|
|
||||||
|
|
||||||
var elems = document.getElementsByTagName('div');
|
var elems = document.getElementsByTagName('div');
|
||||||
var rect = elems[0].getBoundingClientRect();
|
var rect = elems[0].getBoundingClientRect();
|
||||||
is_a(rect, ClientRect);
|
is_a(rect, DOMRect);
|
||||||
|
|
||||||
geq(rect.top, 100);
|
geq(rect.top, 100);
|
||||||
geq(rect.bottom, 200);
|
geq(rect.bottom, 200);
|
||||||
|
|
|
@ -55,8 +55,7 @@ var interfaceNamesInGlobalScope = [
|
||||||
"Blob",
|
"Blob",
|
||||||
"CanvasRenderingContext2D",
|
"CanvasRenderingContext2D",
|
||||||
"CharacterData",
|
"CharacterData",
|
||||||
"ClientRect", // #2814
|
"DOMRect",
|
||||||
"ClientRectList", // #2814
|
|
||||||
"Comment",
|
"Comment",
|
||||||
"Console",
|
"Console",
|
||||||
"CustomEvent",
|
"CustomEvent",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue