PerformanceInteractionMetrics.h (2988B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_PerformanceInteractionMetrics_h__ 8 #define mozilla_dom_PerformanceInteractionMetrics_h__ 9 10 #include "PerformanceEventTiming.h" 11 #include "nsHashtablesFwd.h" 12 13 namespace mozilla::dom { 14 15 class PerformanceInteractionMetrics final { 16 public: 17 PerformanceInteractionMetrics(); 18 19 PerformanceInteractionMetrics(const PerformanceInteractionMetrics& aCopy) = 20 delete; 21 PerformanceInteractionMetrics& operator=( 22 const PerformanceInteractionMetrics& aCopy) = delete; 23 24 Maybe<uint64_t> ComputeInteractionId(PerformanceEventTiming* aEventTiming, 25 const WidgetEvent* aEvent); 26 27 nsTHashMap<uint32_t, RefPtr<PerformanceEventTiming>>& PendingKeyDowns() { 28 return mPendingKeyDowns; 29 } 30 nsTHashMap<uint32_t, RefPtr<PerformanceEventTiming>>& PendingPointerDowns() { 31 return mPendingPointerDowns; 32 } 33 34 uint64_t InteractionCount() { return mInteractionCount; } 35 36 uint64_t IncreaseInteractionValueAndCount(); 37 38 virtual ~PerformanceInteractionMetrics() = default; 39 40 private: 41 // A map of integers to PerformanceEventTimings which is initially empty. 42 // https://w3c.github.io/event-timing/#pending-key-downs 43 nsTHashMap<uint32_t, RefPtr<PerformanceEventTiming>> mPendingKeyDowns; 44 45 // A map of integers to PerformanceEventTimings which is initially empty. 46 // https://w3c.github.io/event-timing/#pending-pointer-downs 47 nsTHashMap<uint32_t, RefPtr<PerformanceEventTiming>> mPendingPointerDowns; 48 49 // https://w3c.github.io/event-timing/#pointer-interaction-value-map 50 nsTHashMap<uint32_t, uint32_t> mPointerInteractionValueMap; 51 52 // An integer which counts the total number of distinct user interactions, 53 // for which there was a unique interactionId computed via computing 54 // interactionId. 55 // https://w3c.github.io/event-timing/#window-interactioncount 56 uint64_t mInteractionCount = 0; 57 58 uint64_t mCurrentInteractionValue; 59 60 Maybe<uint64_t> mLastKeydownInteractionValue; 61 62 bool mContextMenuTriggered = false; 63 }; 64 65 inline void ImplCycleCollectionTraverse( 66 nsCycleCollectionTraversalCallback& aCallback, 67 PerformanceInteractionMetrics& aMetrics, const char* aName, 68 uint32_t aFlags = 0) { 69 ImplCycleCollectionTraverse(aCallback, aMetrics.PendingKeyDowns(), aName, 70 aFlags); 71 ImplCycleCollectionTraverse(aCallback, aMetrics.PendingPointerDowns(), aName, 72 aFlags); 73 } 74 75 inline void ImplCycleCollectionUnlink(PerformanceInteractionMetrics& aMetrics) { 76 aMetrics.PendingKeyDowns().Clear(); 77 aMetrics.PendingPointerDowns().Clear(); 78 } 79 80 } // namespace mozilla::dom 81 82 #endif // mozilla_dom_PerformanceInteractionMetrics_h__