|
1 /** |
|
2 * This file is part of the DOM implementation for KDE. |
|
3 * |
|
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
|
5 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
|
6 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
|
7 * Copyright (C) 2003, 2005, 2006 Apple Computer, Inc. |
|
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 #include "config.h" |
|
26 #include "MouseEvent.h" |
|
27 |
|
28 #include "EventNames.h" |
|
29 |
|
30 namespace WebCore { |
|
31 |
|
32 using namespace EventNames; |
|
33 |
|
34 MouseEvent::MouseEvent() |
|
35 : m_button(0) |
|
36 , m_buttonDown(false) |
|
37 { |
|
38 } |
|
39 |
|
40 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView* view, |
|
41 int detail, int screenX, int screenY, int pageX, int pageY, |
|
42 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
|
43 unsigned short button, EventTargetNode* relatedTarget, |
|
44 Clipboard* clipboard, bool isSimulated) |
|
45 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, screenX, screenY, |
|
46 pageX, pageY, ctrlKey, altKey, shiftKey, metaKey, isSimulated) |
|
47 , m_button(button == (unsigned short)-1 ? 0 : button) |
|
48 , m_buttonDown(button != (unsigned short)-1) |
|
49 , m_relatedTarget(relatedTarget) |
|
50 , m_clipboard(clipboard) |
|
51 { |
|
52 } |
|
53 |
|
54 MouseEvent::~MouseEvent() |
|
55 { |
|
56 } |
|
57 |
|
58 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view, |
|
59 int detail, int screenX, int screenY, int clientX, int clientY, |
|
60 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
|
61 unsigned short button, EventTargetNode* relatedTarget) |
|
62 { |
|
63 if (dispatched()) |
|
64 return; |
|
65 |
|
66 initUIEvent(type, canBubble, cancelable, view, detail); |
|
67 |
|
68 m_screenX = screenX; |
|
69 m_screenY = screenY; |
|
70 m_ctrlKey = ctrlKey; |
|
71 m_altKey = altKey; |
|
72 m_shiftKey = shiftKey; |
|
73 m_metaKey = metaKey; |
|
74 m_button = button == (unsigned short)-1 ? 0 : button; |
|
75 m_buttonDown = button != (unsigned short)-1; |
|
76 m_relatedTarget = relatedTarget; |
|
77 |
|
78 initCoordinates(clientX, clientY); |
|
79 |
|
80 // FIXME: m_isSimulated is not set to false here. |
|
81 // FIXME: m_clipboard is not set to 0 here. |
|
82 } |
|
83 |
|
84 bool MouseEvent::isMouseEvent() const |
|
85 { |
|
86 return true; |
|
87 } |
|
88 |
|
89 bool MouseEvent::isDragEvent() const |
|
90 { |
|
91 const AtomicString& t = type(); |
|
92 return t == dragenterEvent || t == dragoverEvent || t == dragleaveEvent || t == dropEvent |
|
93 || t == dragstartEvent|| t == dragEvent || t == dragendEvent; |
|
94 } |
|
95 |
|
96 int MouseEvent::which() const |
|
97 { |
|
98 // For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively. |
|
99 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively. |
|
100 // So we must add 1. |
|
101 return m_button + 1; |
|
102 } |
|
103 |
|
104 Node* MouseEvent::toElement() const |
|
105 { |
|
106 // MSIE extension - "the object toward which the user is moving the mouse pointer" |
|
107 if (type() == mouseoutEvent) |
|
108 return relatedTarget(); |
|
109 |
|
110 return target() ? target()->toNode() : 0; |
|
111 } |
|
112 |
|
113 Node* MouseEvent::fromElement() const |
|
114 { |
|
115 // MSIE extension - "object from which activation or the mouse pointer is exiting during the event" (huh?) |
|
116 if (type() != mouseoutEvent) |
|
117 return relatedTarget(); |
|
118 |
|
119 return target() ? target()->toNode() : 0; |
|
120 } |
|
121 |
|
122 } // namespace WebCore |