tor-browser

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

SampledAPZCState.h (3119B)


      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_layers_SampledAPZCState_h
      8 #define mozilla_layers_SampledAPZCState_h
      9 
     10 #include "FrameMetrics.h"
     11 #include "mozilla/Maybe.h"
     12 #include "mozilla/ScrollGeneration.h"
     13 #include "mozilla/layers/CompositorScrollUpdate.h"
     14 
     15 namespace mozilla {
     16 namespace layers {
     17 
     18 class SampledAPZCState {
     19 public:
     20  SampledAPZCState();
     21  explicit SampledAPZCState(const FrameMetrics& aMetrics);
     22  SampledAPZCState(const FrameMetrics& aMetrics,
     23                   Maybe<CompositionPayload>&& aPayload,
     24                   APZScrollGeneration aGeneration,
     25                   std::vector<CompositorScrollUpdate>&& aUpdates);
     26 
     27  bool operator==(const SampledAPZCState& aOther) const;
     28  bool operator!=(const SampledAPZCState& aOther) const;
     29 
     30  CSSRect GetLayoutViewport() const { return mLayoutViewport; }
     31  CSSPoint GetVisualScrollOffset() const { return mVisualScrollOffset; }
     32  CSSToParentLayerScale GetZoom() const { return mZoom; }
     33  Maybe<CompositionPayload> TakeScrollPayload();
     34  const APZScrollGeneration& Generation() const { return mGeneration; }
     35  const std::vector<CompositorScrollUpdate> Updates() const { return mUpdates; }
     36 
     37  void UpdateScrollProperties(const FrameMetrics& aMetrics);
     38  void UpdateScrollPropertiesWithRelativeDelta(const FrameMetrics& aMetrics,
     39                                               const CSSPoint& aRelativeDelta);
     40 
     41  void UpdateZoomProperties(const FrameMetrics& aMetrics);
     42 
     43  /**
     44   * Re-clamp mVisualScrollOffset to the scroll range specified by the provided
     45   * metrics. This only needs to be called if the scroll offset changes
     46   * outside of AsyncPanZoomController::SampleCompositedAsyncTransform().
     47   * It also recalculates mLayoutViewport so that it continues to enclose
     48   * the visual viewport. This only needs to be called if the
     49   * layout viewport changes outside of SampleCompositedAsyncTransform().
     50   */
     51  void ClampVisualScrollOffset(const FrameMetrics& aMetrics);
     52 
     53  void ZoomBy(float aScale);
     54 
     55 private:
     56  // These variables cache the layout viewport, scroll offset, and zoom stored
     57  // in |Metrics()| at the time this class was constructed.
     58  CSSRect mLayoutViewport;
     59  CSSPoint mVisualScrollOffset;
     60  CSSToParentLayerScale mZoom;
     61  // An optional payload that rides along with the sampled state.
     62  Maybe<CompositionPayload> mScrollPayload;
     63  APZScrollGeneration mGeneration;
     64  // Compositor scroll updates since the last sample.
     65  std::vector<CompositorScrollUpdate> mUpdates;
     66 
     67  void RemoveFractionalAsyncDelta();
     68  // A handy wrapper to call
     69  // FrameMetrics::KeepLayoutViewportEnclosingVisualViewport with this
     70  // SampledAPZCState and the given |aMetrics|.
     71  void KeepLayoutViewportEnclosingVisualViewport(const FrameMetrics& aMetrics);
     72 };
     73 
     74 }  // namespace layers
     75 }  // namespace mozilla
     76 
     77 #endif  // mozilla_layers_SampledAPZCState_h