|
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/. */ |
|
5 |
|
6 /** |
|
7 * This file defines enum values for all of the DOM objects which have |
|
8 * an entry in nsDOMClassInfo. |
|
9 */ |
|
10 |
|
11 #ifndef nsDOMClassInfoID_h__ |
|
12 #define nsDOMClassInfoID_h__ |
|
13 |
|
14 #include "nsIXPCScriptable.h" |
|
15 |
|
16 #define DOMCI_CLASS(_dom_class) \ |
|
17 eDOMClassInfo_##_dom_class##_id, |
|
18 |
|
19 enum nsDOMClassInfoID { |
|
20 |
|
21 #include "nsDOMClassInfoClasses.h" |
|
22 |
|
23 // This one better be the last one in this list |
|
24 eDOMClassInfoIDCount |
|
25 }; |
|
26 |
|
27 #undef DOMCI_CLASS |
|
28 |
|
29 /** |
|
30 * nsIClassInfo helper macros |
|
31 */ |
|
32 |
|
33 /** |
|
34 * !! THIS MECHANISM IS DEPRECATED, DO NOT ADD MORE INTERFACE TO THESE LISTS !! |
|
35 * |
|
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. |
|
42 * |
|
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 |
|
47 * bindings. |
|
48 */ |
|
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,\ |
|
53 1, _extra) \ |
|
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) |
|
70 |
|
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 |
|
78 namespace mozilla { |
|
79 namespace dom { |
|
80 class Element; |
|
81 class Event; |
|
82 class EventTarget; |
|
83 class MouseEvent; |
|
84 class UIEvent; |
|
85 } // namespace dom |
|
86 } // namespace mozilla |
|
87 |
|
88 #define DOMCI_CASTABLE_NODECL_INTERFACE DOMCI_CASTABLE_INTERFACE |
|
89 |
|
90 #ifdef MOZILLA_INTERNAL_API |
|
91 |
|
92 #define DOMCI_CLASS(_dom_class) \ |
|
93 extern const uint32_t kDOMClassInfo_##_dom_class##_interfaces; |
|
94 |
|
95 #include "nsDOMClassInfoClasses.h" |
|
96 |
|
97 #undef DOMCI_CLASS |
|
98 |
|
99 /** |
|
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. |
|
103 */ |
|
104 |
|
105 #if defined(__GNUC__) || _MSC_FULL_VER >= 140050215 |
|
106 |
|
107 /* Use a compiler intrinsic if one is available. */ |
|
108 |
|
109 #define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class) |
|
110 |
|
111 #else |
|
112 |
|
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. |
|
119 */ |
|
120 |
|
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*); |
|
126 }; |
|
127 |
|
128 #define DOMCI_CASTABLE_TO(_interface, _class) \ |
|
129 (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \ |
|
130 sizeof(DOMCI_CastableTo<_interface>::true_type)) |
|
131 |
|
132 #endif |
|
133 |
|
134 /** |
|
135 * Here we calculate the bitmap for a given class. |
|
136 */ |
|
137 #define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \ |
|
138 (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) + |
|
139 |
|
140 #define DOMCI_DATA(_dom_class, _class) \ |
|
141 const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \ |
|
142 DOMCI_CASTABLE_INTERFACES(_class) \ |
|
143 0; |
|
144 |
|
145 class nsIClassInfo; |
|
146 class nsXPCClassInfo; |
|
147 |
|
148 extern nsIClassInfo* |
|
149 NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); |
|
150 |
|
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; \ |
|
158 } \ |
|
159 } else |
|
160 |
|
161 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \ |
|
162 if ((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; \ |
|
169 } \ |
|
170 } else |
|
171 |
|
172 #else |
|
173 |
|
174 // See nsIDOMClassInfo.h |
|
175 |
|
176 #endif // MOZILLA_INTERNAL_API |
|
177 |
|
178 #endif // nsDOMClassInfoID_h__ |