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