auto merge of #1702 : quandrum/servo/element_to_characterdata, r=jdm

... to characterdata

All other node's parent type names reflect the actual type of the parent. This change extends that convention to the indicated nodes.

closes #1594
This commit is contained in:
bors-servo 2014-02-15 22:05:04 -05:00
commit a0b55b4c6c
10 changed files with 32 additions and 21 deletions

View file

@ -717,7 +717,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
match self.type_id() { match self.type_id() {
TextNodeTypeId => { TextNodeTypeId => {
unsafe { unsafe {
if !self.with_text(|text| text.element if !self.with_text(|text| text.characterdata
.data .data
.chars() .chars()
.all(|c| c.is_whitespace())) { .all(|c| c.is_whitespace())) {

View file

@ -112,7 +112,7 @@ pub trait TLayoutNode {
/// FIXME(pcwalton): Don't copy text. Atomically reference count instead. /// FIXME(pcwalton): Don't copy text. Atomically reference count instead.
fn text(&self) -> ~str { fn text(&self) -> ~str {
unsafe { unsafe {
self.with_text(|text| text.element.data.to_str()) self.with_text(|text| text.characterdata.data.to_str())
} }
} }

View file

@ -14,6 +14,12 @@ macro_rules! generate_cacheable_wrapper(
) )
) )
macro_rules! generate_cacheable_wrapper_characterdata(
($name: path, $wrap: path) => (
generate_cacheable_wrapper_base!($name, $wrap, characterdata)
)
)
macro_rules! generate_cacheable_wrapper_htmlelement( macro_rules! generate_cacheable_wrapper_htmlelement(
($name: path, $wrap: path) => ( ($name: path, $wrap: path) => (
generate_cacheable_wrapper_base!($name, $wrap, htmlelement) generate_cacheable_wrapper_base!($name, $wrap, htmlelement)
@ -60,6 +66,12 @@ macro_rules! generate_traceable(
) )
) )
macro_rules! generate_traceable_characterdata(
($name: path) => (
generate_traceable_base!($name, characterdata)
)
)
macro_rules! generate_traceable_htmlelement( macro_rules! generate_traceable_htmlelement(
($name: path) => ( ($name: path) => (
generate_traceable_base!($name, htmlelement) generate_traceable_base!($name, htmlelement)
@ -95,8 +107,8 @@ macro_rules! generate_traceable_base(
) )
generate_cacheable_wrapper!(Comment, CommentBinding::Wrap) generate_cacheable_wrapper_characterdata!(Comment, CommentBinding::Wrap)
generate_traceable!(Comment) generate_traceable_characterdata!(Comment)
generate_cacheable_wrapper_node!(DocumentFragment, DocumentFragmentBinding::Wrap) generate_cacheable_wrapper_node!(DocumentFragment, DocumentFragmentBinding::Wrap)
generate_traceable_node!(DocumentFragment) generate_traceable_node!(DocumentFragment)
@ -104,11 +116,11 @@ generate_traceable_node!(DocumentFragment)
generate_cacheable_wrapper_node!(DocumentType, DocumentTypeBinding::Wrap) generate_cacheable_wrapper_node!(DocumentType, DocumentTypeBinding::Wrap)
generate_traceable_node!(DocumentType) generate_traceable_node!(DocumentType)
generate_cacheable_wrapper!(Text, TextBinding::Wrap) generate_cacheable_wrapper_characterdata!(Text, TextBinding::Wrap)
generate_traceable!(Text) generate_traceable_characterdata!(Text)
generate_cacheable_wrapper!(ProcessingInstruction, ProcessingInstruction::Wrap) generate_cacheable_wrapper_characterdata!(ProcessingInstruction, ProcessingInstruction::Wrap)
generate_traceable!(ProcessingInstruction) generate_traceable_characterdata!(ProcessingInstruction)
generate_cacheable_wrapper_htmlelement!(HTMLHeadElement, HTMLHeadElementBinding::Wrap) generate_cacheable_wrapper_htmlelement!(HTMLHeadElement, HTMLHeadElementBinding::Wrap)
generate_traceable_htmlelement!(HTMLHeadElement) generate_traceable_htmlelement!(HTMLHeadElement)

View file

@ -12,13 +12,13 @@ use servo_util::str::DOMString;
/// An HTML comment. /// An HTML comment.
pub struct Comment { pub struct Comment {
element: CharacterData, characterdata: CharacterData,
} }
impl Comment { impl Comment {
pub fn new_inherited(text: DOMString, document: AbstractDocument) -> Comment { pub fn new_inherited(text: DOMString, document: AbstractDocument) -> Comment {
Comment { Comment {
element: CharacterData::new_inherited(CommentNodeTypeId, text, document) characterdata: CharacterData::new_inherited(CommentNodeTypeId, text, document)
} }
} }

View file

@ -342,7 +342,7 @@ impl Document {
for child in node.children() { for child in node.children() {
if child.is_text() { if child.is_text() {
child.with_imm_text(|text| { child.with_imm_text(|text| {
title = title + text.element.Data(); title = title + text.characterdata.Data();
}); });
} }
} }

View file

@ -77,7 +77,7 @@ fn serialize_text(node: AbstractNode) -> ~str {
fn serialize_processing_instruction(node: AbstractNode) -> ~str { fn serialize_processing_instruction(node: AbstractNode) -> ~str {
node.with_imm_processing_instruction(|processing_instruction| { node.with_imm_processing_instruction(|processing_instruction| {
~"<?" + processing_instruction.target + " " + processing_instruction.element.data + "?>" ~"<?" + processing_instruction.target + " " + processing_instruction.characterdata.data + "?>"
}) })
} }

View file

@ -1064,7 +1064,7 @@ impl Node {
for node in abstract_self.traverse_preorder() { for node in abstract_self.traverse_preorder() {
if node.is_text() { if node.is_text() {
node.with_imm_text(|text| { node.with_imm_text(|text| {
content = content + text.element.Data(); content = content + text.characterdata.Data();
}) })
} }
} }
@ -1591,7 +1591,7 @@ impl Node {
node.with_imm_processing_instruction(|pi| { node.with_imm_processing_instruction(|pi| {
other.with_imm_processing_instruction(|other_pi| { other.with_imm_processing_instruction(|other_pi| {
(pi.target == other_pi.target) && (pi.target == other_pi.target) &&
(pi.element.data == other_pi.element.data) (pi.characterdata.data == other_pi.characterdata.data)
}) })
}) })
} }

View file

@ -10,15 +10,14 @@ use servo_util::str::DOMString;
/// An HTML processing instruction node. /// An HTML processing instruction node.
pub struct ProcessingInstruction { pub struct ProcessingInstruction {
// FIXME: s/element/characterdata/ https://github.com/mozilla/servo/issues/1594 characterdata: CharacterData,
element: CharacterData,
target: DOMString, target: DOMString,
} }
impl ProcessingInstruction { impl ProcessingInstruction {
pub fn new_inherited(target: DOMString, data: DOMString, document: AbstractDocument) -> ProcessingInstruction { pub fn new_inherited(target: DOMString, data: DOMString, document: AbstractDocument) -> ProcessingInstruction {
ProcessingInstruction { ProcessingInstruction {
element: CharacterData::new_inherited(ProcessingInstructionNodeTypeId, data, document), characterdata: CharacterData::new_inherited(ProcessingInstructionNodeTypeId, data, document),
target: target target: target
} }
} }

View file

@ -12,13 +12,13 @@ use servo_util::str::DOMString;
/// An HTML text node. /// An HTML text node.
pub struct Text { pub struct Text {
element: CharacterData, characterdata: CharacterData,
} }
impl Text { impl Text {
pub fn new_inherited(text: DOMString, document: AbstractDocument) -> Text { pub fn new_inherited(text: DOMString, document: AbstractDocument) -> Text {
Text { Text {
element: CharacterData::new_inherited(TextNodeTypeId, text, document) characterdata: CharacterData::new_inherited(TextNodeTypeId, text, document)
} }
} }

View file

@ -468,7 +468,7 @@ pub fn parse_html(cx: *JSContext,
for child in scriptnode.children() { for child in scriptnode.children() {
debug!("child = {:?}", child); debug!("child = {:?}", child);
child.with_imm_text(|text| { child.with_imm_text(|text| {
data.push(text.element.data.to_str()); // FIXME: Bad copy. data.push(text.characterdata.data.to_str()); // FIXME: Bad copy.
}); });
} }
@ -490,7 +490,7 @@ pub fn parse_html(cx: *JSContext,
for child in style.children() { for child in style.children() {
debug!("child = {:?}", child); debug!("child = {:?}", child);
child.with_imm_text(|text| { child.with_imm_text(|text| {
data.push(text.element.data.to_str()); // FIXME: Bad copy. data.push(text.characterdata.data.to_str()); // FIXME: Bad copy.
}); });
} }