mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #5503 - nox:cleanup-attributes, r=Manishearth
This makes all tests in attributes.html pass.
This commit is contained in:
commit
8d1a6c45f6
18 changed files with 138 additions and 156 deletions
|
@ -250,15 +250,15 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
|
|||
/// Sets the owner element. Should be called after the attribute is added
|
||||
/// or removed from its older parent.
|
||||
fn set_owner(self, owner: Option<JSRef<Element>>) {
|
||||
let ns = self.namespace.clone();
|
||||
let ref ns = self.namespace;
|
||||
match (self.owner().root().r(), owner) {
|
||||
(None, Some(new)) => {
|
||||
// Already in the list of attributes of new owner.
|
||||
assert!(new.get_attribute(ns, &self.local_name).root().r() == Some(self))
|
||||
assert!(new.get_attribute(&ns, &self.local_name).root().r() == Some(self))
|
||||
}
|
||||
(Some(old), None) => {
|
||||
// Already gone from the list of attributes of old owner.
|
||||
assert!(old.get_attribute(ns, &self.local_name).is_none())
|
||||
assert!(old.get_attribute(&ns, &self.local_name).is_none())
|
||||
}
|
||||
(old, new) => assert!(old == new)
|
||||
}
|
||||
|
|
|
@ -653,7 +653,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
let mut iter = name.chars();
|
||||
let mut non_qname_colons = false;
|
||||
let mut seen_colon = false;
|
||||
match iter.next() {
|
||||
let mut last = match iter.next() {
|
||||
None => return XMLName::InvalidXMLName,
|
||||
Some(c) => {
|
||||
if !is_valid_start(c) {
|
||||
|
@ -662,10 +662,11 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
if c == ':' {
|
||||
non_qname_colons = true;
|
||||
}
|
||||
c
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for c in name.chars() {
|
||||
for c in iter {
|
||||
if !is_valid_continuation(c) {
|
||||
return XMLName::InvalidXMLName;
|
||||
}
|
||||
|
@ -675,6 +676,11 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
false => seen_colon = true
|
||||
}
|
||||
}
|
||||
last = c
|
||||
}
|
||||
|
||||
if last == ':' {
|
||||
non_qname_colons = true
|
||||
}
|
||||
|
||||
match non_qname_colons {
|
||||
|
|
|
@ -369,7 +369,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
|||
self.GetElementById(fragid.clone()).or_else(|| {
|
||||
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
|
||||
let elem: JSRef<Element> = ElementCast::from_ref(node);
|
||||
elem.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| {
|
||||
elem.get_attribute(&ns!(""), &atom!("name")).root().map_or(false, |attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
@ -1280,7 +1280,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
Some(element) => element,
|
||||
None => return false,
|
||||
};
|
||||
element.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| {
|
||||
element.get_attribute(&ns!(""), &atom!("name")).root().map_or(false, |attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
|
|
@ -50,7 +50,7 @@ trait PrivateDOMTokenListHelpers {
|
|||
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
||||
fn attribute(self) -> Option<Temporary<Attr>> {
|
||||
let element = self.element.root();
|
||||
element.r().get_attribute(ns!(""), &self.local_name)
|
||||
element.r().get_attribute(&ns!(""), &self.local_name)
|
||||
}
|
||||
|
||||
fn check_token_exceptions(self, token: &str) -> Fallible<Atom> {
|
||||
|
|
|
@ -608,8 +608,11 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
|||
pub trait AttributeHandlers {
|
||||
/// Returns the attribute with given namespace and case-sensitive local
|
||||
/// name, if any.
|
||||
fn get_attribute(self, namespace: Namespace, local_name: &Atom)
|
||||
fn get_attribute(self, namespace: &Namespace, local_name: &Atom)
|
||||
-> Option<Temporary<Attr>>;
|
||||
/// Returns the first attribute with any namespace and given case-sensitive
|
||||
/// name, if any.
|
||||
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>>;
|
||||
fn get_attributes(self, local_name: &Atom)
|
||||
-> Vec<Temporary<Attr>>;
|
||||
fn set_attribute_from_parser(self,
|
||||
|
@ -625,32 +628,48 @@ pub trait AttributeHandlers {
|
|||
fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
|
||||
value: DOMString) -> AttrValue;
|
||||
|
||||
fn remove_attribute(self, namespace: Namespace, name: &str);
|
||||
/// Removes the first attribute with any given namespace and case-sensitive local
|
||||
/// name, if any.
|
||||
fn remove_attribute(self, namespace: &Namespace, local_name: &Atom);
|
||||
/// Removes the first attribute with any namespace and given case-sensitive name.
|
||||
fn remove_attribute_by_name(self, name: &Atom);
|
||||
/// Removes the first attribute that satisfies `find`.
|
||||
fn do_remove_attribute<F>(self, find: F) where F: Fn(JSRef<Attr>) -> bool;
|
||||
|
||||
fn has_class(self, name: &Atom) -> bool;
|
||||
|
||||
fn set_atomic_attribute(self, name: &Atom, value: DOMString);
|
||||
fn set_atomic_attribute(self, local_name: &Atom, value: DOMString);
|
||||
|
||||
// http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
|
||||
fn has_attribute(self, name: &Atom) -> bool;
|
||||
fn set_bool_attribute(self, name: &Atom, value: bool);
|
||||
fn get_url_attribute(self, name: &Atom) -> DOMString;
|
||||
fn set_url_attribute(self, name: &Atom, value: DOMString);
|
||||
fn get_string_attribute(self, name: &Atom) -> DOMString;
|
||||
fn set_string_attribute(self, name: &Atom, value: DOMString);
|
||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom>;
|
||||
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString);
|
||||
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>);
|
||||
fn get_uint_attribute(self, name: &Atom) -> u32;
|
||||
fn set_uint_attribute(self, name: &Atom, value: u32);
|
||||
fn has_attribute(self, local_name: &Atom) -> bool;
|
||||
fn set_bool_attribute(self, local_name: &Atom, value: bool);
|
||||
fn get_url_attribute(self, local_name: &Atom) -> DOMString;
|
||||
fn set_url_attribute(self, local_name: &Atom, value: DOMString);
|
||||
fn get_string_attribute(self, local_name: &Atom) -> DOMString;
|
||||
fn set_string_attribute(self, local_name: &Atom, value: DOMString);
|
||||
fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom>;
|
||||
fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString);
|
||||
fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>);
|
||||
fn get_uint_attribute(self, local_name: &Atom) -> u32;
|
||||
fn set_uint_attribute(self, local_name: &Atom, value: u32);
|
||||
}
|
||||
|
||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||
fn get_attribute(self, namespace: Namespace, local_name: &Atom) -> Option<Temporary<Attr>> {
|
||||
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>> {
|
||||
self.get_attributes(local_name).into_iter().map(|attr| attr.root())
|
||||
.find(|attr| *attr.r().namespace() == namespace)
|
||||
.find(|attr| attr.r().namespace() == namespace)
|
||||
.map(|x| Temporary::from_rooted(x.r()))
|
||||
}
|
||||
|
||||
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attrs = self.attrs.borrow();
|
||||
attrs.iter().map(|attr| attr.root())
|
||||
.find(|a| a.r().name() == name)
|
||||
.map(|x| Temporary::from_rooted(x.r()))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attrs = self.attrs.borrow();
|
||||
|
@ -748,17 +767,24 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_attribute(self, namespace: Namespace, name: &str) {
|
||||
let (_, local_name) = get_attribute_parts(name);
|
||||
let local_name = Atom::from_slice(local_name);
|
||||
|
||||
let idx = self.attrs.borrow().iter().map(|attr| attr.root()).position(|attr| {
|
||||
*attr.r().local_name() == local_name
|
||||
fn remove_attribute(self, namespace: &Namespace, local_name: &Atom) {
|
||||
self.do_remove_attribute(|attr| {
|
||||
attr.namespace() == namespace && attr.local_name() == local_name
|
||||
});
|
||||
}
|
||||
|
||||
fn remove_attribute_by_name(self, name: &Atom) {
|
||||
self.do_remove_attribute(|attr| attr.name() == name);
|
||||
}
|
||||
|
||||
fn do_remove_attribute<F>(self, find: F) where F: Fn(JSRef<Attr>) -> bool {
|
||||
let idx = self.attrs.borrow().iter()
|
||||
.map(|attr| attr.root())
|
||||
.position(|attr| find(attr.r()));
|
||||
|
||||
if let Some(idx) = idx {
|
||||
let attr = (*self.attrs.borrow())[idx].root();
|
||||
if namespace == ns!("") {
|
||||
if attr.r().namespace() == &ns!("") {
|
||||
vtable_for(&NodeCast::from_ref(self)).before_remove_attr(attr.r());
|
||||
}
|
||||
|
||||
|
@ -768,7 +794,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
if node.is_in_doc() {
|
||||
let document = document_from_node(self).root();
|
||||
let damage = if local_name == atom!("style") {
|
||||
let damage = if attr.r().local_name() == &atom!("style") {
|
||||
NodeDamage::NodeStyleDamaged
|
||||
} else {
|
||||
NodeDamage::OtherNodeDamage
|
||||
|
@ -788,7 +814,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
NoQuirks | LimitedQuirks => lhs == rhs,
|
||||
Quirks => lhs.eq_ignore_ascii_case(&rhs)
|
||||
};
|
||||
self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| {
|
||||
self.get_attribute(&ns!(""), &atom!("class")).root().map(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
@ -798,40 +824,38 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn set_atomic_attribute(self, name: &Atom, value: DOMString) {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
fn set_atomic_attribute(self, local_name: &Atom, value: DOMString) {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
let value = AttrValue::from_atomic(value);
|
||||
self.set_attribute(name, value);
|
||||
self.set_attribute(local_name, value);
|
||||
}
|
||||
|
||||
fn has_attribute(self, name: &Atom) -> bool {
|
||||
assert!(name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
||||
fn has_attribute(self, local_name: &Atom) -> bool {
|
||||
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attrs = self.attrs.borrow();
|
||||
attrs.iter().map(|attr| attr.root()).any(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let local_name = attr.local_name();
|
||||
let namespace = attr.namespace();
|
||||
*local_name == *name && *namespace == ns!("")
|
||||
attr.local_name() == local_name && attr.namespace() == &ns!("")
|
||||
})
|
||||
}
|
||||
|
||||
fn set_bool_attribute(self, name: &Atom, value: bool) {
|
||||
if self.has_attribute(name) == value { return; }
|
||||
fn set_bool_attribute(self, local_name: &Atom, value: bool) {
|
||||
if self.has_attribute(local_name) == value { return; }
|
||||
if value {
|
||||
self.set_string_attribute(name, String::new());
|
||||
self.set_string_attribute(local_name, String::new());
|
||||
} else {
|
||||
self.remove_attribute(ns!(""), &name);
|
||||
self.remove_attribute(&ns!(""), local_name);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_url_attribute(self, name: &Atom) -> DOMString {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
if !self.has_attribute(name) {
|
||||
fn get_url_attribute(self, local_name: &Atom) -> DOMString {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
if !self.has_attribute(local_name) {
|
||||
return "".to_owned();
|
||||
}
|
||||
let url = self.get_string_attribute(name);
|
||||
let url = self.get_string_attribute(local_name);
|
||||
let doc = document_from_node(self).root();
|
||||
let base = doc.r().url();
|
||||
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
|
||||
|
@ -841,23 +865,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
Err(_) => "".to_owned()
|
||||
}
|
||||
}
|
||||
fn set_url_attribute(self, name: &Atom, value: DOMString) {
|
||||
self.set_string_attribute(name, value);
|
||||
fn set_url_attribute(self, local_name: &Atom, value: DOMString) {
|
||||
self.set_string_attribute(local_name, value);
|
||||
}
|
||||
|
||||
fn get_string_attribute(self, name: &Atom) -> DOMString {
|
||||
match self.get_attribute(ns!(""), name) {
|
||||
fn get_string_attribute(self, local_name: &Atom) -> DOMString {
|
||||
match self.get_attribute(&ns!(""), local_name) {
|
||||
Some(x) => x.root().r().Value(),
|
||||
None => "".to_owned()
|
||||
}
|
||||
}
|
||||
fn set_string_attribute(self, name: &Atom, value: DOMString) {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
self.set_attribute(name, AttrValue::String(value));
|
||||
fn set_string_attribute(self, local_name: &Atom, value: DOMString) {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
self.set_attribute(local_name, AttrValue::String(value));
|
||||
}
|
||||
|
||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> {
|
||||
self.get_attribute(ns!(""), name).root().map(|attr| {
|
||||
fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom> {
|
||||
self.get_attribute(&ns!(""), local_name).root().map(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
@ -867,21 +891,21 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}).unwrap_or(vec!())
|
||||
}
|
||||
|
||||
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
self.set_attribute(name, AttrValue::from_serialized_tokenlist(value));
|
||||
fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString) {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value));
|
||||
}
|
||||
|
||||
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
self.set_attribute(name, AttrValue::from_atomic_tokens(tokens));
|
||||
fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>) {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens));
|
||||
}
|
||||
|
||||
fn get_uint_attribute(self, name: &Atom) -> u32 {
|
||||
assert!(name.chars().all(|ch| {
|
||||
fn get_uint_attribute(self, local_name: &Atom) -> u32 {
|
||||
assert!(local_name.chars().all(|ch| {
|
||||
!ch.is_ascii() || ch.to_ascii_lowercase() == ch
|
||||
}));
|
||||
let attribute = self.get_attribute(ns!(""), name).root();
|
||||
let attribute = self.get_attribute(&ns!(""), local_name).root();
|
||||
match attribute {
|
||||
Some(attribute) => {
|
||||
match *attribute.r().value() {
|
||||
|
@ -893,9 +917,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
None => 0,
|
||||
}
|
||||
}
|
||||
fn set_uint_attribute(self, name: &Atom, value: u32) {
|
||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
||||
self.set_attribute(name, AttrValue::UInt(value.to_string(), value));
|
||||
fn set_uint_attribute(self, local_name: &Atom, value: u32) {
|
||||
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -974,7 +998,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
// http://dom.spec.whatwg.org/#dom-element-getattribute
|
||||
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
|
||||
let name = self.parsed_name(name);
|
||||
self.get_attribute(ns!(""), &Atom::from_slice(&name)).root()
|
||||
self.get_attribute_by_name(&Atom::from_slice(&name)).root()
|
||||
.map(|s| s.r().Value())
|
||||
}
|
||||
|
||||
|
@ -982,7 +1006,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
fn GetAttributeNS(self,
|
||||
namespace: Option<DOMString>,
|
||||
local_name: DOMString) -> Option<DOMString> {
|
||||
let namespace = namespace::from_domstring(namespace);
|
||||
let namespace = &namespace::from_domstring(namespace);
|
||||
self.get_attribute(namespace, &Atom::from_slice(&local_name)).root()
|
||||
.map(|attr| attr.r().Value())
|
||||
}
|
||||
|
@ -1072,16 +1096,17 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-element-removeattribute
|
||||
fn RemoveAttribute(self, name: DOMString) {
|
||||
let name = self.parsed_name(name);
|
||||
self.remove_attribute(ns!(""), &name)
|
||||
let name = Atom::from_slice(&self.parsed_name(name));
|
||||
self.remove_attribute_by_name(&name);
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-removeattributens
|
||||
fn RemoveAttributeNS(self,
|
||||
namespace: Option<DOMString>,
|
||||
localname: DOMString) {
|
||||
local_name: DOMString) {
|
||||
let namespace = namespace::from_domstring(namespace);
|
||||
self.remove_attribute(namespace, &localname)
|
||||
let local_name = Atom::from_slice(&local_name);
|
||||
self.remove_attribute(&namespace, &local_name);
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-hasattribute
|
||||
|
@ -1379,7 +1404,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
if !tree_in_doc { return; }
|
||||
|
||||
if let Some(attr) = self.get_attribute(ns!(""), &atom!("id")).root() {
|
||||
if let Some(attr) = self.get_attribute(&ns!(""), &atom!("id")).root() {
|
||||
let doc = document_from_node(*self).root();
|
||||
let value = attr.r().Value();
|
||||
if !value.is_empty() {
|
||||
|
@ -1396,7 +1421,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
if !tree_in_doc { return; }
|
||||
|
||||
if let Some(attr) = self.get_attribute(ns!(""), &atom!("id")).root() {
|
||||
if let Some(attr) = self.get_attribute(&ns!(""), &atom!("id")).root() {
|
||||
let doc = document_from_node(*self).root();
|
||||
let value = attr.r().Value();
|
||||
if !value.is_empty() {
|
||||
|
@ -1409,8 +1434,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> {
|
||||
self.get_attribute(namespace.clone(), attr).root().map(|attr| {
|
||||
fn get_attr(self, namespace: &Namespace, local_name: &Atom) -> Option<&'a str> {
|
||||
self.get_attribute(namespace, local_name).root().map(|attr| {
|
||||
// This transmute is used to cheat the lifetime restriction.
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
@ -1419,8 +1444,8 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
|||
})
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
fn get_attrs(self, attr: &Atom) -> Vec<&'a str> {
|
||||
self.get_attributes(attr).into_iter().map(|attr| attr.root()).map(|attr| {
|
||||
fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> {
|
||||
self.get_attributes(local_name).into_iter().map(|attr| attr.root()).map(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
@ -1470,7 +1495,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
|||
node.get_focus_state()
|
||||
}
|
||||
fn get_id(self) -> Option<Atom> {
|
||||
self.get_attribute(ns!(""), &atom!("id")).map(|attr| {
|
||||
self.get_attribute(&ns!(""), &atom!("id")).map(|attr| {
|
||||
let attr = attr.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
@ -1515,7 +1540,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
|||
fn each_class<F>(self, mut callback: F)
|
||||
where F: FnMut(&Atom)
|
||||
{
|
||||
if let Some(ref attr) = self.get_attribute(ns!(""), &atom!("class")).root() {
|
||||
if let Some(ref attr) = self.get_attribute(&ns!(""), &atom!("class")).root() {
|
||||
if let Some(tokens) = attr.r().value().tokens() {
|
||||
for token in tokens {
|
||||
callback(token)
|
||||
|
|
|
@ -122,7 +122,7 @@ impl<'a> Activatable for JSRef<'a, HTMLAnchorElement> {
|
|||
//TODO: Step 3. Handle <img ismap/>.
|
||||
//TODO: Step 4. Download the link is `download` attribute is set.
|
||||
let element: JSRef<Element> = ElementCast::from_ref(*self);
|
||||
let attr = element.get_attribute(ns!(""), &atom!("href")).root();
|
||||
let attr = element.get_attribute(&ns!(""), &atom!("href")).root();
|
||||
match attr {
|
||||
Some(ref href) => {
|
||||
let value = href.r().Value();
|
||||
|
|
|
@ -194,9 +194,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
|
|||
element.set_custom_attribute(to_snake_case(name), value)
|
||||
}
|
||||
|
||||
fn get_custom_attr(self, name: DOMString) -> Option<DOMString> {
|
||||
fn get_custom_attr(self, local_name: DOMString) -> Option<DOMString> {
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
element.get_attribute(ns!(""), &Atom::from_slice(&to_snake_case(name))).map(|attr| {
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||
let attr = attr.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
@ -205,9 +206,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
|
|||
})
|
||||
}
|
||||
|
||||
fn delete_custom_attr(self, name: DOMString) {
|
||||
fn delete_custom_attr(self, local_name: DOMString) {
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
element.remove_attribute(ns!(""), &to_snake_case(name))
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.remove_attribute(&ns!(""), &local_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> {
|
|||
|
||||
fn get_url(self) -> Option<Url> {
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
element.get_attribute(ns!(""), &atom!("src")).root().and_then(|src| {
|
||||
element.get_attribute(&ns!(""), &atom!("src")).root().and_then(|src| {
|
||||
let url = src.r().value();
|
||||
if url.as_slice().is_empty() {
|
||||
None
|
||||
|
|
|
@ -391,7 +391,7 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> {
|
|||
fn get_radio_group_name(self) -> Option<String> {
|
||||
//TODO: determine form owner
|
||||
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||
elem.get_attribute(ns!(""), &atom!("name"))
|
||||
elem.get_attribute(&ns!(""), &atom!("name"))
|
||||
.root()
|
||||
.map(|name| name.r().Value())
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ impl HTMLLinkElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> {
|
||||
let elem = element.get_attribute(ns!(""), name).root();
|
||||
fn get_attr(element: JSRef<Element>, local_name: &Atom) -> Option<String> {
|
||||
let elem = element.get_attribute(&ns!(""), local_name).root();
|
||||
elem.map(|e| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let e = e.r();
|
||||
|
|
|
@ -62,8 +62,8 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> {
|
|||
let elem: JSRef<Element> = ElementCast::from_ref(*self);
|
||||
|
||||
// TODO: support other values
|
||||
match (elem.get_attribute(ns!(""), &atom!("type")).map(|x| x.root().r().Value()),
|
||||
elem.get_attribute(ns!(""), &atom!("data")).map(|x| x.root().r().Value())) {
|
||||
match (elem.get_attribute(&ns!(""), &atom!("type")).map(|x| x.root().r().Value()),
|
||||
elem.get_attribute(&ns!(""), &atom!("data")).map(|x| x.root().r().Value())) {
|
||||
(None, Some(uri)) => {
|
||||
if is_image_data(uri.as_slice()) {
|
||||
let data_url = Url::parse(uri.as_slice()).unwrap();
|
||||
|
|
|
@ -202,8 +202,8 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
}
|
||||
|
||||
// Step 12.
|
||||
let for_attribute = element.get_attribute(ns!(""), &atom!("for")).root();
|
||||
let event_attribute = element.get_attribute(ns!(""), &Atom::from_slice("event")).root();
|
||||
let for_attribute = element.get_attribute(&ns!(""), &atom!("for")).root();
|
||||
let event_attribute = element.get_attribute(&ns!(""), &Atom::from_slice("event")).root();
|
||||
match (for_attribute.r(), event_attribute.r()) {
|
||||
(Some(for_attribute), Some(event_attribute)) => {
|
||||
let for_value = for_attribute.Value()
|
||||
|
@ -223,7 +223,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
}
|
||||
|
||||
// Step 13.
|
||||
if let Some(charset) = element.get_attribute(ns!(""), &Atom::from_slice("charset")).root() {
|
||||
if let Some(charset) = element.get_attribute(&ns!(""), &Atom::from_slice("charset")).root() {
|
||||
if let Some(encodingRef) = encoding_from_whatwg_label(&charset.r().Value()) {
|
||||
*self.block_character_encoding.borrow_mut() = encodingRef;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
let window = window.r();
|
||||
let base_url = window.get_url();
|
||||
|
||||
let load = match element.get_attribute(ns!(""), &atom!("src")).root() {
|
||||
let load = match element.get_attribute(&ns!(""), &atom!("src")).root() {
|
||||
// Step 14.
|
||||
Some(src) => {
|
||||
// Step 14.1
|
||||
|
@ -406,7 +406,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
|
||||
fn is_javascript(self) -> bool {
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
match element.get_attribute(ns!(""), &atom!("type")).root().map(|s| s.r().Value()) {
|
||||
match element.get_attribute(&ns!(""), &atom!("type")).root().map(|s| s.r().Value()) {
|
||||
Some(ref s) if s.is_empty() => {
|
||||
// type attr exists, but empty means js
|
||||
debug!("script type empty, inferring js");
|
||||
|
@ -418,7 +418,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
|||
},
|
||||
None => {
|
||||
debug!("no script type");
|
||||
match element.get_attribute(ns!(""), &atom!("language"))
|
||||
match element.get_attribute(&ns!(""), &atom!("language"))
|
||||
.root()
|
||||
.map(|s| s.r().Value()) {
|
||||
Some(ref s) if s.is_empty() => {
|
||||
|
|
|
@ -2334,7 +2334,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
|||
fn match_attr<F>(self, attr: &AttrSelector, test: F) -> bool
|
||||
where F: Fn(&str) -> bool
|
||||
{
|
||||
let name = {
|
||||
let local_name = {
|
||||
if self.is_html_element_in_html_document() {
|
||||
&attr.lower_name
|
||||
} else {
|
||||
|
@ -2343,7 +2343,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
|||
};
|
||||
match attr.namespace {
|
||||
NamespaceConstraint::Specific(ref ns) => {
|
||||
self.as_element().get_attribute(ns.clone(), name).root()
|
||||
self.as_element().get_attribute(ns, local_name).root()
|
||||
.map_or(false, |attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
@ -2352,7 +2352,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
|||
})
|
||||
},
|
||||
NamespaceConstraint::Any => {
|
||||
self.as_element().get_attributes(name).into_iter()
|
||||
self.as_element().get_attributes(local_name).into_iter()
|
||||
.map(|attr| attr.root())
|
||||
.any(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue