1 /* -*- Mode: C++; tab-width: 2; 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/. */
7 * This file defines enum values for all of the DOM objects which have
8 * an entry in nsDOMClassInfo.
11 #ifndef nsDOMClassInfoID_h__
12 #define nsDOMClassInfoID_h__
14 #include "nsIXPCScriptable.h"
16 #define DOMCI_CLASS(_dom_class) \
17 eDOMClassInfo_##_dom_class##_id,
19 enum nsDOMClassInfoID
{
21 #include "nsDOMClassInfoClasses.h"
23 // This one better be the last one in this list
30 * nsIClassInfo helper macros
34 * !! THIS MECHANISM IS DEPRECATED, DO NOT ADD MORE INTERFACE TO THESE LISTS !!
36 * DOMCI_CASTABLE_INTERFACES contains the list of interfaces that we have a bit
37 * for in nsDOMClassInfo's mInterfacesBitmap. To use it you need to define
38 * DOMCI_CASTABLE_INTERFACE(interface, bit, extra) and then call
39 * DOMCI_CASTABLE_INTERFACES(extra). For every interface there will be one
40 * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and
41 * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES.
43 * WARNING: Be very careful when adding interfaces to this list. Every object
44 * that implements one of these interfaces must be directly castable
45 * to that interface from the *canonical* nsISupports! Also, none of
46 * the objects that implement these interfaces may use the new DOM
49 #undef DOMCI_CASTABLE_INTERFACE
50 #define DOMCI_CASTABLE_INTERFACES(_extra) \
51 DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \
52 DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Element, mozilla::dom::Element,\
54 /* If this is ever removed, the IID for EventTarget can go away */ \
55 DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::EventTarget, \
56 mozilla::dom::EventTarget, 2, _extra) \
57 DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Event, nsIDOMEvent, 3, _extra) \
58 DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 4, _extra) \
59 DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 5, _extra) \
60 DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsIContent, 6, _extra) \
61 DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 7, _extra) \
62 DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 8, _extra) \
63 DOMCI_CASTABLE_INTERFACE(nsSVGElement, nsIContent, 9, _extra) \
64 /* NOTE: When removing the casts below, remove the dom::EventBase class */ \
65 DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::MouseEvent, \
66 mozilla::dom::EventBase, 10, _extra) \
67 DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::UIEvent, \
68 mozilla::dom::EventBase, 11, _extra) \
69 DOMCI_CASTABLE_INTERFACE(nsGlobalWindow, nsIDOMEventTarget, 12, _extra)
71 // Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES
72 // have been declared.
73 #define DOMCI_CASTABLE_NODECL_INTERFACE(_interface, _u1, _u2, _u3) /* Nothing */
74 #define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface;
75 DOMCI_CASTABLE_INTERFACES(unused
)
76 #undef DOMCI_CASTABLE_INTERFACE
77 #undef DOMCI_CASTABLE_NODECL_INTERFACE
86 } // namespace mozilla
88 #define DOMCI_CASTABLE_NODECL_INTERFACE DOMCI_CASTABLE_INTERFACE
90 #ifdef MOZILLA_INTERNAL_API
92 #define DOMCI_CLASS(_dom_class) \
93 extern const uint32_t kDOMClassInfo_##_dom_class##_interfaces;
95 #include "nsDOMClassInfoClasses.h"
100 * Provide a general "does class C implement interface I" predicate.
101 * This is not as sophisticated as e.g. boost's is_base_of template,
102 * but it does the job adequately for our purposes.
105 #if defined(__GNUC__) || _MSC_FULL_VER >= 140050215
107 /* Use a compiler intrinsic if one is available. */
109 #define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class)
113 /* The generic version of this predicate relies on the overload resolution
114 * rules. If |_class| inherits from |_interface|, the |_interface*|
115 * overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise
116 * the |void*| overload will be chosen. There is no definition of these
117 * functions; we determine which overload was selected by inspecting the
118 * size of the return type.
121 template <typename Interface
> struct DOMCI_CastableTo
{
122 struct false_type
{ int x
[1]; };
123 struct true_type
{ int x
[2]; };
124 static false_type
p(void*);
125 static true_type
p(Interface
*);
128 #define DOMCI_CASTABLE_TO(_interface, _class) \
129 (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \
130 sizeof(DOMCI_CastableTo<_interface>::true_type))
135 * Here we calculate the bitmap for a given class.
137 #define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \
138 (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) +
140 #define DOMCI_DATA(_dom_class, _class) \
141 const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \
142 DOMCI_CASTABLE_INTERFACES(_class) \
146 class nsXPCClassInfo
;
149 NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID
);
151 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \
152 if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \
153 aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \
154 foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \
155 if (!foundInterface) { \
156 *aInstancePtr = nullptr; \
157 return NS_ERROR_OUT_OF_MEMORY; \
161 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \
163 (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \
164 aIID.Equals(NS_GET_IID(nsXPCClassInfo)))) { \
165 foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \
166 if (!foundInterface) { \
167 *aInstancePtr = nullptr; \
168 return NS_ERROR_OUT_OF_MEMORY; \
174 // See nsIDOMClassInfo.h
176 #endif // MOZILLA_INTERNAL_API
178 #endif // nsDOMClassInfoID_h__