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>> { pub fn Constructor(owner: @mut Window, data: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
let s = null_str_as_empty(data); let s = null_str_as_empty(data);
unsafe { let cx = (*owner.page).js_info.get_ref().js_compartment.cx.ptr;
let compartment = (*owner.page).js_info.get_ref().js_compartment; let comment = @Comment::new(s);
Ok(Node::as_abstract_node(compartment.cx.ptr, @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> { pub fn CreateTextNode(&self, data: &DOMString) -> AbstractNode<ScriptView> {
let cx = self.get_cx(); 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> { pub fn CreateEvent(&self, _interface: &DOMString) -> Fallible<@mut Event> {

View file

@ -277,14 +277,13 @@ impl Element {
} }
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList { pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
let (rects, cx, scope) = match self.node.owner_doc { let document = self.node.owner_doc.expect("no document");
Some(doc) => { let win = document.with_base(|doc| doc.window).expect("no window");
match doc.with_base(|doc| doc.window) {
Some(win) => {
let node = abstract_self; let node = abstract_self;
assert!(node.is_element()); assert!(node.is_element());
let page = win.page; let page = win.page;
let (port, chan) = comm::stream(); let (port, chan) = comm::stream();
let (rects, cx, scope) =
match page.query_layout(ContentBoxesQuery(node, chan), port) { match page.query_layout(ContentBoxesQuery(node, chan), port) {
ContentBoxesResponse(rects) => { ContentBoxesResponse(rects) => {
let cx = page.js_info.get_ref().js_compartment.cx.ptr; let cx = page.js_info.get_ref().js_compartment.cx.ptr;
@ -299,30 +298,16 @@ impl Element {
cx, cx,
scope) scope)
}; };
Some((rects, cx, scope)) (rects, cx, scope)
}, },
} };
}
None => {
debug!("no window");
None
}
}
}
None => {
debug!("no document");
None
}
}.unwrap();
ClientRectList::new(rects, cx, scope) ClientRectList::new(rects, cx, scope)
} }
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect { pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
match self.node.owner_doc { let document = self.node.owner_doc.expect("no document");
Some(doc) => { let win = document.with_base(|doc| doc.window).expect("no window");
match doc.with_base(|doc| doc.window) {
Some(win) => {
let page = win.page; let page = win.page;
let node = abstract_self; let node = abstract_self;
assert!(node.is_element()); assert!(node.is_element());
@ -342,12 +327,6 @@ impl Element {
} }
} }
} }
None => fail!("no window")
}
}
None => fail!("no document")
}
}
pub fn ScrollIntoView(&self, _top: bool) { pub fn ScrollIntoView(&self, _top: bool) {
} }

View file

@ -117,9 +117,6 @@ impl HTMLFormElement {
} }
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> AbstractNode<ScriptView> { pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> AbstractNode<ScriptView> {
let (_scope, cx) = self.get_scope_and_cx(); fail!("Not implemented.")
// 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) }
} }
} }

View file

@ -22,7 +22,8 @@ impl Text {
pub fn Constructor(owner: @mut Window, text: &DOMString) -> Fallible<AbstractNode<ScriptView>> { pub fn Constructor(owner: @mut Window, text: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
let cx = owner.page.js_info.get_ref().js_compartment.cx.ptr; 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>> { 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, "audio", HTMLAudioElementTypeId, HTMLAudioElement);
handle_htmlmediaelement!(cx, tag, "video", HTMLVideoElementTypeId, HTMLVideoElement); handle_htmlmediaelement!(cx, tag, "video", HTMLVideoElementTypeId, HTMLVideoElement);
unsafe {
let element = @HTMLUnknownElement { let element = @HTMLUnknownElement {
htmlelement: HTMLElement::new(HTMLUnknownElementTypeId, tag.to_str()) htmlelement: HTMLElement::new(HTMLUnknownElementTypeId, tag.to_str())
}; };
Node::as_abstract_node(cx, element) unsafe { Node::as_abstract_node(cx, element) }
}
} }
pub fn parse_html(cx: *JSContext, pub fn parse_html(cx: *JSContext,
@ -367,8 +365,9 @@ pub fn parse_html(cx: *JSContext,
parser.set_tree_handler(~hubbub::TreeHandler { parser.set_tree_handler(~hubbub::TreeHandler {
create_comment: |data: ~str| { create_comment: |data: ~str| {
debug!("create comment"); debug!("create comment");
let comment = @Comment::new(data);
unsafe { 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| { create_doctype: |doctype: ~hubbub::Doctype| {
@ -466,9 +465,8 @@ pub fn parse_html(cx: *JSContext,
}, },
create_text: |data: ~str| { create_text: |data: ~str| {
debug!("create text"); debug!("create text");
unsafe { let text = @Text::new(data);
Node::as_abstract_node(cx, @Text::new(data)).to_hubbub_node() unsafe { Node::as_abstract_node(cx, text).to_hubbub_node() }
}
}, },
ref_node: |_| {}, ref_node: |_| {},
unref_node: |_| {}, unref_node: |_| {},