Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /** |
michael@0 | 7 | * This file defines enum values for all of the DOM objects which have |
michael@0 | 8 | * an entry in nsDOMClassInfo. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef nsDOMClassInfoID_h__ |
michael@0 | 12 | #define nsDOMClassInfoID_h__ |
michael@0 | 13 | |
michael@0 | 14 | #include "nsIXPCScriptable.h" |
michael@0 | 15 | |
michael@0 | 16 | #define DOMCI_CLASS(_dom_class) \ |
michael@0 | 17 | eDOMClassInfo_##_dom_class##_id, |
michael@0 | 18 | |
michael@0 | 19 | enum nsDOMClassInfoID { |
michael@0 | 20 | |
michael@0 | 21 | #include "nsDOMClassInfoClasses.h" |
michael@0 | 22 | |
michael@0 | 23 | // This one better be the last one in this list |
michael@0 | 24 | eDOMClassInfoIDCount |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | #undef DOMCI_CLASS |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * nsIClassInfo helper macros |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * !! THIS MECHANISM IS DEPRECATED, DO NOT ADD MORE INTERFACE TO THESE LISTS !! |
michael@0 | 35 | * |
michael@0 | 36 | * DOMCI_CASTABLE_INTERFACES contains the list of interfaces that we have a bit |
michael@0 | 37 | * for in nsDOMClassInfo's mInterfacesBitmap. To use it you need to define |
michael@0 | 38 | * DOMCI_CASTABLE_INTERFACE(interface, bit, extra) and then call |
michael@0 | 39 | * DOMCI_CASTABLE_INTERFACES(extra). For every interface there will be one |
michael@0 | 40 | * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and |
michael@0 | 41 | * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES. |
michael@0 | 42 | * |
michael@0 | 43 | * WARNING: Be very careful when adding interfaces to this list. Every object |
michael@0 | 44 | * that implements one of these interfaces must be directly castable |
michael@0 | 45 | * to that interface from the *canonical* nsISupports! Also, none of |
michael@0 | 46 | * the objects that implement these interfaces may use the new DOM |
michael@0 | 47 | * bindings. |
michael@0 | 48 | */ |
michael@0 | 49 | #undef DOMCI_CASTABLE_INTERFACE |
michael@0 | 50 | #define DOMCI_CASTABLE_INTERFACES(_extra) \ |
michael@0 | 51 | DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \ |
michael@0 | 52 | DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Element, mozilla::dom::Element,\ |
michael@0 | 53 | 1, _extra) \ |
michael@0 | 54 | /* If this is ever removed, the IID for EventTarget can go away */ \ |
michael@0 | 55 | DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::EventTarget, \ |
michael@0 | 56 | mozilla::dom::EventTarget, 2, _extra) \ |
michael@0 | 57 | DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Event, nsIDOMEvent, 3, _extra) \ |
michael@0 | 58 | DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 4, _extra) \ |
michael@0 | 59 | DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 5, _extra) \ |
michael@0 | 60 | DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsIContent, 6, _extra) \ |
michael@0 | 61 | DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 7, _extra) \ |
michael@0 | 62 | DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 8, _extra) \ |
michael@0 | 63 | DOMCI_CASTABLE_INTERFACE(nsSVGElement, nsIContent, 9, _extra) \ |
michael@0 | 64 | /* NOTE: When removing the casts below, remove the dom::EventBase class */ \ |
michael@0 | 65 | DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::MouseEvent, \ |
michael@0 | 66 | mozilla::dom::EventBase, 10, _extra) \ |
michael@0 | 67 | DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::UIEvent, \ |
michael@0 | 68 | mozilla::dom::EventBase, 11, _extra) \ |
michael@0 | 69 | DOMCI_CASTABLE_INTERFACE(nsGlobalWindow, nsIDOMEventTarget, 12, _extra) |
michael@0 | 70 | |
michael@0 | 71 | // Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES |
michael@0 | 72 | // have been declared. |
michael@0 | 73 | #define DOMCI_CASTABLE_NODECL_INTERFACE(_interface, _u1, _u2, _u3) /* Nothing */ |
michael@0 | 74 | #define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface; |
michael@0 | 75 | DOMCI_CASTABLE_INTERFACES(unused) |
michael@0 | 76 | #undef DOMCI_CASTABLE_INTERFACE |
michael@0 | 77 | #undef DOMCI_CASTABLE_NODECL_INTERFACE |
michael@0 | 78 | namespace mozilla { |
michael@0 | 79 | namespace dom { |
michael@0 | 80 | class Element; |
michael@0 | 81 | class Event; |
michael@0 | 82 | class EventTarget; |
michael@0 | 83 | class MouseEvent; |
michael@0 | 84 | class UIEvent; |
michael@0 | 85 | } // namespace dom |
michael@0 | 86 | } // namespace mozilla |
michael@0 | 87 | |
michael@0 | 88 | #define DOMCI_CASTABLE_NODECL_INTERFACE DOMCI_CASTABLE_INTERFACE |
michael@0 | 89 | |
michael@0 | 90 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 91 | |
michael@0 | 92 | #define DOMCI_CLASS(_dom_class) \ |
michael@0 | 93 | extern const uint32_t kDOMClassInfo_##_dom_class##_interfaces; |
michael@0 | 94 | |
michael@0 | 95 | #include "nsDOMClassInfoClasses.h" |
michael@0 | 96 | |
michael@0 | 97 | #undef DOMCI_CLASS |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * Provide a general "does class C implement interface I" predicate. |
michael@0 | 101 | * This is not as sophisticated as e.g. boost's is_base_of template, |
michael@0 | 102 | * but it does the job adequately for our purposes. |
michael@0 | 103 | */ |
michael@0 | 104 | |
michael@0 | 105 | #if defined(__GNUC__) || _MSC_FULL_VER >= 140050215 |
michael@0 | 106 | |
michael@0 | 107 | /* Use a compiler intrinsic if one is available. */ |
michael@0 | 108 | |
michael@0 | 109 | #define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class) |
michael@0 | 110 | |
michael@0 | 111 | #else |
michael@0 | 112 | |
michael@0 | 113 | /* The generic version of this predicate relies on the overload resolution |
michael@0 | 114 | * rules. If |_class| inherits from |_interface|, the |_interface*| |
michael@0 | 115 | * overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise |
michael@0 | 116 | * the |void*| overload will be chosen. There is no definition of these |
michael@0 | 117 | * functions; we determine which overload was selected by inspecting the |
michael@0 | 118 | * size of the return type. |
michael@0 | 119 | */ |
michael@0 | 120 | |
michael@0 | 121 | template <typename Interface> struct DOMCI_CastableTo { |
michael@0 | 122 | struct false_type { int x[1]; }; |
michael@0 | 123 | struct true_type { int x[2]; }; |
michael@0 | 124 | static false_type p(void*); |
michael@0 | 125 | static true_type p(Interface*); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | #define DOMCI_CASTABLE_TO(_interface, _class) \ |
michael@0 | 129 | (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \ |
michael@0 | 130 | sizeof(DOMCI_CastableTo<_interface>::true_type)) |
michael@0 | 131 | |
michael@0 | 132 | #endif |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * Here we calculate the bitmap for a given class. |
michael@0 | 136 | */ |
michael@0 | 137 | #define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \ |
michael@0 | 138 | (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) + |
michael@0 | 139 | |
michael@0 | 140 | #define DOMCI_DATA(_dom_class, _class) \ |
michael@0 | 141 | const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \ |
michael@0 | 142 | DOMCI_CASTABLE_INTERFACES(_class) \ |
michael@0 | 143 | 0; |
michael@0 | 144 | |
michael@0 | 145 | class nsIClassInfo; |
michael@0 | 146 | class nsXPCClassInfo; |
michael@0 | 147 | |
michael@0 | 148 | extern nsIClassInfo* |
michael@0 | 149 | NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); |
michael@0 | 150 | |
michael@0 | 151 | #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ |
michael@0 | 152 | if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ |
michael@0 | 153 | aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ |
michael@0 | 154 | foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ |
michael@0 | 155 | if (!foundInterface) { \ |
michael@0 | 156 | *aInstancePtr = nullptr; \ |
michael@0 | 157 | return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 158 | } \ |
michael@0 | 159 | } else |
michael@0 | 160 | |
michael@0 | 161 | #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \ |
michael@0 | 162 | if ((condition) && \ |
michael@0 | 163 | (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ |
michael@0 | 164 | aIID.Equals(NS_GET_IID(nsXPCClassInfo)))) { \ |
michael@0 | 165 | foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ |
michael@0 | 166 | if (!foundInterface) { \ |
michael@0 | 167 | *aInstancePtr = nullptr; \ |
michael@0 | 168 | return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 169 | } \ |
michael@0 | 170 | } else |
michael@0 | 171 | |
michael@0 | 172 | #else |
michael@0 | 173 | |
michael@0 | 174 | // See nsIDOMClassInfo.h |
michael@0 | 175 | |
michael@0 | 176 | #endif // MOZILLA_INTERNAL_API |
michael@0 | 177 | |
michael@0 | 178 | #endif // nsDOMClassInfoID_h__ |