michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * nsIContentSerializer implementation that can be used with an michael@0: * nsIDocumentEncoder to convert an XHTML (not HTML!) DOM to an XHTML michael@0: * string that could be parsed into more or less the original DOM. michael@0: */ michael@0: michael@0: #ifndef nsXHTMLContentSerializer_h__ michael@0: #define nsXHTMLContentSerializer_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsXMLContentSerializer.h" michael@0: #include "nsIEntityConverter.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: michael@0: class nsIContent; michael@0: class nsIAtom; michael@0: michael@0: class nsXHTMLContentSerializer : public nsXMLContentSerializer { michael@0: public: michael@0: nsXHTMLContentSerializer(); michael@0: virtual ~nsXHTMLContentSerializer(); michael@0: michael@0: NS_IMETHOD Init(uint32_t flags, uint32_t aWrapColumn, michael@0: const char* aCharSet, bool aIsCopying, michael@0: bool aRewriteEncodingDeclaration) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD AppendText(nsIContent* aText, michael@0: int32_t aStartOffset, michael@0: int32_t aEndOffset, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: michael@0: michael@0: virtual bool CheckElementStart(nsIContent * aContent, michael@0: bool & aForceFormat, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: virtual void AppendEndOfElementStart(nsIContent *aOriginalElement, michael@0: nsIAtom * aName, michael@0: int32_t aNamespaceID, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: virtual void AfterElementStart(nsIContent * aContent, michael@0: nsIContent *aOriginalElement, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: virtual bool CheckElementEnd(nsIContent * aContent, michael@0: bool & aForceFormat, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: virtual void AfterElementEnd(nsIContent * aContent, michael@0: nsAString& aStr) MOZ_OVERRIDE; michael@0: michael@0: virtual bool LineBreakBeforeOpen(int32_t aNamespaceID, nsIAtom* aName) MOZ_OVERRIDE; michael@0: virtual bool LineBreakAfterOpen(int32_t aNamespaceID, nsIAtom* aName) MOZ_OVERRIDE; michael@0: virtual bool LineBreakBeforeClose(int32_t aNamespaceID, nsIAtom* aName) MOZ_OVERRIDE; michael@0: virtual bool LineBreakAfterClose(int32_t aNamespaceID, nsIAtom* aName) MOZ_OVERRIDE; michael@0: michael@0: bool HasLongLines(const nsString& text, int32_t& aLastNewlineOffset); michael@0: michael@0: // functions to check if we enter in or leave from a preformated content michael@0: virtual void MaybeEnterInPreContent(nsIContent* aNode) MOZ_OVERRIDE; michael@0: virtual void MaybeLeaveFromPreContent(nsIContent* aNode) MOZ_OVERRIDE; michael@0: michael@0: virtual void SerializeAttributes(nsIContent* aContent, michael@0: nsIContent *aOriginalElement, michael@0: nsAString& aTagPrefix, michael@0: const nsAString& aTagNamespaceURI, michael@0: nsIAtom* aTagName, michael@0: nsAString& aStr, michael@0: uint32_t aSkipAttr, michael@0: bool aAddNSAttr) MOZ_OVERRIDE; michael@0: michael@0: bool IsFirstChildOfOL(nsIContent* aElement); michael@0: michael@0: void SerializeLIValueAttribute(nsIContent* aElement, michael@0: nsAString& aStr); michael@0: bool IsShorthandAttr(const nsIAtom* aAttrName, michael@0: const nsIAtom* aElementName); michael@0: virtual void AppendAndTranslateEntities(const nsAString& aStr, michael@0: nsAString& aOutputStr) MOZ_OVERRIDE; michael@0: nsresult EscapeURI(nsIContent* aContent, michael@0: const nsAString& aURI, michael@0: nsAString& aEscapedURI); michael@0: michael@0: nsCOMPtr mEntityConverter; michael@0: michael@0: /* michael@0: * isHTMLParser should be set to true by the HTML parser which inherits from michael@0: * this class. It avoids to redefine methods just for few changes. michael@0: */ michael@0: bool mIsHTMLSerializer; michael@0: michael@0: bool mDoHeader; michael@0: bool mIsCopying; // Set to true only while copying michael@0: michael@0: /* michael@0: * mDisableEntityEncoding is higher than 0 while the serializer is serializing michael@0: * the content of a element whose content is considerd CDATA by the michael@0: * serializer (such elements are 'script', 'style', 'noscript' and michael@0: * possibly others in XHTML) This doesn't have anything to do with if the michael@0: * element is defined as CDATA in the DTD, it simply means we'll michael@0: * output the content of the element without doing any entity encoding michael@0: * what so ever. michael@0: */ michael@0: int32_t mDisableEntityEncoding; michael@0: michael@0: // This is to ensure that we only do meta tag fixups when dealing with michael@0: // whole documents. michael@0: bool mRewriteEncodingDeclaration; michael@0: michael@0: // To keep track of First LI child of OL in selected range michael@0: bool mIsFirstChildOfOL; michael@0: michael@0: // To keep track of startvalue of OL and first list item for nested lists michael@0: struct olState { michael@0: olState(int32_t aStart, bool aIsFirst) michael@0: : startVal(aStart), michael@0: isFirstListItem(aIsFirst) michael@0: { michael@0: } michael@0: michael@0: olState(const olState & aOlState) michael@0: { michael@0: startVal = aOlState.startVal; michael@0: isFirstListItem = aOlState.isFirstListItem; michael@0: } michael@0: michael@0: // the value of the start attribute in the OL michael@0: int32_t startVal; michael@0: michael@0: // is true only before the serialization of the first li of an ol michael@0: // should be false for other li in the list michael@0: bool isFirstListItem; michael@0: }; michael@0: michael@0: // Stack to store one olState struct per
    . michael@0: nsAutoTArray mOLStateStack; michael@0: michael@0: bool HasNoChildren(nsIContent* aContent); michael@0: }; michael@0: michael@0: nsresult michael@0: NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer); michael@0: michael@0: #endif