mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Make Element::get_attribute() take its namespace by reference
This commit is contained in:
parent
dd88bcddc4
commit
254207730e
12 changed files with 33 additions and 33 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)
|
||||
}
|
||||
|
|
|
@ -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,7 +608,7 @@ 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.
|
||||
|
@ -655,9 +655,9 @@ pub trait AttributeHandlers {
|
|||
}
|
||||
|
||||
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()))
|
||||
}
|
||||
|
||||
|
@ -814,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();
|
||||
|
@ -872,7 +872,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn get_string_attribute(self, name: &Atom) -> DOMString {
|
||||
match self.get_attribute(ns!(""), name) {
|
||||
match self.get_attribute(&ns!(""), name) {
|
||||
Some(x) => x.root().r().Value(),
|
||||
None => "".to_owned()
|
||||
}
|
||||
|
@ -883,7 +883,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> {
|
||||
self.get_attribute(ns!(""), name).root().map(|attr| {
|
||||
self.get_attribute(&ns!(""), name).root().map(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value = attr.value();
|
||||
|
@ -907,7 +907,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
assert!(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!(""), name).root();
|
||||
match attribute {
|
||||
Some(attribute) => {
|
||||
match *attribute.r().value() {
|
||||
|
@ -1008,7 +1008,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())
|
||||
}
|
||||
|
@ -1406,7 +1406,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() {
|
||||
|
@ -1423,7 +1423,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() {
|
||||
|
@ -1437,7 +1437,7 @@ 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| {
|
||||
self.get_attribute(namespace, attr).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();
|
||||
|
@ -1497,7 +1497,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();
|
||||
|
@ -1542,7 +1542,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();
|
||||
|
|
|
@ -196,7 +196,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
|
|||
|
||||
fn get_custom_attr(self, 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| {
|
||||
element.get_attribute(&ns!(""), &Atom::from_slice(&to_snake_case(name))).map(|attr| {
|
||||
let attr = attr.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ impl HTMLLinkElement {
|
|||
}
|
||||
|
||||
fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> {
|
||||
let elem = element.get_attribute(ns!(""), name).root();
|
||||
let elem = element.get_attribute(&ns!(""), 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() => {
|
||||
|
|
|
@ -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, name).root()
|
||||
.map_or(false, |attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue