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, 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     Object listenerObj() const { return listener; }
00048     // Faster version of listenerObj()
00049     ObjectImp *listenerObjImp() const { return static_cast<ObjectImp *>(listener.imp()); }
00050     // for Window::clear()
00051     void clear() { listener = Object(); }
00052 
00053   protected:
00054     Object listener;
00055     bool html;
00056     Object win, m_hackThisObj;
00057   };
00058 
00059   Value getNodeEventListener(DOM::Node n, int eventId);
00060 
00061   // Constructor for Event - currently only used for some global vars
00062   class EventConstructor : public DOMObject {
00063   public:
00064     EventConstructor(ExecState *);
00065     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00066     Value getValueProperty(ExecState *, int token) const;
00067     // no put - all read-only
00068     virtual const ClassInfo* classInfo() const { return &info; }
00069     static const ClassInfo info;
00070   };
00071 
00072   Value getEventConstructor(ExecState *exec);
00073 
00074   class DOMEvent : public DOMObject {
00075   public:
00076     // Build a DOMEvent
00077     DOMEvent(ExecState *exec, DOM::Event e);
00078     // Constructor for inherited classes
00079     DOMEvent(const Object &proto, DOM::Event e);
00080     ~DOMEvent();
00081     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00082     Value getValueProperty(ExecState *, int token) const;
00083     virtual void tryPut(ExecState *exec, const Identifier &propertyName,
00084             const Value& value, int attr = None);
00085     virtual Value defaultValue(ExecState *exec, KJS::Type hint) const;
00086     void putValueProperty(ExecState *exec, int token, const Value& value, int);
00087     virtual const ClassInfo* classInfo() const { return &info; }
00088     static const ClassInfo info;
00089     enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00090            Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00091        // MS IE equivalents
00092        SrcElement, ReturnValue, CancelBubble };
00093     DOM::Event toEvent() const { return event; }
00094   protected:
00095     DOM::Event event;
00096   };
00097 
00098   Value getDOMEvent(ExecState *exec, DOM::Event e);
00099 
00103   DOM::Event toEvent(const Value&);
00104 
00105   // Constructor object EventException
00106   class EventExceptionConstructor : public DOMObject {
00107   public:
00108     EventExceptionConstructor(ExecState *);
00109     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00110     Value getValueProperty(ExecState *, int token) const;
00111     // no put - all read-only
00112     virtual const ClassInfo* classInfo() const { return &info; }
00113     static const ClassInfo info;
00114   };
00115 
00116   Value getEventExceptionConstructor(ExecState *exec);
00117 
00118   class DOMUIEvent : public DOMEvent {
00119   public:
00120     // Build a DOMUIEvent
00121     DOMUIEvent(ExecState *exec, DOM::UIEvent ue);
00122     // Constructor for inherited classes
00123     DOMUIEvent(const Object &proto, DOM::UIEvent ue);
00124     ~DOMUIEvent();
00125     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00126     Value getValueProperty(ExecState *, int token) const;
00127     // no put - all read-only
00128     virtual const ClassInfo* classInfo() const { return &info; }
00129     static const ClassInfo info;
00130     enum { View, Detail, KeyCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
00131     DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00132   };
00133 
00134   class DOMMouseEvent : public DOMUIEvent {
00135   public:
00136     DOMMouseEvent(ExecState *exec, DOM::MouseEvent me);
00137     ~DOMMouseEvent();
00138     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00139     Value getValueProperty(ExecState *, int token) const;
00140     // no put - all read-only
00141     virtual const ClassInfo* classInfo() const { return &info; }
00142     static const ClassInfo info;
00143     enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00144            CtrlKey, ShiftKey, AltKey,
00145            MetaKey, Button, RelatedTarget, FromElement, ToElement,
00146            InitMouseEvent
00147     };
00148     DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00149   };
00150 
00151   class DOMTextEvent : public DOMUIEvent {
00152   public:
00153     DOMTextEvent(ExecState *exec, DOM::TextEvent ke);
00154     ~DOMTextEvent();
00155     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00156     Value getValueProperty(ExecState *, int token) const;
00157     // no put - all read-only
00158     virtual const ClassInfo* classInfo() const { return &info; }
00159     static const ClassInfo info;
00160     enum { Key, VirtKey, OutputString, InitTextEvent, InputGenerated, NumPad };
00161     DOM::TextEvent toTextEvent() const { return static_cast<DOM::TextEvent>(event); }
00162   };
00163 
00164   // Constructor object MutationEvent
00165   class MutationEventConstructor : public DOMObject {
00166   public:
00167     MutationEventConstructor(ExecState *);
00168     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00169     Value getValueProperty(ExecState *, int token) const;
00170     // no put - all read-only
00171     virtual const ClassInfo* classInfo() const { return &info; }
00172     static const ClassInfo info;
00173   };
00174 
00175   Value getMutationEventConstructor(ExecState *exec);
00176 
00177   class DOMMutationEvent : public DOMEvent {
00178   public:
00179     DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00180     ~DOMMutationEvent();
00181     virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00182     Value getValueProperty(ExecState *, int token) const;
00183     // no put - all read-only
00184     virtual const ClassInfo* classInfo() const { return &info; }
00185     static const ClassInfo info;
00186     enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00187            InitMutationEvent };
00188     DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00189   };
00190 
00191 } // namespace
00192 
00193 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:21 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003