dom2_events.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
00005  *           (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 License
00018  * along with this library; see the file COPYING.LIB.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  */
00023 
00024 #ifndef _DOM_Events_h_
00025 #define _DOM_Events_h_
00026 
00027 #include <dom/dom_node.h>
00028 #include <dom/dom_misc.h>
00029 
00030 namespace DOM {
00031 
00032 class Event;
00033 class EventException;
00034 class UIEvent;
00035 class MouseEvent;
00036 class TextEvent;
00037 class MutationEvent;
00038 class AbstractView;
00039 
00040 class EventListenerImpl;
00041 class EventImpl;
00042 class UIEventImpl;
00043 class MouseEventImpl;
00044 class TextEventImpl;
00045 class MutationEventImpl;
00046 
00047 
00048 
00064 class KHTML_EXPORT EventListener : public DomShared {
00065 public:
00066     EventListener();
00067     virtual ~EventListener();
00068 
00078     virtual void handleEvent(Event &evt);
00079 
00088     virtual DOMString eventListenerType();
00089 
00090 protected:
00095     EventListenerImpl *impl;
00096 };
00097 
00098 
00111 class KHTML_EXPORT Event {
00112     friend class Document;
00113     friend class NodeImpl;
00114     friend class DocumentImpl;
00115 public:
00116     Event();
00117     Event(const Event &other);
00118     virtual ~Event();
00119 
00120     Event & operator = (const Event &other);
00121 
00133     enum PhaseType {
00134     CAPTURING_PHASE = 1,
00135     AT_TARGET = 2,
00136     BUBBLING_PHASE = 3
00137     };
00138 
00143     DOMString type() const;
00144 
00150     Node target() const;
00151 
00158     Node currentTarget() const;
00159 
00164     unsigned short eventPhase() const;
00165 
00171     bool bubbles() const;
00172 
00179     bool cancelable() const;
00180 
00189     DOMTimeStamp timeStamp() const;
00190 
00199     void stopPropagation();
00200 
00213     void preventDefault();
00214 
00240     void initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
00241 
00246     EventImpl *handle() const;
00247     bool isNull() const;
00248 
00249 protected:
00250     Event(EventImpl *i);
00251     EventImpl *impl;
00252 };
00253 
00254 
00262 class KHTML_EXPORT EventException
00263 {
00264 public:
00265     EventException(unsigned short _code);
00266     EventException(const EventException &other);
00267     EventException & operator = (const EventException &other);
00268     virtual ~EventException() {}
00269 
00279     enum EventExceptionCode {
00280         UNSPECIFIED_EVENT_TYPE_ERR     = 0
00281     };
00282 
00283     unsigned short code;
00284 };
00285 
00286 
00294 class KHTML_EXPORT UIEvent : public Event {
00295 public:
00296     UIEvent();
00297     UIEvent(const UIEvent &other);
00298     UIEvent(const Event &other);
00299     UIEvent & operator = (const UIEvent &other);
00300     UIEvent & operator = (const Event &other);
00301     virtual ~UIEvent();
00302 
00308     AbstractView view() const;
00309 
00315     long detail() const;
00316 
00321     int keyCode() const;
00322 
00327     int charCode() const;
00328 
00333     int pageX() const;
00334     int pageY() const;
00335 
00340     int layerX() const;
00341     int layerY() const;
00342 
00347     int which() const;
00348 
00369     void initUIEvent(const DOMString &typeArg,
00370                                  bool canBubbleArg,
00371                                  bool cancelableArg,
00372                                  const AbstractView &viewArg,
00373                                  long detailArg);
00374 protected:
00375     UIEvent(UIEventImpl *impl);
00376 };
00377 
00378 
00379 
00380 
00399 class KHTML_EXPORT MouseEvent : public UIEvent {
00400 public:
00401     MouseEvent();
00402     MouseEvent(const MouseEvent &other);
00403     MouseEvent(const Event &other);
00404     MouseEvent & operator = (const MouseEvent &other);
00405     MouseEvent & operator = (const Event &other);
00406     virtual ~MouseEvent();
00407 
00413     long screenX() const;
00414 
00420     long screenY() const;
00421 
00427     long clientX() const;
00428 
00434     long clientY() const;
00435 
00440     bool ctrlKey() const;
00441 
00447     bool shiftKey() const;
00448 
00455     bool altKey() const;
00456 
00463     bool metaKey() const;
00464 
00475     unsigned short button() const;
00476 
00484     Node relatedTarget() const;
00485 
00525     void initMouseEvent(const DOMString &typeArg,
00526                                     bool canBubbleArg,
00527                                     bool cancelableArg,
00528                                     const AbstractView &viewArg,
00529                                     long detailArg,
00530                                     long screenXArg,
00531                                     long screenYArg,
00532                                     long clientXArg,
00533                                     long clientYArg,
00534                                     bool ctrlKeyArg,
00535                                     bool altKeyArg,
00536                                     bool shiftKeyArg,
00537                                     bool metaKeyArg,
00538                                     unsigned short buttonArg,
00539                                     const Node &relatedTargetArg);
00540 protected:
00541     MouseEvent(MouseEventImpl *impl);
00542 };
00543 
00544 // Introduced in DOM Level 3:
00551 class KHTML_EXPORT TextEvent : public UIEvent {
00552 public:
00553     TextEvent();
00554     TextEvent(const TextEvent &other);
00555     TextEvent(const Event &other);
00556     TextEvent & operator = (const TextEvent &other);
00557     TextEvent & operator = (const Event &other);
00558     virtual ~TextEvent();
00559 
00597     void initTextEvent(const DOMString &typeArg,
00598                       bool canBubbleArg,
00599                       bool cancelableArg,
00600                       const AbstractView &viewArg,
00601                       long detailArg,
00602                       const DOMString &outputStringArg,
00603                       unsigned long keyValArg,
00604                       unsigned long virtKeyValArg,
00605                       bool inputGeneratedArg,
00606                       bool numPadArg);
00607 
00640     void initModifier(unsigned long modifierArg, bool valueArg);
00641 
00658     bool inputGenerated() const;
00659 
00667     unsigned long keyVal() const;
00668 
00676     bool numPad() const;
00677 
00687     DOMString     outputString() const;
00696     unsigned long virtKeyVal() const;
00697 
00730     bool checkModifier(unsigned long modifierArg); // ### KDE 4: const!
00731 
00732 protected:
00733     TextEvent(TextEventImpl *impl);
00734 };
00735 
00736 
00744 class KHTML_EXPORT MutationEvent : public Event {
00745 public:
00746     MutationEvent();
00747     MutationEvent(const MutationEvent &other);
00748     MutationEvent(const Event &other);
00749     MutationEvent & operator = (const MutationEvent &other);
00750     MutationEvent & operator = (const Event &other);
00751     virtual ~MutationEvent();
00752 
00763     enum attrChangeType {
00764     MODIFICATION = 1,
00765     ADDITION = 2,
00766     REMOVAL = 3
00767     };
00768 
00769 
00780     Node relatedNode() const;
00781 
00788     DOMString prevValue() const;
00789 
00795     DOMString newValue() const;
00796 
00802     DOMString attrName() const;
00803 
00810     unsigned short attrChange() const;
00811 
00837     void initMutationEvent(const DOMString &typeArg,
00838                                        bool canBubbleArg,
00839                                        bool cancelableArg,
00840                                        const Node &relatedNodeArg,
00841                                        const DOMString &prevValueArg,
00842                                        const DOMString &newValueArg,
00843                                        const DOMString &attrNameArg,
00844                                        unsigned short attrChangeArg);
00845 protected:
00846     MutationEvent(MutationEventImpl *impl);
00847 };
00848 
00849 
00850 
00851 } //namespace
00852 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys