Skip to content

Commit

Permalink
Rename ClientRect and ClientRectList to DOMRect and DOMRectList (fixes
Browse files Browse the repository at this point in the history
…#2814, fixes #2840).

These interfaces were renamed in the specification, in order to use them in
other contexts than the getClientRects and getBoundingClientRect methods.
  • Loading branch information
hyunjunekim authored and Ms2ger committed Aug 9, 2014
1 parent 7d9908d commit f400cf4
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 54 deletions.
Expand Up @@ -2,27 +2,27 @@
* 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};
use dom::window::Window;
use servo_util::geometry::Au;

#[deriving(Encodable)]
pub struct ClientRect {
pub struct DOMRect {
reflector_: Reflector,
top: f32,
bottom: f32,
left: f32,
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,
Expand All @@ -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
}
Expand All @@ -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_
}
Expand Down
Expand Up @@ -2,45 +2,45 @@
* 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),
}
}

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()))
Expand All @@ -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_
}
Expand Down
16 changes: 8 additions & 8 deletions src/components/script/dom/element.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -711,28 +711,28 @@ 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,
r.origin.x,
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,
Expand Down
@@ -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;
Expand Down
@@ -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);
};
4 changes: 2 additions & 2 deletions src/components/script/dom/webidls/Element.webidl
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/components/script/script.rs
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/test/content/test_empty_clientrect.html
Expand Up @@ -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>
Expand Down
5 changes: 2 additions & 3 deletions src/test/content/test_getBoundingClientRect.html
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/test/content/test_interfaces.html
Expand Up @@ -55,8 +55,7 @@
"Blob",
"CanvasRenderingContext2D",
"CharacterData",
"ClientRect", // #2814
"ClientRectList", // #2814
"DOMRect",
"Comment",
"Console",
"CustomEvent",
Expand Down

0 comments on commit f400cf4

Please sign in to comment.