mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Remove Element::get_attributes()
This commit is contained in:
parent
51418fc348
commit
5672142042
1 changed files with 11 additions and 34 deletions
|
@ -32,7 +32,6 @@ use dom::bindings::error::Error::{InvalidCharacter, Syntax};
|
||||||
use dom::bindings::error::{ErrorResult, Fallible};
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::bindings::trace::RootedVec;
|
|
||||||
use dom::bindings::utils::XMLName::InvalidXMLName;
|
use dom::bindings::utils::XMLName::InvalidXMLName;
|
||||||
use dom::bindings::utils::{namespace_from_domstring, xml_name_type, validate_and_extract};
|
use dom::bindings::utils::{namespace_from_domstring, xml_name_type, validate_and_extract};
|
||||||
use dom::create::create_element;
|
use dom::create::create_element;
|
||||||
|
@ -827,37 +826,24 @@ impl Element {
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
|
||||||
let mut attributes = RootedVec::new();
|
self.attrs.borrow().iter().map(JS::root).find(|attr| {
|
||||||
self.get_attributes(local_name, &mut attributes);
|
attr.local_name() == local_name && attr.namespace() == namespace
|
||||||
attributes.r().
|
})
|
||||||
iter()
|
|
||||||
.find(|attr| attr.namespace() == namespace)
|
|
||||||
.map(|attr| Root::from_ref(*attr))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<Root<Attr>> {
|
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<Root<Attr>> {
|
||||||
let name = &self.parsed_name(name);
|
let name = &self.parsed_name(name);
|
||||||
self.attrs.borrow().iter().map(|attr| attr.root())
|
self.attrs.borrow().iter().map(JS::root)
|
||||||
.find(|a| a.r().name() == name)
|
.find(|a| a.r().name() == name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
|
||||||
pub fn get_attributes(&self, local_name: &Atom, attributes: &mut RootedVec<JS<Attr>>) {
|
|
||||||
for ref attr in self.attrs.borrow().iter() {
|
|
||||||
let attr = attr.root();
|
|
||||||
if attr.r().local_name() == local_name {
|
|
||||||
attributes.push(JS::from_rooted(&attr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_attribute_from_parser(&self,
|
pub fn set_attribute_from_parser(&self,
|
||||||
qname: QualName,
|
qname: QualName,
|
||||||
value: DOMString,
|
value: DOMString,
|
||||||
prefix: Option<Atom>) {
|
prefix: Option<Atom>) {
|
||||||
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing
|
// 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())
|
if self.attrs.borrow().iter().map(JS::root)
|
||||||
.any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) {
|
.any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -907,9 +893,7 @@ impl Element {
|
||||||
cb: F)
|
cb: F)
|
||||||
where F: Fn(&Attr) -> bool
|
where F: Fn(&Attr) -> bool
|
||||||
{
|
{
|
||||||
let idx = self.attrs.borrow().iter()
|
let idx = self.attrs.borrow().iter().map(JS::root).position(|attr| cb(&attr));
|
||||||
.map(|attr| attr.root())
|
|
||||||
.position(|attr| cb(attr.r()));
|
|
||||||
let (idx, set_type) = match idx {
|
let (idx, set_type) = match idx {
|
||||||
Some(idx) => (idx, AttrSettingType::ReplacedAttr),
|
Some(idx) => (idx, AttrSettingType::ReplacedAttr),
|
||||||
None => {
|
None => {
|
||||||
|
@ -948,9 +932,7 @@ impl Element {
|
||||||
pub fn do_remove_attribute<F>(&self, find: F) -> Option<Root<Attr>>
|
pub fn do_remove_attribute<F>(&self, find: F) -> Option<Root<Attr>>
|
||||||
where F: Fn(&Attr) -> bool
|
where F: Fn(&Attr) -> bool
|
||||||
{
|
{
|
||||||
let idx = self.attrs.borrow().iter()
|
let idx = self.attrs.borrow().iter().map(JS::root).position(|attr| find(&attr));
|
||||||
.map(|attr| attr.root())
|
|
||||||
.position(|attr| find(attr.r()));
|
|
||||||
|
|
||||||
idx.map(|idx| {
|
idx.map(|idx| {
|
||||||
let attr = (*self.attrs.borrow())[idx].root();
|
let attr = (*self.attrs.borrow())[idx].root();
|
||||||
|
@ -1003,7 +985,7 @@ impl Element {
|
||||||
|
|
||||||
pub fn has_attribute(&self, local_name: &Atom) -> bool {
|
pub fn has_attribute(&self, local_name: &Atom) -> bool {
|
||||||
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
||||||
self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| {
|
self.attrs.borrow().iter().map(JS::root).any(|attr| {
|
||||||
attr.r().local_name() == local_name && attr.r().namespace() == &ns!("")
|
attr.r().local_name() == local_name && attr.r().namespace() == &ns!("")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1763,14 +1745,9 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => {
|
||||||
let mut attributes: RootedVec<JS<Attr>> = RootedVec::new();
|
self.attrs.borrow().iter().map(JS::root).any(|attr| {
|
||||||
self.get_attributes(local_name, &mut attributes);
|
attr.local_name() == local_name && test(&attr.value())
|
||||||
attributes.iter().any(|attr| {
|
})
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
|
||||||
let attr = attr.root();
|
|
||||||
let value = attr.r().value();
|
|
||||||
test(&value)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue