tor-browser

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

APZCCallbackHelper.h (8817B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_layers_APZCCallbackHelper_h
      7 #define mozilla_layers_APZCCallbackHelper_h
      8 
      9 #include "InputData.h"
     10 #include "LayersTypes.h"
     11 #include "Units.h"
     12 #include "mozilla/EventForwards.h"
     13 #include "mozilla/layers/MatrixMessage.h"
     14 #include "nsRefreshObservers.h"
     15 
     16 #include <functional>
     17 
     18 class nsIContent;
     19 class nsIWidget;
     20 class nsPresContext;
     21 template <class T>
     22 struct already_AddRefed;
     23 template <class T>
     24 class nsCOMPtr;
     25 
     26 namespace mozilla {
     27 
     28 enum class PreventDefaultResult : uint8_t { No, ByContent, ByChrome };
     29 
     30 class PresShell;
     31 class ScrollContainerFrame;
     32 enum class PreventDefaultResult : uint8_t;
     33 
     34 namespace layers {
     35 
     36 struct RepaintRequest;
     37 
     38 namespace apz {
     39 enum class PrecedingPointerDown : bool;
     40 }
     41 
     42 enum class SynthesizeForTests : bool { No, Yes };
     43 
     44 /* Refer to documentation on SendSetTargetAPZCNotification for this class */
     45 class DisplayportSetListener : public ManagedPostRefreshObserver {
     46 public:
     47  DisplayportSetListener(nsIWidget* aWidget, nsPresContext*,
     48                         const uint64_t& aInputBlockId,
     49                         nsTArray<ScrollableLayerGuid>&& aTargets);
     50  virtual ~DisplayportSetListener();
     51  void Register();
     52 
     53 private:
     54  RefPtr<nsIWidget> mWidget;
     55  uint64_t mInputBlockId;
     56  nsTArray<ScrollableLayerGuid> mTargets;
     57 
     58  void OnPostRefresh();
     59 };
     60 
     61 /* This class contains some helper methods that facilitate implementing the
     62   GeckoContentController callback interface required by the
     63   AsyncPanZoomController. Since different platforms need to implement this
     64   interface in similar-but- not-quite-the-same ways, this utility class
     65   provides some helpful methods to hold code that can be shared across the
     66   different platform implementations.
     67 */
     68 class APZCCallbackHelper {
     69  typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
     70 
     71 public:
     72  using PrecedingPointerDown = apz::PrecedingPointerDown;
     73 
     74  static void NotifyLayerTransforms(const nsTArray<MatrixMessage>& aTransforms);
     75 
     76  /* Applies the scroll and zoom parameters from the given RepaintRequest object
     77     to the root frame for the given metrics' scrollId. If tiled thebes layers
     78     are enabled, this will align the displayport to tile boundaries. Setting
     79     the scroll position can cause some small adjustments to be made to the
     80     actual scroll position. */
     81  static void UpdateRootFrame(const RepaintRequest& aRequest);
     82 
     83  /* Applies the scroll parameters from the given RepaintRequest object to the
     84     subframe corresponding to given metrics' scrollId. If tiled thebes
     85     layers are enabled, this will align the displayport to tile boundaries.
     86     Setting the scroll position can cause some small adjustments to be made
     87     to the actual scroll position. */
     88  static void UpdateSubFrame(const RepaintRequest& aRequest);
     89 
     90  /* Get the presShellId and view ID for the given content element.
     91   * If the view ID does not exist, one is created.
     92   * The pres shell ID should generally already exist; if it doesn't for some
     93   * reason, false is returned. */
     94  static bool GetOrCreateScrollIdentifiers(
     95      nsIContent* aContent, uint32_t* aPresShellIdOut,
     96      ScrollableLayerGuid::ViewID* aViewIdOut);
     97 
     98  /* Initialize a zero-margin displayport on the root document element of the
     99     given presShell. */
    100  static void InitializeRootDisplayport(PresShell* aPresShell);
    101 
    102  /* Similar to above InitializeRootDisplayport but for an nsIFrame.
    103     The nsIFrame needs to be a popup menu frame. */
    104  static void InitializeRootDisplayport(nsIFrame* aFrame);
    105 
    106  /* Get the pres context associated with the document enclosing |aContent|. */
    107  static nsPresContext* GetPresContextForContent(nsIContent* aContent);
    108 
    109  /* Get the pres shell associated with the root content document enclosing
    110   * |aContent|. */
    111  static PresShell* GetRootContentDocumentPresShellForContent(
    112      nsIContent* aContent);
    113 
    114  /* Dispatch a widget event via the widget stored in the event, if any.
    115   * In a child process, allows the BrowserParent event-capture mechanism to
    116   * intercept the event. */
    117  static nsEventStatus DispatchWidgetEvent(WidgetGUIEvent& aEvent);
    118 
    119  /* Synthesize a mouse event with the given parameters, and dispatch it
    120   * via the given widget. */
    121  MOZ_CAN_RUN_SCRIPT static nsEventStatus DispatchSynthesizedMouseEvent(
    122      EventMessage aMsg, const LayoutDevicePoint& aRefPoint,
    123      uint32_t aPointerId, Modifiers aModifiers, int32_t aClickCount,
    124      PrecedingPointerDown aPrecedingPointerDownState, nsIWidget* aWidget,
    125      SynthesizeForTests aSynthesizeForTests);
    126 
    127  /*
    128   * Synthesize a contextmenu event with the given parameters, and dispatch it
    129   * via the given widget.
    130   */
    131  MOZ_CAN_RUN_SCRIPT static PreventDefaultResult
    132  DispatchSynthesizedContextmenuEvent(const LayoutDevicePoint& aRefPoint,
    133                                      uint32_t aPointerId, Modifiers aModifiers,
    134                                      nsIWidget* aWidget,
    135                                      SynthesizeForTests aSynthesizeForTests);
    136 
    137  /* Fire a single-tap event at the given point. The event is dispatched
    138   * via the given widget. */
    139  MOZ_CAN_RUN_SCRIPT static void FireSingleTapEvent(
    140      const LayoutDevicePoint& aPoint, uint32_t aPointerId,
    141      Modifiers aModifiers, int32_t aClickCount,
    142      PrecedingPointerDown aPrecedingPointerDownState, nsIWidget* aWidget,
    143      SynthesizeForTests aSynthesizeForTests);
    144 
    145  /* Perform hit-testing on the touch points of |aEvent| to determine
    146   * which scrollable frames they target. If any of these frames don't have
    147   * a displayport, set one.
    148   *
    149   * If any displayports need to be set, this function returns a heap-allocated
    150   * object. The caller is responsible for calling Register() on that object.
    151   *
    152   * The object registers itself as a post-refresh observer on the presShell
    153   * and ensures that notifications get sent to APZ correctly after the
    154   * refresh.
    155   *
    156   * Having the caller manage this object is desirable in case they want to
    157   * (a) know about the fact that a displayport needs to be set, and
    158   * (b) register a post-refresh observer of their own that will run in
    159   *     a defined ordering relative to the APZ messages.
    160   */
    161  static already_AddRefed<DisplayportSetListener> SendSetTargetAPZCNotification(
    162      nsIWidget* aWidget, mozilla::dom::Document* aDocument,
    163      const WidgetGUIEvent& aEvent, const LayersId& aLayersId,
    164      uint64_t aInputBlockId);
    165 
    166  /* Notify content of a mouse scroll testing event. */
    167  static void NotifyMozMouseScrollEvent(
    168      const ScrollableLayerGuid::ViewID& aScrollId, const nsString& aEvent);
    169 
    170  /* Notify content that the repaint flush is complete. */
    171  static void NotifyFlushComplete(PresShell* aPresShell);
    172 
    173  static void NotifyAsyncScrollbarDragInitiated(
    174      uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId,
    175      ScrollDirection aDirection);
    176  static void NotifyAsyncScrollbarDragRejected(
    177      const ScrollableLayerGuid::ViewID& aScrollId);
    178  static void NotifyAsyncAutoscrollRejected(
    179      const ScrollableLayerGuid::ViewID& aScrollId);
    180 
    181  static void CancelAutoscroll(const ScrollableLayerGuid::ViewID& aScrollId);
    182  static void NotifyScaleGestureComplete(const nsCOMPtr<nsIWidget>& aWidget,
    183                                         float aScale);
    184 
    185  /*
    186   * Check if the scroll container frame is currently in the middle of a main
    187   * thread async or smooth scroll, or has already requested some other apz
    188   * scroll that hasn't been acknowledged by apz.
    189   *
    190   * We want to discard apz updates to the main-thread scroll offset if this is
    191   * true to prevent clobbering higher priority origins.
    192   */
    193  static bool IsScrollInProgress(ScrollContainerFrame* aFrame);
    194 
    195  /* Notify content of the progress of a pinch gesture that APZ won't do
    196   * zooming for (because the apz.allow_zooming pref is false). This function
    197   * will dispatch appropriate WidgetSimpleGestureEvent events to gecko.
    198   */
    199  static void NotifyPinchGesture(PinchGestureInput::PinchGestureType aType,
    200                                 const LayoutDevicePoint& aFocusPoint,
    201                                 LayoutDeviceCoord aSpanChange,
    202                                 Modifiers aModifiers,
    203                                 const nsCOMPtr<nsIWidget>& aWidget);
    204 
    205 private:
    206  static uint64_t sLastTargetAPZCNotificationInputBlock;
    207 };
    208 
    209 }  // namespace layers
    210 
    211 std::ostream& operator<<(std::ostream& aOut,
    212                         const PreventDefaultResult aPreventDefaultResult);
    213 
    214 }  // namespace mozilla
    215 
    216 #endif /* mozilla_layers_APZCCallbackHelper_h */