tor-browser

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

ViewTimeline.h (3598B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_ViewTimeline_h
      8 #define mozilla_dom_ViewTimeline_h
      9 
     10 #include "mozilla/dom/ScrollTimeline.h"
     11 
     12 namespace mozilla {
     13 class ScrollContainerFrame;
     14 }  // namespace mozilla
     15 
     16 namespace mozilla::dom {
     17 
     18 /*
     19 * A view progress timeline is a segment of a scroll progress timeline that are
     20 * scoped to the scroll positions in which any part of the associated element’s
     21 * principal box intersects its nearest ancestor scrollport. So ViewTimeline
     22 * is a special case of ScrollTimeline.
     23 */
     24 class ViewTimeline final : public ScrollTimeline {
     25  template <typename T, typename... Args>
     26  friend already_AddRefed<T> mozilla::MakeAndAddRef(Args&&... aArgs);
     27 
     28 public:
     29  NS_DECL_ISUPPORTS_INHERITED
     30  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ViewTimeline, ScrollTimeline)
     31 
     32  ViewTimeline() = delete;
     33 
     34  // Note: |aSubject| is used as the subject which specifies view-timeline-name
     35  // property, and we use this subject to look up its nearest scroll container.
     36  static already_AddRefed<ViewTimeline> MakeNamed(
     37      Document* aDocument, Element* aSubject,
     38      const PseudoStyleRequest& aPseudoRequest,
     39      const StyleViewTimeline& aStyleTimeline);
     40 
     41  static already_AddRefed<ViewTimeline> MakeAnonymous(
     42      Document* aDocument, const NonOwningAnimationTarget& aTarget,
     43      StyleScrollAxis aAxis, const StyleViewTimelineInset& aInset);
     44 
     45  JSObject* WrapObject(JSContext* aCx,
     46                       JS::Handle<JSObject*> aGivenProto) override {
     47    return nullptr;
     48  }
     49 
     50  bool IsViewTimeline() const override { return true; }
     51 
     52  void ReplacePropertiesWith(Element* aSubjectElement,
     53                             const PseudoStyleRequest& aPseudoRequest,
     54                             const StyleViewTimeline& aNew);
     55 
     56 private:
     57  ~ViewTimeline() = default;
     58  ViewTimeline(Document* aDocument, const Scroller& aScroller,
     59               StyleScrollAxis aAxis, Element* aSubject,
     60               PseudoStyleType aSubjectPseudoType,
     61               const StyleViewTimelineInset& aInset)
     62      : ScrollTimeline(aDocument, aScroller, aAxis),
     63        mSubject(aSubject),
     64        mSubjectPseudoType(aSubjectPseudoType),
     65        mInset(aInset) {}
     66 
     67  Maybe<ScrollOffsets> ComputeOffsets(
     68      const ScrollContainerFrame* aScrollContainerFrame,
     69      layers::ScrollDirection aOrientation) const override;
     70 
     71  ScrollOffsets ComputeInsets(const ScrollContainerFrame* aScrollContainerFrame,
     72                              layers::ScrollDirection aOrientation) const;
     73 
     74  // The subject element.
     75  // 1. For view(), the subject element is the animation target.
     76  // 2. For view-timeline property, the subject element is the element who
     77  //    defines this property.
     78  RefPtr<Element> mSubject;
     79  // FIXME: Bug 1928437. We have to update mSubjectPseudoType to use
     80  // PseudoStyleRequest.
     81  PseudoStyleType mSubjectPseudoType;
     82 
     83  // FIXME: Bug 1817073. view-timeline-inset is an animatable property. However,
     84  // the inset from view() is not animatable, so for named view timeline, this
     85  // value depends on the animation style. Therefore, we have to check its style
     86  // value when using it. For now, in order to simplify the implementation, we
     87  // make |mInset| be fixed.
     88  StyleViewTimelineInset mInset;
     89 };
     90 
     91 }  // namespace mozilla::dom
     92 
     93 #endif  // mozilla_dom_ViewTimeline_h