mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +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
|
/// Sets the owner element. Should be called after the attribute is added
|
||||||
/// or removed from its older parent.
|
/// or removed from its older parent.
|
||||||
fn set_owner(self, owner: Option<JSRef<Element>>) {
|
fn set_owner(self, owner: Option<JSRef<Element>>) {
|
||||||
let ns = self.namespace.clone();
|
let ref ns = self.namespace;
|
||||||
match (self.owner().root().r(), owner) {
|
match (self.owner().root().r(), owner) {
|
||||||
(None, Some(new)) => {
|
(None, Some(new)) => {
|
||||||
// Already in the list of attributes of new owner.
|
// 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) => {
|
(Some(old), None) => {
|
||||||
// Already gone from the list of attributes of old owner.
|
// 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)
|
(old, new) => assert!(old == new)
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
||||||
self.GetElementById(fragid.clone()).or_else(|| {
|
self.GetElementById(fragid.clone()).or_else(|| {
|
||||||
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
|
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
|
||||||
let elem: JSRef<Element> = ElementCast::from_ref(node);
|
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)
|
// 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();
|
||||||
|
@ -1280,7 +1280,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
Some(element) => element,
|
Some(element) => element,
|
||||||
None => return false,
|
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)
|
// 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();
|
||||||
|
|
|
@ -50,7 +50,7 @@ trait PrivateDOMTokenListHelpers {
|
||||||
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
impl<'a> PrivateDOMTokenListHelpers for JSRef<'a, DOMTokenList> {
|
||||||
fn attribute(self) -> Option<Temporary<Attr>> {
|
fn attribute(self) -> Option<Temporary<Attr>> {
|
||||||
let element = self.element.root();
|
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> {
|
fn check_token_exceptions(self, token: &str) -> Fallible<Atom> {
|
||||||
|
|
|
@ -608,7 +608,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||||
pub trait AttributeHandlers {
|
pub trait AttributeHandlers {
|
||||||
/// Returns the attribute with given namespace and case-sensitive local
|
/// Returns the attribute with given namespace and case-sensitive local
|
||||||
/// name, if any.
|
/// name, if any.
|
||||||
fn get_attribute(self, namespace: Namespace, local_name: &Atom)
|
fn get_attribute(self, namespace: &Namespace, local_name: &Atom)
|
||||||
-> Option<Temporary<Attr>>;
|
-> Option<Temporary<Attr>>;
|
||||||
/// Returns the first attribute with any namespace and given case-sensitive
|
/// Returns the first attribute with any namespace and given case-sensitive
|
||||||
/// name, if any.
|
/// name, if any.
|
||||||
|
@ -655,9 +655,9 @@ pub trait AttributeHandlers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
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())
|
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()))
|
.map(|x| Temporary::from_rooted(x.r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,7 +814,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
NoQuirks | LimitedQuirks => lhs == rhs,
|
NoQuirks | LimitedQuirks => lhs == rhs,
|
||||||
Quirks => lhs.eq_ignore_ascii_case(&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)
|
// 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();
|
||||||
|
@ -872,7 +872,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string_attribute(self, name: &Atom) -> DOMString {
|
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(),
|
Some(x) => x.root().r().Value(),
|
||||||
None => "".to_owned()
|
None => "".to_owned()
|
||||||
}
|
}
|
||||||
|
@ -883,7 +883,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> {
|
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)
|
// 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();
|
||||||
|
@ -907,7 +907,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
assert!(name.chars().all(|ch| {
|
assert!(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!(""), name).root();
|
||||||
match attribute {
|
match attribute {
|
||||||
Some(attribute) => {
|
Some(attribute) => {
|
||||||
match *attribute.r().value() {
|
match *attribute.r().value() {
|
||||||
|
@ -1008,7 +1008,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
fn GetAttributeNS(self,
|
fn GetAttributeNS(self,
|
||||||
namespace: Option<DOMString>,
|
namespace: Option<DOMString>,
|
||||||
local_name: DOMString) -> 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()
|
self.get_attribute(namespace, &Atom::from_slice(&local_name)).root()
|
||||||
.map(|attr| attr.r().Value())
|
.map(|attr| attr.r().Value())
|
||||||
}
|
}
|
||||||
|
@ -1406,7 +1406,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
if !tree_in_doc { return; }
|
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 doc = document_from_node(*self).root();
|
||||||
let value = attr.r().Value();
|
let value = attr.r().Value();
|
||||||
if !value.is_empty() {
|
if !value.is_empty() {
|
||||||
|
@ -1423,7 +1423,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
if !tree_in_doc { return; }
|
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 doc = document_from_node(*self).root();
|
||||||
let value = attr.r().Value();
|
let value = attr.r().Value();
|
||||||
if !value.is_empty() {
|
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> {
|
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, 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.
|
// 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();
|
||||||
|
@ -1497,7 +1497,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
node.get_focus_state()
|
node.get_focus_state()
|
||||||
}
|
}
|
||||||
fn get_id(self) -> Option<Atom> {
|
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();
|
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();
|
||||||
|
@ -1542,7 +1542,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
fn each_class<F>(self, mut callback: F)
|
fn each_class<F>(self, mut callback: F)
|
||||||
where F: FnMut(&Atom)
|
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() {
|
if let Some(tokens) = attr.r().value().tokens() {
|
||||||
for token in tokens {
|
for token in tokens {
|
||||||
callback(token)
|
callback(token)
|
||||||
|
|
|
@ -122,7 +122,7 @@ impl<'a> Activatable for JSRef<'a, HTMLAnchorElement> {
|
||||||
//TODO: Step 3. Handle <img ismap/>.
|
//TODO: Step 3. Handle <img ismap/>.
|
||||||
//TODO: Step 4. Download the link is `download` attribute is set.
|
//TODO: Step 4. Download the link is `download` attribute is set.
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(*self);
|
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 {
|
match attr {
|
||||||
Some(ref href) => {
|
Some(ref href) => {
|
||||||
let value = href.r().Value();
|
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> {
|
fn get_custom_attr(self, 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| {
|
element.get_attribute(&ns!(""), &Atom::from_slice(&to_snake_case(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();
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> {
|
||||||
|
|
||||||
fn get_url(self) -> Option<Url> {
|
fn get_url(self) -> Option<Url> {
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
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();
|
let url = src.r().value();
|
||||||
if url.as_slice().is_empty() {
|
if url.as_slice().is_empty() {
|
||||||
None
|
None
|
||||||
|
|
|
@ -391,7 +391,7 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> {
|
||||||
fn get_radio_group_name(self) -> Option<String> {
|
fn get_radio_group_name(self) -> Option<String> {
|
||||||
//TODO: determine form owner
|
//TODO: determine form owner
|
||||||
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
elem.get_attribute(ns!(""), &atom!("name"))
|
elem.get_attribute(&ns!(""), &atom!("name"))
|
||||||
.root()
|
.root()
|
||||||
.map(|name| name.r().Value())
|
.map(|name| name.r().Value())
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl HTMLLinkElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> {
|
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| {
|
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();
|
||||||
|
|
|
@ -62,8 +62,8 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> {
|
||||||
let elem: JSRef<Element> = ElementCast::from_ref(*self);
|
let elem: JSRef<Element> = ElementCast::from_ref(*self);
|
||||||
|
|
||||||
// TODO: support other values
|
// TODO: support other values
|
||||||
match (elem.get_attribute(ns!(""), &atom!("type")).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())) {
|
elem.get_attribute(&ns!(""), &atom!("data")).map(|x| x.root().r().Value())) {
|
||||||
(None, Some(uri)) => {
|
(None, Some(uri)) => {
|
||||||
if is_image_data(uri.as_slice()) {
|
if is_image_data(uri.as_slice()) {
|
||||||
let data_url = Url::parse(uri.as_slice()).unwrap();
|
let data_url = Url::parse(uri.as_slice()).unwrap();
|
||||||
|
|
|
@ -202,8 +202,8 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 12.
|
// Step 12.
|
||||||
let for_attribute = element.get_attribute(ns!(""), &atom!("for")).root();
|
let for_attribute = element.get_attribute(&ns!(""), &atom!("for")).root();
|
||||||
let event_attribute = element.get_attribute(ns!(""), &Atom::from_slice("event")).root();
|
let event_attribute = element.get_attribute(&ns!(""), &Atom::from_slice("event")).root();
|
||||||
match (for_attribute.r(), event_attribute.r()) {
|
match (for_attribute.r(), event_attribute.r()) {
|
||||||
(Some(for_attribute), Some(event_attribute)) => {
|
(Some(for_attribute), Some(event_attribute)) => {
|
||||||
let for_value = for_attribute.Value()
|
let for_value = for_attribute.Value()
|
||||||
|
@ -223,7 +223,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 13.
|
// 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()) {
|
if let Some(encodingRef) = encoding_from_whatwg_label(&charset.r().Value()) {
|
||||||
*self.block_character_encoding.borrow_mut() = encodingRef;
|
*self.block_character_encoding.borrow_mut() = encodingRef;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let base_url = window.get_url();
|
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.
|
// Step 14.
|
||||||
Some(src) => {
|
Some(src) => {
|
||||||
// Step 14.1
|
// Step 14.1
|
||||||
|
@ -406,7 +406,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
||||||
|
|
||||||
fn is_javascript(self) -> bool {
|
fn is_javascript(self) -> bool {
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
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() => {
|
Some(ref s) if s.is_empty() => {
|
||||||
// type attr exists, but empty means js
|
// type attr exists, but empty means js
|
||||||
debug!("script type empty, inferring js");
|
debug!("script type empty, inferring js");
|
||||||
|
@ -418,7 +418,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> {
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
debug!("no script type");
|
debug!("no script type");
|
||||||
match element.get_attribute(ns!(""), &atom!("language"))
|
match element.get_attribute(&ns!(""), &atom!("language"))
|
||||||
.root()
|
.root()
|
||||||
.map(|s| s.r().Value()) {
|
.map(|s| s.r().Value()) {
|
||||||
Some(ref s) if s.is_empty() => {
|
Some(ref s) if s.is_empty() => {
|
||||||
|
|
|
@ -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.clone(), name).root()
|
self.as_element().get_attribute(ns, 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();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue