gfx/layers/ipc/APZCTreeManagerChild.cpp
author Ryan Hunt <rhunt@eqrion.net>
Thu, 01 Nov 2018 15:15:46 -0500
changeset 444295 ad0782d7c503f33cfb554d08dedc96287e1ed3f2
parent 426552 fe0653a84312f608e8b9d406b3ab32ebbdd73a5f
child 448947 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1504220 - Move ScrollableLayerGuid, ViewID, ZoomConstraints from FrameMetrics.h r=botond This commit attempts to lower the pain of modifying FrameMetrics.h. It looks like most includes really only want ViewID or ScrollableLayerGuid, so this commit factors them out into a separate header. In the process FrameMetrics::ViewID is changed to ScrollableLayerGuid::ViewID, which personally seems like a better place for it now that we have RepaintRequest. Unfortunately that requires a lot of places to be updated. After this commit there are still a couple of major places that FrameMetrics is included. * nsDisplayList.h * nsIScrollableFrame.h * Layers.h Those are going to be more tricky or impossible to fix so they're not in this commit. Differential Revision: https://phabricator.services.mozilla.com/D10722

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/layers/APZCTreeManagerChild.h"

#include "InputData.h"                  // for InputData
#include "mozilla/dom/TabParent.h"      // for TabParent
#include "mozilla/layers/APZCCallbackHelper.h" // for APZCCallbackHelper
#include "mozilla/layers/APZInputBridgeChild.h" // for APZInputBridgeChild
#include "mozilla/layers/RemoteCompositorSession.h" // for RemoteCompositorSession

namespace mozilla {
namespace layers {

APZCTreeManagerChild::APZCTreeManagerChild()
  : mCompositorSession(nullptr)
{
}

APZCTreeManagerChild::~APZCTreeManagerChild()
{
}

void
APZCTreeManagerChild::SetCompositorSession(RemoteCompositorSession* aSession)
{
  // Exactly one of mCompositorSession and aSession must be null (i.e. either
  // we're setting mCompositorSession or we're clearing it).
  MOZ_ASSERT(!mCompositorSession ^ !aSession);
  mCompositorSession = aSession;
}

void
APZCTreeManagerChild::SetInputBridge(APZInputBridgeChild* aInputBridge)
{
  // The input bridge only exists from the UI process to the GPU process.
  MOZ_ASSERT(XRE_IsParentProcess());
  MOZ_ASSERT(!mInputBridge);

  mInputBridge = aInputBridge;
}

void
APZCTreeManagerChild::Destroy()
{
  MOZ_ASSERT(NS_IsMainThread());
  if (mInputBridge) {
    mInputBridge->Destroy();
    mInputBridge = nullptr;
  }
}

void
APZCTreeManagerChild::SetKeyboardMap(const KeyboardMap& aKeyboardMap)
{
  SendSetKeyboardMap(aKeyboardMap);
}

void
APZCTreeManagerChild::ZoomToRect(
    const ScrollableLayerGuid& aGuid,
    const CSSRect& aRect,
    const uint32_t aFlags)
{
  SendZoomToRect(aGuid, aRect, aFlags);
}

void
APZCTreeManagerChild::ContentReceivedInputBlock(
    uint64_t aInputBlockId,
    bool aPreventDefault)
{
  SendContentReceivedInputBlock(aInputBlockId, aPreventDefault);
}

void
APZCTreeManagerChild::SetTargetAPZC(
    uint64_t aInputBlockId,
    const nsTArray<ScrollableLayerGuid>& aTargets)
{
  SendSetTargetAPZC(aInputBlockId, aTargets);
}

void
APZCTreeManagerChild::UpdateZoomConstraints(
    const ScrollableLayerGuid& aGuid,
    const Maybe<ZoomConstraints>& aConstraints)
{
  SendUpdateZoomConstraints(aGuid, aConstraints);
}

void
APZCTreeManagerChild::SetDPI(float aDpiValue)
{
  SendSetDPI(aDpiValue);
}

void
APZCTreeManagerChild::SetAllowedTouchBehavior(
    uint64_t aInputBlockId,
    const nsTArray<TouchBehaviorFlags>& aValues)
{
  SendSetAllowedTouchBehavior(aInputBlockId, aValues);
}

void
APZCTreeManagerChild::StartScrollbarDrag(
    const ScrollableLayerGuid& aGuid,
    const AsyncDragMetrics& aDragMetrics)
{
  SendStartScrollbarDrag(aGuid, aDragMetrics);
}

bool
APZCTreeManagerChild::StartAutoscroll(
    const ScrollableLayerGuid& aGuid,
    const ScreenPoint& aAnchorLocation)
{
  return SendStartAutoscroll(aGuid, aAnchorLocation);
}

void
APZCTreeManagerChild::StopAutoscroll(const ScrollableLayerGuid& aGuid)
{
  SendStopAutoscroll(aGuid);
}

void
APZCTreeManagerChild::SetLongTapEnabled(bool aTapGestureEnabled)
{
  SendSetLongTapEnabled(aTapGestureEnabled);
}

APZInputBridge*
APZCTreeManagerChild::InputBridge()
{
  MOZ_ASSERT(XRE_IsParentProcess());
  MOZ_ASSERT(mInputBridge);

  return mInputBridge.get();
}

mozilla::ipc::IPCResult
APZCTreeManagerChild::RecvHandleTap(const TapType& aType,
                                    const LayoutDevicePoint& aPoint,
                                    const Modifiers& aModifiers,
                                    const ScrollableLayerGuid& aGuid,
                                    const uint64_t& aInputBlockId)
{
  MOZ_ASSERT(XRE_IsParentProcess());
  if (mCompositorSession &&
      mCompositorSession->RootLayerTreeId() == aGuid.mLayersId &&
      mCompositorSession->GetContentController()) {
    mCompositorSession->GetContentController()->HandleTap(aType, aPoint,
        aModifiers, aGuid, aInputBlockId);
    return IPC_OK();
  }
  dom::TabParent* tab = dom::TabParent::GetTabParentFromLayersId(aGuid.mLayersId);
  if (tab) {
    tab->SendHandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId);
  }
  return IPC_OK();
}

mozilla::ipc::IPCResult
APZCTreeManagerChild::RecvNotifyPinchGesture(const PinchGestureType& aType,
                                             const ScrollableLayerGuid& aGuid,
                                             const LayoutDeviceCoord& aSpanChange,
                                             const Modifiers& aModifiers)
{
  // This will only get sent from the GPU process to the parent process, so
  // this function should never get called in the content process.
  MOZ_ASSERT(XRE_IsParentProcess());
  MOZ_ASSERT(NS_IsMainThread());

  // We want to handle it in this process regardless of what the target guid
  // of the pinch is. This may change in the future.
  if (mCompositorSession &&
      mCompositorSession->GetWidget()) {
    APZCCallbackHelper::NotifyPinchGesture(aType, aSpanChange, aModifiers, mCompositorSession->GetWidget());
  }
  return IPC_OK();
}

mozilla::ipc::IPCResult
APZCTreeManagerChild::RecvCancelAutoscroll(const ScrollableLayerGuid::ViewID& aScrollId)
{
  // This will only get sent from the GPU process to the parent process, so
  // this function should never get called in the content process.
  MOZ_ASSERT(XRE_IsParentProcess());
  MOZ_ASSERT(NS_IsMainThread());

  APZCCallbackHelper::CancelAutoscroll(aScrollId);
  return IPC_OK();
}

} // namespace layers
} // namespace mozilla