auto merge of #1359 : SimonSapin/servo/ns-noalloc, r=metajack

Also rename Element::get_namespace to get_namespace_url.
This commit is contained in:
bors-servo 2013-12-09 08:16:21 -08:00
commit c3a9583000
5 changed files with 23 additions and 23 deletions

View file

@ -75,7 +75,7 @@ impl Attr {
}
pub fn GetNamespaceURI(&self) -> Option<DOMString> {
self.namespace.to_str()
self.namespace.to_str().map(|s| s.to_owned())
}
pub fn GetPrefix(&self) -> Option<DOMString> {

View file

@ -129,8 +129,8 @@ impl ElementLike for Element {
self.tag_name.as_slice()
}
fn get_namespace<'a>(&'a self) -> ~str {
self.namespace.to_str().unwrap_or(~"")
fn get_namespace_url<'a>(&'a self) -> &'a str {
self.namespace.to_str().unwrap_or("")
}
fn get_attr(&self, name: &str) -> Option<~str> {

View file

@ -19,26 +19,26 @@ pub enum Namespace {
impl Namespace {
pub fn from_str(url: Option<DOMString>) -> Namespace {
match null_str_as_empty_ref(&url) {
&"http://www.w3.org/1999/xhtml" => HTML,
&"http://www.w3.org/XML/1998/namespace" => XML,
&"http://www.w3.org/2000/xmlns/" => XMLNS,
&"http://www.w3.org/1999/xlink" => XLink,
&"http://www.w3.org/2000/svg" => SVG,
&"http://www.w3.org/1998/Math/MathML" => MathML,
&"" => Null,
"http://www.w3.org/1999/xhtml" => HTML,
"http://www.w3.org/XML/1998/namespace" => XML,
"http://www.w3.org/2000/xmlns/" => XMLNS,
"http://www.w3.org/1999/xlink" => XLink,
"http://www.w3.org/2000/svg" => SVG,
"http://www.w3.org/1998/Math/MathML" => MathML,
"" => Null,
ns => Other(ns.to_owned())
}
}
pub fn to_str(&self) -> Option<DOMString> {
pub fn to_str<'a>(&'a self) -> Option<&'a str> {
match *self {
Null => None,
HTML => Some(~"http://www.w3.org/1999/xhtml"),
XML => Some(~"http://www.w3.org/XML/1998/namespace"),
XMLNS => Some(~"http://www.w3.org/2000/xmlns/"),
XLink => Some(~"http://www.w3.org/1999/xlink"),
SVG => Some(~"http://www.w3.org/2000/svg"),
MathML => Some(~"http://www.w3.org/1998/Math/MathML"),
Other(ref x) => Some(x.to_owned())
HTML => Some("http://www.w3.org/1999/xhtml"),
XML => Some("http://www.w3.org/XML/1998/namespace"),
XMLNS => Some("http://www.w3.org/2000/xmlns/"),
XLink => Some("http://www.w3.org/1999/xlink"),
SVG => Some("http://www.w3.org/2000/svg"),
MathML => Some("http://www.w3.org/1998/Math/MathML"),
Other(ref x) => Some(x.as_slice())
}
}
}

View file

@ -427,7 +427,7 @@ fn matches_simple_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: Ele
}
NamespaceSelector(ref url) => {
do element.with_imm_element_like |element: &E| {
str::eq_slice(element.get_namespace(), *url)
element.get_namespace_url() == url.as_slice()
}
}
// TODO: case-sensitivity depends on the document type and quirks mode
@ -538,11 +538,11 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
};
let mut element_local_name = "";
let mut element_namespace = ~"";
let mut element_namespace = "";
if is_of_type {
do element.with_imm_element_like |element: &E| {
element_local_name = element.get_local_name();
element_namespace = element.get_namespace();
element_namespace = element.get_namespace_url();
}
}
@ -564,7 +564,7 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
if is_of_type {
do node.with_imm_element_like |node: &E| {
if element_local_name == node.get_local_name() &&
element_namespace == node.get_namespace() {
element_namespace == node.get_namespace_url() {
index += 1;
}
}

View file

@ -348,7 +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_namespace_url<'a>(&'a self) -> &'a str;
fn get_attr(&self, name: &str) -> Option<~str>;
fn get_link(&self) -> Option<~str>;
}