Merge pull request #3428 from Adenilson/moveIsVoidElement01

Move is_void() Element method together with the other struct methods.
This commit is contained in:
Josh Matthews 2014-09-20 13:53:22 -04:00
commit 2adc594e5d
3 changed files with 18 additions and 19 deletions

View file

@ -242,6 +242,7 @@ pub trait ElementHelpers {
fn get_local_name<'a>(&'a self) -> &'a Atom;
fn get_namespace<'a>(&'a self) -> &'a Namespace;
fn summarize(&self) -> Vec<AttrInfo>;
fn is_void(&self) -> bool;
}
impl<'a> ElementHelpers for JSRef<'a, Element> {
@ -269,6 +270,20 @@ impl<'a> ElementHelpers for JSRef<'a, Element> {
}
summarized
}
fn is_void(&self) -> bool {
if self.namespace != namespace::HTML {
return false
}
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" |
"frame" | "hr" | "img" | "input" | "keygen" | "link" | "menuitem" |
"meta" | "param" | "source" | "track" | "wbr" => true,
_ => false
}
}
}
pub trait AttributeHandlers {
@ -489,22 +504,6 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
}
impl Element {
pub fn is_void(&self) -> bool {
if self.namespace != namespace::HTML {
return false
}
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" |
"frame" | "hr" | "img" | "input" | "keygen" | "link" | "menuitem" |
"meta" | "param" | "source" | "track" | "wbr" => true,
_ => false
}
}
}
impl<'a> ElementMethods for JSRef<'a, Element> {
// http://dom.spec.whatwg.org/#dom-element-namespaceuri
fn GetNamespaceURI(&self) -> Option<DOMString> {

View file

@ -10,7 +10,7 @@ use dom::bindings::js::JSRef;
use dom::characterdata::CharacterData;
use dom::comment::Comment;
use dom::documenttype::DocumentType;
use dom::element::Element;
use dom::element::{Element, ElementHelpers};
use dom::node::{Node, NodeIterator};
use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId};
use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId};
@ -131,7 +131,7 @@ fn serialize_elem(elem: JSRef<Element>, open_elements: &mut Vec<String>, html: &
_ => {}
}
if !elem.deref().is_void() {
if !(elem.is_void()) {
open_elements.push(elem.deref().local_name.as_slice().to_string());
}
}

View file

@ -929,7 +929,7 @@ impl NodeIterator {
fn next_child<'b>(&self, node: JSRef<'b, Node>) -> Option<JSRef<'b, Node>> {
if !self.include_descendants_of_void && node.is_element() {
let elem: JSRef<Element> = ElementCast::to_ref(node).unwrap();
if elem.deref().is_void() {
if elem.is_void() {
None
} else {
node.first_child().map(|child| (*child.root()).clone())