2007-03-25 05:02:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
#ifndef nsXULContentSink_h__
|
|
|
|
#define nsXULContentSink_h__
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-25 05:02:10 +00:00
|
|
|
#include "nsIExpatSink.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2008-10-08 11:41:52 +00:00
|
|
|
#include "nsXULElement.h"
|
2009-06-23 21:22:16 +00:00
|
|
|
#include "nsIDTD.h"
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIScriptSecurityManager;
|
|
|
|
class nsAttrName;
|
|
|
|
class nsXULPrototypeDocument;
|
|
|
|
class nsXULPrototypeElement;
|
|
|
|
class nsXULPrototypeNode;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class XULContentSinkImpl final : public nsIXMLContentSink,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIExpatSink
|
2007-03-25 05:02:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
XULContentSinkImpl();
|
|
|
|
|
|
|
|
// nsISupports
|
2013-03-09 02:53:00 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-03-25 05:02:10 +00:00
|
|
|
NS_DECL_NSIEXPATSINK
|
|
|
|
|
2013-03-09 02:53:00 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl, nsIXMLContentSink)
|
|
|
|
|
2007-03-25 05:02:10 +00:00
|
|
|
// nsIContentSink
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD WillParse(void) override { return NS_OK; }
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
|
|
|
NS_IMETHOD WillInterrupt(void) override;
|
|
|
|
NS_IMETHOD WillResume(void) override;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) override { }
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
|
|
|
virtual nsISupports *GetTarget() override;
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the content sink, giving it an nsIDocument object
|
|
|
|
* with which to communicate with the outside world, and an
|
|
|
|
* nsXULPrototypeDocument to build.
|
|
|
|
*/
|
|
|
|
nsresult Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype);
|
|
|
|
|
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~XULContentSinkImpl();
|
|
|
|
|
2007-03-25 05:02:10 +00:00
|
|
|
// pseudo-constants
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* mText;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mTextLength;
|
|
|
|
int32_t mTextSize;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mConstrainSize;
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult AddAttributes(const char16_t** aAttributes,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t aAttrLen,
|
2007-03-25 05:02:10 +00:00
|
|
|
nsXULPrototypeElement* aElement);
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult OpenRoot(const char16_t** aAttributes,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t aAttrLen,
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo *aNodeInfo);
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult OpenTag(const char16_t** aAttributes,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t aAttrLen,
|
|
|
|
const uint32_t aLineNumber,
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo *aNodeInfo);
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2007-12-02 22:27:11 +00:00
|
|
|
// If OpenScript returns NS_OK and after it returns our state is eInScript,
|
|
|
|
// that means that we created a prototype script and stuck it on
|
|
|
|
// mContextStack. If NS_OK is returned but the state is still
|
|
|
|
// eInDocumentElement then we didn't create a prototype script (e.g. the
|
|
|
|
// script had an unknown type), and the caller should create a prototype
|
|
|
|
// element.
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult OpenScript(const char16_t** aAttributes,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t aLineNumber);
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength);
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
// Text management
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult FlushText(bool aCreateTextNode = true);
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult AddText(const char16_t* aText, int32_t aLength);
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsNodeInfoManager> mNodeInfoManager;
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult NormalizeAttributeString(const char16_t *aExpatName,
|
2007-03-25 05:02:10 +00:00
|
|
|
nsAttrName &aName);
|
2014-06-20 02:01:40 +00:00
|
|
|
nsresult CreateElement(mozilla::dom::NodeInfo *aNodeInfo,
|
2007-03-25 05:02:10 +00:00
|
|
|
nsXULPrototypeElement** aResult);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };
|
|
|
|
protected:
|
|
|
|
|
|
|
|
State mState;
|
|
|
|
|
|
|
|
// content stack management
|
|
|
|
class ContextStack {
|
|
|
|
protected:
|
|
|
|
struct Entry {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXULPrototypeNode> mNode;
|
2007-03-25 05:02:10 +00:00
|
|
|
// a LOT of nodes have children; preallocate for 8
|
2008-10-08 11:41:52 +00:00
|
|
|
nsPrototypeArray mChildren;
|
2007-03-25 05:02:10 +00:00
|
|
|
State mState;
|
|
|
|
Entry* mNext;
|
2008-10-08 11:41:52 +00:00
|
|
|
Entry() : mChildren(8) {}
|
2007-03-25 05:02:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Entry* mTop;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mDepth;
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
ContextStack();
|
|
|
|
~ContextStack();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t Depth() { return mDepth; }
|
2007-03-25 05:02:10 +00:00
|
|
|
|
|
|
|
nsresult Push(nsXULPrototypeNode* aNode, State aState);
|
|
|
|
nsresult Pop(State* aState);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
nsresult GetTopNode(RefPtr<nsXULPrototypeNode>& aNode);
|
2008-10-08 11:41:52 +00:00
|
|
|
nsresult GetTopChildren(nsPrototypeArray** aChildren);
|
2007-11-12 14:47:14 +00:00
|
|
|
|
|
|
|
void Clear();
|
2013-03-09 02:53:00 +00:00
|
|
|
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& aCallback);
|
2007-03-25 05:02:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
friend class ContextStack;
|
|
|
|
ContextStack mContextStack;
|
|
|
|
|
|
|
|
nsWeakPtr mDocument; // [OWNER]
|
|
|
|
nsCOMPtr<nsIURI> mDocumentURL; // [OWNER]
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER]
|
2007-03-25 05:02:10 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsParserBase> mParser;
|
2007-03-25 05:02:10 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> mSecMan;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsXULContentSink_h__ */
|