1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsDOMClassInfoID.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,178 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * This file defines enum values for all of the DOM objects which have 1.11 + * an entry in nsDOMClassInfo. 1.12 + */ 1.13 + 1.14 +#ifndef nsDOMClassInfoID_h__ 1.15 +#define nsDOMClassInfoID_h__ 1.16 + 1.17 +#include "nsIXPCScriptable.h" 1.18 + 1.19 +#define DOMCI_CLASS(_dom_class) \ 1.20 + eDOMClassInfo_##_dom_class##_id, 1.21 + 1.22 +enum nsDOMClassInfoID { 1.23 + 1.24 +#include "nsDOMClassInfoClasses.h" 1.25 + 1.26 + // This one better be the last one in this list 1.27 + eDOMClassInfoIDCount 1.28 +}; 1.29 + 1.30 +#undef DOMCI_CLASS 1.31 + 1.32 +/** 1.33 + * nsIClassInfo helper macros 1.34 + */ 1.35 + 1.36 +/** 1.37 + * !! THIS MECHANISM IS DEPRECATED, DO NOT ADD MORE INTERFACE TO THESE LISTS !! 1.38 + * 1.39 + * DOMCI_CASTABLE_INTERFACES contains the list of interfaces that we have a bit 1.40 + * for in nsDOMClassInfo's mInterfacesBitmap. To use it you need to define 1.41 + * DOMCI_CASTABLE_INTERFACE(interface, bit, extra) and then call 1.42 + * DOMCI_CASTABLE_INTERFACES(extra). For every interface there will be one 1.43 + * call to DOMCI_CASTABLE_INTERFACE with the bit that it corresponds to and 1.44 + * the extra argument that was passed in to DOMCI_CASTABLE_INTERFACES. 1.45 + * 1.46 + * WARNING: Be very careful when adding interfaces to this list. Every object 1.47 + * that implements one of these interfaces must be directly castable 1.48 + * to that interface from the *canonical* nsISupports! Also, none of 1.49 + * the objects that implement these interfaces may use the new DOM 1.50 + * bindings. 1.51 + */ 1.52 +#undef DOMCI_CASTABLE_INTERFACE 1.53 +#define DOMCI_CASTABLE_INTERFACES(_extra) \ 1.54 +DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \ 1.55 +DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Element, mozilla::dom::Element,\ 1.56 + 1, _extra) \ 1.57 +/* If this is ever removed, the IID for EventTarget can go away */ \ 1.58 +DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::EventTarget, \ 1.59 + mozilla::dom::EventTarget, 2, _extra) \ 1.60 +DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Event, nsIDOMEvent, 3, _extra) \ 1.61 +DOMCI_CASTABLE_INTERFACE(nsIDocument, nsIDocument, 4, _extra) \ 1.62 +DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 5, _extra) \ 1.63 +DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsIContent, 6, _extra) \ 1.64 +DOMCI_CASTABLE_INTERFACE(nsHTMLDocument, nsIDocument, 7, _extra) \ 1.65 +DOMCI_CASTABLE_INTERFACE(nsStyledElement, nsStyledElement, 8, _extra) \ 1.66 +DOMCI_CASTABLE_INTERFACE(nsSVGElement, nsIContent, 9, _extra) \ 1.67 +/* NOTE: When removing the casts below, remove the dom::EventBase class */ \ 1.68 +DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::MouseEvent, \ 1.69 + mozilla::dom::EventBase, 10, _extra) \ 1.70 +DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::UIEvent, \ 1.71 + mozilla::dom::EventBase, 11, _extra) \ 1.72 +DOMCI_CASTABLE_INTERFACE(nsGlobalWindow, nsIDOMEventTarget, 12, _extra) 1.73 + 1.74 +// Make sure all classes mentioned in DOMCI_CASTABLE_INTERFACES 1.75 +// have been declared. 1.76 +#define DOMCI_CASTABLE_NODECL_INTERFACE(_interface, _u1, _u2, _u3) /* Nothing */ 1.77 +#define DOMCI_CASTABLE_INTERFACE(_interface, _u1, _u2, _u3) class _interface; 1.78 +DOMCI_CASTABLE_INTERFACES(unused) 1.79 +#undef DOMCI_CASTABLE_INTERFACE 1.80 +#undef DOMCI_CASTABLE_NODECL_INTERFACE 1.81 +namespace mozilla { 1.82 +namespace dom { 1.83 +class Element; 1.84 +class Event; 1.85 +class EventTarget; 1.86 +class MouseEvent; 1.87 +class UIEvent; 1.88 +} // namespace dom 1.89 +} // namespace mozilla 1.90 + 1.91 +#define DOMCI_CASTABLE_NODECL_INTERFACE DOMCI_CASTABLE_INTERFACE 1.92 + 1.93 +#ifdef MOZILLA_INTERNAL_API 1.94 + 1.95 +#define DOMCI_CLASS(_dom_class) \ 1.96 + extern const uint32_t kDOMClassInfo_##_dom_class##_interfaces; 1.97 + 1.98 +#include "nsDOMClassInfoClasses.h" 1.99 + 1.100 +#undef DOMCI_CLASS 1.101 + 1.102 +/** 1.103 + * Provide a general "does class C implement interface I" predicate. 1.104 + * This is not as sophisticated as e.g. boost's is_base_of template, 1.105 + * but it does the job adequately for our purposes. 1.106 + */ 1.107 + 1.108 +#if defined(__GNUC__) || _MSC_FULL_VER >= 140050215 1.109 + 1.110 +/* Use a compiler intrinsic if one is available. */ 1.111 + 1.112 +#define DOMCI_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class) 1.113 + 1.114 +#else 1.115 + 1.116 +/* The generic version of this predicate relies on the overload resolution 1.117 + * rules. If |_class| inherits from |_interface|, the |_interface*| 1.118 + * overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise 1.119 + * the |void*| overload will be chosen. There is no definition of these 1.120 + * functions; we determine which overload was selected by inspecting the 1.121 + * size of the return type. 1.122 + */ 1.123 + 1.124 +template <typename Interface> struct DOMCI_CastableTo { 1.125 + struct false_type { int x[1]; }; 1.126 + struct true_type { int x[2]; }; 1.127 + static false_type p(void*); 1.128 + static true_type p(Interface*); 1.129 +}; 1.130 + 1.131 +#define DOMCI_CASTABLE_TO(_interface, _class) \ 1.132 + (sizeof(DOMCI_CastableTo<_interface>::p(static_cast<_class*>(0))) == \ 1.133 + sizeof(DOMCI_CastableTo<_interface>::true_type)) 1.134 + 1.135 +#endif 1.136 + 1.137 +/** 1.138 + * Here we calculate the bitmap for a given class. 1.139 + */ 1.140 +#define DOMCI_CASTABLE_INTERFACE(_interface, _base, _bit, _class) \ 1.141 + (DOMCI_CASTABLE_TO(_interface, _class) ? 1 << _bit : 0) + 1.142 + 1.143 +#define DOMCI_DATA(_dom_class, _class) \ 1.144 +const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \ 1.145 + DOMCI_CASTABLE_INTERFACES(_class) \ 1.146 + 0; 1.147 + 1.148 +class nsIClassInfo; 1.149 +class nsXPCClassInfo; 1.150 + 1.151 +extern nsIClassInfo* 1.152 +NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); 1.153 + 1.154 +#define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ 1.155 + if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ 1.156 + aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ 1.157 + foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ 1.158 + if (!foundInterface) { \ 1.159 + *aInstancePtr = nullptr; \ 1.160 + return NS_ERROR_OUT_OF_MEMORY; \ 1.161 + } \ 1.162 + } else 1.163 + 1.164 +#define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(_class, condition) \ 1.165 + if ((condition) && \ 1.166 + (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ 1.167 + aIID.Equals(NS_GET_IID(nsXPCClassInfo)))) { \ 1.168 + foundInterface = NS_GetDOMClassInfoInstance(eDOMClassInfo_##_class##_id); \ 1.169 + if (!foundInterface) { \ 1.170 + *aInstancePtr = nullptr; \ 1.171 + return NS_ERROR_OUT_OF_MEMORY; \ 1.172 + } \ 1.173 + } else 1.174 + 1.175 +#else 1.176 + 1.177 +// See nsIDOMClassInfo.h 1.178 + 1.179 +#endif // MOZILLA_INTERNAL_API 1.180 + 1.181 +#endif // nsDOMClassInfoID_h__