|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implemetation of WidgetEventHandler |
|
15 * |
|
16 */ |
|
17 #include "WidgetEventHandler.h" |
|
18 #include "config.h" |
|
19 #include <kjs/object.h> |
|
20 |
|
21 // ============================ MEMBER FUNCTIONS =============================== |
|
22 using namespace KJS; |
|
23 |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // WidgetEventHandler::WidgetEventHandler |
|
27 // |
|
28 // |
|
29 // |
|
30 // ---------------------------------------------------------------------------- |
|
31 WidgetEventHandler::WidgetEventHandler( JSValue* aValue, ExecState* aExecState ) : iGlobalExecState (aExecState) |
|
32 { |
|
33 iEventHandler = aValue; |
|
34 Collector::protect(iEventHandler); |
|
35 } |
|
36 |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // WidgetEventHandler::~WidgetEventHandler |
|
40 // |
|
41 // |
|
42 // |
|
43 // ---------------------------------------------------------------------------- |
|
44 WidgetEventHandler::~WidgetEventHandler() |
|
45 { |
|
46 Collector::unprotect(iEventHandler); |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // WidgetEventHandler::Delete |
|
51 // Delete event handler if it isn't handling an event |
|
52 // If InvokeCall is executing then delete after it's done. |
|
53 // |
|
54 // ---------------------------------------------------------------------------- |
|
55 void WidgetEventHandler::Delete() |
|
56 { |
|
57 if (iInUse) { |
|
58 iSelfDelete = ETrue; |
|
59 } |
|
60 else { |
|
61 delete this; |
|
62 } |
|
63 |
|
64 } |
|
65 // ---------------------------------------------------------------------------- |
|
66 // WidgetEventHandler::InvokeCall |
|
67 // Invokes the callback function |
|
68 // |
|
69 // |
|
70 // ---------------------------------------------------------------------------- |
|
71 void WidgetEventHandler::InvokeCall( const TInt& aParam ) |
|
72 { |
|
73 |
|
74 iInUse = ETrue; |
|
75 if (iEventHandler) { |
|
76 |
|
77 JSLock::lock(); |
|
78 if (iGlobalExecState && |
|
79 iGlobalExecState->dynamicInterpreter()) |
|
80 { |
|
81 |
|
82 if (iEventHandler && |
|
83 !iEventHandler->isNull() && |
|
84 iEventHandler->isObject()) { |
|
85 |
|
86 KJS::List args; |
|
87 if ( aParam != -1 ) { |
|
88 args.append( jsNumber(aParam) ); |
|
89 } |
|
90 |
|
91 JSObject* objFunc = static_cast<JSObject*>(iEventHandler); |
|
92 if (objFunc->implementsCall()) { |
|
93 objFunc->call(iGlobalExecState,iGlobalExecState->dynamicInterpreter()->globalObject(),args); |
|
94 } |
|
95 |
|
96 if ( iGlobalExecState->hadException() ) { |
|
97 iGlobalExecState->clearException(); |
|
98 } |
|
99 } |
|
100 |
|
101 } |
|
102 |
|
103 JSLock::unlock(); |
|
104 } |
|
105 |
|
106 iInUse = EFalse; |
|
107 if (iSelfDelete) |
|
108 { |
|
109 delete this; |
|
110 } |
|
111 |
|
112 } |
|
113 |