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 22 matching lines...) Expand all Loading... |
33 MouseEventInit::MouseEventInit() | 33 MouseEventInit::MouseEventInit() |
34 : screenX(0) | 34 : screenX(0) |
35 , screenY(0) | 35 , screenY(0) |
36 , clientX(0) | 36 , clientX(0) |
37 , clientY(0) | 37 , clientY(0) |
38 , ctrlKey(false) | 38 , ctrlKey(false) |
39 , altKey(false) | 39 , altKey(false) |
40 , shiftKey(false) | 40 , shiftKey(false) |
41 , metaKey(false) | 41 , metaKey(false) |
42 , button(0) | 42 , button(0) |
| 43 , buttons(0) |
43 , relatedTarget(nullptr) | 44 , relatedTarget(nullptr) |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
const MouseEventInit& initializer) | 48 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
const MouseEventInit& initializer) |
48 { | 49 { |
49 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); | 50 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); |
50 } | 51 } |
51 | 52 |
52 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event,
int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) | 53 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event,
int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) |
53 { | 54 { |
54 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt
on); | 55 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt
on); |
55 | 56 |
56 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; | 57 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT
ype == EventTypeNames::mouseleave; |
57 bool isCancelable = !isMouseEnterOrLeave; | 58 bool isCancelable = !isMouseEnterOrLeave; |
58 bool isBubbling = !isMouseEnterOrLeave; | 59 bool isBubbling = !isMouseEnterOrLeave; |
59 | 60 |
60 return MouseEvent::create( | 61 return MouseEvent::create( |
61 eventType, isBubbling, isCancelable, view, | 62 eventType, isBubbling, isCancelable, view, |
62 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), | 63 detail, event.globalPosition().x(), event.globalPosition().y(), event.po
sition().x(), event.position().y(), |
63 event.movementDelta().x(), event.movementDelta().y(), | 64 event.movementDelta().x(), event.movementDelta().y(), |
64 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even
t.button(), | 65 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even
t.button(), |
| 66 platformModifiersToButtons(event.modifiers()), |
65 relatedTarget, nullptr, false, event.syntheticEventType()); | 67 relatedTarget, nullptr, false, event.syntheticEventType()); |
66 } | 68 } |
67 | 69 |
68 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, | 70 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type,
bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, |
69 int detail, int screenX, int screenY, int pageX, int pageY, | 71 int detail, int screenX, int screenY, int pageX, int pageY, |
70 int movementX, int movementY, | 72 int movementX, int movementY, |
71 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short butto
n, | 73 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
| 74 unsigned short button, unsigned short buttons, |
72 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Da
taTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventTy
pe syntheticEventType) | 75 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Da
taTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventTy
pe syntheticEventType) |
73 { | 76 { |
74 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, | 77 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, |
75 detail, screenX, screenY, pageX, pageY, | 78 detail, screenX, screenY, pageX, pageY, |
76 movementX, movementY, | 79 movementX, movementY, |
77 ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, dataTransfer,
isSimulated, syntheticEventType)); | 80 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data
Transfer, isSimulated, syntheticEventType)); |
78 } | 81 } |
79 | 82 |
80 MouseEvent::MouseEvent() | 83 MouseEvent::MouseEvent() |
81 : m_button(0) | 84 : m_button(0) |
| 85 , m_buttons(0) |
82 , m_buttonDown(false) | 86 , m_buttonDown(false) |
83 { | 87 { |
84 } | 88 } |
85 | 89 |
86 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, | 90 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
lable, PassRefPtrWillBeRawPtr<AbstractView> view, |
87 int detail, int screenX, int screenY, int pageX, int pageY, | 91 int detail, int screenX, int screenY, int pageX, int pageY, |
88 int movementX, int movementY, | 92 int movementX, int movementY, |
89 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, | 93 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
90 unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, | 94 unsigned short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventT
arget> relatedTarget, |
91 PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, Platfor
mMouseEvent::SyntheticEventType syntheticEventType) | 95 PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, Platfor
mMouseEvent::SyntheticEventType syntheticEventType) |
92 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), | 96 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint
(screenX, screenY), |
93 IntPoint(pageX, pageY), | 97 IntPoint(pageX, pageY), |
94 IntPoint(movementX, movementY), | 98 IntPoint(movementX, movementY), |
95 ctrlKey, altKey, shiftKey, metaKey, isSimulated) | 99 ctrlKey, altKey, shiftKey, metaKey, isSimulated) |
96 , m_button(button == (unsigned short)-1 ? 0 : button) | 100 , m_button(button == (unsigned short)-1 ? 0 : button) |
| 101 , m_buttons(buttons) |
97 , m_buttonDown(button != (unsigned short)-1) | 102 , m_buttonDown(button != (unsigned short)-1) |
98 , m_relatedTarget(relatedTarget) | 103 , m_relatedTarget(relatedTarget) |
99 , m_dataTransfer(dataTransfer) | 104 , m_dataTransfer(dataTransfer) |
100 , m_syntheticEventType(syntheticEventType) | 105 , m_syntheticEventType(syntheticEventType) |
101 { | 106 { |
102 } | 107 } |
103 | 108 |
104 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
ializer) | 109 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
ializer) |
105 : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable,
initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer.
screenY), | 110 : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable,
initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer.
screenY), |
106 IntPoint(0 /* pageX */, 0 /* pageY */), | 111 IntPoint(0 /* pageX */, 0 /* pageY */), |
107 IntPoint(0 /* movementX */, 0 /* movementY */), | 112 IntPoint(0 /* movementX */, 0 /* movementY */), |
108 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ
er.metaKey, false /* isSimulated */) | 113 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ
er.metaKey, false /* isSimulated */) |
109 , m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button
) | 114 , m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button
) |
| 115 , m_buttons(initializer.buttons) |
110 , m_buttonDown(initializer.button != (unsigned short)-1) | 116 , m_buttonDown(initializer.button != (unsigned short)-1) |
111 , m_relatedTarget(initializer.relatedTarget) | 117 , m_relatedTarget(initializer.relatedTarget) |
112 , m_dataTransfer(nullptr) | 118 , m_dataTransfer(nullptr) |
113 { | 119 { |
114 initCoordinates(IntPoint(initializer.clientX, initializer.clientY)); | 120 initCoordinates(IntPoint(initializer.clientX, initializer.clientY)); |
115 } | 121 } |
116 | 122 |
117 MouseEvent::~MouseEvent() | 123 MouseEvent::~MouseEvent() |
118 { | 124 { |
119 } | 125 } |
120 | 126 |
| 127 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) |
| 128 { |
| 129 unsigned short buttons = 0; |
| 130 |
| 131 if (modifiers & PlatformEvent::LeftButtonDown) |
| 132 buttons |= 1; |
| 133 if (modifiers & PlatformEvent::RightButtonDown) |
| 134 buttons |= 2; |
| 135 if (modifiers & PlatformEvent::MiddleButtonDown) |
| 136 buttons |= 4; |
| 137 |
| 138 return buttons; |
| 139 } |
| 140 |
121 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c
ancelable, PassRefPtrWillBeRawPtr<AbstractView> view, | 141 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c
ancelable, PassRefPtrWillBeRawPtr<AbstractView> view, |
122 int detail, int screenX, int screenY, int client
X, int clientY, | 142 int detail, int screenX, int screenY, int client
X, int clientY, |
123 bool ctrlKey, bool altKey, bool shiftKey, bool m
etaKey, | 143 bool ctrlKey, bool altKey, bool shiftKey, bool m
etaKey, |
124 unsigned short button, PassRefPtrWillBeRawPtr<Ev
entTarget> relatedTarget) | 144 unsigned short button, PassRefPtrWillBeRawPtr<Ev
entTarget> relatedTarget, unsigned short buttons) |
125 { | 145 { |
126 if (dispatched()) | 146 if (dispatched()) |
127 return; | 147 return; |
128 | 148 |
129 initUIEvent(type, canBubble, cancelable, view, detail); | 149 initUIEvent(type, canBubble, cancelable, view, detail); |
130 | 150 |
131 m_screenLocation = IntPoint(screenX, screenY); | 151 m_screenLocation = IntPoint(screenX, screenY); |
132 m_ctrlKey = ctrlKey; | 152 m_ctrlKey = ctrlKey; |
133 m_altKey = altKey; | 153 m_altKey = altKey; |
134 m_shiftKey = shiftKey; | 154 m_shiftKey = shiftKey; |
135 m_metaKey = metaKey; | 155 m_metaKey = metaKey; |
136 m_button = button == (unsigned short)-1 ? 0 : button; | 156 m_button = button == (unsigned short)-1 ? 0 : button; |
| 157 m_buttons = buttons; |
137 m_buttonDown = button != (unsigned short)-1; | 158 m_buttonDown = button != (unsigned short)-1; |
138 m_relatedTarget = relatedTarget; | 159 m_relatedTarget = relatedTarget; |
139 | 160 |
140 initCoordinates(IntPoint(clientX, clientY)); | 161 initCoordinates(IntPoint(clientX, clientY)); |
141 | 162 |
142 // FIXME: m_isSimulated is not set to false here. | 163 // FIXME: m_isSimulated is not set to false here. |
143 // FIXME: m_dataTransfer is not set to nullptr here. | 164 // FIXME: m_dataTransfer is not set to nullptr here. |
144 } | 165 } |
145 | 166 |
146 const AtomicString& MouseEvent::interfaceName() const | 167 const AtomicString& MouseEvent::interfaceName() const |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At
omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill
BeRawPtr<Event> underlyingEvent) | 219 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At
omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill
BeRawPtr<Event> underlyingEvent) |
199 { | 220 { |
200 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin
gEvent)); | 221 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin
gEvent)); |
201 } | 222 } |
202 | 223 |
203 SimulatedMouseEvent::~SimulatedMouseEvent() | 224 SimulatedMouseEvent::~SimulatedMouseEvent() |
204 { | 225 { |
205 } | 226 } |
206 | 227 |
207 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent
) | 228 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent
) |
208 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false,
false, false, 0, | 229 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false,
false, false, 0, 0, |
209 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) | 230 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) |
210 { | 231 { |
211 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { | 232 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve
nt.get())) { |
212 m_ctrlKey = keyStateEvent->ctrlKey(); | 233 m_ctrlKey = keyStateEvent->ctrlKey(); |
213 m_altKey = keyStateEvent->altKey(); | 234 m_altKey = keyStateEvent->altKey(); |
214 m_shiftKey = keyStateEvent->shiftKey(); | 235 m_shiftKey = keyStateEvent->shiftKey(); |
215 m_metaKey = keyStateEvent->metaKey(); | 236 m_metaKey = keyStateEvent->metaKey(); |
216 } | 237 } |
217 setUnderlyingEvent(underlyingEvent); | 238 setUnderlyingEvent(underlyingEvent); |
218 | 239 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (event().type() != EventTypeNames::click || event().detail() != 2) | 288 if (event().type() != EventTypeNames::click || event().detail() != 2) |
268 return !swallowEvent; | 289 return !swallowEvent; |
269 | 290 |
270 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part | 291 // Special case: If it's a double click event, we also send the dblclick eve
nt. This is not part |
271 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated | 292 // of the DOM specs, but is used for compatibility with the ondblclick="" at
tribute. This is treated |
272 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. | 293 // as a separate event in other DOM-compliant browsers like Firefox, and so
we do the same. |
273 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); | 294 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); |
274 doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event().bubbles()
, event().cancelable(), event().view(), | 295 doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event().bubbles()
, event().cancelable(), event().view(), |
275 event().detail(), event().screenX(), event().screenY(), event().clientX(
), event().clientY(), | 296 event().detail(), event().screenX(), event().screenY(), event().clientX(
), event().clientY(), |
276 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey
(), | 297 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey
(), |
277 event().button(), relatedTarget); | 298 event().button(), relatedTarget, event().buttons()); |
278 if (event().defaultHandled()) | 299 if (event().defaultHandled()) |
279 doubleClickEvent->setDefaultHandled(); | 300 doubleClickEvent->setDefaultHandled(); |
280 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); | 301 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator
::create(doubleClickEvent)); |
281 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) | 302 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented
()) |
282 return false; | 303 return false; |
283 return !swallowEvent; | 304 return !swallowEvent; |
284 } | 305 } |
285 | 306 |
286 } // namespace blink | 307 } // namespace blink |
OLD | NEW |