Skip to content

Commit

Permalink
Implement Element.localName.(fixes #2188)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpy committed Apr 23, 2014
1 parent c6bdc7b commit dfe5215
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/main/layout/wrapper.rs
Expand Up @@ -348,7 +348,7 @@ impl<'le> LayoutElement<'le> {
impl<'le> TElement for LayoutElement<'le> {
#[inline]
fn get_local_name<'a>(&'a self) -> &'a str {
self.element.tag_name.as_slice()
self.element.local_name.as_slice()
}

#[inline]
Expand Down
14 changes: 7 additions & 7 deletions src/components/script/dom/document.rs
Expand Up @@ -514,7 +514,7 @@ impl Document {
struct ImagesFilter;
impl CollectionFilter for ImagesFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"img"
elem.get().local_name == ~"img"
}
}
let filter = ~ImagesFilter;
Expand All @@ -526,7 +526,7 @@ impl Document {
struct EmbedsFilter;
impl CollectionFilter for EmbedsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"embed"
elem.get().local_name == ~"embed"
}
}
let filter = ~EmbedsFilter;
Expand All @@ -543,7 +543,7 @@ impl Document {
struct LinksFilter;
impl CollectionFilter for LinksFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
(elem.get().tag_name == ~"a" || elem.get().tag_name == ~"area") &&
(elem.get().local_name == ~"a" || elem.get().local_name == ~"area") &&
elem.get_attribute(Null, "href").is_some()
}
}
Expand All @@ -556,7 +556,7 @@ impl Document {
struct FormsFilter;
impl CollectionFilter for FormsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"form"
elem.get().local_name == ~"form"
}
}
let filter = ~FormsFilter;
Expand All @@ -568,7 +568,7 @@ impl Document {
struct ScriptsFilter;
impl CollectionFilter for ScriptsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"script"
elem.get().local_name == ~"script"
}
}
let filter = ~ScriptsFilter;
Expand All @@ -580,7 +580,7 @@ impl Document {
struct AnchorsFilter;
impl CollectionFilter for AnchorsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"a" && elem.get_attribute(Null, "name").is_some()
elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
}
}
let filter = ~AnchorsFilter;
Expand All @@ -592,7 +592,7 @@ impl Document {
struct AppletsFilter;
impl CollectionFilter for AppletsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"applet"
elem.get().local_name == ~"applet"
}
}
let filter = ~AppletsFilter;
Expand Down
20 changes: 12 additions & 8 deletions src/components/script/dom/element.rs
Expand Up @@ -34,7 +34,7 @@ use std::cast;
#[deriving(Encodable)]
pub struct Element {
node: Node,
tag_name: DOMString, // TODO: This should be an atom, not a DOMString.
local_name: DOMString, // TODO: This should be an atom, not a DOMString.
namespace: Namespace,
prefix: Option<DOMString>,
attrs: ~[JS<Attr>],
Expand Down Expand Up @@ -140,10 +140,10 @@ pub enum ElementTypeId {
//

impl Element {
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: JS<Document>) -> Element {
pub fn new_inherited(type_id: ElementTypeId, local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: JS<Document>) -> Element {
Element {
node: Node::new_inherited(ElementNodeTypeId(type_id), document),
tag_name: tag_name,
local_name: local_name,
namespace: namespace,
prefix: prefix,
attrs: ~[],
Expand All @@ -152,8 +152,8 @@ impl 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, prefix, document.clone());
pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JS<Document>) -> JS<Element> {
let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.clone());
Node::reflect_node(~element, document, ElementBinding::Wrap)
}

Expand Down Expand Up @@ -440,7 +440,7 @@ impl Element {
if self.namespace != namespace::HTML {
return false
}
match self.tag_name.as_slice() {
match self.local_name.as_slice() {
/* List of void elements from
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm */
"area" | "base" | "basefont" | "bgsound" | "br" | "col" | "embed" |
Expand All @@ -457,6 +457,10 @@ impl Element {
self.namespace.to_str().to_owned()
}

pub fn LocalName(&self) -> DOMString {
self.local_name.clone()
}

// http://dom.spec.whatwg.org/#dom-element-prefix
pub fn GetPrefix(&self) -> Option<DOMString> {
self.prefix.clone()
Expand All @@ -466,10 +470,10 @@ impl Element {
pub fn TagName(&self) -> DOMString {
match self.prefix {
None => {
self.tag_name.to_ascii_upper()
self.local_name.to_ascii_upper()
}
Some(ref prefix_str) => {
(*prefix_str + ":" + self.tag_name).to_ascii_upper()
(*prefix_str + ":" + self.local_name).to_ascii_upper()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/script/dom/htmlcollection.rs
Expand Up @@ -62,7 +62,7 @@ impl HTMLCollection {
}
impl CollectionFilter for TagNameFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == self.tag
elem.get().local_name == self.tag
}
}
let filter = TagNameFilter {
Expand All @@ -79,7 +79,7 @@ impl HTMLCollection {
}
impl CollectionFilter for TagNameNSFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().namespace == self.namespace && elem.get().tag_name == self.tag
elem.get().namespace == self.namespace && elem.get().local_name == self.tag
}
}
let filter = TagNameNSFilter {
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/dom/htmldatalistelement.rs
Expand Up @@ -45,7 +45,7 @@ impl HTMLDataListElement {
struct HTMLDataListOptionsFilter;
impl CollectionFilter for HTMLDataListOptionsFilter {
fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool {
elem.get().tag_name == ~"option"
elem.get().local_name == ~"option"
}
}
let node: JS<Node> = NodeCast::from(abstract_self);
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/dom/htmlfieldsetelement.rs
Expand Up @@ -76,7 +76,7 @@ impl HTMLFieldSetElement {
static tag_names: StaticStringVec = &["button", "fieldset", "input",
"keygen", "object", "output", "select", "textarea"];
let root: &JS<Element> = &ElementCast::to(root).unwrap();
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().tag_name)
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name)
}
}
let node: JS<Node> = NodeCast::from(abstract_self);
Expand Down
8 changes: 4 additions & 4 deletions src/components/script/dom/htmlserializer.rs
Expand Up @@ -72,7 +72,7 @@ fn serialize_text(text: &JS<Text>) -> ~str {
match text.get().characterdata.node.parent_node {
Some(ref parent) if parent.is_element() => {
let elem: JS<Element> = ElementCast::to(parent).unwrap();
match elem.get().tag_name.as_slice() {
match elem.get().local_name.as_slice() {
"style" | "script" | "xmp" | "iframe" |
"noembed" | "noframes" | "plaintext" |
"noscript" if elem.get().namespace == namespace::HTML => {
Expand All @@ -94,12 +94,12 @@ fn serialize_doctype(doctype: &JS<DocumentType>) -> ~str {
}

fn serialize_elem(elem: &JS<Element>, open_elements: &mut ~[~str]) -> ~str {
let mut rv = ~"<" + elem.get().tag_name;
let mut rv = ~"<" + elem.get().local_name;
for attr in elem.get().attrs.iter() {
rv.push_str(serialize_attr(attr));
};
rv.push_str(">");
match elem.get().tag_name.as_slice() {
match elem.get().local_name.as_slice() {
"pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => {
match elem.get().node.first_child {
Some(ref child) if child.is_text() => {
Expand All @@ -114,7 +114,7 @@ fn serialize_elem(elem: &JS<Element>, open_elements: &mut ~[~str]) -> ~str {
_ => {}
}
if !elem.get().is_void() {
open_elements.push(elem.get().tag_name.clone());
open_elements.push(elem.get().local_name.clone());
}
rv
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/script/dom/node.rs
Expand Up @@ -1327,7 +1327,7 @@ impl Node {
ElementNodeTypeId(..) => {
let element: JS<Element> = ElementCast::to(node).unwrap();
let element = element.get();
let element = build_element_from_tag(element.tag_name.clone(), &document);
let element = build_element_from_tag(element.local_name.clone(), &document);
NodeCast::from(&element)
},
TextNodeTypeId => {
Expand Down Expand Up @@ -1591,7 +1591,7 @@ impl Node {
let other_element: JS<Element> = ElementCast::to(other).unwrap();
// FIXME: namespace prefix
(element.get().namespace == other_element.get().namespace) &&
(element.get().tag_name == other_element.get().tag_name) &&
(element.get().local_name == other_element.get().local_name) &&
(element.get().attrs.len() == other_element.get().attrs.len())
}
fn is_equal_processinginstruction(node: &JS<Node>, other: &JS<Node>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/dom/webidls/Element.webidl
Expand Up @@ -16,7 +16,7 @@
interface Element : Node {

readonly attribute DOMString? prefix;
// readonly attribute DOMString localName;
readonly attribute DOMString localName;

[Constant]
readonly attribute DOMString namespaceURI;
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/script_task.rs
Expand Up @@ -1056,7 +1056,7 @@ impl ScriptTask {

if node.is_element() {
let element: JS<Element> = ElementCast::to(&node).unwrap();
if "a" == element.get().tag_name {
if "a" == element.get().local_name {
self.load_url_from_element(page, &element)
}
}
Expand Down

5 comments on commit dfe5215

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue2188 = dfe5215 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue2188 = dfe5215 merged ok, testing candidate = 3fc2c11

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3fc2c11

Please sign in to comment.