Make NodeTypeId include CharacterData variant

NodeTypeId is supposed to reflect the WebIDL inheritance hierarchy.
All of Text/ProcessingInstruction/Comment inherit from CharacterData,
which inherits from Node. There should be a CharacterDataTypeId value
that differentiates between those, instead.
This commit is contained in:
Jinwoo Song 2015-04-28 14:09:31 +09:00
parent 1e150140bd
commit f404853c99
9 changed files with 67 additions and 78 deletions

View file

@ -47,6 +47,7 @@ use text::TextRunScanner;
use wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode}; use wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode};
use gfx::display_list::OpaqueNode; use gfx::display_list::OpaqueNode;
use script::dom::characterdata::CharacterDataTypeId;
use script::dom::element::ElementTypeId; use script::dom::element::ElementTypeId;
use script::dom::htmlelement::HTMLElementTypeId; use script::dom::htmlelement::HTMLElementTypeId;
use script::dom::htmlobjectelement::is_image_data; use script::dom::htmlobjectelement::is_image_data;
@ -789,7 +790,7 @@ impl<'a> FlowConstructor<'a> {
// fragment that needs to be generated for this inline node. // fragment that needs to be generated for this inline node.
let mut fragments = LinkedList::new(); let mut fragments = LinkedList::new();
match (node.get_pseudo_element_type(), node.type_id()) { match (node.get_pseudo_element_type(), node.type_id()) {
(_, Some(NodeTypeId::Text)) => { (_, Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text))) => {
self.create_fragments_for_node_text_content(&mut fragments, node, &style) self.create_fragments_for_node_text_content(&mut fragments, node, &style)
} }
(PseudoElementType::Normal, _) => { (PseudoElementType::Normal, _) => {
@ -1239,12 +1240,12 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
}; };
(munged_display, style.get_box().float, style.get_box().position) (munged_display, style.get_box().float, style.get_box().position)
} }
Some(NodeTypeId::Text) => (display::T::inline, float::T::none, position::T::static_), Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => (display::T::inline, float::T::none, position::T::static_),
Some(NodeTypeId::Comment) | Some(NodeTypeId::CharacterData(CharacterDataTypeId::Comment)) |
Some(NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction)) |
Some(NodeTypeId::DocumentType) | Some(NodeTypeId::DocumentType) |
Some(NodeTypeId::DocumentFragment) | Some(NodeTypeId::DocumentFragment) |
Some(NodeTypeId::Document) | Some(NodeTypeId::Document) => {
Some(NodeTypeId::ProcessingInstruction) => {
(display::T::none, float::T::none, position::T::static_) (display::T::none, float::T::none, position::T::static_)
} }
}; };
@ -1382,9 +1383,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
fn is_replaced_content(&self) -> bool { fn is_replaced_content(&self) -> bool {
match self.type_id() { match self.type_id() {
None | None |
Some(NodeTypeId::Text) | Some(NodeTypeId::CharacterData(_)) |
Some(NodeTypeId::ProcessingInstruction) |
Some(NodeTypeId::Comment) |
Some(NodeTypeId::DocumentType) | Some(NodeTypeId::DocumentType) |
Some(NodeTypeId::DocumentFragment) | Some(NodeTypeId::DocumentFragment) |
Some(NodeTypeId::Document) | Some(NodeTypeId::Document) |

View file

@ -14,6 +14,7 @@ use incremental::{self, RestyleDamage};
use opaque_node::OpaqueNodeMethods; use opaque_node::OpaqueNodeMethods;
use wrapper::{LayoutElement, LayoutNode, TLayoutNode}; use wrapper::{LayoutElement, LayoutNode, TLayoutNode};
use script::dom::characterdata::CharacterDataTypeId;
use script::dom::node::NodeTypeId; use script::dom::node::NodeTypeId;
use script::layout_interface::Animation; use script::layout_interface::Animation;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
@ -676,7 +677,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
&mut None => panic!("no layout data"), &mut None => panic!("no layout data"),
&mut Some(ref mut layout_data) => { &mut Some(ref mut layout_data) => {
match self.type_id() { match self.type_id() {
Some(NodeTypeId::Text) => { Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => {
// Text nodes get a copy of the parent style. This ensures // Text nodes get a copy of the parent style. This ensures
// that during fragment construction any non-inherited // that during fragment construction any non-inherited
// CSS properties (such as vertical-align) are correctly // CSS properties (such as vertical-align) are correctly

View file

@ -45,7 +45,7 @@ use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLCa
use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast};
use script::dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast, TextCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast, TextCast};
use script::dom::bindings::js::LayoutJS; use script::dom::bindings::js::LayoutJS;
use script::dom::characterdata::LayoutCharacterDataHelpers; use script::dom::characterdata::{CharacterDataTypeId, LayoutCharacterDataHelpers};
use script::dom::element::{Element, ElementTypeId}; use script::dom::element::{Element, ElementTypeId};
use script::dom::element::{LayoutElementHelpers, RawLayoutElementHelpers}; use script::dom::element::{LayoutElementHelpers, RawLayoutElementHelpers};
use script::dom::htmlelement::HTMLElementTypeId; use script::dom::htmlelement::HTMLElementTypeId;
@ -1048,7 +1048,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
/// `empty_cells` per CSS 2.1 § 17.6.1.1. /// `empty_cells` per CSS 2.1 § 17.6.1.1.
pub fn is_content(&self) -> bool { pub fn is_content(&self) -> bool {
match self.type_id() { match self.type_id() {
Some(NodeTypeId::Element(..)) | Some(NodeTypeId::Text(..)) => true, Some(NodeTypeId::Element(..)) | Some(NodeTypeId::CharacterData(CharacterDataTypeId::Text(..))) => true,
_ => false _ => false
} }
} }

View file

@ -33,18 +33,16 @@ pub struct CharacterData {
impl CharacterDataDerived for EventTarget { impl CharacterDataDerived for EventTarget {
fn is_characterdata(&self) -> bool { fn is_characterdata(&self) -> bool {
match *self.type_id() { match *self.type_id() {
EventTargetTypeId::Node(NodeTypeId::Text) | EventTargetTypeId::Node(NodeTypeId::CharacterData(_)) => true,
EventTargetTypeId::Node(NodeTypeId::Comment) |
EventTargetTypeId::Node(NodeTypeId::ProcessingInstruction) => true,
_ => false _ => false
} }
} }
} }
impl CharacterData { impl CharacterData {
pub fn new_inherited(id: NodeTypeId, data: DOMString, document: JSRef<Document>) -> CharacterData { pub fn new_inherited(id: CharacterDataTypeId, data: DOMString, document: JSRef<Document>) -> CharacterData {
CharacterData { CharacterData {
node: Node::new_inherited(id, document), node: Node::new_inherited(NodeTypeId::CharacterData(id), document),
data: DOMRefCell::new(data), data: DOMRefCell::new(data),
} }
} }
@ -153,6 +151,15 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
} }
} }
/// The different types of CharacterData.
#[derive(Copy, Clone, PartialEq, Debug)]
#[jstraceable]
pub enum CharacterDataTypeId {
Comment,
Text,
ProcessingInstruction,
}
pub trait CharacterDataHelpers<'a> { pub trait CharacterDataHelpers<'a> {
fn data(self) -> Ref<'a, DOMString>; fn data(self) -> Ref<'a, DOMString>;
} }

View file

@ -8,7 +8,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Rootable, Temporary}; use dom::bindings::js::{JSRef, Rootable, Temporary};
use dom::characterdata::CharacterData; use dom::characterdata::{CharacterData, CharacterDataTypeId};
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeTypeId};
@ -22,14 +22,14 @@ pub struct Comment {
impl CommentDerived for EventTarget { impl CommentDerived for EventTarget {
fn is_comment(&self) -> bool { fn is_comment(&self) -> bool {
*self.type_id() == EventTargetTypeId::Node(NodeTypeId::Comment) *self.type_id() == EventTargetTypeId::Node(NodeTypeId::CharacterData(CharacterDataTypeId::Comment))
} }
} }
impl Comment { impl Comment {
fn new_inherited(text: DOMString, document: JSRef<Document>) -> Comment { fn new_inherited(text: DOMString, document: JSRef<Document>) -> Comment {
Comment { Comment {
characterdata: CharacterData::new_inherited(NodeTypeId::Comment, text, document) characterdata: CharacterData::new_inherited(CharacterDataTypeId::Comment, text, document)
} }
} }

View file

@ -31,7 +31,7 @@ use dom::bindings::js::Unrooted;
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use dom::bindings::trace::RootedVec; use dom::bindings::trace::RootedVec;
use dom::bindings::utils::{Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflectable, reflect_dom_object};
use dom::characterdata::{CharacterData, CharacterDataHelpers}; use dom::characterdata::{CharacterData, CharacterDataHelpers, CharacterDataTypeId};
use dom::comment::Comment; use dom::comment::Comment;
use dom::document::{Document, DocumentHelpers, IsHTMLDocument, DocumentSource}; use dom::document::{Document, DocumentHelpers, IsHTMLDocument, DocumentSource};
use dom::documentfragment::DocumentFragment; use dom::documentfragment::DocumentFragment;
@ -269,13 +269,11 @@ impl LayoutDataRef {
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
#[jstraceable] #[jstraceable]
pub enum NodeTypeId { pub enum NodeTypeId {
CharacterData(CharacterDataTypeId),
DocumentType, DocumentType,
DocumentFragment, DocumentFragment,
Comment,
Document, Document,
Element(ElementTypeId), Element(ElementTypeId),
Text,
ProcessingInstruction,
} }
trait PrivateNodeHelpers { trait PrivateNodeHelpers {
@ -616,7 +614,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
#[inline] #[inline]
fn is_text(self) -> bool { fn is_text(self) -> bool {
self.type_id == NodeTypeId::Text self.type_id == NodeTypeId::CharacterData(CharacterDataTypeId::Text)
} }
fn get_flag(self, flag: NodeFlags) -> bool { fn get_flag(self, flag: NodeFlags) -> bool {
@ -1420,7 +1418,7 @@ impl Node {
// Step 4-5. // Step 4-5.
match node.type_id() { match node.type_id() {
NodeTypeId::Text => { NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
if parent.is_document() { if parent.is_document() {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
@ -1432,8 +1430,8 @@ impl Node {
}, },
NodeTypeId::DocumentFragment | NodeTypeId::DocumentFragment |
NodeTypeId::Element(_) | NodeTypeId::Element(_) |
NodeTypeId::ProcessingInstruction | NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) |
NodeTypeId::Comment => (), NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => (),
NodeTypeId::Document => return Err(HierarchyRequest) NodeTypeId::Document => return Err(HierarchyRequest)
} }
@ -1507,9 +1505,7 @@ impl Node {
}, },
} }
}, },
NodeTypeId::Text | NodeTypeId::CharacterData(_) => (),
NodeTypeId::ProcessingInstruction |
NodeTypeId::Comment => (),
NodeTypeId::Document => unreachable!(), NodeTypeId::Document => unreachable!(),
} }
}, },
@ -1711,7 +1707,7 @@ impl Node {
let doc_fragment = DocumentFragment::new(document.r()); let doc_fragment = DocumentFragment::new(document.r());
NodeCast::from_temporary(doc_fragment) NodeCast::from_temporary(doc_fragment)
}, },
NodeTypeId::Comment => { NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => {
let cdata = CharacterDataCast::to_ref(node).unwrap(); let cdata = CharacterDataCast::to_ref(node).unwrap();
let comment = Comment::new(cdata.Data(), document.r()); let comment = Comment::new(cdata.Data(), document.r());
NodeCast::from_temporary(comment) NodeCast::from_temporary(comment)
@ -1739,12 +1735,12 @@ impl Node {
document.r(), ElementCreator::ScriptCreated); document.r(), ElementCreator::ScriptCreated);
NodeCast::from_temporary(element) NodeCast::from_temporary(element)
}, },
NodeTypeId::Text => { NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
let cdata = CharacterDataCast::to_ref(node).unwrap(); let cdata = CharacterDataCast::to_ref(node).unwrap();
let text = Text::new(cdata.Data(), document.r()); let text = Text::new(cdata.Data(), document.r());
NodeCast::from_temporary(text) NodeCast::from_temporary(text)
}, },
NodeTypeId::ProcessingInstruction => { NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
let pi: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap(); let pi: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
let pi = ProcessingInstruction::new(pi.Target(), let pi = ProcessingInstruction::new(pi.Target(),
CharacterDataCast::from_ref(pi).Data(), document.r()); CharacterDataCast::from_ref(pi).Data(), document.r());
@ -1819,13 +1815,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-nodetype // https://dom.spec.whatwg.org/#dom-node-nodetype
fn NodeType(self) -> u16 { fn NodeType(self) -> u16 {
match self.type_id { match self.type_id {
NodeTypeId::Element(_) => NodeConstants::ELEMENT_NODE, NodeTypeId::CharacterData(CharacterDataTypeId::Text) => NodeConstants::TEXT_NODE,
NodeTypeId::Text => NodeConstants::TEXT_NODE, NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => NodeConstants::PROCESSING_INSTRUCTION_NODE,
NodeTypeId::ProcessingInstruction => NodeConstants::PROCESSING_INSTRUCTION_NODE, NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => NodeConstants::COMMENT_NODE,
NodeTypeId::Comment => NodeConstants::COMMENT_NODE,
NodeTypeId::Document => NodeConstants::DOCUMENT_NODE, NodeTypeId::Document => NodeConstants::DOCUMENT_NODE,
NodeTypeId::DocumentType => NodeConstants::DOCUMENT_TYPE_NODE, NodeTypeId::DocumentType => NodeConstants::DOCUMENT_TYPE_NODE,
NodeTypeId::DocumentFragment => NodeConstants::DOCUMENT_FRAGMENT_NODE, NodeTypeId::DocumentFragment => NodeConstants::DOCUMENT_FRAGMENT_NODE,
NodeTypeId::Element(_) => NodeConstants::ELEMENT_NODE,
} }
} }
@ -1836,13 +1832,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let elem: JSRef<Element> = ElementCast::to_ref(self).unwrap(); let elem: JSRef<Element> = ElementCast::to_ref(self).unwrap();
elem.TagName() elem.TagName()
} }
NodeTypeId::Text => "#text".to_owned(), NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
NodeTypeId::ProcessingInstruction => { NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
let processing_instruction: JSRef<ProcessingInstruction> = let processing_instruction: JSRef<ProcessingInstruction> =
ProcessingInstructionCast::to_ref(self).unwrap(); ProcessingInstructionCast::to_ref(self).unwrap();
processing_instruction.Target() processing_instruction.Target()
} }
NodeTypeId::Comment => "#comment".to_owned(), NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
NodeTypeId::DocumentType => { NodeTypeId::DocumentType => {
let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap(); let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
doctype.name().clone() doctype.name().clone()
@ -1861,10 +1857,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-ownerdocument // https://dom.spec.whatwg.org/#dom-node-ownerdocument
fn GetOwnerDocument(self) -> Option<Temporary<Document>> { fn GetOwnerDocument(self) -> Option<Temporary<Document>> {
match self.type_id { match self.type_id {
NodeTypeId::CharacterData(..) |
NodeTypeId::Element(..) | NodeTypeId::Element(..) |
NodeTypeId::Comment |
NodeTypeId::Text |
NodeTypeId::ProcessingInstruction |
NodeTypeId::DocumentType | NodeTypeId::DocumentType |
NodeTypeId::DocumentFragment => Some(self.owner_doc()), NodeTypeId::DocumentFragment => Some(self.owner_doc()),
NodeTypeId::Document => None NodeTypeId::Document => None
@ -1924,9 +1918,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-nodevalue // https://dom.spec.whatwg.org/#dom-node-nodevalue
fn GetNodeValue(self) -> Option<DOMString> { fn GetNodeValue(self) -> Option<DOMString> {
match self.type_id { match self.type_id {
NodeTypeId::Comment | NodeTypeId::CharacterData(..) => {
NodeTypeId::Text |
NodeTypeId::ProcessingInstruction => {
let chardata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap(); let chardata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(chardata.Data()) Some(chardata.Data())
} }
@ -1939,9 +1931,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-nodevalue // https://dom.spec.whatwg.org/#dom-node-nodevalue
fn SetNodeValue(self, val: Option<DOMString>) { fn SetNodeValue(self, val: Option<DOMString>) {
match self.type_id { match self.type_id {
NodeTypeId::Comment | NodeTypeId::CharacterData(..) => {
NodeTypeId::Text |
NodeTypeId::ProcessingInstruction => {
self.SetTextContent(val) self.SetTextContent(val)
} }
_ => {} _ => {}
@ -1956,9 +1946,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let content = Node::collect_text_contents(self.traverse_preorder()); let content = Node::collect_text_contents(self.traverse_preorder());
Some(content) Some(content)
} }
NodeTypeId::Comment | NodeTypeId::CharacterData(..) => {
NodeTypeId::Text |
NodeTypeId::ProcessingInstruction => {
let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap(); let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(characterdata.Data()) Some(characterdata.Data())
} }
@ -1986,9 +1974,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// Step 3. // Step 3.
Node::replace_all(node.r(), self); Node::replace_all(node.r(), self);
} }
NodeTypeId::Comment | NodeTypeId::CharacterData(..) => {
NodeTypeId::Text |
NodeTypeId::ProcessingInstruction => {
let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap(); let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
characterdata.SetData(value); characterdata.SetData(value);
@ -2034,14 +2020,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// Step 4-5. // Step 4-5.
match node.type_id() { match node.type_id() {
NodeTypeId::Text if self.is_document() => return Err(HierarchyRequest), NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is_document() => return Err(HierarchyRequest),
NodeTypeId::DocumentType if !self.is_document() => return Err(HierarchyRequest), NodeTypeId::DocumentType if !self.is_document() => return Err(HierarchyRequest),
NodeTypeId::DocumentFragment | NodeTypeId::DocumentFragment |
NodeTypeId::DocumentType | NodeTypeId::DocumentType |
NodeTypeId::Element(..) | NodeTypeId::Element(..) |
NodeTypeId::Text | NodeTypeId::CharacterData(..) => (),
NodeTypeId::ProcessingInstruction |
NodeTypeId::Comment => (),
NodeTypeId::Document => return Err(HierarchyRequest) NodeTypeId::Document => return Err(HierarchyRequest)
} }
@ -2107,9 +2091,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
}, },
NodeTypeId::Text | NodeTypeId::CharacterData(..) => (),
NodeTypeId::ProcessingInstruction |
NodeTypeId::Comment => (),
NodeTypeId::Document => unreachable!() NodeTypeId::Document => unreachable!()
} }
}, },
@ -2269,9 +2251,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// Step 3. // Step 3.
NodeTypeId::DocumentType if !is_equal_doctype(this, node) => return false, NodeTypeId::DocumentType if !is_equal_doctype(this, node) => return false,
NodeTypeId::Element(..) if !is_equal_element(this, node) => return false, NodeTypeId::Element(..) if !is_equal_element(this, node) => return false,
NodeTypeId::ProcessingInstruction if !is_equal_processinginstruction(this, node) => return false, NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) if !is_equal_processinginstruction(this, node) => return false,
NodeTypeId::Text | NodeTypeId::CharacterData(CharacterDataTypeId::Text) |
NodeTypeId::Comment if !is_equal_characterdata(this, node) => return false, NodeTypeId::CharacterData(CharacterDataTypeId::Comment) if !is_equal_characterdata(this, node) => return false,
// Step 4. // Step 4.
NodeTypeId::Element(..) if !is_equal_element_attrs(this, node) => return false, NodeTypeId::Element(..) if !is_equal_element_attrs(this, node) => return false,
_ => () _ => ()

View file

@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::ProcessingInstructionBinding;
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods; use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived; use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::characterdata::CharacterData; use dom::characterdata::{CharacterData, CharacterDataTypeId};
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeTypeId};
@ -21,14 +21,14 @@ pub struct ProcessingInstruction {
impl ProcessingInstructionDerived for EventTarget { impl ProcessingInstructionDerived for EventTarget {
fn is_processinginstruction(&self) -> bool { fn is_processinginstruction(&self) -> bool {
*self.type_id() == EventTargetTypeId::Node(NodeTypeId::ProcessingInstruction) *self.type_id() == EventTargetTypeId::Node(NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction))
} }
} }
impl ProcessingInstruction { impl ProcessingInstruction {
fn new_inherited(target: DOMString, data: DOMString, document: JSRef<Document>) -> ProcessingInstruction { fn new_inherited(target: DOMString, data: DOMString, document: JSRef<Document>) -> ProcessingInstruction {
ProcessingInstruction { ProcessingInstruction {
characterdata: CharacterData::new_inherited(NodeTypeId::ProcessingInstruction, data, document), characterdata: CharacterData::new_inherited(CharacterDataTypeId::ProcessingInstruction, data, document),
target: target target: target
} }
} }

View file

@ -13,7 +13,7 @@ use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, OptionalRootable, Rootable, RootedReference}; use dom::bindings::js::{JSRef, OptionalRootable, Rootable, RootedReference};
use dom::bindings::js::Temporary; use dom::bindings::js::Temporary;
use dom::characterdata::{CharacterData, CharacterDataHelpers}; use dom::characterdata::{CharacterData, CharacterDataHelpers, CharacterDataTypeId};
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId}; use dom::node::{Node, NodeHelpers, NodeTypeId};
@ -27,14 +27,14 @@ pub struct Text {
impl TextDerived for EventTarget { impl TextDerived for EventTarget {
fn is_text(&self) -> bool { fn is_text(&self) -> bool {
*self.type_id() == EventTargetTypeId::Node(NodeTypeId::Text) *self.type_id() == EventTargetTypeId::Node(NodeTypeId::CharacterData(CharacterDataTypeId::Text))
} }
} }
impl Text { impl Text {
fn new_inherited(text: DOMString, document: JSRef<Document>) -> Text { fn new_inherited(text: DOMString, document: JSRef<Document>) -> Text {
Text { Text {
characterdata: CharacterData::new_inherited(NodeTypeId::Text, text, document) characterdata: CharacterData::new_inherited(CharacterDataTypeId::Text, text, document)
} }
} }

View file

@ -14,7 +14,7 @@ use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::js::{JS, JSRef, OptionalRootable, Root, Rootable}; use dom::bindings::js::{JS, JSRef, OptionalRootable, Root, Rootable};
use dom::bindings::js::{RootedReference, Temporary}; use dom::bindings::js::{RootedReference, Temporary};
use dom::bindings::trace::RootedVec; use dom::bindings::trace::RootedVec;
use dom::characterdata::CharacterDataHelpers; use dom::characterdata::{CharacterDataHelpers, CharacterDataTypeId};
use dom::comment::Comment; use dom::comment::Comment;
use dom::document::{Document, DocumentHelpers}; use dom::document::{Document, DocumentHelpers};
use dom::document::{DocumentSource, IsHTMLDocument}; use dom::document::{DocumentSource, IsHTMLDocument};
@ -247,17 +247,17 @@ impl<'a> Serializable for JSRef<'a, Node> {
serializer.write_doctype(&doctype.name()) serializer.write_doctype(&doctype.name())
}, },
(IncludeNode, NodeTypeId::Text) => { (IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => {
let cdata = CharacterDataCast::to_ref(node).unwrap(); let cdata = CharacterDataCast::to_ref(node).unwrap();
serializer.write_text(&cdata.data()) serializer.write_text(&cdata.data())
}, },
(IncludeNode, NodeTypeId::Comment) => { (IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Comment)) => {
let cdata = CharacterDataCast::to_ref(node).unwrap(); let cdata = CharacterDataCast::to_ref(node).unwrap();
serializer.write_comment(&cdata.data()) serializer.write_comment(&cdata.data())
}, },
(IncludeNode, NodeTypeId::ProcessingInstruction) => { (IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction)) => {
let pi: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap(); let pi: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
let data = CharacterDataCast::from_ref(pi).data(); let data = CharacterDataCast::from_ref(pi).data();
serializer.write_processing_instruction(&pi.target(), &data) serializer.write_processing_instruction(&pi.target(), &data)