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 { |
| 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 switch (type) { | 20 switch (type) { |
| 21 case WebPointerProperties::PointerType::kUnknown: | 21 case WebPointerProperties::PointerType::kUnknown: |
| 22 return ""; | 22 return ""; |
| 23 case WebPointerProperties::PointerType::kTouch: | 23 case WebPointerProperties::PointerType::kTouch: |
| 24 return "touch"; | 24 return "touch"; |
| 25 case WebPointerProperties::PointerType::kPen: | 25 case WebPointerProperties::PointerType::kPen: |
| 26 case WebPointerProperties::PointerType::kEraser: | 26 case WebPointerProperties::PointerType::kEraser: |
|
Navid Zolghadr
2017/05/09 20:58:46
nit: With the way you changed the caller of this f
lanwei
2017/05/10 17:50:42
Done.
| |
| 27 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. | 27 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. |
| 28 return "pen"; | 28 return "pen"; |
| 29 case WebPointerProperties::PointerType::kMouse: | 29 case WebPointerProperties::PointerType::kMouse: |
| 30 return "mouse"; | 30 return "mouse"; |
| 31 } | 31 } |
| 32 NOTREACHED(); | 32 NOTREACHED(); |
| 33 return ""; | 33 return ""; |
| 34 } | 34 } |
| 35 | 35 |
| 36 const AtomicString& PointerEventNameForMouseEventName( | 36 const AtomicString& PointerEventNameForMouseEventName( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 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); |
| 203 } | 200 } |
| 204 pointer_event_init.setButtons(buttons); | 201 pointer_event_init.setButtons(buttons); |
| 205 | 202 |
| 203 if (pointer_type == WebPointerProperties::PointerType::kEraser) | |
|
dtapuska
2017/05/09 20:53:08
Can this be rolled into the other pointer_type ==
lanwei
2017/05/10 17:50:42
Done.
| |
| 204 pointer_type = WebPointerProperties::PointerType::kPen; | |
| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 const WebPointerProperties& properties) const { | 560 const WebPointerProperties& properties) const { |
| 560 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse) | 561 if (properties.pointer_type == WebPointerProperties::PointerType::kMouse) |
| 561 return PointerEventFactory::kMouseId; | 562 return PointerEventFactory::kMouseId; |
| 562 IncomingId id(properties.pointer_type, properties.id); | 563 IncomingId id(properties.pointer_type, properties.id); |
| 563 if (pointer_incoming_id_mapping_.Contains(id)) | 564 if (pointer_incoming_id_mapping_.Contains(id)) |
| 564 return pointer_incoming_id_mapping_.at(id); | 565 return pointer_incoming_id_mapping_.at(id); |
| 565 return PointerEventFactory::kInvalidId; | 566 return PointerEventFactory::kInvalidId; |
| 566 } | 567 } |
| 567 | 568 |
| 568 } // namespace blink | 569 } // namespace blink |
| OLD | NEW |