tor-browser

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

APZCTreeManagerParent.cpp (7282B)


      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 "mozilla/layers/APZCTreeManagerParent.h"
      8 
      9 #include "apz/src/APZCTreeManager.h"
     10 #include "mozilla/layers/APZThreadUtils.h"
     11 #include "mozilla/layers/APZUpdater.h"
     12 #include "mozilla/layers/CompositorBridgeParent.h"
     13 #include "mozilla/layers/CompositorThread.h"
     14 #include "nsThreadUtils.h"
     15 
     16 namespace mozilla {
     17 namespace layers {
     18 
     19 APZCTreeManagerParent::APZCTreeManagerParent(
     20    LayersId aLayersId, RefPtr<APZCTreeManager> aAPZCTreeManager,
     21    RefPtr<APZUpdater> aAPZUpdater)
     22    : mLayersId(aLayersId),
     23      mTreeManager(std::move(aAPZCTreeManager)),
     24      mUpdater(std::move(aAPZUpdater)) {
     25  MOZ_ASSERT(mTreeManager != nullptr);
     26  MOZ_ASSERT(mUpdater != nullptr);
     27  MOZ_ASSERT(mUpdater->HasTreeManager(mTreeManager));
     28 }
     29 
     30 APZCTreeManagerParent::~APZCTreeManagerParent() = default;
     31 
     32 void APZCTreeManagerParent::ChildAdopted(
     33    RefPtr<APZCTreeManager> aAPZCTreeManager, RefPtr<APZUpdater> aAPZUpdater) {
     34  MOZ_ASSERT(aAPZCTreeManager != nullptr);
     35  MOZ_ASSERT(aAPZUpdater != nullptr);
     36  MOZ_ASSERT(aAPZUpdater->HasTreeManager(aAPZCTreeManager));
     37  mTreeManager = std::move(aAPZCTreeManager);
     38  mUpdater = std::move(aAPZUpdater);
     39 }
     40 
     41 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetKeyboardMap(
     42    const KeyboardMap& aKeyboardMap) {
     43  mUpdater->RunOnUpdaterThread(
     44      mLayersId, NewRunnableMethod<KeyboardMap>(
     45                     "layers::IAPZCTreeManager::SetKeyboardMap", mTreeManager,
     46                     &IAPZCTreeManager::SetKeyboardMap, aKeyboardMap));
     47 
     48  return IPC_OK();
     49 }
     50 
     51 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvZoomToRect(
     52    const ScrollableLayerGuid& aGuid, const ZoomTarget& aZoomTarget,
     53    const uint32_t& aFlags) {
     54  if (!IsGuidValid(aGuid)) {
     55    return IPC_FAIL_NO_REASON(this);
     56  }
     57 
     58  mUpdater->RunOnUpdaterThread(
     59      aGuid.mLayersId,
     60      NewRunnableMethod<ScrollableLayerGuid, ZoomTarget, uint32_t>(
     61          "layers::IAPZCTreeManager::ZoomToRect", mTreeManager,
     62          &IAPZCTreeManager::ZoomToRect, aGuid, aZoomTarget, aFlags));
     63  return IPC_OK();
     64 }
     65 
     66 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvContentReceivedInputBlock(
     67    const uint64_t& aInputBlockId, const bool& aPreventDefault) {
     68  mUpdater->RunOnUpdaterThread(
     69      mLayersId, NewRunnableMethod<uint64_t, bool>(
     70                     "layers::IAPZCTreeManager::ContentReceivedInputBlock",
     71                     mTreeManager, &IAPZCTreeManager::ContentReceivedInputBlock,
     72                     aInputBlockId, aPreventDefault));
     73 
     74  return IPC_OK();
     75 }
     76 
     77 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetTargetAPZC(
     78    const uint64_t& aInputBlockId, nsTArray<ScrollableLayerGuid>&& aTargets) {
     79  mUpdater->RunOnUpdaterThread(
     80      mLayersId,
     81      NewRunnableMethod<uint64_t,
     82                        StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>(
     83          "layers::IAPZCTreeManager::SetTargetAPZC", mTreeManager,
     84          &IAPZCTreeManager::SetTargetAPZC, aInputBlockId,
     85          std::move(aTargets)));
     86 
     87  return IPC_OK();
     88 }
     89 
     90 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvUpdateZoomConstraints(
     91    const ScrollableLayerGuid& aGuid,
     92    const Maybe<ZoomConstraints>& aConstraints) {
     93  if (!IsGuidValid(aGuid)) {
     94    return IPC_FAIL_NO_REASON(this);
     95  }
     96 
     97  mTreeManager->UpdateZoomConstraints(aGuid, aConstraints);
     98  return IPC_OK();
     99 }
    100 
    101 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetDPI(
    102    const float& aDpiValue) {
    103  mUpdater->RunOnUpdaterThread(
    104      mLayersId,
    105      NewRunnableMethod<float>("layers::IAPZCTreeManager::SetDPI", mTreeManager,
    106                               &IAPZCTreeManager::SetDPI, aDpiValue));
    107  return IPC_OK();
    108 }
    109 
    110 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetAllowedTouchBehavior(
    111    const uint64_t& aInputBlockId, nsTArray<TouchBehaviorFlags>&& aValues) {
    112  mUpdater->RunOnUpdaterThread(
    113      mLayersId,
    114      NewRunnableMethod<uint64_t,
    115                        StoreCopyPassByRRef<nsTArray<TouchBehaviorFlags>>>(
    116          "layers::IAPZCTreeManager::SetAllowedTouchBehavior", mTreeManager,
    117          &IAPZCTreeManager::SetAllowedTouchBehavior, aInputBlockId,
    118          std::move(aValues)));
    119 
    120  return IPC_OK();
    121 }
    122 
    123 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetBrowserGestureResponse(
    124    const uint64_t& aInputBlockId, const BrowserGestureResponse& aResponse) {
    125  mUpdater->RunOnUpdaterThread(
    126      mLayersId, NewRunnableMethod<uint64_t, BrowserGestureResponse>(
    127                     "layers::IAPZCTreeManager::SetBrowserGestureResponse",
    128                     mTreeManager, &IAPZCTreeManager::SetBrowserGestureResponse,
    129                     aInputBlockId, aResponse));
    130 
    131  return IPC_OK();
    132 }
    133 
    134 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvStartScrollbarDrag(
    135    const ScrollableLayerGuid& aGuid, const AsyncDragMetrics& aDragMetrics) {
    136  if (!IsGuidValid(aGuid)) {
    137    return IPC_FAIL_NO_REASON(this);
    138  }
    139 
    140  mUpdater->RunOnUpdaterThread(
    141      aGuid.mLayersId,
    142      NewRunnableMethod<ScrollableLayerGuid, AsyncDragMetrics>(
    143          "layers::IAPZCTreeManager::StartScrollbarDrag", mTreeManager,
    144          &IAPZCTreeManager::StartScrollbarDrag, aGuid, aDragMetrics));
    145 
    146  return IPC_OK();
    147 }
    148 
    149 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvStartAutoscroll(
    150    const ScrollableLayerGuid& aGuid, const ScreenPoint& aAnchorLocation) {
    151  // Unlike RecvStartScrollbarDrag(), this message comes from the parent
    152  // process (via nsIWidget::mAPZC) rather than from the child process
    153  // (via BrowserChild::mApzcTreeManager), so there is no need to check the
    154  // layers id against mLayersId (and in any case, it wouldn't match, because
    155  // mLayersId stores the parent process's layers id, while nsIWidget is
    156  // sending the child process's layers id).
    157 
    158  mUpdater->RunOnControllerThread(
    159      mLayersId,
    160      NewRunnableMethod<ScrollableLayerGuid, ScreenPoint>(
    161          "layers::IAPZCTreeManager::StartAutoscroll", mTreeManager,
    162          &IAPZCTreeManager::StartAutoscroll, aGuid, aAnchorLocation));
    163 
    164  return IPC_OK();
    165 }
    166 
    167 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvStopAutoscroll(
    168    const ScrollableLayerGuid& aGuid) {
    169  // See RecvStartAutoscroll() for why we don't check the layers id.
    170 
    171  mUpdater->RunOnControllerThread(
    172      mLayersId, NewRunnableMethod<ScrollableLayerGuid>(
    173                     "layers::IAPZCTreeManager::StopAutoscroll", mTreeManager,
    174                     &IAPZCTreeManager::StopAutoscroll, aGuid));
    175 
    176  return IPC_OK();
    177 }
    178 
    179 mozilla::ipc::IPCResult APZCTreeManagerParent::RecvSetLongTapEnabled(
    180    const bool& aLongTapEnabled) {
    181  mUpdater->RunOnUpdaterThread(
    182      mLayersId,
    183      NewRunnableMethod<bool>(
    184          "layers::IAPZCTreeManager::SetLongTapEnabled", mTreeManager,
    185          &IAPZCTreeManager::SetLongTapEnabled, aLongTapEnabled));
    186 
    187  return IPC_OK();
    188 }
    189 
    190 bool APZCTreeManagerParent::IsGuidValid(const ScrollableLayerGuid& aGuid) {
    191  if (aGuid.mLayersId != mLayersId) {
    192    NS_ERROR("Unexpected layers id");
    193    return false;
    194  }
    195  return true;
    196 }
    197 
    198 }  // namespace layers
    199 }  // namespace mozilla