mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
Rename many name arguments to local_name
This commit is contained in:
parent
254207730e
commit
561ec7e21d
4 changed files with 62 additions and 63 deletions
|
@ -638,20 +638,20 @@ pub trait AttributeHandlers {
|
||||||
|
|
||||||
fn has_class(self, name: &Atom) -> 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
|
// http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
|
||||||
fn has_attribute(self, name: &Atom) -> bool;
|
fn has_attribute(self, local_name: &Atom) -> bool;
|
||||||
fn set_bool_attribute(self, name: &Atom, value: bool);
|
fn set_bool_attribute(self, local_name: &Atom, value: bool);
|
||||||
fn get_url_attribute(self, name: &Atom) -> DOMString;
|
fn get_url_attribute(self, local_name: &Atom) -> DOMString;
|
||||||
fn set_url_attribute(self, name: &Atom, value: DOMString);
|
fn set_url_attribute(self, local_name: &Atom, value: DOMString);
|
||||||
fn get_string_attribute(self, name: &Atom) -> DOMString;
|
fn get_string_attribute(self, local_name: &Atom) -> DOMString;
|
||||||
fn set_string_attribute(self, name: &Atom, value: DOMString);
|
fn set_string_attribute(self, local_name: &Atom, value: DOMString);
|
||||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom>;
|
fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom>;
|
||||||
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString);
|
fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString);
|
||||||
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>);
|
fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>);
|
||||||
fn get_uint_attribute(self, name: &Atom) -> u32;
|
fn get_uint_attribute(self, local_name: &Atom) -> u32;
|
||||||
fn set_uint_attribute(self, name: &Atom, value: u32);
|
fn set_uint_attribute(self, local_name: &Atom, value: u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
|
@ -824,40 +824,38 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}).unwrap_or(false)
|
}).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_atomic_attribute(self, name: &Atom, value: DOMString) {
|
fn set_atomic_attribute(self, local_name: &Atom, value: DOMString) {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
let value = AttrValue::from_atomic(value);
|
let value = AttrValue::from_atomic(value);
|
||||||
self.set_attribute(name, value);
|
self.set_attribute(local_name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_attribute(self, name: &Atom) -> bool {
|
fn has_attribute(self, local_name: &Atom) -> bool {
|
||||||
assert!(name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = self.attrs.borrow();
|
let attrs = self.attrs.borrow();
|
||||||
attrs.iter().map(|attr| attr.root()).any(|attr| {
|
attrs.iter().map(|attr| attr.root()).any(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let local_name = attr.local_name();
|
attr.local_name() == local_name && attr.namespace() == &ns!("")
|
||||||
let namespace = attr.namespace();
|
|
||||||
*local_name == *name && *namespace == ns!("")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_bool_attribute(self, name: &Atom, value: bool) {
|
fn set_bool_attribute(self, local_name: &Atom, value: bool) {
|
||||||
if self.has_attribute(name) == value { return; }
|
if self.has_attribute(local_name) == value { return; }
|
||||||
if value {
|
if value {
|
||||||
self.set_string_attribute(name, String::new());
|
self.set_string_attribute(local_name, String::new());
|
||||||
} else {
|
} else {
|
||||||
self.remove_attribute(&ns!(""), name);
|
self.remove_attribute(&ns!(""), local_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_url_attribute(self, name: &Atom) -> DOMString {
|
fn get_url_attribute(self, local_name: &Atom) -> DOMString {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
if !self.has_attribute(name) {
|
if !self.has_attribute(local_name) {
|
||||||
return "".to_owned();
|
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 doc = document_from_node(self).root();
|
||||||
let base = doc.r().url();
|
let base = doc.r().url();
|
||||||
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
|
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
|
||||||
|
@ -867,23 +865,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
Err(_) => "".to_owned()
|
Err(_) => "".to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn set_url_attribute(self, name: &Atom, value: DOMString) {
|
fn set_url_attribute(self, local_name: &Atom, value: DOMString) {
|
||||||
self.set_string_attribute(name, value);
|
self.set_string_attribute(local_name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string_attribute(self, name: &Atom) -> DOMString {
|
fn get_string_attribute(self, local_name: &Atom) -> DOMString {
|
||||||
match self.get_attribute(&ns!(""), name) {
|
match self.get_attribute(&ns!(""), local_name) {
|
||||||
Some(x) => x.root().r().Value(),
|
Some(x) => x.root().r().Value(),
|
||||||
None => "".to_owned()
|
None => "".to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn set_string_attribute(self, name: &Atom, value: DOMString) {
|
fn set_string_attribute(self, local_name: &Atom, value: DOMString) {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
self.set_attribute(name, AttrValue::String(value));
|
self.set_attribute(local_name, AttrValue::String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> {
|
fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom> {
|
||||||
self.get_attribute(&ns!(""), name).root().map(|attr| {
|
self.get_attribute(&ns!(""), local_name).root().map(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let value = attr.value();
|
let value = attr.value();
|
||||||
|
@ -893,21 +891,21 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}).unwrap_or(vec!())
|
}).unwrap_or(vec!())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) {
|
fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString) {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
self.set_attribute(name, AttrValue::from_serialized_tokenlist(value));
|
self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) {
|
fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>) {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
self.set_attribute(name, AttrValue::from_atomic_tokens(tokens));
|
self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_uint_attribute(self, name: &Atom) -> u32 {
|
fn get_uint_attribute(self, local_name: &Atom) -> u32 {
|
||||||
assert!(name.chars().all(|ch| {
|
assert!(local_name.chars().all(|ch| {
|
||||||
!ch.is_ascii() || ch.to_ascii_lowercase() == 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 {
|
match attribute {
|
||||||
Some(attribute) => {
|
Some(attribute) => {
|
||||||
match *attribute.r().value() {
|
match *attribute.r().value() {
|
||||||
|
@ -919,9 +917,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
None => 0,
|
None => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn set_uint_attribute(self, name: &Atom, value: u32) {
|
fn set_uint_attribute(self, local_name: &Atom, value: u32) {
|
||||||
assert!(name.as_slice() == name.to_ascii_lowercase());
|
assert!(local_name.as_slice() == local_name.to_ascii_lowercase());
|
||||||
self.set_attribute(name, AttrValue::UInt(value.to_string(), value));
|
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1436,8 +1434,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> {
|
fn get_attr(self, namespace: &Namespace, local_name: &Atom) -> Option<&'a str> {
|
||||||
self.get_attribute(namespace, attr).root().map(|attr| {
|
self.get_attribute(namespace, local_name).root().map(|attr| {
|
||||||
// This transmute is used to cheat the lifetime restriction.
|
// This transmute is used to cheat the lifetime restriction.
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
|
@ -1446,8 +1444,8 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_attrs(self, attr: &Atom) -> Vec<&'a str> {
|
fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> {
|
||||||
self.get_attributes(attr).into_iter().map(|attr| attr.root()).map(|attr| {
|
self.get_attributes(local_name).into_iter().map(|attr| attr.root()).map(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let value = attr.value();
|
let value = attr.value();
|
||||||
|
|
|
@ -194,9 +194,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
|
||||||
element.set_custom_attribute(to_snake_case(name), value)
|
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);
|
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();
|
let attr = attr.root();
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
|
@ -205,10 +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);
|
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
let name = Atom::from_slice(&to_snake_case(name));
|
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||||
element.remove_attribute(&ns!(""), &name);
|
element.remove_attribute(&ns!(""), &local_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ impl HTMLLinkElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> {
|
fn get_attr(element: JSRef<Element>, local_name: &Atom) -> Option<String> {
|
||||||
let elem = element.get_attribute(&ns!(""), name).root();
|
let elem = element.get_attribute(&ns!(""), local_name).root();
|
||||||
elem.map(|e| {
|
elem.map(|e| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let e = e.r();
|
let e = e.r();
|
||||||
|
|
|
@ -2334,7 +2334,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
||||||
fn match_attr<F>(self, attr: &AttrSelector, test: F) -> bool
|
fn match_attr<F>(self, attr: &AttrSelector, test: F) -> bool
|
||||||
where F: Fn(&str) -> bool
|
where F: Fn(&str) -> bool
|
||||||
{
|
{
|
||||||
let name = {
|
let local_name = {
|
||||||
if self.is_html_element_in_html_document() {
|
if self.is_html_element_in_html_document() {
|
||||||
&attr.lower_name
|
&attr.lower_name
|
||||||
} else {
|
} else {
|
||||||
|
@ -2343,7 +2343,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
||||||
};
|
};
|
||||||
match attr.namespace {
|
match attr.namespace {
|
||||||
NamespaceConstraint::Specific(ref ns) => {
|
NamespaceConstraint::Specific(ref ns) => {
|
||||||
self.as_element().get_attribute(ns, name).root()
|
self.as_element().get_attribute(ns, local_name).root()
|
||||||
.map_or(false, |attr| {
|
.map_or(false, |attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
|
@ -2352,7 +2352,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => {
|
||||||
self.as_element().get_attributes(name).into_iter()
|
self.as_element().get_attributes(local_name).into_iter()
|
||||||
.map(|attr| attr.root())
|
.map(|attr| attr.root())
|
||||||
.any(|attr| {
|
.any(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue