OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) | 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/events/MouseEvent.h" | 24 #include "core/events/MouseEvent.h" |
25 | 25 |
26 #include "bindings/core/v8/DOMWrapperWorld.h" | 26 #include "bindings/core/v8/DOMWrapperWorld.h" |
27 #include "bindings/core/v8/ScriptState.h" | 27 #include "bindings/core/v8/ScriptState.h" |
28 #include "core/clipboard/DataTransfer.h" | |
29 #include "core/dom/Element.h" | 28 #include "core/dom/Element.h" |
30 #include "core/events/EventDispatcher.h" | 29 #include "core/events/EventDispatcher.h" |
31 #include "platform/PlatformMouseEvent.h" | 30 #include "platform/PlatformMouseEvent.h" |
32 | 31 |
33 namespace blink { | 32 namespace blink { |
34 | 33 |
35 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(ScriptState* scriptState,
const AtomicString& type, const MouseEventInit& initializer) | 34 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(ScriptState* scriptState,
const AtomicString& type, const MouseEventInit& initializer) |
36 { | 35 { |
37 if (scriptState && scriptState->world().isIsolatedWorld()) | 36 if (scriptState && scriptState->world().isIsolatedWorld()) |
38 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); | 37 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); |
39 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); | 38 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); |
40 } | 39 } |
41 | 40 |
42 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event,
int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) | 41 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event,
int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) |
43 { | 42 { |
44 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt
on); | 43 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt
on); |
45 | 44 |
46 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; | 45 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; |
47 bool isCancelable = !isMouseEnterOrLeave; | 46 bool isCancelable = !isMouseEnterOrLeave; |
48 bool isBubbling = !isMouseEnterOrLeave; | 47 bool isBubbling = !isMouseEnterOrLeave; |
49 | 48 |
50 return MouseEvent::create( | 49 return MouseEvent::create( |
51 eventType, isBubbling, isCancelable, view, | 50 eventType, isBubbling, isCancelable, view, |
52 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), | 51 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), |
53 event.movementDelta().x(), event.movementDelta().y(), | 52 event.movementDelta().x(), event.movementDelta().y(), |
54 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even
t.button(), | 53 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even
t.button(), |
55 platformModifiersToButtons(event.modifiers()), | 54 platformModifiersToButtons(event.modifiers()), |
56 relatedTarget, nullptr, false, event.syntheticEventType(), event.timesta
mp()); | 55 relatedTarget, false, event.syntheticEventType(), event.timestamp()); |
57 } | 56 } |
58 | 57 |
59 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, | 58 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, |
60 int detail, int screenX, int screenY, int windowX, int windowY, | 59 int detail, int screenX, int screenY, int windowX, int windowY, |
61 int movementX, int movementY, | 60 int movementX, int movementY, |
62 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, | 61 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
63 short button, unsigned short buttons, | 62 short button, unsigned short buttons, |
64 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, DataTransfer* dataTransfe
r, bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType, | 63 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, bool isSimulated, Platfor
mMouseEvent::SyntheticEventType syntheticEventType, |
65 double uiCreateTime) | 64 double uiCreateTime) |
66 { | 65 { |
67 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, | 66 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, |
68 detail, screenX, screenY, windowX, windowY, | 67 detail, screenX, screenY, windowX, windowY, |
69 movementX, movementY, | 68 movementX, movementY, |
70 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data
Transfer, isSimulated, syntheticEventType, uiCreateTime)); | 69 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, isSi
mulated, syntheticEventType, uiCreateTime)); |
71 } | 70 } |
72 | 71 |
73 MouseEvent::MouseEvent() | 72 MouseEvent::MouseEvent() |
74 : m_button(0) | 73 : m_button(0) |
75 , m_buttons(0) | 74 , m_buttons(0) |
76 , m_relatedTarget(nullptr) | 75 , m_relatedTarget(nullptr) |
77 , m_dataTransfer(nullptr) | |
78 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) | 76 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) |
79 { | 77 { |
80 } | 78 } |
81 | 79 |
82 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, | 80 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, |
83 int detail, int screenX, int screenY, int windowX, int windowY, | 81 int detail, int screenX, int screenY, int windowX, int windowY, |
84 int movementX, int movementY, | 82 int movementX, int movementY, |
85 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, | 83 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
86 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re
latedTarget, | 84 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re
latedTarget, |
87 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE
ventType syntheticEventType, | 85 bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType, |
88 double uiCreateTime) | 86 double uiCreateTime) |
89 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), | 87 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), |
90 IntPoint(windowX, windowY), | 88 IntPoint(windowX, windowY), |
91 IntPoint(movementX, movementY), | 89 IntPoint(movementX, movementY), |
92 ctrlKey, altKey, shiftKey, metaKey, isSimulated, | 90 ctrlKey, altKey, shiftKey, metaKey, isSimulated, |
93 syntheticEventType == PlatformMouseEvent::FromTouch ? InputDevice::fires
TouchEventsInputDevice() : InputDevice::doesntFireTouchEventsInputDevice()) | 91 syntheticEventType == PlatformMouseEvent::FromTouch ? InputDevice::fires
TouchEventsInputDevice() : InputDevice::doesntFireTouchEventsInputDevice()) |
94 , m_button(button) | 92 , m_button(button) |
95 , m_buttons(buttons) | 93 , m_buttons(buttons) |
96 , m_relatedTarget(relatedTarget) | 94 , m_relatedTarget(relatedTarget) |
97 , m_dataTransfer(dataTransfer) | |
98 , m_syntheticEventType(syntheticEventType) | 95 , m_syntheticEventType(syntheticEventType) |
99 { | 96 { |
100 setUICreateTime(uiCreateTime); | 97 setUICreateTime(uiCreateTime); |
101 } | 98 } |
102 | 99 |
103 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
ializer) | 100 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
ializer) |
104 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable
(), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in
itializer.screenY()), | 101 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable
(), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in
itializer.screenY()), |
105 IntPoint(0 /* pageX */, 0 /* pageY */), | 102 IntPoint(0 /* pageX */, 0 /* pageY */), |
106 IntPoint(initializer.movementX(), initializer.movementY()), | 103 IntPoint(initializer.movementX(), initializer.movementY()), |
107 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini
tializer.metaKey(), false /* isSimulated */, initializer.sourceDevice()) | 104 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini
tializer.metaKey(), false /* isSimulated */, initializer.sourceDevice()) |
108 , m_button(initializer.button()) | 105 , m_button(initializer.button()) |
109 , m_buttons(initializer.buttons()) | 106 , m_buttons(initializer.buttons()) |
110 , m_relatedTarget(initializer.relatedTarget()) | 107 , m_relatedTarget(initializer.relatedTarget()) |
111 , m_dataTransfer(nullptr) | |
112 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) | 108 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) |
113 { | 109 { |
114 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); | 110 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); |
115 } | 111 } |
116 | 112 |
117 MouseEvent::~MouseEvent() | 113 MouseEvent::~MouseEvent() |
118 { | 114 { |
119 } | 115 } |
120 | 116 |
121 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) | 117 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 m_altKey = altKey; | 153 m_altKey = altKey; |
158 m_shiftKey = shiftKey; | 154 m_shiftKey = shiftKey; |
159 m_metaKey = metaKey; | 155 m_metaKey = metaKey; |
160 m_button = button; | 156 m_button = button; |
161 m_buttons = buttons; | 157 m_buttons = buttons; |
162 m_relatedTarget = relatedTarget; | 158 m_relatedTarget = relatedTarget; |
163 | 159 |
164 initCoordinates(IntPoint(clientX, clientY)); | 160 initCoordinates(IntPoint(clientX, clientY)); |
165 | 161 |
166 // FIXME: m_isSimulated is not set to false here. | 162 // FIXME: m_isSimulated is not set to false here. |
167 // FIXME: m_dataTransfer is not set to nullptr here. | |
168 } | 163 } |
169 | 164 |
170 const AtomicString& MouseEvent::interfaceName() const | 165 const AtomicString& MouseEvent::interfaceName() const |
171 { | 166 { |
172 return EventNames::MouseEvent; | 167 return EventNames::MouseEvent; |
173 } | 168 } |
174 | 169 |
175 bool MouseEvent::isMouseEvent() const | 170 bool MouseEvent::isMouseEvent() const |
176 { | 171 { |
177 return true; | 172 return true; |
178 } | 173 } |
179 | 174 |
180 bool MouseEvent::isDragEvent() const | |
181 { | |
182 const AtomicString& t = type(); | |
183 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t
== EventTypeNames::dragleave || t == EventTypeNames::drop | |
184 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag ||
t == EventTypeNames::dragend; | |
185 } | |
186 | |
187 int MouseEvent::which() const | 175 int MouseEvent::which() const |
188 { | 176 { |
189 // For the DOM, the return values for left, middle and right mouse buttons a
re 0, 1, 2, respectively. | 177 // For the DOM, the return values for left, middle and right mouse buttons a
re 0, 1, 2, respectively. |
190 // For the Netscape "which" property, the return values for left, middle and
right mouse buttons are 1, 2, 3, respectively. | 178 // For the Netscape "which" property, the return values for left, middle and
right mouse buttons are 1, 2, 3, respectively. |
191 // So we must add 1. | 179 // So we must add 1. |
192 return m_button + 1; | 180 return m_button + 1; |
193 } | 181 } |
194 | 182 |
195 Node* MouseEvent::toElement() const | 183 Node* MouseEvent::toElement() const |
196 { | 184 { |
197 // MSIE extension - "the object toward which the user is moving the mouse po
inter" | 185 // MSIE extension - "the object toward which the user is moving the mouse po
inter" |
198 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea
ve) | 186 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea
ve) |
199 return relatedTarget() ? relatedTarget()->toNode() : 0; | 187 return relatedTarget() ? relatedTarget()->toNode() : 0; |
200 | 188 |
201 return target() ? target()->toNode() : 0; | 189 return target() ? target()->toNode() : 0; |
202 } | 190 } |
203 | 191 |
204 Node* MouseEvent::fromElement() const | 192 Node* MouseEvent::fromElement() const |
205 { | 193 { |
206 // MSIE extension - "object from which activation or the mouse pointer is ex
iting during the event" (huh?) | 194 // MSIE extension - "object from which activation or the mouse pointer is ex
iting during the event" (huh?) |
207 if (type() != EventTypeNames::mouseout && type() != EventTypeNames::mouselea
ve) | 195 if (type() != EventTypeNames::mouseout && type() != EventTypeNames::mouselea
ve) |
208 return relatedTarget() ? relatedTarget()->toNode() : 0; | 196 return relatedTarget() ? relatedTarget()->toNode() : 0; |
209 | 197 |
210 return target() ? target()->toNode() : 0; | 198 return target() ? target()->toNode() : 0; |
211 } | 199 } |
212 | 200 |
213 DEFINE_TRACE(MouseEvent) | 201 DEFINE_TRACE(MouseEvent) |
214 { | 202 { |
215 visitor->trace(m_relatedTarget); | 203 visitor->trace(m_relatedTarget); |
216 visitor->trace(m_dataTransfer); | |
217 MouseRelatedEvent::trace(visitor); | 204 MouseRelatedEvent::trace(visitor); |
218 } | 205 } |
219 | 206 |
220 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At
omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill
BeRawPtr<Event> underlyingEvent) | 207 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At
omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill
BeRawPtr<Event> underlyingEvent) |
221 { | 208 { |
222 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin
gEvent)); | 209 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin
gEvent)); |
223 } | 210 } |
224 | 211 |
225 SimulatedMouseEvent::~SimulatedMouseEvent() | 212 SimulatedMouseEvent::~SimulatedMouseEvent() |
226 { | 213 { |
227 } | 214 } |
228 | 215 |
229 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent
) | 216 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent
) |
230 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false,
false, false, 0, 0, | 217 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false,
false, false, 0, 0, |
231 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) | 218 nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) |
232 { | 219 { |
233 setTrusted(true); | 220 setTrusted(true); |
234 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { | 221 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { |
235 m_ctrlKey = keyStateEvent->ctrlKey(); | 222 m_ctrlKey = keyStateEvent->ctrlKey(); |
236 m_altKey = keyStateEvent->altKey(); | 223 m_altKey = keyStateEvent->altKey(); |
237 m_shiftKey = keyStateEvent->shiftKey(); | 224 m_shiftKey = keyStateEvent->shiftKey(); |
238 m_metaKey = keyStateEvent->metaKey(); | 225 m_metaKey = keyStateEvent->metaKey(); |
239 } | 226 } |
240 setUnderlyingEvent(underlyingEvent); | 227 setUnderlyingEvent(underlyingEvent); |
241 | 228 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 doubleClickEvent->setTrusted(event().isTrusted()); | 295 doubleClickEvent->setTrusted(event().isTrusted()); |
309 if (event().defaultHandled()) | 296 if (event().defaultHandled()) |
310 doubleClickEvent->setDefaultHandled(); | 297 doubleClickEvent->setDefaultHandled(); |
311 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); | 298 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); |
312 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) | 299 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) |
313 return false; | 300 return false; |
314 return !swallowEvent; | 301 return !swallowEvent; |
315 } | 302 } |
316 | 303 |
317 } // namespace blink | 304 } // namespace blink |
OLD | NEW |