Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: third_party/WebKit/Source/core/events/PointerEventFactory.cpp

Issue 2245063006: Revert of Refactoring button field and its type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix patch apply Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 RETURN_CORRESPONDING_PE_NAME(out); 44 RETURN_CORRESPONDING_PE_NAME(out);
45 RETURN_CORRESPONDING_PE_NAME(over); 45 RETURN_CORRESPONDING_PE_NAME(over);
46 RETURN_CORRESPONDING_PE_NAME(up); 46 RETURN_CORRESPONDING_PE_NAME(up);
47 47
48 #undef RETURN_CORRESPONDING_PE_NAME 48 #undef RETURN_CORRESPONDING_PE_NAME
49 49
50 NOTREACHED(); 50 NOTREACHED();
51 return emptyAtom; 51 return emptyAtom;
52 } 52 }
53 53
54
55 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button)
56 {
57 switch (button) {
58 case WebPointerProperties::Button::NoButton:
59 return static_cast<unsigned short>(MouseEvent::Buttons::None);
60 case WebPointerProperties::Button::Left:
61 return static_cast<unsigned short>(MouseEvent::Buttons::Left);
62 case WebPointerProperties::Button::Right:
63 return static_cast<unsigned short>(MouseEvent::Buttons::Right);
64 case WebPointerProperties::Button::Middle:
65 return static_cast<unsigned short>(MouseEvent::Buttons::Middle);
66 }
67 NOTREACHED();
68 return 0;
69 }
70
71 } // namespace 54 } // namespace
72 55
73 const int PointerEventFactory::s_invalidId = 0; 56 const int PointerEventFactory::s_invalidId = 0;
74 57
75 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. 58 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
76 const int PointerEventFactory::s_mouseId = 1; 59 const int PointerEventFactory::s_mouseId = 1;
77 60
78 float getPointerEventPressure(float force, int buttons) 61 float getPointerEventPressure(float force, int buttons)
79 { 62 {
80 if (std::isnan(force)) 63 if (std::isnan(force))
(...skipping 20 matching lines...) Expand all
101 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 84 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
102 && type != EventTypeNames::pointerleave); 85 && type != EventTypeNames::pointerleave);
103 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter 86 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter
104 && type != EventTypeNames::pointerleave 87 && type != EventTypeNames::pointerleave
105 && type != EventTypeNames::pointercancel 88 && type != EventTypeNames::pointercancel
106 && type != EventTypeNames::gotpointercapture 89 && type != EventTypeNames::gotpointercapture
107 && type != EventTypeNames::lostpointercapture); 90 && type != EventTypeNames::lostpointercapture);
108 } 91 }
109 92
110 PointerEvent* PointerEventFactory::create( 93 PointerEvent* PointerEventFactory::create(
111 const AtomicString& mouseEventName, 94 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent,
112 const PlatformMouseEvent& mouseEvent, 95 EventTarget* relatedTarget,
113 LocalDOMWindow* view) 96 LocalDOMWindow* view)
114 { 97 {
115 DCHECK(mouseEventName == EventTypeNames::mousemove 98 DCHECK(mouseEventName == EventTypeNames::mousemove
116 || mouseEventName == EventTypeNames::mousedown 99 || mouseEventName == EventTypeNames::mousedown
117 || mouseEventName == EventTypeNames::mouseup); 100 || mouseEventName == EventTypeNames::mouseup);
118 101
119 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name); 102 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name);
120 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers()); 103 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers());
121 PointerEventInit pointerEventInit; 104 PointerEventInit pointerEventInit;
122 105
(...skipping 12 matching lines...) Expand all
135 float scaleFactor = 1 / frame->pageZoomFactor(); 118 float scaleFactor = 1 / frame->pageZoomFactor();
136 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 119 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
137 } 120 }
138 121
139 // Set up initial values for coordinates. 122 // Set up initial values for coordinates.
140 pointerEventInit.setClientX(locationInFrameZoomed.x()); 123 pointerEventInit.setClientX(locationInFrameZoomed.x());
141 pointerEventInit.setClientY(locationInFrameZoomed.y()); 124 pointerEventInit.setClientY(locationInFrameZoomed.y());
142 125
143 if (pointerEventName == EventTypeNames::pointerdown 126 if (pointerEventName == EventTypeNames::pointerdown
144 || pointerEventName == EventTypeNames::pointerup) { 127 || pointerEventName == EventTypeNames::pointerup) {
145 pointerEventInit.setButton(static_cast<int>(mouseEvent.pointerProperties ().button)); 128 pointerEventInit.setButton(mouseEvent.button());
146 } else { 129 } else { // Only when pointerEventName == EventTypeNames::pointermove
147 DCHECK(pointerEventName == EventTypeNames::pointermove); 130 pointerEventInit.setButton(NoButton);
148 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
149 } 131 }
150 pointerEventInit.setPressure(getPointerEventPressure( 132 pointerEventInit.setPressure(getPointerEventPressure(
151 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 133 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
152 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 134 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
153 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 135 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
154 136
155 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers()); 137 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers());
156 138
157 // Make sure chorded buttons fire pointermove instead of pointerup/down. 139 // Make sure chorded buttons fire pointermove instead of pointerup/down.
158 if ((pointerEventName == EventTypeNames::pointerdown 140 if ((pointerEventName == EventTypeNames::pointerdown
159 && (buttons & ~buttonToButtonsBitfield(mouseEvent.pointerProperties().bu tton)) != 0) 141 && (buttons & ~MouseEvent::buttonToButtons(mouseEvent.button())) != 0)
160 || (pointerEventName == EventTypeNames::pointerup && buttons != 0)) 142 || (pointerEventName == EventTypeNames::pointerup && buttons != 0))
161 pointerEventName = EventTypeNames::pointermove; 143 pointerEventName = EventTypeNames::pointermove;
162 144
163 145
164 pointerEventInit.setView(view); 146 pointerEventInit.setView(view);
147 if (relatedTarget)
148 pointerEventInit.setRelatedTarget(relatedTarget);
165 149
166 return PointerEvent::create(pointerEventName, pointerEventInit); 150 return PointerEvent::create(pointerEventName, pointerEventInit);
167 } 151 }
168 152
169 PointerEvent* PointerEventFactory::create(const AtomicString& type, 153 PointerEvent* PointerEventFactory::create(const AtomicString& type,
170 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, 154 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers,
171 const FloatSize& pointRadius, 155 const FloatSize& pointRadius,
172 const FloatPoint& clientPoint, 156 const FloatPoint& clientPoint,
173 DOMWindow* view) 157 DOMWindow* view)
174 { 158 {
(...skipping 12 matching lines...) Expand all
187 171
188 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), 172 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(),
189 pointerReleasedOrCancelled ? 0 : 1); 173 pointerReleasedOrCancelled ? 0 : 1);
190 174
191 pointerEventInit.setWidth(pointRadius.width()); 175 pointerEventInit.setWidth(pointRadius.width());
192 pointerEventInit.setHeight(pointRadius.height()); 176 pointerEventInit.setHeight(pointRadius.height());
193 pointerEventInit.setScreenX(touchPoint.screenPos().x()); 177 pointerEventInit.setScreenX(touchPoint.screenPos().x());
194 pointerEventInit.setScreenY(touchPoint.screenPos().y()); 178 pointerEventInit.setScreenY(touchPoint.screenPos().y());
195 pointerEventInit.setClientX(clientPoint.x()); 179 pointerEventInit.setClientX(clientPoint.x());
196 pointerEventInit.setClientY(clientPoint.y()); 180 pointerEventInit.setClientY(clientPoint.y());
197 pointerEventInit.setButton(static_cast<int>(pointerPressedOrReleased ? WebPo interProperties::Button::Left : WebPointerProperties::Button::NoButton)); 181 pointerEventInit.setButton(pointerPressedOrReleased ? LeftButton: NoButton);
198 pointerEventInit.setPressure(getPointerEventPressure( 182 pointerEventInit.setPressure(getPointerEventPressure(
199 touchPoint.force(), pointerEventInit.buttons())); 183 touchPoint.force(), pointerEventInit.buttons()));
200 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); 184 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX);
201 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); 185 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY);
202 pointerEventInit.setView(view); 186 pointerEventInit.setView(view);
203 187
204 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); 188 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers);
205 189
206 pointerEventInit.setBubbles(!isEnterOrLeave); 190 pointerEventInit.setBubbles(!isEnterOrLeave);
207 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc hPoint::TouchCancelled); 191 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc hPoint::TouchCancelled);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (properties.pointerType 378 if (properties.pointerType
395 == WebPointerProperties::PointerType::Mouse) 379 == WebPointerProperties::PointerType::Mouse)
396 return PointerEventFactory::s_mouseId; 380 return PointerEventFactory::s_mouseId;
397 IncomingId id(properties.pointerType, properties.id); 381 IncomingId id(properties.pointerType, properties.id);
398 if (m_pointerIncomingIdMapping.contains(id)) 382 if (m_pointerIncomingIdMapping.contains(id))
399 return m_pointerIncomingIdMapping.get(id); 383 return m_pointerIncomingIdMapping.get(id);
400 return PointerEventFactory::s_invalidId; 384 return PointerEventFactory::s_invalidId;
401 } 385 }
402 386
403 } // namespace blink 387 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698