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

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

Issue 2227563003: Refactoring button field and its type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac/win errors 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 buttonToButtons(WebPointerProperties::Button button)
bokan 2016/08/12 16:25:16 There's got to be a better name for this...:P Per
Navid Zolghadr 2016/08/12 17:14:37 Sure :)
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
54 } // namespace 71 } // namespace
55 72
56 const int PointerEventFactory::s_invalidId = 0; 73 const int PointerEventFactory::s_invalidId = 0;
57 74
58 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. 75 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
59 const int PointerEventFactory::s_mouseId = 1; 76 const int PointerEventFactory::s_mouseId = 1;
60 77
61 float getPointerEventPressure(float force, int buttons) 78 float getPointerEventPressure(float force, int buttons)
62 { 79 {
63 if (std::isnan(force)) 80 if (std::isnan(force))
(...skipping 20 matching lines...) Expand all
84 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 101 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
85 && type != EventTypeNames::pointerleave); 102 && type != EventTypeNames::pointerleave);
86 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter 103 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter
87 && type != EventTypeNames::pointerleave 104 && type != EventTypeNames::pointerleave
88 && type != EventTypeNames::pointercancel 105 && type != EventTypeNames::pointercancel
89 && type != EventTypeNames::gotpointercapture 106 && type != EventTypeNames::gotpointercapture
90 && type != EventTypeNames::lostpointercapture); 107 && type != EventTypeNames::lostpointercapture);
91 } 108 }
92 109
93 PointerEvent* PointerEventFactory::create( 110 PointerEvent* PointerEventFactory::create(
94 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, 111 const AtomicString& mouseEventName,
95 EventTarget* relatedTarget, 112 const PlatformMouseEvent& mouseEvent,
96 LocalDOMWindow* view) 113 LocalDOMWindow* view)
97 { 114 {
98 DCHECK(mouseEventName == EventTypeNames::mousemove 115 DCHECK(mouseEventName == EventTypeNames::mousemove
99 || mouseEventName == EventTypeNames::mousedown 116 || mouseEventName == EventTypeNames::mousedown
100 || mouseEventName == EventTypeNames::mouseup); 117 || mouseEventName == EventTypeNames::mouseup);
101 118
102 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name); 119 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name);
103 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers()); 120 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers());
104 PointerEventInit pointerEventInit; 121 PointerEventInit pointerEventInit;
105 122
(...skipping 12 matching lines...) Expand all
118 float scaleFactor = 1 / frame->pageZoomFactor(); 135 float scaleFactor = 1 / frame->pageZoomFactor();
119 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 136 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
120 } 137 }
121 138
122 // Set up initial values for coordinates. 139 // Set up initial values for coordinates.
123 pointerEventInit.setClientX(locationInFrameZoomed.x()); 140 pointerEventInit.setClientX(locationInFrameZoomed.x());
124 pointerEventInit.setClientY(locationInFrameZoomed.y()); 141 pointerEventInit.setClientY(locationInFrameZoomed.y());
125 142
126 if (pointerEventName == EventTypeNames::pointerdown 143 if (pointerEventName == EventTypeNames::pointerdown
127 || pointerEventName == EventTypeNames::pointerup) { 144 || pointerEventName == EventTypeNames::pointerup) {
128 pointerEventInit.setButton(mouseEvent.button()); 145 pointerEventInit.setButton(static_cast<int>(mouseEvent.pointerProperties ().button));
129 } else { // Only when pointerEventName == EventTypeNames::pointermove 146 } else { // Only when pointerEventName == EventTypeNames::pointermove
bokan 2016/08/12 16:25:16 Perhaps turn this comment into a DCHECK?
Navid Zolghadr 2016/08/12 17:14:37 Done.
130 pointerEventInit.setButton(NoButton); 147 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
131 } 148 }
132 pointerEventInit.setPressure(getPointerEventPressure( 149 pointerEventInit.setPressure(getPointerEventPressure(
133 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 150 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
134 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 151 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
135 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 152 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
136 153
137 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers()); 154 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers());
138 155
139 // Make sure chorded buttons fire pointermove instead of pointerup/down. 156 // Make sure chorded buttons fire pointermove instead of pointerup/down.
140 if ((pointerEventName == EventTypeNames::pointerdown 157 if ((pointerEventName == EventTypeNames::pointerdown
141 && (buttons & ~MouseEvent::buttonToButtons(mouseEvent.button())) != 0) 158 && (buttons & ~buttonToButtons(mouseEvent.pointerProperties().button)) ! = 0)
142 || (pointerEventName == EventTypeNames::pointerup && buttons != 0)) 159 || (pointerEventName == EventTypeNames::pointerup && buttons != 0))
143 pointerEventName = EventTypeNames::pointermove; 160 pointerEventName = EventTypeNames::pointermove;
144 161
145 162
146 pointerEventInit.setView(view); 163 pointerEventInit.setView(view);
147 if (relatedTarget)
148 pointerEventInit.setRelatedTarget(relatedTarget);
bokan 2016/08/12 16:25:16 Why is this no longer needed? Please elaborate in
Navid Zolghadr 2016/08/12 17:14:37 The related target for all pointerevents (similar
149 164
150 return PointerEvent::create(pointerEventName, pointerEventInit); 165 return PointerEvent::create(pointerEventName, pointerEventInit);
151 } 166 }
152 167
153 PointerEvent* PointerEventFactory::create(const AtomicString& type, 168 PointerEvent* PointerEventFactory::create(const AtomicString& type,
154 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, 169 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers,
155 const FloatSize& pointRadius, 170 const FloatSize& pointRadius,
156 const FloatPoint& clientPoint, 171 const FloatPoint& clientPoint,
157 DOMWindow* view) 172 DOMWindow* view)
158 { 173 {
(...skipping 12 matching lines...) Expand all
171 186
172 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), 187 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(),
173 pointerReleasedOrCancelled ? 0 : 1); 188 pointerReleasedOrCancelled ? 0 : 1);
174 189
175 pointerEventInit.setWidth(pointRadius.width()); 190 pointerEventInit.setWidth(pointRadius.width());
176 pointerEventInit.setHeight(pointRadius.height()); 191 pointerEventInit.setHeight(pointRadius.height());
177 pointerEventInit.setScreenX(touchPoint.screenPos().x()); 192 pointerEventInit.setScreenX(touchPoint.screenPos().x());
178 pointerEventInit.setScreenY(touchPoint.screenPos().y()); 193 pointerEventInit.setScreenY(touchPoint.screenPos().y());
179 pointerEventInit.setClientX(clientPoint.x()); 194 pointerEventInit.setClientX(clientPoint.x());
180 pointerEventInit.setClientY(clientPoint.y()); 195 pointerEventInit.setClientY(clientPoint.y());
181 pointerEventInit.setButton(pointerPressedOrReleased ? LeftButton: NoButton); 196 pointerEventInit.setButton(static_cast<int>(pointerPressedOrReleased ? WebPo interProperties::Button::Left : WebPointerProperties::Button::NoButton));
182 pointerEventInit.setPressure(getPointerEventPressure( 197 pointerEventInit.setPressure(getPointerEventPressure(
183 touchPoint.force(), pointerEventInit.buttons())); 198 touchPoint.force(), pointerEventInit.buttons()));
184 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); 199 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX);
185 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); 200 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY);
186 pointerEventInit.setView(view); 201 pointerEventInit.setView(view);
187 202
188 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); 203 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers);
189 204
190 pointerEventInit.setBubbles(!isEnterOrLeave); 205 pointerEventInit.setBubbles(!isEnterOrLeave);
191 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc hPoint::TouchCancelled); 206 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc hPoint::TouchCancelled);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (properties.pointerType 393 if (properties.pointerType
379 == WebPointerProperties::PointerType::Mouse) 394 == WebPointerProperties::PointerType::Mouse)
380 return PointerEventFactory::s_mouseId; 395 return PointerEventFactory::s_mouseId;
381 IncomingId id(properties.pointerType, properties.id); 396 IncomingId id(properties.pointerType, properties.id);
382 if (m_pointerIncomingIdMapping.contains(id)) 397 if (m_pointerIncomingIdMapping.contains(id))
383 return m_pointerIncomingIdMapping.get(id); 398 return m_pointerIncomingIdMapping.get(id);
384 return PointerEventFactory::s_invalidId; 399 return PointerEventFactory::s_invalidId;
385 } 400 }
386 401
387 } // namespace blink 402 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698