aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/layout/wrapper.rs14
-rw-r--r--components/script/dom/element.rs47
-rw-r--r--components/script/dom/htmlcollection.rs10
-rw-r--r--components/script/dom/htmlfieldsetelement.rs2
-rw-r--r--components/script/dom/htmloptionelement.rs2
-rw-r--r--components/script/dom/htmlserializer.rs14
-rw-r--r--components/script/dom/namednodemap.rs4
-rw-r--r--components/script/dom/node.rs20
8 files changed, 72 insertions, 41 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs
index 2aac0411c4a..e7ace898d01 100644
--- a/components/layout/wrapper.rs
+++ b/components/layout/wrapper.rs
@@ -425,7 +425,7 @@ pub struct LayoutElement<'le> {
impl<'le> LayoutElement<'le> {
pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> {
let style: &Option<PropertyDeclarationBlock> = unsafe {
- let style: &RefCell<Option<PropertyDeclarationBlock>> = &self.element.style_attribute;
+ let style: &RefCell<Option<PropertyDeclarationBlock>> = self.element.style_attribute();
// cast to the direct reference to T placed on the head of RefCell<T>
mem::transmute(style)
};
@@ -436,12 +436,12 @@ impl<'le> LayoutElement<'le> {
impl<'le> TElement<'le> for LayoutElement<'le> {
#[inline]
fn get_local_name(self) -> &'le Atom {
- &self.element.local_name
+ self.element.local_name()
}
#[inline]
fn get_namespace(self) -> &'le Namespace {
- &self.element.namespace
+ self.element.namespace()
}
#[inline]
@@ -456,7 +456,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
fn get_link(self) -> Option<&'le str> {
// FIXME: This is HTML only.
- match self.element.node.type_id_for_layout() {
+ match self.element.node().type_id_for_layout() {
// http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html#
// selector-link
ElementNodeTypeId(HTMLAnchorElementTypeId) |
@@ -470,7 +470,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
fn get_hover_state(self) -> bool {
unsafe {
- self.element.node.get_hover_state_for_layout()
+ self.element.node().get_hover_state_for_layout()
}
}
@@ -481,13 +481,13 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
fn get_disabled_state(self) -> bool {
unsafe {
- self.element.node.get_disabled_state_for_layout()
+ self.element.node().get_disabled_state_for_layout()
}
}
fn get_enabled_state(self) -> bool {
unsafe {
- self.element.node.get_enabled_state_for_layout()
+ self.element.node().get_enabled_state_for_layout()
}
}
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 8a929bd913a..6ff62874731 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -35,7 +35,7 @@ use servo_util::namespace;
use servo_util::str::DOMString;
use std::ascii::StrAsciiExt;
-use std::cell::RefCell;
+use std::cell::{Ref, RefMut, RefCell};
use std::default::Default;
use std::mem;
use std::slice::Items;
@@ -44,14 +44,15 @@ use url::UrlParser;
#[jstraceable]
#[must_root]
+#[privatize]
pub struct Element {
- pub node: Node,
- pub local_name: Atom,
- pub namespace: Namespace,
- pub prefix: Option<DOMString>,
- pub attrs: RefCell<Vec<JS<Attr>>>,
- pub style_attribute: RefCell<Option<style::PropertyDeclarationBlock>>,
- pub attr_list: MutNullableJS<NamedNodeMap>,
+ node: Node,
+ local_name: Atom,
+ namespace: Namespace,
+ prefix: Option<DOMString>,
+ attrs: RefCell<Vec<JS<Attr>>>,
+ style_attribute: RefCell<Option<style::PropertyDeclarationBlock>>,
+ attr_list: MutNullableJS<NamedNodeMap>,
class_list: MutNullableJS<DOMTokenList>,
}
@@ -171,6 +172,36 @@ impl Element {
pub fn node<'a>(&'a self) -> &'a Node {
&self.node
}
+
+ #[inline]
+ pub fn local_name<'a>(&'a self) -> &'a Atom {
+ &self.local_name
+ }
+
+ #[inline]
+ pub fn namespace<'a>(&'a self) -> &'a Namespace {
+ &self.namespace
+ }
+
+ #[inline]
+ pub fn prefix<'a>(&'a self) -> &'a Option<DOMString> {
+ &self.prefix
+ }
+
+ #[inline]
+ pub fn attrs(&self) -> Ref<Vec<JS<Attr>>> {
+ self.attrs.borrow()
+ }
+
+ #[inline]
+ pub fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>> {
+ self.attrs.borrow_mut()
+ }
+
+ #[inline]
+ pub fn style_attribute<'a>(&'a self) -> &'a RefCell<Option<style::PropertyDeclarationBlock>> {
+ &self.style_attribute
+ }
}
pub trait RawLayoutElementHelpers {
diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs
index 9e20f4a6572..035ee8287a4 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -67,7 +67,7 @@ impl HTMLCollection {
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
match self.namespace_filter {
None => true,
- Some(ref namespace) => elem.namespace == *namespace
+ Some(ref namespace) => *elem.namespace() == *namespace
}
}
}
@@ -89,9 +89,9 @@ impl HTMLCollection {
impl CollectionFilter for TagNameFilter {
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
if elem.html_element_in_html_document() {
- elem.local_name == self.ascii_lower_tag
+ *elem.local_name() == self.ascii_lower_tag
} else {
- elem.local_name == self.tag
+ *elem.local_name() == self.tag
}
}
}
@@ -121,11 +121,11 @@ impl HTMLCollection {
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
let ns_match = match self.namespace_filter {
Some(ref namespace) => {
- elem.namespace == *namespace
+ *elem.namespace() == *namespace
},
None => true
};
- ns_match && elem.local_name == self.tag
+ ns_match && *elem.local_name() == self.tag
}
}
let filter = TagNameNSFilter {
diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs
index 6f0d2695897..4ec69852e95 100644
--- a/components/script/dom/htmlfieldsetelement.rs
+++ b/components/script/dom/htmlfieldsetelement.rs
@@ -58,7 +58,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
static tag_names: StaticStringVec = &["button", "fieldset", "input",
"keygen", "object", "output", "select", "textarea"];
let root: JSRef<Element> = ElementCast::to_ref(root).unwrap();
- elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.local_name.as_slice())
+ elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.local_name().as_slice())
}
}
let node: JSRef<Node> = NodeCast::from_ref(self);
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index 715f0d6f1f5..e44011bc2ce 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -51,7 +51,7 @@ impl HTMLOptionElement {
fn collect_text(node: &JSRef<Node>, value: &mut DOMString) {
let elem: JSRef<Element> = ElementCast::to_ref(*node).unwrap();
- let svg_script = elem.namespace == ns!(SVG) && elem.local_name.as_slice() == "script";
+ let svg_script = *elem.namespace() == ns!(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/htmlserializer.rs b/components/script/dom/htmlserializer.rs
index 9e84900a9c0..e9de8987ac0 100644
--- a/components/script/dom/htmlserializer.rs
+++ b/components/script/dom/htmlserializer.rs
@@ -78,10 +78,10 @@ fn serialize_text(text: JSRef<Text>, html: &mut String) {
match text_node.parent_node().map(|node| node.root()) {
Some(ref parent) if parent.is_element() => {
let elem: JSRef<Element> = ElementCast::to_ref(**parent).unwrap();
- match elem.local_name.as_slice() {
+ match elem.local_name().as_slice() {
"style" | "script" | "xmp" | "iframe" |
"noembed" | "noframes" | "plaintext" |
- "noscript" if elem.namespace == ns!(HTML)
+ "noscript" if *elem.namespace() == ns!(HTML)
=> html.push_str(text.characterdata().data().as_slice()),
_ => escape(text.characterdata().data().as_slice(), false, html)
}
@@ -107,15 +107,15 @@ fn serialize_doctype(doctype: JSRef<DocumentType>, html: &mut String) {
fn serialize_elem(elem: JSRef<Element>, open_elements: &mut Vec<String>, html: &mut String) {
html.push_char('<');
- html.push_str(elem.local_name.as_slice());
- for attr in elem.attrs.borrow().iter() {
+ html.push_str(elem.local_name().as_slice());
+ for attr in elem.attrs().iter() {
let attr = attr.root();
serialize_attr(*attr, html);
};
html.push_char('>');
- match elem.local_name.as_slice() {
- "pre" | "listing" | "textarea" if elem.namespace == ns!(HTML) => {
+ match elem.local_name().as_slice() {
+ "pre" | "listing" | "textarea" if *elem.namespace() == ns!(HTML) => {
let node: JSRef<Node> = NodeCast::from_ref(elem);
match node.first_child().map(|child| child.root()) {
Some(ref child) if child.is_text() => {
@@ -131,7 +131,7 @@ fn serialize_elem(elem: JSRef<Element>, open_elements: &mut Vec<String>, html: &
}
if !(elem.is_void()) {
- open_elements.push(elem.local_name.as_slice().to_string());
+ open_elements.push(elem.local_name().as_slice().to_string());
}
}
diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs
index c190a39a37f..c0304510c68 100644
--- a/components/script/dom/namednodemap.rs
+++ b/components/script/dom/namednodemap.rs
@@ -35,11 +35,11 @@ impl NamedNodeMap {
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
fn Length(self) -> u32 {
- self.owner.root().attrs.borrow().len() as u32
+ self.owner.root().attrs().len() as u32
}
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
- self.owner.root().attrs.borrow().as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
+ self.owner.root().attrs().as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
}
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 81946a2738e..2716c56dc5c 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1501,8 +1501,8 @@ impl Node {
},
ElementNodeTypeId(..) => {
let element: JSRef<Element> = ElementCast::to_ref(node).unwrap();
- let element = build_element_from_tag(element.local_name.as_slice().to_string(),
- element.namespace.clone(), Some(element.prefix.as_slice().to_string()), *document);
+ let element = build_element_from_tag(element.local_name().as_slice().to_string(),
+ element.namespace().clone(), Some(element.prefix().as_slice().to_string()), *document);
NodeCast::from_temporary(element)
},
TextNodeTypeId => {
@@ -1541,8 +1541,8 @@ impl Node {
// FIXME: https://github.com/mozilla/servo/issues/1737
let window = document.window().root();
- for attr in node_elem.attrs.borrow().iter().map(|attr| attr.root()) {
- copy_elem.attrs.borrow_mut().push_unrooted(
+ for attr in node_elem.attrs().iter().map(|attr| attr.root()) {
+ copy_elem.attrs_mut().push_unrooted(
&Attr::new(*window,
attr.local_name().clone(), attr.value().clone(),
attr.name().clone(), attr.namespace().clone(),
@@ -1983,9 +1983,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let element: JSRef<Element> = ElementCast::to_ref(node).unwrap();
let other_element: JSRef<Element> = ElementCast::to_ref(other).unwrap();
// FIXME: namespace prefix
- (element.namespace == other_element.namespace) &&
- (element.local_name == other_element.local_name) &&
- (element.attrs.borrow().len() == other_element.attrs.borrow().len())
+ (*element.namespace() == *other_element.namespace()) &&
+ (*element.local_name() == *other_element.local_name()) &&
+ (element.attrs().len() == other_element.attrs().len())
}
fn is_equal_processinginstruction(node: JSRef<Node>, other: JSRef<Node>) -> bool {
let pi: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
@@ -2001,9 +2001,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
fn is_equal_element_attrs(node: JSRef<Node>, other: JSRef<Node>) -> bool {
let element: JSRef<Element> = ElementCast::to_ref(node).unwrap();
let other_element: JSRef<Element> = ElementCast::to_ref(other).unwrap();
- assert!(element.attrs.borrow().len() == other_element.attrs.borrow().len());
- element.attrs.borrow().iter().map(|attr| attr.root()).all(|attr| {
- other_element.attrs.borrow().iter().map(|attr| attr.root()).any(|other_attr| {
+ assert!(element.attrs().len() == other_element.attrs().len());
+ element.attrs().iter().map(|attr| attr.root()).all(|attr| {
+ other_element.attrs().iter().map(|attr| attr.root()).any(|other_attr| {
(*attr.namespace() == *other_attr.namespace()) &&
(attr.local_name() == other_attr.local_name()) &&
(attr.value().as_slice() == other_attr.value().as_slice())