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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsIScriptObjectOwner_h__
39 : #define nsIScriptObjectOwner_h__
40 :
41 : #include "nsISupports.h"
42 : #include "nsIScriptContext.h"
43 : #include "nsAString.h"
44 :
45 : template<class> class nsScriptObjectHolder;
46 :
47 : #define NS_ISCRIPTOBJECTOWNER_IID \
48 : { /* 8f6bca7e-ce42-11d1-b724-00600891d8c9 */ \
49 : 0x8f6bca7e, 0xce42, 0x11d1, \
50 : {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } \
51 :
52 : /**
53 : * Creates a link between the script object and its native implementation
54 : *<P>
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>
61 : */
62 : class nsIScriptObjectOwner : public nsISupports {
63 : public:
64 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTOBJECTOWNER_IID)
65 :
66 : /**
67 : * Return the script object associated with this object.
68 : * Create a script object if not present.
69 : *
70 : * @param aContext the context the script object has to be created in
71 : * @param aScriptObject on return will contain the script object
72 : *
73 : * @return nsresult NS_OK if the script object is successfully returned
74 : *
75 : **/
76 : NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) = 0;
77 :
78 : /**
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.
82 : *
83 : * @param aScriptObject the script object to set
84 : *
85 : * @return nsresult NS_OK if the script object is successfully set
86 : *
87 : **/
88 : NS_IMETHOD SetScriptObject(void* aScriptObject) = 0;
89 : };
90 :
91 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptObjectOwner,
92 : NS_ISCRIPTOBJECTOWNER_IID)
93 :
94 : class nsIAtom;
95 :
96 : #define NS_ISCRIPTEVENTHANDLEROWNER_IID \
97 : { 0xc8f35f71, 0x07d1, 0x4ff3, \
98 : { 0xa3, 0x2f, 0x65, 0xcb, 0x35, 0x64, 0xac, 0xe0 } }
99 :
100 : /**
101 : * Associate a compiled event handler with its target object, which owns it
102 : * This is an adjunct to nsIScriptObjectOwner that nsEventListenerManager's
103 : * implementation queries for, in order to avoid recompiling a recurrent or
104 : * prototype-inherited event handler.
105 : */
106 : class nsIScriptEventHandlerOwner : public nsISupports
107 0 : {
108 : public:
109 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTEVENTHANDLEROWNER_IID)
110 :
111 : /**
112 : * Compile the specified event handler. This does NOT bind it to
113 : * anything. That's the caller's responsibility.
114 : *
115 : * @param aContext the context to use when creating event handler
116 : * @param aName the name of the handler
117 : * @param aBody the handler script body
118 : * @param aURL the URL or filename for error messages
119 : * @param aLineNo the starting line number of the script for error messages
120 : * @param aHandler the holder for the compiled handler object
121 : */
122 : virtual nsresult CompileEventHandler(nsIScriptContext* aContext,
123 : nsIAtom *aName,
124 : const nsAString& aBody,
125 : const char* aURL,
126 : PRUint32 aLineNo,
127 : nsScriptObjectHolder<JSObject>& aHandler) = 0;
128 :
129 : /**
130 : * Retrieve an already-compiled event handler that can be bound to a
131 : * target object using a script context.
132 : *
133 : * @param aName the name of the event handler to retrieve
134 : * @param aHandler the holder for the compiled event handler.
135 : */
136 : virtual nsresult GetCompiledEventHandler(nsIAtom *aName,
137 : nsScriptObjectHolder<JSObject>& aHandler) = 0;
138 : };
139 :
140 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptEventHandlerOwner,
141 : NS_ISCRIPTEVENTHANDLEROWNER_IID)
142 :
143 : #endif // nsIScriptObjectOwner_h__
|