diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 1f8014f2ac1..366c33fecbe 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -5,6 +5,7 @@ use dom::bindings::codegen::ClientRectBinding; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; +use servo_util::geometry::Au; pub struct ClientRect { reflector_: Reflector, @@ -17,25 +18,26 @@ pub struct ClientRect { impl ClientRect { pub fn new_inherited(window: @mut Window, - top: f32, bottom: f32, - left: f32, right: f32) -> ClientRect { + top: Au, bottom: Au, + left: Au, right: Au) -> ClientRect { ClientRect { - top: top, - bottom: bottom, - left: left, - right: right, + top: top.to_nearest_px() as f32, + bottom: bottom.to_nearest_px() as f32, + left: left.to_nearest_px() as f32, + right: right.to_nearest_px() as f32, reflector_: Reflector::new(), window: window, } } pub fn new(window: @mut Window, - top: f32, bottom: f32, - left: f32, right: f32) -> @mut ClientRect { + top: Au, bottom: Au, + left: Au, right: Au) -> @mut ClientRect { let rect = ClientRect::new_inherited(window, top, bottom, left, right); reflect_dom_object(@mut rect, window, ClientRectBinding::Wrap) } + pub fn Top(&self) -> f32 { self.top } diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 0d2229c6791..386d0a29dc0 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -415,10 +415,10 @@ impl Element { do rects.map |r| { ClientRect::new( win, - r.origin.y.to_f32().unwrap(), - (r.origin.y + r.size.height).to_f32().unwrap(), - r.origin.x.to_f32().unwrap(), - (r.origin.x + r.size.width).to_f32().unwrap()) + r.origin.y, + r.origin.y + r.size.height, + r.origin.x, + r.origin.x + r.size.width) } }, }; @@ -435,10 +435,10 @@ impl Element { ContentBoxResponse(rect) => { ClientRect::new( win, - rect.origin.y.to_f32().unwrap(), - (rect.origin.y + rect.size.height).to_f32().unwrap(), - rect.origin.x.to_f32().unwrap(), - (rect.origin.x + rect.size.width).to_f32().unwrap()) + rect.origin.y, + rect.origin.y + rect.size.height, + rect.origin.x, + rect.origin.x + rect.size.width) } } } diff --git a/src/test/html/content/test_getBoundingClientRect.html b/src/test/html/content/test_getBoundingClientRect.html index 8ccd55a7df3..4f25d97141c 100644 --- a/src/test/html/content/test_getBoundingClientRect.html +++ b/src/test/html/content/test_getBoundingClientRect.html @@ -10,10 +10,12 @@ var rect = elems[0].getBoundingClientRect(); is_a(rect, ClientRect); geq(rect.top, 100); -geq(rect.bottom, 100); +geq(rect.bottom, 200); geq(rect.left, 100); -geq(rect.right, 100); +geq(rect.right, 200); +is(rect.width, 100); +is(rect.height, 100); is(rect.width, rect.right - rect.left); is(rect.height, rect.bottom - rect.top); @@ -23,6 +25,8 @@ finish(); div { margin-top: 100px; margin-left: 100px; + width: 100px; + height: 100px; }