OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/events/PointerEventFactory.h" | 5 #include "core/events/PointerEventFactory.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "platform/geometry/FloatSize.h" | 8 #include "platform/geometry/FloatSize.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 pointerEventInit->setScreenX(touchPoint.screenPosition.x); | 127 pointerEventInit->setScreenX(touchPoint.screenPosition.x); |
128 pointerEventInit->setScreenY(touchPoint.screenPosition.y); | 128 pointerEventInit->setScreenY(touchPoint.screenPosition.y); |
129 pointerEventInit->setPressure( | 129 pointerEventInit->setPressure( |
130 getPointerEventPressure(touchPoint.force, pointerEventInit->buttons())); | 130 getPointerEventPressure(touchPoint.force, pointerEventInit->buttons())); |
131 pointerEventInit->setTiltX(touchPoint.tiltX); | 131 pointerEventInit->setTiltX(touchPoint.tiltX); |
132 pointerEventInit->setTiltY(touchPoint.tiltY); | 132 pointerEventInit->setTiltY(touchPoint.tiltY); |
133 pointerEventInit->setTangentialPressure(touchPoint.tangentialPressure); | 133 pointerEventInit->setTangentialPressure(touchPoint.tangentialPressure); |
134 pointerEventInit->setTwist(touchPoint.twist); | 134 pointerEventInit->setTwist(touchPoint.twist); |
135 } | 135 } |
136 | 136 |
137 void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent, | 137 void updateMousePointerEventInit(const WebMouseEvent& mouseEvent, |
138 LocalDOMWindow* view, | 138 LocalDOMWindow* view, |
139 PointerEventInit* pointerEventInit) { | 139 PointerEventInit* pointerEventInit) { |
140 // This function should not update attributes like pointerId, isPrimary, | 140 // This function should not update attributes like pointerId, isPrimary, |
141 // and pointerType which is the same among the coalesced events and the | 141 // and pointerType which is the same among the coalesced events and the |
142 // dispatched event. | 142 // dispatched event. |
143 | 143 |
144 pointerEventInit->setScreenX(mouseEvent.globalPosition().x()); | 144 pointerEventInit->setScreenX(mouseEvent.globalX); |
145 pointerEventInit->setScreenY(mouseEvent.globalPosition().y()); | 145 pointerEventInit->setScreenY(mouseEvent.globalY); |
146 | 146 |
147 IntPoint locationInFrameZoomed; | 147 IntPoint locationInFrameZoomed; |
148 if (view && view->frame() && view->frame()->view()) { | 148 if (view && view->frame() && view->frame()->view()) { |
149 LocalFrame* frame = view->frame(); | 149 LocalFrame* frame = view->frame(); |
150 FrameView* frameView = frame->view(); | 150 FrameView* frameView = frame->view(); |
151 IntPoint locationInContents = | 151 IntPoint locationInContents = frameView->rootFrameToContents( |
152 frameView->rootFrameToContents(mouseEvent.position()); | 152 flooredIntPoint(mouseEvent.positionInRootFrame())); |
153 locationInFrameZoomed = frameView->contentsToFrame(locationInContents); | 153 locationInFrameZoomed = frameView->contentsToFrame(locationInContents); |
154 float scaleFactor = 1 / frame->pageZoomFactor(); | 154 float scaleFactor = 1 / frame->pageZoomFactor(); |
155 locationInFrameZoomed.scale(scaleFactor, scaleFactor); | 155 locationInFrameZoomed.scale(scaleFactor, scaleFactor); |
156 } | 156 } |
157 | 157 |
158 pointerEventInit->setClientX(locationInFrameZoomed.x()); | 158 pointerEventInit->setClientX(locationInFrameZoomed.x()); |
159 pointerEventInit->setClientY(locationInFrameZoomed.y()); | 159 pointerEventInit->setClientY(locationInFrameZoomed.y()); |
160 | 160 |
161 pointerEventInit->setPressure(getPointerEventPressure( | 161 pointerEventInit->setPressure( |
162 mouseEvent.pointerProperties().force, pointerEventInit->buttons())); | 162 getPointerEventPressure(mouseEvent.force, pointerEventInit->buttons())); |
163 pointerEventInit->setTiltX(mouseEvent.pointerProperties().tiltX); | 163 pointerEventInit->setTiltX(mouseEvent.tiltX); |
164 pointerEventInit->setTiltY(mouseEvent.pointerProperties().tiltY); | 164 pointerEventInit->setTiltY(mouseEvent.tiltY); |
165 pointerEventInit->setTangentialPressure( | 165 pointerEventInit->setTangentialPressure(mouseEvent.tangentialPressure); |
166 mouseEvent.pointerProperties().tangentialPressure); | 166 pointerEventInit->setTwist(mouseEvent.twist); |
167 pointerEventInit->setTwist(mouseEvent.pointerProperties().twist); | |
168 } | 167 } |
169 | 168 |
170 } // namespace | 169 } // namespace |
171 | 170 |
172 const int PointerEventFactory::s_invalidId = 0; | 171 const int PointerEventFactory::s_invalidId = 0; |
173 | 172 |
174 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. | 173 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. |
175 const int PointerEventFactory::s_mouseId = 1; | 174 const int PointerEventFactory::s_mouseId = 1; |
176 | 175 |
177 void PointerEventFactory::setIdTypeButtons( | 176 void PointerEventFactory::setIdTypeButtons( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 type != EventTypeNames::pointercancel && | 208 type != EventTypeNames::pointercancel && |
210 type != EventTypeNames::gotpointercapture && | 209 type != EventTypeNames::gotpointercapture && |
211 type != EventTypeNames::lostpointercapture); | 210 type != EventTypeNames::lostpointercapture); |
212 | 211 |
213 pointerEventInit.setComposed(true); | 212 pointerEventInit.setComposed(true); |
214 pointerEventInit.setDetail(0); | 213 pointerEventInit.setDetail(0); |
215 } | 214 } |
216 | 215 |
217 PointerEvent* PointerEventFactory::create( | 216 PointerEvent* PointerEventFactory::create( |
218 const AtomicString& mouseEventName, | 217 const AtomicString& mouseEventName, |
219 const PlatformMouseEvent& mouseEvent, | 218 const WebMouseEvent& mouseEvent, |
220 const Vector<PlatformMouseEvent>& coalescedMouseEvents, | 219 const Vector<WebMouseEvent>& coalescedMouseEvents, |
221 LocalDOMWindow* view) { | 220 LocalDOMWindow* view) { |
222 DCHECK(mouseEventName == EventTypeNames::mousemove || | 221 DCHECK(mouseEventName == EventTypeNames::mousemove || |
223 mouseEventName == EventTypeNames::mousedown || | 222 mouseEventName == EventTypeNames::mousedown || |
224 mouseEventName == EventTypeNames::mouseup); | 223 mouseEventName == EventTypeNames::mouseup); |
225 | 224 |
226 AtomicString pointerEventName = | 225 AtomicString pointerEventName = |
227 pointerEventNameForMouseEventName(mouseEventName); | 226 pointerEventNameForMouseEventName(mouseEventName); |
228 | 227 |
229 unsigned buttons = | 228 unsigned buttons = MouseEvent::platformModifiersToButtons( |
230 MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()); | 229 static_cast<PlatformEvent::Modifiers>(mouseEvent.modifiers())); |
231 PointerEventInit pointerEventInit; | 230 PointerEventInit pointerEventInit; |
232 | 231 |
233 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); | 232 setIdTypeButtons(pointerEventInit, mouseEvent, buttons); |
234 setEventSpecificFields(pointerEventInit, pointerEventName); | 233 setEventSpecificFields(pointerEventInit, pointerEventName); |
235 | 234 |
236 if (pointerEventName == EventTypeNames::pointerdown || | 235 if (pointerEventName == EventTypeNames::pointerdown || |
237 pointerEventName == EventTypeNames::pointerup) { | 236 pointerEventName == EventTypeNames::pointerup) { |
238 WebPointerProperties::Button button = mouseEvent.pointerProperties().button; | 237 WebPointerProperties::Button button = mouseEvent.button; |
239 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. | 238 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. |
240 if (mouseEvent.pointerProperties().pointerType == | 239 if (mouseEvent.pointerType == WebPointerProperties::PointerType::Eraser && |
241 WebPointerProperties::PointerType::Eraser && | |
242 button == WebPointerProperties::Button::Left) | 240 button == WebPointerProperties::Button::Left) |
243 button = WebPointerProperties::Button::Eraser; | 241 button = WebPointerProperties::Button::Eraser; |
244 pointerEventInit.setButton(static_cast<int>(button)); | 242 pointerEventInit.setButton(static_cast<int>(button)); |
245 } else { | 243 } else { |
246 DCHECK(pointerEventName == EventTypeNames::pointermove); | 244 DCHECK(pointerEventName == EventTypeNames::pointermove); |
247 pointerEventInit.setButton( | 245 pointerEventInit.setButton( |
248 static_cast<int>(WebPointerProperties::Button::NoButton)); | 246 static_cast<int>(WebPointerProperties::Button::NoButton)); |
249 } | 247 } |
250 | 248 |
251 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, | 249 UIEventWithKeyState::setFromWebInputEventModifiers( |
252 mouseEvent.getModifiers()); | 250 pointerEventInit, |
| 251 static_cast<WebInputEvent::Modifiers>(mouseEvent.modifiers())); |
253 | 252 |
254 // Make sure chorded buttons fire pointermove instead of pointerup/down. | 253 // Make sure chorded buttons fire pointermove instead of pointerup/down. |
255 if ((pointerEventName == EventTypeNames::pointerdown && | 254 if ((pointerEventName == EventTypeNames::pointerdown && |
256 (buttons & | 255 (buttons & ~buttonToButtonsBitfield(mouseEvent.button)) != 0) || |
257 ~buttonToButtonsBitfield(mouseEvent.pointerProperties().button)) != | |
258 0) || | |
259 (pointerEventName == EventTypeNames::pointerup && buttons != 0)) | 256 (pointerEventName == EventTypeNames::pointerup && buttons != 0)) |
260 pointerEventName = EventTypeNames::pointermove; | 257 pointerEventName = EventTypeNames::pointermove; |
261 | 258 |
262 pointerEventInit.setView(view); | 259 pointerEventInit.setView(view); |
263 | 260 |
264 updateMousePointerEventInit(mouseEvent, view, &pointerEventInit); | 261 updateMousePointerEventInit(mouseEvent, view, &pointerEventInit); |
265 | 262 |
266 // Create coalesced events init structure only for pointermove. | 263 // Create coalesced events init structure only for pointermove. |
267 if (pointerEventName == EventTypeNames::pointermove) { | 264 if (pointerEventName == EventTypeNames::pointermove) { |
268 HeapVector<Member<PointerEvent>> coalescedPointerEvents; | 265 HeapVector<Member<PointerEvent>> coalescedPointerEvents; |
269 for (const auto& coalescedMouseEvent : coalescedMouseEvents) { | 266 for (const auto& coalescedMouseEvent : coalescedMouseEvents) { |
270 DCHECK_EQ(mouseEvent.pointerProperties().id, | 267 DCHECK_EQ(mouseEvent.id, coalescedMouseEvent.id); |
271 coalescedMouseEvent.pointerProperties().id); | |
272 // TODO(crbug.com/684292): We need further investigation of why the | 268 // TODO(crbug.com/684292): We need further investigation of why the |
273 // following DCHECK fails. | 269 // following DCHECK fails. |
274 // DCHECK_EQ(mouseEvent.pointerProperties().pointerType, | 270 // DCHECK_EQ(mouseEvent.pointerType, coalescedMouseEvent.pointerType); |
275 // coalescedMouseEvent.pointerProperties().pointerType); | |
276 PointerEventInit coalescedEventInit = pointerEventInit; | 271 PointerEventInit coalescedEventInit = pointerEventInit; |
277 updateMousePointerEventInit(coalescedMouseEvent, view, | 272 updateMousePointerEventInit(coalescedMouseEvent, view, |
278 &coalescedEventInit); | 273 &coalescedEventInit); |
279 coalescedPointerEvents.push_back( | 274 coalescedPointerEvents.push_back( |
280 PointerEvent::create(pointerEventName, coalescedEventInit)); | 275 PointerEvent::create(pointerEventName, coalescedEventInit)); |
281 } | 276 } |
282 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | 277 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
283 } | 278 } |
284 | 279 |
285 return PointerEvent::create(pointerEventName, pointerEventInit); | 280 return PointerEvent::create(pointerEventName, pointerEventInit); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 const WebPointerProperties& properties) const { | 517 const WebPointerProperties& properties) const { |
523 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 518 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
524 return PointerEventFactory::s_mouseId; | 519 return PointerEventFactory::s_mouseId; |
525 IncomingId id(properties.pointerType, properties.id); | 520 IncomingId id(properties.pointerType, properties.id); |
526 if (m_pointerIncomingIdMapping.contains(id)) | 521 if (m_pointerIncomingIdMapping.contains(id)) |
527 return m_pointerIncomingIdMapping.get(id); | 522 return m_pointerIncomingIdMapping.get(id); |
528 return PointerEventFactory::s_invalidId; | 523 return PointerEventFactory::s_invalidId; |
529 } | 524 } |
530 | 525 |
531 } // namespace blink | 526 } // namespace blink |
OLD | NEW |