2007-03-24 22:02:10 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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-24 22:02:10 -07:00
|
|
|
|
|
|
|
#ifndef nsXULContentSink_h__
|
|
|
|
#define nsXULContentSink_h__
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-24 22:02:10 -07:00
|
|
|
#include "nsIExpatSink.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsWeakPtr.h"
|
2008-10-08 04:41:52 -07:00
|
|
|
#include "nsXULElement.h"
|
2009-06-23 14:22:16 -07:00
|
|
|
#include "nsIDTD.h"
|
2007-03-24 22:02:10 -07:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIScriptSecurityManager;
|
|
|
|
class nsAttrName;
|
|
|
|
class nsXULPrototypeDocument;
|
|
|
|
class nsXULPrototypeElement;
|
|
|
|
class nsXULPrototypeNode;
|
|
|
|
|
|
|
|
class XULContentSinkImpl : public nsIXMLContentSink,
|
|
|
|
public nsIExpatSink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XULContentSinkImpl();
|
|
|
|
|
|
|
|
// nsISupports
|
2013-03-08 18:53:00 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-03-24 22:02:10 -07:00
|
|
|
NS_DECL_NSIEXPATSINK
|
|
|
|
|
2013-03-08 18:53:00 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl, nsIXMLContentSink)
|
|
|
|
|
2007-03-24 22:02:10 -07:00
|
|
|
// nsIContentSink
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD WillParse(void) MOZ_OVERRIDE { return NS_OK; }
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD WillResume(void) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE { }
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE;
|
|
|
|
virtual nsISupports *GetTarget() MOZ_OVERRIDE;
|
2007-03-24 22:02:10 -07: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-24 19:09:15 -07:00
|
|
|
virtual ~XULContentSinkImpl();
|
|
|
|
|
2007-03-24 22:02:10 -07:00
|
|
|
// pseudo-constants
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t* mText;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mTextLength;
|
|
|
|
int32_t mTextSize;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mConstrainSize;
|
2007-03-24 22:02:10 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult AddAttributes(const char16_t** aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t aAttrLen,
|
2007-03-24 22:02:10 -07:00
|
|
|
nsXULPrototypeElement* aElement);
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult OpenRoot(const char16_t** aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t aAttrLen,
|
2014-06-19 19:01:40 -07:00
|
|
|
mozilla::dom::NodeInfo *aNodeInfo);
|
2007-03-24 22:02:10 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult OpenTag(const char16_t** aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t aAttrLen,
|
|
|
|
const uint32_t aLineNumber,
|
2014-06-19 19:01:40 -07:00
|
|
|
mozilla::dom::NodeInfo *aNodeInfo);
|
2007-03-24 22:02:10 -07:00
|
|
|
|
2007-12-02 14:27:11 -08: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 07:02:17 -08:00
|
|
|
nsresult OpenScript(const char16_t** aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t aLineNumber);
|
2007-03-24 22:02:10 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength);
|
2007-03-24 22:02:10 -07:00
|
|
|
|
|
|
|
// Text management
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult FlushText(bool aCreateTextNode = true);
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult AddText(const char16_t* aText, int32_t aLength);
|
2007-03-24 22:02:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
nsRefPtr<nsNodeInfoManager> mNodeInfoManager;
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult NormalizeAttributeString(const char16_t *aExpatName,
|
2007-03-24 22:02:10 -07:00
|
|
|
nsAttrName &aName);
|
2014-06-19 19:01:40 -07:00
|
|
|
nsresult CreateElement(mozilla::dom::NodeInfo *aNodeInfo,
|
2007-03-24 22:02:10 -07:00
|
|
|
nsXULPrototypeElement** aResult);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };
|
|
|
|
protected:
|
|
|
|
|
|
|
|
State mState;
|
|
|
|
|
|
|
|
// content stack management
|
|
|
|
class ContextStack {
|
|
|
|
protected:
|
|
|
|
struct Entry {
|
2008-10-08 04:41:52 -07:00
|
|
|
nsRefPtr<nsXULPrototypeNode> mNode;
|
2007-03-24 22:02:10 -07:00
|
|
|
// a LOT of nodes have children; preallocate for 8
|
2008-10-08 04:41:52 -07:00
|
|
|
nsPrototypeArray mChildren;
|
2007-03-24 22:02:10 -07:00
|
|
|
State mState;
|
|
|
|
Entry* mNext;
|
2008-10-08 04:41:52 -07:00
|
|
|
Entry() : mChildren(8) {}
|
2007-03-24 22:02:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Entry* mTop;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDepth;
|
2007-03-24 22:02:10 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
ContextStack();
|
|
|
|
~ContextStack();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Depth() { return mDepth; }
|
2007-03-24 22:02:10 -07:00
|
|
|
|
|
|
|
nsresult Push(nsXULPrototypeNode* aNode, State aState);
|
|
|
|
nsresult Pop(State* aState);
|
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
nsresult GetTopNode(nsRefPtr<nsXULPrototypeNode>& aNode);
|
|
|
|
nsresult GetTopChildren(nsPrototypeArray** aChildren);
|
2007-11-12 06:47:14 -08:00
|
|
|
|
|
|
|
void Clear();
|
2013-03-08 18:53:00 -08:00
|
|
|
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& aCallback);
|
2007-03-24 22:02:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
friend class ContextStack;
|
|
|
|
ContextStack mContextStack;
|
|
|
|
|
|
|
|
nsWeakPtr mDocument; // [OWNER]
|
|
|
|
nsCOMPtr<nsIURI> mDocumentURL; // [OWNER]
|
|
|
|
|
|
|
|
nsRefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER]
|
|
|
|
|
|
|
|
// We use regular pointer b/c of funky exports on nsIParser:
|
2012-01-20 03:16:27 -08:00
|
|
|
nsParserBase* mParser; // [OWNER]
|
2007-03-24 22:02:10 -07:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> mSecMan;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsXULContentSink_h__ */
|