Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 const WebPointerProperties::PointerType pointer_type = |
| 192 pointer_properties.pointer_type; | 192 pointer_properties.pointer_type; |
| 193 const IncomingId incoming_id(pointer_type, pointer_properties.id); | 193 const IncomingId incoming_id(pointer_type, pointer_properties.id); |
|
Navid Zolghadr
2017/05/09 15:00:38
How about this here?
const IncomingId incoming_id(
| |
| 194 int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0); | 194 int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0); |
| 195 | 195 |
| 196 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in | 196 // 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. | 197 // active buttons state w/o even considering the eraser button. |
| 198 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. | 198 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. |
| 199 if (pointer_type == WebPointerProperties::PointerType::kEraser && | 199 if (pointer_type == WebPointerProperties::PointerType::kEraser && |
| 200 buttons != 0) { | 200 buttons != 0) { |
| 201 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser); | 201 buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser); |
| 202 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft); | 202 buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft); |
| 203 } | 203 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 } | 476 } |
| 477 | 477 |
| 478 int PointerEventFactory::AddIdAndActiveButtons(const IncomingId p, | 478 int PointerEventFactory::AddIdAndActiveButtons(const IncomingId p, |
| 479 bool is_active_buttons) { | 479 bool is_active_buttons) { |
| 480 // Do not add extra mouse pointer as it was added in initialization | 480 // Do not add extra mouse pointer as it was added in initialization |
| 481 if (p.GetPointerType() == WebPointerProperties::PointerType::kMouse) { | 481 if (p.GetPointerType() == WebPointerProperties::PointerType::kMouse) { |
| 482 pointer_id_mapping_.Set(kMouseId, PointerAttributes(p, is_active_buttons)); | 482 pointer_id_mapping_.Set(kMouseId, PointerAttributes(p, is_active_buttons)); |
| 483 return kMouseId; | 483 return kMouseId; |
| 484 } | 484 } |
| 485 | 485 |
| 486 if (pointer_incoming_id_mapping_.Contains(p)) { | 486 IncomingId incoming_id = p; |
| 487 int mapped_id = pointer_incoming_id_mapping_.at(p); | 487 if (p.GetPointerType() == WebPointerProperties::PointerType::kEraser) { |
|
dtapuska
2017/05/09 13:24:45
Sorry this seems wrong to me. In that if we get an
| |
| 488 pointer_id_mapping_.Set(mapped_id, PointerAttributes(p, is_active_buttons)); | 488 const IncomingId pen_id = |
| 489 IncomingId(WebPointerProperties::PointerType::kPen, p.RawId()); | |
| 490 if (pointer_incoming_id_mapping_.Contains(pen_id)) | |
| 491 incoming_id = pen_id; | |
| 492 } | |
| 493 | |
| 494 if (pointer_incoming_id_mapping_.Contains(incoming_id)) { | |
| 495 int mapped_id = pointer_incoming_id_mapping_.at(incoming_id); | |
| 496 pointer_id_mapping_.Set(mapped_id, | |
| 497 PointerAttributes(incoming_id, is_active_buttons)); | |
| 489 return mapped_id; | 498 return mapped_id; |
| 490 } | 499 } |
| 491 int type_int = p.PointerTypeInt(); | 500 int type_int = incoming_id.PointerTypeInt(); |
| 492 // We do not handle the overflow of m_currentId as it should be very rare | 501 // We do not handle the overflow of m_currentId as it should be very rare |
| 493 int mapped_id = current_id_++; | 502 int mapped_id = current_id_++; |
| 494 if (!id_count_[type_int]) | 503 if (!id_count_[type_int]) |
| 495 primary_id_[type_int] = mapped_id; | 504 primary_id_[type_int] = mapped_id; |
| 496 id_count_[type_int]++; | 505 id_count_[type_int]++; |
| 497 pointer_incoming_id_mapping_.insert(p, mapped_id); | 506 pointer_incoming_id_mapping_.insert(incoming_id, mapped_id); |
| 498 pointer_id_mapping_.insert(mapped_id, | 507 pointer_id_mapping_.insert(mapped_id, |
| 499 PointerAttributes(p, is_active_buttons)); | 508 PointerAttributes(incoming_id, is_active_buttons)); |
| 500 return mapped_id; | 509 return mapped_id; |
| 501 } | 510 } |
| 502 | 511 |
| 503 bool PointerEventFactory::Remove(const int mapped_id) { | 512 bool PointerEventFactory::Remove(const int mapped_id) { |
| 504 // Do not remove mouse pointer id as it should always be there | 513 // Do not remove mouse pointer id as it should always be there |
| 505 if (mapped_id == kMouseId || !pointer_id_mapping_.Contains(mapped_id)) | 514 if (mapped_id == kMouseId || !pointer_id_mapping_.Contains(mapped_id)) |
| 506 return false; | 515 return false; |
| 507 | 516 |
| 508 IncomingId p = pointer_id_mapping_.at(mapped_id).incoming_id; | 517 IncomingId p = pointer_id_mapping_.at(mapped_id).incoming_id; |
| 509 int type_int = p.PointerTypeInt(); | 518 int type_int = p.PointerTypeInt(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 const WebPointerProperties& properties) const { | 568 const WebPointerProperties& properties) const { |
| 560 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse) | 569 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse) |
| 561 return PointerEventFactory::kMouseId; | 570 return PointerEventFactory::kMouseId; |
| 562 IncomingId id(properties.pointer_type, properties.id); | 571 IncomingId id(properties.pointer_type, properties.id); |
| 563 if (pointer_incoming_id_mapping_.Contains(id)) | 572 if (pointer_incoming_id_mapping_.Contains(id)) |
| 564 return pointer_incoming_id_mapping_.at(id); | 573 return pointer_incoming_id_mapping_.at(id); |
| 565 return PointerEventFactory::kInvalidId; | 574 return PointerEventFactory::kInvalidId; |
| 566 } | 575 } |
| 567 | 576 |
| 568 } // namespace blink | 577 } // namespace blink |
| OLD | NEW |