| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef MarkupAccumulator_h | 26 #ifndef MarkupFormatter_h |
| 27 #define MarkupAccumulator_h | 27 #define MarkupFormatter_h |
| 28 | 28 |
| 29 #include "core/editing/EditingStrategy.h" | 29 #include "core/editing/EditingStrategy.h" |
| 30 #include "core/editing/markup.h" | 30 #include "core/editing/markup.h" |
| 31 #include "wtf/HashMap.h" | 31 #include "wtf/HashMap.h" |
| 32 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
| 33 #include "wtf/text/StringBuilder.h" | 33 #include "wtf/text/StringBuilder.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 class Attribute; | 37 class Attribute; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp, | 55 EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp, |
| 56 EntityMaskInAttributeValue = EntityAmp | EntityQuot | EntityLt | EntityGt, | 56 EntityMaskInAttributeValue = EntityAmp | EntityQuot | EntityLt | EntityGt, |
| 57 EntityMaskInHTMLAttributeValue = EntityAmp | EntityQuot | EntityNbsp, | 57 EntityMaskInHTMLAttributeValue = EntityAmp | EntityQuot | EntityNbsp, |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 enum class SerializationType { | 60 enum class SerializationType { |
| 61 AsOwnerDocument, | 61 AsOwnerDocument, |
| 62 ForcedXML | 62 ForcedXML |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class MarkupAccumulator { | 65 class MarkupFormatter final { |
| 66 WTF_MAKE_NONCOPYABLE(MarkupAccumulator); | 66 WTF_MAKE_NONCOPYABLE(MarkupFormatter); |
| 67 STACK_ALLOCATED(); | 67 STACK_ALLOCATED(); |
| 68 public: | 68 public: |
| 69 static void appendComment(StringBuilder&, const String&); | 69 static void appendComment(StringBuilder&, const String&); |
| 70 static void appendCharactersReplacingEntities(StringBuilder&, const String&,
unsigned, unsigned, EntityMask); | 70 static void appendCharactersReplacingEntities(StringBuilder&, const String&,
unsigned, unsigned, EntityMask); |
| 71 static size_t totalLength(const Vector<String>&); | 71 static size_t totalLength(const Vector<String>&); |
| 72 | 72 |
| 73 MarkupAccumulator(EAbsoluteURLs, SerializationType = SerializationType::AsOw
nerDocument); | 73 MarkupFormatter(EAbsoluteURLs, SerializationType = SerializationType::AsOwne
rDocument); |
| 74 virtual ~MarkupAccumulator(); | 74 ~MarkupFormatter(); |
| 75 | 75 |
| 76 void appendString(const String&); | |
| 77 virtual void appendStartTag(Node&, Namespaces* = nullptr); | |
| 78 virtual void appendEndTag(const Element&); | |
| 79 void appendStartMarkup(StringBuilder&, Node&, Namespaces*); | |
| 80 void appendEndMarkup(StringBuilder&, const Element&); | 76 void appendEndMarkup(StringBuilder&, const Element&); |
| 81 | 77 |
| 82 size_t length() const { return m_markup.length(); } | |
| 83 void concatenateMarkup(StringBuilder&) const; | |
| 84 | |
| 85 bool serializeAsHTMLDocument(const Node&) const; | 78 bool serializeAsHTMLDocument(const Node&) const; |
| 86 String toString() { return m_markup.toString(); } | |
| 87 | 79 |
| 88 void appendAttributeValue(StringBuilder&, const String&, bool); | 80 void appendAttributeValue(StringBuilder&, const String&, bool); |
| 89 virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespac
es*); | |
| 90 | 81 |
| 91 void appendNamespace(StringBuilder&, const AtomicString& prefix, const Atomi
cString& namespaceURI, Namespaces&); | 82 void appendNamespace(StringBuilder&, const AtomicString& prefix, const Atomi
cString& namespaceURI, Namespaces&); |
| 92 virtual void appendText(StringBuilder&, Text&); | 83 void appendText(StringBuilder&, Text&); |
| 93 void appendXMLDeclaration(StringBuilder&, const Document&); | 84 void appendXMLDeclaration(StringBuilder&, const Document&); |
| 94 void appendDocumentType(StringBuilder&, const DocumentType&); | 85 void appendDocumentType(StringBuilder&, const DocumentType&); |
| 95 void appendProcessingInstruction(StringBuilder&, const String& target, const
String& data); | 86 void appendProcessingInstruction(StringBuilder&, const String& target, const
String& data); |
| 96 virtual bool shouldIgnoreAttribute(const Attribute&); | |
| 97 virtual void appendElement(StringBuilder&, Element&, Namespaces*); | |
| 98 void appendOpenTag(StringBuilder&, const Element&, Namespaces*); | 87 void appendOpenTag(StringBuilder&, const Element&, Namespaces*); |
| 99 void appendCloseTag(StringBuilder&, const Element&); | 88 void appendCloseTag(StringBuilder&, const Element&); |
| 100 void appendAttribute(StringBuilder&, const Element&, const Attribute&, Names
paces*); | 89 void appendAttribute(StringBuilder&, const Element&, const Attribute&, Names
paces*); |
| 101 void appendCDATASection(StringBuilder&, const String&); | 90 void appendCDATASection(StringBuilder&, const String&); |
| 102 | 91 |
| 103 bool shouldAddNamespaceElement(const Element&, Namespaces&) const; | 92 bool shouldAddNamespaceElement(const Element&, Namespaces&) const; |
| 104 bool shouldAddNamespaceAttribute(const Attribute&, const Element&) const; | 93 bool shouldAddNamespaceAttribute(const Attribute&, const Element&) const; |
| 105 EntityMask entityMaskForText(const Text&) const; | 94 EntityMask entityMaskForText(const Text&) const; |
| 106 bool shouldSelfClose(const Element&) const; | 95 bool shouldSelfClose(const Element&) const; |
| 107 | 96 |
| 108 private: | 97 private: |
| 109 String resolveURLIfNeeded(const Element&, const String&) const; | 98 String resolveURLIfNeeded(const Element&, const String&) const; |
| 110 void appendQuotedURLAttributeValue(StringBuilder&, const Element&, const Att
ribute&); | 99 void appendQuotedURLAttributeValue(StringBuilder&, const Element&, const Att
ribute&); |
| 111 | 100 |
| 112 StringBuilder m_markup; | |
| 113 const EAbsoluteURLs m_resolveURLsMethod; | 101 const EAbsoluteURLs m_resolveURLsMethod; |
| 114 SerializationType m_serializationType; | 102 SerializationType m_serializationType; |
| 115 }; | 103 }; |
| 116 | 104 |
| 117 template<typename Strategy> | |
| 118 String serializeNodes(MarkupAccumulator&, Node&, EChildrenOnly); | |
| 119 | |
| 120 extern template String serializeNodes<EditingStrategy>(MarkupAccumulator&, Node&
, EChildrenOnly); | |
| 121 | |
| 122 } | 105 } |
| 123 | 106 |
| 124 #endif | 107 #endif |
| OLD | NEW |