1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/xml/document/src/nsXMLContentSink.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,194 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsXMLContentSink_h__ 1.10 +#define nsXMLContentSink_h__ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsContentSink.h" 1.14 +#include "nsIXMLContentSink.h" 1.15 +#include "nsIExpatSink.h" 1.16 +#include "nsIDocumentTransformer.h" 1.17 +#include "nsTArray.h" 1.18 +#include "nsCOMPtr.h" 1.19 +#include "nsCRT.h" 1.20 +#include "nsCycleCollectionParticipant.h" 1.21 +#include "nsIDTD.h" 1.22 +#include "mozilla/dom/FromParser.h" 1.23 + 1.24 +class nsIDocument; 1.25 +class nsIURI; 1.26 +class nsIContent; 1.27 +class nsINodeInfo; 1.28 +class nsIParser; 1.29 +class nsViewManager; 1.30 + 1.31 +typedef enum { 1.32 + eXMLContentSinkState_InProlog, 1.33 + eXMLContentSinkState_InDocumentElement, 1.34 + eXMLContentSinkState_InEpilog 1.35 +} XMLContentSinkState; 1.36 + 1.37 +struct StackNode { 1.38 + nsCOMPtr<nsIContent> mContent; 1.39 + uint32_t mNumFlushed; 1.40 +}; 1.41 + 1.42 +class nsXMLContentSink : public nsContentSink, 1.43 + public nsIXMLContentSink, 1.44 + public nsITransformObserver, 1.45 + public nsIExpatSink 1.46 +{ 1.47 +public: 1.48 + nsXMLContentSink(); 1.49 + virtual ~nsXMLContentSink(); 1.50 + 1.51 + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW 1.52 + 1.53 + nsresult Init(nsIDocument* aDoc, 1.54 + nsIURI* aURL, 1.55 + nsISupports* aContainer, 1.56 + nsIChannel* aChannel); 1.57 + 1.58 + // nsISupports 1.59 + NS_DECL_ISUPPORTS_INHERITED 1.60 + 1.61 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink, 1.62 + nsContentSink) 1.63 + 1.64 + NS_DECL_NSIEXPATSINK 1.65 + 1.66 + // nsIContentSink 1.67 + NS_IMETHOD WillParse(void) MOZ_OVERRIDE; 1.68 + NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE; 1.69 + NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE; 1.70 + NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE; 1.71 + NS_IMETHOD WillResume(void) MOZ_OVERRIDE; 1.72 + NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE; 1.73 + virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE; 1.74 + NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE; 1.75 + virtual nsISupports *GetTarget() MOZ_OVERRIDE; 1.76 + virtual bool IsScriptExecuting() MOZ_OVERRIDE; 1.77 + virtual void ContinueInterruptedParsingAsync() MOZ_OVERRIDE; 1.78 + 1.79 + // nsITransformObserver 1.80 + NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) MOZ_OVERRIDE; 1.81 + NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) MOZ_OVERRIDE; 1.82 + 1.83 + // nsICSSLoaderObserver 1.84 + NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, bool aWasAlternate, 1.85 + nsresult aStatus) MOZ_OVERRIDE; 1.86 + static bool ParsePIData(const nsString &aData, nsString &aHref, 1.87 + nsString &aTitle, nsString &aMedia, 1.88 + bool &aIsAlternate); 1.89 + 1.90 +protected: 1.91 + 1.92 + nsIParser* GetParser(); 1.93 + 1.94 + void ContinueInterruptedParsingIfEnabled(); 1.95 + 1.96 + // Start layout. If aIgnorePendingSheets is true, this will happen even if 1.97 + // we still have stylesheet loads pending. Otherwise, we'll wait until the 1.98 + // stylesheets are all done loading. 1.99 + virtual void MaybeStartLayout(bool aIgnorePendingSheets); 1.100 + 1.101 + virtual nsresult AddAttributes(const char16_t** aNode, nsIContent* aContent); 1.102 + nsresult AddText(const char16_t* aString, int32_t aLength); 1.103 + 1.104 + virtual bool OnOpenContainer(const char16_t **aAtts, 1.105 + uint32_t aAttsCount, 1.106 + int32_t aNameSpaceID, 1.107 + nsIAtom* aTagName, 1.108 + uint32_t aLineNumber) { return true; } 1.109 + // Set the given content as the root element for the created document 1.110 + // don't set if root element was already set. 1.111 + // return TRUE if this call set the root element 1.112 + virtual bool SetDocElement(int32_t aNameSpaceID, 1.113 + nsIAtom *aTagName, 1.114 + nsIContent *aContent); 1.115 + virtual bool NotifyForDocElement() { return true; } 1.116 + virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount, 1.117 + nsINodeInfo* aNodeInfo, uint32_t aLineNumber, 1.118 + nsIContent** aResult, bool* aAppendContent, 1.119 + mozilla::dom::FromParser aFromParser); 1.120 + 1.121 + // aParent is allowed to be null here if this is the root content 1.122 + // being closed 1.123 + virtual nsresult CloseElement(nsIContent* aContent); 1.124 + 1.125 + virtual nsresult FlushText(bool aReleaseTextNode = true); 1.126 + 1.127 + nsresult AddContentAsLeaf(nsIContent *aContent); 1.128 + 1.129 + nsIContent* GetCurrentContent(); 1.130 + StackNode* GetCurrentStackNode(); 1.131 + nsresult PushContent(nsIContent *aContent); 1.132 + void PopContent(); 1.133 + bool HaveNotifiedForCurrentContent() const; 1.134 + 1.135 + nsresult FlushTags() MOZ_OVERRIDE; 1.136 + 1.137 + void UpdateChildCounts() MOZ_OVERRIDE; 1.138 + 1.139 + void DidAddContent() 1.140 + { 1.141 + if (IsTimeToNotify()) { 1.142 + FlushTags(); 1.143 + } 1.144 + } 1.145 + 1.146 + // nsContentSink override 1.147 + virtual nsresult ProcessStyleLink(nsIContent* aElement, 1.148 + const nsSubstring& aHref, 1.149 + bool aAlternate, 1.150 + const nsSubstring& aTitle, 1.151 + const nsSubstring& aType, 1.152 + const nsSubstring& aMedia) MOZ_OVERRIDE; 1.153 + 1.154 + nsresult LoadXSLStyleSheet(nsIURI* aUrl); 1.155 + 1.156 + bool CanStillPrettyPrint(); 1.157 + 1.158 + nsresult MaybePrettyPrint(); 1.159 + 1.160 + bool IsMonolithicContainer(nsINodeInfo* aNodeInfo); 1.161 + 1.162 + nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts, 1.163 + uint32_t aAttsCount, int32_t aIndex, 1.164 + uint32_t aLineNumber, 1.165 + bool aInterruptable); 1.166 + nsresult HandleEndElement(const char16_t *aName, bool aInterruptable); 1.167 + nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength, 1.168 + bool aInterruptable); 1.169 + 1.170 + nsCOMPtr<nsIContent> mDocElement; 1.171 + nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed> 1.172 + char16_t* mText; 1.173 + 1.174 + XMLContentSinkState mState; 1.175 + 1.176 + int32_t mTextLength; 1.177 + int32_t mTextSize; 1.178 + 1.179 + int32_t mNotifyLevel; 1.180 + nsCOMPtr<nsIContent> mLastTextNode; 1.181 + int32_t mLastTextNodeSize; 1.182 + 1.183 + uint8_t mConstrainSize : 1; 1.184 + uint8_t mPrettyPrintXML : 1; 1.185 + uint8_t mPrettyPrintHasSpecialRoot : 1; 1.186 + uint8_t mPrettyPrintHasFactoredElements : 1; 1.187 + uint8_t mPrettyPrinting : 1; // True if we called PrettyPrint() and it 1.188 + // decided we should in fact prettyprint. 1.189 + // True to call prevent script execution in the fragment mode. 1.190 + uint8_t mPreventScriptExecution : 1; 1.191 + 1.192 + nsTArray<StackNode> mContentStack; 1.193 + 1.194 + nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor; 1.195 +}; 1.196 + 1.197 +#endif // nsXMLContentSink_h__