khtml Library API Documentation

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   case CancelBubble: // MSIE extension. not sure if readable. and returnValue ?
00242     return Boolean(event.bubbles());
00243   case Cancelable:
00244     return Boolean(event.cancelable());
00245   case TimeStamp:
00246     return Number((long unsigned int)event.timeStamp()); // ### long long ?
00247   default:
00248     kdWarning() << "Unhandled token in DOMEvent::getValueProperty : " << token << endl;
00249     return Value();
00250   }
00251 }
00252 
00253 void DOMEvent::tryPut(ExecState *exec, const UString &propertyName,
00254                       const Value& value, int attr)
00255 {
00256   DOMObjectLookupPut<DOMEvent, DOMObject>(exec, propertyName, value, attr,
00257                                           &DOMEventTable, this);
00258 }
00259 
00260 void DOMEvent::putValueProperty(ExecState *exec, int token, const Value& value, int)
00261 {
00262   switch (token) {
00263   case ReturnValue:
00264     if (value.toBoolean(exec))
00265       event.preventDefault();
00266     break;
00267   case CancelBubble:
00268     if (value.toBoolean(exec))
00269       event.stopPropagation();
00270     break;
00271   default:
00272     break;
00273   }
00274 }
00275 
00276 Value DOMEventProtoFunc::tryCall(ExecState *exec, Object & thisObj, const List &args)
00277 {
00278   KJS_CHECK_THIS( KJS::DOMEvent, thisObj );
00279   DOM::Event event = static_cast<DOMEvent *>( thisObj.imp() )->toEvent();
00280   switch (id) {
00281     case DOMEvent::StopPropagation:
00282       event.stopPropagation();
00283     case DOMEvent::PreventDefault:
00284       event.preventDefault();
00285       return Undefined();
00286     case DOMEvent::InitEvent:
00287       event.initEvent(args[0].toString(exec).string(),args[1].toBoolean(exec),args[2].toBoolean(exec));
00288       return Undefined();
00289   };
00290   return Undefined();
00291 }
00292 
00293 Value KJS::getDOMEvent(ExecState *exec, DOM::Event e)
00294 {
00295   DOMObject *ret;
00296   if (e.isNull())
00297     return Null();
00298   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
00299   if ((ret = interp->getDOMObject(e.handle())))
00300     return Value(ret);
00301 
00302   DOM::DOMString module = e.eventModuleName();
00303   if (module == "UIEvents")
00304     ret = new DOMUIEvent(exec, static_cast<DOM::UIEvent>(e));
00305   else if (module == "MouseEvents")
00306     ret = new DOMMouseEvent(exec, static_cast<DOM::MouseEvent>(e));
00307   else if (module == "TextEvents")
00308     ret = new DOMTextEvent(exec, static_cast<DOM::TextEvent>(e));
00309   else if (module == "MutationEvents")
00310     ret = new DOMMutationEvent(exec, static_cast<DOM::MutationEvent>(e));
00311   else
00312     ret = new DOMEvent(exec, e);
00313 
00314   interp->putDOMObject(e.handle(),ret);
00315   return Value(ret);
00316 }
00317 
00318 DOM::Event KJS::toEvent(const Value& val)
00319 {
00320   Object obj = Object::dynamicCast(val);
00321   if (obj.isNull() || !obj.inherits(&DOMEvent::info))
00322     return DOM::Event();
00323 
00324   const DOMEvent *dobj = static_cast<const DOMEvent*>(obj.imp());
00325   return dobj->toEvent();
00326 }
00327 
00328 // -------------------------------------------------------------------------
00329 
00330 
00331 const ClassInfo EventExceptionConstructor::info = { "EventExceptionConstructor", 0, &EventExceptionConstructorTable, 0 };
00332 /*
00333 @begin EventExceptionConstructorTable 1
00334   UNSPECIFIED_EVENT_TYPE_ERR    DOM::EventException::UNSPECIFIED_EVENT_TYPE_ERR DontDelete|ReadOnly
00335 @end
00336 */
00337 EventExceptionConstructor::EventExceptionConstructor(ExecState *exec)
00338   : DOMObject(exec->interpreter()->builtinObjectPrototype())
00339 {
00340 }
00341 
00342 Value EventExceptionConstructor::tryGet(ExecState *exec, const UString &p) const
00343 {
00344   return DOMObjectLookupGetValue<EventExceptionConstructor, DOMObject>(exec,p,&EventExceptionConstructorTable,this);
00345 }
00346 
00347 Value EventExceptionConstructor::getValueProperty(ExecState *, int token) const
00348 {
00349   // We use the token as the value to return directly
00350   return Number(token);
00351 }
00352 
00353 Value KJS::getEventExceptionConstructor(ExecState *exec)
00354 {
00355   return cacheGlobalObject<EventExceptionConstructor>(exec, "[[eventException.constructor]]");
00356 }
00357 
00358 // -------------------------------------------------------------------------
00359 
00360 const ClassInfo DOMUIEvent::info = { "UIEvent", &DOMEvent::info, &DOMUIEventTable, 0 };
00361 /*
00362 @begin DOMUIEventTable 2
00363   view      DOMUIEvent::View    DontDelete|ReadOnly
00364   detail    DOMUIEvent::Detail  DontDelete|ReadOnly
00365 @end
00366 @begin DOMUIEventProtoTable 1
00367   initUIEvent   DOMUIEvent::InitUIEvent DontDelete|Function 5
00368 @end
00369 */
00370 DEFINE_PROTOTYPE("DOMUIEvent",DOMUIEventProto)
00371 IMPLEMENT_PROTOFUNC_DOM(DOMUIEventProtoFunc)
00372 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMUIEventProto,DOMUIEventProtoFunc,DOMEventProto)
00373 
00374 DOMUIEvent::~DOMUIEvent()
00375 {
00376 }
00377 
00378 Value DOMUIEvent::tryGet(ExecState *exec, const UString &p) const
00379 {
00380   return DOMObjectLookupGetValue<DOMUIEvent,DOMEvent>(exec,p,&DOMUIEventTable,this);
00381 }
00382 
00383 Value DOMUIEvent::getValueProperty(ExecState *exec, int token) const
00384 {
00385   switch (token) {
00386   case View:
00387     return getDOMAbstractView(exec,static_cast<DOM::UIEvent>(event).view());
00388   case Detail:
00389     return Number(static_cast<DOM::UIEvent>(event).detail());
00390   default:
00391     kdWarning() << "Unhandled token in DOMUIEvent::getValueProperty : " << token << endl;
00392     return Value();
00393   }
00394 }
00395 
00396 Value DOMUIEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00397 {
00398   KJS_CHECK_THIS( KJS::DOMUIEvent, thisObj );
00399   DOM::UIEvent uiEvent = static_cast<DOMUIEvent *>(thisObj.imp())->toUIEvent();
00400   switch (id) {
00401     case DOMUIEvent::InitUIEvent: {
00402       DOM::AbstractView v = toAbstractView(args[3]);
00403       static_cast<DOM::UIEvent>(uiEvent).initUIEvent(args[0].toString(exec).string(),
00404                                                      args[1].toBoolean(exec),
00405                                                      args[2].toBoolean(exec),
00406                                                      v,
00407                                                      args[4].toInteger(exec));
00408       }
00409       return Undefined();
00410   }
00411   return Undefined();
00412 }
00413 
00414 // -------------------------------------------------------------------------
00415 
00416 const ClassInfo DOMMouseEvent::info = { "MouseEvent", &DOMUIEvent::info, &DOMMouseEventTable, 0 };
00417 
00418 /*
00419 @begin DOMMouseEventTable 2
00420   screenX   DOMMouseEvent::ScreenX  DontDelete|ReadOnly
00421   screenY   DOMMouseEvent::ScreenY  DontDelete|ReadOnly
00422   clientX   DOMMouseEvent::ClientX  DontDelete|ReadOnly
00423   x     DOMMouseEvent::X    DontDelete|ReadOnly
00424   clientY   DOMMouseEvent::ClientY  DontDelete|ReadOnly
00425   y     DOMMouseEvent::Y    DontDelete|ReadOnly
00426   offsetX   DOMMouseEvent::OffsetX  DontDelete|ReadOnly
00427   offsetY   DOMMouseEvent::OffsetY  DontDelete|ReadOnly
00428   ctrlKey   DOMMouseEvent::CtrlKey  DontDelete|ReadOnly
00429   shiftKey  DOMMouseEvent::ShiftKey DontDelete|ReadOnly
00430   altKey    DOMMouseEvent::AltKey   DontDelete|ReadOnly
00431   metaKey   DOMMouseEvent::MetaKey  DontDelete|ReadOnly
00432   button    DOMMouseEvent::Button   DontDelete|ReadOnly
00433   relatedTarget DOMMouseEvent::RelatedTarget DontDelete|ReadOnly
00434   fromElement   DOMMouseEvent::FromElement DontDelete|ReadOnly
00435   toElement DOMMouseEvent::ToElement    DontDelete|ReadOnly
00436 @end
00437 @begin DOMMouseEventProtoTable 1
00438   initMouseEvent    DOMMouseEvent::InitMouseEvent   DontDelete|Function 15
00439 @end
00440 */
00441 DEFINE_PROTOTYPE("DOMMouseEvent",DOMMouseEventProto)
00442 IMPLEMENT_PROTOFUNC_DOM(DOMMouseEventProtoFunc)
00443 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMouseEventProto,DOMMouseEventProtoFunc,DOMUIEventProto)
00444 
00445 DOMMouseEvent::~DOMMouseEvent()
00446 {
00447 }
00448 
00449 Value DOMMouseEvent::tryGet(ExecState *exec, const UString &p) const
00450 {
00451 #ifdef KJS_VERBOSE
00452   kdDebug(6070) << "DOMMouseEvent::tryGet " << p.qstring() << endl;
00453 #endif
00454   return DOMObjectLookupGetValue<DOMMouseEvent,DOMUIEvent>(exec,p,&DOMMouseEventTable,this);
00455 }
00456 
00457 Value DOMMouseEvent::getValueProperty(ExecState *exec, int token) const
00458 {
00459   switch (token) {
00460   case ScreenX:
00461     return Number(static_cast<DOM::MouseEvent>(event).screenX());
00462   case ScreenY:
00463     return Number(static_cast<DOM::MouseEvent>(event).screenY());
00464   case ClientX:
00465   case X:
00466     return Number(static_cast<DOM::MouseEvent>(event).clientX());
00467   case ClientY:
00468   case Y:
00469     return Number(static_cast<DOM::MouseEvent>(event).clientY());
00470   case OffsetX:
00471   case OffsetY: // MSIE extension
00472   {
00473     DOM::Node node = event.target();
00474     node.handle()->getDocument()->updateRendering();
00475     khtml::RenderObject *rend = node.handle() ? node.handle()->renderer() : 0L;
00476     int x = static_cast<DOM::MouseEvent>(event).clientX();
00477     int y = static_cast<DOM::MouseEvent>(event).clientY();
00478     if ( rend ) {
00479       int xPos, yPos;
00480       if ( rend->absolutePosition( xPos, yPos ) ) {
00481         kdDebug() << "DOMMouseEvent::getValueProperty rend=" << rend << "  xPos=" << xPos << "  yPos=" << yPos << endl;
00482         x -= xPos;
00483         y -= yPos;
00484       }
00485     }
00486     return Number( token == OffsetX ? x : y );
00487   }
00488   case CtrlKey:
00489     return Boolean(static_cast<DOM::MouseEvent>(event).ctrlKey());
00490   case ShiftKey:
00491     return Boolean(static_cast<DOM::MouseEvent>(event).shiftKey());
00492   case AltKey:
00493     return Boolean(static_cast<DOM::MouseEvent>(event).altKey());
00494   case MetaKey:
00495     return Boolean(static_cast<DOM::MouseEvent>(event).metaKey());
00496   case Button:
00497   {
00498     // Tricky. The DOM (and khtml) use 0 for LMB, 1 for MMB and 2 for RMB
00499     // but MSIE uses 1=LMB, 2=RMB, 4=MMB, as a bitfield
00500     int domButton = static_cast<DOM::MouseEvent>(event).button();
00501     int button = domButton==0 ? 1 : domButton==1 ? 4 : domButton==2 ? 2 : 0;
00502     return Number( (unsigned int)button );
00503   }
00504   case ToElement:
00505     // MSIE extension - "the object toward which the user is moving the mouse pointer"
00506     if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT)
00507       return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget());
00508     return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target());
00509   case FromElement:
00510     // MSIE extension - "object from which activation
00511     // or the mouse pointer is exiting during the event" (huh?)
00512     if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT)
00513       return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target());
00514     /* fall through */
00515   case RelatedTarget:
00516     return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget());
00517   default:
00518     kdWarning() << "Unhandled token in DOMMouseEvent::getValueProperty : " << token << endl;
00519     return Value();
00520   }
00521 }
00522 
00523 Value DOMMouseEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00524 {
00525   KJS_CHECK_THIS( KJS::DOMMouseEvent, thisObj );
00526   DOM::MouseEvent mouseEvent = static_cast<DOMMouseEvent *>(thisObj.imp())->toMouseEvent();
00527   switch (id) {
00528     case DOMMouseEvent::InitMouseEvent:
00529       mouseEvent.initMouseEvent(args[0].toString(exec).string(), // typeArg
00530                                 args[1].toBoolean(exec), // canBubbleArg
00531                                 args[2].toBoolean(exec), // cancelableArg
00532                                 toAbstractView(args[3]), // viewArg
00533                                 args[4].toInteger(exec), // detailArg
00534                                 args[5].toInteger(exec), // screenXArg
00535                                 args[6].toInteger(exec), // screenYArg
00536                                 args[7].toInteger(exec), // clientXArg
00537                                 args[8].toInteger(exec), // clientYArg
00538                                 args[9].toBoolean(exec), // ctrlKeyArg
00539                                 args[10].toBoolean(exec), // altKeyArg
00540                                 args[11].toBoolean(exec), // shiftKeyArg
00541                                 args[12].toBoolean(exec), // metaKeyArg
00542                                 args[13].toInteger(exec), // buttonArg
00543                                 toNode(args[14])); // relatedTargetArg
00544       return Undefined();
00545   }
00546   return Undefined();
00547 }
00548 
00549 // -------------------------------------------------------------------------
00550 
00551 const ClassInfo DOMTextEvent::info = { "TextEvent", &DOMUIEvent::info, &DOMTextEventTable, 0 };
00552 
00553 /*
00554 @begin DOMTextEventTable 2
00555   keyVal     DOMTextEvent::Key       DontDelete|ReadOnly
00556 # IE's name for it
00557   keyCode        DOMTextEvent::Key       DontDelete|ReadOnly
00558   virtKeyVal     DOMTextEvent::VirtKey        DontDelete|ReadOnly
00559   outputString   DOMTextEvent::OutputString   DontDelete|ReadOnly
00560   inputGenerated DOMTextEvent::InputGenerated DontDelete|ReadOnly
00561   numPad         DOMTextEvent::NumPad         DontDelete|ReadOnly
00562 @end
00563 @begin DOMTextEventProtoTable 1
00564   initTextEvent DOMTextEvent::InitTextEvent DontDelete|Function 10
00565   # Missing: initTextEventNS, initModifier
00566 @end
00567 */
00568 DEFINE_PROTOTYPE("DOMTextEvent",DOMTextEventProto)
00569 IMPLEMENT_PROTOFUNC_DOM(DOMTextEventProtoFunc)
00570 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMTextEventProto,DOMTextEventProtoFunc,DOMUIEventProto)
00571 
00572 DOMTextEvent::~DOMTextEvent()
00573 {
00574 }
00575 
00576 Value DOMTextEvent::tryGet(ExecState *exec, const UString &p) const
00577 {
00578 #ifdef KJS_VERBOSE
00579   kdDebug(6070) << "DOMTextEvent::tryGet " << p.qstring() << endl;
00580 #endif
00581   return DOMObjectLookupGetValue<DOMTextEvent,DOMUIEvent>(exec,p,&DOMTextEventTable,this);
00582 }
00583 
00584 Value DOMTextEvent::getValueProperty(ExecState *, int token) const
00585 {
00586   switch (token) {
00587   case Key:
00588     return Number(static_cast<DOM::TextEvent>(event).keyVal());
00589   case VirtKey:
00590     return Number(static_cast<DOM::TextEvent>(event).virtKeyVal());
00591   case OutputString:
00592     return String(static_cast<DOM::TextEvent>(event).outputString());
00593   case InputGenerated:
00594     return Boolean(static_cast<DOM::TextEvent>(event).inputGenerated());
00595   case NumPad:
00596     return Boolean(static_cast<DOM::TextEvent>(event).numPad());
00597   default:
00598     kdWarning() << "Unhandled token in DOMTextEvent::getValueProperty : " << token << endl;
00599     return Value();
00600   }
00601 }
00602 
00603 Value DOMTextEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00604 {
00605   KJS_CHECK_THIS( KJS::DOMTextEvent, thisObj );
00606   DOM::TextEvent keyEvent = static_cast<DOMTextEvent *>(thisObj.imp())->toTextEvent();
00607   switch (id) {
00608     case DOMTextEvent::InitTextEvent:
00609       keyEvent.initTextEvent(args[0].toString(exec).string(), // typeArg
00610                             args[1].toBoolean(exec), // canBubbleArg
00611                             args[2].toBoolean(exec), // cancelableArg
00612                             toAbstractView(args[3]), // viewArg
00613                             args[4].toInteger(exec), // detailArg
00614                             args[5].toString(exec).string(),  // outputStringArg
00615                             args[6].toInteger(exec), // keyValArg
00616                             args[7].toInteger(exec), // virtKeyValArg
00617                             args[8].toBoolean(exec), // inputGeneratedArg
00618                             args[9].toBoolean(exec));// numPadArg
00619 
00620       return Undefined();
00621   }
00622   return Undefined();
00623 }
00624 
00625 // -------------------------------------------------------------------------
00626 
00627 const ClassInfo MutationEventConstructor::info = { "MutationEventConstructor", 0, &MutationEventConstructorTable, 0 };
00628 /*
00629 @begin MutationEventConstructorTable 3
00630   MODIFICATION  DOM::MutationEvent::MODIFICATION    DontDelete|ReadOnly
00631   ADDITION  DOM::MutationEvent::ADDITION        DontDelete|ReadOnly
00632   REMOVAL   DOM::MutationEvent::REMOVAL     DontDelete|ReadOnly
00633 @end
00634 */
00635 MutationEventConstructor::MutationEventConstructor(ExecState* exec)
00636   : DOMObject(exec->interpreter()->builtinObjectPrototype())
00637 {
00638 }
00639 
00640 Value MutationEventConstructor::tryGet(ExecState *exec, const UString &p) const
00641 {
00642   return DOMObjectLookupGetValue<MutationEventConstructor,DOMObject>(exec,p,&MutationEventConstructorTable,this);
00643 }
00644 
00645 Value MutationEventConstructor::getValueProperty(ExecState *, int token) const
00646 {
00647   // We use the token as the value to return directly
00648   return Number(token);
00649 }
00650 
00651 Value KJS::getMutationEventConstructor(ExecState *exec)
00652 {
00653   return cacheGlobalObject<MutationEventConstructor>(exec, "[[mutationEvent.constructor]]");
00654 }
00655 
00656 // -------------------------------------------------------------------------
00657 
00658 const ClassInfo DOMMutationEvent::info = { "MutationEvent", &DOMEvent::info, &DOMMutationEventTable, 0 };
00659 /*
00660 @begin DOMMutationEventTable 5
00661   relatedNode   DOMMutationEvent::RelatedNode   DontDelete|ReadOnly
00662   prevValue DOMMutationEvent::PrevValue DontDelete|ReadOnly
00663   newValue  DOMMutationEvent::NewValue  DontDelete|ReadOnly
00664   attrName  DOMMutationEvent::AttrName  DontDelete|ReadOnly
00665   attrChange    DOMMutationEvent::AttrChange    DontDelete|ReadOnly
00666 @end
00667 @begin DOMMutationEventProtoTable 1
00668   initMutationEvent DOMMutationEvent::InitMutationEvent DontDelete|Function 8
00669 @end
00670 */
00671 DEFINE_PROTOTYPE("DOMMutationEvent",DOMMutationEventProto)
00672 IMPLEMENT_PROTOFUNC_DOM(DOMMutationEventProtoFunc)
00673 IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMutationEventProto,DOMMutationEventProtoFunc,DOMEventProto)
00674 
00675 DOMMutationEvent::~DOMMutationEvent()
00676 {
00677 }
00678 
00679 Value DOMMutationEvent::tryGet(ExecState *exec, const UString &p) const
00680 {
00681   return DOMObjectLookupGetValue<DOMMutationEvent,DOMEvent>(exec,p,&DOMMutationEventTable,this);
00682 }
00683 
00684 Value DOMMutationEvent::getValueProperty(ExecState *exec, int token) const
00685 {
00686   switch (token) {
00687   case RelatedNode:
00688     return getDOMNode(exec,static_cast<DOM::MutationEvent>(event).relatedNode());
00689   case PrevValue:
00690     return String(static_cast<DOM::MutationEvent>(event).prevValue());
00691   case NewValue:
00692     return String(static_cast<DOM::MutationEvent>(event).newValue());
00693   case AttrName:
00694     return String(static_cast<DOM::MutationEvent>(event).attrName());
00695   case AttrChange:
00696     return Number((unsigned int)static_cast<DOM::MutationEvent>(event).attrChange());
00697   default:
00698     kdWarning() << "Unhandled token in DOMMutationEvent::getValueProperty : " << token << endl;
00699     return Value();
00700   }
00701 }
00702 
00703 Value DOMMutationEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00704 {
00705   KJS_CHECK_THIS( KJS::DOMMutationEvent, thisObj );
00706   DOM::MutationEvent mutationEvent = static_cast<DOMMutationEvent *>(thisObj.imp())->toMutationEvent();
00707   switch (id) {
00708     case DOMMutationEvent::InitMutationEvent:
00709       mutationEvent.initMutationEvent(args[0].toString(exec).string(), // typeArg,
00710                                       args[1].toBoolean(exec), // canBubbleArg
00711                                       args[2].toBoolean(exec), // cancelableArg
00712                                       toNode(args[3]), // relatedNodeArg
00713                                       args[4].toString(exec).string(), // prevValueArg
00714                                       args[5].toString(exec).string(), // newValueArg
00715                                       args[6].toString(exec).string(), // attrNameArg
00716                                       args[7].toInteger(exec)); // attrChangeArg
00717       return Undefined();
00718   }
00719   return Undefined();
00720 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:40 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001