tor-browser

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

TimelineCollection.cpp (2355B)


      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 #include "TimelineCollection.h"
      8 
      9 #include <type_traits>
     10 
     11 #include "mozilla/ElementAnimationData.h"
     12 #include "mozilla/dom/Element.h"
     13 #include "mozilla/dom/ScrollTimeline.h"
     14 #include "mozilla/dom/ViewTimeline.h"
     15 
     16 namespace mozilla {
     17 
     18 template <class TimelineType>
     19 TimelineCollection<TimelineType>::~TimelineCollection() {
     20  MOZ_COUNT_DTOR(TimelineCollection);
     21 
     22  // FIXME: Bug 1774060. We have to restyle the animations which use the
     23  // timelines associtated with this TimelineCollection.
     24 
     25  LinkedListElement<SelfType>::remove();
     26 }
     27 
     28 template <class TimelineType>
     29 void TimelineCollection<TimelineType>::Destroy() {
     30  auto* data = mElement.GetAnimationData();
     31  MOZ_ASSERT(data);
     32  // Copy the request because mPseudo may be deleted when clearing the
     33  // collection.
     34  const PseudoStyleRequest request = mPseudo;
     35  if constexpr (std::is_same_v<TimelineType, dom::ScrollTimeline>) {
     36    MOZ_ASSERT(data->GetScrollTimelineCollection(request) == this);
     37    data->ClearScrollTimelineCollectionFor(request);
     38  } else if constexpr (std::is_same_v<TimelineType, dom::ViewTimeline>) {
     39    MOZ_ASSERT(data->GetViewTimelineCollection(request) == this);
     40    data->ClearViewTimelineCollectionFor(request);
     41  } else {
     42    MOZ_ASSERT_UNREACHABLE("Unsupported TimelienType");
     43  }
     44 }
     45 
     46 template <class TimelineType>
     47 /* static */ TimelineCollection<TimelineType>*
     48 TimelineCollection<TimelineType>::Get(
     49    const dom::Element* aElement, const PseudoStyleRequest& aPseudoRequest) {
     50  MOZ_ASSERT(aElement);
     51  auto* data = aElement->GetAnimationData();
     52  if (!data) {
     53    return nullptr;
     54  }
     55 
     56  if constexpr (std::is_same_v<TimelineType, dom::ScrollTimeline>) {
     57    return data->GetScrollTimelineCollection(aPseudoRequest);
     58  }
     59 
     60  if constexpr (std::is_same_v<TimelineType, dom::ViewTimeline>) {
     61    return data->GetViewTimelineCollection(aPseudoRequest);
     62  }
     63 
     64  return nullptr;
     65 }
     66 
     67 // Explicit class instantiations
     68 template class TimelineCollection<dom::ScrollTimeline>;
     69 template class TimelineCollection<dom::ViewTimeline>;
     70 
     71 }  // namespace mozilla