mirror of
https://github.com/servo/servo.git
synced 2025-06-19 06:38:59 +01:00
Implement Element.prefix (Fixes #1737)
This commit is contained in:
parent
bb8a037cb2
commit
36bf23de20
6 changed files with 23 additions and 31 deletions
|
@ -269,7 +269,7 @@ impl Document {
|
|||
}
|
||||
|
||||
let (prefix_from_qname, local_name_from_qname) = get_attribute_parts(qualified_name);
|
||||
match (&ns, prefix_from_qname, local_name_from_qname.as_slice()) {
|
||||
match (&ns, prefix_from_qname.clone(), local_name_from_qname.as_slice()) {
|
||||
// throw if prefix is not null and namespace is null
|
||||
(&namespace::Null, Some(_), _) => {
|
||||
debug!("Namespace can't be null with a non-null prefix");
|
||||
|
@ -293,7 +293,7 @@ impl Document {
|
|||
if ns == namespace::HTML {
|
||||
Ok(build_element_from_tag(local_name_from_qname, abstract_self))
|
||||
} else {
|
||||
Ok(Element::new(local_name_from_qname, ns, abstract_self))
|
||||
Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, abstract_self))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ pub struct Element {
|
|||
node: Node,
|
||||
tag_name: DOMString, // TODO: This should be an atom, not a DOMString.
|
||||
namespace: Namespace,
|
||||
prefix: Option<DOMString>,
|
||||
attrs: ~[JS<Attr>],
|
||||
style_attribute: Option<style::PropertyDeclarationBlock>,
|
||||
attr_list: Option<JS<AttrList>>
|
||||
|
@ -139,19 +140,20 @@ pub enum ElementTypeId {
|
|||
//
|
||||
|
||||
impl Element {
|
||||
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, namespace: Namespace, document: JS<Document>) -> Element {
|
||||
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: JS<Document>) -> Element {
|
||||
Element {
|
||||
node: Node::new_inherited(ElementNodeTypeId(type_id), document),
|
||||
tag_name: tag_name,
|
||||
namespace: namespace,
|
||||
prefix: prefix,
|
||||
attrs: ~[],
|
||||
attr_list: None,
|
||||
style_attribute: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(tag_name: DOMString, namespace: Namespace, document: &JS<Document>) -> JS<Element> {
|
||||
let element = Element::new_inherited(ElementTypeId, tag_name, namespace, document.clone());
|
||||
pub fn new(tag_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JS<Document>) -> JS<Element> {
|
||||
let element = Element::new_inherited(ElementTypeId, tag_name, namespace, prefix, document.clone());
|
||||
Node::reflect_node(~element, document, ElementBinding::Wrap)
|
||||
}
|
||||
|
||||
|
@ -455,10 +457,22 @@ impl Element {
|
|||
self.namespace.to_str().to_owned()
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-prefix
|
||||
pub fn GetPrefix(&self) -> Option<DOMString> {
|
||||
self.prefix.clone()
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-tagname
|
||||
pub fn TagName(&self) -> DOMString {
|
||||
match self.prefix {
|
||||
None => {
|
||||
self.tag_name.to_ascii_upper()
|
||||
}
|
||||
Some(ref prefix_str) => {
|
||||
(*prefix_str + ":" + self.tag_name).to_ascii_upper()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-id
|
||||
pub fn Id(&self, abstract_self: &JS<Element>) -> DOMString {
|
||||
|
|
|
@ -35,7 +35,7 @@ impl HTMLElementDerived for EventTarget {
|
|||
impl HTMLElement {
|
||||
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS<Document>) -> HTMLElement {
|
||||
HTMLElement {
|
||||
element: Element::new_inherited(type_id, tag_name, namespace::HTML, document)
|
||||
element: Element::new_inherited(type_id, tag_name, namespace::HTML, None, document)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1731,16 +1731,6 @@ impl Node {
|
|||
false
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-node-prefix
|
||||
pub fn GetPrefix(&self) -> Option<DOMString> {
|
||||
None
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-node-localname
|
||||
pub fn GetLocalName(&self) -> Option<DOMString> {
|
||||
None
|
||||
}
|
||||
|
||||
//
|
||||
// Low-level pointer stitching
|
||||
//
|
||||
|
|
|
@ -14,13 +14,10 @@
|
|||
*/
|
||||
|
||||
interface Element : Node {
|
||||
/*
|
||||
We haven't moved these from Node to Element like the spec wants.
|
||||
|
||||
[Throws]
|
||||
readonly attribute DOMString? prefix;
|
||||
readonly attribute DOMString localName;
|
||||
*/
|
||||
// readonly attribute DOMString localName;
|
||||
|
||||
[Constant]
|
||||
readonly attribute DOMString namespaceURI;
|
||||
// Not [Constant] because it depends on which document we're in
|
||||
|
|
|
@ -76,13 +76,4 @@ interface Node : EventTarget {
|
|||
Node replaceChild(Node node, Node child);
|
||||
[Throws]
|
||||
Node removeChild(Node child);
|
||||
|
||||
// Mozilla-specific stuff
|
||||
// These have been moved to Element in the spec.
|
||||
// If we move prefix and localName to Element they should return
|
||||
// a non-nullable type.
|
||||
[Constant]
|
||||
readonly attribute DOMString? prefix;
|
||||
[Constant]
|
||||
readonly attribute DOMString? localName;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue