Cleanup some code.

This commit is contained in:
Ms2ger 2013-10-07 16:30:34 +02:00
parent d99e69e244
commit 388f685549
7 changed files with 59 additions and 84 deletions

View file

@ -22,9 +22,8 @@ impl Comment {
pub fn Constructor(owner: @mut Window, data: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
let s = null_str_as_empty(data);
unsafe {
let compartment = (*owner.page).js_info.get_ref().js_compartment;
Ok(Node::as_abstract_node(compartment.cx.ptr, @Comment::new(s)))
}
let cx = (*owner.page).js_info.get_ref().js_compartment.cx.ptr;
let comment = @Comment::new(s);
Ok(unsafe { Node::as_abstract_node(cx, comment) })
}
}

View file

@ -258,7 +258,8 @@ impl Document {
pub fn CreateTextNode(&self, data: &DOMString) -> AbstractNode<ScriptView> {
let cx = self.get_cx();
unsafe { Node::as_abstract_node(cx, @Text::new(null_str_as_empty(data))) }
let text = @Text::new(null_str_as_empty(data));
unsafe { Node::as_abstract_node(cx, text) }
}
pub fn CreateEvent(&self, _interface: &DOMString) -> Fallible<@mut Event> {

View file

@ -277,75 +277,54 @@ impl Element {
}
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
let (rects, cx, scope) = match self.node.owner_doc {
Some(doc) => {
match doc.with_base(|doc| doc.window) {
Some(win) => {
let node = abstract_self;
assert!(node.is_element());
let page = win.page;
let (port, chan) = comm::stream();
match page.query_layout(ContentBoxesQuery(node, chan), port) {
ContentBoxesResponse(rects) => {
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
let cache = win.get_wrappercache();
let scope = cache.get_wrapper();
let rects = do rects.map |r| {
ClientRect::new(
r.origin.y.to_f32(),
(r.origin.y + r.size.height).to_f32(),
r.origin.x.to_f32(),
(r.origin.x + r.size.width).to_f32(),
cx,
scope)
};
Some((rects, cx, scope))
},
}
}
None => {
debug!("no window");
None
}
}
}
None => {
debug!("no document");
None
}
}.unwrap();
let document = self.node.owner_doc.expect("no document");
let win = document.with_base(|doc| doc.window).expect("no window");
let node = abstract_self;
assert!(node.is_element());
let page = win.page;
let (port, chan) = comm::stream();
let (rects, cx, scope) =
match page.query_layout(ContentBoxesQuery(node, chan), port) {
ContentBoxesResponse(rects) => {
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
let cache = win.get_wrappercache();
let scope = cache.get_wrapper();
let rects = do rects.map |r| {
ClientRect::new(
r.origin.y.to_f32(),
(r.origin.y + r.size.height).to_f32(),
r.origin.x.to_f32(),
(r.origin.x + r.size.width).to_f32(),
cx,
scope)
};
(rects, cx, scope)
},
};
ClientRectList::new(rects, cx, scope)
}
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
match self.node.owner_doc {
Some(doc) => {
match doc.with_base(|doc| doc.window) {
Some(win) => {
let page = win.page;
let node = abstract_self;
assert!(node.is_element());
let (port, chan) = comm::stream();
match page.query_layout(ContentBoxQuery(node, chan), port) {
ContentBoxResponse(rect) => {
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
let cache = win.get_wrappercache();
let scope = cache.get_wrapper();
ClientRect::new(
rect.origin.y.to_f32(),
(rect.origin.y + rect.size.height).to_f32(),
rect.origin.x.to_f32(),
(rect.origin.x + rect.size.width).to_f32(),
cx,
scope)
}
}
}
None => fail!("no window")
}
let document = self.node.owner_doc.expect("no document");
let win = document.with_base(|doc| doc.window).expect("no window");
let page = win.page;
let node = abstract_self;
assert!(node.is_element());
let (port, chan) = comm::stream();
match page.query_layout(ContentBoxQuery(node, chan), port) {
ContentBoxResponse(rect) => {
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
let cache = win.get_wrappercache();
let scope = cache.get_wrapper();
ClientRect::new(
rect.origin.y.to_f32(),
(rect.origin.y + rect.size.height).to_f32(),
rect.origin.x.to_f32(),
(rect.origin.x + rect.size.width).to_f32(),
cx,
scope)
}
None => fail!("no document")
}
}

View file

@ -117,9 +117,6 @@ impl HTMLFormElement {
}
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> AbstractNode<ScriptView> {
let (_scope, cx) = self.get_scope_and_cx();
// FIXME: This should be replaced with a proper value according to the index
let node = @Node::new(ElementNodeTypeId(HTMLFormElementTypeId));
unsafe { return Node::as_abstract_node(cx, node) }
fail!("Not implemented.")
}
}

View file

@ -508,7 +508,7 @@ impl Node<ScriptView> {
None => None
}
}
}
}
impl Node<ScriptView> {
pub fn NodeType(&self) -> u16 {

View file

@ -22,7 +22,8 @@ impl Text {
pub fn Constructor(owner: @mut Window, text: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
let cx = owner.page.js_info.get_ref().js_compartment.cx.ptr;
unsafe { Ok(Node::as_abstract_node(cx, @Text::new(null_str_as_empty(text)))) }
let text = @Text::new(null_str_as_empty(text));
Ok(unsafe { Node::as_abstract_node(cx, text) })
}
pub fn SplitText(&self, _offset: u32) -> Fallible<AbstractNode<ScriptView>> {

View file

@ -291,12 +291,10 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptV
handle_htmlmediaelement!(cx, tag, "audio", HTMLAudioElementTypeId, HTMLAudioElement);
handle_htmlmediaelement!(cx, tag, "video", HTMLVideoElementTypeId, HTMLVideoElement);
unsafe {
let element = @HTMLUnknownElement {
htmlelement: HTMLElement::new(HTMLUnknownElementTypeId, tag.to_str())
};
Node::as_abstract_node(cx, element)
}
let element = @HTMLUnknownElement {
htmlelement: HTMLElement::new(HTMLUnknownElementTypeId, tag.to_str())
};
unsafe { Node::as_abstract_node(cx, element) }
}
pub fn parse_html(cx: *JSContext,
@ -367,8 +365,9 @@ pub fn parse_html(cx: *JSContext,
parser.set_tree_handler(~hubbub::TreeHandler {
create_comment: |data: ~str| {
debug!("create comment");
let comment = @Comment::new(data);
unsafe {
Node::as_abstract_node(cx, @Comment::new(data)).to_hubbub_node()
Node::as_abstract_node(cx, comment).to_hubbub_node()
}
},
create_doctype: |doctype: ~hubbub::Doctype| {
@ -466,9 +465,8 @@ pub fn parse_html(cx: *JSContext,
},
create_text: |data: ~str| {
debug!("create text");
unsafe {
Node::as_abstract_node(cx, @Text::new(data)).to_hubbub_node()
}
let text = @Text::new(data);
unsafe { Node::as_abstract_node(cx, text).to_hubbub_node() }
},
ref_node: |_| {},
unref_node: |_| {},