Bug 572417 - Release mouse capture in flash subclass after mouse events get delivered...
[mozilla-central.git] / xpcom / glue / nsComponentManagerUtils.h
blob068648b06364784cf4465fb22a4820424365ecdd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org Code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsComponentManagerUtils_h__
39 #define nsComponentManagerUtils_h__
41 #ifndef nscore_h__
42 #include "nscore.h"
43 #endif
45 #ifndef nsCOMPtr_h__
46 #include "nsCOMPtr.h"
47 #endif
49 #include "nsIFactory.h"
52 NS_COM_GLUE nsresult
53 CallCreateInstance
54 (const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID,
55 void **aResult);
57 NS_COM_GLUE nsresult
58 CallCreateInstance
59 (const char *aContractID, nsISupports *aDelegate, const nsIID &aIID,
60 void **aResult);
62 NS_COM_GLUE nsresult
63 CallGetClassObject
64 (const nsCID &aClass, const nsIID &aIID, void **aResult);
66 NS_COM_GLUE nsresult
67 CallGetClassObject
68 (const char *aContractID, const nsIID &aIID, void **aResult);
71 class NS_COM_GLUE nsCreateInstanceByCID : public nsCOMPtr_helper
73 public:
74 nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
75 : mCID(aCID),
76 mOuter(aOuter),
77 mErrorPtr(aErrorPtr)
79 // nothing else to do here
82 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
84 private:
85 const nsCID& mCID;
86 nsISupports* mOuter;
87 nsresult* mErrorPtr;
90 class NS_COM_GLUE nsCreateInstanceByContractID : public nsCOMPtr_helper
92 public:
93 nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
94 : mContractID(aContractID),
95 mOuter(aOuter),
96 mErrorPtr(aErrorPtr)
98 // nothing else to do here
101 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
103 private:
104 const char* mContractID;
105 nsISupports* mOuter;
106 nsresult* mErrorPtr;
109 class NS_COM_GLUE nsCreateInstanceFromFactory : public nsCOMPtr_helper
111 public:
112 nsCreateInstanceFromFactory( nsIFactory* aFactory, nsISupports* aOuter, nsresult* aErrorPtr )
113 : mFactory(aFactory),
114 mOuter(aOuter),
115 mErrorPtr(aErrorPtr)
117 // nothing else to do here
120 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
122 private:
123 nsIFactory* mFactory;
124 nsISupports* mOuter;
125 nsresult* mErrorPtr;
129 inline
130 const nsCreateInstanceByCID
131 do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
133 return nsCreateInstanceByCID(aCID, 0, error);
136 inline
137 const nsCreateInstanceByCID
138 do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
140 return nsCreateInstanceByCID(aCID, aOuter, error);
143 inline
144 const nsCreateInstanceByContractID
145 do_CreateInstance( const char* aContractID, nsresult* error = 0 )
147 return nsCreateInstanceByContractID(aContractID, 0, error);
150 inline
151 const nsCreateInstanceByContractID
152 do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
154 return nsCreateInstanceByContractID(aContractID, aOuter, error);
157 inline
158 const nsCreateInstanceFromFactory
159 do_CreateInstance( nsIFactory* aFactory, nsresult* error = 0 )
161 return nsCreateInstanceFromFactory(aFactory, 0, error);
164 inline
165 const nsCreateInstanceFromFactory
166 do_CreateInstance( nsIFactory* aFactory, nsISupports* aOuter, nsresult* error = 0 )
168 return nsCreateInstanceFromFactory(aFactory, aOuter, error);
172 class NS_COM_GLUE nsGetClassObjectByCID : public nsCOMPtr_helper
174 public:
175 nsGetClassObjectByCID( const nsCID& aCID, nsresult* aErrorPtr )
176 : mCID(aCID),
177 mErrorPtr(aErrorPtr)
179 // nothing else to do here
182 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
184 private:
185 const nsCID& mCID;
186 nsresult* mErrorPtr;
189 class NS_COM_GLUE nsGetClassObjectByContractID : public nsCOMPtr_helper
191 public:
192 nsGetClassObjectByContractID( const char* aContractID, nsresult* aErrorPtr )
193 : mContractID(aContractID),
194 mErrorPtr(aErrorPtr)
196 // nothing else to do here
199 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
201 private:
202 const char* mContractID;
203 nsresult* mErrorPtr;
207 * do_GetClassObject can be used to improve performance of callers
208 * that call |CreateInstance| many times. They can cache the factory
209 * and call do_CreateInstance or CallCreateInstance with the cached
210 * factory rather than having the component manager retrieve it every
211 * time.
213 inline const nsGetClassObjectByCID
214 do_GetClassObject( const nsCID& aCID, nsresult* error = 0 )
216 return nsGetClassObjectByCID(aCID, error);
219 inline const nsGetClassObjectByContractID
220 do_GetClassObject( const char* aContractID, nsresult* error = 0 )
222 return nsGetClassObjectByContractID(aContractID, error);
225 // type-safe shortcuts for calling |CreateInstance|
226 template <class DestinationType>
227 inline
228 nsresult
229 CallCreateInstance( const nsCID &aClass,
230 nsISupports *aDelegate,
231 DestinationType** aDestination )
233 NS_PRECONDITION(aDestination, "null parameter");
235 return CallCreateInstance(aClass, aDelegate,
236 NS_GET_TEMPLATE_IID(DestinationType),
237 reinterpret_cast<void**>(aDestination));
240 template <class DestinationType>
241 inline
242 nsresult
243 CallCreateInstance( const nsCID &aClass,
244 DestinationType** aDestination )
246 NS_PRECONDITION(aDestination, "null parameter");
248 return CallCreateInstance(aClass, nsnull,
249 NS_GET_TEMPLATE_IID(DestinationType),
250 reinterpret_cast<void**>(aDestination));
253 template <class DestinationType>
254 inline
255 nsresult
256 CallCreateInstance( const char *aContractID,
257 nsISupports *aDelegate,
258 DestinationType** aDestination )
260 NS_PRECONDITION(aContractID, "null parameter");
261 NS_PRECONDITION(aDestination, "null parameter");
263 return CallCreateInstance(aContractID,
264 aDelegate,
265 NS_GET_TEMPLATE_IID(DestinationType),
266 reinterpret_cast<void**>(aDestination));
269 template <class DestinationType>
270 inline
271 nsresult
272 CallCreateInstance( const char *aContractID,
273 DestinationType** aDestination )
275 NS_PRECONDITION(aContractID, "null parameter");
276 NS_PRECONDITION(aDestination, "null parameter");
278 return CallCreateInstance(aContractID, nsnull,
279 NS_GET_TEMPLATE_IID(DestinationType),
280 reinterpret_cast<void**>(aDestination));
283 template <class DestinationType>
284 inline
285 nsresult
286 CallCreateInstance( nsIFactory *aFactory,
287 nsISupports *aDelegate,
288 DestinationType** aDestination )
290 NS_PRECONDITION(aFactory, "null parameter");
291 NS_PRECONDITION(aDestination, "null parameter");
293 return aFactory->CreateInstance(aDelegate,
294 NS_GET_TEMPLATE_IID(DestinationType),
295 reinterpret_cast<void**>(aDestination));
298 template <class DestinationType>
299 inline
300 nsresult
301 CallCreateInstance( nsIFactory *aFactory,
302 DestinationType** aDestination )
304 NS_PRECONDITION(aFactory, "null parameter");
305 NS_PRECONDITION(aDestination, "null parameter");
307 return aFactory->CreateInstance(nsnull,
308 NS_GET_TEMPLATE_IID(DestinationType),
309 reinterpret_cast<void**>(aDestination));
312 template <class DestinationType>
313 inline
314 nsresult
315 CallGetClassObject( const nsCID &aClass,
316 DestinationType** aDestination )
318 NS_PRECONDITION(aDestination, "null parameter");
320 return CallGetClassObject(aClass,
321 NS_GET_TEMPLATE_IID(DestinationType), reinterpret_cast<void**>(aDestination));
324 template <class DestinationType>
325 inline
326 nsresult
327 CallGetClassObject( const char* aContractID,
328 DestinationType** aDestination )
330 NS_PRECONDITION(aDestination, "null parameter");
332 return CallGetClassObject(aContractID,
333 NS_GET_TEMPLATE_IID(DestinationType), reinterpret_cast<void**>(aDestination));
336 #endif /* nsComponentManagerUtils_h__ */