ScrollingMetrics.h (1713B)
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_ScrollingMetrics_h 8 #define mozilla_dom_ScrollingMetrics_h 9 10 #include "Units.h" 11 #include "mozilla/MozPromise.h" 12 #include "mozilla/RefPtr.h" 13 #include "mozilla/StaticPtr.h" 14 15 namespace mozilla { 16 17 /** 18 * ScrollingMetrics records user-intiated scrolling interactions. These are 19 * aggregrated along with other user interactions (e.g. typing, view time), in 20 * the history metadata. 21 */ 22 class ScrollingMetrics { 23 public: 24 using ScrollingMetricsPromise = 25 MozPromise<std::tuple<uint32_t, uint32_t>, bool, true>; 26 27 static RefPtr<ScrollingMetricsPromise> CollectScrollingMetrics() { 28 return GetSingleton()->CollectScrollingMetricsInternal(); 29 } 30 31 // Return the tuple of <scrollingTimeInMilliseconds, 32 // ScrollingDistanceInPixels> 33 static std::tuple<uint32_t, uint32_t> CollectLocalScrollingMetrics() { 34 return GetSingleton()->CollectLocalScrollingMetricsInternal(); 35 } 36 37 // Report a new user-initiated scrolling interaction 38 static void OnScrollingInteraction(CSSCoord distanceScrolled); 39 40 static void OnScrollingInteractionEnded(); 41 42 private: 43 static ScrollingMetrics* GetSingleton(); 44 static StaticAutoPtr<ScrollingMetrics> sSingleton; 45 RefPtr<ScrollingMetricsPromise> CollectScrollingMetricsInternal(); 46 std::tuple<uint32_t, uint32_t> CollectLocalScrollingMetricsInternal(); 47 }; 48 49 } // namespace mozilla 50 51 #endif /* mozilla_dom_ScrollingMetrics_h */