void JSEventListener::handleEvent(DOM::Event &evt) { KHTMLPart *part = qobject_cast<KHTMLPart*>(static_cast<Window*>(win.get())->part()); KJSProxy *proxy = 0L; if (part) proxy = part->jScript(); if (proxy && listener && listener->implementsCall()) { #ifdef KJS_DEBUGGER //### This is the wrong place to do this --- we need // a more global/general stategy to prevent unwanted event loop recursion issues. if (proxy->debugEnabled() && DebugWindow::window()->inSession()) return; #endif ref(); KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(proxy->interpreter()); ExecState *exec = interpreter->globalExec(); List args; args.append(getDOMEvent(exec,evt.handle())); JSObject *thisObj = 0; // Check whether handler is a function or an object with handleEvent method if (listener == compareListenerImp) { // Set "this" to the event's current target thisObj = getEventTarget(exec,evt.handle()->currentTarget())->getObject(); } else { thisObj = compareListenerImp; } if ( !thisObj ) { // ### can this still happen? eventTarget should be window on Window events now. thisObj = win; } Window *window = static_cast<Window*>(win.get()); // Set the event we're handling in the Window object window->setCurrentEvent( evt.handle() ); // ... and in the interpreter interpreter->setCurrentEvent( &evt ); interpreter->startCPUGuard(); JSValue *retval = listener->call(exec, thisObj, args); interpreter->stopCPUGuard(); window->setCurrentEvent( 0 ); interpreter->setCurrentEvent( 0 ); if ( exec->hadException() ) exec->clearException(); else if (html) { QVariant ret = ValueToVariant(exec, retval); if (ret.type() == QVariant::Bool && ret.toBool() == false) evt.preventDefault(); } window->afterScriptExecution(); deref(); } }
void KJSProxyImpl::finishedWithEvent(const DOM::Event &event) { // This is called when the DOM implementation has finished with a particular event. This // is the case in sitations where an event has been created just for temporary usage, // e.g. an image load or mouse move. Once the event has been dispatched, it is forgotten // by the DOM implementation and so does not need to be cached still by the interpreter m_script->forgetDOMObject(event.handle()); }