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

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: Incremental patch on crrev.com/2289273002 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
« no previous file with comments | « third_party/WebKit/Source/core/events/MouseEvent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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): Fix when the spec starts supporting hovering erasers.
25 return "pen"; 26 return "pen";
26 case WebPointerProperties::PointerType::Mouse: 27 case WebPointerProperties::PointerType::Mouse:
27 return "mouse"; 28 return "mouse";
28 } 29 }
29 NOTREACHED(); 30 NOTREACHED();
30 return ""; 31 return "";
31 } 32 }
32 33
33 const AtomicString& pointerEventNameForMouseEventName( 34 const AtomicString& pointerEventNameForMouseEventName(
34 const AtomicString& mouseEventName) 35 const AtomicString& mouseEventName)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 } // namespace 73 } // namespace
73 74
74 const int PointerEventFactory::s_invalidId = 0; 75 const int PointerEventFactory::s_invalidId = 0;
75 76
76 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. 77 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
77 const int PointerEventFactory::s_mouseId = 1; 78 const int PointerEventFactory::s_mouseId = 1;
78 79
79 float getPointerEventPressure(float force, int buttons) 80 float getPointerEventPressure(float force, int buttons)
80 { 81 {
81 if (std::isnan(force)) 82 if (std::isnan(force)) {
82 return buttons ? 0.5 : 0; 83 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
84 return (buttons & ~static_cast<unsigned>(MouseEvent::Buttons::Eraser)) ? 0.5 : 0;
85 }
83 return force; 86 return force;
84 } 87 }
85 88
86 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit, 89 void PointerEventFactory::setIdTypeButtons(PointerEventInit& pointerEventInit,
87 const WebPointerProperties& pointerProperties, unsigned buttons) 90 const WebPointerProperties& pointerProperties, unsigned buttons)
88 { 91 {
89 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType; 92 const WebPointerProperties::PointerType pointerType = pointerProperties.poin terType;
90 const IncomingId incomingId(pointerType, pointerProperties.id); 93 const IncomingId incomingId(pointerType, pointerProperties.id);
91 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); 94 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0);
92 95
96 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in
97 // active buttons state w/o even considering the eraser button.
98 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
99 if (pointerType == WebPointerProperties::PointerType::Eraser && buttons != 0 )
Navid Zolghadr 2016/08/31 20:01:16 I wonder if we can just do this when pointerType i
mustaq 2016/08/31 20:29:37 I don't like this for two reasons: [A] That would
100 buttons |= static_cast<unsigned>(MouseEvent::Buttons::Eraser);
93 pointerEventInit.setButtons(buttons); 101 pointerEventInit.setButtons(buttons);
102
94 pointerEventInit.setPointerId(pointerId); 103 pointerEventInit.setPointerId(pointerId);
95 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType)); 104 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe rType));
96 pointerEventInit.setIsPrimary(isPrimary(pointerId)); 105 pointerEventInit.setIsPrimary(isPrimary(pointerId));
97 } 106 }
98 107
99 void PointerEventFactory::setBubblesAndCancelable( 108 void PointerEventFactory::setBubblesAndCancelable(
100 PointerEventInit& pointerEventInit, const AtomicString& type) 109 PointerEventInit& pointerEventInit, const AtomicString& type)
101 { 110 {
102 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 111 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
103 && type != EventTypeNames::pointerleave); 112 && type != EventTypeNames::pointerleave);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (properties.pointerType 404 if (properties.pointerType
396 == WebPointerProperties::PointerType::Mouse) 405 == WebPointerProperties::PointerType::Mouse)
397 return PointerEventFactory::s_mouseId; 406 return PointerEventFactory::s_mouseId;
398 IncomingId id(properties.pointerType, properties.id); 407 IncomingId id(properties.pointerType, properties.id);
399 if (m_pointerIncomingIdMapping.contains(id)) 408 if (m_pointerIncomingIdMapping.contains(id))
400 return m_pointerIncomingIdMapping.get(id); 409 return m_pointerIncomingIdMapping.get(id);
401 return PointerEventFactory::s_invalidId; 410 return PointerEventFactory::s_invalidId;
402 } 411 }
403 412
404 } // namespace blink 413 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/MouseEvent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698