content/xul/document/src/nsXULContentSink.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/document/src/nsXULContentSink.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,151 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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 nsXULContentSink_h__
    1.10 +#define nsXULContentSink_h__
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsIExpatSink.h"
    1.14 +#include "nsIXMLContentSink.h"
    1.15 +#include "nsAutoPtr.h"
    1.16 +#include "nsNodeInfoManager.h"
    1.17 +#include "nsWeakPtr.h"
    1.18 +#include "nsXULElement.h"
    1.19 +#include "nsIDTD.h"
    1.20 +
    1.21 +class nsIDocument;
    1.22 +class nsIScriptSecurityManager;
    1.23 +class nsAttrName;
    1.24 +class nsXULPrototypeDocument;
    1.25 +class nsXULPrototypeElement;
    1.26 +class nsXULPrototypeNode;
    1.27 +
    1.28 +class XULContentSinkImpl : public nsIXMLContentSink,
    1.29 +                           public nsIExpatSink
    1.30 +{
    1.31 +public:
    1.32 +    XULContentSinkImpl();
    1.33 +    virtual ~XULContentSinkImpl();
    1.34 +
    1.35 +    // nsISupports
    1.36 +    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.37 +    NS_DECL_NSIEXPATSINK
    1.38 +
    1.39 +    NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl, nsIXMLContentSink)
    1.40 +
    1.41 +    // nsIContentSink
    1.42 +    NS_IMETHOD WillParse(void) MOZ_OVERRIDE { return NS_OK; }
    1.43 +    NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE;
    1.44 +    NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE;
    1.45 +    NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE;
    1.46 +    NS_IMETHOD WillResume(void) MOZ_OVERRIDE;
    1.47 +    NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE;
    1.48 +    virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE { }
    1.49 +    NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE;
    1.50 +    virtual nsISupports *GetTarget() MOZ_OVERRIDE;
    1.51 +
    1.52 +    /**
    1.53 +     * Initialize the content sink, giving it an nsIDocument object
    1.54 +     * with which to communicate with the outside world, and an
    1.55 +     * nsXULPrototypeDocument to build.
    1.56 +     */
    1.57 +    nsresult Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype);
    1.58 +
    1.59 +protected:
    1.60 +    // pseudo-constants
    1.61 +    char16_t* mText;
    1.62 +    int32_t mTextLength;
    1.63 +    int32_t mTextSize;
    1.64 +    bool mConstrainSize;
    1.65 +
    1.66 +    nsresult AddAttributes(const char16_t** aAttributes,
    1.67 +                           const uint32_t aAttrLen,
    1.68 +                           nsXULPrototypeElement* aElement);
    1.69 +
    1.70 +    nsresult OpenRoot(const char16_t** aAttributes,
    1.71 +                      const uint32_t aAttrLen,
    1.72 +                      nsINodeInfo *aNodeInfo);
    1.73 +
    1.74 +    nsresult OpenTag(const char16_t** aAttributes,
    1.75 +                     const uint32_t aAttrLen,
    1.76 +                     const uint32_t aLineNumber,
    1.77 +                     nsINodeInfo *aNodeInfo);
    1.78 +
    1.79 +    // If OpenScript returns NS_OK and after it returns our state is eInScript,
    1.80 +    // that means that we created a prototype script and stuck it on
    1.81 +    // mContextStack.  If NS_OK is returned but the state is still
    1.82 +    // eInDocumentElement then we didn't create a prototype script (e.g. the
    1.83 +    // script had an unknown type), and the caller should create a prototype
    1.84 +    // element.
    1.85 +    nsresult OpenScript(const char16_t** aAttributes,
    1.86 +                        const uint32_t aLineNumber);
    1.87 +
    1.88 +    static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength);
    1.89 +
    1.90 +    // Text management
    1.91 +    nsresult FlushText(bool aCreateTextNode = true);
    1.92 +    nsresult AddText(const char16_t* aText, int32_t aLength);
    1.93 +
    1.94 +
    1.95 +    nsRefPtr<nsNodeInfoManager> mNodeInfoManager;
    1.96 +
    1.97 +    nsresult NormalizeAttributeString(const char16_t *aExpatName,
    1.98 +                                      nsAttrName &aName);
    1.99 +    nsresult CreateElement(nsINodeInfo *aNodeInfo,
   1.100 +                           nsXULPrototypeElement** aResult);
   1.101 +
   1.102 +
   1.103 +    public:
   1.104 +    enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };
   1.105 +    protected:
   1.106 +
   1.107 +    State mState;
   1.108 +
   1.109 +    // content stack management
   1.110 +    class ContextStack {
   1.111 +    protected:
   1.112 +        struct Entry {
   1.113 +            nsRefPtr<nsXULPrototypeNode> mNode;
   1.114 +            // a LOT of nodes have children; preallocate for 8
   1.115 +            nsPrototypeArray    mChildren;
   1.116 +            State               mState;
   1.117 +            Entry*              mNext;
   1.118 +            Entry() : mChildren(8) {}
   1.119 +        };
   1.120 +
   1.121 +        Entry* mTop;
   1.122 +        int32_t mDepth;
   1.123 +
   1.124 +    public:
   1.125 +        ContextStack();
   1.126 +        ~ContextStack();
   1.127 +
   1.128 +        int32_t Depth() { return mDepth; }
   1.129 +
   1.130 +        nsresult Push(nsXULPrototypeNode* aNode, State aState);
   1.131 +        nsresult Pop(State* aState);
   1.132 +
   1.133 +        nsresult GetTopNode(nsRefPtr<nsXULPrototypeNode>& aNode);
   1.134 +        nsresult GetTopChildren(nsPrototypeArray** aChildren);
   1.135 +
   1.136 +        void Clear();
   1.137 +
   1.138 +        void Traverse(nsCycleCollectionTraversalCallback& aCallback);
   1.139 +    };
   1.140 +
   1.141 +    friend class ContextStack;
   1.142 +    ContextStack mContextStack;
   1.143 +
   1.144 +    nsWeakPtr              mDocument;             // [OWNER]
   1.145 +    nsCOMPtr<nsIURI>       mDocumentURL;          // [OWNER]
   1.146 +
   1.147 +    nsRefPtr<nsXULPrototypeDocument> mPrototype;  // [OWNER]
   1.148 +
   1.149 +    // We use regular pointer b/c of funky exports on nsIParser:
   1.150 +    nsParserBase*         mParser;               // [OWNER]
   1.151 +    nsCOMPtr<nsIScriptSecurityManager> mSecMan;
   1.152 +};
   1.153 +
   1.154 +#endif /* nsXULContentSink_h__ */

mercurial