Bug 1799694 - Rename action/menu button class names in unified extensions. r=Itiel...
[gecko.git] / dom / xul / nsXULContentSink.h
blob0538c013b417baf7ec0d367db64d358ac5245ec9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsXULContentSink_h__
7 #define nsXULContentSink_h__
9 #include "mozilla/Attributes.h"
10 #include "nsIExpatSink.h"
11 #include "nsIWeakReferenceUtils.h"
12 #include "nsIXMLContentSink.h"
13 #include "nsNodeInfoManager.h"
14 #include "nsXULElement.h"
15 #include "nsIDTD.h"
17 class nsIScriptSecurityManager;
18 class nsAttrName;
19 class nsXULPrototypeDocument;
20 class nsXULPrototypeElement;
21 class nsXULPrototypeNode;
23 class XULContentSinkImpl final : public nsIXMLContentSink, public nsIExpatSink {
24 public:
25 XULContentSinkImpl();
27 // nsISupports
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
29 NS_DECL_NSIEXPATSINK
31 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl,
32 nsIXMLContentSink)
34 // nsIContentSink
35 NS_IMETHOD WillParse(void) override { return NS_OK; }
36 NS_IMETHOD DidBuildModel(bool aTerminated) override;
37 NS_IMETHOD WillInterrupt(void) override;
38 void WillResume() override;
39 NS_IMETHOD SetParser(nsParserBase* aParser) override;
40 virtual void FlushPendingNotifications(mozilla::FlushType aType) override {}
41 virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
42 virtual nsISupports* GetTarget() override;
44 /**
45 * Initialize the content sink, giving it a document with which to communicate
46 * with the outside world, and an nsXULPrototypeDocument to build.
48 nsresult Init(mozilla::dom::Document* aDocument,
49 nsXULPrototypeDocument* aPrototype);
51 protected:
52 virtual ~XULContentSinkImpl();
54 // pseudo-constants
55 char16_t* mText;
56 int32_t mTextLength;
57 int32_t mTextSize;
58 bool mConstrainSize;
60 nsresult AddAttributes(const char16_t** aAttributes, const uint32_t aAttrLen,
61 nsXULPrototypeElement* aElement);
63 nsresult OpenRoot(const char16_t** aAttributes, const uint32_t aAttrLen,
64 mozilla::dom::NodeInfo* aNodeInfo);
66 nsresult OpenTag(const char16_t** aAttributes, const uint32_t aAttrLen,
67 const uint32_t aLineNumber,
68 mozilla::dom::NodeInfo* aNodeInfo);
70 // If OpenScript returns NS_OK and after it returns our state is eInScript,
71 // that means that we created a prototype script and stuck it on
72 // mContextStack. If NS_OK is returned but the state is still
73 // eInDocumentElement then we didn't create a prototype script (e.g. the
74 // script had an unknown type), and the caller should create a prototype
75 // element.
76 nsresult OpenScript(const char16_t** aAttributes, const uint32_t aLineNumber);
78 static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength);
80 // Text management
81 nsresult FlushText(bool aCreateTextNode = true);
82 nsresult AddText(const char16_t* aText, int32_t aLength);
84 RefPtr<nsNodeInfoManager> mNodeInfoManager;
86 nsresult NormalizeAttributeString(const char16_t* aExpatName,
87 nsAttrName& aName);
89 public:
90 enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog };
92 protected:
93 State mState;
95 // content stack management
96 class ContextStack {
97 protected:
98 struct Entry {
99 RefPtr<nsXULPrototypeNode> mNode;
100 // a LOT of nodes have children; preallocate for 8
101 nsPrototypeArray mChildren;
102 State mState;
103 Entry* mNext;
104 Entry(RefPtr<nsXULPrototypeNode>&& aNode, State aState, Entry* aNext)
105 : mNode(std::move(aNode)),
106 mChildren(8),
107 mState(aState),
108 mNext(aNext) {}
111 Entry* mTop;
112 int32_t mDepth;
114 public:
115 ContextStack();
116 ~ContextStack();
118 int32_t Depth() { return mDepth; }
120 void Push(RefPtr<nsXULPrototypeNode>&& aNode, State aState);
121 nsresult Pop(State* aState);
123 nsresult GetTopNode(RefPtr<nsXULPrototypeNode>& aNode);
124 nsresult GetTopChildren(nsPrototypeArray** aChildren);
126 void Clear();
128 void Traverse(nsCycleCollectionTraversalCallback& aCallback);
131 friend class ContextStack;
132 ContextStack mContextStack;
134 nsWeakPtr mDocument; // [OWNER]
135 nsCOMPtr<nsIURI> mDocumentURL; // [OWNER]
137 RefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER]
139 RefPtr<nsParserBase> mParser;
140 nsCOMPtr<nsIScriptSecurityManager> mSecMan;
143 #endif /* nsXULContentSink_h__ */