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

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

Issue 2867093003: Do not increase the pointer id when type is eraser (Closed)
Patch Set: eraser id Created 3 years, 7 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) { 14 inline int ToInt(WebPointerProperties::PointerType t) {
15 return static_cast<int>(t); 15 return static_cast<int>(t);
16 } 16 }
17 17
18 const char* PointerTypeNameForWebPointPointerType( 18 const char* PointerTypeNameForWebPointPointerType(
19 WebPointerProperties::PointerType type) { 19 WebPointerProperties::PointerType type) {
20 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
20 switch (type) { 21 switch (type) {
21 case WebPointerProperties::PointerType::kUnknown: 22 case WebPointerProperties::PointerType::kUnknown:
22 return ""; 23 return "";
23 case WebPointerProperties::PointerType::kTouch: 24 case WebPointerProperties::PointerType::kTouch:
24 return "touch"; 25 return "touch";
25 case WebPointerProperties::PointerType::kPen: 26 case WebPointerProperties::PointerType::kPen:
26 case WebPointerProperties::PointerType::kEraser:
27 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
28 return "pen"; 27 return "pen";
29 case WebPointerProperties::PointerType::kMouse: 28 case WebPointerProperties::PointerType::kMouse:
30 return "mouse"; 29 return "mouse";
30 default:
31 NOTREACHED();
32 return "";
31 } 33 }
32 NOTREACHED();
33 return "";
34 } 34 }
35 35
36 const AtomicString& PointerEventNameForMouseEventName( 36 const AtomicString& PointerEventNameForMouseEventName(
37 const AtomicString& mouse_event_name) { 37 const AtomicString& mouse_event_name) {
38 #define RETURN_CORRESPONDING_PE_NAME(eventSuffix) \ 38 #define RETURN_CORRESPONDING_PE_NAME(eventSuffix) \
39 if (mouse_event_name == EventTypeNames::mouse##eventSuffix) { \ 39 if (mouse_event_name == EventTypeNames::mouse##eventSuffix) { \
40 return EventTypeNames::pointer##eventSuffix; \ 40 return EventTypeNames::pointer##eventSuffix; \
41 } 41 }
42 42
43 RETURN_CORRESPONDING_PE_NAME(down); 43 RETURN_CORRESPONDING_PE_NAME(down);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 const int PointerEventFactory::kInvalidId = 0; 182 const int PointerEventFactory::kInvalidId = 0;
183 183
184 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. 184 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
185 const int PointerEventFactory::kMouseId = 1; 185 const int PointerEventFactory::kMouseId = 1;
186 186
187 void PointerEventFactory::SetIdTypeButtons( 187 void PointerEventFactory::SetIdTypeButtons(
188 PointerEventInit& pointer_event_init, 188 PointerEventInit& pointer_event_init,
189 const WebPointerProperties& pointer_properties, 189 const WebPointerProperties& pointer_properties,
190 unsigned buttons) { 190 unsigned buttons) {
191 const WebPointerProperties::PointerType pointer_type = 191 WebPointerProperties::PointerType pointer_type =
192 pointer_properties.pointer_type; 192 pointer_properties.pointer_type;
193 const IncomingId incoming_id(pointer_type, pointer_properties.id);
194 int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0);
195
196 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in 193 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in
197 // active buttons state w/o even considering the eraser button. 194 // active buttons state w/o even considering the eraser button.
198 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. 195 // TODO(mustaq): Fix when the spec starts supporting hovering erasers.
199 if (pointer_type == WebPointerProperties::PointerType::kEraser && 196 if (pointer_type == WebPointerProperties::PointerType::kEraser) {
200 buttons != 0) { 197 if (buttons != 0) {
201 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser); 198 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser);
202 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft); 199 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft);
200 }
201 pointer_type = WebPointerProperties::PointerType::kPen;
203 } 202 }
204 pointer_event_init.setButtons(buttons); 203 pointer_event_init.setButtons(buttons);
205 204
205 const IncomingId incoming_id(pointer_type, pointer_properties.id);
206 int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0);
206 pointer_event_init.setPointerId(pointer_id); 207 pointer_event_init.setPointerId(pointer_id);
207 pointer_event_init.setPointerType( 208 pointer_event_init.setPointerType(
208 PointerTypeNameForWebPointPointerType(pointer_type)); 209 PointerTypeNameForWebPointPointerType(pointer_type));
209 pointer_event_init.setIsPrimary(IsPrimary(pointer_id)); 210 pointer_event_init.setIsPrimary(IsPrimary(pointer_id));
210 } 211 }
211 212
212 void PointerEventFactory::SetEventSpecificFields( 213 void PointerEventFactory::SetEventSpecificFields(
213 PointerEventInit& pointer_event_init, 214 PointerEventInit& pointer_event_init,
214 const AtomicString& type) { 215 const AtomicString& type) {
215 pointer_event_init.setBubbles(type != EventTypeNames::pointerenter && 216 pointer_event_init.setBubbles(type != EventTypeNames::pointerenter &&
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 IncomingId p = pointer_id_mapping_.at(mapped_id).incoming_id; 509 IncomingId p = pointer_id_mapping_.at(mapped_id).incoming_id;
509 int type_int = p.PointerTypeInt(); 510 int type_int = p.PointerTypeInt();
510 pointer_id_mapping_.erase(mapped_id); 511 pointer_id_mapping_.erase(mapped_id);
511 pointer_incoming_id_mapping_.erase(p); 512 pointer_incoming_id_mapping_.erase(p);
512 if (primary_id_[type_int] == mapped_id) 513 if (primary_id_[type_int] == mapped_id)
513 primary_id_[type_int] = PointerEventFactory::kInvalidId; 514 primary_id_[type_int] = PointerEventFactory::kInvalidId;
514 id_count_[type_int]--; 515 id_count_[type_int]--;
515 return true; 516 return true;
516 } 517 }
517 518
519 // This function does not work with pointer type of eraser, because we save
520 // them as pen type in the pointer id map.
518 Vector<int> PointerEventFactory::GetPointerIdsOfType( 521 Vector<int> PointerEventFactory::GetPointerIdsOfType(
519 WebPointerProperties::PointerType pointer_type) const { 522 WebPointerProperties::PointerType pointer_type) const {
520 Vector<int> mapped_ids; 523 Vector<int> mapped_ids;
521 524
522 for (auto iter = pointer_id_mapping_.begin(); 525 for (auto iter = pointer_id_mapping_.begin();
523 iter != pointer_id_mapping_.end(); ++iter) { 526 iter != pointer_id_mapping_.end(); ++iter) {
524 int mapped_id = iter->key; 527 int mapped_id = iter->key;
525 if (iter->value.incoming_id.GetPointerType() == pointer_type) 528 if (iter->value.incoming_id.GetPointerType() == pointer_type)
526 mapped_ids.push_back(mapped_id); 529 mapped_ids.push_back(mapped_id);
527 } 530 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 const WebPointerProperties& properties) const { 562 const WebPointerProperties& properties) const {
560 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse) 563 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse)
561 return PointerEventFactory::kMouseId; 564 return PointerEventFactory::kMouseId;
562 IncomingId id(properties.pointer_type, properties.id); 565 IncomingId id(properties.pointer_type, properties.id);
563 if (pointer_incoming_id_mapping_.Contains(id)) 566 if (pointer_incoming_id_mapping_.Contains(id))
564 return pointer_incoming_id_mapping_.at(id); 567 return pointer_incoming_id_mapping_.at(id);
565 return PointerEventFactory::kInvalidId; 568 return PointerEventFactory::kInvalidId;
566 } 569 }
567 570
568 } // namespace blink 571 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698