mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move Attr helper methods to AttrHelpers trait to avoid to touch them from layout task.
This commit is contained in:
parent
842823e321
commit
b73b06b9a8
9 changed files with 45 additions and 34 deletions
|
@ -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>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue