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