| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kjs_events.cpp

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU Library General Public
    00008  *  License as published by the Free Software Foundation; either
    00009  *  version 2 of the License, or (at your option) any later version.
    00010  *
    00011  *  This library is distributed in the hope that it will be useful,
    00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  *  Library General Public License for more details.
    00015  *
    00016  *  You should have received a copy of the GNU Library General Public
    00017  *  License along with this library; if not, write to the Free Software
    00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019  */
    00020
    00021 #include "kjs_window.h"
    00022 #include "kjs_events.h"
    00023 #include "kjs_events.lut.h"
    00024 #include "kjs_views.h"
    00025 #include "kjs_proxy.h"
    00026 #include "xml/dom_nodeimpl.h"
    00027 #include "xml/dom_docimpl.h"
    00028 #include "xml/dom2_eventsimpl.h"
    00029 #include "rendering/render_object.h"
    00030
    00031 #include <kdebug.h>
    00032
    00033 using namespace KJS;
    00034
    00035 // -------------------------------------------------------------------------
    00036
    00037 JSEventListener::JSEventListener(Object _listener, const Object &_win, bool _html)
    00038   : listener( _listener ), html( _html ), win( _win )
    00039 {
    00040     //fprintf(stderr,"JSEventListener::JSEventListener this=%p listener=%p\n",this,listener.imp());
    00041     static_cast<Window*>(win.imp())->jsEventListeners.append(this);
    00042 }
    00043
    00044 JSEventListener::~JSEventListener()
    00045 {
    00046     static_cast<Window*>(win.imp())->jsEventListeners.removeRef(this);
    00047     //fprintf(stderr,"JSEventListener::~JSEventListener this=%p listener=%p\n",this,listener.imp());
    00048 }
    00049
    00050 void JSEventListener::handleEvent(DOM::Event &evt)
    00051 {
    00052 #ifdef KJS_DEBUGGER
    00053   if (KJSDebugWin::instance() && KJSDebugWin::instance()->inSession())
    00054     return;
    00055 #endif
    00056   KHTMLPart *part = static_cast<Window*>(win.imp())->part();
    00057   KJSProxy *proxy = 0L;
    00058   if (part)
    00059       proxy = KJSProxy::proxy( part );
    00060
    00061   if (proxy && listener.implementsCall()) {
    00062     ref();
    00063
    00064     KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(proxy->interpreter());
    00065     ExecState *exec = interpreter->globalExec();
    00066
    00067     List args;
    00068     args.append(getDOMEvent(exec,evt));
    00069
    00070     // Add the event's target element to the scope
    00071     // (and the document, and the form - see KJS::HTMLElement::eventHandlerScope)
    00072     Object thisObj = Object::dynamicCast(getDOMNode(exec,evt.currentTarget()));
    00073     List scope;
    00074     List oldScope = listener.scope();
    00075     if ( thisObj.isValid() ) {
    00076       scope = static_cast<DOMNode*>(thisObj.imp())->eventHandlerScope(exec);
    00077       if ( !scope.isEmpty() ) {
    00078         List curScope = oldScope.copy();
    00079         curScope.prependList( scope );
    00080         listener.setScope( curScope );
    00081       }
    00082     }
    00083     else {
    00084       if ( m_hackThisObj.isValid() )
    00085         thisObj = m_hackThisObj;
    00086       else
    00087         kdWarning() << "Null 'this' object! evt=" << evt.type().string() << " currentTarget==" << evt.currentTarget().handle() << endl;
    00088     }
    00089
    00090     Window *window = static_cast<Window*>(win.imp());
    00091     // Set the event we're handling in the Window object
    00092     window->setCurrentEvent( &evt );
    00093     // ... and in the interpreter
    00094     interpreter->setCurrentEvent( &evt );
    00095
    00096     KJSCPUGuard guard;
    00097     guard.start();
    00098     Value retval = listener.call(exec, thisObj, args);
    00099     guard.stop();
    00100
    00101     if ( !scope.isEmpty() ) {
    00102       listener.setScope( oldScope );
    00103     }
    00104
    00105     window->setCurrentEvent( 0 );
    00106     interpreter->setCurrentEvent( 0 );
    00107     if ( exec->hadException() )
    00108         exec->clearException();
    00109     else
    00110     {
    00111         QVariant ret = ValueToVariant(exec, retval);
    00112         if (ret.type() == QVariant::Bool && ret.toBool() == false)
    00113             evt.preventDefault();
    00114     }
    00115     window->afterScriptExecution();
    00116     deref();
    00117   }
    00118 }
    00119
    00120 DOM::DOMString JSEventListener::eventListenerType()
    00121 {
    00122     if (html)
    00123         return "_khtml_HTMLEventListener";
    00124     else
    00125         return "_khtml_JSEventListener";
    00126 }
    00127
    00128 Value KJS::getNodeEventListener(DOM::Node n, int eventId)
    00129 {
    00130     DOM::EventListener *listener = n.handle()->getHTMLEventListener(eventId);
    00131     if (listener)
    00132         return static_cast<JSEventListener*>(listener)->listenerObj();
    00133     else
    00134         return Null();
    00135 }
    00136
    00137 // -------------------------------------------------------------------------
    00138
    00139 const ClassInfo EventConstructor::info = { "EventConstructor", 0, &EventConstructorTable, 0 };
    00140 /*
    00141 @begin EventConstructorTable 3
    00142   CAPTURING_PHASE       DOM::Event::CAPTURING_PHASE     DontDelete|ReadOnly
    00143   AT_TARGET             DOM::Event::AT_TARGET           DontDelete|ReadOnly
    00144   BUBBLING_PHASE        DOM::Event::BUBBLING_PHASE      DontDelete|ReadOnly
    00145 # Reverse-engineered from Netscape
    00146   MOUSEDOWN             1                               DontDelete|ReadOnly
    00147   MOUSEUP               2                               DontDelete|ReadOnly
    00148   MOUSEOVER             4                               DontDelete|ReadOnly
    00149   MOUSEOUT              8                               DontDelete|ReadOnly
    00150   MOUSEMOVE             16                              DontDelete|ReadOnly
    00151   MOUSEDRAG             32                              DontDelete|ReadOnly
    00152   CLICK                 64                              DontDelete|ReadOnly
    00153   DBLCLICK              128                             DontDelete|ReadOnly
    00154   KEYDOWN               256                             DontDelete|ReadOnly
    00155   KEYUP                 512                             DontDelete|ReadOnly
    00156   KEYPRESS              1024                            DontDelete|ReadOnly
    00157   DRAGDROP              2048                            DontDelete|ReadOnly
    00158   FOCUS                 4096                            DontDelete|ReadOnly
    00159   BLUR                  8192                            DontDelete|ReadOnly
    00160   SELECT                16384                           DontDelete|ReadOnly
    00161   CHANGE                32768                           DontDelete|ReadOnly
    00162 @end
    00163 */
    00164
    00165 EventConstructor::EventConstructor(ExecState *exec)
    00166   : DOMObject(exec->interpreter()->builtinObjectPrototype())
    00167 {
    00168 }
    00169
    00170 Value EventConstructor::tryGet(ExecState *exec, const UString &p) const
    00171 {
    00172   return DOMObjectLookupGetValue<EventConstructor, DOMObject>(exec,p,&EventConstructorTable,this);
    00173 }
    00174
    00175 Value EventConstructor::getValueProperty(ExecState *, int token) const
    00176 {
    00177   // We use the token as the value to return directly
    00178   return Number(token);
    00179 }
    00180
    00181 Value KJS::getEventConstructor(ExecState *exec)
    00182 {
    00183   return cacheGlobalObject<EventConstructor>(exec, "[[event.constructor]]");
    00184 }
    00185
    00186 // -------------------------------------------------------------------------
    00187
    00188 const ClassInfo DOMEvent::info = { "Event", 0, &DOMEventTable, 0 };
    00189 /*
    00190 @begin DOMEventTable 7
    00191   type          DOMEvent::Type          DontDelete|ReadOnly
    00192   target        DOMEvent::Target        DontDelete|ReadOnly
    00193   currentTarget DOMEvent::CurrentTarget DontDelete|ReadOnly
    00194   srcElement    DOMEvent::SrcElement    DontDelete|ReadOnly
    00195   eventPhase    DOMEvent::EventPhase    DontDelete|ReadOnly
    00196   bubbles       DOMEvent::Bubbles       DontDelete|ReadOnly
    00197   cancelable    DOMEvent::Cancelable    DontDelete|ReadOnly
    00198   timeStamp     DOMEvent::TimeStamp     DontDelete|ReadOnly
    00199   returnValue   DOMEvent::ReturnValue   DontDelete
    00200   cancelBubble  DOMEvent::CancelBubble  DontDelete
    00201 @end
    00202 @begin DOMEventProtoTable 3
    00203   stopPropagation       DOMEvent::StopPropagation       DontDelete|Function 0
    00204   preventDefault        DOMEvent::PreventDefault        DontDelete|Function 0
    00205   initEvent             DOMEvent::InitEvent             DontDelete|Function 3
    00206 @end
    00207 */
    00208 DEFINE_PROTOTYPE("DOMEvent", DOMEventProto)
    00209 IMPLEMENT_PROTOFUNC_DOM(DOMEventProtoFunc)
    00210 IMPLEMENT_PROTOTYPE(DOMEventProto, DOMEventProtoFunc)
    00211
    00212 DOMEvent::DOMEvent(ExecState *exec, DOM::Event e)
    00213   : DOMObject(DOMEventProto::self(exec)), event(e) { }
    00214
    00215 DOMEvent::~DOMEvent()
    00216 {
    00217   ScriptInterpreter::forgetDOMObject(event.handle());
    00218 }
    00219
    00220 Value DOMEvent::tryGet(ExecState *exec, const UString &p) const
    00221 {
    00222 #ifdef KJS_VERBOSE
    00223   kdDebug() << "KJS::DOMEvent::tryGet " << p.qstring() << endl;
    00224 #endif
    00225   return DOMObjectLookupGetValue<DOMEvent,DOMObject>(exec, p, &DOMEventTable, this );
    00226 }
    00227
    00228 Value DOMEvent::getValueProperty(ExecState *exec, int token) const
    00229 {
    00230   switch (token) {
    00231   case Type:
    00232     return String(event.type());
    00233   case Target:
    00234   case SrcElement: /*MSIE extension - "the object that fired the event"*/
    00235     return getDOMNode(exec,event.target());
    00236   case CurrentTarget:
    00237     return getDOMNode(exec,event.currentTarget());
    00238   case EventPhase:
    00239     return Number((unsigned int)event.eventPhase());
    00240   case Bubbles:
    00241     return Boolean(event.bubbles());
    00242   case Cancelable:
    00243     return Boolean(event.cancelable());
    00244   case TimeStamp:
    00245     return Number((long unsigned int)event.timeStamp()); // ### long long ?
    00246   case ReturnValue: // MSIE extension
    00247     return Boolean(event.handle()->defaultPrevented());
    00248   case CancelBubble: // MSIE extension
    00249     return Boolean(event.handle()->propagationStopped());
    00250   default:
    00251     kdWarning() << "Unhandled token in DOMEvent::getValueProperty : " << token << endl;
    00252     return Value();
    00253   }
    00254 }
    00255
    00256 void DOMEvent::tryPut(ExecState *exec, const UString &propertyName,
    00257                       const Value& value, int attr)
    00258 {
    00259   DOMObjectLookupPut<DOMEvent, DOMObject>(exec, propertyName, value, attr,
    00260                                           &DOMEventTable, this);
    00261 }
    00262
    00263 void DOMEvent::putValueProperty(ExecState *exec, int token, const Value& value, int)
    00264 {
    00265   switch (token) {
    00266   case ReturnValue: // MSIE equivalent for "preventDefault" (but with a way to reset it)
    00267     // returnValue=false means "default action of the event on the source object is canceled",
    00268     // which means preventDefault(true). Hence the '!'.
    00269     event.handle()->preventDefault(!value.toBoolean(exec));
    00270     break;
    00271   case CancelBubble: // MSIE equivalent for "stopPropagation" (but with a way to reset it)
    00272     event.handle()->stopPropagation(value.toBoolean(exec));
    00273     break;
    00274   default:
    00275     break;
    00276   }
    00277 }
    00278
    00279 Value DOMEventProtoFunc::tryCall(ExecState *exec, Object & thisObj, const List &args)
    00280 {
    00281   KJS_CHECK_THIS( KJS::DOMEvent, thisObj );
    00282   DOM::Event event = static_cast<DOMEvent *>( thisObj.imp() )->toEvent();
    00283   switch (id) {
    00284     case DOMEvent::StopPropagation:
    00285       event.stopPropagation();
    00286     case DOMEvent::PreventDefault:
    00287       event.preventDefault();
    00288       return Undefined();
    00289     case DOMEvent::InitEvent:
    00290       event.initEvent(args[0].toString(exec).string(),args[1].toBoolean(exec),args[2].toBoolean(exec));
    00291       return Undefined();
    00292   };
    00293   return Undefined();
    00294 }
    00295
    00296 Value KJS::getDOMEvent(ExecState *exec, DOM::Event e)
    00297 {
    00298   DOMObject *ret;
    00299   if (e.isNull())
    00300     return Null();
    00301   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
    00302   if ((ret = interp->getDOMObject(e.handle())))
    00303     return Value(ret);
    00304
    00305   DOM::DOMString module = e.eventModuleName();
    00306   if (module == "UIEvents")
    00307     ret = new DOMUIEvent(exec, static_cast<DOM::UIEvent>(e));
    00308   else if (module == "MouseEvents")
    00309     ret = new DOMMouseEvent(exec, static_cast<DOM::MouseEvent>(e));
    00310   else if (module == "TextEvents")
    00311     ret = new DOMTextEvent(exec, static_cast<DOM::TextEvent>(e));
    00312   else if (module == "MutationEvents")
    00313     ret = new DOMMutationEvent(exec, static_cast<DOM::MutationEvent>(e));
    00314   else
    00315     ret = new DOMEvent(exec, e);
    00316
    00317   interp->putDOMObject(e.handle(),ret);
    00318   return Value(ret);
    00319 }
    00320
    00321 DOM::Event KJS::toEvent(const Value& val)
    00322 {
    00323   Object obj = Object::dynamicCast(val);
    00324   if (obj.isNull() || !obj.inherits(&DOMEvent::info))
    00325     return DOM::Event();
    00326
    00327   const DOMEvent *dobj = static_cast<const DOMEvent*>(obj.imp());
    00328   return dobj->toEvent();
    00329 }
    00330
    00331 // -------------------------------------------------------------------------
    00332
    00333
    00334 const ClassInfo EventExceptionConstructor::info = { "EventExceptionConstructor", 0, &EventExceptionConstructorTable, 0 };
    00335 /*
    00336 @begin EventExceptionConstructorTable 1
    00337   UNSPECIFIED_EVENT_TYPE_ERR    DOM::EventException::UNSPECIFIED_EVENT_TYPE_ERR DontDelete|ReadOnly
    00338 @end
    00339 */
    00340 EventExceptionConstructor::EventExceptionConstructor(ExecState *exec)
    00341   : DOMObject(exec->interpreter()->builtinObjectPrototype())
    00342 {
    00343 }
    00344
    00345 Value EventExceptionConstructor::tryGet(ExecState *exec, const UString &p) const
    00346 {
    00347   return DOMObjectLookupGetValue<EventExceptionConstructor, DOMObject>(exec,p,&EventExceptionConstructorTable,this);
    00348 }
    00349
    00350 Value EventExceptionConstructor::getValueProperty(ExecState *, int token) const
    00351 {
    00352   // We use the token as the value to return directly
    00353   return Number(token);
    00354 }
    00355
    00356 Value KJS::getEventExceptionConstructor(ExecState *exec)
    00357 {
    00358   return cacheGlobalObject<EventExceptionConstructor>(exec, "[[eventException.constructor]]");
    00359 }
    00360
    00361 // -------------------------------------------------------------------------
    00362
    00363 const ClassInfo DOMUIEvent::info = { "UIEvent", &DOMEvent::info, &DOMUIEventTable, 0 };
    00364 /*
    00365 @begin DOMUIEventTable 2
    00366   view          DOMUIEvent::View        DontDelete|ReadOnly
    00367   detail        DOMUIEvent::Detail      DontDelete|ReadOnly
    00368 @end
    00369 @begin DOMUIEventProtoTable 1
    00370   initUIEvent   DOMUIEvent::InitUIEvent DontDelete|Function 5
    00371 @end
    00372 */
    00373 DEFINE_PROTOTYPE("DOMUIEvent",DOMUIEventProto)
    00374 IMPLEMENT_PROTOFUNC_DOM(DOMUIEventProtoFunc)
    00375 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMUIEventProto,DOMUIEventProtoFunc,DOMEventProto)
    00376
    00377 DOMUIEvent::~DOMUIEvent()
    00378 {
    00379 }
    00380
    00381 Value DOMUIEvent::tryGet(ExecState *exec, const UString &p) const
    00382 {
    00383   return DOMObjectLookupGetValue<DOMUIEvent,DOMEvent>(exec,p,&DOMUIEventTable,this);
    00384 }
    00385
    00386 Value DOMUIEvent::getValueProperty(ExecState *exec, int token) const
    00387 {
    00388   switch (token) {
    00389   case View:
    00390     return getDOMAbstractView(exec,static_cast<DOM::UIEvent>(event).view());
    00391   case Detail:
    00392     return Number(static_cast<DOM::UIEvent>(event).detail());
    00393   default:
    00394     kdWarning() << "Unhandled token in DOMUIEvent::getValueProperty : " << token << endl;
    00395     return Value();
    00396   }
    00397 }
    00398
    00399 Value DOMUIEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00400 {
    00401   KJS_CHECK_THIS( KJS::DOMUIEvent, thisObj );
    00402   DOM::UIEvent uiEvent = static_cast<DOMUIEvent *>(thisObj.imp())->toUIEvent();
    00403   switch (id) {
    00404     case DOMUIEvent::InitUIEvent: {
    00405       DOM::AbstractView v = toAbstractView(args[3]);
    00406       static_cast<DOM::UIEvent>(uiEvent).initUIEvent(args[0].toString(exec).string(),
    00407                                                      args[1].toBoolean(exec),
    00408                                                      args[2].toBoolean(exec),
    00409                                                      v,
    00410                                                      args[4].toInteger(exec));
    00411       }
    00412       return Undefined();
    00413   }
    00414   return Undefined();
    00415 }
    00416
    00417 // -------------------------------------------------------------------------
    00418
    00419 const ClassInfo DOMMouseEvent::info = { "MouseEvent", &DOMUIEvent::info, &DOMMouseEventTable, 0 };
    00420
    00421 /*
    00422 @begin DOMMouseEventTable 2
    00423   screenX       DOMMouseEvent::ScreenX  DontDelete|ReadOnly
    00424   screenY       DOMMouseEvent::ScreenY  DontDelete|ReadOnly
    00425   clientX       DOMMouseEvent::ClientX  DontDelete|ReadOnly
    00426   x             DOMMouseEvent::X        DontDelete|ReadOnly
    00427   clientY       DOMMouseEvent::ClientY  DontDelete|ReadOnly
    00428   y             DOMMouseEvent::Y        DontDelete|ReadOnly
    00429   offsetX       DOMMouseEvent::OffsetX  DontDelete|ReadOnly
    00430   offsetY       DOMMouseEvent::OffsetY  DontDelete|ReadOnly
    00431   ctrlKey       DOMMouseEvent::CtrlKey  DontDelete|ReadOnly
    00432   shiftKey      DOMMouseEvent::ShiftKey DontDelete|ReadOnly
    00433   altKey        DOMMouseEvent::AltKey   DontDelete|ReadOnly
    00434   metaKey       DOMMouseEvent::MetaKey  DontDelete|ReadOnly
    00435   button        DOMMouseEvent::Button   DontDelete|ReadOnly
    00436   relatedTarget DOMMouseEvent::RelatedTarget DontDelete|ReadOnly
    00437   fromElement   DOMMouseEvent::FromElement DontDelete|ReadOnly
    00438   toElement     DOMMouseEvent::ToElement        DontDelete|ReadOnly
    00439 @end
    00440 @begin DOMMouseEventProtoTable 1
    00441   initMouseEvent        DOMMouseEvent::InitMouseEvent   DontDelete|Function 15
    00442 @end
    00443 */
    00444 DEFINE_PROTOTYPE("DOMMouseEvent",DOMMouseEventProto)
    00445 IMPLEMENT_PROTOFUNC_DOM(DOMMouseEventProtoFunc)
    00446 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMouseEventProto,DOMMouseEventProtoFunc,DOMUIEventProto)
    00447
    00448 DOMMouseEvent::~DOMMouseEvent()
    00449 {
    00450 }
    00451
    00452 Value DOMMouseEvent::tryGet(ExecState *exec, const UString &p) const
    00453 {
    00454 #ifdef KJS_VERBOSE
    00455   kdDebug(6070) << "DOMMouseEvent::tryGet " << p.qstring() << endl;
    00456 #endif
    00457   return DOMObjectLookupGetValue<DOMMouseEvent,DOMUIEvent>(exec,p,&DOMMouseEventTable,this);
    00458 }
    00459
    00460 Value DOMMouseEvent::getValueProperty(ExecState *exec, int token) const
    00461 {
    00462   switch (token) {
    00463   case ScreenX:
    00464     return Number(static_cast<DOM::MouseEvent>(event).screenX());
    00465   case ScreenY:
    00466     return Number(static_cast<DOM::MouseEvent>(event).screenY());
    00467   case ClientX:
    00468   case X:
    00469     return Number(static_cast<DOM::MouseEvent>(event).clientX());
    00470   case ClientY:
    00471   case Y:
    00472     return Number(static_cast<DOM::MouseEvent>(event).clientY());
    00473   case OffsetX:
    00474   case OffsetY: // MSIE extension
    00475   {
    00476     DOM::Node node = event.target();
    00477     node.handle()->getDocument()->updateRendering();
    00478     khtml::RenderObject *rend = node.handle() ? node.handle()->renderer() : 0L;
    00479     int x = static_cast<DOM::MouseEvent>(event).clientX();
    00480     int y = static_cast<DOM::MouseEvent>(event).clientY();
    00481     if ( rend ) {
    00482       int xPos, yPos;
    00483       if ( rend->absolutePosition( xPos, yPos ) ) {
    00484         kdDebug() << "DOMMouseEvent::getValueProperty rend=" << rend << "  xPos=" << xPos << "  yPos=" << yPos << endl;
    00485         x -= xPos;
    00486         y -= yPos;
    00487       }
    00488     }
    00489     return Number( token == OffsetX ? x : y );
    00490   }
    00491   case CtrlKey:
    00492     return Boolean(static_cast<DOM::MouseEvent>(event).ctrlKey());
    00493   case ShiftKey:
    00494     return Boolean(static_cast<DOM::MouseEvent>(event).shiftKey());
    00495   case AltKey:
    00496     return Boolean(static_cast<DOM::MouseEvent>(event).altKey());
    00497   case MetaKey:
    00498     return Boolean(static_cast<DOM::MouseEvent>(event).metaKey());
    00499   case Button:
    00500   {
    00501     // Tricky. The DOM (and khtml) use 0 for LMB, 1 for MMB and 2 for RMB
    00502     // but MSIE uses 1=LMB, 2=RMB, 4=MMB, as a bitfield
    00503     int domButton = static_cast<DOM::MouseEvent>(event).button();
    00504     int button = domButton==0 ? 1 : domButton==1 ? 4 : domButton==2 ? 2 : 0;
    00505     return Number( (unsigned int)button );
    00506   }
    00507   case ToElement:
    00508     // MSIE extension - "the object toward which the user is moving the mouse pointer"
    00509     if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT)
    00510       return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget());
    00511     return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target());
    00512   case FromElement:
    00513     // MSIE extension - "object from which activation
    00514     // or the mouse pointer is exiting during the event" (huh?)
    00515     if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT)
    00516       return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target());
    00517     /* fall through */
    00518   case RelatedTarget:
    00519     return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget());
    00520   default:
    00521     kdWarning() << "Unhandled token in DOMMouseEvent::getValueProperty : " << token << endl;
    00522     return Value();
    00523   }
    00524 }
    00525
    00526 Value DOMMouseEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00527 {
    00528   KJS_CHECK_THIS( KJS::DOMMouseEvent, thisObj );
    00529   DOM::MouseEvent mouseEvent = static_cast<DOMMouseEvent *>(thisObj.imp())->toMouseEvent();
    00530   switch (id) {
    00531     case DOMMouseEvent::InitMouseEvent:
    00532       mouseEvent.initMouseEvent(args[0].toString(exec).string(), // typeArg
    00533                                 args[1].toBoolean(exec), // canBubbleArg
    00534                                 args[2].toBoolean(exec), // cancelableArg
    00535                                 toAbstractView(args[3]), // viewArg
    00536                                 args[4].toInteger(exec), // detailArg
    00537                                 args[5].toInteger(exec), // screenXArg
    00538                                 args[6].toInteger(exec), // screenYArg
    00539                                 args[7].toInteger(exec), // clientXArg
    00540                                 args[8].toInteger(exec), // clientYArg
    00541                                 args[9].toBoolean(exec), // ctrlKeyArg
    00542                                 args[10].toBoolean(exec), // altKeyArg
    00543                                 args[11].toBoolean(exec), // shiftKeyArg
    00544                                 args[12].toBoolean(exec), // metaKeyArg
    00545                                 args[13].toInteger(exec), // buttonArg
    00546                                 toNode(args[14])); // relatedTargetArg
    00547       return Undefined();
    00548   }
    00549   return Undefined();
    00550 }
    00551
    00552 // -------------------------------------------------------------------------
    00553
    00554 const ClassInfo DOMTextEvent::info = { "TextEvent", &DOMUIEvent::info, &DOMTextEventTable, 0 };
    00555
    00556 /*
    00557 @begin DOMTextEventTable 2
    00558   keyVal         DOMTextEvent::Key           DontDelete|ReadOnly
    00559 # IE's name for it
    00560   keyCode        DOMTextEvent::Key           DontDelete|ReadOnly
    00561   virtKeyVal     DOMTextEvent::VirtKey        DontDelete|ReadOnly
    00562   outputString   DOMTextEvent::OutputString   DontDelete|ReadOnly
    00563   inputGenerated DOMTextEvent::InputGenerated DontDelete|ReadOnly
    00564   numPad         DOMTextEvent::NumPad         DontDelete|ReadOnly
    00565 @end
    00566 @begin DOMTextEventProtoTable 1
    00567   initTextEvent DOMTextEvent::InitTextEvent     DontDelete|Function 10
    00568   # Missing: initTextEventNS, initModifier
    00569 @end
    00570 */
    00571 DEFINE_PROTOTYPE("DOMTextEvent",DOMTextEventProto)
    00572 IMPLEMENT_PROTOFUNC_DOM(DOMTextEventProtoFunc)
    00573 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMTextEventProto,DOMTextEventProtoFunc,DOMUIEventProto)
    00574
    00575 DOMTextEvent::~DOMTextEvent()
    00576 {
    00577 }
    00578
    00579 Value DOMTextEvent::tryGet(ExecState *exec, const UString &p) const
    00580 {
    00581 #ifdef KJS_VERBOSE
    00582   kdDebug(6070) << "DOMTextEvent::tryGet " << p.qstring() << endl;
    00583 #endif
    00584   return DOMObjectLookupGetValue<DOMTextEvent,DOMUIEvent>(exec,p,&DOMTextEventTable,this);
    00585 }
    00586
    00587 Value DOMTextEvent::getValueProperty(ExecState *, int token) const
    00588 {
    00589   switch (token) {
    00590   case Key:
    00591     return Number(static_cast<DOM::TextEvent>(event).keyVal());
    00592   case VirtKey:
    00593     return Number(static_cast<DOM::TextEvent>(event).virtKeyVal());
    00594   case OutputString:
    00595     return String(static_cast<DOM::TextEvent>(event).outputString());
    00596   case InputGenerated:
    00597     return Boolean(static_cast<DOM::TextEvent>(event).inputGenerated());
    00598   case NumPad:
    00599     return Boolean(static_cast<DOM::TextEvent>(event).numPad());
    00600   default:
    00601     kdWarning() << "Unhandled token in DOMTextEvent::getValueProperty : " << token << endl;
    00602     return Value();
    00603   }
    00604 }
    00605
    00606 Value DOMTextEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00607 {
    00608   KJS_CHECK_THIS( KJS::DOMTextEvent, thisObj );
    00609   DOM::TextEvent keyEvent = static_cast<DOMTextEvent *>(thisObj.imp())->toTextEvent();
    00610   switch (id) {
    00611     case DOMTextEvent::InitTextEvent:
    00612       keyEvent.initTextEvent(args[0].toString(exec).string(), // typeArg
    00613                             args[1].toBoolean(exec), // canBubbleArg
    00614                             args[2].toBoolean(exec), // cancelableArg
    00615                             toAbstractView(args[3]), // viewArg
    00616                             args[4].toInteger(exec), // detailArg
    00617                             args[5].toString(exec).string(),  // outputStringArg
    00618                             args[6].toInteger(exec), // keyValArg
    00619                             args[7].toInteger(exec), // virtKeyValArg
    00620                             args[8].toBoolean(exec), // inputGeneratedArg
    00621                             args[9].toBoolean(exec));// numPadArg
    00622
    00623       return Undefined();
    00624   }
    00625   return Undefined();
    00626 }
    00627
    00628 // -------------------------------------------------------------------------
    00629
    00630 const ClassInfo MutationEventConstructor::info = { "MutationEventConstructor", 0, &MutationEventConstructorTable, 0 };
    00631 /*
    00632 @begin MutationEventConstructorTable 3
    00633   MODIFICATION  DOM::MutationEvent::MODIFICATION        DontDelete|ReadOnly
    00634   ADDITION      DOM::MutationEvent::ADDITION            DontDelete|ReadOnly
    00635   REMOVAL       DOM::MutationEvent::REMOVAL             DontDelete|ReadOnly
    00636 @end
    00637 */
    00638 MutationEventConstructor::MutationEventConstructor(ExecState* exec)
    00639   : DOMObject(exec->interpreter()->builtinObjectPrototype())
    00640 {
    00641 }
    00642
    00643 Value MutationEventConstructor::tryGet(ExecState *exec, const UString &p) const
    00644 {
    00645   return DOMObjectLookupGetValue<MutationEventConstructor,DOMObject>(exec,p,&MutationEventConstructorTable,this);
    00646 }
    00647
    00648 Value MutationEventConstructor::getValueProperty(ExecState *, int token) const
    00649 {
    00650   // We use the token as the value to return directly
    00651   return Number(token);
    00652 }
    00653
    00654 Value KJS::getMutationEventConstructor(ExecState *exec)
    00655 {
    00656   return cacheGlobalObject<MutationEventConstructor>(exec, "[[mutationEvent.constructor]]");
    00657 }
    00658
    00659 // -------------------------------------------------------------------------
    00660
    00661 const ClassInfo DOMMutationEvent::info = { "MutationEvent", &DOMEvent::info, &DOMMutationEventTable, 0 };
    00662 /*
    00663 @begin DOMMutationEventTable 5
    00664   relatedNode   DOMMutationEvent::RelatedNode   DontDelete|ReadOnly
    00665   prevValue     DOMMutationEvent::PrevValue     DontDelete|ReadOnly
    00666   newValue      DOMMutationEvent::NewValue      DontDelete|ReadOnly
    00667   attrName      DOMMutationEvent::AttrName      DontDelete|ReadOnly
    00668   attrChange    DOMMutationEvent::AttrChange    DontDelete|ReadOnly
    00669 @end
    00670 @begin DOMMutationEventProtoTable 1
    00671   initMutationEvent     DOMMutationEvent::InitMutationEvent     DontDelete|Function 8
    00672 @end
    00673 */
    00674 DEFINE_PROTOTYPE("DOMMutationEvent",DOMMutationEventProto)
    00675 IMPLEMENT_PROTOFUNC_DOM(DOMMutationEventProtoFunc)
    00676 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMutationEventProto,DOMMutationEventProtoFunc,DOMEventProto)
    00677
    00678 DOMMutationEvent::~DOMMutationEvent()
    00679 {
    00680 }
    00681
    00682 Value DOMMutationEvent::tryGet(ExecState *exec, const UString &p) const
    00683 {
    00684   return DOMObjectLookupGetValue<DOMMutationEvent,DOMEvent>(exec,p,&DOMMutationEventTable,this);
    00685 }
    00686
    00687 Value DOMMutationEvent::getValueProperty(ExecState *exec, int token) const
    00688 {
    00689   switch (token) {
    00690   case RelatedNode:
    00691     return getDOMNode(exec,static_cast<DOM::MutationEvent>(event).relatedNode());
    00692   case PrevValue:
    00693     return String(static_cast<DOM::MutationEvent>(event).prevValue());
    00694   case NewValue:
    00695     return String(static_cast<DOM::MutationEvent>(event).newValue());
    00696   case AttrName:
    00697     return String(static_cast<DOM::MutationEvent>(event).attrName());
    00698   case AttrChange:
    00699     return Number((unsigned int)static_cast<DOM::MutationEvent>(event).attrChange());
    00700   default:
    00701     kdWarning() << "Unhandled token in DOMMutationEvent::getValueProperty : " << token << endl;
    00702     return Value();
    00703   }
    00704 }
    00705
    00706 Value DOMMutationEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00707 {
    00708   KJS_CHECK_THIS( KJS::DOMMutationEvent, thisObj );
    00709   DOM::MutationEvent mutationEvent = static_cast<DOMMutationEvent *>(thisObj.imp())->toMutationEvent();
    00710   switch (id) {
    00711     case DOMMutationEvent::InitMutationEvent:
    00712       mutationEvent.initMutationEvent(args[0].toString(exec).string(), // typeArg,
    00713                                       args[1].toBoolean(exec), // canBubbleArg
    00714                                       args[2].toBoolean(exec), // cancelableArg
    00715                                       toNode(args[3]), // relatedNodeArg
    00716                                       args[4].toString(exec).string(), // prevValueArg
    00717                                       args[5].toString(exec).string(), // newValueArg
    00718                                       args[6].toString(exec).string(), // attrNameArg
    00719                                       args[7].toInteger(exec)); // attrChangeArg
    00720       return Undefined();
    00721   }
    00722   return Undefined();
    00723 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:15 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001