32 static JSClassRef AAMPJSEvent_class_ref();
34 #ifdef JSEVENT_WITH_NATIVE_MEMORY
39 AAMPJSEvent::AAMPJSEvent()
43 , _currentTarget(NULL)
44 , _defaultPrevented(false)
51 , _stopImmediatePropagation(false)
52 , _stopPropagation(false)
61 AAMPJSEvent::AAMPJSEvent(
const char *type,
bool bubble,
bool cancelable)
63 , _cancelable(cancelable)
65 , _currentTarget(NULL)
66 , _defaultPrevented(false)
73 , _stopImmediatePropagation(false)
74 , _stopPropagation(false)
82 AAMPJSEvent::~AAMPJSEvent()
86 JSValueUnprotect(_ctx, _target);
89 if(_currentTarget != NULL)
91 JSValueUnprotect(_ctx, _currentTarget);
98 void AAMPJSEvent::initEvent(
const char *type,
bool bubble,
bool cancelable)
102 _cancelable = cancelable;
115 static void initEvent(JSContextRef context, JSObjectRef thisObj,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
118 bool bubbles =
false;
119 bool cancelable =
false;
121 if (argumentCount >= 1 && JSValueIsString(context, arguments[0]))
125 if (argumentCount >= 2 && JSValueIsObject(context, arguments[1]))
127 JSObjectRef eventParams = JSValueToObject(context, arguments[1], NULL);
129 JSStringRef bubblesProp = JSStringCreateWithUTF8CString(
"bubbles");
130 JSValueRef bubblesValue = JSObjectGetProperty(context, eventParams, bubblesProp, NULL);
131 if (JSValueIsBoolean(context, bubblesValue))
133 bubbles = JSValueToBoolean(context, bubblesValue);
135 JSStringRelease(bubblesProp);
137 JSStringRef cancelableProp = JSStringCreateWithUTF8CString(
"cancelable");
138 JSValueRef cancelableValue = JSObjectGetProperty(context, eventParams, cancelableProp, NULL);
139 if (JSValueIsBoolean(context, cancelableValue))
141 cancelable = JSValueToBoolean(context, cancelableValue);
143 JSStringRelease(cancelableProp);
146 AAMPJSEvent* ev = (AAMPJSEvent*) JSObjectGetPrivate(thisObj);
148 if (ev && evType != NULL)
150 ev->initEvent(evType, bubbles, cancelable);
152 SAFE_DELETE_ARRAY(evType);
167 static JSValueRef AAMPJSEvent_initEvent(JSContextRef context, JSObjectRef func, JSObjectRef thisObj,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
169 initEvent(context, thisObj, argumentCount, arguments, exception);
171 return JSValueMakeUndefined(context);
185 static JSValueRef AAMPJSEvent_preventDefault(JSContextRef context, JSObjectRef func, JSObjectRef thisObj,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
187 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
189 if (eventObj != NULL)
191 eventObj->preventDefault();
194 return JSValueMakeUndefined(context);
208 static JSValueRef AAMPJSEvent_stopImmediatePropagation(JSContextRef context, JSObjectRef func, JSObjectRef thisObj,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
210 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
212 if (eventObj != NULL)
214 eventObj->stopImmediatePropagation();
217 return JSValueMakeUndefined(context);
231 static JSValueRef AAMPJSEvent_stopPropagation(JSContextRef context, JSObjectRef func, JSObjectRef thisObj,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
233 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
235 if (eventObj != NULL)
237 eventObj->stopPropagation();
240 return JSValueMakeUndefined(context);
252 static JSValueRef AAMPJSEvent_getproperty_bubbles(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
254 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
256 if (eventObj == NULL)
258 return JSValueMakeUndefined(context);
261 return JSValueMakeBoolean(context, eventObj->getBubbles());
273 static JSValueRef AAMPJSEvent_getproperty_cancelable(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
275 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
277 if (eventObj == NULL)
279 return JSValueMakeUndefined(context);
282 return JSValueMakeBoolean(context, eventObj->getCancelable());
294 static JSValueRef AAMPJSEvent_getproperty_defaultPrevented(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
296 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
298 if (eventObj == NULL)
300 return JSValueMakeUndefined(context);
303 return JSValueMakeBoolean(context, eventObj->getIsDefaultPrevented());
315 static JSValueRef AAMPJSEvent_getproperty_eventPhase(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
317 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
319 if (eventObj == NULL)
321 return JSValueMakeUndefined(context);
324 return JSValueMakeNumber(context, eventObj->getEventPhase());
336 static JSValueRef AAMPJSEvent_getproperty_target(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
338 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
340 if (eventObj == NULL)
342 return JSValueMakeUndefined(context);
345 return eventObj->getTarget();
357 static JSValueRef AAMPJSEvent_getproperty_currentTarget(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
359 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
361 if (eventObj == NULL)
363 return JSValueMakeUndefined(context);
366 return eventObj->getCurrentTarget();
378 static JSValueRef AAMPJSEvent_getproperty_timestamp(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
380 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
382 if (eventObj == NULL)
384 return JSValueMakeUndefined(context);
387 return JSValueMakeNumber(context, eventObj->getTimestamp());
399 static JSValueRef AAMPJSEvent_getproperty_type(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
401 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
403 if (eventObj == NULL)
405 return JSValueMakeUndefined(context);
420 static JSValueRef AAMPJSEvent_getproperty_isTrusted(JSContextRef context, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception)
422 AAMPJSEvent *eventObj = (AAMPJSEvent *) JSObjectGetPrivate(thisObj);
424 if (eventObj == NULL)
426 return JSValueMakeUndefined(context);
429 return JSValueMakeBoolean(context, eventObj->getIsTrusted());
438 void AAMPJSEvent_initialize (JSContextRef ctx, JSObjectRef
object)
440 AAMPJSEvent* ev =
new AAMPJSEvent();
441 JSObjectSetPrivate(
object, ev);
449 void AAMPJSEvent_finalize(JSObjectRef
object)
451 AAMPJSEvent *ev = (AAMPJSEvent *) JSObjectGetPrivate(
object);
459 static JSStaticFunction AAMPJSEvent_static_functions[] =
461 {
"initEvent", AAMPJSEvent_initEvent, kJSPropertyAttributeReadOnly },
462 {
"preventDefault", AAMPJSEvent_preventDefault, kJSPropertyAttributeReadOnly },
463 {
"stopImmediatePropagation", AAMPJSEvent_stopImmediatePropagation, kJSPropertyAttributeReadOnly },
464 {
"stopPropagation", AAMPJSEvent_stopPropagation, kJSPropertyAttributeReadOnly },
471 static JSStaticValue AAMPJSEvent_static_values[] =
473 {
"bubbles", AAMPJSEvent_getproperty_bubbles, NULL, kJSPropertyAttributeReadOnly },
474 {
"cancelable", AAMPJSEvent_getproperty_cancelable, NULL, kJSPropertyAttributeReadOnly },
475 {
"defaultPrevented", AAMPJSEvent_getproperty_defaultPrevented, NULL, kJSPropertyAttributeReadOnly },
476 {
"eventPhase", AAMPJSEvent_getproperty_eventPhase, NULL, kJSPropertyAttributeReadOnly },
477 {
"target", AAMPJSEvent_getproperty_target, NULL, kJSPropertyAttributeReadOnly },
478 {
"currentTarget", AAMPJSEvent_getproperty_currentTarget, NULL, kJSPropertyAttributeReadOnly },
479 {
"timestamp", AAMPJSEvent_getproperty_timestamp, NULL, kJSPropertyAttributeReadOnly },
480 {
"type", AAMPJSEvent_getproperty_type, NULL, kJSPropertyAttributeReadOnly },
481 {
"isTrusted", AAMPJSEvent_getproperty_isTrusted, NULL, kJSPropertyAttributeReadOnly },
482 { NULL, NULL, NULL, 0 }
492 kJSClassAttributeNone,
495 #ifdef JSEVENT_WITH_NATIVE_MEMORY
496 AAMPJSEvent_static_values,
497 AAMPJSEvent_static_functions,
498 AAMPJSEvent_initialize,
499 AAMPJSEvent_finalize,
521 JSObjectRef eventObj = JSObjectMake(ctx, AAMPJSEvent_class_ref(), NULL);
522 #ifdef JSEVENT_WITH_NATIVE_MEMORY
523 AAMPJSEvent *eventPriv = (AAMPJSEvent *) JSObjectGetPrivate(eventObj);
524 eventPriv->initEvent(type, bubbles, cancelable);
530 static JSClassRef AAMPJSEvent_class_ref()
532 static JSClassRef classDef = NULL;