mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48:59 +01:00
Cleanup some code.
This commit is contained in:
parent
d99e69e244
commit
388f685549
7 changed files with 59 additions and 84 deletions
|
@ -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) })
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
|
@ -277,75 +277,54 @@ 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) {
|
let node = abstract_self;
|
||||||
Some(win) => {
|
assert!(node.is_element());
|
||||||
let node = abstract_self;
|
let page = win.page;
|
||||||
assert!(node.is_element());
|
let (port, chan) = comm::stream();
|
||||||
let page = win.page;
|
let (rects, cx, scope) =
|
||||||
let (port, chan) = comm::stream();
|
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;
|
let cache = win.get_wrappercache();
|
||||||
let cache = win.get_wrappercache();
|
let scope = cache.get_wrapper();
|
||||||
let scope = cache.get_wrapper();
|
let rects = do rects.map |r| {
|
||||||
let rects = do rects.map |r| {
|
ClientRect::new(
|
||||||
ClientRect::new(
|
r.origin.y.to_f32(),
|
||||||
r.origin.y.to_f32(),
|
(r.origin.y + r.size.height).to_f32(),
|
||||||
(r.origin.y + r.size.height).to_f32(),
|
r.origin.x.to_f32(),
|
||||||
r.origin.x.to_f32(),
|
(r.origin.x + r.size.width).to_f32(),
|
||||||
(r.origin.x + r.size.width).to_f32(),
|
cx,
|
||||||
cx,
|
scope)
|
||||||
scope)
|
};
|
||||||
};
|
(rects, cx, scope)
|
||||||
Some((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) {
|
let page = win.page;
|
||||||
Some(win) => {
|
let node = abstract_self;
|
||||||
let page = win.page;
|
assert!(node.is_element());
|
||||||
let node = abstract_self;
|
let (port, chan) = comm::stream();
|
||||||
assert!(node.is_element());
|
match page.query_layout(ContentBoxQuery(node, chan), port) {
|
||||||
let (port, chan) = comm::stream();
|
ContentBoxResponse(rect) => {
|
||||||
match page.query_layout(ContentBoxQuery(node, chan), port) {
|
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
|
||||||
ContentBoxResponse(rect) => {
|
let cache = win.get_wrappercache();
|
||||||
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
|
let scope = cache.get_wrapper();
|
||||||
let cache = win.get_wrappercache();
|
ClientRect::new(
|
||||||
let scope = cache.get_wrapper();
|
rect.origin.y.to_f32(),
|
||||||
ClientRect::new(
|
(rect.origin.y + rect.size.height).to_f32(),
|
||||||
rect.origin.y.to_f32(),
|
rect.origin.x.to_f32(),
|
||||||
(rect.origin.y + rect.size.height).to_f32(),
|
(rect.origin.x + rect.size.width).to_f32(),
|
||||||
rect.origin.x.to_f32(),
|
cx,
|
||||||
(rect.origin.x + rect.size.width).to_f32(),
|
scope)
|
||||||
cx,
|
|
||||||
scope)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => fail!("no window")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => fail!("no document")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,7 @@ impl Node<ScriptView> {
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node<ScriptView> {
|
impl Node<ScriptView> {
|
||||||
pub fn NodeType(&self) -> u16 {
|
pub fn NodeType(&self) -> u16 {
|
||||||
|
|
|
@ -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>> {
|
||||||
|
|
|
@ -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())
|
};
|
||||||
};
|
unsafe { Node::as_abstract_node(cx, element) }
|
||||||
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: |_| {},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue