tor-browser

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

GeckoContentController.h (8047B)


      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_GeckoContentController_h
      8 #define mozilla_layers_GeckoContentController_h
      9 
     10 #include "GeckoContentControllerTypes.h"
     11 #include "InputData.h"              // for PinchGestureInput
     12 #include "LayersTypes.h"            // for ScrollDirection
     13 #include "Units.h"                  // for CSSPoint, CSSRect, etc
     14 #include "mozilla/Attributes.h"     // for MOZ_CAN_RUN_SCRIPT
     15 #include "mozilla/DefineEnum.h"     // for MOZ_DEFINE_ENUM
     16 #include "mozilla/EventForwards.h"  // for Modifiers
     17 #include "mozilla/layers/APZThreadUtils.h"
     18 #include "mozilla/layers/MatrixMessage.h"        // for MatrixMessage
     19 #include "mozilla/layers/ScrollableLayerGuid.h"  // for ScrollableLayerGuid, etc
     20 #include "nsISupportsImpl.h"
     21 
     22 namespace mozilla {
     23 
     24 class Runnable;
     25 
     26 namespace layers {
     27 
     28 struct DoubleTapToZoomMetrics;
     29 struct RepaintRequest;
     30 
     31 class GeckoContentController {
     32 public:
     33  using APZStateChange = GeckoContentController_APZStateChange;
     34  using TapType = GeckoContentController_TapType;
     35  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GeckoContentController)
     36 
     37  /**
     38   * Notifies the content side of the most recently computed transforms for
     39   * each layers subtree to the root. The nsTArray will contain one
     40   *  MatrixMessage for each layers id in the current APZ tree, along with the
     41   * corresponding transform.
     42   */
     43  virtual void NotifyLayerTransforms(nsTArray<MatrixMessage>&& aTransforms) = 0;
     44 
     45  /**
     46   * Requests a paint of the given RepaintRequest |aRequest| from Gecko.
     47   * Implementations per-platform are responsible for actually handling this.
     48   *
     49   * This method must always be called on the repaint thread, which depends
     50   * on the GeckoContentController. For ChromeProcessController it is the
     51   * Gecko main thread, while for RemoteContentController it is the compositor
     52   * thread where it can send IPDL messages.
     53   */
     54  virtual void RequestContentRepaint(const RepaintRequest& aRequest) = 0;
     55 
     56  /**
     57   * Requests handling of a tap event. |aPoint| is in LD pixels, relative to the
     58   * current scroll offset.
     59   */
     60  MOZ_CAN_RUN_SCRIPT
     61  virtual void HandleTap(
     62      TapType aType, const LayoutDevicePoint& aPoint, Modifiers aModifiers,
     63      const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId,
     64      const Maybe<DoubleTapToZoomMetrics>& aDoubleTapTooZoomMetrics) = 0;
     65 
     66  /**
     67   * When the apz.allow_zooming pref is set to false, the APZ will not
     68   * translate pinch gestures to actual zooming. Instead, it will call this
     69   * method to notify gecko of the pinch gesture, and allow it to deal with it
     70   * however it wishes. Note that this function is not called if the pinch is
     71   * prevented by content calling preventDefault() on the touch events, or via
     72   * use of the touch-action property.
     73   * @param aType One of PINCHGESTURE_START, PINCHGESTURE_SCALE,
     74   *        PINCHGESTURE_FINGERLIFTED, or PINCHGESTURE_END, indicating the phase
     75   *        of the pinch.
     76   * @param aGuid The guid of the APZ that is detecting the pinch. This is
     77   *        generally the root APZC for the layers id.
     78   * @param aFocusPoint The focus point of the pinch event.
     79   * @param aSpanChange For the START or END event, this is always 0.
     80   *        For a SCALE event, this is the difference in span between the
     81   *        previous state and the new state.
     82   * @param aModifiers The keyboard modifiers depressed during the pinch.
     83   */
     84  virtual void NotifyPinchGesture(PinchGestureInput::PinchGestureType aType,
     85                                  const ScrollableLayerGuid& aGuid,
     86                                  const LayoutDevicePoint& aFocusPoint,
     87                                  LayoutDeviceCoord aSpanChange,
     88                                  Modifiers aModifiers) = 0;
     89 
     90  /**
     91   * Schedules a runnable to run on the controller thread at some time
     92   * in the future.
     93   * This method must always be called on the controller thread.
     94   */
     95  virtual void PostDelayedTask(already_AddRefed<Runnable> aRunnable,
     96                               int aDelayMs) {
     97    APZThreadUtils::DelayedDispatch(std::move(aRunnable), aDelayMs);
     98  }
     99 
    100  /**
    101   * Returns true if we are currently on the thread that can send repaint
    102   * requests.
    103   */
    104  virtual bool IsRepaintThread() = 0;
    105 
    106  /**
    107   * Runs the given task on the "repaint" thread.
    108   */
    109  virtual void DispatchToRepaintThread(already_AddRefed<Runnable> aTask) = 0;
    110 
    111  /**
    112   * General notices of APZ state changes for consumers.
    113   * |aGuid| identifies the APZC originating the state change.
    114   * |aChange| identifies the type of state change
    115   * |aArg| is used by some state changes to pass extra information (see
    116   *        the documentation for each state change above)
    117   * |aInputBlockId| is populated for the |eStartTouch| and |eEndTouch|
    118   *                 state changes and identifies the input block of the
    119   *                 gesture that triggers the state change.
    120   */
    121  virtual void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
    122                                    APZStateChange aChange, int aArg = 0,
    123                                    Maybe<uint64_t> aInputBlockId = Nothing()) {
    124  }
    125 
    126  /**
    127   * Notify content of a MozMouseScrollFailed event.
    128   */
    129  virtual void NotifyMozMouseScrollEvent(
    130      const ScrollableLayerGuid::ViewID& aScrollId, const nsString& aEvent) {}
    131 
    132  /**
    133   * Notify content that the repaint requests have been flushed.
    134   */
    135  virtual void NotifyFlushComplete() = 0;
    136 
    137  /**
    138   * If the async scrollbar-drag initiation code kicks in on the APZ side, then
    139   * we need to let content know that we are dragging the scrollbar. Otherwise,
    140   * by the time the mousedown events is handled by content, the scrollthumb
    141   * could already have been moved via a RequestContentRepaint message at a
    142   * new scroll position, and the mousedown might end up triggering a click-to-
    143   * scroll on where the thumb used to be.
    144   */
    145  virtual void NotifyAsyncScrollbarDragInitiated(
    146      uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId,
    147      ScrollDirection aDirection) = 0;
    148  virtual void NotifyAsyncScrollbarDragRejected(
    149      const ScrollableLayerGuid::ViewID& aScrollId) = 0;
    150 
    151  virtual void NotifyAsyncAutoscrollRejected(
    152      const ScrollableLayerGuid::ViewID& aScrollId) = 0;
    153 
    154  virtual void CancelAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
    155 
    156  virtual void NotifyScaleGestureComplete(const ScrollableLayerGuid& aGuid,
    157                                          float aScale) = 0;
    158 
    159  /**
    160   * Following functions with empty implementations are Android-specific
    161   * and handled in the parent process. They are overridden by
    162   * AndroidContentController in the parent process,
    163   * and by RemoteContentController for the purpose of routing them from
    164   * the compositor process to the parent process.
    165   */
    166  virtual void UpdateOverscrollVelocity(const ScrollableLayerGuid& aGuid,
    167                                        float aX, float aY,
    168                                        bool aIsRootContent) {}
    169  virtual void UpdateOverscrollOffset(const ScrollableLayerGuid& aGuid,
    170                                      float aX, float aY, bool aIsRootContent) {
    171  }
    172  virtual void HideDynamicToolbar(const ScrollableLayerGuid& aGuid) {}
    173 
    174  GeckoContentController() = default;
    175 
    176  /**
    177   * Needs to be called on the main thread.
    178   */
    179  virtual void Destroy() {}
    180 
    181  /**
    182   * Whether this is RemoteContentController.
    183   */
    184  virtual bool IsRemote() { return false; }
    185 
    186  virtual PresShell* GetTopLevelPresShell() const { return nullptr; };
    187 
    188 protected:
    189  // Protected destructor, to discourage deletion outside of Release():
    190  virtual ~GeckoContentController() = default;
    191 };
    192 
    193 }  // namespace layers
    194 }  // namespace mozilla
    195 
    196 #endif  // mozilla_layers_GeckoContentController_h