1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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
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.
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 nsIScriptObjectOwner_h__
39 #define nsIScriptObjectOwner_h__
41 #include "nsISupports.h"
42 #include "nsIScriptContext.h"
43 #include "nsAString.h"
45 class nsScriptObjectHolder
;
47 #define NS_ISCRIPTOBJECTOWNER_IID \
48 { /* 8f6bca7e-ce42-11d1-b724-00600891d8c9 */ \
49 0x8f6bca7e, 0xce42, 0x11d1, \
50 {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } \
53 * Creates a link between the script object and its native implementation
55 * Every object that wants to be exposed in a script environment should
56 * implement this interface. This interface should guarantee that the same
57 * script object is returned in the context of the same script.
58 * <P><I>It does have a bit too much java script information now, that
59 * should be removed in a short time. Ideally this interface will be
60 * language neutral</I>
62 class nsIScriptObjectOwner
: public nsISupports
{
64 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTOBJECTOWNER_IID
)
67 * Return the script object associated with this object.
68 * Create a script object if not present.
70 * @param aContext the context the script object has to be created in
71 * @param aScriptObject on return will contain the script object
73 * @return nsresult NS_OK if the script object is successfully returned
76 NS_IMETHOD
GetScriptObject(nsIScriptContext
*aContext
, void** aScriptObject
) = 0;
79 * Set the script object associated with this object.
80 * Often used to either reset the object to null or initially
81 * set it in cases where the object comes before the owner.
83 * @param aScriptObject the script object to set
85 * @return nsresult NS_OK if the script object is successfully set
88 NS_IMETHOD
SetScriptObject(void* aScriptObject
) = 0;
91 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptObjectOwner
,
92 NS_ISCRIPTOBJECTOWNER_IID
)
96 #define NS_ISCRIPTEVENTHANDLEROWNER_IID \
97 { /* 2ad54ae0-a839-11d3-ba97-00104ba02d3d */ \
98 0x2ad54ae0, 0xa839, 0x11d3, \
99 {0xba, 0x97, 0x00, 0x10, 0x4b, 0xa0, 0x2d, 0x3d} }
102 * Associate a compiled event handler with its target object, which owns it
103 * This is an adjunct to nsIScriptObjectOwner that nsIEventListenerManager's
104 * implementation queries for, in order to avoid recompiling a recurrent or
105 * prototype-inherited event handler.
107 class nsIScriptEventHandlerOwner
: public nsISupports
110 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTEVENTHANDLEROWNER_IID
)
113 * Compile the specified event handler, and bind it to aTarget using
116 * @param aContext the context to use when creating event handler
117 * @param aTarget the object to which to bind the event handler
118 * @param aName the name of the handler
119 * @param aBody the handler script body
120 * @param aURL the URL or filename for error messages
121 * @param aLineNo the starting line number of the script for error messages
122 * @param aHandler the holder for the compiled, bound handler object
124 virtual nsresult
CompileEventHandler(nsIScriptContext
* aContext
,
125 nsISupports
* aTarget
,
127 const nsAString
& aBody
,
130 nsScriptObjectHolder
&aHandler
) = 0;
133 * Retrieve an already-compiled event handler that can be bound to a
134 * target object using a script context.
136 * @param aName the name of the event handler to retrieve
137 * @param aHandler the holder for the compiled event handler.
139 virtual nsresult
GetCompiledEventHandler(nsIAtom
*aName
,
140 nsScriptObjectHolder
&aHandler
) = 0;
143 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptEventHandlerOwner
,
144 NS_ISCRIPTEVENTHANDLEROWNER_IID
)
146 #endif // nsIScriptObjectOwner_h__