/src/mozilla-central/dom/xbl/nsXBLContentSink.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsXBLContentSink_h__ |
8 | | #define nsXBLContentSink_h__ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "nsXMLContentSink.h" |
12 | | #include "nsXBLDocumentInfo.h" |
13 | | #include "nsXBLPrototypeHandler.h" |
14 | | #include "nsXBLProtoImpl.h" |
15 | | #include "nsLayoutCID.h" |
16 | | |
17 | | /* |
18 | | * Enum that describes the primary state of the parsing process |
19 | | */ |
20 | | typedef enum { |
21 | | eXBL_InDocument, /* outside any bindings */ |
22 | | eXBL_InBindings, /* Inside a <bindings> element */ |
23 | | eXBL_InBinding, /* Inside a <binding> */ |
24 | | eXBL_InResources, /* Inside a <resources> */ |
25 | | eXBL_InImplementation, /* Inside a <implementation> */ |
26 | | eXBL_InHandlers, /* Inside a <handlers> */ |
27 | | eXBL_Error /* An error has occurred. Suspend binding construction */ |
28 | | } XBLPrimaryState; |
29 | | |
30 | | /* |
31 | | * Enum that describes our substate (typically when parsing something |
32 | | * like <handlers> or <implementation>). |
33 | | */ |
34 | | typedef enum { |
35 | | eXBL_None, |
36 | | eXBL_InHandler, |
37 | | eXBL_InMethod, |
38 | | eXBL_InProperty, |
39 | | eXBL_InField, |
40 | | eXBL_InBody, |
41 | | eXBL_InGetter, |
42 | | eXBL_InSetter, |
43 | | eXBL_InConstructor, |
44 | | eXBL_InDestructor |
45 | | } XBLSecondaryState; |
46 | | |
47 | | class nsXULPrototypeElement; |
48 | | class nsXBLProtoImplMember; |
49 | | class nsXBLProtoImplProperty; |
50 | | class nsXBLProtoImplMethod; |
51 | | class nsXBLProtoImplField; |
52 | | class nsXBLPrototypeBinding; |
53 | | |
54 | | // The XBL content sink overrides the XML content sink to |
55 | | // builds its own lightweight data structures for the <resources>, |
56 | | // <handlers>, <implementation>, and |
57 | | |
58 | | class nsXBLContentSink : public nsXMLContentSink { |
59 | | public: |
60 | | nsXBLContentSink(); |
61 | | ~nsXBLContentSink(); |
62 | | |
63 | | nsresult Init(nsIDocument* aDoc, |
64 | | nsIURI* aURL, |
65 | | nsISupports* aContainer); |
66 | | |
67 | | // nsIContentSink overrides |
68 | | NS_IMETHOD HandleStartElement(const char16_t *aName, |
69 | | const char16_t **aAtts, |
70 | | uint32_t aAttsCount, |
71 | | uint32_t aLineNumber, |
72 | | uint32_t aColumnNumber) override; |
73 | | |
74 | | NS_IMETHOD HandleEndElement(const char16_t *aName) override; |
75 | | |
76 | | NS_IMETHOD HandleCDataSection(const char16_t *aData, |
77 | | uint32_t aLength) override; |
78 | | |
79 | | protected: |
80 | | // nsXMLContentSink overrides |
81 | | virtual void MaybeStartLayout(bool aIgnorePendingSheets) override; |
82 | | |
83 | | bool OnOpenContainer(const char16_t **aAtts, |
84 | | uint32_t aAttsCount, |
85 | | int32_t aNameSpaceID, |
86 | | nsAtom* aTagName, |
87 | | uint32_t aLineNumber) override; |
88 | | |
89 | 0 | bool NotifyForDocElement() override { return false; } |
90 | | |
91 | | nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount, |
92 | | mozilla::dom::NodeInfo* aNodeInfo, |
93 | | uint32_t aLineNumber, uint32_t aColumnNumber, |
94 | | nsIContent** aResult, bool* aAppendContent, |
95 | | mozilla::dom::FromParser aFromParser) override; |
96 | | |
97 | | nsresult AddAttributes(const char16_t** aAtts, Element* aElement) override; |
98 | | |
99 | | #ifdef MOZ_XUL |
100 | | nsresult AddAttributesToXULPrototype(const char16_t **aAtts, |
101 | | uint32_t aAttsCount, |
102 | | nsXULPrototypeElement* aElement); |
103 | | #endif |
104 | | |
105 | | // Our own helpers for constructing XBL prototype objects. |
106 | | nsresult ConstructBinding(uint32_t aLineNumber); |
107 | | void ConstructHandler(const char16_t **aAtts, uint32_t aLineNumber); |
108 | | void ConstructResource(const char16_t **aAtts, nsAtom* aResourceType); |
109 | | void ConstructImplementation(const char16_t **aAtts); |
110 | | void ConstructProperty(const char16_t **aAtts, uint32_t aLineNumber); |
111 | | void ConstructMethod(const char16_t **aAtts); |
112 | | void ConstructParameter(const char16_t **aAtts); |
113 | | void ConstructField(const char16_t **aAtts, uint32_t aLineNumber); |
114 | | |
115 | | |
116 | | // nsXMLContentSink overrides |
117 | | nsresult FlushText(bool aReleaseTextNode = true) override; |
118 | | |
119 | | // nsIExpatSink overrides |
120 | | NS_IMETHOD ReportError(const char16_t* aErrorText, |
121 | | const char16_t* aSourceText, |
122 | | nsIScriptError *aError, |
123 | | bool *_retval) override; |
124 | | |
125 | | protected: |
126 | | nsresult ReportUnexpectedElement(nsAtom* aElementName, uint32_t aLineNumber); |
127 | | |
128 | | void AddMember(nsXBLProtoImplMember* aMember); |
129 | | void AddField(nsXBLProtoImplField* aField); |
130 | | |
131 | | XBLPrimaryState mState; |
132 | | XBLSecondaryState mSecondaryState; |
133 | | nsXBLDocumentInfo* mDocInfo; |
134 | | bool mIsChromeOrResource; // For bug #45989 |
135 | | bool mFoundFirstBinding; |
136 | | |
137 | | nsString mCurrentBindingID; |
138 | | |
139 | | nsXBLPrototypeBinding* mBinding; |
140 | | nsXBLPrototypeHandler* mHandler; // current handler, owned by its PrototypeBinding |
141 | | nsXBLProtoImpl* mImplementation; |
142 | | nsXBLProtoImplMember* mImplMember; |
143 | | nsXBLProtoImplField* mImplField; |
144 | | nsXBLProtoImplProperty* mProperty; |
145 | | nsXBLProtoImplMethod* mMethod; |
146 | | nsXBLProtoImplField* mField; |
147 | | }; |
148 | | |
149 | | nsresult |
150 | | NS_NewXBLContentSink(nsIXMLContentSink** aResult, |
151 | | nsIDocument* aDoc, |
152 | | nsIURI* aURL, |
153 | | nsISupports* aContainer); |
154 | | #endif // nsXBLContentSink_h__ |