1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
5  *           (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
6  *           (C) 2002 Apple Computer, Inc.
7  *           (C) 2010 Maksim Orlovich (maksim@kde.org)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #ifndef _DOM_EventsImpl_h_
27 #define _DOM_EventsImpl_h_
28 
29 #include "dom/dom2_events.h"
30 #include "xml/dom2_viewsimpl.h"
31 #include "misc/idstring.h"
32 #include "misc/enum.h"
33 #include <QDateTime>
34 #include <QWeakPointer>
35 
36 #undef FOCUS_EVENT //for win32
37 
38 class QMouseEvent;
39 class QKeyEvent;
40 class KHTMLPart;
41 
42 namespace DOM
43 {
44 
45 class AbstractViewImpl;
46 class DOMStringImpl;
47 class NodeImpl;
48 class DocumentImpl;
49 
50 class RegisteredEventListener
51 {
52 public:
RegisteredEventListener()53     RegisteredEventListener() : useCapture(false), listener(nullptr) {}
54 
RegisteredEventListener(EventName _id,EventListener * _listener,bool _useCapture)55     RegisteredEventListener(EventName _id, EventListener *_listener, bool _useCapture)
56         : eventName(_id), useCapture(_useCapture), listener(_listener)
57     {
58         if (listener) {
59             listener->ref();
60         }
61     }
62 
~RegisteredEventListener()63     ~RegisteredEventListener()
64     {
65         if (listener) {
66             listener->deref();
67         } listener = nullptr;
68     }
69 
70     bool operator==(const RegisteredEventListener &other) const
71     {
72         return eventName == other.eventName && listener == other.listener
73                && useCapture == other.useCapture;
74     }
75 
76     EventName eventName;
77     bool useCapture;
78     EventListener *listener;
79 
RegisteredEventListener(const RegisteredEventListener & other)80     RegisteredEventListener(const RegisteredEventListener &other) :
81         eventName(other.eventName), useCapture(other.useCapture), listener(other.listener)
82     {
83         if (listener) {
84             listener->ref();
85         }
86     }
87 
88     RegisteredEventListener &operator=(const RegisteredEventListener &other)
89     {
90         eventName  = other.eventName;
91         useCapture = other.useCapture;
92         if (other.listener) {
93             other.listener->ref();
94         }
95         if (listener) {
96             listener->deref();
97         }
98         listener = other.listener;
99         return *this;
100     }
101 };
102 
103 struct RegisteredListenerList {
RegisteredListenerListRegisteredListenerList104     RegisteredListenerList() : listeners(nullptr)
105     {}
106 
107     ~RegisteredListenerList();
108 
109     void addEventListener(EventName id, EventListener *listener, const bool useCapture);
110     void removeEventListener(EventName id, EventListener *listener, bool useCapture);
111 
112     void setHTMLEventListener(EventName id, EventListener *listener);
113     EventListener *getHTMLEventListener(EventName id);
114 
115     bool hasEventListener(EventName id);
116     void clear();
117 
118     // TODO: remove/deprecate?
119     bool stillContainsListener(const RegisteredEventListener &listener);
120 
121     QList<RegisteredEventListener> *listeners;//The actual listener list - may be 0
122 private:
123     bool isHTMLEventListener(EventListener *listener);
124 };
125 
126 class EventTargetImpl : public khtml::TreeShared<EventTargetImpl>
127 {
128 public:
129     enum Type {
130         DOM_NODE,
131         WINDOW,
132         XML_HTTP_REQUEST
133     };
134 
135     virtual Type eventTargetType() const = 0;
136 
137     /* Override this to provide access to associated document in order to
138      * set appropriate 'has listerner' flags
139      */
140     virtual DocumentImpl *eventTargetDocument();
141 
142     /**
143      * Perform the default action for an event e.g. submitting a form
144      */
145     virtual void defaultEventHandler(EventImpl *evt);
146 
147     /*
148      * This method fires all the registered handlers for this event
149      * (checking the capture flag as well(
150      */
151     void handleLocalEvents(EventImpl *evt, bool useCapture);
152 
153     void addEventListener(EventName id, EventListener *listener, const bool useCapture);
154     void removeEventListener(EventName id, EventListener *listener, bool useCapture);
155     void setHTMLEventListener(EventName id, EventListener *listener);
156     void setHTMLEventListener(unsigned id, EventListener *listener);
157     EventListener *getHTMLEventListener(EventName id);
158     EventListener *getHTMLEventListener(unsigned id);
159 
listenerList()160     RegisteredListenerList &listenerList()
161     {
162         return m_regdListeners;
163     }
164 private:
165     void setDocListenerFlag(unsigned flag);
166     RegisteredListenerList m_regdListeners;
167 };
168 
169 class EventImpl : public khtml::Shared<EventImpl>
170 {
171 public:
172     enum EventId {
173         // UI events
174         DOMFOCUSIN_EVENT,
175         DOMFOCUSOUT_EVENT,
176         DOMACTIVATE_EVENT,
177         // Mouse events
178         CLICK_EVENT,
179         MOUSEDOWN_EVENT,
180         MOUSEUP_EVENT,
181         MOUSEOVER_EVENT,
182         MOUSEMOVE_EVENT,
183         MOUSEOUT_EVENT,
184         // Mutation events
185         DOMSUBTREEMODIFIED_EVENT,
186         DOMNODEINSERTED_EVENT,
187         DOMNODEREMOVED_EVENT,
188         DOMNODEREMOVEDFROMDOCUMENT_EVENT,
189         DOMNODEINSERTEDINTODOCUMENT_EVENT,
190         DOMATTRMODIFIED_EVENT,
191         DOMCHARACTERDATAMODIFIED_EVENT,
192         // HTML events
193         LOAD_EVENT,
194         UNLOAD_EVENT,
195         ABORT_EVENT,
196         ERROR_EVENT,
197         SELECT_EVENT,
198         CHANGE_EVENT,
199         SUBMIT_EVENT,
200         RESET_EVENT,
201         FOCUS_EVENT,
202         BLUR_EVENT,
203         RESIZE_EVENT,
204         SCROLL_EVENT,
205         HASHCHANGE_EVENT,
206         // keyboard events
207         KEYDOWN_EVENT,
208         KEYUP_EVENT,
209         KEYPRESS_EVENT, //Mostly corresponds to DOM3 textInput event.
210         // khtml events (not part of DOM)
211         KHTML_ECMA_DBLCLICK_EVENT, // for html ondblclick
212         KHTML_ECMA_CLICK_EVENT, // for html onclick
213         KHTML_DRAGDROP_EVENT,
214         KHTML_MOVE_EVENT,
215         KHTML_MOUSEWHEEL_EVENT,
216         KHTML_CONTENTLOADED_EVENT,
217         // XMLHttpRequest events
218         KHTML_READYSTATECHANGE_EVENT,
219         // HTML5 events
220         MESSAGE_EVENT
221     };
222 
223     EventImpl();
224     EventImpl(EventId id, bool canBubbleArg, bool cancelableArg);
225     virtual ~EventImpl();
226 
id()227     EventId id() const
228     {
229         return EventId(m_eventName.id());
230     }
type()231     DOMString type() const
232     {
233         return m_eventName.toString();
234     }
name()235     EventName name() const
236     {
237         return m_eventName;
238     }
239 
target()240     EventTargetImpl *target() const
241     {
242         return m_target;
243     }
244     void setTarget(EventTargetImpl *_target);
currentTarget()245     EventTargetImpl *currentTarget() const
246     {
247         return m_currentTarget;
248     }
setCurrentTarget(EventTargetImpl * _currentTarget)249     void setCurrentTarget(EventTargetImpl *_currentTarget)
250     {
251         m_currentTarget = _currentTarget;
252     }
eventPhase()253     unsigned short eventPhase() const
254     {
255         return m_eventPhase;
256     }
setEventPhase(unsigned short _eventPhase)257     void setEventPhase(unsigned short _eventPhase)
258     {
259         m_eventPhase = _eventPhase;
260     }
bubbles()261     bool bubbles() const
262     {
263         return m_canBubble;
264     }
cancelable()265     bool cancelable() const
266     {
267         return m_cancelable;
268     }
269     DOMTimeStamp timeStamp();
stopPropagation(bool stop)270     void stopPropagation(bool stop)
271     {
272         m_propagationStopped = stop;
273     }
preventDefault(bool prevent)274     void preventDefault(bool prevent)
275     {
276         if (m_cancelable) {
277             m_defaultPrevented = prevent;
278         }
279     }
280 
281     void initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
282 
283     virtual bool isUIEvent() const;
284     virtual bool isMouseEvent() const;
285     virtual bool isMutationEvent() const;
286     virtual bool isTextInputEvent() const;
287     virtual bool isKeyboardEvent() const;
288     virtual bool isMessageEvent() const;
289     virtual bool isHashChangeEvent() const;
isKeyRelatedEvent()290     bool isKeyRelatedEvent() const
291     {
292         return isTextInputEvent() || isKeyboardEvent();
293     }
294 
propagationStopped()295     bool propagationStopped() const
296     {
297         return m_propagationStopped;
298     }
defaultPrevented()299     bool defaultPrevented() const
300     {
301         return m_defaultPrevented;
302     }
303 
setDefaultHandled()304     void setDefaultHandled()
305     {
306         m_defaultHandled = true;
307     }
defaultHandled()308     bool defaultHandled() const
309     {
310         return m_defaultHandled;
311     }
312 
message()313     DOMString message() const
314     {
315         return m_message;
316     }
setMessage(const DOMString & _message)317     void setMessage(const DOMString &_message)
318     {
319         m_message = _message;
320     }
321 
idTable()322     static khtml::IDTable<EventImpl> *idTable()
323     {
324         if (s_idTable) {
325             return s_idTable;
326         } else {
327             return initIdTable();
328         }
329     }
330 protected:
331     static khtml::IDTable<EventImpl> *s_idTable;
332     static khtml::IDTable<EventImpl> *initIdTable();
333     EventName m_eventName;
334     bool m_canBubble  : 1;
335     bool m_cancelable : 1;
336 
337     bool m_propagationStopped : 1;
338     bool m_defaultPrevented   : 1;
339     bool m_defaultHandled     : 1;
340     unsigned short m_eventPhase : 2;
341     EventTargetImpl *m_currentTarget; // ref > 0 maintained externally
342     EventTargetImpl *m_target;
343     QDateTime m_createTime;
344     DOMString m_message;
345 };
346 
347 class UIEventImpl : public EventImpl
348 {
349 public:
UIEventImpl()350     UIEventImpl() : m_view(nullptr), m_detail(0) {}
351     UIEventImpl(EventId _id,
352                 bool canBubbleArg,
353                 bool cancelableArg,
354                 AbstractViewImpl *viewArg,
355                 long detailArg);
356     virtual ~UIEventImpl();
view()357     AbstractViewImpl *view() const
358     {
359         return m_view;
360     }
detail()361     long detail() const
362     {
363         return m_detail;
364     }
365     void initUIEvent(const DOMString &typeArg,
366                      bool canBubbleArg,
367                      bool cancelableArg,
368                      AbstractViewImpl *viewArg,
369                      long detailArg);
370     bool isUIEvent() const override;
371 
372     //Compat stuff
keyCode()373     virtual int keyCode() const
374     {
375         return 0;
376     }
charCode()377     virtual int charCode() const
378     {
379         return 0;
380     }
381 
pageX()382     virtual long pageX() const
383     {
384         return 0;
385     }
pageY()386     virtual long pageY() const
387     {
388         return 0;
389     }
layerX()390     virtual long layerX() const
391     {
392         return 0;
393     }
layerY()394     virtual long layerY() const
395     {
396         return 0;
397     }
which()398     virtual int which() const
399     {
400         return 0;
401     }
402 protected:
403     AbstractViewImpl *m_view;
404     long m_detail;
405 
406 };
407 
408 // Introduced in DOM Level 2: - internal
409 class MouseEventImpl : public UIEventImpl
410 {
411 public:
412     enum Orientation {
413         ONone = 0,
414         OHorizontal,
415         OVertical
416     };
417 
418     MouseEventImpl();
419     MouseEventImpl(EventId _id,
420                    bool canBubbleArg,
421                    bool cancelableArg,
422                    AbstractViewImpl *viewArg,
423                    long detailArg,
424                    long screenXArg,
425                    long screenYArg,
426                    long clientXArg,
427                    long clientYArg,
428                    long pageXArg,
429                    long pageYArg,
430                    bool ctrlKeyArg,
431                    bool altKeyArg,
432                    bool shiftKeyArg,
433                    bool metaKeyArg,
434                    unsigned short buttonArg,
435                    NodeImpl *relatedTargetArg,
436                    QMouseEvent *qe = nullptr,
437                    bool isDoubleClick = false,
438                    Orientation orient = ONone);
439     virtual ~MouseEventImpl();
screenX()440     long screenX() const
441     {
442         return m_screenX;
443     }
screenY()444     long screenY() const
445     {
446         return m_screenY;
447     }
clientX()448     long clientX() const
449     {
450         return m_clientX;
451     }
clientY()452     long clientY() const
453     {
454         return m_clientY;
455     }
layerX()456     long layerX() const override
457     {
458         return m_layerX;    // non-DOM extension
459     }
layerY()460     long layerY() const override
461     {
462         return m_layerY;    // non-DOM extension
463     }
pageX()464     long pageX() const override
465     {
466         return m_pageX;    // non-DOM extension
467     }
pageY()468     long pageY() const override
469     {
470         return m_pageY;    // non-DOM extension
471     }
which()472     int which() const override
473     {
474         return button() + 1;    // non-DOM extension
475     }
isDoubleClick()476     bool isDoubleClick() const
477     {
478         return m_isDoubleClick;    // non-DOM extension
479     }
orientation()480     Orientation orientation() const
481     {
482         return KDE_CAST_BF_ENUM(Orientation, m_orientation);    // non-DOM extension
483     }
ctrlKey()484     bool ctrlKey() const
485     {
486         return m_ctrlKey;
487     }
shiftKey()488     bool shiftKey() const
489     {
490         return m_shiftKey;
491     }
altKey()492     bool altKey() const
493     {
494         return m_altKey;
495     }
metaKey()496     bool metaKey() const
497     {
498         return m_metaKey;
499     }
button()500     unsigned short button() const
501     {
502         return m_button;
503     }
relatedTarget()504     NodeImpl *relatedTarget() const
505     {
506         return m_relatedTarget;
507     }
508 
509     void computeLayerPos();
510 
511     void initMouseEvent(const DOMString &typeArg,
512                         bool canBubbleArg,
513                         bool cancelableArg,
514                         AbstractViewImpl *viewArg,
515                         long detailArg,
516                         long screenXArg,
517                         long screenYArg,
518                         long clientXArg,
519                         long clientYArg,
520                         bool ctrlKeyArg,
521                         bool altKeyArg,
522                         bool shiftKeyArg,
523                         bool metaKeyArg,
524                         unsigned short buttonArg,
525                         const Node &relatedTargetArg,
526                         Orientation orient = ONone);
527     bool isMouseEvent() const override;
528 
qEvent()529     QMouseEvent *qEvent() const
530     {
531         return m_qevent;
532     }
533 protected:
534     long m_screenX;
535     long m_screenY;
536     long m_clientX;
537     long m_clientY;
538     long m_layerX;
539     long m_layerY;
540     long m_pageX;
541     long m_pageY;
542     bool m_ctrlKey : 1;
543     bool m_altKey  : 1;
544     bool m_shiftKey : 1;
545     bool m_metaKey : 1;
546     bool m_isDoubleClick : 1;
547     KDE_BF_ENUM(Orientation) m_orientation : 2;
548     unsigned short m_button;
549     NodeImpl *m_relatedTarget;
550     QMouseEvent *m_qevent;
551 };
552 
553 class KeyEventBaseImpl : public UIEventImpl
554 {
555 public:
556     // VirtualKeyCode
557     enum KeyCodes  {
558         DOM_VK_UNDEFINED           = 0x0,
559         DOM_VK_RIGHT_ALT           = 0x12,
560         DOM_VK_LEFT_ALT            = 0x12,
561         DOM_VK_LEFT_CONTROL        = 0x11,
562         DOM_VK_RIGHT_CONTROL       = 0x11,
563         DOM_VK_LEFT_SHIFT          = 0x10,
564         DOM_VK_RIGHT_SHIFT         = 0x10,
565         DOM_VK_META            = 0x9D,
566         DOM_VK_BACK_SPACE          = 0x08,
567         DOM_VK_CAPS_LOCK           = 0x14,
568         DOM_VK_INSERT          = 0x2D,
569         DOM_VK_DELETE          = 0x7F,
570         DOM_VK_END             = 0x23,
571         DOM_VK_ENTER           = 0x0D,
572         DOM_VK_ESCAPE          = 0x1B,
573         DOM_VK_HOME            = 0x24,
574         DOM_VK_NUM_LOCK            = 0x90,
575         DOM_VK_PAUSE           = 0x13,
576         DOM_VK_PRINTSCREEN         = 0x9A,
577         DOM_VK_SCROLL_LOCK         = 0x91,
578         DOM_VK_SPACE           = 0x20,
579         DOM_VK_TAB             = 0x09,
580         DOM_VK_LEFT            = 0x25,
581         DOM_VK_RIGHT           = 0x27,
582         DOM_VK_UP              = 0x26,
583         DOM_VK_DOWN            = 0x28,
584         DOM_VK_PAGE_DOWN           = 0x22,
585         DOM_VK_PAGE_UP             = 0x21,
586         DOM_VK_F1              = 0x70,
587         DOM_VK_F2              = 0x71,
588         DOM_VK_F3              = 0x72,
589         DOM_VK_F4              = 0x73,
590         DOM_VK_F5              = 0x74,
591         DOM_VK_F6              = 0x75,
592         DOM_VK_F7              = 0x76,
593         DOM_VK_F8              = 0x77,
594         DOM_VK_F9              = 0x78,
595         DOM_VK_F10             = 0x79,
596         DOM_VK_F11             = 0x7A,
597         DOM_VK_F12             = 0x7B,
598         DOM_VK_F13             = 0xF000,
599         DOM_VK_F14             = 0xF001,
600         DOM_VK_F15             = 0xF002,
601         DOM_VK_F16             = 0xF003,
602         DOM_VK_F17             = 0xF004,
603         DOM_VK_F18             = 0xF005,
604         DOM_VK_F19             = 0xF006,
605         DOM_VK_F20             = 0xF007,
606         DOM_VK_F21             = 0xF008,
607         DOM_VK_F22             = 0xF009,
608         DOM_VK_F23             = 0xF00A,
609         DOM_VK_F24             = 0xF00B
610     };
611 
612     void initKeyBaseEvent(const DOMString &typeArg,
613                           bool canBubbleArg,
614                           bool cancelableArg,
615                           AbstractViewImpl *viewArg,
616                           unsigned long keyVal,
617                           unsigned long virtKeyVal,
618                           unsigned long modifiers);
619 
ctrlKey()620     bool ctrlKey()  const
621     {
622         return m_modifier & Qt::ControlModifier;
623     }
shiftKey()624     bool shiftKey() const
625     {
626         return m_modifier & Qt::ShiftModifier;
627     }
altKey()628     bool altKey()   const
629     {
630         return m_modifier & Qt::AltModifier;
631     }
metaKey()632     bool metaKey()  const
633     {
634         return m_modifier & Qt::MetaModifier;
635     }
636 
inputGenerated()637     bool             inputGenerated() const
638     {
639         return m_virtKeyVal == 0;
640     }
keyVal()641     unsigned long    keyVal() const
642     {
643         return m_keyVal;
644     }
virtKeyVal()645     unsigned long    virtKeyVal() const
646     {
647         return m_virtKeyVal;
648     }
649 
qKeyEvent()650     QKeyEvent *qKeyEvent() const
651     {
652         if (!m_keyEvent) {
653             buildQKeyEvent();
654         } return m_keyEvent;
655     }
656 
657     ~KeyEventBaseImpl();
658 
659     bool checkModifier(unsigned long modifierArg);
660 
which()661     int which() const override
662     {
663         return keyCode();    // non-DOM extension
664     }
665 
666     //Returns true if the event was synthesized by client use of DOM
isSynthetic()667     bool isSynthetic() const
668     {
669         return m_synthetic;
670     }
671 protected:
KeyEventBaseImpl()672     KeyEventBaseImpl(): m_keyEvent(nullptr), m_keyVal(0), m_virtKeyVal(0), m_modifier(0), m_synthetic(false)
673     {
674         m_detail = 0;
675     }
676 
677     KeyEventBaseImpl(EventId id,
678                      bool canBubbleArg,
679                      bool cancelableArg,
680                      AbstractViewImpl *viewArg,
681                      QKeyEvent *key);
682 
683     mutable QKeyEvent *m_keyEvent;
684     unsigned long m_keyVal;     //Unicode key value
685     unsigned long m_virtKeyVal; //Virtual key value for keys like arrows, Fn, etc.
686 
687     // bitfield containing state of modifiers. not part of the dom.
688     unsigned long    m_modifier;
689 
690     bool             m_synthetic;
691 
692     void buildQKeyEvent() const; //Construct a Qt key event from m_keyVal/m_virtKeyVal
693 };
694 
695 class TextEventImpl : public KeyEventBaseImpl
696 {
697 public:
698     TextEventImpl();
699 
700     TextEventImpl(QKeyEvent *key, DOM::AbstractViewImpl *view);
701 
702     void initTextEvent(const DOMString &typeArg,
703                        bool canBubbleArg,
704                        bool cancelableArg,
705                        AbstractViewImpl *viewArg,
706                        const DOMString &text);
707 
708     bool isTextInputEvent() const override;
709 
710     //Legacy key stuff...
711     int keyCode() const override;
712     int charCode() const override;
713 
data()714     DOMString data() const
715     {
716         return m_outputString;
717     }
718 private:
719     DOMString m_outputString;
720 };
721 
722 class KeyboardEventImpl : public KeyEventBaseImpl
723 {
724 public:
725     KeyboardEventImpl();
726     KeyboardEventImpl(QKeyEvent *key, DOM::AbstractViewImpl *view);
727 
728     bool isKeyboardEvent() const override;
729 
730     //Legacy key stuff...
731     int keyCode() const override;
732     int charCode() const override;
733 
734     DOMString     keyIdentifier() const;
keyLocation()735     unsigned long keyLocation() const
736     {
737         return m_keyLocation;
738     }
739 
740     bool getModifierState(const DOMString &keyIdentifierArg) const;
741 
742     void initKeyboardEvent(const DOMString &typeArg,
743                            bool canBubbleArg,
744                            bool cancelableArg,
745                            AbstractViewImpl *viewArg,
746                            const DOMString &keyIdentifierArg,
747                            unsigned long keyLocationArg,
748                            const DOMString &modifiersList);
749 
750 private:
751     unsigned long m_keyLocation;
752 };
753 
754 class MutationEventImpl : public EventImpl
755 {
756 // ### fire these during parsing (if necessary)
757 public:
758     MutationEventImpl();
759     MutationEventImpl(EventId _id, /* for convenience */
760                       bool canBubbleArg,
761                       bool cancelableArg,
762                       const Node &relatedNodeArg,
763                       const DOMString &prevValueArg,
764                       const DOMString &newValueArg,
765                       const DOMString &attrNameArg,
766                       unsigned short attrChangeArg);
767     ~MutationEventImpl();
768 
relatedNode()769     Node relatedNode() const
770     {
771         return m_relatedNode;
772     }
prevValue()773     DOMString prevValue() const
774     {
775         return m_prevValue;
776     }
newValue()777     DOMString newValue() const
778     {
779         return m_newValue;
780     }
attrName()781     DOMString attrName() const
782     {
783         return m_attrName;
784     }
attrChange()785     unsigned short attrChange() const
786     {
787         return m_attrChange;
788     }
789     void initMutationEvent(const DOMString &typeArg,
790                            bool canBubbleArg,
791                            bool cancelableArg,
792                            const Node &relatedNodeArg,
793                            const DOMString &prevValueArg,
794                            const DOMString &newValueArg,
795                            const DOMString &attrNameArg,
796                            unsigned short attrChangeArg);
797     bool isMutationEvent() const override;
798 protected:
799     NodeImpl *m_relatedNode;
800     DOMStringImpl *m_prevValue;
801     DOMStringImpl *m_newValue;
802     DOMStringImpl *m_attrName;
803     unsigned short m_attrChange;
804 };
805 
806 class MessageEventImpl : public EventImpl
807 {
808 public:
809     enum DataType {
810         JS_VALUE
811     };
812 
813     class Data : public khtml::Shared<Data>
814     {
815     public:
816         virtual DataType messageDataType() const = 0;
~Data()817         virtual ~Data() {}
818     };
819 
data()820     RefPtr<Data> data() const
821     {
822         return m_data;
823     }
origin()824     DOMString  origin() const
825     {
826         return m_origin;
827     }
source()828     KHTMLPart *source() const
829     {
830         return m_source.toStrongRef().data();
831     }
lastEventId()832     DOMString  lastEventId() const
833     {
834         return m_lastEventId;
835     }
836 
837     MessageEventImpl();
838 
839     void initMessageEvent(const DOMString &eventTypeArg,
840                           bool  canBubbleArg,
841                           bool  cancelableArg,
842                           const RefPtr<Data> &dataArg,
843                           const DOMString &originArg,
844                           const DOMString &lastEventIdArg,
845                           KHTMLPart *sourceArg); // no message ports yet.
846     bool isMessageEvent() const override;
847 private:
848     RefPtr<Data> m_data;
849     DOMString    m_origin;
850     DOMString    m_lastEventId;
851     QWeakPointer<KHTMLPart>  m_source;
852 };
853 
854 class HashChangeEventImpl : public EventImpl
855 {
856 public:
oldUrl()857     const DOMString &oldUrl() const
858     {
859         return m_oldUrl;
860     }
newUrl()861     const DOMString &newUrl() const
862     {
863         return m_newUrl;
864     }
865 
866     HashChangeEventImpl();
867 
868     void initHashChangeEvent(const DOMString &eventTypeArg,
869                              bool  canBubbleArg,
870                              bool  cancelableArg,
871                              const DOMString &oldUrl,
872                              const DOMString &newUrl
873                             );
874     bool isHashChangeEvent() const override;
875 private:
876     DOMString    m_oldUrl;
877     DOMString    m_newUrl;
878 };
879 
880 } //namespace
881 #endif
882