fix unit of clientrect &

add width,height test in src/test/html/content/test_getBoundingClientRect.html
This commit is contained in:
patrick kim 2013-12-31 11:09:17 +09:00
parent 2b487ed3e9
commit e0a04fff46
3 changed files with 24 additions and 18 deletions

View file

@ -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
}

View file

@ -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)
}
}
}

View file

@ -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;
}
</style>
</head>