mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48: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);
|
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
|
// throw if prefix is not null and namespace is null
|
||||||
(&namespace::Null, Some(_), _) => {
|
(&namespace::Null, Some(_), _) => {
|
||||||
debug!("Namespace can't be null with a non-null prefix");
|
debug!("Namespace can't be null with a non-null prefix");
|
||||||
|
@ -293,7 +293,7 @@ impl Document {
|
||||||
if ns == namespace::HTML {
|
if ns == namespace::HTML {
|
||||||
Ok(build_element_from_tag(local_name_from_qname, abstract_self))
|
Ok(build_element_from_tag(local_name_from_qname, abstract_self))
|
||||||
} else {
|
} 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,
|
node: Node,
|
||||||
tag_name: DOMString, // TODO: This should be an atom, not a DOMString.
|
tag_name: DOMString, // TODO: This should be an atom, not a DOMString.
|
||||||
namespace: Namespace,
|
namespace: Namespace,
|
||||||
|
prefix: Option<DOMString>,
|
||||||
attrs: ~[JS<Attr>],
|
attrs: ~[JS<Attr>],
|
||||||
style_attribute: Option<style::PropertyDeclarationBlock>,
|
style_attribute: Option<style::PropertyDeclarationBlock>,
|
||||||
attr_list: Option<JS<AttrList>>
|
attr_list: Option<JS<AttrList>>
|
||||||
|
@ -139,19 +140,20 @@ pub enum ElementTypeId {
|
||||||
//
|
//
|
||||||
|
|
||||||
impl Element {
|
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 {
|
Element {
|
||||||
node: Node::new_inherited(ElementNodeTypeId(type_id), document),
|
node: Node::new_inherited(ElementNodeTypeId(type_id), document),
|
||||||
tag_name: tag_name,
|
tag_name: tag_name,
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
|
prefix: prefix,
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
attr_list: None,
|
attr_list: None,
|
||||||
style_attribute: None,
|
style_attribute: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(tag_name: DOMString, namespace: Namespace, document: &JS<Document>) -> JS<Element> {
|
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, document.clone());
|
let element = Element::new_inherited(ElementTypeId, tag_name, namespace, prefix, document.clone());
|
||||||
Node::reflect_node(~element, document, ElementBinding::Wrap)
|
Node::reflect_node(~element, document, ElementBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,9 +457,21 @@ impl Element {
|
||||||
self.namespace.to_str().to_owned()
|
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
|
// http://dom.spec.whatwg.org/#dom-element-tagname
|
||||||
pub fn TagName(&self) -> DOMString {
|
pub fn TagName(&self) -> DOMString {
|
||||||
self.tag_name.to_ascii_upper()
|
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
|
// http://dom.spec.whatwg.org/#dom-element-id
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl HTMLElementDerived for EventTarget {
|
||||||
impl HTMLElement {
|
impl HTMLElement {
|
||||||
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS<Document>) -> HTMLElement {
|
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS<Document>) -> HTMLElement {
|
||||||
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
|
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
|
// Low-level pointer stitching
|
||||||
//
|
//
|
||||||
|
|
|
@ -14,13 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface Element : Node {
|
interface Element : Node {
|
||||||
/*
|
|
||||||
We haven't moved these from Node to Element like the spec wants.
|
|
||||||
|
|
||||||
[Throws]
|
|
||||||
readonly attribute DOMString? prefix;
|
readonly attribute DOMString? prefix;
|
||||||
readonly attribute DOMString localName;
|
// readonly attribute DOMString localName;
|
||||||
*/
|
|
||||||
[Constant]
|
[Constant]
|
||||||
readonly attribute DOMString namespaceURI;
|
readonly attribute DOMString namespaceURI;
|
||||||
// Not [Constant] because it depends on which document we're in
|
// Not [Constant] because it depends on which document we're in
|
||||||
|
|
|
@ -76,13 +76,4 @@ interface Node : EventTarget {
|
||||||
Node replaceChild(Node node, Node child);
|
Node replaceChild(Node node, Node child);
|
||||||
[Throws]
|
[Throws]
|
||||||
Node removeChild(Node child);
|
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