diff options
-rw-r--r-- | components/script/dom/attr.rs | 79 | ||||
-rw-r--r-- | components/script/dom/document.rs | 1 | ||||
-rw-r--r-- | components/script/dom/domtokenlist.rs | 2 | ||||
-rw-r--r-- | components/script/dom/element.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 1 | ||||
-rw-r--r-- | components/script/dom/htmlserializer.rs | 4 | ||||
-rw-r--r-- | components/script/dom/node.rs | 2 | ||||
-rw-r--r-- | components/script/html/hubbub_html_parser.rs | 1 | ||||
-rw-r--r-- | components/script/page.rs | 1 |
9 files changed, 57 insertions, 40 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 9f3fc9dc96e..02945088bbb 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -110,39 +110,6 @@ impl Attr { let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); 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 - } } impl<'a> AttrMethods for JSRef<'a, Attr> { @@ -177,9 +144,51 @@ 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>; + fn local_name<'a>(&'a self) -> &'a Atom; +} + +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() + } + + fn local_name<'a>(&'a self) -> &'a Atom { + &self.local_name + } +} + pub trait AttrHelpersForLayout { unsafe fn value_ref_forever(&self) -> &'static str; unsafe fn value_atom_forever(&self) -> Option<Atom>; + unsafe fn local_name_atom_forever(&self) -> Atom; } impl AttrHelpersForLayout for Attr { @@ -197,4 +206,8 @@ impl AttrHelpersForLayout for Attr { _ => None, } } + + unsafe fn local_name_atom_forever(&self) -> Atom { + self.local_name.clone() + } } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 503f618384d..f8f83183dc2 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 11f7eaf59d0..7c1b1fc3365 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::Attr; +use dom::attr::{Attr, AttrHelpers}; use dom::bindings::codegen::Bindings::DOMTokenListBinding; use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods; use dom::bindings::error::{Fallible, InvalidCharacter, Syntax}; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 1fe2c9f80bd..a4df58eb06e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -4,7 +4,7 @@ //! Element nodes. -use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrHelpersForLayout}; +use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrHelpers, AttrHelpersForLayout}; use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue, AtomAttrValue}; use dom::namednodemap::NamedNodeMap; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; @@ -178,7 +178,7 @@ impl RawLayoutElementHelpers for Element { let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); (*attrs).iter().find(|attr: & &JS<Attr>| { let attr = attr.unsafe_get(); - name == (*attr).local_name().as_slice() && + name == (*attr).local_name_atom_forever().as_slice() && (*attr).namespace == *namespace }).map(|attr| { let attr = attr.unsafe_get(); @@ -193,7 +193,7 @@ impl RawLayoutElementHelpers for Element { let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); (*attrs).iter().find(|attr: & &JS<Attr>| { let attr = attr.unsafe_get(); - name == (*attr).local_name().as_slice() && + name == (*attr).local_name_atom_forever().as_slice() && (*attr).namespace == *namespace }).and_then(|attr| { let attr = attr.unsafe_get(); diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index b2d2c05f728..6422e5a8f10 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast}; diff --git a/components/script/dom/htmlserializer.rs b/components/script/dom/htmlserializer.rs index cb9e1769255..624ede52bb7 100644 --- a/components/script/dom/htmlserializer.rs +++ b/components/script/dom/htmlserializer.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::Attr; +use dom::attr::{Attr, AttrHelpers}; use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast}; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; @@ -153,7 +153,7 @@ fn serialize_attr(attr: &JSRef<Attr>, html: &mut String) { html.push_str(attr.deref().name.as_slice()); }; html.push_str("=\""); - escape(attr.deref().value().as_slice(), true, html); + escape(attr.value().as_slice(), true, html); html.push_char('"'); } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 96ee5f62ba2..f419798a110 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -4,7 +4,7 @@ //! The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. -use dom::attr::Attr; +use dom::attr::{Attr, AttrHelpers}; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; diff --git a/components/script/html/hubbub_html_parser.rs b/components/script/html/hubbub_html_parser.rs index 8b49a2bae03..6862ef4a492 100644 --- a/components/script/html/hubbub_html_parser.rs +++ b/components/script/html/hubbub_html_parser.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast}; diff --git a/components/script/page.rs b/components/script/page.rs index 633a7de204b..1955d9c8c2d 100644 --- a/components/script/page.rs +++ b/components/script/page.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast}; use dom::bindings::js::{JS, JSRef, Temporary}; |