mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Add and hook up parsing for Doctype and Comment node types
This commit is contained in:
parent
3f2d253a71
commit
d260e06688
7 changed files with 58 additions and 20 deletions
|
@ -62,10 +62,27 @@ enum NodeData = {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum NodeKind {
|
enum NodeKind {
|
||||||
|
Doctype(DoctypeData),
|
||||||
|
Comment(~str),
|
||||||
Element(ElementData),
|
Element(ElementData),
|
||||||
Text(~str)
|
Text(~str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DoctypeData {
|
||||||
|
let name: ~str;
|
||||||
|
let public_id: Option<~str>;
|
||||||
|
let system_id: Option<~str>;
|
||||||
|
let force_quirks: bool;
|
||||||
|
|
||||||
|
new (name: ~str, public_id: Option<~str>,
|
||||||
|
system_id: Option<~str>, force_quirks: bool) {
|
||||||
|
self.name = name;
|
||||||
|
self.public_id = public_id;
|
||||||
|
self.system_id = system_id;
|
||||||
|
self.force_quirks = force_quirks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ElementData {
|
struct ElementData {
|
||||||
let tag_name: ~str;
|
let tag_name: ~str;
|
||||||
let kind: ~ElementKind;
|
let kind: ~ElementKind;
|
||||||
|
|
|
@ -9,7 +9,7 @@ import js::jsapi::bindgen::*;
|
||||||
import js::glue::bindgen::*;
|
import js::glue::bindgen::*;
|
||||||
import js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ConvertStub};
|
import js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ConvertStub};
|
||||||
|
|
||||||
import dom::base::{Node, NodeScope, Element, Text};
|
import dom::base::{Node, NodeScope, Element, Text, Doctype, Comment};
|
||||||
import utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval, str};
|
import utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval, str};
|
||||||
import libc::c_uint;
|
import libc::c_uint;
|
||||||
import ptr::null;
|
import ptr::null;
|
||||||
|
@ -47,10 +47,15 @@ fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
|
||||||
~Element(*) => {
|
~Element(*) => {
|
||||||
element::create(cx, node, scope)
|
element::create(cx, node, scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
~Text(*) => {
|
~Text(*) => {
|
||||||
fail ~"no text node bindings yet";
|
fail ~"no text node bindings yet";
|
||||||
}
|
}
|
||||||
|
~Comment(*) => {
|
||||||
|
fail ~"no comment node bindings yet";
|
||||||
|
}
|
||||||
|
~Doctype(*) => {
|
||||||
|
fail ~"no doctype node bindings yet";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +132,9 @@ extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool {
|
||||||
let nodeType = do (*bundle).payload.node.read |nd| {
|
let nodeType = do (*bundle).payload.node.read |nd| {
|
||||||
match nd.kind {
|
match nd.kind {
|
||||||
~Element(*) => 1,
|
~Element(*) => 1,
|
||||||
~Text(*) => 3
|
~Text(*) => 3,
|
||||||
|
~Comment(*) => 8,
|
||||||
|
~Doctype(*) => 10
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*vp = RUST_INT_TO_JSVAL(nodeType);
|
*vp = RUST_INT_TO_JSVAL(nodeType);
|
||||||
|
|
|
@ -171,7 +171,8 @@ impl Node : PrivBoxBuilder {
|
||||||
fail ~"The specified display style should be a default instead of none"
|
fail ~"The specified display style should be a default instead of none"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
_ => fail ~"unstyleable node type encountered"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl Node : PrivMatchingMethods {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Text(*) => { /*fall through, currently unsupported*/ }
|
_ => { /*fall through, currently unsupported*/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
import std::arc::{ARC, get, clone};
|
import std::arc::{ARC, get, clone};
|
||||||
|
|
||||||
import dom::style::{DisplayType, DisBlock, DisInline, DisNone, Stylesheet, Unit, Auto};
|
import dom::style::{DisplayType, DisBlock, DisInline, DisNone, Stylesheet, Unit, Auto};
|
||||||
import dom::base::{Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement, Node, NodeKind, UnknownElement, HTMLScriptElement};
|
import dom::base::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement};
|
||||||
import dom::base::{Text};
|
import dom::base::{Comment, Doctype, Element, Node, NodeKind, Text};
|
||||||
import util::color::{Color, rgb};
|
import util::color::{Color, rgb};
|
||||||
import util::color::css_colors::{white, black};
|
import util::color::css_colors::{white, black};
|
||||||
import base::{LayoutData, NTree};
|
import base::{LayoutData, NTree};
|
||||||
|
@ -29,7 +29,8 @@ impl NodeKind : DefaultStyleMethods {
|
||||||
fn default_color() -> Color {
|
fn default_color() -> Color {
|
||||||
match self {
|
match self {
|
||||||
Text(*) => white(),
|
Text(*) => white(),
|
||||||
Element(*) => white()
|
Element(*) => white(),
|
||||||
|
_ => fail ~"unstyleable node type encountered"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +45,8 @@ impl NodeKind : DefaultStyleMethods {
|
||||||
HTMLScriptElement => DisNone,
|
HTMLScriptElement => DisNone,
|
||||||
UnknownElement => DisInline,
|
UnknownElement => DisInline,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
_ => fail ~"unstyleable node type encountered"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(*) => {
|
_ => {
|
||||||
fail ~"attempt to link up an attribute to a text node"
|
fail ~"attempt to link up an attribute to an unstyleable node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement};
|
use dom::base::{Attr, Comment, Doctype, DoctypeData, Element, ElementData, ElementKind};
|
||||||
use dom::base::{HTMLImageElement, HTMLScriptElement, Node, NodeScope, Text, UnknownElement};
|
use dom::base::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, HTMLScriptElement};
|
||||||
|
use dom::base::{Node, NodeScope, Text, UnknownElement};
|
||||||
use dom::style::Stylesheet;
|
use dom::style::Stylesheet;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use gfx::geometry::px_to_au;
|
use gfx::geometry::px_to_au;
|
||||||
|
@ -152,16 +153,26 @@ fn parse_html(scope: NodeScope, url: Url, resource_task: ResourceTask) -> HtmlPa
|
||||||
parser.set_document_node(reinterpret_cast(&root));
|
parser.set_document_node(reinterpret_cast(&root));
|
||||||
parser.enable_scripting(true);
|
parser.enable_scripting(true);
|
||||||
parser.set_tree_handler(@hubbub::TreeHandler {
|
parser.set_tree_handler(@hubbub::TreeHandler {
|
||||||
create_comment: |_data| {
|
create_comment: |data: &str| {
|
||||||
debug!("create comment");
|
debug!("create comment");
|
||||||
0u // FIXME: causes segfaults
|
let new_node = scope.new_node(Comment(from_slice(data)));
|
||||||
},
|
|
||||||
create_doctype: |_doctype| {
|
|
||||||
debug!("create doctype");
|
|
||||||
let new_node = scope.new_node(Element(ElementData(~"doctype", ~UnknownElement)));
|
|
||||||
unsafe { reinterpret_cast(&new_node) }
|
unsafe { reinterpret_cast(&new_node) }
|
||||||
},
|
},
|
||||||
create_element: |tag| {
|
create_doctype: |doctype: &hubbub::Doctype| {
|
||||||
|
debug!("create doctype");
|
||||||
|
let name = from_slice(doctype.name);
|
||||||
|
let public_id = match doctype.public_id {
|
||||||
|
None => None,
|
||||||
|
Some(id) => Some(from_slice(id))
|
||||||
|
};
|
||||||
|
let system_id = match doctype.system_id {
|
||||||
|
None => None,
|
||||||
|
Some(id) => Some(from_slice(id))
|
||||||
|
};
|
||||||
|
let new_node = scope.new_node(Doctype(DoctypeData(name, public_id, system_id, doctype.force_quirks)));
|
||||||
|
unsafe { reinterpret_cast(&new_node) }
|
||||||
|
},
|
||||||
|
create_element: |tag: &hubbub::Tag| {
|
||||||
debug!("create element");
|
debug!("create element");
|
||||||
let element_kind = build_element_kind(tag.name);
|
let element_kind = build_element_kind(tag.name);
|
||||||
let node = scope.new_node(Element(ElementData(from_slice(tag.name), element_kind)));
|
let node = scope.new_node(Element(ElementData(from_slice(tag.name), element_kind)));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue