khtml Library API Documentation

kjs_events.h

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  *  Copyright (C) 2003 Apple Computer, Inc.
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Library General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #ifndef _KJS_EVENTS_H_
00023 #define _KJS_EVENTS_H_
00024 
00025 #include "ecma/kjs_dom.h"
00026 #include "dom/dom2_events.h"
00027 #include "dom/dom_misc.h"
00028 
00029 namespace KJS {
00030 
00031   class Window;
00032 
00033   class JSEventListener : public DOM::EventListener {
00034   public:
00040     JSEventListener(Object _listener, ObjectImp *_compareListenerImp, const Object &_win, bool _html = false);
00041     virtual ~JSEventListener();
00042     void hackSetThisObj( Object& thisObj ) { m_hackThisObj = thisObj; }
00043     void hackUnsetThisObj() { m_hackThisObj = Object(0L); }
00044     virtual void handleEvent(DOM::Event &evt);
00045     virtual DOM::DOMString eventListenerType();
00046     // Return the KJS function object executed when this event is emitted
00047     virtual Object listenerObj() const;
00048     ObjectImp *listenerObjImp() const { return listenerObj().imp(); }
00049     // for Window::clear(). This is a bad hack though. The JSEventListener might not get deleted
00050     // if it was added to a DOM node in another frame (#61467). But calling removeEventListener on
00051     // all nodes we're listening to is quite difficult.
00052     void clear() { listener = Object(); }
00053 
00054   protected:
00055     mutable Object listener;
00056     // Storing a different ObjectImp ptr is needed to support addEventListener(.. [Object] ..) calls
00057     // In the real-life case (where a 'function' is passed to addEventListener) we can directly call
00058     // the 'listener' object and can cache the 'listener.imp()'. If the event listener should be removed
00059     // the implementation will call removeEventListener(.. [Function] ..), and we can lookup the event
00060     // listener by the passed function's imp() ptr.
00061     // In the only dom-approved way (passing an Object to add/removeEventListener), the 'listener'
00062     // variable stores the function object 'passedListener.handleEvent'. But we need to cache
00063     // the imp() ptr of the 'passedListener' function _object_, as the implementation will
00064     // call removeEventListener(.. [Object ..] on removal, and now we can successfully lookup
00065     // the correct event listener, as well as the 'listener.handleEvent' function, we need to call.
00066     mutable ObjectImp *compareListenerImp;
00067     bool html;
00068     Object win, m_hackThisObj;
00069   };
00070 
00071   class JSLazyEventListener : public JSEventListener {
00072   public:
00073     JSLazyEventListener(const QString &_code, const QString &_name, const Object &_win, bool _html = false);
00074     ~JSLazyEventListener();
00075     virtual void handleEvent(DOM::Event &evt);
00076     Object listenerObj() const;
00077   private:
00078     void parseCode() const;
00079 
00080     mutable QString code;
00081     mutable QString name;
00082     mutable bool parsed;
00083   };
00084 
00085   // Constructor for Event - currently only used for some global vars
00086   class EventConstructor : public DOMObject {
00087   public:
00088     EventConstructor(ExecState *);
00089     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00090     Value getValueProperty(ExecState *, int token) const;
00091     // no put - all read-only
00092     virtual const ClassInfo* classInfo() const { return &info; }
00093     static const ClassInfo info;
00094   };
00095 
00096   Value getEventConstructor(ExecState *exec);
00097 
00098   class DOMEvent : public DOMObject {
00099   public:
00100     // Build a DOMEvent
00101     DOMEvent(ExecState *exec, DOM::Event e);
00102     // Constructor for inherited classes
00103     DOMEvent(const Object &proto, DOM::Event e);
00104     ~DOMEvent();
00105     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00106     Value getValueProperty(ExecState *, int token) const;
00107     virtual void tryPut(ExecState *exec, const Identifier &propertyName,
00108             const Value& value, int attr = None);
00109     virtual Value defaultValue(ExecState *exec, KJS::Type hint) const;
00110     void putValueProperty(ExecState *exec, int token, const Value& value, int);
00111     virtual const ClassInfo* classInfo() const { return &info; }
00112     static const ClassInfo info;
00113     enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00114            Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00115        // MS IE equivalents
00116        SrcElement, ReturnValue, CancelBubble };
00117     DOM::Event toEvent() const { return event; }
00118   protected:
00119     DOM::Event event;
00120   };
00121 
00122   Value getDOMEvent(ExecState *exec, DOM::Event e);
00123 
00127   DOM::Event toEvent(const Value&);
00128 
00129   // Constructor object EventException
00130   class EventExceptionConstructor : public DOMObject {
00131   public:
00132     EventExceptionConstructor(ExecState *);
00133     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00134     Value getValueProperty(ExecState *, int token) const;
00135     // no put - all read-only
00136     virtual const ClassInfo* classInfo() const { return &info; }
00137     static const ClassInfo info;
00138   };
00139 
00140   Value getEventExceptionConstructor(ExecState *exec);
00141 
00142   class DOMUIEvent : public DOMEvent {
00143   public:
00144     // Build a DOMUIEvent
00145     DOMUIEvent(ExecState *exec, DOM::UIEvent ue);
00146     // Constructor for inherited classes
00147     DOMUIEvent(const Object &proto, DOM::UIEvent ue);
00148     ~DOMUIEvent();
00149     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00150     Value getValueProperty(ExecState *, int token) const;
00151     // no put - all read-only
00152     virtual const ClassInfo* classInfo() const { return &info; }
00153     static const ClassInfo info;
00154     enum { View, Detail, KeyCode, CharCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
00155     DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00156   };
00157 
00158   class DOMMouseEvent : public DOMUIEvent {
00159   public:
00160     DOMMouseEvent(ExecState *exec, DOM::MouseEvent me);
00161     ~DOMMouseEvent();
00162     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00163     Value getValueProperty(ExecState *, int token) const;
00164     // no put - all read-only
00165     virtual const ClassInfo* classInfo() const { return &info; }
00166     static const ClassInfo info;
00167     enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00168            CtrlKey, ShiftKey, AltKey,
00169            MetaKey, Button, RelatedTarget, FromElement, ToElement,
00170            InitMouseEvent
00171     };
00172     DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00173   };
00174 
00175   class DOMTextEvent : public DOMUIEvent {
00176   public:
00177     DOMTextEvent(ExecState *exec, DOM::TextEvent ke);
00178     ~DOMTextEvent();
00179     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00180     Value getValueProperty(ExecState *, int token) const;
00181     // no put - all read-only
00182     virtual const ClassInfo* classInfo() const { return &info; }
00183     static const ClassInfo info;
00184     enum { Key, VirtKey, OutputString, InitTextEvent, InputGenerated, NumPad };
00185     DOM::TextEvent toTextEvent() const { return static_cast<DOM::TextEvent>(event); }
00186   };
00187 
00188   // Constructor object MutationEvent
00189   class MutationEventConstructor : public DOMObject {
00190   public:
00191     MutationEventConstructor(ExecState *);
00192     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00193     Value getValueProperty(ExecState *, int token) const;
00194     // no put - all read-only
00195     virtual const ClassInfo* classInfo() const { return &info; }
00196     static const ClassInfo info;
00197   };
00198 
00199   Value getMutationEventConstructor(ExecState *exec);
00200 
00201   class DOMMutationEvent : public DOMEvent {
00202   public:
00203     DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00204     ~DOMMutationEvent();
00205     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00206     Value getValueProperty(ExecState *, int token) const;
00207     // no put - all read-only
00208     virtual const ClassInfo* classInfo() const { return &info; }
00209     static const ClassInfo info;
00210     enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00211            InitMutationEvent };
00212     DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00213   };
00214 
00215 } // namespace
00216 
00217 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 28 01:40:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003