michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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: #ifndef nsXULContentSink_h__ michael@0: #define nsXULContentSink_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIExpatSink.h" michael@0: #include "nsIXMLContentSink.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsNodeInfoManager.h" michael@0: #include "nsWeakPtr.h" michael@0: #include "nsXULElement.h" michael@0: #include "nsIDTD.h" michael@0: michael@0: class nsIDocument; michael@0: class nsIScriptSecurityManager; michael@0: class nsAttrName; michael@0: class nsXULPrototypeDocument; michael@0: class nsXULPrototypeElement; michael@0: class nsXULPrototypeNode; michael@0: michael@0: class XULContentSinkImpl : public nsIXMLContentSink, michael@0: public nsIExpatSink michael@0: { michael@0: public: michael@0: XULContentSinkImpl(); michael@0: virtual ~XULContentSinkImpl(); michael@0: michael@0: // nsISupports michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_NSIEXPATSINK michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl, nsIXMLContentSink) michael@0: michael@0: // nsIContentSink michael@0: NS_IMETHOD WillParse(void) MOZ_OVERRIDE { return NS_OK; } michael@0: NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE; michael@0: NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE; michael@0: NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE; michael@0: NS_IMETHOD WillResume(void) MOZ_OVERRIDE; michael@0: NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE; michael@0: virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE { } michael@0: NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE; michael@0: virtual nsISupports *GetTarget() MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Initialize the content sink, giving it an nsIDocument object michael@0: * with which to communicate with the outside world, and an michael@0: * nsXULPrototypeDocument to build. michael@0: */ michael@0: nsresult Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype); michael@0: michael@0: protected: michael@0: // pseudo-constants michael@0: char16_t* mText; michael@0: int32_t mTextLength; michael@0: int32_t mTextSize; michael@0: bool mConstrainSize; michael@0: michael@0: nsresult AddAttributes(const char16_t** aAttributes, michael@0: const uint32_t aAttrLen, michael@0: nsXULPrototypeElement* aElement); michael@0: michael@0: nsresult OpenRoot(const char16_t** aAttributes, michael@0: const uint32_t aAttrLen, michael@0: nsINodeInfo *aNodeInfo); michael@0: michael@0: nsresult OpenTag(const char16_t** aAttributes, michael@0: const uint32_t aAttrLen, michael@0: const uint32_t aLineNumber, michael@0: nsINodeInfo *aNodeInfo); michael@0: michael@0: // If OpenScript returns NS_OK and after it returns our state is eInScript, michael@0: // that means that we created a prototype script and stuck it on michael@0: // mContextStack. If NS_OK is returned but the state is still michael@0: // eInDocumentElement then we didn't create a prototype script (e.g. the michael@0: // script had an unknown type), and the caller should create a prototype michael@0: // element. michael@0: nsresult OpenScript(const char16_t** aAttributes, michael@0: const uint32_t aLineNumber); michael@0: michael@0: static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength); michael@0: michael@0: // Text management michael@0: nsresult FlushText(bool aCreateTextNode = true); michael@0: nsresult AddText(const char16_t* aText, int32_t aLength); michael@0: michael@0: michael@0: nsRefPtr mNodeInfoManager; michael@0: michael@0: nsresult NormalizeAttributeString(const char16_t *aExpatName, michael@0: nsAttrName &aName); michael@0: nsresult CreateElement(nsINodeInfo *aNodeInfo, michael@0: nsXULPrototypeElement** aResult); michael@0: michael@0: michael@0: public: michael@0: enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog }; michael@0: protected: michael@0: michael@0: State mState; michael@0: michael@0: // content stack management michael@0: class ContextStack { michael@0: protected: michael@0: struct Entry { michael@0: nsRefPtr mNode; michael@0: // a LOT of nodes have children; preallocate for 8 michael@0: nsPrototypeArray mChildren; michael@0: State mState; michael@0: Entry* mNext; michael@0: Entry() : mChildren(8) {} michael@0: }; michael@0: michael@0: Entry* mTop; michael@0: int32_t mDepth; michael@0: michael@0: public: michael@0: ContextStack(); michael@0: ~ContextStack(); michael@0: michael@0: int32_t Depth() { return mDepth; } michael@0: michael@0: nsresult Push(nsXULPrototypeNode* aNode, State aState); michael@0: nsresult Pop(State* aState); michael@0: michael@0: nsresult GetTopNode(nsRefPtr& aNode); michael@0: nsresult GetTopChildren(nsPrototypeArray** aChildren); michael@0: michael@0: void Clear(); michael@0: michael@0: void Traverse(nsCycleCollectionTraversalCallback& aCallback); michael@0: }; michael@0: michael@0: friend class ContextStack; michael@0: ContextStack mContextStack; michael@0: michael@0: nsWeakPtr mDocument; // [OWNER] michael@0: nsCOMPtr mDocumentURL; // [OWNER] michael@0: michael@0: nsRefPtr mPrototype; // [OWNER] michael@0: michael@0: // We use regular pointer b/c of funky exports on nsIParser: michael@0: nsParserBase* mParser; // [OWNER] michael@0: nsCOMPtr mSecMan; michael@0: }; michael@0: michael@0: #endif /* nsXULContentSink_h__ */