2 * This file is part of the DOM implementation for KDE.
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.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef _DOM_EventsImpl_h_
26 #define _DOM_EventsImpl_h_
28 #include "dom/dom2_events.h"
29 #include "xml/dom2_viewsimpl.h"
30 #include "misc/idstring.h"
32 #undef FOCUS_EVENT //for win32
38 class AbstractViewImpl
;
42 class EventImpl
: public khtml::Shared
<EventImpl
>
58 DOMSUBTREEMODIFIED_EVENT
,
59 DOMNODEINSERTED_EVENT
,
61 DOMNODEREMOVEDFROMDOCUMENT_EVENT
,
62 DOMNODEINSERTEDINTODOCUMENT_EVENT
,
63 DOMATTRMODIFIED_EVENT
,
64 DOMCHARACTERDATAMODIFIED_EVENT
,
81 KEYPRESS_EVENT
, //Mostly corresponds to DOM3 textInput event.
82 // khtml events (not part of DOM)
83 KHTML_ECMA_DBLCLICK_EVENT
, // for html ondblclick
84 KHTML_ECMA_CLICK_EVENT
, // for html onclick
87 KHTML_MOUSEWHEEL_EVENT
,
88 KHTML_CONTENTLOADED_EVENT
,
89 // XMLHttpRequest events
90 KHTML_READYSTATECHANGE_EVENT
94 EventImpl(EventId id
, bool canBubbleArg
, bool cancelableArg
);
97 EventId
id() const { return EventId(m_eventName
.id()); }
98 DOMString
type() const { return m_eventName
.toString(); }
99 EventName
name() const { return m_eventName
; }
101 NodeImpl
*target() const { return m_target
; }
102 void setTarget(NodeImpl
*_target
);
103 NodeImpl
*currentTarget() const { return m_currentTarget
; }
104 void setCurrentTarget(NodeImpl
*_currentTarget
) { m_currentTarget
= _currentTarget
; }
105 unsigned short eventPhase() const { return m_eventPhase
; }
106 void setEventPhase(unsigned short _eventPhase
) { m_eventPhase
= _eventPhase
; }
107 bool bubbles() const { return m_canBubble
; }
108 bool cancelable() const { return m_cancelable
; }
109 DOMTimeStamp
timeStamp();
110 void stopPropagation(bool stop
) { m_propagationStopped
= stop
; }
111 void preventDefault(bool prevent
) { if ( m_cancelable
) m_defaultPrevented
= prevent
; }
113 void initEvent(const DOMString
&eventTypeArg
, bool canBubbleArg
, bool cancelableArg
);
115 virtual bool isUIEvent() const;
116 virtual bool isMouseEvent() const;
117 virtual bool isMutationEvent() const;
118 virtual bool isTextInputEvent() const;
119 virtual bool isKeyboardEvent() const;
120 bool isKeyRelatedEvent() const { return isTextInputEvent() || isKeyboardEvent(); }
122 bool propagationStopped() const { return m_propagationStopped
; }
123 bool defaultPrevented() const { return m_defaultPrevented
; }
125 void setDefaultHandled() { m_defaultHandled
= true; }
126 bool defaultHandled() const { return m_defaultHandled
; }
128 DOMString
message() const { return m_message
; }
129 void setMessage(const DOMString
&_message
) { m_message
= _message
; }
131 static khtml::IDTable
<EventImpl
>* idTable() {
135 return initIdTable();
138 static khtml::IDTable
<EventImpl
>* s_idTable
;
139 static khtml::IDTable
<EventImpl
>* initIdTable();
140 EventName m_eventName
;
141 bool m_canBubble
: 1;
142 bool m_cancelable
: 1;
144 bool m_propagationStopped
: 1;
145 bool m_defaultPrevented
: 1;
146 bool m_defaultHandled
: 1;
147 unsigned short m_eventPhase
: 2;
148 NodeImpl
*m_currentTarget
; // ref > 0 maintained externally
150 QDateTime m_createTime
;
156 class UIEventImpl
: public EventImpl
159 UIEventImpl() : m_view(0), m_detail(0) {}
160 UIEventImpl(EventId _id
,
163 AbstractViewImpl
*viewArg
,
165 virtual ~UIEventImpl();
166 AbstractViewImpl
*view() const { return m_view
; }
167 long detail() const { return m_detail
; }
168 void initUIEvent(const DOMString
&typeArg
,
171 AbstractViewImpl
* viewArg
,
173 virtual bool isUIEvent() const;
176 virtual int keyCode() const { return 0; }
177 virtual int charCode() const { return 0; }
179 virtual long pageX() const { return 0; }
180 virtual long pageY() const { return 0; }
181 virtual long layerX() const { return 0; }
182 virtual long layerY() const { return 0; }
183 virtual int which() const { return 0; }
185 AbstractViewImpl
*m_view
;
190 // Introduced in DOM Level 2: - internal
191 class MouseEventImpl
: public UIEventImpl
{
200 MouseEventImpl(EventId _id
,
203 AbstractViewImpl
*viewArg
,
215 unsigned short buttonArg
,
216 NodeImpl
*relatedTargetArg
,
218 bool isDoubleClick
= false,
219 Orientation orient
= ONone
);
220 virtual ~MouseEventImpl();
221 long screenX() const { return m_screenX
; }
222 long screenY() const { return m_screenY
; }
223 long clientX() const { return m_clientX
; }
224 long clientY() const { return m_clientY
; }
225 long layerX() const { return m_layerX
; } // non-DOM extension
226 long layerY() const { return m_layerY
; } // non-DOM extension
227 long pageX() const { return m_pageX
; } // non-DOM extension
228 long pageY() const { return m_pageY
; } // non-DOM extension
229 virtual int which() const { return button() + 1; } // non-DOM extension
230 bool isDoubleClick() const { return m_isDoubleClick
; } // non-DOM extension
231 Orientation
orientation() const { return KDE_CAST_BF_ENUM(Orientation
, m_orientation
); } // non-DOM extension
232 bool ctrlKey() const { return m_ctrlKey
; }
233 bool shiftKey() const { return m_shiftKey
; }
234 bool altKey() const { return m_altKey
; }
235 bool metaKey() const { return m_metaKey
; }
236 unsigned short button() const { return m_button
; }
237 NodeImpl
*relatedTarget() const { return m_relatedTarget
; }
239 void computeLayerPos();
241 void initMouseEvent(const DOMString
&typeArg
,
244 AbstractViewImpl
* viewArg
,
254 unsigned short buttonArg
,
255 const Node
&relatedTargetArg
,
256 Orientation orient
= ONone
);
257 virtual bool isMouseEvent() const;
259 QMouseEvent
*qEvent() const { return m_qevent
; }
273 bool m_isDoubleClick
: 1;
274 KDE_BF_ENUM(Orientation
) m_orientation
: 2;
275 unsigned short m_button
;
276 NodeImpl
*m_relatedTarget
;
277 QMouseEvent
*m_qevent
;
280 class KeyEventBaseImpl
: public UIEventImpl
{
284 DOM_VK_UNDEFINED
= 0x0,
285 DOM_VK_RIGHT_ALT
= 0x12,
286 DOM_VK_LEFT_ALT
= 0x12,
287 DOM_VK_LEFT_CONTROL
= 0x11,
288 DOM_VK_RIGHT_CONTROL
= 0x11,
289 DOM_VK_LEFT_SHIFT
= 0x10,
290 DOM_VK_RIGHT_SHIFT
= 0x10,
292 DOM_VK_BACK_SPACE
= 0x08,
293 DOM_VK_CAPS_LOCK
= 0x14,
294 DOM_VK_DELETE
= 0x7F,
297 DOM_VK_ESCAPE
= 0x1B,
299 DOM_VK_NUM_LOCK
= 0x90,
301 DOM_VK_PRINTSCREEN
= 0x9A,
302 DOM_VK_SCROLL_LOCK
= 0x91,
309 DOM_VK_PAGE_DOWN
= 0x22,
310 DOM_VK_PAGE_UP
= 0x21,
337 void initKeyBaseEvent(const DOMString
&typeArg
,
340 AbstractViewImpl
* viewArg
,
341 unsigned long keyVal
,
342 unsigned long virtKeyVal
,
343 unsigned long modifiers
);
345 bool ctrlKey() const { return m_modifier
& Qt::ControlModifier
; }
346 bool shiftKey() const { return m_modifier
& Qt::ShiftModifier
; }
347 bool altKey() const { return m_modifier
& Qt::AltModifier
; }
348 bool metaKey() const { return m_modifier
& Qt::MetaModifier
; }
350 bool inputGenerated() const { return m_virtKeyVal
== 0; }
351 unsigned long keyVal() const { return m_keyVal
; }
352 unsigned long virtKeyVal() const { return m_virtKeyVal
; }
354 QKeyEvent
*qKeyEvent() const { if (!m_keyEvent
) buildQKeyEvent(); return m_keyEvent
; }
358 bool checkModifier(unsigned long modifierArg
);
360 virtual int which() const { return keyCode(); } // non-DOM extension
362 //Returns true if the event was synthesized by client use of DOM
363 bool isSynthetic() const { return m_synthetic
; }
365 KeyEventBaseImpl(): m_keyEvent(0), m_keyVal(0), m_virtKeyVal(0), m_modifier(0), m_synthetic(false)
368 KeyEventBaseImpl(EventId id
,
371 AbstractViewImpl
*viewArg
,
375 mutable QKeyEvent
*m_keyEvent
;
376 unsigned long m_keyVal
; //Unicode key value
377 unsigned long m_virtKeyVal
; //Virtual key value for keys like arrows, Fn, etc.
379 // bitfield containing state of modifiers. not part of the dom.
380 unsigned long m_modifier
;
384 void buildQKeyEvent() const; //Construct a Qt key event from m_keyVal/m_virtKeyVal
387 class TextEventImpl
: public KeyEventBaseImpl
{
391 TextEventImpl(QKeyEvent
* key
, DOM::AbstractViewImpl
* view
);
393 void initTextEvent(const DOMString
&typeArg
,
396 AbstractViewImpl
* viewArg
,
397 const DOMString
& text
);
399 virtual bool isTextInputEvent() const;
401 //Legacy key stuff...
402 virtual int keyCode() const;
403 virtual int charCode() const;
405 DOMString
data() const { return m_outputString
; }
407 DOMString m_outputString
;
410 class KeyboardEventImpl
: public KeyEventBaseImpl
{
413 KeyboardEventImpl(QKeyEvent
* key
, DOM::AbstractViewImpl
* view
);
415 virtual bool isKeyboardEvent() const;
417 //Legacy key stuff...
419 int charCode() const;
421 DOMString
keyIdentifier() const;
422 unsigned long keyLocation() const { return m_keyLocation
; }
424 bool getModifierState(const DOMString
& keyIdentifierArg
) const;
426 void initKeyboardEvent(const DOMString
&typeArg
,
429 AbstractViewImpl
* viewArg
,
430 const DOMString
&keyIdentifierArg
,
431 unsigned long keyLocationArg
,
432 const DOMString
& modifiersList
);
435 unsigned long m_keyLocation
;
439 class MutationEventImpl
: public EventImpl
{
440 // ### fire these during parsing (if necessary)
443 MutationEventImpl(EventId _id
, /* for convenience */
446 const Node
&relatedNodeArg
,
447 const DOMString
&prevValueArg
,
448 const DOMString
&newValueArg
,
449 const DOMString
&attrNameArg
,
450 unsigned short attrChangeArg
);
451 ~MutationEventImpl();
453 Node
relatedNode() const { return m_relatedNode
; }
454 DOMString
prevValue() const { return m_prevValue
; }
455 DOMString
newValue() const { return m_newValue
; }
456 DOMString
attrName() const { return m_attrName
; }
457 unsigned short attrChange() const { return m_attrChange
; }
458 void initMutationEvent(const DOMString
&typeArg
,
461 const Node
&relatedNodeArg
,
462 const DOMString
&prevValueArg
,
463 const DOMString
&newValueArg
,
464 const DOMString
&attrNameArg
,
465 unsigned short attrChangeArg
);
466 virtual bool isMutationEvent() const;
468 NodeImpl
*m_relatedNode
;
469 DOMStringImpl
*m_prevValue
;
470 DOMStringImpl
*m_newValue
;
471 DOMStringImpl
*m_attrName
;
472 unsigned short m_attrChange
;
476 class RegisteredEventListener
{
478 RegisteredEventListener() : useCapture(false), listener(0) {}
480 RegisteredEventListener(EventName _id
, EventListener
*_listener
, bool _useCapture
)
481 : eventName(_id
), useCapture(_useCapture
), listener(_listener
) { if (listener
) listener
->ref(); }
483 ~RegisteredEventListener() { if (listener
) listener
->deref(); listener
= 0; }
485 bool operator==(const RegisteredEventListener
&other
) const
486 { return eventName
== other
.eventName
&& listener
== other
.listener
487 && useCapture
== other
.useCapture
; }
492 EventListener
*listener
;
494 RegisteredEventListener( const RegisteredEventListener
&other
) :
495 eventName(other
.eventName
), useCapture(other
.useCapture
), listener(other
.listener
)
496 { if (listener
) listener
->ref(); }
498 RegisteredEventListener
& operator=( const RegisteredEventListener
&other
) {
499 eventName
= other
.eventName
;
500 useCapture
= other
.useCapture
;
502 other
.listener
->ref();
505 listener
= other
.listener
;