mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
parent
f7bfea5879
commit
4c5bebeb10
3 changed files with 97 additions and 4 deletions
|
@ -440,6 +440,7 @@ pub trait ElementHelpers<'a> {
|
|||
fn get_important_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>;
|
||||
fn get_root_element(self) -> Option<Temporary<Element>>;
|
||||
fn lookup_prefix(self, namespace: Option<DOMString>) -> Option<DOMString>;
|
||||
}
|
||||
|
||||
impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||
|
@ -599,6 +600,32 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
|||
None => Some(self).map(Temporary::from_rooted),
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
|
||||
fn lookup_prefix(self, namespace: Option<DOMString>) -> Option<DOMString> {
|
||||
for node in NodeCast::from_ref(self).inclusive_ancestors() {
|
||||
match ElementCast::to_ref(node.root().r()) {
|
||||
Some(element) => {
|
||||
// Step 1.
|
||||
if element.GetNamespaceURI() == namespace && element.GetPrefix().is_some() {
|
||||
return element.GetPrefix();
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
let attrs = element.Attributes().root();
|
||||
for i in 0..attrs.r().Length() {
|
||||
let attr = attrs.r().Item(i).unwrap().root();
|
||||
if attr.r().GetPrefix() == Some("xmlns".to_owned()) &&
|
||||
Some(attr.r().Value()) == namespace {
|
||||
return Some(attr.r().LocalName());
|
||||
}
|
||||
}
|
||||
},
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FocusElementHelpers {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue