aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/script/dom/element.rs8
-rw-r--r--src/components/script/dom/htmlelement.rs3
-rw-r--r--src/components/style/selector_matching.rs19
-rw-r--r--src/components/util/tree.rs1
4 files changed, 21 insertions, 10 deletions
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 955c52a8845..82cd7207f8e 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -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,
diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs
index cdffbae1611..4d966720428 100644
--- a/src/components/script/dom/htmlelement.rs
+++ b/src/components/script/dom/htmlelement.rs
@@ -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)
}
}
diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs
index 100af097115..01301bc070b 100644
--- a/src/components/style/selector_matching.rs
+++ b/src/components/style/selector_matching.rs
@@ -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;
}
}
diff --git a/src/components/util/tree.rs b/src/components/util/tree.rs
index 7f41dd2958e..5f28974a1e3 100644
--- a/src/components/util/tree.rs
+++ b/src/components/util/tree.rs
@@ -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>;
}