diff --git a/Cargo.lock b/Cargo.lock index e04ebaa0b673..e63d4a54df5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,6 +287,8 @@ dependencies = [ "plugins 0.0.1", "script 0.0.1", "script_traits 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "style 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", @@ -397,6 +399,8 @@ dependencies = [ "net 0.0.1", "plugins 0.0.1", "script_traits 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "style 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", @@ -459,6 +463,8 @@ dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", "lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)", "plugins 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", ] @@ -481,7 +487,9 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure#b357751c04a89a87e6ef1f0cebe5f20957dd112d)", "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", + "plugins 0.0.1", "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "task_info 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", ] diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index b6e7da758c59..edd6ed0ad1b6 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -39,3 +39,9 @@ git = "https://github.com/servo/rust-geom" [dependencies.url] git = "https://github.com/servo/rust-url" + +[dependencies.string_cache] +git = "https://github.com/servo/string-cache" + +[dependencies.string_cache_macros] +git = "https://github.com/servo/string-cache" diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 30df9591f5fb..5f57490b3d09 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -57,7 +57,6 @@ use script::dom::node::{CommentNodeTypeId, DoctypeNodeTypeId, DocumentFragmentNo use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId}; use script::dom::node::{TextNodeTypeId}; use script::dom::htmlobjectelement::is_image_data; -use servo_util::namespace; use std::mem; use std::sync::atomics::Relaxed; use style::ComputedValues; @@ -1091,7 +1090,7 @@ trait ObjectElement<'a> { impl<'ln> ObjectElement<'ln> for ThreadSafeLayoutNode<'ln> { fn get_type_and_data(&self) -> (Option<&'ln str>, Option<&'ln str>) { let elem = self.as_element(); - (elem.get_attr(&namespace::Null, "type"), elem.get_attr(&namespace::Null, "data")) + (elem.get_attr(&satom!(""), "type"), elem.get_attr(&satom!(""), "data")) } fn has_object_data(&self) -> bool { diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 564e5f6569f3..094e420d8747 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -14,7 +14,6 @@ use script::dom::node::{TextNodeTypeId}; use servo_util::atom::Atom; use servo_util::bloom::BloomFilter; use servo_util::cache::{Cache, LRUCache, SimpleHashCache}; -use servo_util::namespace::Null; use servo_util::smallvec::{SmallVec, SmallVec16}; use servo_util::str::DOMString; use std::mem; @@ -223,7 +222,7 @@ impl StyleSharingCandidate { style: style, parent_style: parent_style, local_name: element.get_local_name().clone(), - class: element.get_attr(&Null, "class") + class: element.get_attr(&satom!(""), "class") .map(|string| string.to_string()), }) } @@ -232,7 +231,7 @@ impl StyleSharingCandidate { if *element.get_local_name() != self.local_name { return false } - match (&self.class, element.get_attr(&Null, "class")) { + match (&self.class, element.get_attr(&satom!(""), "class")) { (&None, Some(_)) | (&Some(_), None) => return false, (&Some(ref this_class), Some(element_class)) if element_class != this_class.as_slice() => { return false @@ -454,7 +453,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { } let ok = { let element = self.as_element(); - element.style_attribute().is_none() && element.get_attr(&Null, "id").is_none() + element.style_attribute().is_none() && element.get_attr(&satom!(""), "id").is_none() }; if !ok { return CannotShare(false) @@ -501,7 +500,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { // TODO: case-sensitivity depends on the document type and quirks mode element - .get_attr(&Null, "class") + .get_attr(&satom!(""), "class") .map(|attr| { for c in attr.split(style::SELECTOR_WHITESPACE) { bf.insert(&c); @@ -520,7 +519,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { // TODO: case-sensitivity depends on the document type and quirks mode element - .get_attr(&Null, "class") + .get_attr(&satom!(""), "class") .map(|attr| { for c in attr.split(style::SELECTOR_WHITESPACE) { bf.remove(&c); diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 35537fae4605..0af5e8841960 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -43,7 +43,6 @@ use servo_util::geometry::Au; use servo_util::geometry; use servo_util::logical_geometry::{LogicalRect, LogicalSize, LogicalMargin}; use servo_util::range::*; -use servo_util::namespace; use servo_util::smallvec::SmallVec; use servo_util::str::is_whitespace; use std::cmp::{max, min}; @@ -179,7 +178,7 @@ impl ImageFragmentInfo { -> ImageFragmentInfo { fn convert_length(node: &ThreadSafeLayoutNode, name: &str) -> Option { let element = node.as_element(); - element.get_attr(&namespace::Null, name).and_then(|string| { + element.get_attr(&satom!(""), name).and_then(|string| { let n: Option = FromStr::from_str(string); n }).and_then(|pixels| Some(Au::from_px(pixels))) @@ -352,7 +351,7 @@ impl TableColumnFragmentInfo { pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnFragmentInfo { let span = { let element = node.as_element(); - element.get_attr(&namespace::Null, "span").and_then(|string| { + element.get_attr(&satom!(""), "span").and_then(|string| { let n: Option = FromStr::from_str(string); n }) diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 5ef17f65359c..c15b2658ab43 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -28,6 +28,9 @@ extern crate "net" as servo_net; extern crate "msg" as servo_msg; #[phase(plugin, link)] extern crate "util" as servo_util; +extern crate string_cache; +#[phase(plugin)] +extern crate string_cache_macros; extern crate collections; extern crate encoding; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4b4f3eef939a..214807103a51 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -49,8 +49,6 @@ use script::dom::text::Text; use script::layout_interface::LayoutChan; use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_util::atom::Atom; -use servo_util::namespace::Namespace; -use servo_util::namespace; use servo_util::str::is_whitespace; use std::cell::{RefCell, Ref, RefMut}; use std::kinds::marker::ContravariantLifetime; @@ -396,12 +394,12 @@ impl<'le> TElement<'le> for LayoutElement<'le> { } #[inline] - fn get_namespace<'a>(&'a self) -> &'a Namespace { + fn get_namespace<'a>(&'a self) -> &'a Atom { &self.element.namespace } #[inline] - fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> { + fn get_attr(&self, namespace: &Atom, name: &str) -> Option<&'le str> { unsafe { self.element.get_attr_val_for_layout(namespace, name) } } @@ -413,7 +411,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> { ElementNodeTypeId(HTMLAnchorElementTypeId) | ElementNodeTypeId(HTMLAreaElementTypeId) | ElementNodeTypeId(HTMLLinkElementTypeId) => { - unsafe { self.element.get_attr_val_for_layout(&namespace::Null, "href") } + unsafe { self.element.get_attr_val_for_layout(&satom!(""), "href") } } _ => None, } @@ -427,7 +425,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] fn get_id(&self) -> Option { - unsafe { self.element.get_attr_atom_for_layout(&namespace::Null, "id") } + unsafe { self.element.get_attr_atom_for_layout(&satom!(""), "id") } } fn get_disabled_state(&self) -> bool { @@ -791,7 +789,7 @@ pub struct ThreadSafeLayoutElement<'le> { impl<'le> ThreadSafeLayoutElement<'le> { #[inline] - pub fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> { + pub fn get_attr(&self, namespace: &Atom, name: &str) -> Option<&'le str> { unsafe { self.element.get_attr_val_for_layout(namespace, name) } } } diff --git a/components/plugins/lints.rs b/components/plugins/lints.rs index 3d77b90a92f9..04f9bd8d07ef 100644 --- a/components/plugins/lints.rs +++ b/components/plugins/lints.rs @@ -145,4 +145,3 @@ impl LintPass for UnrootedPass { } } } - diff --git a/components/plugins/macros.rs b/components/plugins/macros.rs index 12a1953c43c4..16cdd29c0cb3 100644 --- a/components/plugins/macros.rs +++ b/components/plugins/macros.rs @@ -22,3 +22,16 @@ macro_rules! bitfield( } ) ) + +// NB: if your crate uses these then you also need +// #[phase(plugin)] extern crate string_cache; + +#[macro_export] +macro_rules! satom( + ($str:tt) => (::servo_util::atom::Atom { atom: atom!($str) }) +) + +#[macro_export] +macro_rules! sns( + ($str:tt) => (::servo_util::atom::Atom { atom: ns!($str) }) +) diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index cfd3c3d8e448..b3c657102852 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -57,3 +57,9 @@ git = "https://github.com/servo/rust-mozjs" [dependencies.url] git = "https://github.com/servo/rust-url" + +[dependencies.string_cache] +git = "https://github.com/servo/string-cache" + +[dependencies.string_cache_macros] +git = "https://github.com/servo/string-cache" diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index eaab52635078..7c03607181c1 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -16,8 +16,6 @@ use dom::virtualmethods::vtable_for; use devtools_traits::AttrInfo; use servo_util::atom::Atom; -use servo_util::namespace; -use servo_util::namespace::Namespace; use servo_util::str::{DOMString, split_html_space_chars}; use std::cell::{Ref, RefCell}; use std::mem; @@ -80,7 +78,7 @@ pub struct Attr { local_name: Atom, value: Traceable>, pub name: Atom, - pub namespace: Namespace, + pub namespace: Atom, pub prefix: Option, /// the element that owns this attribute. @@ -95,7 +93,7 @@ impl Reflectable for Attr { impl Attr { fn new_inherited(local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, + name: Atom, namespace: Atom, prefix: Option, owner: JSRef) -> Attr { Attr { reflector_: Reflector::new(), @@ -109,7 +107,7 @@ impl Attr { } pub fn new(window: JSRef, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, + name: Atom, namespace: Atom, prefix: Option, owner: JSRef) -> Temporary { reflect_dom_object(box Attr::new_inherited(local_name, value, name, namespace, prefix, owner), &Window(window), AttrBinding::Wrap) @@ -136,7 +134,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> { } fn GetNamespaceURI(self) -> Option { - match self.namespace.to_str() { + match self.namespace.as_slice() { "" => None, url => Some(url.to_string()), } @@ -158,7 +156,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { fn set_value(self, set_type: AttrSettingType, value: AttrValue) { let owner = self.owner.root(); let node: JSRef = NodeCast::from_ref(*owner); - let namespace_is_null = self.namespace == namespace::Null; + let namespace_is_null = self.namespace == satom!(""); match set_type { ReplacedAttr => { @@ -190,7 +188,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { fn summarize(self) -> AttrInfo { AttrInfo { - namespace: self.namespace.to_str().to_string(), + namespace: self.namespace.as_slice().to_string(), name: self.Name(), value: self.Value(), } diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 0d87892aecf3..65c4b3a8c68e 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -36,7 +36,6 @@ use std::cell::{Cell, RefCell}; use url::Url; use servo_util::atom::Atom; -use servo_util::namespace::Namespace; use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData}; use net::image_cache_task::ImageCacheTask; use script_traits::ScriptControlChan; @@ -226,7 +225,7 @@ untraceable!(uint, u8, u16, u32, u64) untraceable!(int, i8, i16, i32, i64) untraceable!(Untraceable) untraceable!(ImageCacheTask, ScriptControlChan) -untraceable!(Atom, Namespace) +untraceable!(Atom) untraceable!(PropertyDeclarationBlock) // These three are interdependent, if you plan to put jsmanaged data // in one of these make sure it is propagated properly to containing structs diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 41837aa5130f..3b27dae9149d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -54,10 +54,8 @@ use dom::window::{Window, WindowHelpers}; use html::hubbub_html_parser::build_element_from_tag; use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks}; use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage}; -use servo_util::atom::Atom; -use servo_util::namespace; -use servo_util::namespace::{Namespace, Null}; use servo_util::str::{DOMString, split_html_space_chars}; +use servo_util::atom::Atom; use std::collections::hashmap::HashMap; use std::ascii::StrAsciiExt; @@ -465,14 +463,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { return Err(InvalidCharacter); } let local_name = local_name.as_slice().to_ascii_lower(); - Ok(build_element_from_tag(local_name, namespace::HTML, self)) + Ok(build_element_from_tag(local_name, sns!(HTML), self)) } // http://dom.spec.whatwg.org/#dom-document-createelementns fn CreateElementNS(self, namespace: Option, qualified_name: DOMString) -> Fallible> { - let ns = Namespace::from_str(namespace); + let ns = Atom::from_option_domstring(&namespace); match xml_name_type(qualified_name.as_slice()) { InvalidXMLName => { debug!("Not a valid element name"); @@ -489,26 +487,26 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { local_name_from_qname) = get_attribute_parts(qualified_name.as_slice()); match (&ns, prefix_from_qname.clone(), local_name_from_qname.as_slice()) { // throw if prefix is not null and namespace is null - (&namespace::Null, Some(_), _) => { + (&satom!(""), Some(_), _) => { debug!("Namespace can't be null with a non-null prefix"); return Err(NamespaceError); }, // throw if prefix is "xml" and namespace is not the XML namespace - (_, Some(ref prefix), _) if "xml" == prefix.as_slice() && ns != namespace::XML => { + (_, Some(ref prefix), _) if "xml" == prefix.as_slice() && ns != sns!(XML) => { debug!("Namespace must be the xml namespace if the prefix is 'xml'"); return Err(NamespaceError); }, // throw if namespace is the XMLNS namespace and neither qualifiedName nor prefix is "xmlns" - (&namespace::XMLNS, Some(ref prefix), _) if "xmlns" == prefix.as_slice() => {}, - (&namespace::XMLNS, _, "xmlns") => {}, - (&namespace::XMLNS, _, _) => { + (&sns!(XMLNS), Some(ref prefix), _) if "xmlns" == prefix.as_slice() => {}, + (&sns!(XMLNS), _, "xmlns") => {}, + (&sns!(XMLNS), _, _) => { debug!("The prefix or the qualified name must be 'xmlns' if namespace is the XMLNS namespace "); return Err(NamespaceError); }, _ => {} } - if ns == namespace::HTML { + if ns == sns!(HTML) { Ok(build_element_from_tag(local_name_from_qname.to_string(), ns, self)) } else { Ok(Element::new(local_name_from_qname.to_string(), ns, @@ -750,7 +748,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } let element: JSRef = ElementCast::to_ref(node).unwrap(); - element.get_attribute(Null, "name").root().map_or(false, |attr| { + element.get_attribute(satom!(""), "name").root().map_or(false, |attr| { attr.value().as_slice() == name.as_slice() }) }) diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 3d99d9df7ebc..6b00d91072c6 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -13,7 +13,6 @@ use dom::element::{Element, AttributeHandlers}; use dom::node::window_from_node; use servo_util::atom::Atom; -use servo_util::namespace::Null; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; #[jstraceable] @@ -56,7 +55,7 @@ trait PrivateDOMTokenListHelpers { impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> { fn attribute(self) -> Option> { let element = self.element.root(); - element.deref().get_attribute(Null, self.local_name) + element.deref().get_attribute(satom!(""), self.local_name) } fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<&'a str> { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 7852f7aae0a7..77bdf785e60a 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -35,8 +35,6 @@ use devtools_traits::AttrInfo; use style::{matches, parse_selector_list_from_str}; use style; use servo_util::atom::Atom; -use servo_util::namespace; -use servo_util::namespace::{Namespace, Null}; use servo_util::str::DOMString; use std::ascii::StrAsciiExt; @@ -48,7 +46,7 @@ use std::mem; pub struct Element { pub node: Node, pub local_name: Atom, - pub namespace: Namespace, + pub namespace: Atom, pub prefix: Option, pub attrs: RefCell>>, pub style_attribute: Traceable>>, @@ -150,7 +148,7 @@ pub enum ElementTypeId { // impl Element { - pub fn new_inherited(type_id: ElementTypeId, local_name: DOMString, namespace: Namespace, prefix: Option, document: JSRef) -> Element { + pub fn new_inherited(type_id: ElementTypeId, local_name: DOMString, namespace: Atom, prefix: Option, document: JSRef) -> Element { Element { node: Node::new_inherited(ElementNodeTypeId(type_id), document), local_name: Atom::from_slice(local_name.as_slice()), @@ -163,22 +161,22 @@ impl Element { } } - pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: JSRef) -> Temporary { + pub fn new(local_name: DOMString, namespace: Atom, prefix: Option, document: JSRef) -> Temporary { Node::reflect_node(box Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document), document, ElementBinding::Wrap) } } pub trait RawLayoutElementHelpers { - unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &str) -> Option<&'a str>; - unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) -> Option; + unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Atom, name: &str) -> Option<&'a str>; + unsafe fn get_attr_atom_for_layout(&self, namespace: &Atom, name: &str) -> Option; unsafe fn has_class_for_layout(&self, name: &str) -> bool; } impl RawLayoutElementHelpers for Element { #[inline] #[allow(unrooted_must_root)] - unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &str) + unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Atom, name: &str) -> Option<&'a str> { // cast to point to T in RefCell directly let attrs: *const Vec> = mem::transmute(&self.attrs); @@ -194,7 +192,7 @@ impl RawLayoutElementHelpers for Element { #[inline] #[allow(unrooted_must_root)] - unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) + unsafe fn get_attr_atom_for_layout(&self, namespace: &Atom, name: &str) -> Option { // cast to point to T in RefCell directly let attrs: *const Vec> = mem::transmute(&self.attrs); @@ -229,7 +227,7 @@ pub trait LayoutElementHelpers { impl LayoutElementHelpers for JS { #[allow(unrooted_must_root)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool { - if (*self.unsafe_get()).namespace != namespace::HTML { + if (*self.unsafe_get()).namespace != sns!(HTML) { return false } let node: JS = self.transmute_copy(); @@ -241,7 +239,7 @@ impl LayoutElementHelpers for JS { pub trait ElementHelpers { fn html_element_in_html_document(&self) -> bool; fn get_local_name<'a>(&'a self) -> &'a Atom; - fn get_namespace<'a>(&'a self) -> &'a Namespace; + fn get_namespace<'a>(&'a self) -> &'a Atom; fn summarize(self) -> Vec; fn is_void(self) -> bool; } @@ -249,14 +247,14 @@ pub trait ElementHelpers { impl<'a> ElementHelpers for JSRef<'a, Element> { fn html_element_in_html_document(&self) -> bool { let node: JSRef = NodeCast::from_ref(*self); - self.namespace == namespace::HTML && node.is_in_html_doc() + self.namespace == sns!(HTML) && node.is_in_html_doc() } fn get_local_name<'a>(&'a self) -> &'a Atom { &self.deref().local_name } - fn get_namespace<'a>(&'a self) -> &'a Namespace { + fn get_namespace<'a>(&'a self) -> &'a Atom { &self.deref().namespace } @@ -273,7 +271,7 @@ impl<'a> ElementHelpers for JSRef<'a, Element> { } fn is_void(self) -> bool { - if self.namespace != namespace::HTML { + if self.namespace != sns!(HTML) { return false } match self.local_name.as_slice() { @@ -290,19 +288,19 @@ impl<'a> ElementHelpers for JSRef<'a, Element> { pub trait AttributeHandlers { /// Returns the attribute with given namespace and case-sensitive local /// name, if any. - fn get_attribute(self, namespace: Namespace, local_name: &str) + fn get_attribute(self, namespace: Atom, local_name: &str) -> Option>; fn set_attribute_from_parser(self, local_name: Atom, - value: DOMString, namespace: Namespace, + value: DOMString, namespace: Atom, prefix: Option); fn set_attribute(self, name: &str, value: AttrValue); fn do_set_attribute(self, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, + name: Atom, namespace: Atom, prefix: Option, cb: |JSRef| -> bool); - fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, + fn parse_attribute(self, namespace: &Atom, local_name: &Atom, value: DOMString) -> AttrValue; - fn remove_attribute(self, namespace: Namespace, name: &str); + fn remove_attribute(self, namespace: Atom, name: &str); fn notify_attribute_changed(self, local_name: &Atom); fn has_class(&self, name: &str) -> bool; @@ -321,7 +319,7 @@ pub trait AttributeHandlers { } impl<'a> AttributeHandlers for JSRef<'a, Element> { - fn get_attribute(self, namespace: Namespace, local_name: &str) -> Option> { + fn get_attribute(self, namespace: Atom, local_name: &str) -> Option> { let local_name = Atom::from_slice(local_name); self.attrs.borrow().iter().map(|attr| attr.root()).find(|attr| { *attr.local_name() == local_name && attr.namespace == namespace @@ -329,7 +327,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn set_attribute_from_parser(self, local_name: Atom, - value: DOMString, namespace: Namespace, + value: DOMString, namespace: Atom, prefix: Option) { let name = match prefix { None => local_name.clone(), @@ -351,11 +349,11 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let name = Atom::from_slice(name); self.do_set_attribute(name.clone(), value, name.clone(), - namespace::Null, None, |attr| *attr.local_name() == name); + satom!(""), None, |attr| *attr.local_name() == name); } fn do_set_attribute(self, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, + name: Atom, namespace: Atom, prefix: Option, cb: |JSRef| -> bool) { let idx = self.deref().attrs.borrow().iter() .map(|attr| attr.root()) @@ -374,9 +372,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { (*self.deref().attrs.borrow())[idx].root().set_value(set_type, value); } - fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, + fn parse_attribute(self, namespace: &Atom, local_name: &Atom, value: DOMString) -> AttrValue { - if *namespace == namespace::Null { + if *namespace == satom!("") { vtable_for(&NodeCast::from_ref(self)) .parse_plain_attribute(local_name.as_slice(), value) } else { @@ -384,7 +382,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } } - fn remove_attribute(self, namespace: Namespace, name: &str) { + fn remove_attribute(self, namespace: Atom, name: &str) { let (_, local_name) = get_attribute_parts(name); let local_name = Atom::from_slice(local_name); @@ -400,7 +398,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { node.wait_until_safe_to_modify_dom(); } - if namespace == namespace::Null { + if namespace == satom!("") { let removed_raw_value = (*self.deref().attrs.borrow())[idx].root().Value(); vtable_for(&NodeCast::from_ref(self)) .before_remove_attr(&local_name, @@ -425,7 +423,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn has_class(&self, name: &str) -> bool { - self.get_attribute(Null, "class").root().map(|attr| { + self.get_attribute(satom!(""), "class").root().map(|attr| { attr.deref().value().tokens().map(|mut tokens| { tokens.any(|atom| atom.as_slice() == name) }).unwrap_or(false) @@ -444,7 +442,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { false => Atom::from_slice(name) }; self.deref().attrs.borrow().iter().map(|attr| attr.root()).any(|attr| { - *attr.local_name() == name && attr.namespace == Null + *attr.local_name() == name && attr.namespace == satom!("") }) } @@ -453,7 +451,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { if value { self.set_string_attribute(name, String::new()); } else { - self.remove_attribute(Null, name); + self.remove_attribute(satom!(""), name); } } @@ -468,7 +466,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_string_attribute(self, name: &str) -> DOMString { assert!(name == name.to_ascii_lower().as_slice()); - match self.get_attribute(Null, name) { + match self.get_attribute(satom!(""), name) { Some(x) => { let x = x.root(); x.deref().Value() @@ -488,7 +486,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_uint_attribute(self, name: &str) -> u32 { assert!(name == name.to_ascii_lower().as_slice()); - let attribute = self.get_attribute(Null, name).root(); + let attribute = self.get_attribute(satom!(""), name).root(); match attribute { Some(attribute) => { match *attribute.deref().value() { @@ -509,8 +507,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-namespaceuri fn GetNamespaceURI(self) -> Option { match self.namespace { - Null => None, - ref ns => Some(ns.to_str().to_string()) + satom!("") => None, + ref ns => Some(ns.as_slice().to_string()) } } @@ -592,7 +590,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } else { name }; - self.get_attribute(Null, name.as_slice()).root() + self.get_attribute(satom!(""), name.as_slice()).root() .map(|s| s.deref().Value()) } @@ -600,7 +598,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetAttributeNS(self, namespace: Option, local_name: DOMString) -> Option { - let namespace = Namespace::from_str(namespace); + let namespace = Atom::from_option_domstring(&namespace); self.get_attribute(namespace, local_name.as_slice()).root() .map(|attr| attr.deref().Value()) } @@ -629,8 +627,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // Step 3-5. let name = Atom::from_slice(name.as_slice()); - let value = self.parse_attribute(&namespace::Null, &name, value); - self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| { + let value = self.parse_attribute(&satom!(""), &name, value); + self.do_set_attribute(name.clone(), value, name.clone(), satom!(""), None, |attr| { attr.deref().name.as_slice() == name.as_slice() }); Ok(()) @@ -647,7 +645,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // Step 1. - let namespace = Namespace::from_str(namespace_url); + let namespace = Atom::from_option_domstring(&namespace_url); let name_type = xml_name_type(name.as_slice()); match name_type { @@ -663,17 +661,17 @@ impl<'a> ElementMethods for JSRef<'a, Element> { match prefix { Some(ref prefix_str) => { // Step 5. - if namespace == namespace::Null { + if namespace == satom!("") { return Err(NamespaceError); } // Step 6. - if "xml" == prefix_str.as_slice() && namespace != namespace::XML { + if "xml" == prefix_str.as_slice() && namespace != sns!(XML) { return Err(NamespaceError); } // Step 7b. - if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { + if "xmlns" == prefix_str.as_slice() && namespace != sns!(XMLNS) { return Err(NamespaceError); } }, @@ -685,12 +683,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let xmlns = Atom::from_slice("xmlns"); // TODO: Make this a static atom type // Step 7a. - if xmlns == name && namespace != namespace::XMLNS { + if xmlns == name && namespace != sns!(XMLNS) { return Err(NamespaceError); } // Step 8. - if namespace == namespace::XMLNS && xmlns != name && Some("xmlns") != prefix { + if namespace == sns!(XMLNS) && xmlns != name && Some("xmlns") != prefix { return Err(NamespaceError); } @@ -712,14 +710,14 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } else { name }; - self.remove_attribute(namespace::Null, name.as_slice()) + self.remove_attribute(satom!(""), name.as_slice()) } // http://dom.spec.whatwg.org/#dom-element-removeattributens fn RemoveAttributeNS(self, namespace: Option, localname: DOMString) { - let namespace = Namespace::from_str(namespace); + let namespace = Atom::from_option_domstring(&namespace); self.remove_attribute(namespace, localname.as_slice()) } @@ -913,7 +911,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { if !tree_in_doc { return; } - match self.get_attribute(Null, "id").root() { + match self.get_attribute(satom!(""), "id").root() { Some(attr) => { let doc = document_from_node(*self).root(); let value = attr.deref().Value(); @@ -934,7 +932,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { if !tree_in_doc { return; } - match self.get_attribute(Null, "id").root() { + match self.get_attribute(satom!(""), "id").root() { Some(attr) => { let doc = document_from_node(*self).root(); let value = attr.deref().Value(); @@ -949,7 +947,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } impl<'a> style::TElement<'a> for JSRef<'a, Element> { - fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str> { + fn get_attr(&self, namespace: &Atom, attr: &str) -> Option<&'a str> { self.get_attribute(namespace.clone(), attr).root().map(|attr| { unsafe { mem::transmute(attr.deref().value().as_slice()) } }) @@ -962,14 +960,14 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { // selector-link ElementNodeTypeId(HTMLAnchorElementTypeId) | ElementNodeTypeId(HTMLAreaElementTypeId) | - ElementNodeTypeId(HTMLLinkElementTypeId) => self.get_attr(&namespace::Null, "href"), + ElementNodeTypeId(HTMLLinkElementTypeId) => self.get_attr(&satom!(""), "href"), _ => None, } } fn get_local_name<'b>(&'b self) -> &'b Atom { (self as &ElementHelpers).get_local_name() } - fn get_namespace<'b>(&'b self) -> &'b Namespace { + fn get_namespace<'b>(&'b self) -> &'b Atom { (self as &ElementHelpers).get_namespace() } fn get_hover_state(&self) -> bool { @@ -977,7 +975,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { node.get_hover_state() } fn get_id<'a>(&self) -> Option { - self.get_attribute(namespace::Null, "id").map(|attr| { + self.get_attribute(satom!(""), "id").map(|attr| { let attr = attr.root(); match *attr.value() { AtomAttrValue(ref val) => val.clone(), diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index c73cb01a8dec..90a27dff3f14 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -20,7 +20,6 @@ use dom::node::{Node, NodeHelpers, ElementNodeTypeId}; use dom::virtualmethods::VirtualMethods; use servo_util::atom::Atom; -use servo_util::namespace::Null; use servo_util::str::DOMString; #[jstraceable] @@ -57,7 +56,7 @@ impl<'a> PrivateHTMLAnchorElementHelpers for JSRef<'a, HTMLAnchorElement> { fn handle_event_impl(self, event: JSRef) { if "click" == event.Type().as_slice() && !event.DefaultPrevented() { let element: JSRef = ElementCast::from_ref(self); - let attr = element.get_attribute(Null, "href").root(); + let attr = element.get_attribute(satom!(""), "href").root(); match attr { Some(ref href) => { let value = href.Value(); diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 857dbb2ef5d6..66a759734c10 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -13,7 +13,6 @@ use dom::element::{Element, AttributeHandlers, ElementHelpers}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; use servo_util::atom::Atom; -use servo_util::namespace::Namespace; use servo_util::str::{DOMString, split_html_space_chars}; use std::ascii::StrAsciiExt; @@ -57,10 +56,10 @@ impl HTMLCollection { } fn all_elements(window: JSRef, root: JSRef, - namespace_filter: Option) -> Temporary { + namespace_filter: Option) -> Temporary { #[jstraceable] struct AllElementFilter { - namespace_filter: Option + namespace_filter: Option } impl CollectionFilter for AllElementFilter { fn filter(&self, elem: JSRef, _root: JSRef) -> bool { @@ -105,7 +104,7 @@ impl HTMLCollection { maybe_ns: Option) -> Temporary { let namespace_filter = match maybe_ns { Some(ref namespace) if namespace.as_slice() == "*" => None, - ns => Some(Namespace::from_str(ns)), + ns => Some(Atom::from_option_domstring(&ns)), }; if tag.as_slice() == "*" { @@ -114,7 +113,7 @@ impl HTMLCollection { #[jstraceable] struct TagNameNSFilter { tag: Atom, - namespace_filter: Option + namespace_filter: Option } impl CollectionFilter for TagNameNSFilter { fn filter(&self, elem: JSRef, _root: JSRef) -> bool { diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index c8831eab5739..4a14a94fc26d 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -18,7 +18,6 @@ use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; use servo_util::atom::Atom; -use servo_util::namespace; use servo_util::str::DOMString; #[jstraceable] @@ -40,7 +39,7 @@ impl HTMLElementDerived for EventTarget { impl HTMLElement { pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JSRef) -> HTMLElement { HTMLElement { - element: Element::new_inherited(type_id, tag_name, namespace::HTML, None, document) + element: Element::new_inherited(type_id, tag_name, sns!(HTML), None, document) } } diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 828ba978427c..9238a3750fad 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -24,7 +24,6 @@ use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_msg::constellation_msg::{IFrameSandboxed, IFrameUnsandboxed}; use servo_msg::constellation_msg::{ConstellationChan, LoadIframeUrlMsg}; use servo_util::atom::Atom; -use servo_util::namespace::Null; use servo_util::str::DOMString; use std::ascii::StrAsciiExt; @@ -75,7 +74,7 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { fn get_url(self) -> Option { let element: JSRef = ElementCast::from_ref(self); - element.get_attribute(Null, "src").root().and_then(|src| { + element.get_attribute(satom!(""), "src").root().and_then(|src| { let url = src.deref().value(); if url.as_slice().is_empty() { None diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index c347e7e27a2c..d0bc652474fa 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -17,7 +17,6 @@ use dom::virtualmethods::VirtualMethods; use layout_interface::{LayoutChan, LoadStylesheetMsg}; use servo_util::atom::Atom; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; -use servo_util::namespace::Null; use std::ascii::StrAsciiExt; use url::UrlParser; @@ -49,7 +48,7 @@ impl HTMLLinkElement { } fn get_attr(element: JSRef, name: &str) -> Option { - let elem = element.get_attribute(Null, name).root(); + let elem = element.get_attribute(satom!(""), name).root(); elem.map(|e| e.deref().value().as_slice().to_string()) } diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 49ea7d1a716b..569b2ee96f60 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -21,7 +21,6 @@ use dom::virtualmethods::VirtualMethods; use servo_net::image_cache_task; use servo_net::image_cache_task::ImageCacheTask; use servo_util::atom::Atom; -use servo_util::namespace::Null; use servo_util::str::DOMString; use url::Url; @@ -63,8 +62,8 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { let elem: JSRef = ElementCast::from_ref(*self); // TODO: support other values - match (elem.get_attribute(Null, "type").map(|x| x.root().Value()), - elem.get_attribute(Null, "data").map(|x| x.root().Value())) { + match (elem.get_attribute(satom!(""), "type").map(|x| x.root().Value()), + elem.get_attribute(satom!(""), "data").map(|x| x.root().Value())) { (None, Some(uri)) => { if is_image_data(uri.as_slice()) { let data_url = Url::parse(uri.as_slice()).unwrap(); diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index fc889bc855c3..77d2d475660c 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -20,7 +20,6 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId}; use dom::virtualmethods::VirtualMethods; use servo_util::atom::Atom; -use servo_util::namespace; use servo_util::str::{DOMString, split_html_space_chars}; #[jstraceable] @@ -51,7 +50,7 @@ impl HTMLOptionElement { fn collect_text(node: &JSRef, value: &mut DOMString) { let elem: JSRef = ElementCast::to_ref(*node).unwrap(); - let svg_script = elem.namespace == namespace::SVG && elem.local_name.as_slice() == "script"; + let svg_script = elem.namespace == sns!(SVG) && elem.local_name.as_slice() == "script"; let html_script = node.is_htmlscriptelement(); if svg_script || html_script { return; diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index e29010ec2ecb..fb085554933c 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -16,7 +16,6 @@ use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::node::{Node, NodeHelpers, ElementNodeTypeId}; -use servo_util::namespace::Null; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec}; #[jstraceable] @@ -75,7 +74,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { fn is_javascript(self) -> bool { let element: JSRef = ElementCast::from_ref(self); - match element.get_attribute(Null, "type").root().map(|s| s.Value()) { + match element.get_attribute(satom!(""), "type").root().map(|s| s.Value()) { Some(ref s) if s.is_empty() => { // type attr exists, but empty means js debug!("script type empty, inferring js"); @@ -87,7 +86,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { }, None => { debug!("no script type"); - match element.get_attribute(Null, "language").root().map(|s| s.Value()) { + match element.get_attribute(satom!(""), "language").root().map(|s| s.Value()) { Some(ref s) if s.is_empty() => { debug!("script language empty, inferring js"); true diff --git a/components/script/dom/htmlserializer.rs b/components/script/dom/htmlserializer.rs index 19aa7e2f0dd9..f175d132a1f9 100644 --- a/components/script/dom/htmlserializer.rs +++ b/components/script/dom/htmlserializer.rs @@ -19,7 +19,6 @@ use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; use servo_util::atom::Atom; -use servo_util::namespace; #[allow(unrooted_must_root)] pub fn serialize(iterator: &mut NodeIterator) -> String { @@ -82,7 +81,7 @@ fn serialize_text(text: JSRef, html: &mut String) { match elem.deref().local_name.as_slice() { "style" | "script" | "xmp" | "iframe" | "noembed" | "noframes" | "plaintext" | - "noscript" if elem.deref().namespace == namespace::HTML + "noscript" if elem.deref().namespace == sns!(HTML) => html.push_str(text.deref().characterdata.data.deref().borrow().as_slice()), _ => escape(text.deref().characterdata.data.deref().borrow().as_slice(), false, html) } @@ -116,7 +115,7 @@ fn serialize_elem(elem: JSRef, open_elements: &mut Vec, html: & html.push_char('>'); match elem.deref().local_name.as_slice() { - "pre" | "listing" | "textarea" if elem.deref().namespace == namespace::HTML => { + "pre" | "listing" | "textarea" if elem.deref().namespace == sns!(HTML) => { let node: JSRef = NodeCast::from_ref(elem); match node.first_child().map(|child| child.root()) { Some(ref child) if child.is_text() => { @@ -138,16 +137,16 @@ fn serialize_elem(elem: JSRef, open_elements: &mut Vec, html: & fn serialize_attr(attr: JSRef, html: &mut String) { html.push_char(' '); - if attr.deref().namespace == namespace::XML { + if attr.deref().namespace == sns!(XML) { html.push_str("xml:"); html.push_str(attr.local_name().as_slice()); - } else if attr.deref().namespace == namespace::XMLNS && + } else if attr.deref().namespace == sns!(XMLNS) && *attr.local_name() == Atom::from_slice("xmlns") { html.push_str("xmlns"); - } else if attr.deref().namespace == namespace::XMLNS { + } else if attr.deref().namespace == sns!(XMLNS) { html.push_str("xmlns:"); html.push_str(attr.local_name().as_slice()); - } else if attr.deref().namespace == namespace::XLink { + } else if attr.deref().namespace == sns!(XLink) { html.push_str("xlink:"); html.push_str(attr.local_name().as_slice()); } else { diff --git a/components/script/html/hubbub_html_parser.rs b/components/script/html/hubbub_html_parser.rs index 097f8438cb5a..b0337f9f7662 100644 --- a/components/script/html/hubbub_html_parser.rs +++ b/components/script/html/hubbub_html_parser.rs @@ -26,8 +26,6 @@ use hubbub::hubbub; use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs}; use servo_net::resource_task::{Load, LoadData, Payload, Done, ResourceTask, load_whole_resource}; use servo_util::atom::Atom; -use servo_util::namespace; -use servo_util::namespace::{Namespace, Null}; use servo_util::str::DOMString; use servo_util::task::spawn_named; use std::ascii::StrAsciiExt; @@ -152,8 +150,8 @@ fn parse_last_modified(timestamp: &str) -> String { // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, ns: Namespace, document: JSRef) -> Temporary { - if ns != namespace::HTML { +pub fn build_element_from_tag(tag: DOMString, ns: Atom, document: JSRef) -> Temporary { + if ns != sns!(HTML) { return Element::new(tag, ns, None, document); } @@ -373,9 +371,9 @@ pub fn parse_html(page: &Page, let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let namespace = match tag.ns { - HtmlNs => namespace::HTML, - MathMlNs => namespace::MathML, - SvgNs => namespace::SVG, + HtmlNs => sns!(HTML), + MathMlNs => sns!(MathML), + SvgNs => sns!(SVG), ns => fail!("Not expecting namespace {:?}", ns), }; let element: Root = build_element_from_tag(tag.name.clone(), namespace, *tmp).root(); @@ -383,10 +381,10 @@ pub fn parse_html(page: &Page, debug!("-- attach attrs"); for attr in tag.attributes.iter() { let (namespace, prefix) = match attr.ns { - NullNs => (namespace::Null, None), - XLinkNs => (namespace::XLink, Some("xlink")), - XmlNs => (namespace::XML, Some("xml")), - XmlNsNs => (namespace::XMLNS, Some("xmlns")), + NullNs => (satom!(""), None), + XLinkNs => (sns!(XLink), Some("xlink")), + XmlNs => (sns!(XML), Some("xml")), + XmlNsNs => (sns!(XMLNS), Some("xmlns")), ns => fail!("Not expecting namespace {:?}", ns), }; element.set_attribute_from_parser(Atom::from_slice(attr.name.as_slice()), @@ -472,7 +470,7 @@ pub fn parse_html(page: &Page, }; let script_element: JSRef = ElementCast::from_ref(script); - match script_element.get_attribute(Null, "src").root() { + match script_element.get_attribute(satom!(""), "src").root() { Some(src) => { debug!("found script: {:s}", src.deref().Value()); let mut url_parser = UrlParser::new(); diff --git a/components/script/lib.rs b/components/script/lib.rs index 695aef3c1b57..09bea1b73bdc 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -42,6 +42,9 @@ extern crate sync; extern crate "msg" as servo_msg; extern crate url; extern crate uuid; +extern crate string_cache; +#[phase(plugin)] +extern crate string_cache_macros; pub mod cors; diff --git a/components/script/page.rs b/components/script/page.rs index da2b99c0c6ff..554ae41196fc 100644 --- a/components/script/page.rs +++ b/components/script/page.rs @@ -27,7 +27,6 @@ use servo_msg::compositor_msg::ScriptListener; use servo_msg::constellation_msg::{ConstellationChan, WindowSizeData}; use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_net::resource_task::ResourceTask; -use servo_util::namespace::Null; use servo_util::str::DOMString; use std::cell::{Cell, RefCell, Ref, RefMut}; use std::comm::{channel, Receiver, Empty, Disconnected}; @@ -400,7 +399,7 @@ impl Page { .filter(|node| node.is_anchor_element()); anchors.find(|node| { let elem: JSRef = ElementCast::to_ref(*node).unwrap(); - elem.get_attribute(Null, "name").root().map_or(false, |attr| { + elem.get_attribute(satom!(""), "name").root().map_or(false, |attr| { attr.deref().value().as_slice() == fragid.as_slice() }) }).map(|node| Temporary::from_rooted(ElementCast::to_ref(node).unwrap())) diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index a272eeb01f3e..330970e478a0 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -31,3 +31,9 @@ git = "https://github.com/lifthrasiir/rust-encoding" [dependencies.lazy_static] git = "https://github.com/Kimundi/lazy-static.rs" + +[dependencies.string_cache] +git = "https://github.com/servo/string-cache" + +[dependencies.string_cache_macros] +git = "https://github.com/servo/string-cache" diff --git a/components/style/lib.rs b/components/style/lib.rs index 05b358eec708..8aff7c436a72 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -22,9 +22,17 @@ extern crate url; extern crate cssparser; extern crate encoding; +extern crate string_cache; + +#[phase(plugin)] +extern crate string_cache_macros; + #[phase(plugin)] extern crate lazy_static; +#[phase(plugin)] +extern crate "plugins" as servo_plugins; + extern crate "util" as servo_util; diff --git a/components/style/namespaces.rs b/components/style/namespaces.rs index 77e5fed340b2..b8e6eb47ca4e 100644 --- a/components/style/namespaces.rs +++ b/components/style/namespaces.rs @@ -4,12 +4,12 @@ use cssparser::ast::*; use std::collections::hashmap::HashMap; -use servo_util::namespace::Namespace; +use servo_util::atom::Atom; use errors::log_css_error; pub struct NamespaceMap { - pub default: Option, - pub prefix_map: HashMap, + pub default: Option, + pub prefix_map: HashMap, } @@ -30,7 +30,7 @@ pub fn parse_namespace_rule(rule: AtRule, namespaces: &mut NamespaceMap) { ); if rule.block.is_some() { syntax_error!() } let mut prefix: Option = None; - let mut ns: Option = None; + let mut ns: Option = None; let mut iter = rule.prelude.move_skip_whitespace(); for component_value in iter { match component_value { @@ -40,7 +40,7 @@ pub fn parse_namespace_rule(rule: AtRule, namespaces: &mut NamespaceMap) { }, URL(value) | String(value) => { if ns.is_some() { syntax_error!() } - ns = Some(Namespace::from_str(Some(value))); + ns = Some(Atom::from_slice(value.as_slice())); break }, _ => syntax_error!(), diff --git a/components/style/node.rs b/components/style/node.rs index 8b05097f9c05..f0fdc73e570f 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -7,7 +7,6 @@ use selectors::AttrSelector; use servo_util::atom::Atom; -use servo_util::namespace::Namespace; pub trait TNode<'a, E: TElement<'a>> : Clone { @@ -24,10 +23,10 @@ pub trait TNode<'a, E: TElement<'a>> : Clone { } pub trait TElement<'a> { - fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str>; + fn get_attr(&self, namespace: &Atom, attr: &str) -> Option<&'a str>; fn get_link(&self) -> Option<&'a str>; fn get_local_name<'b>(&'b self) -> &'b Atom; - fn get_namespace<'b>(&'b self) -> &'b Namespace; + fn get_namespace<'b>(&'b self) -> &'b Atom; fn get_hover_state(&self) -> bool; fn get_id(&self) -> Option; fn get_disabled_state(&self) -> bool; diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 3fb904352690..b4920a1a97a3 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -11,7 +11,6 @@ use url::Url; use servo_util::atom::Atom; use servo_util::bloom::BloomFilter; -use servo_util::namespace; use servo_util::smallvec::VecLike; use servo_util::sort; @@ -107,7 +106,7 @@ impl SelectorMap { None => {} } - match element.get_attr(&namespace::Null, "class") { + match element.get_attr(&satom!(""), "class") { Some(ref class_attr) => { // FIXME: Store classes pre-split as atoms to make the loop below faster. for class in class_attr.split(SELECTOR_WHITESPACE) { diff --git a/components/style/selectors.rs b/components/style/selectors.rs index 8540dc1648d2..1e68820aa98b 100644 --- a/components/style/selectors.rs +++ b/components/style/selectors.rs @@ -10,8 +10,6 @@ use cssparser::ast::*; use cssparser::{tokenize, parse_nth}; use servo_util::atom::Atom; -use servo_util::namespace::Namespace; -use servo_util::namespace; use namespaces::NamespaceMap; @@ -59,7 +57,7 @@ pub enum SimpleSelector { IDSelector(Atom), ClassSelector(Atom), LocalNameSelector(LocalNameSelector), - NamespaceSelector(Namespace), + NamespaceSelector(Atom), // Attribute selectors AttrExists(AttrSelector), // [foo] @@ -108,7 +106,7 @@ pub struct AttrSelector { #[deriving(Eq, PartialEq, Clone, Hash)] pub enum NamespaceConstraint { AnyNamespace, - SpecificNamespace(Namespace), + SpecificNamespace(Atom), } @@ -414,7 +412,7 @@ fn parse_qualified_name>( explicit_namespace(iter, SpecificNamespace(namespace)) }, _ if in_attr_selector => Ok(Some( - (SpecificNamespace(namespace::Null), Some(value)))), + (SpecificNamespace(satom!("")), Some(value)))), _ => default_namespace(Some(value)), } }, @@ -428,7 +426,7 @@ fn parse_qualified_name>( }, } }, - Some(&Delim('|')) => explicit_namespace(iter, SpecificNamespace(namespace::Null)), + Some(&Delim('|')) => explicit_namespace(iter, SpecificNamespace(satom!(""))), _ => Ok(None), } } @@ -576,7 +574,6 @@ mod tests { use sync::Arc; use cssparser; use servo_util::atom::Atom; - use servo_util::namespace; use namespaces::NamespaceMap; use super::*; @@ -655,7 +652,7 @@ mod tests { simple_selectors: vec!(AttrExists(AttrSelector { name: Atom::from_slice("Foo"), lower_name: Atom::from_slice("foo"), - namespace: SpecificNamespace(namespace::Null), + namespace: SpecificNamespace(satom!("")), })), next: None, }), @@ -664,13 +661,13 @@ mod tests { }))) // Default namespace does not apply to attribute selectors // https://github.com/mozilla/servo/pull/1652 - namespaces.default = Some(namespace::MathML); + namespaces.default = Some(sns!(MathML)); assert!(parse_ns("[Foo]", &namespaces) == Ok(vec!(Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec!(AttrExists(AttrSelector { name: Atom::from_slice("Foo"), lower_name: Atom::from_slice("foo"), - namespace: SpecificNamespace(namespace::Null), + namespace: SpecificNamespace(satom!("")), })), next: None, }), @@ -681,7 +678,7 @@ mod tests { assert!(parse_ns("e", &namespaces) == Ok(vec!(Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec!( - NamespaceSelector(namespace::MathML), + NamespaceSelector(sns!(MathML)), LocalNameSelector(LocalNameSelector { name: Atom::from_slice("e"), lower_name: Atom::from_slice("e") }), diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 3e599630f0c1..5b930c305e3a 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -7,6 +7,9 @@ authors = ["The Servo Project Developers"] name = "util" path = "lib.rs" +[dependencies.plugins] +path = "../plugins" + [dependencies.azure] git = "https://github.com/servo/rust-azure" @@ -19,5 +22,8 @@ path = "../../support/rust-task_info" [dependencies.string_cache] git = "https://github.com/servo/string-cache" +[dependencies.string_cache_macros] +git = "https://github.com/servo/string-cache" + [dependencies.url] git = "https://github.com/servo/rust-url" diff --git a/components/util/atom.rs b/components/util/atom.rs index 49cb047768e5..43afea2e3745 100644 --- a/components/util/atom.rs +++ b/components/util/atom.rs @@ -6,6 +6,8 @@ //! crate. It's needed so that it can implement the Encodable //! trait which is required by Servo. +use str::DOMString; + use serialize::{Encoder, Encodable}; use std::fmt; use std::hash::Hash; @@ -13,7 +15,8 @@ use string_cache::atom; #[deriving(Clone, Eq, Hash, PartialEq)] pub struct Atom { - atom: atom::Atom, + /// Public for use by pattern macros + pub atom: atom::Atom, } impl Atom { @@ -24,6 +27,14 @@ impl Atom { } } + #[inline(always)] + pub fn from_option_domstring(s: &Option) -> Atom { + match *s { + None => satom!(""), + Some(ref s) => Atom::from_slice(s.as_slice()), + } + } + #[inline(always)] pub fn as_slice<'t>(&'t self) -> &'t str { self.atom.as_slice() diff --git a/components/util/lib.rs b/components/util/lib.rs index 89fcec41d933..c1eb8c1d8c7a 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -29,6 +29,11 @@ extern crate "time" as std_time; extern crate string_cache; extern crate url; +#[phase(plugin)] +extern crate string_cache_macros; +#[phase(plugin)] +extern crate "plugins" as servo_plugins; + pub mod atom; pub mod bloom; pub mod cache; @@ -37,7 +42,6 @@ pub mod fnv; pub mod geometry; pub mod logical_geometry; pub mod memory; -pub mod namespace; pub mod opts; pub mod range; pub mod smallvec; @@ -49,6 +53,11 @@ pub mod time; pub mod vec; pub mod workqueue; +// for macros +pub mod servo_util { + pub use atom; +} + pub fn breakpoint() { unsafe { ::std::intrinsics::breakpoint() }; } diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 74fe836c0b3e..f58ccc2d99c3 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -12,10 +12,10 @@ dependencies = [ "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", "js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#ed570335738913fb41fc62a024389dfa415962e8)", -"plugins 0.0.1", "msg 0.0.1", "net 0.0.1", "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", + "plugins 0.0.1", "png 0.1.0 (git+https://github.com/servo/rust-png#74418ffbf20e94b0d3bed4a9d004062a13342c79)", "script 0.0.1", "servo 0.0.1", @@ -194,9 +194,9 @@ dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", "harfbuzz 0.1.0 (git+https://github.com/servo/rust-harfbuzz#ad520942cc17232e1a40cdd8a99c2905623d35f6)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#ed570335738913fb41fc62a024389dfa415962e8)", - "plugins 0.0.1", "msg 0.0.1", "net 0.0.1", + "plugins 0.0.1", "png 0.1.0 (git+https://github.com/servo/rust-png#74418ffbf20e94b0d3bed4a9d004062a13342c79)", "stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image#f5022de4ad6bb474a03493d1f274dde9b0f1af0c)", "style 0.0.1", @@ -295,10 +295,12 @@ dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", "gfx 0.0.1", "layout_traits 0.0.1", - "plugins 0.0.1", "net 0.0.1", + "plugins 0.0.1", "script 0.0.1", "script_traits 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "style 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", @@ -320,10 +322,6 @@ name = "lazy_static" version = "0.1.0" source = "git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360" -[[package]] -name = "plugins" -version = "0.0.1" - [[package]] name = "mozjs-sys" version = "0.0.0" @@ -379,6 +377,10 @@ name = "phf_mac" version = "0.0.0" source = "git+https://github.com/sfackler/rust-phf#06254fdde7708630a6397c41c6c17ef81a4b66a0" +[[package]] +name = "plugins" +version = "0.0.1" + [[package]] name = "png" version = "0.1.0" @@ -405,10 +407,12 @@ dependencies = [ "http 0.1.0-pre (git+https://github.com/servo/rust-http?ref=servo#4fdedeea8fc77149adf51bb24a37372af21c25b7)", "hubbub 0.1.0 (git+https://github.com/servo/rust-hubbub#c7f868e688de6e9cbdc26aa09292ed072bc2648b)", "js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)", - "plugins 0.0.1", "msg 0.0.1", "net 0.0.1", + "plugins 0.0.1", "script_traits 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "style 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", @@ -485,6 +489,8 @@ dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", "lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)", "plugins 0.0.1", + "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", "util 0.0.1", ] @@ -507,7 +513,9 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure#b357751c04a89a87e6ef1f0cebe5f20957dd112d)", "geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)", + "plugins 0.0.1", "string_cache 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", + "string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache#b348bd00cc8991e1f25749be077c5bd9cec019bb)", "task_info 0.0.1", "url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)", ]