tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TimelineManager.h (2529B)


      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 #ifndef mozilla_TimelineManager_h
      7 #define mozilla_TimelineManager_h
      8 
      9 #include "mozilla/Assertions.h"
     10 #include "mozilla/LinkedList.h"
     11 #include "mozilla/TimelineCollection.h"
     12 #include "nsStyleAutoArray.h"
     13 
     14 class nsPresContext;
     15 
     16 namespace mozilla {
     17 class ComputedStyle;
     18 struct PseudoStyleRequest;
     19 
     20 namespace dom {
     21 class Element;
     22 class ScrollTimeline;
     23 class ViewTimeline;
     24 }  // namespace dom
     25 
     26 class TimelineManager {
     27 public:
     28  explicit TimelineManager(nsPresContext* aPresContext)
     29      : mPresContext(aPresContext) {}
     30 
     31  ~TimelineManager() {
     32    MOZ_ASSERT(!mPresContext, "Disconnect should have been called");
     33  }
     34 
     35  void Disconnect() {
     36    while (auto* head = mScrollTimelineCollections.getFirst()) {
     37      head->Destroy();
     38    }
     39    while (auto* head = mViewTimelineCollections.getFirst()) {
     40      head->Destroy();
     41    }
     42 
     43    mPresContext = nullptr;
     44  }
     45 
     46  enum class ProgressTimelineType : uint8_t {
     47    Scroll,
     48    View,
     49  };
     50  void UpdateTimelines(dom::Element* aElement,
     51                       const PseudoStyleRequest& aPseudoRequest,
     52                       const ComputedStyle* aComputedStyle,
     53                       ProgressTimelineType aType);
     54 
     55 private:
     56  template <typename StyleType, typename TimelineType>
     57  void DoUpdateTimelines(nsPresContext* aPresContext, dom::Element* aElement,
     58                         const PseudoStyleRequest& aPseudoRequest,
     59                         const nsStyleAutoArray<StyleType>& aStyleTimelines,
     60                         size_t aTimelineCount);
     61 
     62  template <typename T>
     63  void AddTimelineCollection(TimelineCollection<T>* aCollection);
     64 
     65  LinkedList<TimelineCollection<dom::ScrollTimeline>>
     66      mScrollTimelineCollections;
     67  LinkedList<TimelineCollection<dom::ViewTimeline>> mViewTimelineCollections;
     68  nsPresContext* mPresContext;
     69 };
     70 
     71 template <>
     72 inline void TimelineManager::AddTimelineCollection(
     73    TimelineCollection<dom::ScrollTimeline>* aCollection) {
     74  mScrollTimelineCollections.insertBack(aCollection);
     75 }
     76 
     77 template <>
     78 inline void TimelineManager::AddTimelineCollection(
     79    TimelineCollection<dom::ViewTimeline>* aCollection) {
     80  mViewTimelineCollections.insertBack(aCollection);
     81 }
     82 
     83 }  // namespace mozilla
     84 
     85 #endif  // mozilla_TimelineManager_h