Index: third_party/WebKit/Source/core/events/PointerEventFactory.h |
diff --git a/third_party/WebKit/Source/core/events/PointerEventFactory.h b/third_party/WebKit/Source/core/events/PointerEventFactory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0106546425642c2ddf7969389f8eb93ecdc118f9 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/events/PointerEventFactory.h |
@@ -0,0 +1,77 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef PointerEventFactory_h |
+#define PointerEventFactory_h |
+ |
+#include "core/CoreExport.h" |
+#include "core/events/PointerEvent.h" |
+#include "public/platform/WebPointerProperties.h" |
+#include "wtf/Allocator.h" |
+#include "wtf/HashMap.h" |
+ |
+namespace blink { |
+ |
+// Helper class for tracking the pointer ids for each type of PointerEvents. |
+// Using id re-mapping at this layer, this class makes sure that regardless of |
+// the domain of the id (i.e. in touch or pen) the corresponding pointer event |
+// will have a unique id amongst all pointer events as per pointer events' |
+// specification. This class intended to behave the same as existing browsers as |
+// much as possible for compatibility reasons. Particularly it behaves very |
+// similar to MS Edge to have pointer event ids generated by mouse always equal |
+// 1 and those that are generated by touch and pen will have increasing ids from |
+// 2. |
+class CORE_EXPORT PointerEventFactory { |
+ DISALLOW_NEW(); |
+public: |
+ |
+ PointerEventFactory(); |
+ ~PointerEventFactory(); |
+ |
+ PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, |
+ const PlatformMouseEvent&, PassRefPtrWillBeRawPtr<Node> relatedTarget, |
+ PassRefPtrWillBeRawPtr<AbstractView>); |
+ |
+ PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, |
+ const PlatformTouchPoint&, PlatformEvent::Modifiers, |
+ const double width, const double height, |
+ const double clientX, const double clientY); |
+ |
+ PassRefPtrWillBeRawPtr<PointerEvent> createPointerCancel( |
+ const PlatformTouchPoint&); |
+ |
+ PassRefPtrWillBeRawPtr<PointerEvent> create( |
+ PassRefPtrWillBeRawPtr<PointerEvent>, |
+ const AtomicString& type, |
+ PassRefPtrWillBeRawPtr<EventTarget>); |
+ |
+ // Clear all the existing ids. |
+ void clear(); |
+ |
+ // When a pointerEvent with a particular id is removed that id is considered |
+ // free even though there might have been other PointerEvents that were |
+ // generated with the same id before. |
+ void remove(const PassRefPtrWillBeRawPtr<PointerEvent>); |
+ |
+private: |
+ typedef std::pair<int, int> IncomingId; |
+ typedef WTF::UnsignedWithZeroKeyHashTraits<int> UnsignedHash; |
+ |
+ int add(const IncomingId); |
+ bool isPrimary(const int) const; |
+ void setIdAndType(PointerEventInit &, const WebPointerProperties &); |
+ |
+ static const int s_invalidId; |
+ static const int s_mouseId; |
+ |
+ int m_currentId; |
+ HashMap<IncomingId, int, WTF::PairHash<int, int>, WTF::PairHashTraits<UnsignedHash, UnsignedHash>> m_idMapping; |
+ HashMap<int, IncomingId, WTF::IntHash<int>, UnsignedHash> m_idReverseMapping; |
+ int m_primaryId[static_cast<int>(WebPointerProperties::PointerType::LastEntry) + 1]; |
+ int m_idCount[static_cast<int>(WebPointerProperties::PointerType::LastEntry) + 1]; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // PointerEventFactory_h |