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

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

Issue 2314093002: Revert of Make a pen in eraser mode visible thru PointerEvent.buttons (Closed)
Patch Set: Created 4 years, 3 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 {
11 11
12 namespace { 12 namespace {
13 13
14 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>( t); } 14 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>( t); }
15 15
16 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT ype type) 16 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT ype type)
17 { 17 {
18 switch (type) { 18 switch (type) {
19 case WebPointerProperties::PointerType::Unknown: 19 case WebPointerProperties::PointerType::Unknown:
20 return ""; 20 return "";
21 case WebPointerProperties::PointerType::Touch: 21 case WebPointerProperties::PointerType::Touch:
22 return "touch"; 22 return "touch";
23 case WebPointerProperties::PointerType::Pen: 23 case WebPointerProperties::PointerType::Pen:
24 case WebPointerProperties::PointerType::Eraser:
25 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
26 return "pen"; 24 return "pen";
27 case WebPointerProperties::PointerType::Mouse: 25 case WebPointerProperties::PointerType::Mouse:
28 return "mouse"; 26 return "mouse";
29 } 27 }
30 NOTREACHED(); 28 NOTREACHED();
31 return ""; 29 return "";
32 } 30 }
33 31
34 const AtomicString& pointerEventNameForMouseEventName( 32 const AtomicString& pointerEventNameForMouseEventName(
35 const AtomicString& mouseEventName) 33 const AtomicString& mouseEventName)
(...skipping 13 matching lines...) Expand all
49 47
50 #undef RETURN_CORRESPONDING_PE_NAME 48 #undef RETURN_CORRESPONDING_PE_NAME
51 49
52 NOTREACHED(); 50 NOTREACHED();
53 return emptyAtom; 51 return emptyAtom;
54 } 52 }
55 53
56 54
57 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button) 55 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button)
58 { 56 {
59 #define CASE_BUTTON_TO_BUTTONS(enumLabel) \
60 case WebPointerProperties::Button::enumLabel:\
61 return static_cast<unsigned short>(WebPointerProperties::Buttons::enumLa bel)
62
63 switch (button) { 57 switch (button) {
64 CASE_BUTTON_TO_BUTTONS(NoButton); 58 case WebPointerProperties::Button::NoButton:
65 CASE_BUTTON_TO_BUTTONS(Left); 59 return static_cast<unsigned short>(MouseEvent::Buttons::None);
66 CASE_BUTTON_TO_BUTTONS(Right); 60 case WebPointerProperties::Button::Left:
67 CASE_BUTTON_TO_BUTTONS(Middle); 61 return static_cast<unsigned short>(MouseEvent::Buttons::Left);
68 CASE_BUTTON_TO_BUTTONS(X1); 62 case WebPointerProperties::Button::Right:
69 CASE_BUTTON_TO_BUTTONS(X2); 63 return static_cast<unsigned short>(MouseEvent::Buttons::Right);
70 CASE_BUTTON_TO_BUTTONS(Eraser); 64 case WebPointerProperties::Button::Middle:
65 return static_cast<unsigned short>(MouseEvent::Buttons::Middle);
71 } 66 }
72
73 #undef CASE_BUTTON_TO_BUTTONS
74
75 NOTREACHED(); 67 NOTREACHED();
76 return 0; 68 return 0;
77 } 69 }
78 70
79 } // namespace 71 } // namespace
80 72
81 const int PointerEventFactory::s_invalidId = 0; 73 const int PointerEventFactory::s_invalidId = 0;
82 74
83 // 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.
84 const int PointerEventFactory::s_mouseId = 1; 76 const int PointerEventFactory::s_mouseId = 1;
85 77
86 float getPointerEventPressure(float force, int buttons) 78 float getPointerEventPressure(float force, int buttons)
87 { 79 {
88 if (std::isnan(force)) 80 if (std::isnan(force))
89 return buttons ? 0.5 : 0; 81 return buttons ? 0.5 : 0;
90 return force; 82 return force;
91 } 83 }
92 84
93 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit, 85 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit,
94 const WebPointerProperties& pointerProperties, unsigned buttons) 86 const WebPointerProperties& pointerProperties, unsigned buttons)
95 { 87 {
96 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType; 88 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType;
97 const IncomingId incomingId(pointerType, pointerProperties.id); 89 const IncomingId incomingId(pointerType, pointerProperties.id);
98 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); 90 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0);
99 91
100 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in
101 // active buttons state w/o even considering the eraser button.
102 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
103 if (pointerType == WebPointerProperties::PointerType::Eraser && buttons != 0 ) {
104 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::Eraser);
105 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::Left);
106 }
107 pointerEventInit.setButtons(buttons); 92 pointerEventInit.setButtons(buttons);
108
109 pointerEventInit.setPointerId(pointerId); 93 pointerEventInit.setPointerId(pointerId);
110 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType)); 94 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType));
111 pointerEventInit.setIsPrimary(isPrimary(pointerId)); 95 pointerEventInit.setIsPrimary(isPrimary(pointerId));
112 } 96 }
113 97
114 void PointerEventFactory::setBubblesAndCancelable( 98 void PointerEventFactory::setBubblesAndCancelable(
115 PointerEventInit& pointerEventInit, const AtomicString& type) 99 PointerEventInit& pointerEventInit, const AtomicString& type)
116 { 100 {
117 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 101 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
118 && type != EventTypeNames::pointerleave); 102 && type != EventTypeNames::pointerleave);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 float scaleFactor = 1 / frame->pageZoomFactor(); 135 float scaleFactor = 1 / frame->pageZoomFactor();
152 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 136 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
153 } 137 }
154 138
155 // Set up initial values for coordinates. 139 // Set up initial values for coordinates.
156 pointerEventInit.setClientX(locationInFrameZoomed.x()); 140 pointerEventInit.setClientX(locationInFrameZoomed.x());
157 pointerEventInit.setClientY(locationInFrameZoomed.y()); 141 pointerEventInit.setClientY(locationInFrameZoomed.y());
158 142
159 if (pointerEventName == EventTypeNames::pointerdown 143 if (pointerEventName == EventTypeNames::pointerdown
160 || pointerEventName == EventTypeNames::pointerup) { 144 || pointerEventName == EventTypeNames::pointerup) {
161 WebPointerProperties::Button button = mouseEvent.pointerProperties().but ton; 145 pointerEventInit.setButton(static_cast<int>(mouseEvent.pointerProperties ().button));
162 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
163 if (mouseEvent.pointerProperties().pointerType == WebPointerProperties:: PointerType::Eraser
164 && button == WebPointerProperties::Button::Left)
165 button = WebPointerProperties::Button::Eraser;
166 pointerEventInit.setButton(static_cast<int>(button));
167 } else { 146 } else {
168 DCHECK(pointerEventName == EventTypeNames::pointermove); 147 DCHECK(pointerEventName == EventTypeNames::pointermove);
169 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton)); 148 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
170 } 149 }
171 pointerEventInit.setPressure(getPointerEventPressure( 150 pointerEventInit.setPressure(getPointerEventPressure(
172 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 151 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
173 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 152 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
174 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 153 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
175 154
176 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers()); 155 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (properties.pointerType 394 if (properties.pointerType
416 == WebPointerProperties::PointerType::Mouse) 395 == WebPointerProperties::PointerType::Mouse)
417 return PointerEventFactory::s_mouseId; 396 return PointerEventFactory::s_mouseId;
418 IncomingId id(properties.pointerType, properties.id); 397 IncomingId id(properties.pointerType, properties.id);
419 if (m_pointerIncomingIdMapping.contains(id)) 398 if (m_pointerIncomingIdMapping.contains(id))
420 return m_pointerIncomingIdMapping.get(id); 399 return m_pointerIncomingIdMapping.get(id);
421 return PointerEventFactory::s_invalidId; 400 return PointerEventFactory::s_invalidId;
422 } 401 }
423 402
424 } // namespace blink 403 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/MouseEvent.cpp ('k') | third_party/WebKit/public/platform/WebPointerProperties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698