content/base/src/nsXHTMLContentSerializer.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial