Bug 627938: Fix nsGlobalChromeWindow cleanup. (r=smaug, a=jst)
[mozilla-central.git] / dom / base / nsDOMClassInfoID.h
blob6c5eaa88db43a932ab99e147450f80ac14b527b6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2000
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Johnny Stenback <jst@netscape.com> (original author)
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 /**
40 * This file defines enum values for all of the DOM objects which have
41 * an entry in nsDOMClassInfo.
44 #ifndef nsDOMClassInfoID_h__
45 #define nsDOMClassInfoID_h__
47 #define DOMCI_CLASS(_dom_class) \
48 eDOMClassInfo_##_dom_class##_id,
50 enum nsDOMClassInfoID {
52 #include "nsDOMClassInfoClasses.h"
54 // This one better be the last one in this list
55 eDOMClassInfoIDCount
58 #undef DOMCI_CLASS
60 /**
61 * nsIClassInfo helper macros
64 /**
65 * DOMCI_CASTABLE_INTERFACES contains the list of interfaces that we have a bit
66 * for in nsDOMClassInfo's mInterfacesBitmap. To use it you need to define
67 * DOMCI_CASTABLE_INTERFACE(interface, bit, extra) and then call
68 * DOMCI_CASTABLE_INTERFACES(extra). For every interface there will be one
69 * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and
70 * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES.
72 * WARNING: Be very careful when adding interfaces to this list. Every object
73 * that implements one of these interfaces must be directly castable
74 * to that interface from the *canonical* nsISupports!
76 #define DOMCI_CASTABLE_INTERFACES(_extra) \
77 DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \
78 DOMCI_CASTABLE_INTERFACE(nsIContent, nsIContent, 1, _extra) \
79 DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 2, _extra) \
80 DOMCI_CASTABLE_INTERFACE(nsINodeList, nsINodeList, 3, _extra) \
81 DOMCI_CASTABLE_INTERFACE(nsICSSDeclaration, nsICSSDeclaration, 4, _extra) \
82 DOMCI_CASTABLE_INTERFACE(nsGenericTextNode, nsGenericTextNode, 5, _extra) \
83 DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 6, _extra) \
84 DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsGenericHTMLElement, 7, \
85 _extra) \
86 DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 8, _extra) \
87 DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 9, _extra) \
88 DOMCI_CASTABLE_INTERFACE(nsSVGStylableElement, nsIContent, 10, _extra)
90 // Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES
91 // have been declared.
92 #define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface;
93 DOMCI_CASTABLE_INTERFACES(unused)
94 #undef DOMCI_CASTABLE_INTERFACE
96 #ifdef _IMPL_NS_LAYOUT
98 #define DOMCI_CLASS(_dom_class) \
99 extern const PRUint32 kDOMClassInfo_##_dom_class##_interfaces;
101 #include "nsDOMClassInfoClasses.h"
103 #undef DOMCI_CLASS
106 * Provide a general "does class C implement interface I" predicate.
107 * This is not as sophisticated as e.g. boost's is_base_of template,
108 * but it does the job adequately for our purposes.
111 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || \
112 _MSC_FULL_VER >= 140050215
114 /* Use a compiler intrinsic if one is available. */
116 #define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class)
118 #else
120 /* The generic version of this predicate relies on the overload resolution
121 * rules. If |_class| inherits from |_interface|, the |_interface*|
122 * overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise
123 * the |void*| overload will be chosen. There is no definition of these
124 * functions; we determine which overload was selected by inspecting the
125 * size of the return type.
128 template <typename Interface> struct DOMCI_CastableTo {
129 struct false_type { int x[1]; };
130 struct true_type { int x[2]; };
131 static false_type p(void*);
132 static true_type p(Interface*);
135 #define DOMCI_CASTABLE_TO(_interface, _class) \
136 (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \
137 sizeof(DOMCI_CastableTo<_interface>::true_type))
139 #endif
142 * Here we calculate the bitmap for a given class.
144 #define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \
145 (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) +
147 #define DOMCI_DATA(_dom_class, _class) \
148 const PRUint32 kDOMClassInfo_##_dom_class##_interfaces = \
149 DOMCI_CASTABLE_INTERFACES(_class) \
152 class nsIClassInfo;
153 class nsXPCClassInfo;
155 extern nsIClassInfo*
156 NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID);
158 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \
159 if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \
160 aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \
161 foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \
162 if (!foundInterface) { \
163 *aInstancePtr = nsnull; \
164 return NS_ERROR_OUT_OF_MEMORY; \
166 } else
168 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \
169 if ((condition) && \
170 (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \
171 aIID.Equals(NS_GET_IID(nsXPCClassInfo)))) { \
172 foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \
173 if (!foundInterface) { \
174 *aInstancePtr = nsnull; \
175 return NS_ERROR_OUT_OF_MEMORY; \
177 } else
179 #else
181 // See nsIDOMClassInfo.h
183 #endif // _IMPL_NS_LAYOUT
185 #endif // nsDOMClassInfoID_h__