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: #ifndef nsXBLContentSink_h__ michael@0: #define nsXBLContentSink_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsXMLContentSink.h" michael@0: #include "nsXBLDocumentInfo.h" michael@0: #include "nsXBLPrototypeHandler.h" michael@0: #include "nsXBLProtoImpl.h" michael@0: #include "nsLayoutCID.h" michael@0: michael@0: /* michael@0: * Enum that describes the primary state of the parsing process michael@0: */ michael@0: typedef enum { michael@0: eXBL_InDocument, /* outside any bindings */ michael@0: eXBL_InBindings, /* Inside a element */ michael@0: eXBL_InBinding, /* Inside a */ michael@0: eXBL_InResources, /* Inside a */ michael@0: eXBL_InImplementation, /* Inside a */ michael@0: eXBL_InHandlers, /* Inside a */ michael@0: eXBL_Error /* An error has occurred. Suspend binding construction */ michael@0: } XBLPrimaryState; michael@0: michael@0: /* michael@0: * Enum that describes our substate (typically when parsing something michael@0: * like or ). michael@0: */ michael@0: typedef enum { michael@0: eXBL_None, michael@0: eXBL_InHandler, michael@0: eXBL_InMethod, michael@0: eXBL_InProperty, michael@0: eXBL_InField, michael@0: eXBL_InBody, michael@0: eXBL_InGetter, michael@0: eXBL_InSetter, michael@0: eXBL_InConstructor, michael@0: eXBL_InDestructor michael@0: } XBLSecondaryState; michael@0: michael@0: class nsXULPrototypeElement; michael@0: class nsXBLProtoImplMember; michael@0: class nsXBLProtoImplProperty; michael@0: class nsXBLProtoImplMethod; michael@0: class nsXBLProtoImplField; michael@0: class nsXBLPrototypeBinding; michael@0: michael@0: // The XBL content sink overrides the XML content sink to michael@0: // builds its own lightweight data structures for the , michael@0: // , , and michael@0: michael@0: class nsXBLContentSink : public nsXMLContentSink { michael@0: public: michael@0: nsXBLContentSink(); michael@0: ~nsXBLContentSink(); michael@0: michael@0: NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW michael@0: michael@0: nsresult Init(nsIDocument* aDoc, michael@0: nsIURI* aURL, michael@0: nsISupports* aContainer); michael@0: michael@0: // nsIContentSink overrides michael@0: NS_IMETHOD HandleStartElement(const char16_t *aName, michael@0: const char16_t **aAtts, michael@0: uint32_t aAttsCount, michael@0: int32_t aIndex, michael@0: uint32_t aLineNumber) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD HandleEndElement(const char16_t *aName) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD HandleCDataSection(const char16_t *aData, michael@0: uint32_t aLength) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: // nsXMLContentSink overrides michael@0: virtual void MaybeStartLayout(bool aIgnorePendingSheets) MOZ_OVERRIDE; michael@0: michael@0: bool OnOpenContainer(const char16_t **aAtts, michael@0: uint32_t aAttsCount, michael@0: int32_t aNameSpaceID, michael@0: nsIAtom* aTagName, michael@0: uint32_t aLineNumber) MOZ_OVERRIDE; michael@0: michael@0: bool NotifyForDocElement() MOZ_OVERRIDE { return false; } michael@0: michael@0: nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount, michael@0: nsINodeInfo* aNodeInfo, uint32_t aLineNumber, michael@0: nsIContent** aResult, bool* aAppendContent, michael@0: mozilla::dom::FromParser aFromParser) MOZ_OVERRIDE; michael@0: michael@0: nsresult AddAttributes(const char16_t** aAtts, michael@0: nsIContent* aContent) MOZ_OVERRIDE; michael@0: michael@0: #ifdef MOZ_XUL michael@0: nsresult AddAttributesToXULPrototype(const char16_t **aAtts, michael@0: uint32_t aAttsCount, michael@0: nsXULPrototypeElement* aElement); michael@0: #endif michael@0: michael@0: // Our own helpers for constructing XBL prototype objects. michael@0: nsresult ConstructBinding(uint32_t aLineNumber); michael@0: void ConstructHandler(const char16_t **aAtts, uint32_t aLineNumber); michael@0: void ConstructResource(const char16_t **aAtts, nsIAtom* aResourceType); michael@0: void ConstructImplementation(const char16_t **aAtts); michael@0: void ConstructProperty(const char16_t **aAtts, uint32_t aLineNumber); michael@0: void ConstructMethod(const char16_t **aAtts); michael@0: void ConstructParameter(const char16_t **aAtts); michael@0: void ConstructField(const char16_t **aAtts, uint32_t aLineNumber); michael@0: michael@0: michael@0: // nsXMLContentSink overrides michael@0: nsresult FlushText(bool aReleaseTextNode = true) MOZ_OVERRIDE; michael@0: michael@0: // nsIExpatSink overrides michael@0: NS_IMETHOD ReportError(const char16_t* aErrorText, michael@0: const char16_t* aSourceText, michael@0: nsIScriptError *aError, michael@0: bool *_retval) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: nsresult ReportUnexpectedElement(nsIAtom* aElementName, uint32_t aLineNumber); michael@0: michael@0: void AddMember(nsXBLProtoImplMember* aMember); michael@0: void AddField(nsXBLProtoImplField* aField); michael@0: michael@0: XBLPrimaryState mState; michael@0: XBLSecondaryState mSecondaryState; michael@0: nsXBLDocumentInfo* mDocInfo; michael@0: bool mIsChromeOrResource; // For bug #45989 michael@0: bool mFoundFirstBinding; michael@0: michael@0: nsString mCurrentBindingID; michael@0: michael@0: nsXBLPrototypeBinding* mBinding; michael@0: nsXBLPrototypeHandler* mHandler; // current handler, owned by its PrototypeBinding michael@0: nsXBLProtoImpl* mImplementation; michael@0: nsXBLProtoImplMember* mImplMember; michael@0: nsXBLProtoImplField* mImplField; michael@0: nsXBLProtoImplProperty* mProperty; michael@0: nsXBLProtoImplMethod* mMethod; michael@0: nsXBLProtoImplField* mField; michael@0: }; michael@0: michael@0: nsresult michael@0: NS_NewXBLContentSink(nsIXMLContentSink** aResult, michael@0: nsIDocument* aDoc, michael@0: nsIURI* aURL, michael@0: nsISupports* aContainer); michael@0: #endif // nsXBLContentSink_h__