Skip to content
Permalink
Browse files

Use string-cache's Namespace type

  • Loading branch information
kmcallister committed Sep 30, 2014
1 parent 6429750 commit d50114c41d5233bc55ad1b86273995c0fa3f8d62

Some generated files are not rendered by default. Learn more.

@@ -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(&ns!(""), "type"), elem.get_attr(&ns!(""), "data"))
}

fn has_object_data(&self) -> bool {
@@ -13,7 +13,6 @@ use wrapper::{LayoutElement, LayoutNode, PostorderNodeMutTraversal, ThreadSafeLa
use script::dom::node::{TextNodeTypeId};
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(&ns!(""), "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(&ns!(""), "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(&ns!(""), "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(&ns!(""), "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(&ns!(""), "class")
.map(|attr| {
for c in attr.split(style::SELECTOR_WHITESPACE) {
bf.remove(&c);
@@ -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<Au> {
let element = node.as_element();
element.get_attr(&namespace::Null, name).and_then(|string| {
element.get_attr(&ns!(""), name).and_then(|string| {
let n: Option<int> = 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(&ns!(""), "span").and_then(|string| {
let n: Option<int> = FromStr::from_str(string);
n
})
@@ -48,8 +48,6 @@ use script::dom::node::{LayoutNodeHelpers, RawLayoutNodeHelpers, SharedLayoutDat
use script::dom::text::Text;
use script::layout_interface::LayoutChan;
use servo_msg::constellation_msg::{PipelineId, SubpageId};
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;
@@ -58,7 +56,7 @@ use style::computed_values::{content, display, white_space};
use style::{AnyNamespace, AttrSelector, PropertyDeclarationBlock, SpecificNamespace, TElement};
use style::{TNode};
use url::Url;
use string_cache::Atom;
use string_cache::{Atom, Namespace};

/// Allows some convenience methods on generic layout nodes.
pub trait TLayoutNode {
@@ -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(&ns!(""), "href") }
}
_ => None,
}
@@ -427,7 +425,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {

#[inline]
fn get_id(&self) -> Option<Atom> {
unsafe { self.element.get_attr_atom_for_layout(&namespace::Null, "id") }
unsafe { self.element.get_attr_atom_for_layout(&ns!(""), "id") }
}

fn get_disabled_state(&self) -> bool {
@@ -15,13 +15,11 @@ use dom::window::Window;
use dom::virtualmethods::vtable_for;

use devtools_traits::AttrInfo;
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;
use std::slice::Items;
use string_cache::Atom;
use string_cache::{Atom, Namespace};

pub enum AttrSettingType {
FirstSetAttr,
@@ -136,7 +134,8 @@ impl<'a> AttrMethods for JSRef<'a, Attr> {
}

fn GetNamespaceURI(self) -> Option<DOMString> {
match self.namespace.to_str() {
let Namespace(ref atom) = self.namespace;
match atom.as_slice() {
"" => None,
url => Some(url.to_string()),
}
@@ -158,7 +157,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<Node> = NodeCast::from_ref(*owner);
let namespace_is_null = self.namespace == namespace::Null;
let namespace_is_null = self.namespace == ns!("");

match set_type {
ReplacedAttr => {
@@ -189,8 +188,9 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
}

fn summarize(self) -> AttrInfo {
let Namespace(ref ns) = self.namespace;
AttrInfo {
namespace: self.namespace.to_str().to_string(),
namespace: ns.as_slice().to_string(),
name: self.Name(),
value: self.Value(),
}
@@ -35,14 +35,13 @@ use std::rc::Rc;
use std::cell::{Cell, RefCell};

use url::Url;
use servo_util::namespace::Namespace;
use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData};
use net::image_cache_task::ImageCacheTask;
use script_traits::ScriptControlChan;
use std::collections::hashmap::HashMap;
use collections::hash::Hash;
use style::PropertyDeclarationBlock;
use string_cache::Atom;
use string_cache::{Atom, Namespace};

impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
@@ -56,7 +56,6 @@ use html::hubbub_html_parser::build_element_from_tag;
use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks};
use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage};
use servo_util::namespace;
use servo_util::namespace::{Namespace, Null};
use servo_util::str::{DOMString, split_html_space_chars};
use string_cache::Atom;

@@ -466,14 +465,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, ns!(HTML), self))
}

// http://dom.spec.whatwg.org/#dom-document-createelementns
fn CreateElementNS(self,
namespace: Option<DOMString>,
qualified_name: DOMString) -> Fallible<Temporary<Element>> {
let ns = Namespace::from_str(namespace);
let ns = namespace::from_domstring(namespace);
match xml_name_type(qualified_name.as_slice()) {
InvalidXMLName => {
debug!("Not a valid element name");
@@ -490,26 +489,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(_), _) => {
(&ns!(""), 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 != ns!(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, _, _) => {
(&ns!(XMLNS), Some(ref prefix), _) if "xmlns" == prefix.as_slice() => {},
(&ns!(XMLNS), _, "xmlns") => {},
(&ns!(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 == ns!(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,
@@ -755,7 +754,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}

let element: JSRef<Element> = ElementCast::to_ref(node).unwrap();
element.get_attribute(Null, "name").root().map_or(false, |attr| {
element.get_attribute(ns!(""), "name").root().map_or(false, |attr| {
attr.value().as_slice() == name.as_slice()
})
})
@@ -12,7 +12,6 @@ use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::element::{Element, AttributeHandlers};
use dom::node::window_from_node;

use servo_util::namespace::Null;
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
use string_cache::Atom;

@@ -56,7 +55,7 @@ trait PrivateDOMTokenListHelpers {
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
fn attribute(self) -> Option<Temporary<Attr>> {
let element = self.element.root();
element.deref().get_attribute(Null, self.local_name)
element.deref().get_attribute(ns!(""), self.local_name)
}

fn check_token_exceptions<'a>(self, token: &'a str) -> Fallible<&'a str> {

5 comments on commit d50114c

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Sep 30, 2014

saw approval from Ms2ger
at kmcallister@d50114c

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Sep 30, 2014

merging kmcallister/servo/namespace-atom = d50114c into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Sep 30, 2014

kmcallister/servo/namespace-atom = d50114c merged ok, testing candidate = 698b916

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Sep 30, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Sep 30, 2014

fast-forwarding master to auto = 698b916

Please sign in to comment.
You can’t perform that action at this time.