| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights
reserved. |
| 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void MarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& node, Nam
espaces* namespaces) | 74 void MarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& node, Nam
espaces* namespaces) |
| 75 { | 75 { |
| 76 switch (node.nodeType()) { | 76 switch (node.nodeType()) { |
| 77 case Node::TEXT_NODE: | 77 case Node::TEXT_NODE: |
| 78 appendText(result, toText(node)); | 78 appendText(result, toText(node)); |
| 79 break; | 79 break; |
| 80 case Node::COMMENT_NODE: | 80 case Node::COMMENT_NODE: |
| 81 MarkupFormatter::appendComment(result, toComment(node).data()); | 81 MarkupFormatter::appendComment(result, toComment(node).data()); |
| 82 break; | 82 break; |
| 83 case Node::DOCUMENT_NODE: | 83 case Node::DOCUMENT_NODE: |
| 84 appendXMLDeclaration(result, toDocument(node)); | 84 MarkupFormatter::appendXMLDeclaration(result, toDocument(node)); |
| 85 break; | 85 break; |
| 86 case Node::DOCUMENT_FRAGMENT_NODE: | 86 case Node::DOCUMENT_FRAGMENT_NODE: |
| 87 break; | 87 break; |
| 88 case Node::DOCUMENT_TYPE_NODE: | 88 case Node::DOCUMENT_TYPE_NODE: |
| 89 appendDocumentType(result, toDocumentType(node)); | 89 MarkupFormatter::appendDocumentType(result, toDocumentType(node)); |
| 90 break; | 90 break; |
| 91 case Node::PROCESSING_INSTRUCTION_NODE: | 91 case Node::PROCESSING_INSTRUCTION_NODE: |
| 92 appendProcessingInstruction(result, toProcessingInstruction(node).target
(), toProcessingInstruction(node).data()); | 92 MarkupFormatter::appendProcessingInstruction(result, toProcessingInstruc
tion(node).target(), toProcessingInstruction(node).data()); |
| 93 break; | 93 break; |
| 94 case Node::ELEMENT_NODE: | 94 case Node::ELEMENT_NODE: |
| 95 appendElement(result, toElement(node), namespaces); | 95 appendElement(result, toElement(node), namespaces); |
| 96 break; | 96 break; |
| 97 case Node::CDATA_SECTION_NODE: | 97 case Node::CDATA_SECTION_NODE: |
| 98 appendCDATASection(result, toCDATASection(node).data()); | 98 MarkupFormatter::appendCDATASection(result, toCDATASection(node).data())
; |
| 99 break; | 99 break; |
| 100 case Node::ATTRIBUTE_NODE: | 100 case Node::ATTRIBUTE_NODE: |
| 101 ASSERT_NOT_REACHED(); | 101 ASSERT_NOT_REACHED(); |
| 102 break; | 102 break; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 static bool elementCannotHaveEndTag(const Node& node) | 106 static bool elementCannotHaveEndTag(const Node& node) |
| 107 { | 107 { |
| 108 if (!node.isHTMLElement()) | 108 if (!node.isHTMLElement()) |
| 109 return false; | 109 return false; |
| 110 | 110 |
| 111 // FIXME: ieForbidsInsertHTML may not be the right function to call here | 111 // FIXME: ieForbidsInsertHTML may not be the right function to call here |
| 112 // ieForbidsInsertHTML is used to disallow setting innerHTML/outerHTML | 112 // ieForbidsInsertHTML is used to disallow setting innerHTML/outerHTML |
| 113 // or createContextualFragment. It does not necessarily align with | 113 // or createContextualFragment. It does not necessarily align with |
| 114 // which elements should be serialized w/o end tags. | 114 // which elements should be serialized w/o end tags. |
| 115 return toHTMLElement(node).ieForbidsInsertHTML(); | 115 return toHTMLElement(node).ieForbidsInsertHTML(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void MarkupAccumulator::appendEndMarkup(StringBuilder& result, const Element& el
ement) | 118 void MarkupAccumulator::appendEndMarkup(StringBuilder& result, const Element& el
ement) |
| 119 { | 119 { |
| 120 m_formatter.appendEndMarkup(result, element); | 120 m_formatter.appendEndMarkup(result, element); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void MarkupAccumulator::concatenateMarkup(StringBuilder& result) const | 123 void MarkupAccumulator::concatenateMarkup(StringBuilder& result) const |
| 124 { | 124 { |
| 125 result.append(m_markup); | 125 result.append(m_markup); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void MarkupAccumulator::appendAttributeValue(StringBuilder& result, const String
& attribute, bool documentIsHTML) | |
| 129 { | |
| 130 m_formatter.appendAttributeValue(result, attribute, documentIsHTML); | |
| 131 } | |
| 132 | |
| 133 void MarkupAccumulator::appendCustomAttributes(StringBuilder&, const Element&, N
amespaces*) | 128 void MarkupAccumulator::appendCustomAttributes(StringBuilder&, const Element&, N
amespaces*) |
| 134 { | 129 { |
| 135 } | 130 } |
| 136 | 131 |
| 137 void MarkupAccumulator::appendNamespace(StringBuilder& result, const AtomicStrin
g& prefix, const AtomicString& namespaceURI, Namespaces& namespaces) | |
| 138 { | |
| 139 m_formatter.appendNamespace(result, prefix, namespaceURI, namespaces); | |
| 140 } | |
| 141 | |
| 142 void MarkupAccumulator::appendText(StringBuilder& result, Text& text) | 132 void MarkupAccumulator::appendText(StringBuilder& result, Text& text) |
| 143 { | 133 { |
| 144 m_formatter.appendText(result, text); | 134 m_formatter.appendText(result, text); |
| 145 } | 135 } |
| 146 | 136 |
| 147 void MarkupAccumulator::appendXMLDeclaration(StringBuilder& result, const Docume
nt& document) | |
| 148 { | |
| 149 m_formatter.appendXMLDeclaration(result, document); | |
| 150 } | |
| 151 | |
| 152 void MarkupAccumulator::appendDocumentType(StringBuilder& result, const Document
Type& n) | |
| 153 { | |
| 154 m_formatter.appendDocumentType(result, n); | |
| 155 } | |
| 156 | |
| 157 void MarkupAccumulator::appendProcessingInstruction(StringBuilder& result, const
String& target, const String& data) | |
| 158 { | |
| 159 m_formatter.appendProcessingInstruction(result, target, data); | |
| 160 } | |
| 161 | |
| 162 bool MarkupAccumulator::shouldIgnoreAttribute(const Attribute& attribute) | 137 bool MarkupAccumulator::shouldIgnoreAttribute(const Attribute& attribute) |
| 163 { | 138 { |
| 164 return false; | 139 return false; |
| 165 } | 140 } |
| 166 | 141 |
| 167 void MarkupAccumulator::appendElement(StringBuilder& result, Element& element, N
amespaces* namespaces) | 142 void MarkupAccumulator::appendElement(StringBuilder& result, Element& element, N
amespaces* namespaces) |
| 168 { | 143 { |
| 169 appendOpenTag(result, element, namespaces); | 144 appendOpenTag(result, element, namespaces); |
| 170 | 145 |
| 171 AttributeCollection attributes = element.attributes(); | 146 AttributeCollection attributes = element.attributes(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 188 void MarkupAccumulator::appendCloseTag(StringBuilder& result, const Element& ele
ment) | 163 void MarkupAccumulator::appendCloseTag(StringBuilder& result, const Element& ele
ment) |
| 189 { | 164 { |
| 190 m_formatter.appendCloseTag(result, element); | 165 m_formatter.appendCloseTag(result, element); |
| 191 } | 166 } |
| 192 | 167 |
| 193 void MarkupAccumulator::appendAttribute(StringBuilder& result, const Element& el
ement, const Attribute& attribute, Namespaces* namespaces) | 168 void MarkupAccumulator::appendAttribute(StringBuilder& result, const Element& el
ement, const Attribute& attribute, Namespaces* namespaces) |
| 194 { | 169 { |
| 195 m_formatter.appendAttribute(result, element, attribute, namespaces); | 170 m_formatter.appendAttribute(result, element, attribute, namespaces); |
| 196 } | 171 } |
| 197 | 172 |
| 198 void MarkupAccumulator::appendCDATASection(StringBuilder& result, const String&
section) | |
| 199 { | |
| 200 m_formatter.appendCDATASection(result, section); | |
| 201 } | |
| 202 | |
| 203 bool MarkupAccumulator::shouldAddNamespaceElement(const Element& element, Namesp
aces& namespaces) const | |
| 204 { | |
| 205 return m_formatter.shouldAddNamespaceElement(element, namespaces); | |
| 206 } | |
| 207 | |
| 208 bool MarkupAccumulator::shouldAddNamespaceAttribute(const Attribute& attribute,
const Element& element) const | |
| 209 { | |
| 210 return m_formatter.shouldAddNamespaceAttribute(attribute, element); | |
| 211 } | |
| 212 | |
| 213 EntityMask MarkupAccumulator::entityMaskForText(const Text& text) const | 173 EntityMask MarkupAccumulator::entityMaskForText(const Text& text) const |
| 214 { | 174 { |
| 215 return m_formatter.entityMaskForText(text); | 175 return m_formatter.entityMaskForText(text); |
| 216 } | 176 } |
| 217 | 177 |
| 218 bool MarkupAccumulator::shouldSelfClose(const Element& element) const | |
| 219 { | |
| 220 return m_formatter.shouldSelfClose(element); | |
| 221 } | |
| 222 | |
| 223 bool MarkupAccumulator::serializeAsHTMLDocument(const Node& node) const | 178 bool MarkupAccumulator::serializeAsHTMLDocument(const Node& node) const |
| 224 { | 179 { |
| 225 return m_formatter.serializeAsHTMLDocument(node); | 180 return m_formatter.serializeAsHTMLDocument(node); |
| 226 } | 181 } |
| 227 | 182 |
| 228 template<typename Strategy> | 183 template<typename Strategy> |
| 229 static void serializeNodesWithNamespaces(MarkupAccumulator& accumulator, Node& t
argetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces) | 184 static void serializeNodesWithNamespaces(MarkupAccumulator& accumulator, Node& t
argetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces) |
| 230 { | 185 { |
| 231 Namespaces namespaceHash; | 186 Namespaces namespaceHash; |
| 232 if (namespaces) | 187 if (namespaces) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 256 namespaces = &namespaceHash; | 211 namespaces = &namespaceHash; |
| 257 } | 212 } |
| 258 | 213 |
| 259 serializeNodesWithNamespaces<Strategy>(accumulator, targetNode, childrenOnly
, namespaces); | 214 serializeNodesWithNamespaces<Strategy>(accumulator, targetNode, childrenOnly
, namespaces); |
| 260 return accumulator.toString(); | 215 return accumulator.toString(); |
| 261 } | 216 } |
| 262 | 217 |
| 263 template String serializeNodes<EditingStrategy>(MarkupAccumulator&, Node&, EChil
drenOnly); | 218 template String serializeNodes<EditingStrategy>(MarkupAccumulator&, Node&, EChil
drenOnly); |
| 264 | 219 |
| 265 } | 220 } |
| OLD | NEW |