mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::ClientRectBinding;
|
||||
use dom::bindings::codegen::Bindings::ClientRectBinding::ClientRectMethods;
|
||||
use dom::bindings::codegen::Bindings::DOMRectBinding;
|
||||
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||
use dom::bindings::global::Window;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -11,7 +11,7 @@ use dom::window::Window;
|
|||
use servo_util::geometry::Au;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct ClientRect {
|
||||
pub struct DOMRect {
|
||||
reflector_: Reflector,
|
||||
top: f32,
|
||||
bottom: f32,
|
||||
|
@ -19,10 +19,10 @@ pub struct ClientRect {
|
|||
right: f32,
|
||||
}
|
||||
|
||||
impl ClientRect {
|
||||
impl DOMRect {
|
||||
pub fn new_inherited(top: Au, bottom: Au,
|
||||
left: Au, right: Au) -> ClientRect {
|
||||
ClientRect {
|
||||
left: Au, right: Au) -> DOMRect {
|
||||
DOMRect {
|
||||
top: top.to_nearest_px() as f32,
|
||||
bottom: bottom.to_nearest_px() as f32,
|
||||
left: left.to_nearest_px() as f32,
|
||||
|
@ -33,13 +33,13 @@ impl ClientRect {
|
|||
|
||||
pub fn new(window: &JSRef<Window>,
|
||||
top: Au, bottom: Au,
|
||||
left: Au, right: Au) -> Temporary<ClientRect> {
|
||||
let rect = ClientRect::new_inherited(top, bottom, left, right);
|
||||
reflect_dom_object(box rect, &Window(*window), ClientRectBinding::Wrap)
|
||||
left: Au, right: Au) -> Temporary<DOMRect> {
|
||||
let rect = DOMRect::new_inherited(top, bottom, left, right);
|
||||
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 {
|
||||
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 {
|
||||
&self.reflector_
|
||||
}
|
|
@ -2,26 +2,26 @@
|
|||
* 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::ClientRectListBinding;
|
||||
use dom::bindings::codegen::Bindings::ClientRectListBinding::ClientRectListMethods;
|
||||
use dom::bindings::codegen::Bindings::DOMRectListBinding;
|
||||
use dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods;
|
||||
use dom::bindings::global::Window;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::clientrect::ClientRect;
|
||||
use dom::domrect::DOMRect;
|
||||
use dom::window::Window;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct ClientRectList {
|
||||
pub struct DOMRectList {
|
||||
reflector_: Reflector,
|
||||
rects: Vec<JS<ClientRect>>,
|
||||
rects: Vec<JS<DOMRect>>,
|
||||
window: JS<Window>,
|
||||
}
|
||||
|
||||
impl ClientRectList {
|
||||
impl DOMRectList {
|
||||
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();
|
||||
ClientRectList {
|
||||
DOMRectList {
|
||||
reflector_: Reflector::new(),
|
||||
rects: rects,
|
||||
window: JS::from_rooted(window),
|
||||
|
@ -29,18 +29,18 @@ impl ClientRectList {
|
|||
}
|
||||
|
||||
pub fn new(window: &JSRef<Window>,
|
||||
rects: Vec<JSRef<ClientRect>>) -> Temporary<ClientRectList> {
|
||||
reflect_dom_object(box ClientRectList::new_inherited(window, rects),
|
||||
&Window(*window), ClientRectListBinding::Wrap)
|
||||
rects: Vec<JSRef<DOMRect>>) -> Temporary<DOMRectList> {
|
||||
reflect_dom_object(box DOMRectList::new_inherited(window, rects),
|
||||
&Window(*window), DOMRectListBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> {
|
||||
impl<'a> DOMRectListMethods for JSRef<'a, DOMRectList> {
|
||||
fn Length(&self) -> 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;
|
||||
if index < rects.len() as u32 {
|
||||
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;
|
||||
self.Item(index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for ClientRectList {
|
||||
impl Reflectable for DOMRectList {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
&self.reflector_
|
||||
}
|
|
@ -18,8 +18,8 @@ use dom::bindings::trace::Traceable;
|
|||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter, Syntax};
|
||||
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
|
||||
use dom::clientrect::ClientRect;
|
||||
use dom::clientrectlist::ClientRectList;
|
||||
use dom::domrect::DOMRect;
|
||||
use dom::domrectlist::DOMRectList;
|
||||
use dom::document::{Document, DocumentHelpers};
|
||||
use dom::domtokenlist::DOMTokenList;
|
||||
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
|
||||
fn GetClientRects(&self) -> Temporary<ClientRectList> {
|
||||
fn GetClientRects(&self) -> Temporary<DOMRectList> {
|
||||
let win = window_from_node(self).root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let rects = node.get_content_boxes();
|
||||
let rects: Vec<Root<ClientRect>> = rects.iter().map(|r| {
|
||||
ClientRect::new(
|
||||
let rects: Vec<Root<DOMRect>> = rects.iter().map(|r| {
|
||||
DOMRect::new(
|
||||
&*win,
|
||||
r.origin.y,
|
||||
r.origin.y + r.size.height,
|
||||
|
@ -724,15 +724,15 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
r.origin.x + r.size.width).root()
|
||||
}).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
|
||||
fn GetBoundingClientRect(&self) -> Temporary<ClientRect> {
|
||||
fn GetBoundingClientRect(&self) -> Temporary<DOMRect> {
|
||||
let win = window_from_node(self).root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let rect = node.get_bounding_content_box();
|
||||
ClientRect::new(
|
||||
DOMRect::new(
|
||||
&*win,
|
||||
rect.origin.y,
|
||||
rect.origin.y + rect.size.height,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* -*- 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/.
|
||||
*/
|
||||
* 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/. */
|
||||
|
||||
interface ClientRect {
|
||||
// http://dev.w3.org/fxtf/geometry/#DOMRect
|
||||
interface DOMRect {
|
||||
readonly attribute float top;
|
||||
readonly attribute float right;
|
||||
readonly attribute float bottom;
|
|
@ -1,10 +1,12 @@
|
|||
/* -*- 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/.
|
||||
*/
|
||||
* 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/. */
|
||||
|
||||
interface ClientRectList {
|
||||
// http://dev.w3.org/fxtf/geometry/#DOMRectList
|
||||
[NoInterfaceObject/*,
|
||||
ArrayClass*/]
|
||||
interface DOMRectList {
|
||||
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
|
||||
partial interface Element {
|
||||
ClientRectList getClientRects();
|
||||
ClientRect getBoundingClientRect();
|
||||
DOMRectList getClientRects();
|
||||
DOMRect getBoundingClientRect();
|
||||
};
|
||||
|
||||
// http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
|
||||
|
|
|
@ -80,8 +80,8 @@ pub mod dom {
|
|||
pub mod browsercontext;
|
||||
pub mod canvasrenderingcontext2d;
|
||||
pub mod characterdata;
|
||||
pub mod clientrect;
|
||||
pub mod clientrectlist;
|
||||
pub mod domrect;
|
||||
pub mod domrectlist;
|
||||
pub mod comment;
|
||||
pub mod console;
|
||||
pub mod customevent;
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
<script>
|
||||
var rect = window.document.head.getBoundingClientRect();
|
||||
var rects = window.document.head.getClientRects();
|
||||
is_a(rect, ClientRect);
|
||||
is_a(rect, DOMRect);
|
||||
is(rect.top, 0);
|
||||
is(rect.bottom, 0);
|
||||
is(rect.left, 0);
|
||||
is(rect.right, 0);
|
||||
is(rect.width, 0);
|
||||
is(rect.height, 0);
|
||||
is_a(rects, ClientRectList);
|
||||
is(rects.length, 0);
|
||||
finish();
|
||||
</script>
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
<head>
|
||||
<script src="harness.js"></script>
|
||||
<script>
|
||||
is_function(ClientRect, "ClientRect");
|
||||
is_function(ClientRectList, "ClientRectList");
|
||||
is_function(DOMRect, "DOMRect");
|
||||
|
||||
var elems = document.getElementsByTagName('div');
|
||||
var rect = elems[0].getBoundingClientRect();
|
||||
is_a(rect, ClientRect);
|
||||
is_a(rect, DOMRect);
|
||||
|
||||
geq(rect.top, 100);
|
||||
geq(rect.bottom, 200);
|
||||
|
|
|
@ -55,8 +55,7 @@ var interfaceNamesInGlobalScope = [
|
|||
"Blob",
|
||||
"CanvasRenderingContext2D",
|
||||
"CharacterData",
|
||||
"ClientRect", // #2814
|
||||
"ClientRectList", // #2814
|
||||
"DOMRect",
|
||||
"Comment",
|
||||
"Console",
|
||||
"CustomEvent",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue