Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5 :
6 : #ifndef TX_TXSTYLESHEET_H
7 : #define TX_TXSTYLESHEET_H
8 :
9 : #include "txOutputFormat.h"
10 : #include "txExpandedNameMap.h"
11 : #include "txList.h"
12 : #include "txXSLTPatterns.h"
13 : #include "nsISupportsImpl.h"
14 :
15 : class txInstruction;
16 : class txTemplateItem;
17 : class txVariableItem;
18 : class txStripSpaceItem;
19 : class txAttributeSetItem;
20 : class txDecimalFormat;
21 : class txStripSpaceTest;
22 : class txXSLKey;
23 :
24 : class txStylesheet final
25 : {
26 : public:
27 : class ImportFrame;
28 : class GlobalVariable;
29 : friend class txStylesheetCompilerState;
30 : // To be able to do some cleaning up in destructor
31 : friend class ImportFrame;
32 :
33 : txStylesheet();
34 : nsresult init();
35 :
36 0 : NS_INLINE_DECL_REFCOUNTING(txStylesheet)
37 :
38 : nsresult findTemplate(const txXPathNode& aNode,
39 : const txExpandedName& aMode,
40 : txIMatchContext* aContext,
41 : ImportFrame* aImportedBy,
42 : txInstruction** aTemplate,
43 : ImportFrame** aImportFrame);
44 : txDecimalFormat* getDecimalFormat(const txExpandedName& aName);
45 : txInstruction* getAttributeSet(const txExpandedName& aName);
46 : txInstruction* getNamedTemplate(const txExpandedName& aName);
47 : txOutputFormat* getOutputFormat();
48 : GlobalVariable* getGlobalVariable(const txExpandedName& aName);
49 : const txOwningExpandedNameMap<txXSLKey>& getKeyMap();
50 : nsresult isStripSpaceAllowed(const txXPathNode& aNode,
51 : txIMatchContext* aContext,
52 : bool& aAllowed);
53 :
54 : /**
55 : * Called by the stylesheet compiler once all stylesheets has been read.
56 : */
57 : nsresult doneCompiling();
58 :
59 : /**
60 : * Add a key to the stylesheet
61 : */
62 : nsresult addKey(const txExpandedName& aName, nsAutoPtr<txPattern> aMatch,
63 : nsAutoPtr<Expr> aUse);
64 :
65 : /**
66 : * Add a decimal-format to the stylesheet
67 : */
68 : nsresult addDecimalFormat(const txExpandedName& aName,
69 : nsAutoPtr<txDecimalFormat>&& aFormat);
70 :
71 0 : struct MatchableTemplate {
72 : txInstruction* mFirstInstruction;
73 : nsAutoPtr<txPattern> mMatch;
74 : double mPriority;
75 : };
76 :
77 : /**
78 : * Contain information that is import precedence dependant.
79 : */
80 : class ImportFrame {
81 : public:
82 0 : ImportFrame()
83 0 : : mFirstNotImported(nullptr)
84 : {
85 0 : }
86 : ~ImportFrame();
87 :
88 : // List of toplevel items
89 : txList mToplevelItems;
90 :
91 : // Map of template modes
92 : txOwningExpandedNameMap< nsTArray<MatchableTemplate> > mMatchableTemplates;
93 :
94 : // ImportFrame which is the first one *not* imported by this frame
95 : ImportFrame* mFirstNotImported;
96 : };
97 :
98 0 : class GlobalVariable : public txObject {
99 : public:
100 : GlobalVariable(nsAutoPtr<Expr>&& aExpr,
101 : nsAutoPtr<txInstruction>&& aFirstInstruction,
102 : bool aIsParam);
103 :
104 : nsAutoPtr<Expr> mExpr;
105 : nsAutoPtr<txInstruction> mFirstInstruction;
106 : bool mIsParam;
107 : };
108 :
109 : private:
110 : // Private destructor, to discourage deletion outside of Release():
111 : ~txStylesheet();
112 :
113 : nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
114 : nsresult addGlobalVariable(txVariableItem* aVariable);
115 : nsresult addFrames(txListIterator& aInsertIter);
116 : nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem,
117 : nsTArray<txStripSpaceTest*>& aFrameStripSpaceTests);
118 : nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem);
119 :
120 : // List of ImportFrames
121 : txList mImportFrames;
122 :
123 : // output format
124 : txOutputFormat mOutputFormat;
125 :
126 : // List of first instructions of templates. This is the owner of all
127 : // instructions used in templates
128 : txList mTemplateInstructions;
129 :
130 : // Root importframe
131 : ImportFrame* mRootFrame;
132 :
133 : // Named templates
134 : txExpandedNameMap<txInstruction> mNamedTemplates;
135 :
136 : // Map with all decimal-formats
137 : txOwningExpandedNameMap<txDecimalFormat> mDecimalFormats;
138 :
139 : // Map with all named attribute sets
140 : txExpandedNameMap<txInstruction> mAttributeSets;
141 :
142 : // Map with all global variables and parameters
143 : txOwningExpandedNameMap<GlobalVariable> mGlobalVariables;
144 :
145 : // Map with all keys
146 : txOwningExpandedNameMap<txXSLKey> mKeys;
147 :
148 : // Array of all txStripSpaceTests, sorted in acending order
149 : nsTArray<nsAutoPtr<txStripSpaceTest> > mStripSpaceTests;
150 :
151 : // Default templates
152 : nsAutoPtr<txInstruction> mContainerTemplate;
153 : nsAutoPtr<txInstruction> mCharactersTemplate;
154 : nsAutoPtr<txInstruction> mEmptyTemplate;
155 : };
156 :
157 :
158 : /**
159 : * txStripSpaceTest holds both an txNameTest and a bool for use in
160 : * whitespace stripping.
161 : */
162 0 : class txStripSpaceTest {
163 : public:
164 0 : txStripSpaceTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
165 : bool stripSpace)
166 0 : : mNameTest(aPrefix, aLocalName, aNSID, txXPathNodeType::ELEMENT_NODE),
167 0 : mStrips(stripSpace)
168 : {
169 0 : }
170 :
171 0 : nsresult matches(const txXPathNode& aNode, txIMatchContext* aContext,
172 : bool& aMatched)
173 : {
174 0 : return mNameTest.matches(aNode, aContext, aMatched);
175 : }
176 :
177 0 : bool stripsSpace() {
178 0 : return mStrips;
179 : }
180 :
181 0 : double getDefaultPriority() {
182 0 : return mNameTest.getDefaultPriority();
183 : }
184 :
185 : protected:
186 : txNameTest mNameTest;
187 : bool mStrips;
188 : };
189 :
190 : /**
191 : * Value of a global parameter
192 : */
193 : class txIGlobalParameter
194 : {
195 : public:
196 0 : txIGlobalParameter()
197 0 : {
198 0 : MOZ_COUNT_CTOR(txIGlobalParameter);
199 0 : }
200 0 : virtual ~txIGlobalParameter()
201 0 : {
202 0 : MOZ_COUNT_DTOR(txIGlobalParameter);
203 0 : }
204 : virtual nsresult getValue(txAExprResult** aValue) = 0;
205 : };
206 :
207 :
208 : #endif //TX_TXSTYLESHEET_H
|