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 14 matching lines...) Expand all Loading... | |
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 "core/frame/FrameView.h" | 29 #include "core/frame/FrameView.h" |
30 #include "core/frame/LocalDOMWindow.h" | 30 #include "core/frame/LocalDOMWindow.h" |
31 #include "core/frame/LocalFrame.h" | 31 #include "core/frame/LocalFrame.h" |
32 #include "core/layout/LayoutObject.h" | 32 #include "core/layout/LayoutObject.h" |
33 #include "core/paint/PaintLayer.h" | 33 #include "core/paint/PaintLayer.h" |
34 #include "core/svg/SVGElement.h" | 34 #include "core/svg/SVGElement.h" |
35 #include "platform/PlatformMouseEvent.h" | |
36 #include "public/platform/WebPointerProperties.h" | 35 #include "public/platform/WebPointerProperties.h" |
37 | 36 |
38 namespace blink { | 37 namespace blink { |
39 | 38 |
40 namespace { | 39 namespace { |
41 | 40 |
42 LayoutSize contentsScrollOffset(AbstractView* abstractView) { | 41 LayoutSize contentsScrollOffset(AbstractView* abstractView) { |
43 if (!abstractView || !abstractView->isLocalDOMWindow()) | 42 if (!abstractView || !abstractView->isLocalDOMWindow()) |
44 return LayoutSize(); | 43 return LayoutSize(); |
45 LocalFrame* frame = toLocalDOMWindow(abstractView)->frame(); | 44 LocalFrame* frame = toLocalDOMWindow(abstractView)->frame(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 const MouseEventInit& initializer) { | 83 const MouseEventInit& initializer) { |
85 if (scriptState && scriptState->world().isIsolatedWorld()) | 84 if (scriptState && scriptState->world().isIsolatedWorld()) |
86 UIEventWithKeyState::didCreateEventInIsolatedWorld( | 85 UIEventWithKeyState::didCreateEventInIsolatedWorld( |
87 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), | 86 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), |
88 initializer.metaKey()); | 87 initializer.metaKey()); |
89 return new MouseEvent(type, initializer); | 88 return new MouseEvent(type, initializer); |
90 } | 89 } |
91 | 90 |
92 MouseEvent* MouseEvent::create(const AtomicString& eventType, | 91 MouseEvent* MouseEvent::create(const AtomicString& eventType, |
93 AbstractView* view, | 92 AbstractView* view, |
94 const PlatformMouseEvent& event, | 93 const WebMouseEvent& event, |
95 int detail, | 94 int detail, |
95 const String& canvasRegionId, | |
96 Node* relatedTarget) { | 96 Node* relatedTarget) { |
97 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || | 97 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || |
98 eventType == EventTypeNames::mouseleave; | 98 eventType == EventTypeNames::mouseleave; |
99 bool isCancelable = !isMouseEnterOrLeave; | 99 bool isCancelable = !isMouseEnterOrLeave; |
100 bool isBubbling = !isMouseEnterOrLeave; | 100 bool isBubbling = !isMouseEnterOrLeave; |
101 | 101 return new MouseEvent(eventType, isBubbling, isCancelable, view, event, |
102 return MouseEvent::create( | 102 detail, canvasRegionId, relatedTarget); |
103 eventType, isBubbling, isCancelable, view, detail, | |
104 event.globalPosition().x(), event.globalPosition().y(), | |
105 event.position().x(), event.position().y(), event.movementDelta().x(), | |
106 event.movementDelta().y(), event.getModifiers(), | |
107 static_cast<short>(event.pointerProperties().button), | |
108 platformModifiersToButtons(event.getModifiers()), relatedTarget, | |
109 event.timestamp(), event.getSyntheticEventType(), event.region(), &event); | |
110 } | |
111 | |
112 MouseEvent* MouseEvent::create( | |
113 const AtomicString& type, | |
114 bool canBubble, | |
115 bool cancelable, | |
116 AbstractView* view, | |
117 int detail, | |
118 int screenX, | |
119 int screenY, | |
120 int windowX, | |
121 int windowY, | |
122 int movementX, | |
123 int movementY, | |
124 PlatformEvent::Modifiers modifiers, | |
125 short button, | |
126 unsigned short buttons, | |
127 EventTarget* relatedTarget, | |
128 TimeTicks platformTimeStamp, | |
129 PlatformMouseEvent::SyntheticEventType syntheticEventType, | |
130 const String& region, | |
131 const PlatformMouseEvent* mouseEvent) { | |
132 return new MouseEvent( | |
133 type, canBubble, cancelable, view, detail, screenX, screenY, windowX, | |
134 windowY, movementX, movementY, modifiers, button, buttons, relatedTarget, | |
135 platformTimeStamp, syntheticEventType, region, mouseEvent); | |
136 } | 103 } |
137 | 104 |
138 MouseEvent* MouseEvent::create(const AtomicString& eventType, | 105 MouseEvent* MouseEvent::create(const AtomicString& eventType, |
139 AbstractView* view, | 106 AbstractView* view, |
140 Event* underlyingEvent, | 107 Event* underlyingEvent, |
141 SimulatedClickCreationScope creationScope) { | 108 SimulatedClickCreationScope creationScope) { |
142 PlatformEvent::Modifiers modifiers = PlatformEvent::NoModifiers; | 109 PlatformEvent::Modifiers modifiers = PlatformEvent::NoModifiers; |
143 if (UIEventWithKeyState* keyStateEvent = | 110 if (UIEventWithKeyState* keyStateEvent = |
144 findEventWithKeyState(underlyingEvent)) { | 111 findEventWithKeyState(underlyingEvent)) { |
145 modifiers = keyStateEvent->modifiers(); | 112 modifiers = keyStateEvent->modifiers(); |
146 } | 113 } |
147 | 114 |
148 PlatformMouseEvent::SyntheticEventType syntheticType = | 115 SyntheticEventType syntheticType = Positionless; |
149 PlatformMouseEvent::Positionless; | |
150 int screenX = 0; | 116 int screenX = 0; |
151 int screenY = 0; | 117 int screenY = 0; |
152 if (underlyingEvent && underlyingEvent->isMouseEvent()) { | 118 if (underlyingEvent && underlyingEvent->isMouseEvent()) { |
153 syntheticType = PlatformMouseEvent::RealOrIndistinguishable; | 119 syntheticType = RealOrIndistinguishable; |
154 MouseEvent* mouseEvent = toMouseEvent(underlyingEvent); | 120 MouseEvent* mouseEvent = toMouseEvent(underlyingEvent); |
155 screenX = mouseEvent->screenX(); | 121 screenX = mouseEvent->screenX(); |
156 screenY = mouseEvent->screenY(); | 122 screenY = mouseEvent->screenY(); |
157 } | 123 } |
158 | 124 |
159 TimeTicks timestamp = | 125 TimeTicks timestamp = |
160 underlyingEvent ? underlyingEvent->platformTimeStamp() : TimeTicks::Now(); | 126 underlyingEvent ? underlyingEvent->platformTimeStamp() : TimeTicks::Now(); |
161 MouseEvent* createdEvent = MouseEvent::create( | 127 MouseEvent* createdEvent = new MouseEvent( |
162 eventType, true, true, view, 0, screenX, screenY, 0, 0, 0, 0, modifiers, | 128 eventType, true, true, view, 0, screenX, screenY, 0, 0, 0, 0, modifiers, |
163 0, 0, nullptr, timestamp, syntheticType, String(), nullptr); | 129 0, 0, nullptr, timestamp, syntheticType, String()); |
164 | 130 |
165 createdEvent->setTrusted(creationScope == | 131 createdEvent->setTrusted(creationScope == |
166 SimulatedClickCreationScope::FromUserAgent); | 132 SimulatedClickCreationScope::FromUserAgent); |
167 createdEvent->setUnderlyingEvent(underlyingEvent); | 133 createdEvent->setUnderlyingEvent(underlyingEvent); |
168 if (syntheticType == PlatformMouseEvent::RealOrIndistinguishable) { | 134 if (syntheticType == RealOrIndistinguishable) { |
169 MouseEvent* mouseEvent = toMouseEvent(createdEvent->underlyingEvent()); | 135 MouseEvent* mouseEvent = toMouseEvent(createdEvent->underlyingEvent()); |
170 createdEvent->initCoordinates(mouseEvent->clientX(), mouseEvent->clientY()); | 136 createdEvent->initCoordinates(mouseEvent->clientX(), mouseEvent->clientY()); |
171 } | 137 } |
172 | 138 |
173 return createdEvent; | 139 return createdEvent; |
174 } | 140 } |
175 | 141 |
176 MouseEvent::MouseEvent() | 142 MouseEvent::MouseEvent() |
177 : m_positionType(PositionType::Position), | 143 : m_positionType(PositionType::Position), |
178 m_hasCachedRelativePosition(false), | 144 m_hasCachedRelativePosition(false), |
179 m_button(0), | 145 m_button(0), |
180 m_buttons(0), | 146 m_buttons(0), |
181 m_relatedTarget(nullptr), | 147 m_relatedTarget(nullptr), |
182 m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) {} | 148 m_syntheticEventType(RealOrIndistinguishable) {} |
183 | 149 |
184 MouseEvent::MouseEvent( | 150 MouseEvent::MouseEvent(const AtomicString& eventType, |
185 const AtomicString& eventType, | 151 bool canBubble, |
186 bool canBubble, | 152 bool cancelable, |
187 bool cancelable, | 153 AbstractView* abstractView, |
188 AbstractView* abstractView, | 154 const WebMouseEvent& event, |
189 PlatformMouseEvent::SyntheticEventType syntheticEventType, | 155 int detail, |
190 const String& region, | 156 const String& region, |
191 const WebMouseEvent& event) | 157 EventTarget* relatedTarget) |
192 : UIEventWithKeyState( | 158 : UIEventWithKeyState( |
193 eventType, | 159 eventType, |
194 canBubble, | 160 canBubble, |
195 cancelable, | 161 cancelable, |
196 abstractView, | 162 abstractView, |
197 0, | 163 detail, |
198 static_cast<PlatformEvent::Modifiers>(event.modifiers()), | 164 static_cast<PlatformEvent::Modifiers>(event.modifiers()), |
199 TimeTicks::FromSeconds(event.timeStampSeconds()), | 165 TimeTicks::FromSeconds(event.timeStampSeconds()), |
200 syntheticEventType == PlatformMouseEvent::FromTouch | 166 event.fromTouch() |
201 ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() | 167 ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() |
202 : InputDeviceCapabilities:: | 168 : InputDeviceCapabilities:: |
203 doesntFireTouchEventsSourceCapabilities()), | 169 doesntFireTouchEventsSourceCapabilities()), |
204 m_screenLocation(event.globalX, event.globalY), | 170 m_screenLocation(event.globalX, event.globalY), |
205 m_movementDelta(flooredIntPoint(event.movementInRootFrame())), | 171 m_movementDelta(flooredIntPoint(event.movementInRootFrame())), |
206 m_positionType(syntheticEventType == PlatformMouseEvent::Positionless | 172 m_positionType(PositionType::Position), |
207 ? PositionType::Positionless | 173 m_button(static_cast<short>(event.button)), |
208 : PositionType::Position), | |
209 m_button(0), | |
210 m_buttons(platformModifiersToButtons(event.modifiers())), | 174 m_buttons(platformModifiersToButtons(event.modifiers())), |
211 m_syntheticEventType(syntheticEventType), | 175 m_relatedTarget(relatedTarget), |
176 m_syntheticEventType(event.fromTouch() ? FromTouch | |
177 : RealOrIndistinguishable), | |
212 m_region(region) { | 178 m_region(region) { |
213 IntPoint rootFrameCoordinates = flooredIntPoint(event.positionInRootFrame()); | 179 IntPoint rootFrameCoordinates = flooredIntPoint(event.positionInRootFrame()); |
214 initCoordinatesFromRootFrame(rootFrameCoordinates.x(), | 180 initCoordinatesFromRootFrame(rootFrameCoordinates.x(), |
215 rootFrameCoordinates.y()); | 181 rootFrameCoordinates.y()); |
216 } | 182 } |
217 | 183 |
218 MouseEvent::MouseEvent( | 184 MouseEvent::MouseEvent(const AtomicString& eventType, |
219 const AtomicString& eventType, | 185 bool canBubble, |
220 bool canBubble, | 186 bool cancelable, |
221 bool cancelable, | 187 AbstractView* abstractView, |
222 AbstractView* abstractView, | 188 int detail, |
223 int detail, | 189 int screenX, |
224 int screenX, | 190 int screenY, |
225 int screenY, | 191 int windowX, |
226 int windowX, | 192 int windowY, |
227 int windowY, | 193 int movementX, |
228 int movementX, | 194 int movementY, |
229 int movementY, | 195 PlatformEvent::Modifiers modifiers, |
mustaq
2017/01/27 16:53:44
Please remove platform Modifiers from MouseEvent i
dtapuska
2017/01/27 21:00:00
I will do this in here: https://codereview.chromiu
| |
230 PlatformEvent::Modifiers modifiers, | 196 short button, |
231 short button, | 197 unsigned short buttons, |
232 unsigned short buttons, | 198 EventTarget* relatedTarget, |
233 EventTarget* relatedTarget, | 199 TimeTicks platformTimeStamp, |
234 TimeTicks platformTimeStamp, | 200 SyntheticEventType syntheticEventType, |
235 PlatformMouseEvent::SyntheticEventType syntheticEventType, | 201 const String& region) |
236 const String& region, | |
237 const PlatformMouseEvent* mouseEvent) | |
238 : UIEventWithKeyState( | 202 : UIEventWithKeyState( |
239 eventType, | 203 eventType, |
240 canBubble, | 204 canBubble, |
241 cancelable, | 205 cancelable, |
242 abstractView, | 206 abstractView, |
243 detail, | 207 detail, |
244 modifiers, | 208 modifiers, |
245 platformTimeStamp, | 209 platformTimeStamp, |
246 syntheticEventType == PlatformMouseEvent::FromTouch | 210 syntheticEventType == FromTouch |
247 ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() | 211 ? InputDeviceCapabilities::firesTouchEventsSourceCapabilities() |
248 : InputDeviceCapabilities:: | 212 : InputDeviceCapabilities:: |
249 doesntFireTouchEventsSourceCapabilities()), | 213 doesntFireTouchEventsSourceCapabilities()), |
250 m_screenLocation(screenX, screenY), | 214 m_screenLocation(screenX, screenY), |
251 m_movementDelta(movementX, movementY), | 215 m_movementDelta(movementX, movementY), |
252 m_positionType(syntheticEventType == PlatformMouseEvent::Positionless | 216 m_positionType(syntheticEventType == Positionless |
253 ? PositionType::Positionless | 217 ? PositionType::Positionless |
254 : PositionType::Position), | 218 : PositionType::Position), |
255 m_button(button), | 219 m_button(button), |
256 m_buttons(buttons), | 220 m_buttons(buttons), |
257 m_relatedTarget(relatedTarget), | 221 m_relatedTarget(relatedTarget), |
258 m_syntheticEventType(syntheticEventType), | 222 m_syntheticEventType(syntheticEventType), |
259 m_region(region) { | 223 m_region(region) { |
260 if (mouseEvent) | |
261 m_mouseEvent.reset(new PlatformMouseEvent(*mouseEvent)); | |
262 initCoordinatesFromRootFrame(windowX, windowY); | 224 initCoordinatesFromRootFrame(windowX, windowY); |
263 } | 225 } |
264 | 226 |
265 MouseEvent::MouseEvent(const AtomicString& eventType, | 227 MouseEvent::MouseEvent(const AtomicString& eventType, |
266 const MouseEventInit& initializer) | 228 const MouseEventInit& initializer) |
267 : UIEventWithKeyState(eventType, initializer), | 229 : UIEventWithKeyState(eventType, initializer), |
268 m_screenLocation( | 230 m_screenLocation( |
269 DoublePoint(initializer.screenX(), initializer.screenY())), | 231 DoublePoint(initializer.screenX(), initializer.screenY())), |
270 m_movementDelta( | 232 m_movementDelta( |
271 IntPoint(initializer.movementX(), initializer.movementY())), | 233 IntPoint(initializer.movementX(), initializer.movementY())), |
272 m_positionType(PositionType::Position), | 234 m_positionType(PositionType::Position), |
273 m_button(initializer.button()), | 235 m_button(initializer.button()), |
274 m_buttons(initializer.buttons()), | 236 m_buttons(initializer.buttons()), |
275 m_relatedTarget(initializer.relatedTarget()), | 237 m_relatedTarget(initializer.relatedTarget()), |
276 m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable), | 238 m_syntheticEventType(RealOrIndistinguishable), |
277 m_region(initializer.region()) { | 239 m_region(initializer.region()) { |
278 initCoordinates(initializer.clientX(), initializer.clientY()); | 240 initCoordinates(initializer.clientX(), initializer.clientY()); |
279 } | 241 } |
280 | 242 |
281 void MouseEvent::initCoordinates(const double clientX, const double clientY) { | 243 void MouseEvent::initCoordinates(const double clientX, const double clientY) { |
282 // Set up initial values for coordinates. | 244 // Set up initial values for coordinates. |
283 // Correct values are computed lazily, see computeRelativePosition. | 245 // Correct values are computed lazily, see computeRelativePosition. |
284 m_clientLocation = DoublePoint(clientX, clientY); | 246 m_clientLocation = DoublePoint(clientX, clientY); |
285 m_pageLocation = m_clientLocation + DoubleSize(contentsScrollOffset(view())); | 247 m_pageLocation = m_clientLocation + DoubleSize(contentsScrollOffset(view())); |
286 | 248 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 // Correct values are computed lazily, see computeRelativePosition. | 280 // Correct values are computed lazily, see computeRelativePosition. |
319 m_layerLocation = m_pageLocation; | 281 m_layerLocation = m_pageLocation; |
320 m_offsetLocation = m_pageLocation; | 282 m_offsetLocation = m_pageLocation; |
321 | 283 |
322 computePageLocation(); | 284 computePageLocation(); |
323 m_hasCachedRelativePosition = false; | 285 m_hasCachedRelativePosition = false; |
324 } | 286 } |
325 | 287 |
326 MouseEvent::~MouseEvent() {} | 288 MouseEvent::~MouseEvent() {} |
327 | 289 |
328 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) { | 290 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) { |
mustaq
2017/01/27 16:53:44
Also s/platformModifiersToButtons()/webModifiersTo
dtapuska
2017/01/27 21:00:00
See dependent change as well.
| |
329 unsigned short buttons = 0; | 291 unsigned short buttons = 0; |
330 | 292 |
331 if (modifiers & PlatformEvent::LeftButtonDown) | 293 if (modifiers & PlatformEvent::LeftButtonDown) |
332 buttons |= static_cast<unsigned short>(WebPointerProperties::Buttons::Left); | 294 buttons |= static_cast<unsigned short>(WebPointerProperties::Buttons::Left); |
333 if (modifiers & PlatformEvent::RightButtonDown) | 295 if (modifiers & PlatformEvent::RightButtonDown) |
334 buttons |= | 296 buttons |= |
335 static_cast<unsigned short>(WebPointerProperties::Buttons::Right); | 297 static_cast<unsigned short>(WebPointerProperties::Buttons::Right); |
336 if (modifiers & PlatformEvent::MiddleButtonDown) | 298 if (modifiers & PlatformEvent::MiddleButtonDown) |
337 buttons |= | 299 buttons |= |
338 static_cast<unsigned short>(WebPointerProperties::Buttons::Middle); | 300 static_cast<unsigned short>(WebPointerProperties::Buttons::Middle); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 | 561 |
600 int MouseEvent::offsetY() { | 562 int MouseEvent::offsetY() { |
601 if (!hasPosition()) | 563 if (!hasPosition()) |
602 return 0; | 564 return 0; |
603 if (!m_hasCachedRelativePosition) | 565 if (!m_hasCachedRelativePosition) |
604 computeRelativePosition(); | 566 computeRelativePosition(); |
605 return std::round(m_offsetLocation.y()); | 567 return std::round(m_offsetLocation.y()); |
606 } | 568 } |
607 | 569 |
608 } // namespace blink | 570 } // namespace blink |
OLD | NEW |