Skip to content

Commit

Permalink
auto merge of #3530 : kmcallister/servo/namespace-atom, r=Ms2ger
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Sep 30, 2014
2 parents eec2225 + d50114c commit 698b916
Show file tree
Hide file tree
Showing 46 changed files with 181 additions and 235 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions components/layout/Cargo.toml
Expand Up @@ -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"
3 changes: 1 addition & 2 deletions components/layout/construct.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 6 additions & 7 deletions components/layout/css/matching.rs
Expand Up @@ -11,10 +11,8 @@ use util::{LayoutDataAccess, LayoutDataWrapper};
use wrapper::{LayoutElement, LayoutNode, PostorderNodeMutTraversal, ThreadSafeLayoutNode, TLayoutNode};

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;
Expand All @@ -24,6 +22,7 @@ use style;
use style::{After, Before, ComputedValues, DeclarationBlock, Stylist, TElement, TNode};
use style::cascade;
use sync::Arc;
use string_cache::Atom;

pub struct ApplicableDeclarations {
pub normal: SmallVec16<DeclarationBlock>,
Expand Down Expand Up @@ -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()),
})
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions components/layout/fragment.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
})
Expand Down
3 changes: 3 additions & 0 deletions components/layout/lib.rs
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions components/layout/wrapper.rs
Expand Up @@ -48,9 +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::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;
Expand All @@ -59,6 +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, Namespace};

/// Allows some convenience methods on generic layout nodes.
pub trait TLayoutNode {
Expand Down Expand Up @@ -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,
}
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions components/script/Cargo.toml
Expand Up @@ -60,3 +60,9 @@ git = "https://github.com/servo/rust-url"

[dependencies.uuid]
git = "https://github.com/rust-lang/uuid"

[dependencies.string_cache]
git = "https://github.com/servo/string-cache"

[dependencies.string_cache_macros]
git = "https://github.com/servo/string-cache"
12 changes: 6 additions & 6 deletions components/script/dom/attr.rs
Expand Up @@ -15,13 +15,11 @@ use dom::window::Window;
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;
use std::slice::Items;
use string_cache::{Atom, Namespace};

pub enum AttrSettingType {
FirstSetAttr,
Expand Down Expand Up @@ -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()),
}
Expand All @@ -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 => {
Expand Down Expand Up @@ -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(),
}
Expand Down
3 changes: 1 addition & 2 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -35,14 +35,13 @@ use std::rc::Rc;
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;
use std::collections::hashmap::HashMap;
use collections::hash::Hash;
use style::PropertyDeclarationBlock;
use string_cache::{Atom, Namespace};

impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
Expand Down
21 changes: 10 additions & 11 deletions components/script/dom/document.rs
Expand Up @@ -55,10 +55,9 @@ 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 string_cache::Atom;

use std::collections::hashmap::HashMap;
use std::ascii::StrAsciiExt;
Expand Down Expand Up @@ -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");
Expand All @@ -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,
Expand Down Expand Up @@ -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()
})
})
Expand Down
5 changes: 2 additions & 3 deletions components/script/dom/domtokenlist.rs
Expand Up @@ -12,9 +12,8 @@ use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
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};
use string_cache::Atom;

#[jstraceable]
#[must_root]
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 698b916

Please sign in to comment.