michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This file defines enum values for all of the DOM objects which have michael@0: * an entry in nsDOMClassInfo. michael@0: */ michael@0: michael@0: #ifndef nsDOMClassInfoID_h__ michael@0: #define nsDOMClassInfoID_h__ michael@0: michael@0: #include "nsIXPCScriptable.h" michael@0: michael@0: #define DOMCI_CLASS(_dom_class) \ michael@0: eDOMClassInfo_##_dom_class##_id, michael@0: michael@0: enum nsDOMClassInfoID { michael@0: michael@0: #include "nsDOMClassInfoClasses.h" michael@0: michael@0: // This one better be the last one in this list michael@0: eDOMClassInfoIDCount michael@0: }; michael@0: michael@0: #undef DOMCI_CLASS michael@0: michael@0: /** michael@0: * nsIClassInfo helper macros michael@0: */ michael@0: michael@0: /** michael@0: * !! THIS MECHANISM IS DEPRECATED, DO NOT ADD MORE INTERFACE TO THESE LISTS !! michael@0: * michael@0: * DOMCI_CASTABLE_INTERFACES contains the list of interfaces that we have a bit michael@0: * for in nsDOMClassInfo's mInterfacesBitmap. To use it you need to define michael@0: * DOMCI_CASTABLE_INTERFACE(interface, bit, extra) and then call michael@0: * DOMCI_CASTABLE_INTERFACES(extra). For every interface there will be one michael@0: * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and michael@0: * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES. michael@0: * michael@0: * WARNING: Be very careful when adding interfaces to this list. Every object michael@0: * that implements one of these interfaces must be directly castable michael@0: * to that interface from the *canonical* nsISupports! Also, none of michael@0: * the objects that implement these interfaces may use the new DOM michael@0: * bindings. michael@0: */ michael@0: #undef DOMCI_CASTABLE_INTERFACE michael@0: #define DOMCI_CASTABLE_INTERFACES(_extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \ michael@0: DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Element, mozilla::dom::Element,\ michael@0: 1, _extra) \ michael@0: /* If this is ever removed, the IID for EventTarget can go away */ \ michael@0: DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::EventTarget, \ michael@0: mozilla::dom::EventTarget, 2, _extra) \ michael@0: DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Event, nsIDOMEvent, 3, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 4, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 5, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsIContent, 6, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 7, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 8, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsSVGElement, nsIContent, 9, _extra) \ michael@0: /* NOTE: When removing the casts below, remove the dom::EventBase class */ \ michael@0: DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::MouseEvent, \ michael@0: mozilla::dom::EventBase, 10, _extra) \ michael@0: DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::UIEvent, \ michael@0: mozilla::dom::EventBase, 11, _extra) \ michael@0: DOMCI_CASTABLE_INTERFACE(nsGlobalWindow, nsIDOMEventTarget, 12, _extra) michael@0: michael@0: // Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES michael@0: // have been declared. michael@0: #define DOMCI_CASTABLE_NODECL_INTERFACE(_interface, _u1, _u2, _u3) /* Nothing */ michael@0: #define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface; michael@0: DOMCI_CASTABLE_INTERFACES(unused) michael@0: #undef DOMCI_CASTABLE_INTERFACE michael@0: #undef DOMCI_CASTABLE_NODECL_INTERFACE michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class Element; michael@0: class Event; michael@0: class EventTarget; michael@0: class MouseEvent; michael@0: class UIEvent; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #define DOMCI_CASTABLE_NODECL_INTERFACE DOMCI_CASTABLE_INTERFACE michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: michael@0: #define DOMCI_CLASS(_dom_class) \ michael@0: extern const uint32_t kDOMClassInfo_##_dom_class##_interfaces; michael@0: michael@0: #include "nsDOMClassInfoClasses.h" michael@0: michael@0: #undef DOMCI_CLASS michael@0: michael@0: /** michael@0: * Provide a general "does class C implement interface I" predicate. michael@0: * This is not as sophisticated as e.g. boost's is_base_of template, michael@0: * but it does the job adequately for our purposes. michael@0: */ michael@0: michael@0: #if defined(__GNUC__) || _MSC_FULL_VER >= 140050215 michael@0: michael@0: /* Use a compiler intrinsic if one is available. */ michael@0: michael@0: #define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class) michael@0: michael@0: #else michael@0: michael@0: /* The generic version of this predicate relies on the overload resolution michael@0: * rules. If |_class| inherits from |_interface|, the |_interface*| michael@0: * overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise michael@0: * the |void*| overload will be chosen. There is no definition of these michael@0: * functions; we determine which overload was selected by inspecting the michael@0: * size of the return type. michael@0: */ michael@0: michael@0: template struct DOMCI_CastableTo { michael@0: struct false_type { int x[1]; }; michael@0: struct true_type { int x[2]; }; michael@0: static false_type p(void*); michael@0: static true_type p(Interface*); michael@0: }; michael@0: michael@0: #define DOMCI_CASTABLE_TO(_interface, _class) \ michael@0: (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \ michael@0: sizeof(DOMCI_CastableTo<_interface>::true_type)) michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Here we calculate the bitmap for a given class. michael@0: */ michael@0: #define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \ michael@0: (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) + michael@0: michael@0: #define DOMCI_DATA(_dom_class, _class) \ michael@0: const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \ michael@0: DOMCI_CASTABLE_INTERFACES(_class) \ michael@0: 0; michael@0: michael@0: class nsIClassInfo; michael@0: class nsXPCClassInfo; michael@0: michael@0: extern nsIClassInfo* michael@0: NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); michael@0: michael@0: #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ michael@0: if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ michael@0: aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ michael@0: foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ michael@0: if (!foundInterface) { \ michael@0: *aInstancePtr = nullptr; \ michael@0: return NS_ERROR_OUT_OF_MEMORY; \ michael@0: } \ michael@0: } else michael@0: michael@0: #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \ michael@0: if ((condition) && \ michael@0: (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ michael@0: aIID.Equals(NS_GET_IID(nsXPCClassInfo)))) { \ michael@0: foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ michael@0: if (!foundInterface) { \ michael@0: *aInstancePtr = nullptr; \ michael@0: return NS_ERROR_OUT_OF_MEMORY; \ michael@0: } \ michael@0: } else michael@0: michael@0: #else michael@0: michael@0: // See nsIDOMClassInfo.h michael@0: michael@0: #endif // MOZILLA_INTERNAL_API michael@0: michael@0: #endif // nsDOMClassInfoID_h__