mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Make the HTML parser parse into the document rather than an element.
This removes the duplicate html element.
This commit is contained in:
parent
800c2b3c0f
commit
dc6dbc63af
5 changed files with 18 additions and 32 deletions
|
@ -77,17 +77,6 @@ impl AbstractDocument {
|
|||
document: ptr as *mut Box<Document>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_root(&self, root: AbstractNode<ScriptView>) {
|
||||
assert!(do root.traverse_preorder().all |node| {
|
||||
node.node().owner_doc() == *self
|
||||
});
|
||||
|
||||
let document = self.mut_document();
|
||||
document.node.AppendChild(AbstractNode::from_document(*self), root);
|
||||
// Register elements having "id" attribute to the owner doc.
|
||||
document.register_nodes_with_id(&root);
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
|
@ -173,7 +162,9 @@ impl Reflectable for Document {
|
|||
|
||||
impl Document {
|
||||
pub fn GetDocumentElement(&self) -> Option<AbstractNode<ScriptView>> {
|
||||
self.node.first_child
|
||||
do self.node.children().find |c| {
|
||||
c.is_element()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cx(&self) -> *JSContext {
|
||||
|
|
|
@ -441,9 +441,7 @@ impl<'self, View> AbstractNode<View> {
|
|||
}
|
||||
|
||||
pub fn children(&self) -> AbstractNodeChildrenIterator<View> {
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: self.first_child(),
|
||||
}
|
||||
self.node().children()
|
||||
}
|
||||
|
||||
// Issue #1030: should not walk the tree
|
||||
|
@ -498,6 +496,12 @@ impl<View> Node<View> {
|
|||
pub fn set_owner_doc(&mut self, document: AbstractDocument) {
|
||||
self.owner_doc = Some(document);
|
||||
}
|
||||
|
||||
pub fn children(&self) -> AbstractNodeChildrenIterator<View> {
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: self.first_child,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Node<ScriptView> {
|
||||
|
|
|
@ -72,7 +72,6 @@ pub enum HtmlDiscoveryMessage {
|
|||
}
|
||||
|
||||
pub struct HtmlParserResult {
|
||||
root: AbstractNode<ScriptView>,
|
||||
discovery_port: Port<HtmlDiscoveryMessage>,
|
||||
}
|
||||
|
||||
|
@ -300,12 +299,11 @@ pub fn parse_html(cx: *JSContext,
|
|||
(*page).url = Some((url2.clone(), true));
|
||||
}
|
||||
|
||||
// Build the root node.
|
||||
let root = HTMLHtmlElement::new(~"html", document);
|
||||
debug!("created new node");
|
||||
let mut parser = hubbub::Parser("UTF-8", false);
|
||||
debug!("created parser");
|
||||
parser.set_document_node(unsafe { root.to_hubbub_node() });
|
||||
|
||||
let document_node = AbstractNode::<ScriptView>::from_document(document);
|
||||
parser.set_document_node(unsafe { document_node.to_hubbub_node() });
|
||||
parser.enable_scripting(true);
|
||||
parser.enable_styling(true);
|
||||
|
||||
|
@ -427,10 +425,7 @@ pub fn parse_html(cx: *JSContext,
|
|||
debug!("append child {:x} {:x}", parent, child);
|
||||
let parent: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(parent);
|
||||
let child: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(child);
|
||||
// FIXME this needs to be AppendChild.
|
||||
// Probably blocked on #838, so that we can remove the
|
||||
// double root element.
|
||||
parent.add_child(child, None);
|
||||
parent.AppendChild(child);
|
||||
}
|
||||
child
|
||||
},
|
||||
|
@ -543,7 +538,6 @@ pub fn parse_html(cx: *JSContext,
|
|||
js_chan.send(JSTaskExit);
|
||||
|
||||
HtmlParserResult {
|
||||
root: root,
|
||||
discovery_port: discovery_port,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -701,7 +701,7 @@ impl ScriptTask {
|
|||
self.constellation_chan.clone());
|
||||
|
||||
|
||||
let HtmlParserResult {root, discovery_port} = html_parsing_result;
|
||||
let HtmlParserResult {discovery_port} = html_parsing_result;
|
||||
|
||||
// Create the root frame.
|
||||
page.frame = Some(Frame {
|
||||
|
@ -741,11 +741,8 @@ impl ScriptTask {
|
|||
}
|
||||
}
|
||||
|
||||
// Tie the root into the document. This will kick off the initial reflow
|
||||
// of the page.
|
||||
// FIXME: We have no way to ensure that the first reflow performed is a
|
||||
// ReflowForDisplay operation.
|
||||
document.set_root(root);
|
||||
// Kick off the initial reflow of the page.
|
||||
document.document().content_changed();
|
||||
|
||||
// No more reflow required
|
||||
page.url = Some((url, false));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<script>
|
||||
is_a(window, Window);
|
||||
is_a(document.documentElement, HTMLHtmlElement);
|
||||
is_a(document.documentElement.firstChild, HTMLHtmlElement);
|
||||
is_a(document.documentElement.firstChild, HTMLHeadElement);
|
||||
is(document.documentElement.nextSibling, null);
|
||||
is_a(document, HTMLDocument);
|
||||
is_a(document, Document);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue