mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Merge pull request #3428 from Adenilson/moveIsVoidElement01
Move is_void() Element method together with the other struct methods.
This commit is contained in:
commit
2adc594e5d
3 changed files with 18 additions and 19 deletions
|
@ -242,6 +242,7 @@ pub trait ElementHelpers {
|
||||||
fn get_local_name<'a>(&'a self) -> &'a Atom;
|
fn get_local_name<'a>(&'a self) -> &'a Atom;
|
||||||
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
||||||
fn summarize(&self) -> Vec<AttrInfo>;
|
fn summarize(&self) -> Vec<AttrInfo>;
|
||||||
|
fn is_void(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ElementHelpers for JSRef<'a, Element> {
|
impl<'a> ElementHelpers for JSRef<'a, Element> {
|
||||||
|
@ -269,6 +270,20 @@ impl<'a> ElementHelpers for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
summarized
|
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 {
|
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> {
|
impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
// http://dom.spec.whatwg.org/#dom-element-namespaceuri
|
// http://dom.spec.whatwg.org/#dom-element-namespaceuri
|
||||||
fn GetNamespaceURI(&self) -> Option<DOMString> {
|
fn GetNamespaceURI(&self) -> Option<DOMString> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use dom::bindings::js::JSRef;
|
||||||
use dom::characterdata::CharacterData;
|
use dom::characterdata::CharacterData;
|
||||||
use dom::comment::Comment;
|
use dom::comment::Comment;
|
||||||
use dom::documenttype::DocumentType;
|
use dom::documenttype::DocumentType;
|
||||||
use dom::element::Element;
|
use dom::element::{Element, ElementHelpers};
|
||||||
use dom::node::{Node, NodeIterator};
|
use dom::node::{Node, NodeIterator};
|
||||||
use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId};
|
use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId};
|
||||||
use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId};
|
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());
|
open_elements.push(elem.deref().local_name.as_slice().to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -929,7 +929,7 @@ impl NodeIterator {
|
||||||
fn next_child<'b>(&self, node: JSRef<'b, Node>) -> Option<JSRef<'b, Node>> {
|
fn next_child<'b>(&self, node: JSRef<'b, Node>) -> Option<JSRef<'b, Node>> {
|
||||||
if !self.include_descendants_of_void && node.is_element() {
|
if !self.include_descendants_of_void && node.is_element() {
|
||||||
let elem: JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let elem: JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
if elem.deref().is_void() {
|
if elem.is_void() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
node.first_child().map(|child| (*child.root()).clone())
|
node.first_child().map(|child| (*child.root()).clone())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue