mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Port attribute name to use atom.
This commit is contained in:
parent
5808cb302d
commit
036bd29ead
2 changed files with 16 additions and 14 deletions
|
@ -12,6 +12,7 @@ use dom::element::{Element, AttributeHandlers};
|
|||
use dom::node::Node;
|
||||
use dom::window::Window;
|
||||
use dom::virtualmethods::vtable_for;
|
||||
use servo_util::atom::Atom;
|
||||
use servo_util::namespace;
|
||||
use servo_util::namespace::Namespace;
|
||||
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
||||
|
@ -62,7 +63,7 @@ pub struct Attr {
|
|||
reflector_: Reflector,
|
||||
pub local_name: DOMString,
|
||||
value: Traceable<RefCell<AttrValue>>,
|
||||
pub name: DOMString,
|
||||
pub name: Atom,
|
||||
pub namespace: Namespace,
|
||||
pub prefix: Option<DOMString>,
|
||||
|
||||
|
@ -78,13 +79,13 @@ impl Reflectable for Attr {
|
|||
|
||||
impl Attr {
|
||||
fn new_inherited(local_name: DOMString, value: AttrValue,
|
||||
name: DOMString, namespace: Namespace,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Attr {
|
||||
Attr {
|
||||
reflector_: Reflector::new(),
|
||||
local_name: local_name,
|
||||
value: Traceable::new(RefCell::new(value)),
|
||||
name: name, //TODO: Intern attribute names
|
||||
name: name,
|
||||
namespace: namespace,
|
||||
prefix: prefix,
|
||||
owner: Cell::new(JS::from_rooted(owner)),
|
||||
|
@ -92,7 +93,7 @@ impl Attr {
|
|||
}
|
||||
|
||||
pub fn new(window: &JSRef<Window>, local_name: DOMString, value: AttrValue,
|
||||
name: DOMString, namespace: Namespace,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Temporary<Attr> {
|
||||
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner);
|
||||
reflect_dom_object(box attr, &Window(*window), AttrBinding::Wrap)
|
||||
|
@ -150,7 +151,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> {
|
|||
}
|
||||
|
||||
fn Name(&self) -> DOMString {
|
||||
self.name.clone()
|
||||
self.name.as_slice().to_string()
|
||||
}
|
||||
|
||||
fn GetNamespaceURI(&self) -> Option<DOMString> {
|
||||
|
|
|
@ -31,10 +31,10 @@ use layout_interface::ContentChangedDocumentDamage;
|
|||
use layout_interface::MatchSelectorsDocumentDamage;
|
||||
use style::{matches_compound_selector, NamespaceMap, parse_selector_list};
|
||||
use style;
|
||||
use servo_util::atom::Atom;
|
||||
use servo_util::namespace;
|
||||
use servo_util::namespace::{Namespace, Null};
|
||||
use servo_util::str::{DOMString, null_str_as_empty_ref, split_html_space_chars};
|
||||
use servo_util::atom::Atom;
|
||||
|
||||
use std::ascii::StrAsciiExt;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
@ -228,7 +228,7 @@ pub trait AttributeHandlers {
|
|||
prefix: Option<DOMString>);
|
||||
fn set_attribute(&self, name: &str, value: AttrValue);
|
||||
fn do_set_attribute(&self, local_name: DOMString, value: AttrValue,
|
||||
name: DOMString, namespace: Namespace,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool);
|
||||
fn parse_attribute(&self, namespace: &Namespace, local_name: &str,
|
||||
value: DOMString) -> AttrValue;
|
||||
|
@ -267,8 +267,8 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
value: DOMString, namespace: Namespace,
|
||||
prefix: Option<DOMString>) {
|
||||
let name = match prefix {
|
||||
None => local_name.clone(),
|
||||
Some(ref prefix) => format!("{:s}:{:s}", *prefix, local_name),
|
||||
None => Atom::from_slice(local_name.as_slice()),
|
||||
Some(ref prefix) => Atom::from_slice(format!("{:s}:{:s}", *prefix, local_name).as_slice()),
|
||||
};
|
||||
let value = self.parse_attribute(&namespace, local_name.as_slice(), value);
|
||||
self.do_set_attribute(local_name, value, name, namespace, prefix, |_| false)
|
||||
|
@ -281,13 +281,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.wait_until_safe_to_modify_dom();
|
||||
|
||||
self.do_set_attribute(name.to_string(), value, name.to_string(),
|
||||
self.do_set_attribute(name.to_string(), value, Atom::from_slice(name),
|
||||
namespace::Null, None,
|
||||
|attr| attr.deref().local_name.as_slice() == name);
|
||||
}
|
||||
|
||||
fn do_set_attribute(&self, local_name: DOMString, value: AttrValue,
|
||||
name: DOMString, namespace: Namespace,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
|
||||
let idx = self.deref().attrs.borrow().iter()
|
||||
.map(|attr| attr.root())
|
||||
|
@ -576,8 +576,9 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// Step 3-5.
|
||||
let value = self.parse_attribute(&namespace::Null, name.as_slice(), value);
|
||||
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
|
||||
attr.deref().name == name
|
||||
let name_atom = Atom::from_slice(name.as_slice());
|
||||
self.do_set_attribute(name.clone(), value, name_atom.clone(), namespace::Null, None, |attr| {
|
||||
attr.deref().name == name_atom
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -638,7 +639,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// Step 9.
|
||||
let value = self.parse_attribute(&namespace, local_name.as_slice(), value);
|
||||
self.do_set_attribute(local_name.to_string(), value, name.to_string(),
|
||||
self.do_set_attribute(local_name.to_string(), value, Atom::from_slice(name.as_slice()),
|
||||
namespace.clone(), prefix.map(|s| s.to_string()),
|
||||
|attr| {
|
||||
attr.deref().local_name.as_slice() == local_name &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue