コード例 #1
0
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();
  }
}
コード例 #2
0
ファイル: kjs_audio.cpp プロジェクト: vasi/kdelibs
void Audio::error(int, const QString &)
{
    if (m_cs) {
        m_cs->deref(this);
        m_cs = 0;
    }

    if (m_onErrorListener && m_doc->view() && m_doc->view()->part()) {
        DOM::Event ev = m_doc->view()->part()->document().createEvent("Event");
        ev.initEvent("error", true, true);
        m_onErrorListener->handleEvent(ev);
    }
}
コード例 #3
0
ファイル: kjs_audio.cpp プロジェクト: vasi/kdelibs
void Audio::notifyFinished(khtml::CachedObject * /*co*/)
{
    if (!m_cs) return;

    m_qObj->setSound( m_cs->sound() );
    m_cs->deref(this);
    m_cs = 0;

    m_qObj->setupPlayer();

    if (m_onLoadListener && m_doc->view() && m_doc->view()->part()) {
        DOM::Event ev = m_doc->view()->part()->document().createEvent("Event");
        ev.initEvent("load", true, true);
        m_onLoadListener->handleEvent(ev);
    }
}
コード例 #4
0
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());
}