Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Side by Side Diff: Source/core/editing/MarkupFormatter.h

Issue 1295073002: Move serializer related files in core/editing/ related files into core/editing/serializers/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-17T15:24:31 Rebase for Source/web/WebPageSerializerImpl.cpp Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/editing/MarkupAccumulator.cpp ('k') | Source/core/editing/MarkupFormatter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24 */
25
26 #ifndef MarkupFormatter_h
27 #define MarkupFormatter_h
28
29 #include "core/editing/EditingStrategy.h"
30 #include "core/editing/Serialization.h"
31 #include "wtf/HashMap.h"
32 #include "wtf/Vector.h"
33 #include "wtf/text/StringBuilder.h"
34
35 namespace blink {
36
37 class Attribute;
38 class DocumentType;
39 class Element;
40 class Node;
41
42 typedef HashMap<AtomicString, AtomicString> Namespaces;
43
44 enum EntityMask {
45 EntityAmp = 0x0001,
46 EntityLt = 0x0002,
47 EntityGt = 0x0004,
48 EntityQuot = 0x0008,
49 EntityNbsp = 0x0010,
50
51 // Non-breaking space needs to be escaped in innerHTML for compatibility rea son. See http://trac.webkit.org/changeset/32879
52 // However, we cannot do this in a XML document because it does not have the entity reference defined (See the bug 19215).
53 EntityMaskInCDATA = 0,
54 EntityMaskInPCDATA = EntityAmp | EntityLt | EntityGt,
55 EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp,
56 EntityMaskInAttributeValue = EntityAmp | EntityQuot | EntityLt | EntityGt,
57 EntityMaskInHTMLAttributeValue = EntityAmp | EntityQuot | EntityNbsp,
58 };
59
60 enum class SerializationType {
61 AsOwnerDocument,
62 ForcedXML
63 };
64
65 class MarkupFormatter final {
66 WTF_MAKE_NONCOPYABLE(MarkupFormatter);
67 STACK_ALLOCATED();
68 public:
69 static void appendAttributeValue(StringBuilder&, const String&, bool);
70 static void appendCDATASection(StringBuilder&, const String&);
71 static void appendCharactersReplacingEntities(StringBuilder&, const String&, unsigned, unsigned, EntityMask);
72 static void appendComment(StringBuilder&, const String&);
73 static void appendDocumentType(StringBuilder&, const DocumentType&);
74 static void appendNamespace(StringBuilder&, const AtomicString& prefix, cons t AtomicString& namespaceURI, Namespaces&);
75 static void appendProcessingInstruction(StringBuilder&, const String& target , const String& data);
76 static void appendXMLDeclaration(StringBuilder&, const Document&);
77
78 MarkupFormatter(EAbsoluteURLs, SerializationType = SerializationType::AsOwne rDocument);
79 ~MarkupFormatter();
80
81 void appendStartMarkup(StringBuilder&, const Node&, Namespaces*);
82 void appendEndMarkup(StringBuilder&, const Element&);
83
84 bool serializeAsHTMLDocument(const Node&) const;
85
86 void appendText(StringBuilder&, Text&);
87 void appendOpenTag(StringBuilder&, const Element&, Namespaces*);
88 void appendCloseTag(StringBuilder&, const Element&);
89 void appendAttribute(StringBuilder&, const Element&, const Attribute&, Names paces*);
90
91 bool shouldAddNamespaceElement(const Element&, Namespaces&) const;
92 bool shouldAddNamespaceAttribute(const Attribute&, const Element&) const;
93 EntityMask entityMaskForText(const Text&) const;
94 bool shouldSelfClose(const Element&) const;
95
96 private:
97 String resolveURLIfNeeded(const Element&, const String&) const;
98 void appendQuotedURLAttributeValue(StringBuilder&, const Element&, const Att ribute&);
99
100 const EAbsoluteURLs m_resolveURLsMethod;
101 SerializationType m_serializationType;
102 };
103
104 }
105
106 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/MarkupAccumulator.cpp ('k') | Source/core/editing/MarkupFormatter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698