mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Pass Atom to Attr:new for the prefix argument.
This commit is contained in:
parent
89a0c004d5
commit
e8b02acb1d
5 changed files with 13 additions and 15 deletions
|
@ -109,21 +109,21 @@ pub struct Attr {
|
|||
|
||||
impl Attr {
|
||||
fn new_inherited(local_name: Atom, value: AttrValue, name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, owner: Option<JSRef<Element>>) -> Attr {
|
||||
prefix: Option<Atom>, owner: Option<JSRef<Element>>) -> Attr {
|
||||
Attr {
|
||||
reflector_: Reflector::new(),
|
||||
local_name: local_name,
|
||||
value: DOMRefCell::new(value),
|
||||
name: name,
|
||||
namespace: namespace,
|
||||
prefix: prefix.map(|p| Atom::from_slice(&p)),
|
||||
prefix: prefix,
|
||||
owner: MutNullableHeap::new(owner.map(JS::from_rooted)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(window: JSRef<Window>, local_name: Atom, value: AttrValue,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, owner: Option<JSRef<Element>>) -> Temporary<Attr> {
|
||||
prefix: Option<Atom>, owner: Option<JSRef<Element>>) -> Temporary<Attr> {
|
||||
reflect_dom_object(
|
||||
box Attr::new_inherited(local_name, value, name, namespace, prefix, owner),
|
||||
GlobalRef::Window(window),
|
||||
|
|
|
@ -17,7 +17,6 @@ use util::str::DOMString;
|
|||
|
||||
use libc;
|
||||
use libc::c_uint;
|
||||
use std::borrow::ToOwned;
|
||||
use std::boxed;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::CString;
|
||||
|
@ -628,7 +627,7 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
|
|||
/// Validate a namespace and qualified name and extract their parts.
|
||||
/// See https://dom.spec.whatwg.org/#validate-and-extract for details.
|
||||
pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
|
||||
-> Fallible<(Namespace, Option<DOMString>, Atom)> {
|
||||
-> Fallible<(Namespace, Option<Atom>, Atom)> {
|
||||
// Step 1.
|
||||
let namespace = namespace::from_domstring(namespace);
|
||||
|
||||
|
@ -667,7 +666,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
|
|||
},
|
||||
(ns, p) => {
|
||||
// Step 10.
|
||||
Ok((ns, p.map(|s| s.to_owned()), Atom::from_slice(local_name)))
|
||||
Ok((ns, p.map(Atom::from_slice), Atom::from_slice(local_name)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1025,7 +1025,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
let (namespace, prefix, local_name) =
|
||||
try!(validate_and_extract(namespace, &qualified_name));
|
||||
let name = QualName::new(namespace, local_name);
|
||||
Ok(Element::create(name, prefix, self, ElementCreator::ScriptCreated))
|
||||
Ok(Element::create(name, prefix.map(|p| (*p).to_owned()), self, ElementCreator::ScriptCreated))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createattribute
|
||||
|
|
|
@ -670,12 +670,12 @@ pub trait AttributeHandlers {
|
|||
fn set_attribute_from_parser(self,
|
||||
name: QualName,
|
||||
value: DOMString,
|
||||
prefix: Option<DOMString>);
|
||||
prefix: Option<Atom>);
|
||||
fn set_attribute(self, name: &Atom, value: AttrValue);
|
||||
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
|
||||
fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: F)
|
||||
prefix: Option<Atom>, cb: F)
|
||||
where F: Fn(JSRef<Attr>) -> bool;
|
||||
fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
|
||||
value: DOMString) -> AttrValue;
|
||||
|
@ -743,7 +743,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
fn set_attribute_from_parser(self,
|
||||
qname: QualName,
|
||||
value: DOMString,
|
||||
prefix: Option<DOMString>) {
|
||||
prefix: Option<Atom>) {
|
||||
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing
|
||||
if self.attrs.borrow().iter().map(|attr| attr.root())
|
||||
.any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) {
|
||||
|
@ -753,7 +753,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
let name = match prefix {
|
||||
None => qname.local.clone(),
|
||||
Some(ref prefix) => {
|
||||
let name = format!("{}:{}", *prefix, &*qname.local);
|
||||
let name = format!("{}:{}", &**prefix, &*qname.local);
|
||||
Atom::from_slice(&name)
|
||||
},
|
||||
};
|
||||
|
@ -791,7 +791,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
value: AttrValue,
|
||||
name: Atom,
|
||||
namespace: Namespace,
|
||||
prefix: Option<DOMString>,
|
||||
prefix: Option<Atom>,
|
||||
cb: F)
|
||||
where F: Fn(JSRef<Attr>) -> bool
|
||||
{
|
||||
|
@ -1099,8 +1099,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
let qualified_name = Atom::from_slice(&qualified_name);
|
||||
let value = self.parse_attribute(&namespace, &local_name, value);
|
||||
self.do_set_attribute(local_name.clone(), value, qualified_name,
|
||||
namespace.clone(), prefix.map(|s| s.to_owned()),
|
||||
|attr| {
|
||||
namespace.clone(), prefix, |attr| {
|
||||
*attr.local_name() == local_name &&
|
||||
*attr.namespace() == namespace
|
||||
});
|
||||
|
|
|
@ -1778,7 +1778,7 @@ impl Node {
|
|||
&Attr::new(window.r(),
|
||||
attr.r().local_name().clone(), attr.r().value().clone(),
|
||||
attr.r().name().clone(), attr.r().namespace().clone(),
|
||||
attr.r().GetPrefix(), Some(copy_elem)));
|
||||
attr.r().prefix().clone(), Some(copy_elem)));
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue