Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PointerEventFactory_h | |
| 6 #define PointerEventFactory_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "core/events/PointerEvent.h" | |
| 10 #include "public/platform/WebPointerProperties.h" | |
| 11 #include "wtf/Allocator.h" | |
| 12 #include "wtf/HashMap.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 /** | |
| 17 Helper class for tracking the pointer ids for each type of PointerEvents. | |
| 18 Using id re-mapping at this layer, this class makes sure that regardless of th e | |
| 19 domain of the id (i.e. in touch or pen) the corresponding pointer event will h ave | |
| 20 a unique id amongst all pointer events as per pointer events' specification. | |
| 21 This class intended to behave the same as existing browsers as much as possibl e | |
| 22 for compatibility reasons. Particularly it behaves very similar to MS Edge to have | |
| 23 pointer event ids generated by mouse always equal 1 and those that are generat ed | |
| 24 by touch and pen will have increasing ids from 2. | |
| 25 */ | |
| 26 class CORE_EXPORT PointerEventFactory { | |
| 27 DISALLOW_NEW(); | |
| 28 public: | |
| 29 | |
| 30 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | |
| 31 const PlatformMouseEvent&, PassRefPtrWillBeRawPtr<Node> relatedTarget, | |
| 32 PassRefPtrWillBeRawPtr<AbstractView>); | |
| 33 | |
| 34 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | |
| 35 const PlatformTouchPoint&, PlatformEvent::Modifiers, | |
| 36 const double width, const double height, | |
| 37 const double clientX, const double clientY); | |
| 38 | |
| 39 PassRefPtrWillBeRawPtr<PointerEvent> createPointerCancel(const PlatformTouch Point&); | |
| 40 | |
| 41 PointerEventFactory(); | |
| 42 ~PointerEventFactory(); | |
| 43 | |
| 44 // Clear all the existing ids. | |
| 45 void clear(); | |
| 46 /* | |
| 47 * When a pointerEvent with a particular id is removed that id is considered | |
| 48 * free even though there might have been other PointerEvents that were | |
| 49 * generated with the same id before. | |
| 50 */ | |
| 51 void remove(const PassRefPtrWillBeRawPtr<PointerEvent>); | |
| 52 | |
| 53 private: | |
| 54 typedef long MappedId; | |
| 55 typedef std::pair<WebPointerProperties::PointerType, int> GeneratedPointer; | |
|
mustaq
2015/11/25 21:43:39
GeneratedPointer confused me several times here.
Navid Zolghadr
2015/11/25 22:22:59
Sure. I'll do that.
| |
| 56 | |
| 57 MappedId add(const GeneratedPointer); | |
| 58 bool isPrimary(const MappedId) const; | |
| 59 MappedId getPrimaryId(const WebPointerProperties::PointerType) const; | |
| 60 WebPointerProperties::PointerType getType(const MappedId) const; | |
| 61 | |
| 62 static const MappedId s_invalidId; | |
| 63 static const MappedId s_mouseId; | |
| 64 | |
| 65 PointerEventFactory::MappedId m_currentId; | |
| 66 HashMap<int, MappedId, WTF::IntHash<int>, WTF::UnsignedWithZeroKeyHashTraits <int>> m_ids[static_cast<int>(WebPointerProperties::PointerType::LastEntry) + 1] ; | |
| 67 HashMap<MappedId, GeneratedPointer, WTF::IntHash<MappedId>, WTF::UnsignedWit hZeroKeyHashTraits<MappedId>> m_reverseMapping; | |
| 68 MappedId m_primaryId[static_cast<int>(WebPointerProperties::PointerType::Las tEntry) + 1]; | |
| 69 }; | |
| 70 | |
| 71 } // namespace blink | |
| 72 | |
| 73 #endif // PointerEventFactory_h | |
| OLD | NEW |