OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/PointerEventManager.h" | 5 #include "core/events/PointerEventManager.h" |
6 | 6 |
7 namespace blink { | 7 namespace blink { |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. | 33 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. |
34 const PointerEventManager::MappedId PointerEventManager::s_mouseId = 1; | 34 const PointerEventManager::MappedId PointerEventManager::s_mouseId = 1; |
35 | 35 |
36 EventTarget* PointerEventManager::getCapturingNode(PassRefPtrWillBeRawPtr<Pointe
rEvent> pointerEvent) | 36 EventTarget* PointerEventManager::getCapturingNode(PassRefPtrWillBeRawPtr<Pointe
rEvent> pointerEvent) |
37 { | 37 { |
38 // TODO(nzolghadr): Add APIs to set the capturing nodes and return the corre
ct node here | 38 // TODO(nzolghadr): Add APIs to set the capturing nodes and return the corre
ct node here |
39 return nullptr; | 39 return nullptr; |
40 } | 40 } |
41 | 41 |
| 42 float getPointerEventPressure(float force, int buttons) |
| 43 { |
| 44 if (isnan(force)) |
| 45 return buttons ? 0.5 : 0; |
| 46 return force; |
| 47 } |
| 48 |
42 void PointerEventManager::setIdAndType(PointerEventInit &pointerEventInit, | 49 void PointerEventManager::setIdAndType(PointerEventInit &pointerEventInit, |
43 const WebPointerProperties &pointerProperties) | 50 const WebPointerProperties &pointerProperties) |
44 { | 51 { |
45 const WebPointerProperties::PointerType pointerType = pointerProperties.poin
terType; | 52 const WebPointerProperties::PointerType pointerType = pointerProperties.poin
terType; |
46 MappedId pointerId = add(PointerEventManager::IncomingId(toInt(pointerType),
pointerProperties.id)); | 53 MappedId pointerId = add(PointerEventManager::IncomingId(toInt(pointerType),
pointerProperties.id)); |
47 pointerEventInit.setPointerId(pointerId); | 54 pointerEventInit.setPointerId(pointerId); |
48 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); | 55 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); |
49 pointerEventInit.setIsPrimary(isPrimary(pointerId)); | 56 pointerEventInit.setIsPrimary(isPrimary(pointerId)); |
50 } | 57 } |
51 | 58 |
52 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventManager::create(const AtomicStr
ing& type, | 59 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventManager::create(const AtomicStr
ing& type, |
53 const PlatformMouseEvent& mouseEvent, | 60 const PlatformMouseEvent& mouseEvent, |
54 PassRefPtrWillBeRawPtr<Node> relatedTarget, | 61 PassRefPtrWillBeRawPtr<Node> relatedTarget, |
55 PassRefPtrWillBeRawPtr<AbstractView> view) | 62 PassRefPtrWillBeRawPtr<AbstractView> view) |
56 { | 63 { |
57 PointerEventInit pointerEventInit; | 64 PointerEventInit pointerEventInit; |
58 | 65 |
59 setIdAndType(pointerEventInit, mouseEvent.pointerProperties()); | 66 setIdAndType(pointerEventInit, mouseEvent.pointerProperties()); |
60 | 67 |
61 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); | 68 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); |
62 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); | 69 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); |
63 pointerEventInit.setClientX(mouseEvent.position().x()); | 70 pointerEventInit.setClientX(mouseEvent.position().x()); |
64 pointerEventInit.setClientY(mouseEvent.position().y()); | 71 pointerEventInit.setClientY(mouseEvent.position().y()); |
65 | 72 |
66 pointerEventInit.setButton(mouseEvent.button()); | 73 pointerEventInit.setButton(mouseEvent.button()); |
67 pointerEventInit.setButtons(MouseEvent::platformModifiersToButtons(mouseEven
t.modifiers())); | 74 pointerEventInit.setButtons(MouseEvent::platformModifiersToButtons(mouseEven
t.modifiers())); |
| 75 pointerEventInit.setPressure(getPointerEventPressure( |
| 76 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); |
68 | 77 |
69 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.m
odifiers()); | 78 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.m
odifiers()); |
70 | 79 |
71 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter | 80 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter |
72 && type != EventTypeNames::pointerleave); | 81 && type != EventTypeNames::pointerleave); |
73 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter | 82 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter |
74 && type != EventTypeNames::pointerleave && type != EventTypeNames::point
ercancel); | 83 && type != EventTypeNames::pointerleave && type != EventTypeNames::point
ercancel); |
75 | 84 |
76 pointerEventInit.setView(view); | 85 pointerEventInit.setView(view); |
77 if (relatedTarget) | 86 if (relatedTarget) |
(...skipping 13 matching lines...) Expand all Loading... |
91 || pointState == PlatformTouchPoint::TouchCancelled; | 100 || pointState == PlatformTouchPoint::TouchCancelled; |
92 | 101 |
93 bool isEnterOrLeave = false; | 102 bool isEnterOrLeave = false; |
94 | 103 |
95 PointerEventInit pointerEventInit; | 104 PointerEventInit pointerEventInit; |
96 | 105 |
97 setIdAndType(pointerEventInit, touchPoint.pointerProperties()); | 106 setIdAndType(pointerEventInit, touchPoint.pointerProperties()); |
98 | 107 |
99 pointerEventInit.setWidth(width); | 108 pointerEventInit.setWidth(width); |
100 pointerEventInit.setHeight(height); | 109 pointerEventInit.setHeight(height); |
101 pointerEventInit.setPressure(touchPoint.force()); | |
102 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); | 110 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); |
103 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); | 111 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); |
104 pointerEventInit.setScreenX(touchPoint.screenPos().x()); | 112 pointerEventInit.setScreenX(touchPoint.screenPos().x()); |
105 pointerEventInit.setScreenY(touchPoint.screenPos().y()); | 113 pointerEventInit.setScreenY(touchPoint.screenPos().y()); |
106 pointerEventInit.setClientX(clientX); | 114 pointerEventInit.setClientX(clientX); |
107 pointerEventInit.setClientY(clientY); | 115 pointerEventInit.setClientY(clientY); |
108 pointerEventInit.setButton(0); | 116 pointerEventInit.setButton(0); |
109 pointerEventInit.setButtons(pointerReleasedOrCancelled ? 0 : 1); | 117 pointerEventInit.setButtons(pointerReleasedOrCancelled ? 0 : 1); |
| 118 pointerEventInit.setPressure(getPointerEventPressure( |
| 119 touchPoint.force(), pointerEventInit.buttons())); |
110 | 120 |
111 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); | 121 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); |
112 | 122 |
113 pointerEventInit.setBubbles(!isEnterOrLeave); | 123 pointerEventInit.setBubbles(!isEnterOrLeave); |
114 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc
hPoint::TouchCancelled); | 124 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc
hPoint::TouchCancelled); |
115 | 125 |
116 return PointerEvent::create(type, pointerEventInit); | 126 return PointerEvent::create(type, pointerEventInit); |
117 } | 127 } |
118 | 128 |
119 | 129 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (!m_idReverseMapping.contains(mappedId)) | 206 if (!m_idReverseMapping.contains(mappedId)) |
197 return false; | 207 return false; |
198 | 208 |
199 IncomingId p = m_idReverseMapping.get(mappedId); | 209 IncomingId p = m_idReverseMapping.get(mappedId); |
200 int type = p.first; | 210 int type = p.first; |
201 return m_primaryId[type] == mappedId; | 211 return m_primaryId[type] == mappedId; |
202 } | 212 } |
203 | 213 |
204 | 214 |
205 } // namespace blink | 215 } // namespace blink |
OLD | NEW |