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

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

Issue 2313653004: 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.
24 return "pen"; 26 return "pen";
25 case WebPointerProperties::PointerType::Mouse: 27 case WebPointerProperties::PointerType::Mouse:
26 return "mouse"; 28 return "mouse";
27 } 29 }
28 NOTREACHED(); 30 NOTREACHED();
29 return ""; 31 return "";
30 } 32 }
31 33
32 const AtomicString& pointerEventNameForMouseEventName( 34 const AtomicString& pointerEventNameForMouseEventName(
33 const AtomicString& mouseEventName) 35 const AtomicString& mouseEventName)
(...skipping 13 matching lines...) Expand all
47 49
48 #undef RETURN_CORRESPONDING_PE_NAME 50 #undef RETURN_CORRESPONDING_PE_NAME
49 51
50 NOTREACHED(); 52 NOTREACHED();
51 return emptyAtom; 53 return emptyAtom;
52 } 54 }
53 55
54 56
55 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button) 57 unsigned short buttonToButtonsBitfield(WebPointerProperties::Button button)
56 { 58 {
59 #define CASE_BUTTON_TO_BUTTONS(enumLabel) \
60 case WebPointerProperties::Button::enumLabel:\
61 return static_cast<unsigned short>(WebPointerProperties::Buttons::enumLa bel)
62
57 switch (button) { 63 switch (button) {
58 case WebPointerProperties::Button::NoButton: 64 CASE_BUTTON_TO_BUTTONS(NoButton);
59 return static_cast<unsigned short>(MouseEvent::Buttons::None); 65 CASE_BUTTON_TO_BUTTONS(Left);
60 case WebPointerProperties::Button::Left: 66 CASE_BUTTON_TO_BUTTONS(Right);
61 return static_cast<unsigned short>(MouseEvent::Buttons::Left); 67 CASE_BUTTON_TO_BUTTONS(Middle);
62 case WebPointerProperties::Button::Right: 68 CASE_BUTTON_TO_BUTTONS(X1);
63 return static_cast<unsigned short>(MouseEvent::Buttons::Right); 69 CASE_BUTTON_TO_BUTTONS(X2);
64 case WebPointerProperties::Button::Middle: 70 CASE_BUTTON_TO_BUTTONS(Eraser);
65 return static_cast<unsigned short>(MouseEvent::Buttons::Middle);
66 } 71 }
72
73 #undef CASE_BUTTON_TO_BUTTONS
74
67 NOTREACHED(); 75 NOTREACHED();
68 return 0; 76 return 0;
69 } 77 }
70 78
71 } // namespace 79 } // namespace
72 80
73 const int PointerEventFactory::s_invalidId = 0; 81 const int PointerEventFactory::s_invalidId = 0;
74 82
75 // 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.
76 const int PointerEventFactory::s_mouseId = 1; 84 const int PointerEventFactory::s_mouseId = 1;
77 85
78 float getPointerEventPressure(float force, int buttons) 86 float getPointerEventPressure(float force, int buttons)
79 { 87 {
80 if (std::isnan(force)) 88 if (std::isnan(force))
81 return buttons ? 0.5 : 0; 89 return buttons ? 0.5 : 0;
82 return force; 90 return force;
83 } 91 }
84 92
85 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit, 93 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit,
86 const WebPointerProperties& pointerProperties, unsigned buttons) 94 const WebPointerProperties& pointerProperties, unsigned buttons)
87 { 95 {
88 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType; 96 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType;
89 const IncomingId incomingId(pointerType, pointerProperties.id); 97 const IncomingId incomingId(pointerType, pointerProperties.id);
90 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); 98 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0);
91 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 }
92 pointerEventInit.setButtons(buttons); 107 pointerEventInit.setButtons(buttons);
108
93 pointerEventInit.setPointerId(pointerId); 109 pointerEventInit.setPointerId(pointerId);
94 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType)); 110 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType));
95 pointerEventInit.setIsPrimary(isPrimary(pointerId)); 111 pointerEventInit.setIsPrimary(isPrimary(pointerId));
96 } 112 }
97 113
98 void PointerEventFactory::setBubblesAndCancelable( 114 void PointerEventFactory::setBubblesAndCancelable(
99 PointerEventInit& pointerEventInit, const AtomicString& type) 115 PointerEventInit& pointerEventInit, const AtomicString& type)
100 { 116 {
101 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 117 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
102 && type != EventTypeNames::pointerleave); 118 && type != EventTypeNames::pointerleave);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 float scaleFactor = 1 / frame->pageZoomFactor(); 151 float scaleFactor = 1 / frame->pageZoomFactor();
136 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 152 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
137 } 153 }
138 154
139 // Set up initial values for coordinates. 155 // Set up initial values for coordinates.
140 pointerEventInit.setClientX(locationInFrameZoomed.x()); 156 pointerEventInit.setClientX(locationInFrameZoomed.x());
141 pointerEventInit.setClientY(locationInFrameZoomed.y()); 157 pointerEventInit.setClientY(locationInFrameZoomed.y());
142 158
143 if (pointerEventName == EventTypeNames::pointerdown 159 if (pointerEventName == EventTypeNames::pointerdown
144 || pointerEventName == EventTypeNames::pointerup) { 160 || pointerEventName == EventTypeNames::pointerup) {
145 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));
146 } else { 167 } else {
147 DCHECK(pointerEventName == EventTypeNames::pointermove); 168 DCHECK(pointerEventName == EventTypeNames::pointermove);
148 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton)); 169 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
149 } 170 }
150 pointerEventInit.setPressure(getPointerEventPressure( 171 pointerEventInit.setPressure(getPointerEventPressure(
151 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 172 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
152 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 173 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
153 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 174 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
154 175
155 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
394 if (properties.pointerType 415 if (properties.pointerType
395 == WebPointerProperties::PointerType::Mouse) 416 == WebPointerProperties::PointerType::Mouse)
396 return PointerEventFactory::s_mouseId; 417 return PointerEventFactory::s_mouseId;
397 IncomingId id(properties.pointerType, properties.id); 418 IncomingId id(properties.pointerType, properties.id);
398 if (m_pointerIncomingIdMapping.contains(id)) 419 if (m_pointerIncomingIdMapping.contains(id))
399 return m_pointerIncomingIdMapping.get(id); 420 return m_pointerIncomingIdMapping.get(id);
400 return PointerEventFactory::s_invalidId; 421 return PointerEventFactory::s_invalidId;
401 } 422 }
402 423
403 } // 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