|
1 /* |
|
2 * Copyright (c) 2004 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <SysUtil.h> |
|
22 #include "../../bidi.h" |
|
23 #include <AknAppUi.h> |
|
24 |
|
25 #include "Widget.h" |
|
26 #include "WidgetFuncs.h" |
|
27 #include "WidgetCallbacks.h" |
|
28 #include "WidgetEventHandler.h" |
|
29 #include "Wrt.h" |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // MACROS |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 using namespace KJS; |
|
47 const ClassInfo JSWidget::info = { "JSWidget", 0, &WidgetTable, 0 }; |
|
48 |
|
49 // ============================= LOCAL FUNCTIONS =============================== |
|
50 /* |
|
51 @begin WidgetTable 16 |
|
52 openApplication JSWidget::openApplication DontDelete|Function 1 |
|
53 openURL JSWidget::openURL DontDelete|Function 1 |
|
54 preferenceForKey JSWidget::preferenceForKey DontDelete|Function 1 |
|
55 prepareForTransition JSWidget::prepareForTransition DontDelete|Function 1 |
|
56 performTransition JSWidget::performTransition DontDelete|Function 0 |
|
57 setPreferenceForKey JSWidget::setPreferenceForKey DontDelete|Function 2 |
|
58 setNavigationEnabled JSWidget::setNavigationEnabled DontDelete|Function 1 |
|
59 identifier JSWidget::identifier DontDelete|ReadOnly |
|
60 onhide JSWidget::onhide DontDelete|ReadOnly |
|
61 onremove JSWidget::onremove DontDelete|ReadOnly |
|
62 onshow JSWidget::onshow DontDelete|ReadOnly |
|
63 onexit JSWidget::onexit DontDelete|ReadOnly |
|
64 setDisplayLandscape JSWidget::setDisplayLandscape DontDelete|Function 0 |
|
65 setDisplayPortrait JSWidget::setDisplayPortrait DontDelete|Function 0 |
|
66 isrotationsupported JSWidget::isRotationSupported DontDelete|ReadOnly |
|
67 wrt JSWidget::wrt DontDelete|ReadOnly |
|
68 @end |
|
69 */ |
|
70 |
|
71 // ============================ MEMBER FUNCTIONS =============================== |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // JSWidget::JSWidget |
|
75 // |
|
76 // |
|
77 // |
|
78 // ---------------------------------------------------------------------------- |
|
79 JSWidget::JSWidget(MJSWidgetCallbacks* aWidgetCallbacks) : |
|
80 JSObject(), |
|
81 d(new WidgetPrivate(aWidgetCallbacks,0,0,0,0)) |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // JSWidget::~JSWidget |
|
87 // |
|
88 // |
|
89 // |
|
90 // ---------------------------------------------------------------------------- |
|
91 JSWidget::~JSWidget() |
|
92 { |
|
93 delete d; |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // JSWidget::type |
|
98 // |
|
99 // |
|
100 // |
|
101 // ---------------------------------------------------------------------------- |
|
102 JSType JSWidget::type() const |
|
103 { |
|
104 return ObjectType; |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // JSWidget::mark |
|
109 // |
|
110 // |
|
111 // |
|
112 // ---------------------------------------------------------------------------- |
|
113 void JSWidget::mark() |
|
114 { |
|
115 JSObject::mark(); |
|
116 if(d->m_wrt) |
|
117 d->m_wrt->mark(); |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // JSWidget::toString |
|
122 // |
|
123 // |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 UString JSWidget::toString(ExecState *exec) const |
|
127 { |
|
128 return "[object JSWidget]"; |
|
129 } |
|
130 |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // JSWidget::getOwnPropertySlot |
|
134 // |
|
135 // |
|
136 // |
|
137 // ---------------------------------------------------------------------------- |
|
138 bool JSWidget::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
139 { |
|
140 const HashEntry* entry = Lookup::findEntry(&WidgetTable, propertyName); |
|
141 if (entry) |
|
142 { |
|
143 slot.setStaticEntry(this, entry, staticValueGetter<JSWidget>); |
|
144 return true; |
|
145 } |
|
146 |
|
147 return JSObject::getOwnPropertySlot(exec, propertyName, slot); |
|
148 } |
|
149 |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // JSWidget::getValueProperty |
|
153 // |
|
154 // |
|
155 // |
|
156 // ---------------------------------------------------------------------------- |
|
157 JSValue* JSWidget::getValueProperty(KJS::ExecState* exec, int token) const |
|
158 { |
|
159 |
|
160 switch (token) { |
|
161 case openApplication: |
|
162 case openURL: |
|
163 case preferenceForKey: |
|
164 case prepareForTransition: |
|
165 case performTransition: |
|
166 case setPreferenceForKey: |
|
167 case setNavigationEnabled: |
|
168 case setDisplayLandscape: |
|
169 case setDisplayPortrait: { |
|
170 JSWidgetFunc *wf = new JSWidgetFunc(exec,token,d->m_callbacks); |
|
171 return wf; |
|
172 } |
|
173 case identifier: { |
|
174 TPtrC tstrUrl(d->m_callbacks->getWidgetBundleId()); |
|
175 return jsString(UString((const KJS::UChar*)tstrUrl.Ptr(), tstrUrl.Length())); |
|
176 } |
|
177 case isRotationSupported: { |
|
178 return jsBoolean(iAvkonAppUi->OrientationCanBeChanged()); |
|
179 } |
|
180 case wrt: { |
|
181 return d->m_wrt ? d->m_wrt : d->m_wrt = new JSWrt(exec); |
|
182 } |
|
183 default: |
|
184 return throwError(exec, GeneralError); |
|
185 } |
|
186 |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // JSWidget::canPut |
|
191 // |
|
192 // |
|
193 // |
|
194 // ---------------------------------------------------------------------------- |
|
195 bool JSWidget::canPut(ExecState *exec, const Identifier &propertyName) const |
|
196 { |
|
197 return true; |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // JSWidget::put |
|
202 // |
|
203 // |
|
204 // |
|
205 // ---------------------------------------------------------------------------- |
|
206 void JSWidget::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr) |
|
207 { |
|
208 const HashEntry* entry = Lookup::findEntry(&WidgetTable, propertyName); |
|
209 if (entry) { |
|
210 switch( entry->value ) { |
|
211 case onhide: { |
|
212 delete d->m_hideCallback; |
|
213 d->m_hideCallback = NULL; |
|
214 d->m_hideCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec()); |
|
215 break; |
|
216 } |
|
217 case onshow: { |
|
218 delete d->m_showCallback; |
|
219 d->m_showCallback = NULL; |
|
220 d->m_showCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec()); |
|
221 // fire the onShow if the SetVisibilty was called before the onShowCallback was created |
|
222 if (d->m_visibility) { |
|
223 d->m_visibility = !d->m_visibility; |
|
224 setVisibility(!d->m_visibility); |
|
225 } |
|
226 break; |
|
227 } |
|
228 case onexit: { |
|
229 delete d->m_exitCallback; |
|
230 d->m_exitCallback = NULL; |
|
231 d->m_exitCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec()); |
|
232 break; |
|
233 } |
|
234 default: |
|
235 break; |
|
236 } |
|
237 } |
|
238 |
|
239 } |
|
240 |
|
241 |
|
242 // ---------------------------------------------------------------------------- |
|
243 // JSWidget::SetVisibility |
|
244 // Invokes onShow or onHide callback function depending on the visibility |
|
245 // status of the widget |
|
246 // |
|
247 // |
|
248 // |
|
249 // ---------------------------------------------------------------------------- |
|
250 void JSWidget::setVisibility(bool visibility) |
|
251 { |
|
252 if (d->m_visibility != visibility) { |
|
253 d->m_visibility = visibility; |
|
254 if(visibility && d->m_showCallback) |
|
255 d->m_showCallback->InvokeCall(); |
|
256 else if (d->m_hideCallback) |
|
257 d->m_hideCallback->InvokeCall(); |
|
258 } |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------------------------- |
|
262 // JSWidget::handleExit |
|
263 // Invokes onExit callback function |
|
264 // |
|
265 // |
|
266 // |
|
267 // ---------------------------------------------------------------------------- |
|
268 void JSWidget::handleExit() |
|
269 { |
|
270 if (d->m_exitCallback) |
|
271 d->m_exitCallback->InvokeCall(); |
|
272 } |
|
273 //END OF FILE |
|
274 |
|
275 |
|
276 |
|
277 |