mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
fix unit of clientrect &
add width,height test in src/test/html/content/test_getBoundingClientRect.html
This commit is contained in:
parent
2b487ed3e9
commit
e0a04fff46
3 changed files with 24 additions and 18 deletions
|
@ -5,6 +5,7 @@
|
||||||
use dom::bindings::codegen::ClientRectBinding;
|
use dom::bindings::codegen::ClientRectBinding;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
use servo_util::geometry::Au;
|
||||||
|
|
||||||
pub struct ClientRect {
|
pub struct ClientRect {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -17,25 +18,26 @@ pub struct ClientRect {
|
||||||
|
|
||||||
impl ClientRect {
|
impl ClientRect {
|
||||||
pub fn new_inherited(window: @mut Window,
|
pub fn new_inherited(window: @mut Window,
|
||||||
top: f32, bottom: f32,
|
top: Au, bottom: Au,
|
||||||
left: f32, right: f32) -> ClientRect {
|
left: Au, right: Au) -> ClientRect {
|
||||||
ClientRect {
|
ClientRect {
|
||||||
top: top,
|
top: top.to_nearest_px() as f32,
|
||||||
bottom: bottom,
|
bottom: bottom.to_nearest_px() as f32,
|
||||||
left: left,
|
left: left.to_nearest_px() as f32,
|
||||||
right: right,
|
right: right.to_nearest_px() as f32,
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
window: window,
|
window: window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: @mut Window,
|
pub fn new(window: @mut Window,
|
||||||
top: f32, bottom: f32,
|
top: Au, bottom: Au,
|
||||||
left: f32, right: f32) -> @mut ClientRect {
|
left: Au, right: Au) -> @mut ClientRect {
|
||||||
let rect = ClientRect::new_inherited(window, top, bottom, left, right);
|
let rect = ClientRect::new_inherited(window, top, bottom, left, right);
|
||||||
reflect_dom_object(@mut rect, window, ClientRectBinding::Wrap)
|
reflect_dom_object(@mut rect, window, ClientRectBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn Top(&self) -> f32 {
|
pub fn Top(&self) -> f32 {
|
||||||
self.top
|
self.top
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,10 +415,10 @@ impl Element {
|
||||||
do rects.map |r| {
|
do rects.map |r| {
|
||||||
ClientRect::new(
|
ClientRect::new(
|
||||||
win,
|
win,
|
||||||
r.origin.y.to_f32().unwrap(),
|
r.origin.y,
|
||||||
(r.origin.y + r.size.height).to_f32().unwrap(),
|
r.origin.y + r.size.height,
|
||||||
r.origin.x.to_f32().unwrap(),
|
r.origin.x,
|
||||||
(r.origin.x + r.size.width).to_f32().unwrap())
|
r.origin.x + r.size.width)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -435,10 +435,10 @@ impl Element {
|
||||||
ContentBoxResponse(rect) => {
|
ContentBoxResponse(rect) => {
|
||||||
ClientRect::new(
|
ClientRect::new(
|
||||||
win,
|
win,
|
||||||
rect.origin.y.to_f32().unwrap(),
|
rect.origin.y,
|
||||||
(rect.origin.y + rect.size.height).to_f32().unwrap(),
|
rect.origin.y + rect.size.height,
|
||||||
rect.origin.x.to_f32().unwrap(),
|
rect.origin.x,
|
||||||
(rect.origin.x + rect.size.width).to_f32().unwrap())
|
rect.origin.x + rect.size.width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@ var rect = elems[0].getBoundingClientRect();
|
||||||
is_a(rect, ClientRect);
|
is_a(rect, ClientRect);
|
||||||
|
|
||||||
geq(rect.top, 100);
|
geq(rect.top, 100);
|
||||||
geq(rect.bottom, 100);
|
geq(rect.bottom, 200);
|
||||||
geq(rect.left, 100);
|
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.width, rect.right - rect.left);
|
||||||
is(rect.height, rect.bottom - rect.top);
|
is(rect.height, rect.bottom - rect.top);
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@ finish();
|
||||||
div {
|
div {
|
||||||
margin-top: 100px;
|
margin-top: 100px;
|
||||||
margin-left: 100px;
|
margin-left: 100px;
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue