khtml Library API Documentation

dom2_eventsimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * (C) 2001 Peter Kelly (pmk@post.com)
00005  * (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
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 License
00018  * along with this library; see the file COPYING.LIB.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  *
00022  * $Id: dom2_eventsimpl.h,v 1.24.2.3 2003/05/18 12:34:40 mueller Exp $
00023  */
00024 
00025 #ifndef _DOM_EventsImpl_h_
00026 #define _DOM_EventsImpl_h_
00027 
00028 #include "dom/dom2_events.h"
00029 #include "misc/shared.h"
00030 #include "xml/dom2_viewsimpl.h"
00031 #include <qdatetime.h>
00032 #include <qevent.h>
00033 
00034 class KHTMLPart;
00035 
00036 namespace DOM {
00037 
00038 class AbstractViewImpl;
00039 class DOMStringImpl;
00040 class NodeImpl;
00041 
00042 // ### support user-defined events
00043 
00044 class EventImpl : public khtml::Shared<EventImpl>
00045 {
00046 public:
00047     enum EventId {
00048     UNKNOWN_EVENT = 0,
00049     // UI events
00050         DOMFOCUSIN_EVENT,
00051         DOMFOCUSOUT_EVENT,
00052         DOMACTIVATE_EVENT,
00053         // Mouse events
00054         CLICK_EVENT,
00055         MOUSEDOWN_EVENT,
00056         MOUSEUP_EVENT,
00057         MOUSEOVER_EVENT,
00058         MOUSEMOVE_EVENT,
00059         MOUSEOUT_EVENT,
00060         // Mutation events
00061         DOMSUBTREEMODIFIED_EVENT,
00062         DOMNODEINSERTED_EVENT,
00063         DOMNODEREMOVED_EVENT,
00064         DOMNODEREMOVEDFROMDOCUMENT_EVENT,
00065         DOMNODEINSERTEDINTODOCUMENT_EVENT,
00066         DOMATTRMODIFIED_EVENT,
00067         DOMCHARACTERDATAMODIFIED_EVENT,
00068     // HTML events
00069     LOAD_EVENT,
00070     UNLOAD_EVENT,
00071     ABORT_EVENT,
00072     ERROR_EVENT,
00073     SELECT_EVENT,
00074     CHANGE_EVENT,
00075     SUBMIT_EVENT,
00076     RESET_EVENT,
00077     FOCUS_EVENT,
00078     BLUR_EVENT,
00079     RESIZE_EVENT,
00080     SCROLL_EVENT,
00081     // khtml events (not part of DOM)
00082     KHTML_ECMA_DBLCLICK_EVENT, // for html ondblclick
00083     KHTML_ECMA_CLICK_EVENT, // for html onclick
00084     KHTML_DRAGDROP_EVENT,
00085     KHTML_ERROR_EVENT,
00086     KHTML_KEYDOWN_EVENT,
00087     KHTML_KEYPRESS_EVENT,
00088     KHTML_KEYUP_EVENT,
00089     KHTML_MOVE_EVENT,
00090     KHTML_ORIGCLICK_MOUSEUP_EVENT
00091     };
00092 
00093     EventImpl();
00094     EventImpl(EventId _id, bool canBubbleArg, bool cancelableArg);
00095     virtual ~EventImpl();
00096 
00097     EventId id() { return m_id; }
00098 
00099     DOMString type() const { return m_type; }
00100     NodeImpl *target() const { return m_target; }
00101     void setTarget(NodeImpl *_target);
00102     NodeImpl *currentTarget() const { return m_currentTarget; }
00103     void setCurrentTarget(NodeImpl *_currentTarget) { m_currentTarget = _currentTarget; }
00104     unsigned short eventPhase() const { return m_eventPhase; }
00105     void setEventPhase(unsigned short _eventPhase) { m_eventPhase = _eventPhase; }
00106     bool bubbles() const { return m_canBubble; }
00107     bool cancelable() const { return m_cancelable; }
00108     DOMTimeStamp timeStamp();
00109     void stopPropagation(bool stop) { m_propagationStopped = stop; }
00110     void preventDefault(bool prevent) { if ( m_cancelable ) m_defaultPrevented = prevent; }
00111 
00112     void initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
00113 
00114     virtual bool isUIEvent() { return false; }
00115     virtual bool isMouseEvent() { return false; }
00116     virtual bool isTextEvent() { return false; }
00117     virtual bool isMutationEvent() { return false; }
00118     virtual DOMString eventModuleName() { return ""; }
00119 
00120     virtual bool propagationStopped() { return m_propagationStopped; }
00121     virtual bool defaultPrevented() { return m_defaultPrevented; }
00122 
00123     static EventId typeToId(DOMString type);
00124     static DOMString idToType(EventId id);
00125 
00126     void setDefaultHandled() { m_defaultHandled = true; }
00127     bool defaultHandled() const { return m_defaultHandled; }
00128 
00129 protected:
00130     DOMStringImpl *m_type;
00131     bool m_canBubble;
00132     bool m_cancelable;
00133 
00134     bool m_propagationStopped;
00135     bool m_defaultPrevented;
00136     bool m_defaultHandled;
00137     EventId m_id;
00138     NodeImpl *m_currentTarget; // ref > 0 maintained externally
00139     unsigned short m_eventPhase;
00140     NodeImpl *m_target;
00141     QDateTime m_createTime;
00142 };
00143 
00144 
00145 
00146 class UIEventImpl : public EventImpl
00147 {
00148 public:
00149     UIEventImpl() : m_view(0), m_detail(0) {};
00150     UIEventImpl(EventId _id,
00151         bool canBubbleArg,
00152         bool cancelableArg,
00153         AbstractViewImpl *viewArg,
00154         long detailArg);
00155     virtual ~UIEventImpl();
00156     AbstractViewImpl *view() const { return m_view; }
00157     long detail() const { return m_detail; }
00158     void initUIEvent(const DOMString &typeArg,
00159              bool canBubbleArg,
00160              bool cancelableArg,
00161              const AbstractView &viewArg,
00162              long detailArg);
00163     virtual bool isUIEvent() { return true; }
00164     virtual DOMString eventModuleName() { return "UIEvents"; }
00165 protected:
00166     AbstractViewImpl *m_view;
00167     long m_detail;
00168 
00169 };
00170 
00171 
00172 
00173 
00174 // Introduced in DOM Level 2: - internal
00175 class MouseEventImpl : public UIEventImpl {
00176 public:
00177     MouseEventImpl();
00178     MouseEventImpl(EventId _id,
00179            bool canBubbleArg,
00180            bool cancelableArg,
00181            AbstractViewImpl *viewArg,
00182            long detailArg,
00183            long screenXArg,
00184            long screenYArg,
00185            long clientXArg,
00186            long clientYArg,
00187            bool ctrlKeyArg,
00188            bool altKeyArg,
00189            bool shiftKeyArg,
00190            bool metaKeyArg,
00191            unsigned short buttonArg,
00192            NodeImpl *relatedTargetArg);
00193     virtual ~MouseEventImpl();
00194     long screenX() const { return m_screenX; }
00195     long screenY() const { return m_screenY; }
00196     long clientX() const { return m_clientX; }
00197     long clientY() const { return m_clientY; }
00198     bool ctrlKey() const { return m_ctrlKey; }
00199     bool shiftKey() const { return m_shiftKey; }
00200     bool altKey() const { return m_altKey; }
00201     bool metaKey() const { return m_metaKey; }
00202     unsigned short button() const { return m_button; }
00203     NodeImpl *relatedTarget() const { return m_relatedTarget; }
00204 
00205 
00206     void initMouseEvent(const DOMString &typeArg,
00207             bool canBubbleArg,
00208             bool cancelableArg,
00209             const AbstractView &viewArg,
00210             long detailArg,
00211             long screenXArg,
00212             long screenYArg,
00213             long clientXArg,
00214             long clientYArg,
00215             bool ctrlKeyArg,
00216             bool altKeyArg,
00217             bool shiftKeyArg,
00218             bool metaKeyArg,
00219             unsigned short buttonArg,
00220             const Node &relatedTargetArg);
00221     virtual bool isMouseEvent() { return true; }
00222     virtual DOMString eventModuleName() { return "MouseEvents"; }
00223 protected:
00224     long m_screenX;
00225     long m_screenY;
00226     long m_clientX;
00227     long m_clientY;
00228     bool m_ctrlKey;
00229     bool m_altKey;
00230     bool m_shiftKey;
00231     bool m_metaKey;
00232     unsigned short m_button;
00233     NodeImpl *m_relatedTarget;
00234 };
00235 
00236 
00237 class TextEventImpl : public UIEventImpl {
00238 public:
00239   TextEventImpl();
00240   TextEventImpl(EventId _id,
00241            bool canBubbleArg,
00242            bool cancelableArg,
00243            AbstractViewImpl *viewArg,
00244            unsigned short detailArg,
00245            DOMString &outputStringArg,
00246            unsigned long keyValArg,
00247            unsigned long virtKeyValArg,
00248            bool inputGeneratedArg,
00249            bool numPadArg);
00250 
00251   TextEventImpl(QKeyEvent *key, AbstractViewImpl *view);
00252 
00253   virtual ~TextEventImpl();
00254 
00255   // VirtualKeyCode
00256   enum KeyCodes  {
00257          DOM_VK_UNDEFINED               = 0x0,
00258          DOM_VK_RIGHT_ALT               = 0x01,
00259          DOM_VK_LEFT_ALT                = 0x02,
00260          DOM_VK_LEFT_CONTROL            = 0x03,
00261          DOM_VK_RIGHT_CONTROL           = 0x04,
00262          DOM_VK_LEFT_SHIFT              = 0x05,
00263          DOM_VK_RIGHT_SHIFT             = 0x06,
00264          DOM_VK_LEFT_META               = 0x07,
00265          DOM_VK_RIGHT_META              = 0x08,
00266          DOM_VK_CAPS_LOCK               = 0x09,
00267          DOM_VK_DELETE                  = 0x0A,
00268          DOM_VK_END                     = 0x0B,
00269          DOM_VK_ENTER                   = 0x0C,
00270          DOM_VK_ESCAPE                  = 0x0D,
00271          DOM_VK_HOME                    = 0x0E,
00272          DOM_VK_INSERT                  = 0x0F,
00273          DOM_VK_NUM_LOCK                = 0x10,
00274          DOM_VK_PAUSE                   = 0x11,
00275          DOM_VK_PRINTSCREEN             = 0x12,
00276          DOM_VK_SCROLL_LOCK             = 0x13,
00277          DOM_VK_LEFT                    = 0x14,
00278          DOM_VK_RIGHT                   = 0x15,
00279          DOM_VK_UP                      = 0x16,
00280          DOM_VK_DOWN                    = 0x17,
00281          DOM_VK_PAGE_DOWN               = 0x18,
00282          DOM_VK_PAGE_UP                 = 0x19,
00283          DOM_VK_F1                      = 0x1A,
00284          DOM_VK_F2                      = 0x1B,
00285          DOM_VK_F3                      = 0x1C,
00286          DOM_VK_F4                      = 0x1D,
00287          DOM_VK_F5                      = 0x1E,
00288          DOM_VK_F6                      = 0x1F,
00289          DOM_VK_F7                      = 0x20,
00290          DOM_VK_F8                      = 0x21,
00291          DOM_VK_F9                      = 0x22,
00292          DOM_VK_F10                     = 0x23,
00293          DOM_VK_F11                     = 0x24,
00294          DOM_VK_F12                     = 0x25,
00295          DOM_VK_F13                     = 0x26,
00296          DOM_VK_F14                     = 0x27,
00297          DOM_VK_F15                     = 0x28,
00298          DOM_VK_F16                     = 0x29,
00299          DOM_VK_F17                     = 0x2A,
00300          DOM_VK_F18                     = 0x2B,
00301          DOM_VK_F19                     = 0x2C,
00302          DOM_VK_F20                     = 0x2D,
00303          DOM_VK_F21                     = 0x2E,
00304          DOM_VK_F22                     = 0x2F,
00305          DOM_VK_F23                     = 0x30,
00306          DOM_VK_F24                     = 0x31
00307   };
00308 
00309   void initTextEvent(const DOMString &typeArg,
00310                     bool canBubbleArg,
00311                     bool cancelableArg,
00312                     const AbstractView &viewArg,
00313                     long detailArg,
00314                     const DOMString &outputStringArg,
00315                     unsigned long keyValArg,
00316                     unsigned long virtKeyValArg,
00317                     bool inputGeneratedArg,
00318                     bool numPadArg);
00319   void initModifier(unsigned long modifierArg, bool valueArg);
00320 
00321   bool checkModifier(unsigned long modiferArg);
00322 
00323  //Attributes:
00324     bool             inputGenerated() const { return m_inputGenerated; }
00325     unsigned long    keyVal() const { return m_keyVal; }
00326     unsigned long    virtKeyVal() const { return m_virtKeyVal; }
00327     bool             numPad() const { return m_numPad; }
00328     DOMString        outputString() const { return m_outputString; }
00329 
00330   virtual DOMString eventModuleName() { return "TextEvents"; }
00331   virtual bool isTextEvent() { return true; }
00332 
00333  QKeyEvent *qKeyEvent;
00334 
00335 private:
00336   unsigned long m_keyVal;
00337   unsigned long m_virtKeyVal;
00338   bool m_inputGenerated;
00339   DOMString m_outputString;
00340   bool m_numPad;
00341   // bitfield containing state of modifiers. not part of the dom.
00342   unsigned long    m_modifier;
00343 };
00344 
00345 class MutationEventImpl : public EventImpl {
00346 // ### fire these during parsing (if necessary)
00347 public:
00348     MutationEventImpl();
00349     MutationEventImpl(EventId _id,
00350               bool canBubbleArg,
00351               bool cancelableArg,
00352               const Node &relatedNodeArg,
00353               const DOMString &prevValueArg,
00354               const DOMString &newValueArg,
00355               const DOMString &attrNameArg,
00356               unsigned short attrChangeArg);
00357     ~MutationEventImpl();
00358 
00359     Node relatedNode() const { return m_relatedNode; }
00360     DOMString prevValue() const { return m_prevValue; }
00361     DOMString newValue() const { return m_newValue; }
00362     DOMString attrName() const { return m_attrName; }
00363     unsigned short attrChange() const { return m_attrChange; }
00364     void initMutationEvent(const DOMString &typeArg,
00365                bool canBubbleArg,
00366                bool cancelableArg,
00367                const Node &relatedNodeArg,
00368                const DOMString &prevValueArg,
00369                const DOMString &newValueArg,
00370                const DOMString &attrNameArg,
00371                unsigned short attrChangeArg);
00372     virtual bool isMutationEvent() { return true; }
00373     virtual DOMString eventModuleName() { return "MutationEvents"; }
00374 protected:
00375     NodeImpl *m_relatedNode;
00376     DOMStringImpl *m_prevValue;
00377     DOMStringImpl *m_newValue;
00378     DOMStringImpl *m_attrName;
00379     unsigned short m_attrChange;
00380 };
00381 
00382 
00383 class RegisteredEventListener {
00384 public:
00385     RegisteredEventListener(EventImpl::EventId _id, EventListener *_listener, bool _useCapture)
00386         : id(_id), listener(_listener), useCapture(_useCapture) { listener->ref(); }
00387 
00388     ~RegisteredEventListener() { listener->deref(); }
00389 
00390     bool operator==(const RegisteredEventListener &other)
00391     { return id == other.id && listener == other.listener && useCapture == other.useCapture; }
00392 
00393 
00394     EventImpl::EventId id;
00395     EventListener *listener;
00396     bool useCapture;
00397 private:
00398     RegisteredEventListener( const RegisteredEventListener & );
00399     RegisteredEventListener & operator=( const RegisteredEventListener & );
00400 };
00401 
00402 } //namespace
00403 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:16:32 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001