/src/mozilla-central/dom/base/nsXHTMLContentSerializer.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* |
8 | | * nsIContentSerializer implementation that can be used with an |
9 | | * nsIDocumentEncoder to convert an XHTML (not HTML!) DOM to an XHTML |
10 | | * string that could be parsed into more or less the original DOM. |
11 | | */ |
12 | | |
13 | | #ifndef nsXHTMLContentSerializer_h__ |
14 | | #define nsXHTMLContentSerializer_h__ |
15 | | |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "nsXMLContentSerializer.h" |
18 | | #include "nsString.h" |
19 | | #include "nsTArray.h" |
20 | | |
21 | | class nsIContent; |
22 | | class nsAtom; |
23 | | |
24 | | namespace mozilla { |
25 | | class Encoding; |
26 | | } |
27 | | |
28 | | class nsXHTMLContentSerializer : public nsXMLContentSerializer { |
29 | | public: |
30 | | nsXHTMLContentSerializer(); |
31 | | virtual ~nsXHTMLContentSerializer(); |
32 | | |
33 | | NS_IMETHOD Init(uint32_t flags, |
34 | | uint32_t aWrapColumn, |
35 | | const mozilla::Encoding* aEncoding, |
36 | | bool aIsCopying, |
37 | | bool aRewriteEncodingDeclaration, |
38 | | bool* aNeedsPreformatScanning) override; |
39 | | |
40 | | NS_IMETHOD AppendText(nsIContent* aText, |
41 | | int32_t aStartOffset, |
42 | | int32_t aEndOffset, |
43 | | nsAString& aStr) override; |
44 | | |
45 | | NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument, |
46 | | nsAString& aStr) override; |
47 | | |
48 | | protected: |
49 | | |
50 | | |
51 | | virtual bool CheckElementStart(mozilla::dom::Element* aElement, |
52 | | bool& aForceFormat, |
53 | | nsAString& aStr, |
54 | | nsresult& aResult) override; |
55 | | |
56 | | MOZ_MUST_USE |
57 | | virtual bool AfterElementStart(nsIContent* aContent, |
58 | | nsIContent* aOriginalElement, |
59 | | nsAString& aStr) override; |
60 | | |
61 | | virtual bool CheckElementEnd(mozilla::dom::Element* aContent, |
62 | | bool& aForceFormat, |
63 | | nsAString& aStr) override; |
64 | | |
65 | | virtual void AfterElementEnd(nsIContent * aContent, |
66 | | nsAString& aStr) override; |
67 | | |
68 | | virtual bool LineBreakBeforeOpen(int32_t aNamespaceID, nsAtom* aName) override; |
69 | | virtual bool LineBreakAfterOpen(int32_t aNamespaceID, nsAtom* aName) override; |
70 | | virtual bool LineBreakBeforeClose(int32_t aNamespaceID, nsAtom* aName) override; |
71 | | virtual bool LineBreakAfterClose(int32_t aNamespaceID, nsAtom* aName) override; |
72 | | |
73 | | bool HasLongLines(const nsString& text, int32_t& aLastNewlineOffset); |
74 | | |
75 | | // functions to check if we enter in or leave from a preformated content |
76 | | virtual void MaybeEnterInPreContent(nsIContent* aNode) override; |
77 | | virtual void MaybeLeaveFromPreContent(nsIContent* aNode) override; |
78 | | |
79 | | MOZ_MUST_USE |
80 | | virtual bool SerializeAttributes(mozilla::dom::Element* aContent, |
81 | | mozilla::dom::Element* aOriginalElement, |
82 | | nsAString& aTagPrefix, |
83 | | const nsAString& aTagNamespaceURI, |
84 | | nsAtom* aTagName, |
85 | | nsAString& aStr, |
86 | | uint32_t aSkipAttr, |
87 | | bool aAddNSAttr) override; |
88 | | |
89 | | bool IsFirstChildOfOL(nsIContent* aElement); |
90 | | |
91 | | MOZ_MUST_USE |
92 | | bool SerializeLIValueAttribute(nsIContent* aElement, |
93 | | nsAString& aStr); |
94 | | bool IsShorthandAttr(const nsAtom* aAttrName, |
95 | | const nsAtom* aElementName); |
96 | | |
97 | | MOZ_MUST_USE |
98 | | virtual bool AppendAndTranslateEntities(const nsAString& aStr, |
99 | | nsAString& aOutputStr) override; |
100 | | |
101 | | private: |
102 | | bool IsElementPreformatted(nsIContent* aNode); |
103 | | |
104 | | protected: |
105 | | |
106 | | /* |
107 | | * isHTMLParser should be set to true by the HTML parser which inherits from |
108 | | * this class. It avoids to redefine methods just for few changes. |
109 | | */ |
110 | | bool mIsHTMLSerializer; |
111 | | |
112 | | bool mIsCopying; // Set to true only while copying |
113 | | |
114 | | /* |
115 | | * mDisableEntityEncoding is higher than 0 while the serializer is serializing |
116 | | * the content of a element whose content is considerd CDATA by the |
117 | | * serializer (such elements are 'script', 'style', 'noscript' and |
118 | | * possibly others in XHTML) This doesn't have anything to do with if the |
119 | | * element is defined as CDATA in the DTD, it simply means we'll |
120 | | * output the content of the element without doing any entity encoding |
121 | | * what so ever. |
122 | | */ |
123 | | int32_t mDisableEntityEncoding; |
124 | | |
125 | | // This is to ensure that we only do meta tag fixups when dealing with |
126 | | // whole documents. |
127 | | bool mRewriteEncodingDeclaration; |
128 | | |
129 | | // To keep track of First LI child of OL in selected range |
130 | | bool mIsFirstChildOfOL; |
131 | | |
132 | | // To keep track of startvalue of OL and first list item for nested lists |
133 | | struct olState { |
134 | | olState(int32_t aStart, bool aIsFirst) |
135 | | : startVal(aStart), |
136 | | isFirstListItem(aIsFirst) |
137 | 0 | { |
138 | 0 | } |
139 | | |
140 | | olState(const olState & aOlState) |
141 | 0 | { |
142 | 0 | startVal = aOlState.startVal; |
143 | 0 | isFirstListItem = aOlState.isFirstListItem; |
144 | 0 | } |
145 | | |
146 | | // the value of the start attribute in the OL |
147 | | int32_t startVal; |
148 | | |
149 | | // is true only before the serialization of the first li of an ol |
150 | | // should be false for other li in the list |
151 | | bool isFirstListItem; |
152 | | }; |
153 | | |
154 | | // Stack to store one olState struct per <OL>. |
155 | | AutoTArray<olState, 8> mOLStateStack; |
156 | | |
157 | | bool HasNoChildren(nsIContent* aContent); |
158 | | }; |
159 | | |
160 | | nsresult |
161 | | NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer); |
162 | | |
163 | | #endif |