mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +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 {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use dom::attr::{Attr, AttrHelpers};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
||||
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||
|
@ -2278,9 +2279,27 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-lookupprefix
|
||||
fn LookupPrefix(self, _prefix: Option<DOMString>) -> Option<DOMString> {
|
||||
// FIXME (#1826) implement.
|
||||
None
|
||||
fn LookupPrefix(self, namespace: Option<DOMString>) -> Option<DOMString> {
|
||||
// Step 1.
|
||||
if null_str_as_empty(&namespace).is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
match self.type_id() {
|
||||
NodeTypeId::Element(..) => ElementCast::to_ref(self).unwrap().lookup_prefix(namespace),
|
||||
NodeTypeId::Document => {
|
||||
DocumentCast::to_ref(self).unwrap().GetDocumentElement().and_then(|element| {
|
||||
element.root().r().lookup_prefix(namespace)
|
||||
})
|
||||
},
|
||||
NodeTypeId::DocumentType | NodeTypeId::DocumentFragment => None,
|
||||
_ => {
|
||||
self.GetParentElement().and_then(|element| {
|
||||
element.root().r().lookup_prefix(namespace)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri
|
||||
|
@ -2517,4 +2536,3 @@ pub enum NodeDamage {
|
|||
/// Other parts of a node changed; attributes, text content, etc.
|
||||
OtherNodeDamage,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue