aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2015-11-03 12:16:53 -0800
committerBobby Holley <bobbyholley@gmail.com>2015-11-09 21:40:22 -0800
commitc9704992a9f378a682835fe86def542b9086ea1c (patch)
treefa144c385130fe666305cf8eade54500dfee18f7 /components/script/dom/attr.rs
parent488c1291d483b0d5e0308f9499202577d3470482 (diff)
downloadservo-c9704992a9f378a682835fe86def542b9086ea1c.tar.gz
servo-c9704992a9f378a682835fe86def542b9086ea1c.zip
Factor the name-related fields of Attr into a struct and move it to style.
Diffstat (limited to 'components/script/dom/attr.rs')
-rw-r--r--components/script/dom/attr.rs43
1 files changed, 21 insertions, 22 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 8a16124b389..c5cd7c3d4ec 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -17,18 +17,15 @@ use std::borrow::ToOwned;
use std::cell::Ref;
use std::mem;
use string_cache::{Atom, Namespace};
-pub use style::attr::AttrValue;
+pub use style::attr::{AttrIdentifier, AttrValue};
use util::str::DOMString;
// https://dom.spec.whatwg.org/#interface-attr
#[dom_struct]
pub struct Attr {
reflector_: Reflector,
- local_name: Atom,
+ identifier: AttrIdentifier,
value: DOMRefCell<AttrValue>,
- name: Atom,
- namespace: Namespace,
- prefix: Option<Atom>,
/// the element that owns this attribute.
owner: MutNullableHeap<JS<Element>>,
@@ -39,11 +36,13 @@ impl Attr {
prefix: Option<Atom>, owner: Option<&Element>) -> Attr {
Attr {
reflector_: Reflector::new(),
- local_name: local_name,
+ identifier: AttrIdentifier {
+ local_name: local_name,
+ name: name,
+ namespace: namespace,
+ prefix: prefix,
+ },
value: DOMRefCell::new(value),
- name: name,
- namespace: namespace,
- prefix: prefix,
owner: MutNullableHeap::new(owner),
}
}
@@ -59,17 +58,17 @@ impl Attr {
#[inline]
pub fn name(&self) -> &Atom {
- &self.name
+ &self.identifier.name
}
#[inline]
pub fn namespace(&self) -> &Namespace {
- &self.namespace
+ &self.identifier.namespace
}
#[inline]
pub fn prefix(&self) -> &Option<Atom> {
- &self.prefix
+ &self.identifier.prefix
}
}
@@ -89,7 +88,7 @@ impl AttrMethods for Attr {
match self.owner() {
None => *self.value.borrow_mut() = AttrValue::String(value),
Some(owner) => {
- let value = owner.parse_attribute(&self.namespace, self.local_name(), value);
+ let value = owner.parse_attribute(&self.identifier.namespace, self.local_name(), value);
self.set_value(value, owner.r());
}
}
@@ -117,12 +116,12 @@ impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-name
fn Name(&self) -> DOMString {
- DOMString((*self.name).to_owned())
+ DOMString((*self.identifier.name).to_owned())
}
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
fn GetNamespaceURI(&self) -> Option<DOMString> {
- let Namespace(ref atom) = self.namespace;
+ let Namespace(ref atom) = self.identifier.namespace;
match &**atom {
"" => None,
url => Some(DOMString(url.to_owned())),
@@ -150,7 +149,7 @@ impl Attr {
pub fn set_value(&self, mut value: AttrValue, owner: &Element) {
assert!(Some(owner) == self.owner().r());
mem::swap(&mut *self.value.borrow_mut(), &mut value);
- if self.namespace == ns!("") {
+ if self.identifier.namespace == ns!("") {
vtable_for(owner.upcast()).attribute_mutated(
self, AttributeMutation::Set(Some(&value)));
}
@@ -161,21 +160,21 @@ impl Attr {
}
pub fn local_name(&self) -> &Atom {
- &self.local_name
+ &self.identifier.local_name
}
/// Sets the owner element. Should be called after the attribute is added
/// or removed from its older parent.
pub fn set_owner(&self, owner: Option<&Element>) {
- let ref ns = self.namespace;
+ let ref ns = self.identifier.namespace;
match (self.owner().r(), owner) {
(None, Some(new)) => {
// Already in the list of attributes of new owner.
- assert!(new.get_attribute(&ns, &self.local_name) == Some(Root::from_ref(self)))
+ assert!(new.get_attribute(&ns, &self.identifier.local_name) == Some(Root::from_ref(self)))
}
(Some(old), None) => {
// Already gone from the list of attributes of old owner.
- assert!(old.get_attribute(&ns, &self.local_name).is_none())
+ assert!(old.get_attribute(&ns, &self.identifier.local_name).is_none())
}
(old, new) => assert!(old == new)
}
@@ -187,7 +186,7 @@ impl Attr {
}
pub fn summarize(&self) -> AttrInfo {
- let Namespace(ref ns) = self.namespace;
+ let Namespace(ref ns) = self.identifier.namespace;
AttrInfo {
namespace: (**ns).to_owned(),
name: self.Name().0,
@@ -239,7 +238,7 @@ impl AttrHelpersForLayout for LayoutJS<Attr> {
#[inline]
unsafe fn local_name_atom_forever(&self) -> Atom {
- (*self.unsafe_get()).local_name.clone()
+ (*self.unsafe_get()).identifier.local_name.clone()
}
#[inline]