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 "core/events/MouseEvent.h" | 23 #include "core/events/MouseEvent.h" |
24 | 24 |
25 #include "bindings/core/v8/DOMWrapperWorld.h" | 25 #include "bindings/core/v8/DOMWrapperWorld.h" |
26 #include "bindings/core/v8/ScriptState.h" | 26 #include "bindings/core/v8/ScriptState.h" |
27 #include "core/dom/Element.h" | 27 #include "core/dom/Element.h" |
28 #include "core/events/EventDispatcher.h" | 28 #include "core/events/EventDispatcher.h" |
29 #include "platform/PlatformMouseEvent.h" | 29 #include "platform/PlatformMouseEvent.h" |
30 #include "public/platform/WebPointerProperties.h" | |
31 | 30 |
32 namespace blink { | 31 namespace blink { |
33 | 32 |
34 MouseEvent* MouseEvent::create(ScriptState* scriptState, const AtomicString& typ
e, const MouseEventInit& initializer) | 33 MouseEvent* MouseEvent::create(ScriptState* scriptState, const AtomicString& typ
e, const MouseEventInit& initializer) |
35 { | 34 { |
36 if (scriptState && scriptState->world().isIsolatedWorld()) | 35 if (scriptState && scriptState->world().isIsolatedWorld()) |
37 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); | 36 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey()
, initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); |
38 return new MouseEvent(type, initializer); | 37 return new MouseEvent(type, initializer); |
39 } | 38 } |
40 | 39 |
41 MouseEvent* MouseEvent::create(const AtomicString& eventType, AbstractView* view
, const PlatformMouseEvent& event, int detail, Node* relatedTarget) | 40 MouseEvent* MouseEvent::create(const AtomicString& eventType, AbstractView* view
, const PlatformMouseEvent& event, int detail, Node* relatedTarget) |
42 { | 41 { |
43 DCHECK(event.type() == PlatformEvent::MouseMoved || event.pointerProperties(
).button != WebPointerProperties::Button::NoButton); | 42 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt
on); |
44 | 43 |
45 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; | 44 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; |
46 bool isCancelable = !isMouseEnterOrLeave; | 45 bool isCancelable = !isMouseEnterOrLeave; |
47 bool isBubbling = !isMouseEnterOrLeave; | 46 bool isBubbling = !isMouseEnterOrLeave; |
48 | 47 |
49 return MouseEvent::create( | 48 return MouseEvent::create( |
50 eventType, isBubbling, isCancelable, view, | 49 eventType, isBubbling, isCancelable, view, |
51 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), | 50 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), |
52 event.movementDelta().x(), event.movementDelta().y(), | 51 event.movementDelta().x(), event.movementDelta().y(), |
53 event.getModifiers(), static_cast<short>(event.pointerProperties().butto
n), | 52 event.getModifiers(), event.button(), |
54 platformModifiersToButtons(event.getModifiers()), | 53 platformModifiersToButtons(event.getModifiers()), |
55 relatedTarget, event.timestamp(), event.getSyntheticEventType(), event.r
egion()); | 54 relatedTarget, event.timestamp(), event.getSyntheticEventType(), event.r
egion()); |
56 } | 55 } |
57 | 56 |
58 MouseEvent* MouseEvent::create(const AtomicString& type, bool canBubble, bool ca
ncelable, AbstractView* view, | 57 MouseEvent* MouseEvent::create(const AtomicString& type, bool canBubble, bool ca
ncelable, AbstractView* view, |
59 int detail, int screenX, int screenY, int windowX, int windowY, | 58 int detail, int screenX, int screenY, int windowX, int windowY, |
60 int movementX, int movementY, | 59 int movementX, int movementY, |
61 PlatformEvent::Modifiers modifiers, | 60 PlatformEvent::Modifiers modifiers, |
62 short button, unsigned short buttons, | 61 short button, unsigned short buttons, |
63 EventTarget* relatedTarget, | 62 EventTarget* relatedTarget, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (modifiers & PlatformEvent::LeftButtonDown) | 153 if (modifiers & PlatformEvent::LeftButtonDown) |
155 buttons |= static_cast<unsigned short>(Buttons::Left); | 154 buttons |= static_cast<unsigned short>(Buttons::Left); |
156 if (modifiers & PlatformEvent::RightButtonDown) | 155 if (modifiers & PlatformEvent::RightButtonDown) |
157 buttons |= static_cast<unsigned short>(Buttons::Right); | 156 buttons |= static_cast<unsigned short>(Buttons::Right); |
158 if (modifiers & PlatformEvent::MiddleButtonDown) | 157 if (modifiers & PlatformEvent::MiddleButtonDown) |
159 buttons |= static_cast<unsigned short>(Buttons::Middle); | 158 buttons |= static_cast<unsigned short>(Buttons::Middle); |
160 | 159 |
161 return buttons; | 160 return buttons; |
162 } | 161 } |
163 | 162 |
| 163 unsigned short MouseEvent::buttonToButtons(short button) |
| 164 { |
| 165 switch (button) { |
| 166 case NoButton: |
| 167 return static_cast<unsigned short>(Buttons::None); |
| 168 case LeftButton: |
| 169 return static_cast<unsigned short>(Buttons::Left); |
| 170 case RightButton: |
| 171 return static_cast<unsigned short>(Buttons::Right); |
| 172 case MiddleButton: |
| 173 return static_cast<unsigned short>(Buttons::Middle); |
| 174 } |
| 175 ASSERT_NOT_REACHED(); |
| 176 return 0; |
| 177 } |
| 178 |
164 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty
pe, bool canBubble, bool cancelable, AbstractView* view, | 179 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty
pe, bool canBubble, bool cancelable, AbstractView* view, |
165 int detail, int screenX, int screenY, int client
X, int clientY, | 180 int detail, int screenX, int screenY, int client
X, int clientY, |
166 bool ctrlKey, bool altKey, bool shiftKey, bool m
etaKey, | 181 bool ctrlKey, bool altKey, bool shiftKey, bool m
etaKey, |
167 short button, EventTarget* relatedTarget, unsign
ed short buttons) | 182 short button, EventTarget* relatedTarget, unsign
ed short buttons) |
168 { | 183 { |
169 if (isBeingDispatched()) | 184 if (isBeingDispatched()) |
170 return; | 185 return; |
171 | 186 |
172 if (scriptState && scriptState->world().isIsolatedWorld()) | 187 if (scriptState && scriptState->world().isIsolatedWorld()) |
173 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif
tKey, metaKey); | 188 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif
tKey, metaKey); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 277 |
263 if (!mouseEvent.isTrusted()) | 278 if (!mouseEvent.isTrusted()) |
264 return dispatcher.dispatch(); | 279 return dispatcher.dispatch(); |
265 | 280 |
266 if (isDisabledFormControl(&dispatcher.node())) | 281 if (isDisabledFormControl(&dispatcher.node())) |
267 return DispatchEventResult::CanceledBeforeDispatch; | 282 return DispatchEventResult::CanceledBeforeDispatch; |
268 | 283 |
269 if (mouseEvent.type().isEmpty()) | 284 if (mouseEvent.type().isEmpty()) |
270 return DispatchEventResult::NotCanceled; // Shouldn't happen. | 285 return DispatchEventResult::NotCanceled; // Shouldn't happen. |
271 | 286 |
272 DCHECK(!mouseEvent.target() || mouseEvent.target() != mouseEvent.relatedTarg
et()); | 287 ASSERT(!mouseEvent.target() || mouseEvent.target() != mouseEvent.relatedTarg
et()); |
273 | 288 |
274 EventTarget* relatedTarget = mouseEvent.relatedTarget(); | 289 EventTarget* relatedTarget = mouseEvent.relatedTarget(); |
275 | 290 |
276 DispatchEventResult dispatchResult = dispatcher.dispatch(); | 291 DispatchEventResult dispatchResult = dispatcher.dispatch(); |
277 | 292 |
278 if (mouseEvent.type() != EventTypeNames::click || mouseEvent.detail() != 2) | 293 if (mouseEvent.type() != EventTypeNames::click || mouseEvent.detail() != 2) |
279 return dispatchResult; | 294 return dispatchResult; |
280 | 295 |
281 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part | 296 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part |
282 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated | 297 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated |
283 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. | 298 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. |
284 MouseEvent* doubleClickEvent = MouseEvent::create(); | 299 MouseEvent* doubleClickEvent = MouseEvent::create(); |
285 doubleClickEvent->initMouseEventInternal(EventTypeNames::dblclick, mouseEven
t.bubbles(), mouseEvent.cancelable(), mouseEvent.view(), | 300 doubleClickEvent->initMouseEventInternal(EventTypeNames::dblclick, mouseEven
t.bubbles(), mouseEvent.cancelable(), mouseEvent.view(), |
286 mouseEvent.detail(), mouseEvent.screenX(), mouseEvent.screenY(), mouseEv
ent.clientX(), mouseEvent.clientY(), | 301 mouseEvent.detail(), mouseEvent.screenX(), mouseEvent.screenY(), mouseEv
ent.clientX(), mouseEvent.clientY(), |
287 mouseEvent.modifiers(), mouseEvent.button(), relatedTarget, mouseEvent.s
ourceCapabilities(), mouseEvent.buttons()); | 302 mouseEvent.modifiers(), mouseEvent.button(), relatedTarget, mouseEvent.s
ourceCapabilities(), mouseEvent.buttons()); |
288 | 303 |
289 // Inherit the trusted status from the original event. | 304 // Inherit the trusted status from the original event. |
290 doubleClickEvent->setTrusted(mouseEvent.isTrusted()); | 305 doubleClickEvent->setTrusted(mouseEvent.isTrusted()); |
291 if (mouseEvent.defaultHandled()) | 306 if (mouseEvent.defaultHandled()) |
292 doubleClickEvent->setDefaultHandled(); | 307 doubleClickEvent->setDefaultHandled(); |
293 DispatchEventResult doubleClickDispatchResult = EventDispatcher::dispatchEve
nt(dispatcher.node(), MouseEventDispatchMediator::create(doubleClickEvent)); | 308 DispatchEventResult doubleClickDispatchResult = EventDispatcher::dispatchEve
nt(dispatcher.node(), MouseEventDispatchMediator::create(doubleClickEvent)); |
294 if (doubleClickDispatchResult != DispatchEventResult::NotCanceled) | 309 if (doubleClickDispatchResult != DispatchEventResult::NotCanceled) |
295 return doubleClickDispatchResult; | 310 return doubleClickDispatchResult; |
296 return dispatchResult; | 311 return dispatchResult; |
297 } | 312 } |
298 | 313 |
299 } // namespace blink | 314 } // namespace blink |
OLD | NEW |