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