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  *
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 #ifndef _KJS_EVENTS_H_
00022 #define _KJS_EVENTS_H_
00023 
00024 #include "ecma/kjs_dom.h"
00025 #include "dom/dom2_events.h"
00026 #include "dom/dom_misc.h"
00027 
00028 namespace KJS {
00029 
00030   class Window;
00031 
00032   class JSEventListener : public DOM::EventListener {
00033   public:
00039     JSEventListener(Object _listener, const Object &_win, bool _html = false);
00040     virtual ~JSEventListener();
00041     void hackSetThisObj( Object& thisObj ) { m_hackThisObj = thisObj; }
00042     void hackUnsetThisObj() { m_hackThisObj = Object(0L); }
00043     virtual void handleEvent(DOM::Event &evt);
00044     virtual DOM::DOMString eventListenerType();
00045     // Return the KJS function object executed when this event is emitted
00046     Object listenerObj() const { return listener; }
00047     // Faster version of listenerObj()
00048     ObjectImp *listenerObjImp() const { return static_cast<ObjectImp *>(listener.imp()); }
00049     // for Window::clear()
00050     void clear() { listener = Object(); }
00051 
00052   protected:
00053     Object listener;
00054     bool html;
00055     Object win, m_hackThisObj;
00056   };
00057 
00058   Value getNodeEventListener(DOM::Node n, int eventId);
00059 
00060   // Constructor for Event - currently only used for some global vars
00061   class EventConstructor : public DOMObject {
00062   public:
00063     EventConstructor(ExecState *);
00064     virtual Value tryGet(ExecState *exec,const UString &p) const;
00065     Value getValueProperty(ExecState *, int token) const;
00066     // no put - all read-only
00067     virtual const ClassInfo* classInfo() const { return &info; }
00068     static const ClassInfo info;
00069   };
00070 
00071   Value getEventConstructor(ExecState *exec);
00072 
00073   class DOMEvent : public DOMObject {
00074   public:
00075     DOMEvent(ExecState *exec, DOM::Event e);
00076     ~DOMEvent();
00077     virtual Value tryGet(ExecState *exec,const UString &p) const;
00078     Value getValueProperty(ExecState *, int token) const;
00079     virtual void tryPut(ExecState *exec, const UString &propertyName,
00080             const Value& value, int attr = None);
00081     void putValueProperty(ExecState *exec, int token, const Value& value, int);
00082     virtual const ClassInfo* classInfo() const { return &info; }
00083     static const ClassInfo info;
00084     enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00085            Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00086        // MS IE equivalents
00087        SrcElement, ReturnValue, CancelBubble };
00088     DOM::Event toEvent() const { return event; }
00089   protected:
00090     DOM::Event event;
00091   };
00092 
00093   Value getDOMEvent(ExecState *exec, DOM::Event e);
00094 
00098   DOM::Event toEvent(const Value&);
00099 
00100   // Constructor object EventException
00101   class EventExceptionConstructor : public DOMObject {
00102   public:
00103     EventExceptionConstructor(ExecState *);
00104     virtual Value tryGet(ExecState *exec,const UString &p) const;
00105     Value getValueProperty(ExecState *, int token) const;
00106     // no put - all read-only
00107     virtual const ClassInfo* classInfo() const { return &info; }
00108     static const ClassInfo info;
00109   };
00110 
00111   Value getEventExceptionConstructor(ExecState *exec);
00112 
00113   class DOMUIEvent : public DOMEvent {
00114   public:
00115     DOMUIEvent(ExecState *exec, DOM::UIEvent ue) : DOMEvent(exec, ue) {}
00116     ~DOMUIEvent();
00117     virtual Value tryGet(ExecState *exec,const UString &p) const;
00118     Value getValueProperty(ExecState *, int token) const;
00119     // no put - all read-only
00120     virtual const ClassInfo* classInfo() const { return &info; }
00121     static const ClassInfo info;
00122     enum { View, Detail, InitUIEvent };
00123     DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00124   };
00125 
00126   class DOMMouseEvent : public DOMUIEvent {
00127   public:
00128     DOMMouseEvent(ExecState *exec, DOM::MouseEvent me) : DOMUIEvent(exec, me) {}
00129     ~DOMMouseEvent();
00130     virtual Value tryGet(ExecState *exec,const UString &p) const;
00131     Value getValueProperty(ExecState *, int token) const;
00132     // no put - all read-only
00133     virtual const ClassInfo* classInfo() const { return &info; }
00134     static const ClassInfo info;
00135     enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00136            CtrlKey, ShiftKey, AltKey,
00137            MetaKey, Button, RelatedTarget, FromElement, ToElement,
00138            InitMouseEvent };
00139     DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00140   };
00141 
00142   class DOMTextEvent : public DOMUIEvent {
00143   public:
00144     DOMTextEvent(ExecState *exec, DOM::TextEvent ke) : DOMUIEvent(exec, ke) {}
00145     ~DOMTextEvent();
00146     virtual Value tryGet(ExecState *exec,const UString &p) const;
00147     Value getValueProperty(ExecState *, int token) const;
00148     // no put - all read-only
00149     virtual const ClassInfo* classInfo() const { return &info; }
00150     static const ClassInfo info;
00151     enum { Key, VirtKey, OutputString, InitTextEvent, InputGenerated, NumPad };
00152     DOM::TextEvent toTextEvent() const { return static_cast<DOM::TextEvent>(event); }
00153   };
00154 
00155   // Constructor object MutationEvent
00156   class MutationEventConstructor : public DOMObject {
00157   public:
00158     MutationEventConstructor(ExecState *);
00159     virtual Value tryGet(ExecState *exec,const UString &p) const;
00160     Value getValueProperty(ExecState *, int token) const;
00161     // no put - all read-only
00162     virtual const ClassInfo* classInfo() const { return &info; }
00163     static const ClassInfo info;
00164   };
00165 
00166   Value getMutationEventConstructor(ExecState *exec);
00167 
00168   class DOMMutationEvent : public DOMEvent {
00169   public:
00170     DOMMutationEvent(ExecState *exec, DOM::MutationEvent me) : DOMEvent(exec, me) {}
00171     ~DOMMutationEvent();
00172     virtual Value tryGet(ExecState *exec,const UString &p) const;
00173     Value getValueProperty(ExecState *, int token) const;
00174     // no put - all read-only
00175     virtual const ClassInfo* classInfo() const { return &info; }
00176     static const ClassInfo info;
00177     enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00178            InitMutationEvent };
00179     DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00180   };
00181 
00182 }; // namespace
00183 
00184 #endif
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