aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorTetsuharu OHZEKI <saneyuki.snyk@gmail.com>2014-09-10 14:07:55 +0900
committerTetsuharu OHZEKI <saneyuki.snyk@gmail.com>2014-09-11 04:54:38 +0900
commitb73b06b9a82f6a02fdc4859776af1c9929d95641 (patch)
tree39b6fee8400b319ea89ee9044d59b146f4adaf34 /components/script/dom/attr.rs
parent842823e321fdadcff0ef4e7c077873b1d83a5289 (diff)
downloadservo-b73b06b9a82f6a02fdc4859776af1c9929d95641.tar.gz
servo-b73b06b9a82f6a02fdc4859776af1c9929d95641.zip
Move Attr helper methods to AttrHelpers trait to avoid to touch them from layout task.
Diffstat (limited to 'components/script/dom/attr.rs')
-rw-r--r--components/script/dom/attr.rs65
1 files changed, 36 insertions, 29 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 9f3fc9dc96e..7482e200d68 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -111,35 +111,6 @@ impl Attr {
reflect_dom_object(box attr, &Window(*window), AttrBinding::Wrap)
}
- pub 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;
-
- match set_type {
- ReplacedAttr => {
- if namespace_is_null {
- vtable_for(node).before_remove_attr(
- self.local_name(),
- self.value().as_slice().to_string())
- }
- }
- FirstSetAttr => {}
- }
-
- *self.value.deref().borrow_mut() = value;
-
- if namespace_is_null {
- vtable_for(node).after_set_attr(
- self.local_name(),
- self.value().as_slice().to_string())
- }
- }
-
- pub fn value<'a>(&'a self) -> Ref<'a, AttrValue> {
- self.value.deref().borrow()
- }
-
pub fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}
@@ -177,6 +148,42 @@ impl<'a> AttrMethods for JSRef<'a, Attr> {
}
}
+pub trait AttrHelpers {
+ fn set_value(&self, set_type: AttrSettingType, value: AttrValue);
+ fn value<'a>(&'a self) -> Ref<'a, AttrValue>;
+}
+
+impl<'a> AttrHelpers 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;
+
+ match set_type {
+ ReplacedAttr => {
+ if namespace_is_null {
+ vtable_for(node).before_remove_attr(
+ self.local_name(),
+ self.value().as_slice().to_string())
+ }
+ }
+ FirstSetAttr => {}
+ }
+
+ *self.value.deref().borrow_mut() = value;
+
+ if namespace_is_null {
+ vtable_for(node).after_set_attr(
+ self.local_name(),
+ self.value().as_slice().to_string())
+ }
+ }
+
+ fn value<'a>(&'a self) -> Ref<'a, AttrValue> {
+ self.value.deref().borrow()
+ }
+}
+
pub trait AttrHelpersForLayout {
unsafe fn value_ref_forever(&self) -> &'static str;
unsafe fn value_atom_forever(&self) -> Option<Atom>;