Bug 588735 - Mirror glass caption buttons for rtl windows. r=roc, a=blocking-betaN.
[mozilla-central.git] / js / src / jsxml.h
bloba46851a1fe735690d7d5d97d68ba5470e13c3d05
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is SpiderMonkey E4X code, released August, 2004.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef jsxml_h___
40 #define jsxml_h___
42 #include "jspubtd.h"
43 #include "jsobj.h"
45 extern const char js_AnyName_str[];
46 extern const char js_AttributeName_str[];
47 extern const char js_isXMLName_str[];
48 extern const char js_XMLList_str[];
50 extern const char js_amp_entity_str[];
51 extern const char js_gt_entity_str[];
52 extern const char js_lt_entity_str[];
53 extern const char js_quot_entity_str[];
55 typedef JSBool
56 (* JSIdentityOp)(const void *a, const void *b);
58 struct JSXMLArray {
59 uint32 length;
60 uint32 capacity;
61 void **vector;
62 JSXMLArrayCursor *cursors;
64 void init() {
65 length = capacity = 0;
66 vector = NULL;
67 cursors = NULL;
70 void finish(JSContext *cx);
72 bool setCapacity(JSContext *cx, uint32 capacity);
73 void trim();
76 struct JSXMLArrayCursor
78 JSXMLArray *array;
79 uint32 index;
80 JSXMLArrayCursor *next;
81 JSXMLArrayCursor **prevp;
82 void *root;
84 JSXMLArrayCursor(JSXMLArray *array)
85 : array(array), index(0), next(array->cursors), prevp(&array->cursors),
86 root(NULL)
88 if (next)
89 next->prevp = &next;
90 array->cursors = this;
93 ~JSXMLArrayCursor() { disconnect(); }
95 void disconnect() {
96 if (!array)
97 return;
98 if (next)
99 next->prevp = prevp;
100 *prevp = next;
101 array = NULL;
104 void *getNext() {
105 if (!array || index >= array->length)
106 return NULL;
107 return root = array->vector[index++];
110 void *getCurrent() {
111 if (!array || index >= array->length)
112 return NULL;
113 return root = array->vector[index];
116 void trace(JSTracer *trc) {
117 #ifdef DEBUG
118 size_t index = 0;
119 #endif
120 for (JSXMLArrayCursor *cursor = this; cursor; cursor = cursor->next)
121 js::MarkGCThing(trc, cursor->root, "cursor_root", index++);
125 #define JSXML_PRESET_CAPACITY JS_BIT(31)
126 #define JSXML_CAPACITY_MASK JS_BITMASK(31)
127 #define JSXML_CAPACITY(array) ((array)->capacity & JSXML_CAPACITY_MASK)
130 * NB: don't reorder this enum without changing all array initializers that
131 * depend on it in jsxml.c.
133 typedef enum JSXMLClass {
134 JSXML_CLASS_LIST,
135 JSXML_CLASS_ELEMENT,
136 JSXML_CLASS_ATTRIBUTE,
137 JSXML_CLASS_PROCESSING_INSTRUCTION,
138 JSXML_CLASS_TEXT,
139 JSXML_CLASS_COMMENT,
140 JSXML_CLASS_LIMIT
141 } JSXMLClass;
143 #define JSXML_CLASS_HAS_KIDS(class_) ((class_) < JSXML_CLASS_ATTRIBUTE)
144 #define JSXML_CLASS_HAS_VALUE(class_) ((class_) >= JSXML_CLASS_ATTRIBUTE)
145 #define JSXML_CLASS_HAS_NAME(class_) \
146 ((uintN)((class_) - JSXML_CLASS_ELEMENT) <= \
147 (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
149 #ifdef DEBUG_notme
150 #include "jsclist.h"
151 #endif
153 typedef struct JSXMLListVar {
154 JSXMLArray kids; /* NB: must come first */
155 JSXML *target;
156 JSObject *targetprop;
157 } JSXMLListVar;
159 typedef struct JSXMLElemVar {
160 JSXMLArray kids; /* NB: must come first */
161 JSXMLArray namespaces;
162 JSXMLArray attrs;
163 } JSXMLElemVar;
165 struct JSXML {
166 #ifdef DEBUG_notme
167 JSCList links;
168 uint32 serial;
169 #endif
170 JSObject *object;
171 void *domnode; /* DOM node if mapped info item */
172 JSXML *parent;
173 JSObject *name;
174 uint32 xml_class; /* discriminates u, below */
175 uint32 xml_flags; /* flags, see below */
176 union {
177 JSXMLListVar list;
178 JSXMLElemVar elem;
179 JSString *value;
180 } u;
183 JS_STATIC_ASSERT(sizeof(JSXML) % JS_GCTHING_ALIGN == 0);
185 /* union member shorthands */
186 #define xml_kids u.list.kids
187 #define xml_target u.list.target
188 #define xml_targetprop u.list.targetprop
189 #define xml_namespaces u.elem.namespaces
190 #define xml_attrs u.elem.attrs
191 #define xml_value u.value
193 /* xml_flags values */
194 #define XMLF_WHITESPACE_TEXT 0x1
196 /* xml_class-testing macros */
197 #define JSXML_HAS_KIDS(xml) JSXML_CLASS_HAS_KIDS((xml)->xml_class)
198 #define JSXML_HAS_VALUE(xml) JSXML_CLASS_HAS_VALUE((xml)->xml_class)
199 #define JSXML_HAS_NAME(xml) JSXML_CLASS_HAS_NAME((xml)->xml_class)
200 #define JSXML_LENGTH(xml) (JSXML_CLASS_HAS_KIDS((xml)->xml_class) \
201 ? (xml)->xml_kids.length \
202 : 0)
204 extern JSXML *
205 js_NewXML(JSContext *cx, JSXMLClass xml_class);
207 extern void
208 js_TraceXML(JSTracer *trc, JSXML *xml);
210 extern void
211 js_FinalizeXML(JSContext *cx, JSXML *xml);
213 extern JSObject *
214 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
216 extern JSObject *
217 js_GetXMLObject(JSContext *cx, JSXML *xml);
219 extern JS_FRIEND_DATA(js::Class) js_XMLClass;
220 extern JS_FRIEND_DATA(js::Class) js_NamespaceClass;
221 extern JS_FRIEND_DATA(js::Class) js_QNameClass;
222 extern JS_FRIEND_DATA(js::Class) js_AttributeNameClass;
223 extern JS_FRIEND_DATA(js::Class) js_AnyNameClass;
224 extern js::Class js_XMLFilterClass;
227 * Methods to test whether an object or a value is of type "xml" (per typeof).
229 inline bool
230 JSObject::isXML() const
232 return getClass() == &js_XMLClass;
235 inline bool
236 JSObject::isXMLId() const
238 js::Class *clasp = getClass();
239 return clasp == &js_QNameClass ||
240 clasp == &js_AttributeNameClass ||
241 clasp == &js_AnyNameClass;
244 #define VALUE_IS_XML(v) (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isXML())
246 inline bool
247 JSObject::isNamespace() const
249 return getClass() == &js_NamespaceClass;
252 inline bool
253 JSObject::isQName() const
255 js::Class* clasp = getClass();
256 return clasp == &js_QNameClass ||
257 clasp == &js_AttributeNameClass ||
258 clasp == &js_AnyNameClass;
261 static inline bool
262 IsXML(const js::Value &v)
264 return v.isObject() && v.toObject().isXML();
267 extern JSObject *
268 js_InitNamespaceClass(JSContext *cx, JSObject *obj);
270 extern JSObject *
271 js_InitQNameClass(JSContext *cx, JSObject *obj);
273 extern JSObject *
274 js_InitAttributeNameClass(JSContext *cx, JSObject *obj);
276 extern JSObject *
277 js_InitAnyNameClass(JSContext *cx, JSObject *obj);
279 extern JSObject *
280 js_InitXMLClass(JSContext *cx, JSObject *obj);
282 extern JSObject *
283 js_InitXMLClasses(JSContext *cx, JSObject *obj);
285 extern JSBool
286 js_GetFunctionNamespace(JSContext *cx, js::Value *vp);
289 * If obj is QName corresponding to function::name, set *funidp to name's id,
290 * otherwise set *funidp to void.
292 JSBool
293 js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp);
295 extern JSBool
296 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
298 extern JSBool
299 js_SetDefaultXMLNamespace(JSContext *cx, const js::Value &v);
302 * Return true if v is a XML QName object, or if it converts to a string that
303 * contains a valid XML qualified name (one containing no :), false otherwise.
304 * NB: This function is an infallible predicate, it hides exceptions.
306 extern JSBool
307 js_IsXMLName(JSContext *cx, jsval v);
309 extern JSBool
310 js_ToAttributeName(JSContext *cx, js::Value *vp);
312 extern JSString *
313 js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote);
315 extern JSString *
316 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
317 JSString *str2);
319 extern JSString *
320 js_EscapeElementValue(JSContext *cx, JSString *str);
322 extern JSString *
323 js_ValueToXMLString(JSContext *cx, const js::Value &v);
325 extern JSObject *
326 js_ConstructXMLQNameObject(JSContext *cx, const js::Value & nsval,
327 const js::Value & lnval);
329 extern JSBool
330 js_GetAnyName(JSContext *cx, jsid *idp);
333 * Note: nameval must be either QName, AttributeName, or AnyName.
335 extern JSBool
336 js_FindXMLProperty(JSContext *cx, const js::Value &nameval, JSObject **objp, jsid *idp);
338 extern JSBool
339 js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
341 extern JSBool
342 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
344 extern JSBool
345 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
347 extern JSBool
348 js_StepXMLListFilter(JSContext *cx, JSBool initialized);
350 extern JSObject *
351 js_ValueToXMLObject(JSContext *cx, const js::Value &v);
353 extern JSObject *
354 js_ValueToXMLListObject(JSContext *cx, const js::Value &v);
356 extern JSObject *
357 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
358 JSString *value);
360 extern JSString *
361 js_MakeXMLCDATAString(JSContext *cx, JSString *str);
363 extern JSString *
364 js_MakeXMLCommentString(JSContext *cx, JSString *str);
366 extern JSString *
367 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
369 /* The caller must ensure that either v1 or v2 is an object. */
370 extern JSBool
371 js_TestXMLEquality(JSContext *cx, const js::Value &v1, const js::Value &v2,
372 JSBool *bp);
374 extern JSBool
375 js_ConcatenateXML(JSContext *cx, JSObject *obj1, JSObject *obj2, js::Value *vp);
377 #endif /* jsxml_h___ */