mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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)
|
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 {
|
pub fn local_name<'a>(&'a self) -> &'a Atom {
|
||||||
&self.local_name
|
&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 {
|
pub trait AttrHelpersForLayout {
|
||||||
unsafe fn value_ref_forever(&self) -> &'static str;
|
unsafe fn value_ref_forever(&self) -> &'static str;
|
||||||
unsafe fn value_atom_forever(&self) -> Option<Atom>;
|
unsafe fn value_atom_forever(&self) -> Option<Atom>;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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;
|
||||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
||||||
use dom::bindings::error::{Fallible, InvalidCharacter, Syntax};
|
use dom::bindings::error::{Fallible, InvalidCharacter, Syntax};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! Element nodes.
|
//! 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::attr::{AttrValue, StringAttrValue, UIntAttrValue, AtomAttrValue};
|
||||||
use dom::namednodemap::NamedNodeMap;
|
use dom::namednodemap::NamedNodeMap;
|
||||||
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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;
|
||||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::{ElementCast, TextCast, CommentCast, NodeCast};
|
||||||
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast};
|
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast};
|
||||||
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
|
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(attr.deref().name.as_slice());
|
||||||
};
|
};
|
||||||
html.push_str("=\"");
|
html.push_str("=\"");
|
||||||
escape(attr.deref().value().as_slice(), true, html);
|
escape(attr.value().as_slice(), true, html);
|
||||||
html.push_char('"');
|
html.push_char('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements.
|
//! 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::AttrBinding::AttrMethods;
|
||||||
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
|
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::AttrBinding::AttrMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast};
|
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue