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

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: Moved Buttons to WebPointerProperties, fixed button val, rebased. 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;
90 }
Navid Zolghadr 2016/09/02 16:04:31 nit: This bracket is not needed here.
mustaq 2016/09/02 16:12:27 Done.
85 return force; 91 return force;
86 } 92 }
87 93
88 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit, 94 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit,
89 const WebPointerProperties& pointerProperties, unsigned buttons) 95 const WebPointerProperties& pointerProperties, unsigned buttons)
90 { 96 {
91 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType; 97 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType;
92 const IncomingId incomingId(pointerType, pointerProperties.id); 98 const IncomingId incomingId(pointerType, pointerProperties.id);
93 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); 99 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0);
94 100
101 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in
102 // active buttons state w/o even considering the eraser button.
103 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
104 if (pointerType == WebPointerProperties::PointerType::Eraser && buttons != 0 ) {
105 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::Eraser);
106 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::Left);
Navid Zolghadr 2016/09/02 16:04:31 If I understood from your previous comment, you sa
mustaq 2016/09/02 16:12:27 Yes, well, mostly: - Windows: definitely. - Linux:
107 }
95 pointerEventInit.setButtons(buttons); 108 pointerEventInit.setButtons(buttons);
109
96 pointerEventInit.setPointerId(pointerId); 110 pointerEventInit.setPointerId(pointerId);
97 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType)); 111 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType));
98 pointerEventInit.setIsPrimary(isPrimary(pointerId)); 112 pointerEventInit.setIsPrimary(isPrimary(pointerId));
99 } 113 }
100 114
101 void PointerEventFactory::setBubblesAndCancelable( 115 void PointerEventFactory::setBubblesAndCancelable(
102 PointerEventInit& pointerEventInit, const AtomicString& type) 116 PointerEventInit& pointerEventInit, const AtomicString& type)
103 { 117 {
104 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 118 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
105 && type != EventTypeNames::pointerleave); 119 && type != EventTypeNames::pointerleave);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 float scaleFactor = 1 / frame->pageZoomFactor(); 152 float scaleFactor = 1 / frame->pageZoomFactor();
139 locationInFrameZoomed.scale(scaleFactor, scaleFactor); 153 locationInFrameZoomed.scale(scaleFactor, scaleFactor);
140 } 154 }
141 155
142 // Set up initial values for coordinates. 156 // Set up initial values for coordinates.
143 pointerEventInit.setClientX(locationInFrameZoomed.x()); 157 pointerEventInit.setClientX(locationInFrameZoomed.x());
144 pointerEventInit.setClientY(locationInFrameZoomed.y()); 158 pointerEventInit.setClientY(locationInFrameZoomed.y());
145 159
146 if (pointerEventName == EventTypeNames::pointerdown 160 if (pointerEventName == EventTypeNames::pointerdown
147 || pointerEventName == EventTypeNames::pointerup) { 161 || pointerEventName == EventTypeNames::pointerup) {
148 pointerEventInit.setButton(static_cast<int>(mouseEvent.pointerProperties ().button)); 162 WebPointerProperties::Button button = mouseEvent.pointerProperties().but ton;
163 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
164 if (mouseEvent.pointerProperties().pointerType == WebPointerProperties:: PointerType::Eraser
165 && button == WebPointerProperties::Button::Left)
166 button = WebPointerProperties::Button::Eraser;
167 pointerEventInit.setButton(static_cast<int>(button));
149 } else { 168 } else {
150 DCHECK(pointerEventName == EventTypeNames::pointermove); 169 DCHECK(pointerEventName == EventTypeNames::pointermove);
151 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton)); 170 pointerEventInit.setButton(static_cast<int>(WebPointerProperties::Button ::NoButton));
152 } 171 }
153 pointerEventInit.setPressure(getPointerEventPressure( 172 pointerEventInit.setPressure(getPointerEventPressure(
154 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); 173 mouseEvent.pointerProperties().force, pointerEventInit.buttons()));
155 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); 174 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
156 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); 175 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
157 176
158 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers()); 177 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.g etModifiers());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (properties.pointerType 416 if (properties.pointerType
398 == WebPointerProperties::PointerType::Mouse) 417 == WebPointerProperties::PointerType::Mouse)
399 return PointerEventFactory::s_mouseId; 418 return PointerEventFactory::s_mouseId;
400 IncomingId id(properties.pointerType, properties.id); 419 IncomingId id(properties.pointerType, properties.id);
401 if (m_pointerIncomingIdMapping.contains(id)) 420 if (m_pointerIncomingIdMapping.contains(id))
402 return m_pointerIncomingIdMapping.get(id); 421 return m_pointerIncomingIdMapping.get(id);
403 return PointerEventFactory::s_invalidId; 422 return PointerEventFactory::s_invalidId;
404 } 423 }
405 424
406 } // namespace blink 425 } // 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