mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
add namespaces to elements
This commit is contained in:
parent
76e3b34c75
commit
28575c20bf
4 changed files with 21 additions and 10 deletions
|
@ -30,6 +30,7 @@ use std::ascii::StrAsciiExt;
|
|||
pub struct Element {
|
||||
node: Node<ScriptView>,
|
||||
tag_name: ~str, // TODO: This should be an atom, not a ~str.
|
||||
namespace: Namespace,
|
||||
attrs: HashMap<~str, ~[@mut Attr]>,
|
||||
attrs_insert_order: ~[(~str, Namespace)], // store an order of attributes.
|
||||
style_attribute: Option<style::PropertyDeclarationBlock>,
|
||||
|
@ -128,6 +129,10 @@ impl ElementLike for Element {
|
|||
self.tag_name.as_slice()
|
||||
}
|
||||
|
||||
fn get_namespace<'a>(&'a self) -> ~str {
|
||||
self.namespace.to_str().unwrap_or(~"")
|
||||
}
|
||||
|
||||
fn get_attr(&self, name: &str) -> Option<~str> {
|
||||
self.get_attribute(None, name).map(|attr| attr.value.clone())
|
||||
}
|
||||
|
@ -146,10 +151,11 @@ impl ElementLike for Element {
|
|||
}
|
||||
|
||||
impl<'self> Element {
|
||||
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
|
||||
pub fn new(type_id: ElementTypeId, tag_name: ~str, namespace: Namespace, document: AbstractDocument) -> Element {
|
||||
Element {
|
||||
node: Node::new(ElementNodeTypeId(type_id), document),
|
||||
tag_name: tag_name,
|
||||
namespace: namespace,
|
||||
attrs: HashMap::new(),
|
||||
attrs_insert_order: ~[],
|
||||
attr_list: None,
|
||||
|
|
|
@ -9,6 +9,7 @@ use dom::element::{Element, ElementTypeId, HTMLElementTypeId};
|
|||
use dom::node::{AbstractNode, Node, ScriptView};
|
||||
use js::jsapi::{JSContext, JSVal};
|
||||
use js::JSVAL_NULL;
|
||||
use dom::namespace;
|
||||
|
||||
pub struct HTMLElement {
|
||||
element: Element
|
||||
|
@ -17,7 +18,7 @@ pub struct HTMLElement {
|
|||
impl HTMLElement {
|
||||
pub fn new_inherited(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> HTMLElement {
|
||||
HTMLElement {
|
||||
element: Element::new(type_id, tag_name, document)
|
||||
element: Element::new(type_id, tag_name, namespace::HTML, document)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -425,7 +425,11 @@ fn matches_simple_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: Ele
|
|||
element.get_local_name().eq_ignore_ascii_case(name.as_slice())
|
||||
}
|
||||
}
|
||||
NamespaceSelector(_) => false, // TODO, when the DOM supports namespaces on elements.
|
||||
NamespaceSelector(ref url) => {
|
||||
do element.with_imm_element_like |element: &E| {
|
||||
str::eq_slice(element.get_namespace(), *url)
|
||||
}
|
||||
}
|
||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||
// TODO: cache and intern IDs on elements.
|
||||
IDSelector(ref id) => {
|
||||
|
@ -533,12 +537,12 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
|
|||
None => return false
|
||||
};
|
||||
|
||||
let mut local_name = "";
|
||||
let mut element_local_name = "";
|
||||
let mut element_namespace = ~"";
|
||||
if is_of_type {
|
||||
// FIXME this is wrong
|
||||
// TODO when the DOM supports namespaces on elements
|
||||
do element.with_imm_element_like |element: &E| {
|
||||
local_name = element.get_local_name();
|
||||
element_local_name = element.get_local_name();
|
||||
element_namespace = element.get_namespace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -558,10 +562,9 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
|
|||
|
||||
if node.is_element() {
|
||||
if is_of_type {
|
||||
// FIXME this is wrong
|
||||
// TODO when the DOM supports namespaces on elements
|
||||
do node.with_imm_element_like |node: &E| {
|
||||
if local_name == node.get_local_name() {
|
||||
if element_local_name == node.get_local_name() &&
|
||||
element_namespace == node.get_namespace() {
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,6 +348,7 @@ pub trait TreeNode<Ref: TreeNodeRef<Self>> {
|
|||
|
||||
pub trait ElementLike {
|
||||
fn get_local_name<'a>(&'a self) -> &'a str;
|
||||
fn get_namespace<'a>(&'a self) -> ~str;
|
||||
fn get_attr(&self, name: &str) -> Option<~str>;
|
||||
fn get_link(&self) -> Option<~str>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue