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. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 movementX, movementY, | 69 movementX, movementY, |
70 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data
Transfer, isSimulated, syntheticEventType, uiCreateTime)); | 70 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data
Transfer, isSimulated, syntheticEventType, uiCreateTime)); |
71 } | 71 } |
72 | 72 |
73 MouseEvent::MouseEvent() | 73 MouseEvent::MouseEvent() |
74 : m_button(0) | 74 : m_button(0) |
75 , m_buttons(0) | 75 , m_buttons(0) |
76 , m_relatedTarget(nullptr) | 76 , m_relatedTarget(nullptr) |
77 , m_dataTransfer(nullptr) | 77 , m_dataTransfer(nullptr) |
78 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) | 78 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) |
| 79 , m_isTrusted(false) |
79 { | 80 { |
80 } | 81 } |
81 | 82 |
82 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, | 83 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, |
83 int detail, int screenX, int screenY, int windowX, int windowY, | 84 int detail, int screenX, int screenY, int windowX, int windowY, |
84 int movementX, int movementY, | 85 int movementX, int movementY, |
85 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, | 86 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
86 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re
latedTarget, | 87 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re
latedTarget, |
87 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE
ventType syntheticEventType, | 88 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE
ventType syntheticEventType, |
88 double uiCreateTime) | 89 double uiCreateTime) |
89 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), | 90 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), |
90 IntPoint(windowX, windowY), | 91 IntPoint(windowX, windowY), |
91 IntPoint(movementX, movementY), | 92 IntPoint(movementX, movementY), |
92 ctrlKey, altKey, shiftKey, metaKey, isSimulated, | 93 ctrlKey, altKey, shiftKey, metaKey, isSimulated, |
93 syntheticEventType == PlatformMouseEvent::FromTouch ? InputDevice::fires
TouchEventsInputDevice() : InputDevice::doesntFireTouchEventsInputDevice()) | 94 syntheticEventType == PlatformMouseEvent::FromTouch ? InputDevice::fires
TouchEventsInputDevice() : InputDevice::doesntFireTouchEventsInputDevice()) |
94 , m_button(button) | 95 , m_button(button) |
95 , m_buttons(buttons) | 96 , m_buttons(buttons) |
96 , m_relatedTarget(relatedTarget) | 97 , m_relatedTarget(relatedTarget) |
97 , m_dataTransfer(dataTransfer) | 98 , m_dataTransfer(dataTransfer) |
98 , m_syntheticEventType(syntheticEventType) | 99 , m_syntheticEventType(syntheticEventType) |
| 100 , m_isTrusted(false) |
99 { | 101 { |
100 setUICreateTime(uiCreateTime); | 102 setUICreateTime(uiCreateTime); |
101 } | 103 } |
102 | 104 |
103 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
ializer) | 105 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()), | 106 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable
(), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in
itializer.screenY()), |
105 IntPoint(0 /* pageX */, 0 /* pageY */), | 107 IntPoint(0 /* pageX */, 0 /* pageY */), |
106 IntPoint(initializer.movementX(), initializer.movementY()), | 108 IntPoint(initializer.movementX(), initializer.movementY()), |
107 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini
tializer.metaKey(), false /* isSimulated */, initializer.sourceDevice()) | 109 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini
tializer.metaKey(), false /* isSimulated */, initializer.sourceDevice()) |
108 , m_button(initializer.button()) | 110 , m_button(initializer.button()) |
109 , m_buttons(initializer.buttons()) | 111 , m_buttons(initializer.buttons()) |
110 , m_relatedTarget(initializer.relatedTarget()) | 112 , m_relatedTarget(initializer.relatedTarget()) |
111 , m_dataTransfer(nullptr) | 113 , m_dataTransfer(nullptr) |
112 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) | 114 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) |
| 115 , m_isTrusted(false) |
113 { | 116 { |
114 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); | 117 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); |
115 } | 118 } |
116 | 119 |
117 MouseEvent::~MouseEvent() | 120 MouseEvent::~MouseEvent() |
118 { | 121 { |
119 } | 122 } |
120 | 123 |
121 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) | 124 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) |
122 { | 125 { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 226 } |
224 | 227 |
225 SimulatedMouseEvent::~SimulatedMouseEvent() | 228 SimulatedMouseEvent::~SimulatedMouseEvent() |
226 { | 229 { |
227 } | 230 } |
228 | 231 |
229 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent
) | 232 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, | 233 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false,
false, false, 0, 0, |
231 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) | 234 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) |
232 { | 235 { |
| 236 setTrusted(true); |
233 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { | 237 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { |
234 m_ctrlKey = keyStateEvent->ctrlKey(); | 238 m_ctrlKey = keyStateEvent->ctrlKey(); |
235 m_altKey = keyStateEvent->altKey(); | 239 m_altKey = keyStateEvent->altKey(); |
236 m_shiftKey = keyStateEvent->shiftKey(); | 240 m_shiftKey = keyStateEvent->shiftKey(); |
237 m_metaKey = keyStateEvent->metaKey(); | 241 m_metaKey = keyStateEvent->metaKey(); |
238 } | 242 } |
239 setUnderlyingEvent(underlyingEvent); | 243 setUnderlyingEvent(underlyingEvent); |
240 | 244 |
241 if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) { | 245 if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) { |
242 MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent()); | 246 MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent()); |
243 m_screenLocation = mouseEvent->screenLocation(); | 247 m_screenLocation = mouseEvent->screenLocation(); |
244 initCoordinates(mouseEvent->clientLocation()); | 248 initCoordinates(mouseEvent->clientLocation()); |
245 } | 249 } |
246 } | 250 } |
247 | 251 |
| 252 PassRefPtrWillBeRawPtr<EventDispatchMediator> MouseEvent::createMediator() |
| 253 { |
| 254 return MouseEventDispatchMediator::create(this); |
| 255 } |
| 256 |
248 DEFINE_TRACE(SimulatedMouseEvent) | 257 DEFINE_TRACE(SimulatedMouseEvent) |
249 { | 258 { |
250 MouseEvent::trace(visitor); | 259 MouseEvent::trace(visitor); |
251 } | 260 } |
252 | 261 |
253 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c
reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent, MouseEventType mouseEventTy
pe) | 262 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c
reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent) |
254 { | 263 { |
255 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent, mouseEv
entType)); | 264 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent)); |
256 } | 265 } |
257 | 266 |
258 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo
useEvent> mouseEvent, MouseEventType mouseEventType) | 267 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo
useEvent> mouseEvent) |
259 : EventDispatchMediator(mouseEvent), m_mouseEventType(mouseEventType) | 268 : EventDispatchMediator(mouseEvent) |
260 { | 269 { |
261 } | 270 } |
262 | 271 |
263 MouseEvent& MouseEventDispatchMediator::event() const | 272 MouseEvent& MouseEventDispatchMediator::event() const |
264 { | 273 { |
265 return toMouseEvent(EventDispatchMediator::event()); | 274 return toMouseEvent(EventDispatchMediator::event()); |
266 } | 275 } |
267 | 276 |
268 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons
t | 277 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons
t |
269 { | 278 { |
270 if (isSyntheticMouseEvent()) { | 279 if (!event().isTrusted()) { |
271 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re
latedTarget()); | 280 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re
latedTarget()); |
272 return dispatcher.dispatch(); | 281 return dispatcher.dispatch(); |
273 } | 282 } |
274 | 283 |
275 if (isDisabledFormControl(&dispatcher.node())) | 284 if (isDisabledFormControl(&dispatcher.node())) |
276 return false; | 285 return false; |
277 | 286 |
278 if (event().type().isEmpty()) | 287 if (event().type().isEmpty()) |
279 return true; // Shouldn't happen. | 288 return true; // Shouldn't happen. |
280 | 289 |
281 ASSERT(!event().target() || event().target() != event().relatedTarget()); | 290 ASSERT(!event().target() || event().target() != event().relatedTarget()); |
282 | 291 |
283 EventTarget* relatedTarget = event().relatedTarget(); | 292 EventTarget* relatedTarget = event().relatedTarget(); |
284 event().eventPath().adjustForRelatedTarget(dispatcher.node(), relatedTarget)
; | 293 event().eventPath().adjustForRelatedTarget(dispatcher.node(), relatedTarget)
; |
285 | 294 |
286 dispatcher.dispatch(); | 295 dispatcher.dispatch(); |
287 bool swallowEvent = event().defaultHandled() || event().defaultPrevented(); | 296 bool swallowEvent = event().defaultHandled() || event().defaultPrevented(); |
288 | 297 |
289 if (event().type() != EventTypeNames::click || event().detail() != 2) | 298 if (event().type() != EventTypeNames::click || event().detail() != 2) |
290 return !swallowEvent; | 299 return !swallowEvent; |
291 | 300 |
292 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part | 301 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part |
293 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated | 302 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated |
294 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. | 303 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. |
295 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); | 304 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); |
296 doubleClickEvent->initMouseEventInternal(nullptr, EventTypeNames::dblclick,
event().bubbles(), event().cancelable(), event().view(), | 305 doubleClickEvent->initMouseEventInternal(nullptr, EventTypeNames::dblclick,
event().bubbles(), event().cancelable(), event().view(), |
297 event().detail(), event().screenX(), event().screenY(), event().clientX(
), event().clientY(), | 306 event().detail(), event().screenX(), event().screenY(), event().clientX(
), event().clientY(), |
298 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey
(), | 307 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey
(), |
299 event().button(), relatedTarget, event().sourceDevice(), event().buttons
()); | 308 event().button(), relatedTarget, event().sourceDevice(), event().buttons
()); |
| 309 |
| 310 // Inherit the trusted status from the original event. |
| 311 doubleClickEvent->setTrusted(event().isTrusted()); |
300 if (event().defaultHandled()) | 312 if (event().defaultHandled()) |
301 doubleClickEvent->setDefaultHandled(); | 313 doubleClickEvent->setDefaultHandled(); |
302 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); | 314 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); |
303 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) | 315 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) |
304 return false; | 316 return false; |
305 return !swallowEvent; | 317 return !swallowEvent; |
306 } | 318 } |
307 | 319 |
308 } // namespace blink | 320 } // namespace blink |
OLD | NEW |