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

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

Issue 2296303002: Make a pen in eraser mode visible thru PointerEvent.buttons (Closed)
Patch Set: nzolghadr's comments. 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: 24 case WebPointerProperties::PointerType::Eraser:
25 // TODO(mustaq): Continue eraser plumbing to web API. 25 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
26 // See crbug.com/642455
27 return "pen"; 26 return "pen";
28 case WebPointerProperties::PointerType::Mouse: 27 case WebPointerProperties::PointerType::Mouse:
29 return "mouse"; 28 return "mouse";
30 } 29 }
31 NOTREACHED(); 30 NOTREACHED();
32 return ""; 31 return "";
33 } 32 }
34 33
35 const AtomicString& pointerEventNameForMouseEventName( 34 const AtomicString& pointerEventNameForMouseEventName(
36 const AtomicString& mouseEventName) 35 const AtomicString& mouseEventName)
(...skipping 13 matching lines...) Expand all
50 49
51 #undef RETURN_CORRESPONDING_PE_NAME 50 #undef RETURN_CORRESPONDING_PE_NAME
52 51
53 NOTREACHED(); 52 NOTREACHED();
54 return emptyAtom; 53 return emptyAtom;
55 } 54 }
56 55
57 56
58 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button) 57 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button)
59 { 58 {
59 #define CASE_BUTTON_TO_BUTTONS(enumLabel) \
60 case WebPointerProperties::Button::enumLabel:\
61 return static_cast<unsigned short>(WebPointerProperties::Buttons::enumLa bel)
62
60 switch (button) { 63 switch (button) {
61 case WebPointerProperties::Button::NoButton: 64 CASE_BUTTON_TO_BUTTONS(NoButton);
62 return static_cast<unsigned short>(MouseEvent::Buttons::None); 65 CASE_BUTTON_TO_BUTTONS(Left);
63 case WebPointerProperties::Button::Left: 66 CASE_BUTTON_TO_BUTTONS(Right);
64 return static_cast<unsigned short>(MouseEvent::Buttons::Left); 67 CASE_BUTTON_TO_BUTTONS(Middle);
65 case WebPointerProperties::Button::Right: 68 CASE_BUTTON_TO_BUTTONS(X1);
66 return static_cast<unsigned short>(MouseEvent::Buttons::Right); 69 CASE_BUTTON_TO_BUTTONS(X2);
67 case WebPointerProperties::Button::Middle: 70 CASE_BUTTON_TO_BUTTONS(Eraser);
68 return static_cast<unsigned short>(MouseEvent::Buttons::Middle);
69 } 71 }
72
73 #undef CASE_BUTTON_TO_BUTTONS
74
70 NOTREACHED(); 75 NOTREACHED();
71 return 0; 76 return 0;
72 } 77 }
73 78
74 } // namespace 79 } // namespace
75 80
76 const int PointerEventFactory::s_invalidId = 0; 81 const int PointerEventFactory::s_invalidId = 0;
77 82
78 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. 83 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
79 const int PointerEventFactory::s_mouseId = 1; 84 const int PointerEventFactory::s_mouseId = 1;
80 85
81 float getPointerEventPressure(float force, int buttons) 86 float getPointerEventPressure(float force, int buttons)
82 { 87 {
83 if (std::isnan(force)) 88 if (std::isnan(force))
84 return buttons ? 0.5 : 0; 89 return buttons ? 0.5 : 0;
85 return force; 90 return force;
86 } 91 }
87 92
88 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit, 93 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit,
89 const WebPointerProperties& pointerProperties, unsigned buttons) 94 const WebPointerProperties& pointerProperties, unsigned buttons)
90 { 95 {
91 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType; 96 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType;
92 const IncomingId incomingId(pointerType, pointerProperties.id); 97 const IncomingId incomingId(pointerType, pointerProperties.id);
93 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); 98 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0);
94 99
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 }
95 pointerEventInit.setButtons(buttons); 107 pointerEventInit.setButtons(buttons);
108
96 pointerEventInit.setPointerId(pointerId); 109 pointerEventInit.setPointerId(pointerId);
97 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType)); 110 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType));
98 pointerEventInit.setIsPrimary(isPrimary(pointerId)); 111 pointerEventInit.setIsPrimary(isPrimary(pointerId));
99 } 112 }
100 113
101 void PointerEventFactory::setBubblesAndCancelable( 114 void PointerEventFactory::setBubblesAndCancelable(
102 PointerEventInit& pointerEventInit, const AtomicString& type) 115 PointerEventInit& pointerEventInit, const AtomicString& type)
103 { 116 {
104 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 117 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
105 && type != EventTypeNames::pointerleave); 118 && type != EventTypeNames::pointerleave);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 float scaleFactor = 1 / frame->pageZoomFactor(); 151 float scaleFactor = 1 / frame->pageZoomFactor();
139 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 152 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
140 } 153 }
141 154
142 // Set up initial values for coordinates. 155 // Set up initial values for coordinates.
143 pointerEventInit.setClientX(locationInFrameZoomed.x()); 156 pointerEventInit.setClientX(locationInFrameZoomed.x());
144 pointerEventInit.setClientY(locationInFrameZoomed.y()); 157 pointerEventInit.setClientY(locationInFrameZoomed.y());
145 158
146 if (pointerEventName == EventTypeNames::pointerdown 159 if (pointerEventName == EventTypeNames::pointerdown
147 || pointerEventName == EventTypeNames::pointerup) { 160 || pointerEventName == EventTypeNames::pointerup) {
148 pointerEventInit.setButton(static_cast<int>(mouseEvent.pointerProperties ().button)); 161 WebPointerProperties::Button button = mouseEvent.pointerProperties().but ton;
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));
149 } else { 167 } else {
150 DCHECK(pointerEventName == EventTypeNames::pointermove); 168 DCHECK(pointerEventName == EventTypeNames::pointermove);
151 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton)); 169 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
152 } 170 }
153 pointerEventInit.setPressure(getPointerEventPressure( 171 pointerEventInit.setPressure(getPointerEventPressure(
154 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 172 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
155 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 173 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
156 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 174 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
157 175
158 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers()); 176 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (properties.pointerType 415 if (properties.pointerType
398 == WebPointerProperties::PointerType::Mouse) 416 == WebPointerProperties::PointerType::Mouse)
399 return PointerEventFactory::s_mouseId; 417 return PointerEventFactory::s_mouseId;
400 IncomingId id(properties.pointerType, properties.id); 418 IncomingId id(properties.pointerType, properties.id);
401 if (m_pointerIncomingIdMapping.contains(id)) 419 if (m_pointerIncomingIdMapping.contains(id))
402 return m_pointerIncomingIdMapping.get(id); 420 return m_pointerIncomingIdMapping.get(id);
403 return PointerEventFactory::s_invalidId; 421 return PointerEventFactory::s_invalidId;
404 } 422 }
405 423
406 } // namespace blink 424 } // 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