mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Cleanup ClientRectList binding.
This commit is contained in:
parent
f75568e939
commit
6af555ab23
2 changed files with 22 additions and 25 deletions
|
@ -3,29 +3,32 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::ClientRectListBinding;
|
use dom::bindings::codegen::ClientRectListBinding;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::clientrect::ClientRect;
|
use dom::clientrect::ClientRect;
|
||||||
use script_task::page_from_context;
|
use dom::window::Window;
|
||||||
|
|
||||||
use js::jsapi::{JSObject, JSContext};
|
use js::jsapi::{JSObject, JSContext};
|
||||||
|
|
||||||
pub struct ClientRectList {
|
pub struct ClientRectList {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
rects: ~[@mut ClientRect]
|
rects: ~[@mut ClientRect],
|
||||||
|
window: @mut Window,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientRectList {
|
impl ClientRectList {
|
||||||
pub fn new(rects: ~[@mut ClientRect], cx: *JSContext, scope: *JSObject) -> @mut ClientRectList {
|
pub fn new_inherited(window: @mut Window,
|
||||||
let list = @mut ClientRectList {
|
rects: ~[@mut ClientRect]) -> ClientRectList {
|
||||||
|
ClientRectList {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
rects: rects
|
rects: rects,
|
||||||
};
|
window: window,
|
||||||
list.init_wrapper(cx, scope);
|
}
|
||||||
list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_wrapper(@mut self, cx: *JSContext, scope: *JSObject) {
|
pub fn new(window: @mut Window,
|
||||||
self.wrap_object_shared(cx, scope);
|
rects: ~[@mut ClientRect]) -> @mut ClientRectList {
|
||||||
|
reflect_dom_object(@mut ClientRectList::new_inherited(window, rects),
|
||||||
|
window, ClientRectListBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Length(&self) -> u32 {
|
pub fn Length(&self) -> u32 {
|
||||||
|
@ -55,14 +58,11 @@ impl Reflectable for ClientRectList {
|
||||||
&mut self.reflector_
|
&mut self.reflector_
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
|
fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
|
||||||
ClientRectListBinding::Wrap(cx, scope, self)
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn GetParentObject(&self, cx: *JSContext) -> Option<@mut Reflectable> {
|
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
|
||||||
let page = page_from_context(cx);
|
Some(self.window as @mut Reflectable)
|
||||||
unsafe {
|
|
||||||
Some((*page).frame.get_ref().window as @mut Reflectable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,24 +287,21 @@ impl Element {
|
||||||
let node = abstract_self;
|
let node = abstract_self;
|
||||||
assert!(node.is_element());
|
assert!(node.is_element());
|
||||||
let (port, chan) = comm::stream();
|
let (port, chan) = comm::stream();
|
||||||
let (rects, cx, scope) =
|
let rects =
|
||||||
match win.page.query_layout(ContentBoxesQuery(node, chan), port) {
|
match win.page.query_layout(ContentBoxesQuery(node, chan), port) {
|
||||||
ContentBoxesResponse(rects) => {
|
ContentBoxesResponse(rects) => {
|
||||||
let cx = win.get_cx();
|
do rects.map |r| {
|
||||||
let scope = win.reflector().get_jsobject();
|
|
||||||
let rects = do rects.map |r| {
|
|
||||||
ClientRect::new(
|
ClientRect::new(
|
||||||
win,
|
win,
|
||||||
r.origin.y.to_f32().unwrap(),
|
r.origin.y.to_f32().unwrap(),
|
||||||
(r.origin.y + r.size.height).to_f32().unwrap(),
|
(r.origin.y + r.size.height).to_f32().unwrap(),
|
||||||
r.origin.x.to_f32().unwrap(),
|
r.origin.x.to_f32().unwrap(),
|
||||||
(r.origin.x + r.size.width).to_f32().unwrap())
|
(r.origin.x + r.size.width).to_f32().unwrap())
|
||||||
};
|
}
|
||||||
(rects, cx, scope)
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientRectList::new(rects, cx, scope)
|
ClientRectList::new(win, rects)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue