2013-07-30 11:03:40 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "APZCTreeManager.h"
|
2013-07-30 11:03:41 -07:00
|
|
|
#include "AsyncCompositionManager.h" // for ViewTransform
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "Compositor.h" // for Compositor
|
|
|
|
#include "CompositorParent.h" // for CompositorParent, etc
|
|
|
|
#include "InputData.h" // for InputData, etc
|
|
|
|
#include "Layers.h" // for ContainerLayer, Layer, etc
|
|
|
|
#include "gfx3DMatrix.h" // for gfx3DMatrix
|
|
|
|
#include "mozilla/dom/Touch.h" // for Touch
|
|
|
|
#include "mozilla/gfx/Point.h" // for Point
|
|
|
|
#include "mozilla/layers/AsyncPanZoomController.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/mozalloc.h" // for operator new
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2014-01-22 13:37:57 -08:00
|
|
|
#include "mozilla/Preferences.h" // for Preferences
|
2013-11-07 13:10:29 -08:00
|
|
|
#include "nsDebug.h" // for NS_WARNING
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "nsPoint.h" // for nsIntPoint
|
|
|
|
#include "nsThreadUtils.h" // for NS_IsMainThread
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-11-21 14:38:00 -08:00
|
|
|
#include <algorithm> // for std::stable_sort
|
|
|
|
|
2013-07-30 11:55:57 -07:00
|
|
|
#define APZC_LOG(...)
|
2013-10-08 14:13:04 -07:00
|
|
|
// #define APZC_LOG(...) printf_stderr("APZC: " __VA_ARGS__)
|
2013-07-30 11:03:41 -07:00
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-01-23 13:34:31 -08:00
|
|
|
float APZCTreeManager::sDPI = 160.0;
|
2013-08-22 17:28:02 -07:00
|
|
|
|
2014-01-22 13:37:57 -08:00
|
|
|
// Pref that enables printing of the APZC tree for debugging.
|
|
|
|
static bool gPrintApzcTree = false;
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
APZCTreeManager::APZCTreeManager()
|
2013-11-07 13:10:29 -08:00
|
|
|
: mTreeLock("APZCTreeLock"),
|
|
|
|
mTouchCount(0)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
AsyncPanZoomController::InitializeGlobalState();
|
2014-01-22 13:37:57 -08:00
|
|
|
Preferences::AddBoolVarCache(&gPrintApzcTree, "apz.printtree", gPrintApzcTree);
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
APZCTreeManager::~APZCTreeManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-15 07:03:15 -08:00
|
|
|
void
|
|
|
|
APZCTreeManager::GetAllowedTouchBehavior(WidgetInputEvent* aEvent,
|
|
|
|
nsTArray<TouchBehaviorFlags>& aOutValues)
|
|
|
|
{
|
|
|
|
WidgetTouchEvent *touchEvent = aEvent->AsTouchEvent();
|
|
|
|
|
|
|
|
aOutValues.Clear();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < touchEvent->touches.Length(); i++) {
|
|
|
|
// If aEvent wasn't transformed previously we might need to
|
|
|
|
// add transforming of the spt here.
|
|
|
|
mozilla::ScreenIntPoint spt;
|
|
|
|
spt.x = touchEvent->touches[i]->mRefPoint.x;
|
|
|
|
spt.y = touchEvent->touches[i]->mRefPoint.y;
|
|
|
|
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(spt);
|
|
|
|
aOutValues.AppendElement(apzc
|
|
|
|
? apzc->GetAllowedTouchBehavior(spt)
|
|
|
|
: AllowedTouchBehavior::UNKNOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::SetAllowedTouchBehavior(const ScrollableLayerGuid& aGuid,
|
|
|
|
const nsTArray<TouchBehaviorFlags> &aValues)
|
|
|
|
{
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aGuid);
|
|
|
|
if (apzc) {
|
|
|
|
apzc->SetAllowedTouchBehavior(aValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:41 -07:00
|
|
|
void
|
|
|
|
APZCTreeManager::AssertOnCompositorThread()
|
|
|
|
{
|
|
|
|
Compositor::AssertOnCompositorThread();
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
/* Flatten the tree of APZC instances into the given nsTArray */
|
|
|
|
static void
|
|
|
|
Collect(AsyncPanZoomController* aApzc, nsTArray< nsRefPtr<AsyncPanZoomController> >* aCollection)
|
|
|
|
{
|
|
|
|
if (aApzc) {
|
|
|
|
aCollection->AppendElement(aApzc);
|
|
|
|
Collect(aApzc->GetLastChild(), aCollection);
|
|
|
|
Collect(aApzc->GetPrevSibling(), aCollection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
void
|
|
|
|
APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor, Layer* aRoot,
|
2013-07-30 11:03:40 -07:00
|
|
|
bool aIsFirstPaint, uint64_t aFirstPaintLayersId)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
2013-07-30 11:03:41 -07:00
|
|
|
AssertOnCompositorThread();
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
// We do this business with collecting the entire tree into an array because otherwise
|
|
|
|
// it's very hard to determine which APZC instances need to be destroyed. In the worst
|
|
|
|
// case, there are two scenarios: (a) a layer with an APZC is removed from the layer
|
|
|
|
// tree and (b) a layer with an APZC is moved in the layer tree from one place to a
|
|
|
|
// completely different place. In scenario (a) we would want to destroy the APZC while
|
|
|
|
// walking the layer tree and noticing that the layer/APZC is no longer there. But if
|
|
|
|
// we do that then we run into a problem in scenario (b) because we might encounter that
|
|
|
|
// layer later during the walk. To handle both of these we have to 'remember' that the
|
|
|
|
// layer was not found, and then do the destroy only at the end of the tree walk after
|
|
|
|
// we are sure that the layer was removed and not just transplanted elsewhere. Doing that
|
|
|
|
// as part of a recursive tree walk is hard and so maintaining a list and removing
|
|
|
|
// APZCs that are still alive is much simpler.
|
|
|
|
nsTArray< nsRefPtr<AsyncPanZoomController> > apzcsToDestroy;
|
|
|
|
Collect(mRootApzc, &apzcsToDestroy);
|
|
|
|
mRootApzc = nullptr;
|
|
|
|
|
|
|
|
if (aRoot) {
|
|
|
|
UpdatePanZoomControllerTree(aCompositor,
|
2013-07-30 11:03:43 -07:00
|
|
|
aRoot,
|
|
|
|
// aCompositor is null in gtest scenarios
|
|
|
|
aCompositor ? aCompositor->RootLayerTreeId() : 0,
|
2013-08-06 13:20:14 -07:00
|
|
|
gfx3DMatrix(), nullptr, nullptr,
|
2013-07-30 11:03:40 -07:00
|
|
|
aIsFirstPaint, aFirstPaintLayersId,
|
|
|
|
&apzcsToDestroy);
|
|
|
|
}
|
|
|
|
|
2013-08-21 09:03:03 -07:00
|
|
|
for (size_t i = 0; i < apzcsToDestroy.Length(); i++) {
|
2013-07-30 11:03:41 -07:00
|
|
|
APZC_LOG("Destroying APZC at %p\n", apzcsToDestroy[i].get());
|
2013-07-30 11:03:40 -07:00
|
|
|
apzcsToDestroy[i]->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AsyncPanZoomController*
|
|
|
|
APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor,
|
|
|
|
Layer* aLayer, uint64_t aLayersId,
|
2013-08-06 13:20:14 -07:00
|
|
|
gfx3DMatrix aTransform,
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController* aParent,
|
|
|
|
AsyncPanZoomController* aNextSibling,
|
|
|
|
bool aIsFirstPaint, uint64_t aFirstPaintLayersId,
|
|
|
|
nsTArray< nsRefPtr<AsyncPanZoomController> >* aApzcsToDestroy)
|
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
mTreeLock.AssertCurrentThreadOwns();
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
ContainerLayer* container = aLayer->AsContainerLayer();
|
2013-09-13 07:18:38 -07:00
|
|
|
AsyncPanZoomController* apzc = nullptr;
|
2013-07-30 11:03:40 -07:00
|
|
|
if (container) {
|
|
|
|
if (container->GetFrameMetrics().IsScrollable()) {
|
|
|
|
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(aLayersId);
|
|
|
|
if (state && state->mController.get()) {
|
|
|
|
// If we get here, aLayer is a scrollable container layer and somebody
|
|
|
|
// has registered a GeckoContentController for it, so we need to ensure
|
|
|
|
// it has an APZC instance to manage its scrolling.
|
|
|
|
|
2013-09-13 07:18:38 -07:00
|
|
|
apzc = container->GetAsyncPanZoomController();
|
2013-09-13 07:18:33 -07:00
|
|
|
|
2013-11-18 07:14:08 -08:00
|
|
|
// If the content represented by the container layer has changed (which may
|
|
|
|
// be possible because of DLBI heuristics) then we don't want to keep using
|
|
|
|
// the same old APZC for the new content. Null it out so we run through the
|
|
|
|
// code to find another one or create one.
|
|
|
|
if (apzc && !apzc->Matches(ScrollableLayerGuid(aLayersId, container->GetFrameMetrics()))) {
|
|
|
|
apzc = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-14 12:35:30 -08:00
|
|
|
// If the container doesn't have an APZC already, try to find one of our
|
|
|
|
// pre-existing ones that matches. In particular, if we find an APZC whose
|
|
|
|
// ScrollableLayerGuid is the same, then we know what happened is that the
|
|
|
|
// layout of the page changed causing the layer tree to be rebuilt, but the
|
|
|
|
// underlying content for which the APZC was originally created is still
|
|
|
|
// there. So it makes sense to pick up that APZC instance again and use it here.
|
|
|
|
if (apzc == nullptr) {
|
|
|
|
ScrollableLayerGuid target(aLayersId, container->GetFrameMetrics());
|
|
|
|
for (size_t i = 0; i < aApzcsToDestroy->Length(); i++) {
|
|
|
|
if (aApzcsToDestroy->ElementAt(i)->Matches(target)) {
|
|
|
|
apzc = aApzcsToDestroy->ElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 02:30:17 -07:00
|
|
|
// The APZC we get off the layer may have been destroyed previously if the layer was inactive
|
|
|
|
// or omitted from the layer tree for whatever reason from a layers update. If it later comes
|
|
|
|
// back it will have a reference to a destroyed APZC and so we need to throw that out and make
|
|
|
|
// a new one.
|
|
|
|
bool newApzc = (apzc == nullptr || apzc->IsDestroyed());
|
2013-09-13 07:18:38 -07:00
|
|
|
if (newApzc) {
|
2013-08-20 15:10:47 -07:00
|
|
|
apzc = new AsyncPanZoomController(aLayersId, this, state->mController,
|
2013-09-13 07:18:38 -07:00
|
|
|
AsyncPanZoomController::USE_GESTURE_DETECTOR);
|
|
|
|
apzc->SetCompositorParent(aCompositor);
|
2013-12-19 12:19:25 -08:00
|
|
|
apzc->SetCrossProcessCompositorParent(state->mCrossProcessParent);
|
2013-07-30 11:03:40 -07:00
|
|
|
} else {
|
|
|
|
// If there was already an APZC for the layer clear the tree pointers
|
|
|
|
// so that it doesn't continue pointing to APZCs that should no longer
|
|
|
|
// be in the tree. These pointers will get reset properly as we continue
|
|
|
|
// building the tree. Also remove it from the set of APZCs that are going
|
|
|
|
// to be destroyed, because it's going to remain active.
|
2013-09-13 07:18:38 -07:00
|
|
|
aApzcsToDestroy->RemoveElement(apzc);
|
|
|
|
apzc->SetPrevSibling(nullptr);
|
|
|
|
apzc->SetLastChild(nullptr);
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-09-13 07:18:38 -07:00
|
|
|
APZC_LOG("Using APZC %p for layer %p with identifiers %lld %lld\n", apzc, aLayer, aLayersId, container->GetFrameMetrics().mScrollId);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-09-13 07:18:38 -07:00
|
|
|
apzc->NotifyLayersUpdated(container->GetFrameMetrics(),
|
2013-11-18 07:14:08 -08:00
|
|
|
aIsFirstPaint && (aLayersId == aFirstPaintLayersId));
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2014-01-16 12:19:59 -08:00
|
|
|
// Use the composition bounds as the hit test region.
|
|
|
|
// Optionally, the GeckoContentController can provide a touch-sensitive
|
|
|
|
// region that constrains all frames associated with the controller.
|
|
|
|
// In this case we intersect the composition bounds with that region.
|
2013-10-30 12:58:25 -07:00
|
|
|
ScreenRect visible(container->GetFrameMetrics().mCompositionBounds);
|
2014-01-16 12:19:59 -08:00
|
|
|
CSSRect touchSensitiveRegion;
|
|
|
|
if (state->mController->GetTouchSensitiveRegion(&touchSensitiveRegion)) {
|
|
|
|
visible = visible.Intersect(touchSensitiveRegion
|
|
|
|
* container->GetFrameMetrics().LayersPixelsPerCSSPixel()
|
|
|
|
* LayerToScreenScale(1.0));
|
|
|
|
}
|
2014-01-27 07:28:47 -08:00
|
|
|
gfx3DMatrix transform;
|
|
|
|
gfx::To3DMatrix(aLayer->GetTransform(), transform);
|
|
|
|
|
|
|
|
apzc->SetLayerHitTestData(visible, aTransform, transform);
|
2013-08-06 13:20:14 -07:00
|
|
|
APZC_LOG("Setting rect(%f %f %f %f) as visible region for APZC %p\n", visible.x, visible.y,
|
|
|
|
visible.width, visible.height,
|
2013-09-13 07:18:38 -07:00
|
|
|
apzc);
|
2013-07-30 11:03:41 -07:00
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
// Bind the APZC instance into the tree of APZCs
|
|
|
|
if (aNextSibling) {
|
2013-09-13 07:18:38 -07:00
|
|
|
aNextSibling->SetPrevSibling(apzc);
|
2013-07-30 11:03:40 -07:00
|
|
|
} else if (aParent) {
|
2013-09-13 07:18:38 -07:00
|
|
|
aParent->SetLastChild(apzc);
|
2013-07-30 11:03:40 -07:00
|
|
|
} else {
|
2013-09-13 07:18:38 -07:00
|
|
|
mRootApzc = apzc;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-09-13 07:18:38 -07:00
|
|
|
// Let this apzc be the parent of other controllers when we recurse downwards
|
|
|
|
aParent = apzc;
|
2013-09-13 07:18:33 -07:00
|
|
|
|
2013-12-02 15:01:19 -08:00
|
|
|
if (newApzc) {
|
|
|
|
if (apzc->IsRootForLayersId()) {
|
|
|
|
// If we just created a new apzc that is the root for its layers ID, then
|
|
|
|
// we need to update its zoom constraints which might have arrived before this
|
|
|
|
// was created
|
2014-01-06 10:26:44 -08:00
|
|
|
ZoomConstraints constraints;
|
|
|
|
if (state->mController->GetRootZoomConstraints(&constraints)) {
|
|
|
|
apzc->UpdateZoomConstraints(constraints);
|
2013-12-02 15:01:19 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For an apzc that is not the root for its layers ID, we give it the
|
|
|
|
// same zoom constraints as its parent. This ensures that if e.g.
|
|
|
|
// user-scalable=no was specified, none of the APZCs allow double-tap
|
|
|
|
// to zoom.
|
2014-01-06 10:26:44 -08:00
|
|
|
apzc->UpdateZoomConstraints(apzc->GetParent()->GetZoomConstraints());
|
2013-09-13 07:18:33 -07:00
|
|
|
}
|
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-09-13 07:18:38 -07:00
|
|
|
container->SetAsyncPanZoomController(apzc);
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-08-14 07:15:54 -07:00
|
|
|
// Accumulate the CSS transform between layers that have an APZC, but exclude any
|
|
|
|
// any layers that do have an APZC, and reset the accumulation at those layers.
|
2013-09-13 07:18:38 -07:00
|
|
|
if (apzc) {
|
2013-08-14 07:15:54 -07:00
|
|
|
aTransform = gfx3DMatrix();
|
|
|
|
} else {
|
|
|
|
// Multiply child layer transforms on the left so they get applied first
|
2014-01-27 07:28:47 -08:00
|
|
|
gfx3DMatrix matrix;
|
|
|
|
gfx::To3DMatrix(aLayer->GetTransform(), matrix);
|
|
|
|
aTransform = matrix * aTransform;
|
2013-08-14 07:15:54 -07:00
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
uint64_t childLayersId = (aLayer->AsRefLayer() ? aLayer->AsRefLayer()->GetReferentId() : aLayersId);
|
2013-11-20 12:27:40 -08:00
|
|
|
// If there's no APZC at this level, any APZCs for our child layers will
|
|
|
|
// have our siblings as siblings.
|
|
|
|
AsyncPanZoomController* next = apzc ? nullptr : aNextSibling;
|
2013-07-30 11:03:40 -07:00
|
|
|
for (Layer* child = aLayer->GetLastChild(); child; child = child->GetPrevSibling()) {
|
2013-08-06 13:20:14 -07:00
|
|
|
next = UpdatePanZoomControllerTree(aCompositor, child, childLayersId, aTransform, aParent, next,
|
2013-07-30 11:03:40 -07:00
|
|
|
aIsFirstPaint, aFirstPaintLayersId, aApzcsToDestroy);
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
// Return the APZC that should be the sibling of other APZCs as we continue
|
|
|
|
// moving towards the first child at this depth in the layer tree.
|
2013-09-13 07:18:38 -07:00
|
|
|
// If this layer doesn't have an APZC, we promote any APZCs in the subtree
|
2013-07-30 11:03:40 -07:00
|
|
|
// upwards. Otherwise we fall back to the aNextSibling that was passed in.
|
2013-09-13 07:18:38 -07:00
|
|
|
if (apzc) {
|
|
|
|
return apzc;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
if (next) {
|
|
|
|
return next;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
return aNextSibling;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-08-14 07:15:54 -07:00
|
|
|
/*static*/ template<class T> void
|
|
|
|
ApplyTransform(gfx::PointTyped<T>* aPoint, const gfx3DMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
gfxPoint result = aMatrix.Transform(gfxPoint(aPoint->x, aPoint->y));
|
|
|
|
aPoint->x = result.x;
|
|
|
|
aPoint->y = result.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ template<class T> void
|
|
|
|
ApplyTransform(gfx::IntPointTyped<T>* aPoint, const gfx3DMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
gfxPoint result = aMatrix.Transform(gfxPoint(aPoint->x, aPoint->y));
|
|
|
|
aPoint->x = NS_lround(result.x);
|
|
|
|
aPoint->y = NS_lround(result.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ApplyTransform(nsIntPoint* aPoint, const gfx3DMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
gfxPoint result = aMatrix.Transform(gfxPoint(aPoint->x, aPoint->y));
|
|
|
|
aPoint->x = NS_lround(result.x);
|
|
|
|
aPoint->y = NS_lround(result.y);
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
nsEventStatus
|
2013-11-10 08:43:17 -08:00
|
|
|
APZCTreeManager::ReceiveInputEvent(const InputData& aEvent,
|
|
|
|
ScrollableLayerGuid* aOutTargetGuid)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
2013-09-12 04:31:34 -07:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
2013-08-14 07:15:54 -07:00
|
|
|
gfx3DMatrix transformToApzc;
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix transformToGecko;
|
2013-07-30 11:03:40 -07:00
|
|
|
switch (aEvent.mInputType) {
|
|
|
|
case MULTITOUCH_INPUT: {
|
|
|
|
const MultiTouchInput& multiTouchInput = aEvent.AsMultiTouchInput();
|
2013-08-21 09:03:02 -07:00
|
|
|
if (multiTouchInput.mType == MultiTouchInput::MULTITOUCH_START) {
|
2014-01-22 06:06:35 -08:00
|
|
|
// MULTITOUCH_START input contains all active touches of the current
|
|
|
|
// session thus resetting mTouchCount.
|
|
|
|
mTouchCount = multiTouchInput.mTouches.Length();
|
2013-08-21 09:03:03 -07:00
|
|
|
mApzcForInputBlock = GetTargetAPZC(ScreenPoint(multiTouchInput.mTouches[0].mScreenPoint));
|
2013-11-29 13:40:21 -08:00
|
|
|
if (multiTouchInput.mTouches.Length() == 1) {
|
|
|
|
// If we have one touch point, this might be the start of a pan.
|
|
|
|
// Prepare for possible overscroll handoff.
|
|
|
|
BuildOverscrollHandoffChain(mApzcForInputBlock);
|
|
|
|
}
|
2013-08-21 09:03:03 -07:00
|
|
|
for (size_t i = 1; i < multiTouchInput.mTouches.Length(); i++) {
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc2 = GetTargetAPZC(ScreenPoint(multiTouchInput.mTouches[i].mScreenPoint));
|
|
|
|
mApzcForInputBlock = CommonAncestor(mApzcForInputBlock.get(), apzc2.get());
|
|
|
|
APZC_LOG("Using APZC %p as the common ancestor\n", mApzcForInputBlock.get());
|
2013-08-22 07:40:44 -07:00
|
|
|
// For now, we only ever want to do pinching on the root APZC for a given layers id. So
|
|
|
|
// when we find the common ancestor of multiple points, also walk up to the root APZC.
|
|
|
|
mApzcForInputBlock = RootAPZCForLayersId(mApzcForInputBlock);
|
|
|
|
APZC_LOG("Using APZC %p as the root APZC for multi-touch\n", mApzcForInputBlock.get());
|
2013-08-21 09:03:03 -07:00
|
|
|
}
|
2013-08-20 16:00:57 -07:00
|
|
|
|
|
|
|
if (mApzcForInputBlock) {
|
2014-01-17 06:53:08 -08:00
|
|
|
// Cache transformToApzc so it can be used for future events in this block.
|
2013-10-31 11:44:33 -07:00
|
|
|
GetInputTransforms(mApzcForInputBlock, transformToApzc, transformToGecko);
|
2013-08-20 16:00:57 -07:00
|
|
|
mCachedTransformToApzcForInputBlock = transformToApzc;
|
2014-01-17 06:53:08 -08:00
|
|
|
} else {
|
|
|
|
// Reset the cached apz transform
|
|
|
|
mCachedTransformToApzcForInputBlock = gfx3DMatrix();
|
2013-08-20 16:00:57 -07:00
|
|
|
}
|
2013-08-21 09:03:03 -07:00
|
|
|
} else if (mApzcForInputBlock) {
|
|
|
|
APZC_LOG("Re-using APZC %p as continuation of event block\n", mApzcForInputBlock.get());
|
2013-08-21 09:03:02 -07:00
|
|
|
}
|
|
|
|
if (mApzcForInputBlock) {
|
2013-11-10 08:43:17 -08:00
|
|
|
mApzcForInputBlock->GetGuid(aOutTargetGuid);
|
2013-08-20 16:00:57 -07:00
|
|
|
// Use the cached transform to compute the point to send to the APZC.
|
|
|
|
// This ensures that the sequence of touch points an APZC sees in an
|
|
|
|
// input block are all in the same coordinate space.
|
|
|
|
transformToApzc = mCachedTransformToApzcForInputBlock;
|
2013-08-14 07:15:54 -07:00
|
|
|
MultiTouchInput inputForApzc(multiTouchInput);
|
2013-08-21 09:03:03 -07:00
|
|
|
for (size_t i = 0; i < inputForApzc.mTouches.Length(); i++) {
|
2013-08-14 07:15:54 -07:00
|
|
|
ApplyTransform(&(inputForApzc.mTouches[i].mScreenPoint), transformToApzc);
|
|
|
|
}
|
2013-09-12 04:31:34 -07:00
|
|
|
result = mApzcForInputBlock->ReceiveInputEvent(inputForApzc);
|
2013-11-07 13:10:29 -08:00
|
|
|
}
|
|
|
|
if (multiTouchInput.mType == MultiTouchInput::MULTITOUCH_CANCEL ||
|
|
|
|
multiTouchInput.mType == MultiTouchInput::MULTITOUCH_END) {
|
|
|
|
if (mTouchCount >= multiTouchInput.mTouches.Length()) {
|
2014-01-22 06:06:35 -08:00
|
|
|
// MULTITOUCH_END input contains only released touches thus decrementing.
|
2013-11-07 13:10:29 -08:00
|
|
|
mTouchCount -= multiTouchInput.mTouches.Length();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Got an unexpected touchend/touchcancel");
|
|
|
|
mTouchCount = 0;
|
|
|
|
}
|
2013-08-22 21:03:43 -07:00
|
|
|
// If we have an mApzcForInputBlock and it's the end of the touch sequence
|
|
|
|
// then null it out so we don't keep a dangling reference and leak things.
|
2013-11-07 13:10:29 -08:00
|
|
|
if (mTouchCount == 0) {
|
2013-08-22 21:03:43 -07:00
|
|
|
mApzcForInputBlock = nullptr;
|
2013-11-21 14:38:00 -08:00
|
|
|
mOverscrollHandoffChain.clear();
|
2013-08-22 21:03:43 -07:00
|
|
|
}
|
2013-08-14 07:15:54 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
break;
|
|
|
|
} case PINCHGESTURE_INPUT: {
|
|
|
|
const PinchGestureInput& pinchInput = aEvent.AsPinchGestureInput();
|
2013-08-21 09:03:03 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(pinchInput.mFocusPoint);
|
2013-08-14 07:15:54 -07:00
|
|
|
if (apzc) {
|
2013-11-10 08:43:17 -08:00
|
|
|
apzc->GetGuid(aOutTargetGuid);
|
2013-10-31 11:44:33 -07:00
|
|
|
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
2013-08-14 07:15:54 -07:00
|
|
|
PinchGestureInput inputForApzc(pinchInput);
|
|
|
|
ApplyTransform(&(inputForApzc.mFocusPoint), transformToApzc);
|
2013-09-12 04:31:34 -07:00
|
|
|
result = apzc->ReceiveInputEvent(inputForApzc);
|
2013-08-14 07:15:54 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
break;
|
|
|
|
} case TAPGESTURE_INPUT: {
|
|
|
|
const TapGestureInput& tapInput = aEvent.AsTapGestureInput();
|
2013-08-21 09:03:03 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(ScreenPoint(tapInput.mPoint));
|
2013-08-14 07:15:54 -07:00
|
|
|
if (apzc) {
|
2013-11-10 08:43:17 -08:00
|
|
|
apzc->GetGuid(aOutTargetGuid);
|
2013-10-31 11:44:33 -07:00
|
|
|
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
2013-08-14 07:15:54 -07:00
|
|
|
TapGestureInput inputForApzc(tapInput);
|
|
|
|
ApplyTransform(&(inputForApzc.mPoint), transformToApzc);
|
2013-09-12 04:31:34 -07:00
|
|
|
result = apzc->ReceiveInputEvent(inputForApzc);
|
2013-08-14 07:15:54 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-12 04:31:34 -07:00
|
|
|
return result;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-11-12 08:56:57 -08:00
|
|
|
already_AddRefed<AsyncPanZoomController>
|
2014-01-17 06:53:08 -08:00
|
|
|
APZCTreeManager::GetTouchInputBlockAPZC(const WidgetTouchEvent& aEvent)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
2014-01-17 06:53:08 -08:00
|
|
|
ScreenPoint point = ScreenPoint(aEvent.touches[0]->mRefPoint.x, aEvent.touches[0]->mRefPoint.y);
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(point);
|
2013-11-29 13:40:21 -08:00
|
|
|
if (aEvent.touches.Length() == 1) {
|
|
|
|
// If we have one touch point, this might be the start of a pan.
|
|
|
|
// Prepare for possible overscroll handoff.
|
|
|
|
BuildOverscrollHandoffChain(apzc);
|
|
|
|
}
|
2013-09-24 14:17:26 -07:00
|
|
|
for (size_t i = 1; i < aEvent.touches.Length(); i++) {
|
2014-01-17 06:53:08 -08:00
|
|
|
point = ScreenPoint(aEvent.touches[i]->mRefPoint.x, aEvent.touches[i]->mRefPoint.y);
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc2 = GetTargetAPZC(point);
|
2013-09-24 14:17:26 -07:00
|
|
|
apzc = CommonAncestor(apzc.get(), apzc2.get());
|
|
|
|
APZC_LOG("Using APZC %p as the common ancestor\n", apzc.get());
|
|
|
|
// For now, we only ever want to do pinching on the root APZC for a given layers id. So
|
|
|
|
// when we find the common ancestor of multiple points, also walk up to the root APZC.
|
|
|
|
apzc = RootAPZCForLayersId(apzc);
|
|
|
|
APZC_LOG("Using APZC %p as the root APZC for multi-touch\n", apzc.get());
|
|
|
|
}
|
2013-11-12 08:56:57 -08:00
|
|
|
return apzc.forget();
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2013-09-26 23:20:57 -07:00
|
|
|
APZCTreeManager::ProcessTouchEvent(const WidgetTouchEvent& aEvent,
|
2013-11-10 08:43:17 -08:00
|
|
|
ScrollableLayerGuid* aOutTargetGuid,
|
2013-09-26 23:20:57 -07:00
|
|
|
WidgetTouchEvent* aOutEvent)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-11-07 13:12:33 -08:00
|
|
|
nsEventStatus ret = nsEventStatus_eIgnore;
|
2013-11-07 13:11:34 -08:00
|
|
|
if (!aEvent.touches.Length()) {
|
2013-11-07 13:12:33 -08:00
|
|
|
return ret;
|
2013-11-07 13:11:34 -08:00
|
|
|
}
|
|
|
|
if (aEvent.message == NS_TOUCH_START) {
|
2014-01-22 06:06:35 -08:00
|
|
|
// NS_TOUCH_START event contains all active touches of the current
|
|
|
|
// session thus resetting mTouchCount.
|
|
|
|
mTouchCount = aEvent.touches.Length();
|
2014-01-17 06:53:08 -08:00
|
|
|
mApzcForInputBlock = GetTouchInputBlockAPZC(aEvent);
|
2014-01-17 06:52:49 -08:00
|
|
|
if (mApzcForInputBlock) {
|
|
|
|
// Cache apz transform so it can be used for future events in this block.
|
|
|
|
gfx3DMatrix transformToGecko;
|
|
|
|
GetInputTransforms(mApzcForInputBlock, mCachedTransformToApzcForInputBlock, transformToGecko);
|
|
|
|
} else {
|
|
|
|
// Reset the cached apz transform
|
|
|
|
mCachedTransformToApzcForInputBlock = gfx3DMatrix();
|
|
|
|
}
|
2013-11-07 13:11:34 -08:00
|
|
|
}
|
2013-09-24 14:17:26 -07:00
|
|
|
|
2013-11-07 13:12:33 -08:00
|
|
|
if (mApzcForInputBlock) {
|
2013-11-10 08:43:17 -08:00
|
|
|
mApzcForInputBlock->GetGuid(aOutTargetGuid);
|
2013-11-07 13:12:33 -08:00
|
|
|
// For computing the input for the APZC, used the cached transform.
|
|
|
|
// This ensures that the sequence of touch points an APZC sees in an
|
|
|
|
// input block are all in the same coordinate space.
|
|
|
|
gfx3DMatrix transformToApzc = mCachedTransformToApzcForInputBlock;
|
|
|
|
MultiTouchInput inputForApzc(aEvent);
|
|
|
|
for (size_t i = 0; i < inputForApzc.mTouches.Length(); i++) {
|
|
|
|
ApplyTransform(&(inputForApzc.mTouches[i].mScreenPoint), transformToApzc);
|
|
|
|
}
|
|
|
|
ret = mApzcForInputBlock->ReceiveInputEvent(inputForApzc);
|
|
|
|
|
|
|
|
// For computing the event to pass back to Gecko, use the up-to-date transforms.
|
|
|
|
// This ensures that transformToApzc and transformToGecko are in sync
|
|
|
|
// (note that transformToGecko isn't cached).
|
|
|
|
gfx3DMatrix transformToGecko;
|
|
|
|
GetInputTransforms(mApzcForInputBlock, transformToApzc, transformToGecko);
|
|
|
|
gfx3DMatrix outTransform = transformToApzc * transformToGecko;
|
|
|
|
for (size_t i = 0; i < aOutEvent->touches.Length(); i++) {
|
|
|
|
ApplyTransform(&(aOutEvent->touches[i]->mRefPoint), outTransform);
|
|
|
|
}
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
// If we have an mApzcForInputBlock and it's the end of the touch sequence
|
|
|
|
// then null it out so we don't keep a dangling reference and leak things.
|
|
|
|
if (aEvent.message == NS_TOUCH_CANCEL ||
|
2013-11-07 13:10:29 -08:00
|
|
|
aEvent.message == NS_TOUCH_END) {
|
|
|
|
if (mTouchCount >= aEvent.touches.Length()) {
|
2014-01-22 06:06:35 -08:00
|
|
|
// NS_TOUCH_END event contains only released touches thus decrementing.
|
2013-11-07 13:10:29 -08:00
|
|
|
mTouchCount -= aEvent.touches.Length();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Got an unexpected touchend/touchcancel");
|
|
|
|
mTouchCount = 0;
|
|
|
|
}
|
|
|
|
if (mTouchCount == 0) {
|
|
|
|
mApzcForInputBlock = nullptr;
|
2013-11-21 14:38:00 -08:00
|
|
|
mOverscrollHandoffChain.clear();
|
2013-11-07 13:10:29 -08:00
|
|
|
}
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-10 08:43:18 -08:00
|
|
|
void
|
|
|
|
APZCTreeManager::TransformCoordinateToGecko(const ScreenIntPoint& aPoint,
|
|
|
|
LayoutDeviceIntPoint* aOutTransformedPoint)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOutTransformedPoint);
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aPoint);
|
|
|
|
if (apzc && aOutTransformedPoint) {
|
|
|
|
gfx3DMatrix transformToApzc;
|
|
|
|
gfx3DMatrix transformToGecko;
|
|
|
|
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
|
|
|
gfx3DMatrix outTransform = transformToApzc * transformToGecko;
|
|
|
|
aOutTransformedPoint->x = aPoint.x;
|
|
|
|
aOutTransformedPoint->y = aPoint.y;
|
|
|
|
ApplyTransform(aOutTransformedPoint, outTransform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
nsEventStatus
|
2013-10-01 23:38:27 -07:00
|
|
|
APZCTreeManager::ProcessMouseEvent(const WidgetMouseEvent& aEvent,
|
2013-11-10 08:43:17 -08:00
|
|
|
ScrollableLayerGuid* aOutTargetGuid,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent* aOutEvent)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(ScreenPoint(aEvent.refPoint.x, aEvent.refPoint.y));
|
|
|
|
if (!apzc) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2013-11-10 08:43:17 -08:00
|
|
|
apzc->GetGuid(aOutTargetGuid);
|
2013-09-24 14:17:26 -07:00
|
|
|
gfx3DMatrix transformToApzc;
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix transformToGecko;
|
|
|
|
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
2013-09-24 14:17:26 -07:00
|
|
|
MultiTouchInput inputForApzc(aEvent);
|
|
|
|
ApplyTransform(&(inputForApzc.mTouches[0].mScreenPoint), transformToApzc);
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix outTransform = transformToApzc * transformToGecko;
|
2013-10-22 01:55:20 -07:00
|
|
|
ApplyTransform(&aOutEvent->refPoint, outTransform);
|
2013-09-24 14:17:26 -07:00
|
|
|
return apzc->ReceiveInputEvent(inputForApzc);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2013-10-01 00:23:02 -07:00
|
|
|
APZCTreeManager::ProcessEvent(const WidgetInputEvent& aEvent,
|
2013-11-10 08:43:17 -08:00
|
|
|
ScrollableLayerGuid* aOutTargetGuid,
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetInputEvent* aOutEvent)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
// Transform the refPoint
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(ScreenPoint(aEvent.refPoint.x, aEvent.refPoint.y));
|
|
|
|
if (!apzc) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2013-11-10 08:43:17 -08:00
|
|
|
apzc->GetGuid(aOutTargetGuid);
|
2013-09-24 14:17:26 -07:00
|
|
|
gfx3DMatrix transformToApzc;
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix transformToGecko;
|
|
|
|
GetInputTransforms(apzc, transformToApzc, transformToGecko);
|
|
|
|
gfx3DMatrix outTransform = transformToApzc * transformToGecko;
|
2013-09-24 14:17:26 -07:00
|
|
|
ApplyTransform(&(aOutEvent->refPoint), outTransform);
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
nsEventStatus
|
2013-10-01 00:23:02 -07:00
|
|
|
APZCTreeManager::ReceiveInputEvent(const WidgetInputEvent& aEvent,
|
2013-11-10 08:43:17 -08:00
|
|
|
ScrollableLayerGuid* aOutTargetGuid,
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetInputEvent* aOutEvent)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
switch (aEvent.eventStructType) {
|
|
|
|
case NS_TOUCH_EVENT: {
|
2013-10-17 23:10:23 -07:00
|
|
|
const WidgetTouchEvent& touchEvent = *aEvent.AsTouchEvent();
|
2013-11-10 08:43:17 -08:00
|
|
|
return ProcessTouchEvent(touchEvent, aOutTargetGuid, aOutEvent->AsTouchEvent());
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
case NS_MOUSE_EVENT: {
|
|
|
|
// For b2g emulation
|
2013-10-22 01:55:20 -07:00
|
|
|
const WidgetMouseEvent& mouseEvent = *aEvent.AsMouseEvent();
|
|
|
|
WidgetMouseEvent* outMouseEvent = aOutEvent->AsMouseEvent();
|
2013-11-10 08:43:17 -08:00
|
|
|
return ProcessMouseEvent(mouseEvent, aOutTargetGuid, outMouseEvent);
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
default: {
|
2013-11-10 08:43:17 -08:00
|
|
|
return ProcessEvent(aEvent, aOutTargetGuid, aOutEvent);
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
nsEventStatus
|
2013-11-10 08:43:17 -08:00
|
|
|
APZCTreeManager::ReceiveInputEvent(WidgetInputEvent& aEvent,
|
|
|
|
ScrollableLayerGuid* aOutTargetGuid)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
switch (aEvent.eventStructType) {
|
|
|
|
case NS_TOUCH_EVENT: {
|
2013-10-17 23:10:23 -07:00
|
|
|
WidgetTouchEvent& touchEvent = *aEvent.AsTouchEvent();
|
2013-11-10 08:43:17 -08:00
|
|
|
return ProcessTouchEvent(touchEvent, aOutTargetGuid, &touchEvent);
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
default: {
|
2013-11-10 08:43:17 -08:00
|
|
|
return ProcessEvent(aEvent, aOutTargetGuid, &aEvent);
|
2013-09-24 14:17:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
void
|
|
|
|
APZCTreeManager::ZoomToRect(const ScrollableLayerGuid& aGuid,
|
|
|
|
const CSSRect& aRect)
|
|
|
|
{
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aGuid);
|
|
|
|
if (apzc) {
|
|
|
|
apzc->ZoomToRect(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::ContentReceivedTouch(const ScrollableLayerGuid& aGuid,
|
|
|
|
bool aPreventDefault)
|
|
|
|
{
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aGuid);
|
|
|
|
if (apzc) {
|
|
|
|
apzc->ContentReceivedTouch(aPreventDefault);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
|
2014-01-06 10:26:44 -08:00
|
|
|
const ZoomConstraints& aConstraints)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aGuid);
|
2013-12-02 15:01:19 -08:00
|
|
|
// For a given layers id, non-root APZCs inherit the zoom constraints
|
|
|
|
// of their root.
|
|
|
|
if (apzc && apzc->IsRootForLayersId()) {
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
2014-01-06 10:26:44 -08:00
|
|
|
UpdateZoomConstraintsRecursively(apzc.get(), aConstraints);
|
2013-12-02 15:01:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::UpdateZoomConstraintsRecursively(AsyncPanZoomController* aApzc,
|
2014-01-06 10:26:44 -08:00
|
|
|
const ZoomConstraints& aConstraints)
|
2013-12-02 15:01:19 -08:00
|
|
|
{
|
|
|
|
mTreeLock.AssertCurrentThreadOwns();
|
|
|
|
|
2014-01-06 10:26:44 -08:00
|
|
|
aApzc->UpdateZoomConstraints(aConstraints);
|
2013-12-02 15:01:19 -08:00
|
|
|
for (AsyncPanZoomController* child = aApzc->GetLastChild(); child; child = child->GetPrevSibling()) {
|
|
|
|
// We can have subtrees with their own layers id - leave those alone.
|
|
|
|
if (!child->IsRootForLayersId()) {
|
2014-01-06 10:26:44 -08:00
|
|
|
UpdateZoomConstraintsRecursively(child, aConstraints);
|
2013-12-02 15:01:19 -08:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::CancelAnimation(const ScrollableLayerGuid &aGuid)
|
|
|
|
{
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(aGuid);
|
|
|
|
if (apzc) {
|
|
|
|
apzc->CancelAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
APZCTreeManager::ClearTree()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
// This can be done as part of a tree walk but it's easier to
|
|
|
|
// just re-use the Collect method that we need in other places.
|
|
|
|
// If this is too slow feel free to change it to a recursive walk.
|
|
|
|
nsTArray< nsRefPtr<AsyncPanZoomController> > apzcsToDestroy;
|
|
|
|
Collect(mRootApzc, &apzcsToDestroy);
|
2013-08-21 09:03:03 -07:00
|
|
|
for (size_t i = 0; i < apzcsToDestroy.Length(); i++) {
|
2013-07-30 11:03:40 -07:00
|
|
|
apzcsToDestroy[i]->Destroy();
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
mRootApzc = nullptr;
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-08-20 16:00:57 -07:00
|
|
|
void
|
2013-11-29 13:40:21 -08:00
|
|
|
APZCTreeManager::DispatchScroll(AsyncPanZoomController* aPrev, ScreenPoint aStartPoint, ScreenPoint aEndPoint,
|
|
|
|
uint32_t aOverscrollHandoffChainIndex)
|
2013-08-20 16:00:57 -07:00
|
|
|
{
|
2013-11-29 13:40:21 -08:00
|
|
|
// If we have reached the end of the overscroll handoff chain, there is
|
|
|
|
// nothing more to scroll, so we ignore the rest of the pan gesture.
|
2013-11-21 14:38:00 -08:00
|
|
|
if (aOverscrollHandoffChainIndex >= mOverscrollHandoffChain.length()) {
|
|
|
|
// Nothing more to scroll - ignore the rest of the pan gesture.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<AsyncPanZoomController> next = mOverscrollHandoffChain[aOverscrollHandoffChainIndex];
|
|
|
|
if (next == nullptr)
|
2013-08-20 16:00:57 -07:00
|
|
|
return;
|
|
|
|
|
2013-11-29 13:40:21 -08:00
|
|
|
// Convert the start and end points from |aPrev|'s coordinate space to
|
|
|
|
// |next|'s coordinate space. Since |aPrev| may be the same as |next|
|
|
|
|
// (if |aPrev| is the APZC that is initiating the scroll and there is no
|
|
|
|
// scroll grabbing to grab the scroll from it), don't bother doing the
|
|
|
|
// transformations in that case.
|
|
|
|
if (next != aPrev) {
|
|
|
|
gfx3DMatrix transformToApzc;
|
|
|
|
gfx3DMatrix transformToGecko; // ignored
|
2013-08-20 16:00:57 -07:00
|
|
|
|
2013-11-29 13:40:21 -08:00
|
|
|
// Convert start and end points to untransformed screen coordinates.
|
|
|
|
GetInputTransforms(aPrev, transformToApzc, transformToGecko);
|
|
|
|
ApplyTransform(&aStartPoint, transformToApzc.Inverse());
|
|
|
|
ApplyTransform(&aEndPoint, transformToApzc.Inverse());
|
2013-08-20 16:00:57 -07:00
|
|
|
|
2013-11-29 13:40:21 -08:00
|
|
|
// Convert start and end points to next's transformed screen coordinates.
|
|
|
|
GetInputTransforms(next, transformToApzc, transformToGecko);
|
|
|
|
ApplyTransform(&aStartPoint, transformToApzc);
|
|
|
|
ApplyTransform(&aEndPoint, transformToApzc);
|
|
|
|
}
|
2013-08-20 16:00:57 -07:00
|
|
|
|
2013-11-29 13:40:21 -08:00
|
|
|
// Scroll |next|. If this causes overscroll, it will call DispatchScroll()
|
|
|
|
// again with an incremented index.
|
2013-11-21 14:38:00 -08:00
|
|
|
next->AttemptScroll(aStartPoint, aEndPoint, aOverscrollHandoffChainIndex);
|
2013-08-20 16:00:57 -07:00
|
|
|
}
|
|
|
|
|
2014-02-07 11:11:32 -08:00
|
|
|
bool
|
|
|
|
APZCTreeManager::FlushRepaintsForOverscrollHandoffChain()
|
|
|
|
{
|
|
|
|
if (mOverscrollHandoffChain.length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < mOverscrollHandoffChain.length(); i++) {
|
|
|
|
nsRefPtr<AsyncPanZoomController> item = mOverscrollHandoffChain[i];
|
|
|
|
if (item) {
|
|
|
|
item->FlushRepaintForOverscrollHandoff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
bool
|
2013-11-10 08:43:18 -08:00
|
|
|
APZCTreeManager::HitTestAPZC(const ScreenIntPoint& aPoint)
|
2013-09-24 14:17:26 -07:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
|
|
|
nsRefPtr<AsyncPanZoomController> target;
|
|
|
|
// The root may have siblings, so check those too
|
|
|
|
gfxPoint point(aPoint.x, aPoint.y);
|
|
|
|
for (AsyncPanZoomController* apzc = mRootApzc; apzc; apzc = apzc->GetPrevSibling()) {
|
|
|
|
target = GetAPZCAtPoint(apzc, point);
|
|
|
|
if (target) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
already_AddRefed<AsyncPanZoomController>
|
|
|
|
APZCTreeManager::GetTargetAPZC(const ScrollableLayerGuid& aGuid)
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
2013-07-30 11:03:40 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> target;
|
|
|
|
// The root may have siblings, check those too
|
|
|
|
for (AsyncPanZoomController* apzc = mRootApzc; apzc; apzc = apzc->GetPrevSibling()) {
|
|
|
|
target = FindTargetAPZC(apzc, aGuid);
|
|
|
|
if (target) {
|
|
|
|
break;
|
|
|
|
}
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:38:00 -08:00
|
|
|
struct CompareByScrollPriority
|
|
|
|
{
|
|
|
|
bool operator()(const nsRefPtr<AsyncPanZoomController>& a, const nsRefPtr<AsyncPanZoomController>& b) {
|
|
|
|
return a->HasScrollgrab() && !b->HasScrollgrab();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
already_AddRefed<AsyncPanZoomController>
|
2013-08-21 09:03:03 -07:00
|
|
|
APZCTreeManager::GetTargetAPZC(const ScreenPoint& aPoint)
|
2013-07-30 11:03:40 -07:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mTreeLock);
|
2013-07-30 11:03:41 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> target;
|
|
|
|
// The root may have siblings, so check those too
|
|
|
|
gfxPoint point(aPoint.x, aPoint.y);
|
|
|
|
for (AsyncPanZoomController* apzc = mRootApzc; apzc; apzc = apzc->GetPrevSibling()) {
|
2013-08-21 09:03:02 -07:00
|
|
|
target = GetAPZCAtPoint(apzc, point);
|
2013-07-30 11:03:41 -07:00
|
|
|
if (target) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target.forget();
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
|
2013-11-29 13:40:21 -08:00
|
|
|
void
|
|
|
|
APZCTreeManager::BuildOverscrollHandoffChain(const nsRefPtr<AsyncPanZoomController>& aInitialTarget)
|
2013-11-21 14:38:00 -08:00
|
|
|
{
|
|
|
|
// Scroll grabbing is a mechanism that allows content to specify that
|
|
|
|
// the initial target of a pan should be not the innermost scrollable
|
|
|
|
// frame at the touch point (which is what GetTargetAPZC finds), but
|
|
|
|
// something higher up in the tree.
|
|
|
|
// It's not sufficient to just find the initial target, however, as
|
|
|
|
// overscroll can be handed off to another APZC. Without scroll grabbing,
|
|
|
|
// handoff just occurs from child to parent. With scroll grabbing, the
|
|
|
|
// handoff order can be different, so we build a chain of APZCs in the
|
|
|
|
// order in which scroll will be handed off to them.
|
|
|
|
|
|
|
|
mOverscrollHandoffChain.clear();
|
|
|
|
|
|
|
|
// Start with the child -> parent chain.
|
|
|
|
for (AsyncPanZoomController* apzc = aInitialTarget; apzc; apzc = apzc->GetParent()) {
|
|
|
|
if (!mOverscrollHandoffChain.append(apzc)) {
|
|
|
|
NS_WARNING("Vector::append failed");
|
|
|
|
mOverscrollHandoffChain.clear();
|
2013-11-29 13:40:21 -08:00
|
|
|
return;
|
2013-11-21 14:38:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now adjust the chain to account for scroll grabbing. Sorting is a bit
|
|
|
|
// of an overkill here, but scroll grabbing will likely be generalized
|
|
|
|
// to scroll priorities, so we might as well do it this way.
|
|
|
|
// The sorting being stable ensures that the relative order between
|
|
|
|
// non-scrollgrabbing APZCs remains child -> parent.
|
|
|
|
// (The relative order between scrollgrabbing APZCs will also remain
|
|
|
|
// child -> parent, though that's just an artefact of the implementation
|
|
|
|
// and users of 'scrollgrab' should not rely on this.)
|
|
|
|
std::stable_sort(mOverscrollHandoffChain.begin(), mOverscrollHandoffChain.end(),
|
|
|
|
CompareByScrollPriority());
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController*
|
2013-11-13 10:20:31 -08:00
|
|
|
APZCTreeManager::FindTargetAPZC(AsyncPanZoomController* aApzc, const ScrollableLayerGuid& aGuid)
|
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
mTreeLock.AssertCurrentThreadOwns();
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
// This walks the tree in depth-first, reverse order, so that it encounters
|
|
|
|
// APZCs front-to-back on the screen.
|
|
|
|
for (AsyncPanZoomController* child = aApzc->GetLastChild(); child; child = child->GetPrevSibling()) {
|
|
|
|
AsyncPanZoomController* match = FindTargetAPZC(child, aGuid);
|
|
|
|
if (match) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aApzc->Matches(aGuid)) {
|
|
|
|
return aApzc;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:41 -07:00
|
|
|
AsyncPanZoomController*
|
2013-08-21 09:03:02 -07:00
|
|
|
APZCTreeManager::GetAPZCAtPoint(AsyncPanZoomController* aApzc, const gfxPoint& aHitTestPoint)
|
2013-07-30 11:03:41 -07:00
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
mTreeLock.AssertCurrentThreadOwns();
|
|
|
|
|
2013-08-14 07:15:54 -07:00
|
|
|
// The comments below assume there is a chain of layers L..R with L and P having APZC instances as
|
2013-08-21 09:03:03 -07:00
|
|
|
// explained in the comment on GetInputTransforms. This function will recurse with aApzc at L and P, and the
|
2013-08-14 07:15:54 -07:00
|
|
|
// comments explain what values are stored in the variables at these two levels. All the comments
|
|
|
|
// use standard matrix notation where the leftmost matrix in a multiplication is applied first.
|
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
// ancestorUntransform takes points from aApzc's parent APZC's layer coordinates
|
2013-10-30 12:58:25 -07:00
|
|
|
// to aApzc's screen coordinates.
|
|
|
|
// It is OC.Inverse() * NC.Inverse() * MC.Inverse() at recursion level for L,
|
|
|
|
// and RC.Inverse() * QC.Inverse() at recursion level for P.
|
2013-08-14 07:15:54 -07:00
|
|
|
gfx3DMatrix ancestorUntransform = aApzc->GetAncestorTransform().Inverse();
|
2013-10-30 12:58:25 -07:00
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
// hitTestTransform takes points from aApzc's parent APZC's layer coordinates to
|
|
|
|
// the hit test space (which is aApzc's transient coordinates).
|
|
|
|
// It is OC.Inverse() * NC.Inverse() * MC.Inverse() * LC.Inverse() * LN.Inverse() at L,
|
|
|
|
// and RC.Inverse() * QC.Inverse() * PC.Inverse() * PN.Inverse() at P.
|
|
|
|
gfx3DMatrix hitTestTransform = ancestorUntransform
|
|
|
|
* aApzc->GetCSSTransform().Inverse()
|
|
|
|
* aApzc->GetNontransientAsyncTransform().Inverse();
|
|
|
|
gfxPoint hitTestPointForThisLayer = hitTestTransform.ProjectPoint(aHitTestPoint);
|
|
|
|
APZC_LOG("Untransformed %f %f to transient coordinates %f %f for hit-testing APZC %p\n",
|
2013-10-30 12:58:25 -07:00
|
|
|
aHitTestPoint.x, aHitTestPoint.y,
|
|
|
|
hitTestPointForThisLayer.x, hitTestPointForThisLayer.y, aApzc);
|
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
// childUntransform takes points from aApzc's parent APZC's layer coordinates
|
2013-10-30 12:58:25 -07:00
|
|
|
// to aApzc's layer coordinates (which are aApzc's children's screen coordinates).
|
2013-11-08 10:56:31 -08:00
|
|
|
// It is OC.Inverse() * NC.Inverse() * MC.Inverse() * LC.Inverse() * LA.Inverse() at L
|
|
|
|
// and RC.Inverse() * QC.Inverse() * PC.Inverse() * PA.Inverse() at P.
|
|
|
|
gfx3DMatrix childUntransform = ancestorUntransform
|
|
|
|
* aApzc->GetCSSTransform().Inverse()
|
|
|
|
* gfx3DMatrix(aApzc->GetCurrentAsyncTransform()).Inverse();
|
|
|
|
gfxPoint hitTestPointForChildLayers = childUntransform.ProjectPoint(aHitTestPoint);
|
2013-10-30 12:58:25 -07:00
|
|
|
APZC_LOG("Untransformed %f %f to layer coordinates %f %f for APZC %p\n",
|
|
|
|
aHitTestPoint.x, aHitTestPoint.y,
|
|
|
|
hitTestPointForChildLayers.x, hitTestPointForChildLayers.y, aApzc);
|
2013-08-06 13:20:14 -07:00
|
|
|
|
2013-07-30 11:03:41 -07:00
|
|
|
// This walks the tree in depth-first, reverse order, so that it encounters
|
|
|
|
// APZCs front-to-back on the screen.
|
|
|
|
for (AsyncPanZoomController* child = aApzc->GetLastChild(); child; child = child->GetPrevSibling()) {
|
2013-10-30 12:58:25 -07:00
|
|
|
AsyncPanZoomController* match = GetAPZCAtPoint(child, hitTestPointForChildLayers);
|
2013-07-30 11:03:41 -07:00
|
|
|
if (match) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 12:58:25 -07:00
|
|
|
if (aApzc->VisibleRegionContains(ScreenPoint(hitTestPointForThisLayer.x, hitTestPointForThisLayer.y))) {
|
|
|
|
APZC_LOG("Successfully matched untransformed point %f %f to visible region for APZC %p\n",
|
|
|
|
hitTestPointForThisLayer.x, hitTestPointForThisLayer.y, aApzc);
|
2013-07-30 11:03:41 -07:00
|
|
|
return aApzc;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-31 11:44:33 -07:00
|
|
|
/* This function sets the aTransformToApzcOut and aTransformToGeckoOut out-parameters
|
2013-08-21 09:03:03 -07:00
|
|
|
to some useful transformations that input events may need applied. This is best
|
|
|
|
illustrated with an example. Consider a chain of layers, L, M, N, O, P, Q, R. Layer L
|
2014-01-21 13:27:20 -08:00
|
|
|
is the layer that corresponds to the argument |aApzc|, and layer R is the root
|
2013-08-21 09:03:03 -07:00
|
|
|
of the layer tree. Layer M is the parent of L, N is the parent of M, and so on.
|
|
|
|
When layer L is displayed to the screen by the compositor, the set of transforms that
|
|
|
|
are applied to L are (in order from top to bottom):
|
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
L's transient async transform (hereafter referred to as transform matrix LT)
|
|
|
|
L's nontransient async transform (hereafter referred to as transform matrix LN)
|
|
|
|
L's CSS transform (hereafter referred to as transform matrix LC)
|
|
|
|
M's transient async transform (hereafter referred to as transform matrix MT)
|
|
|
|
M's nontransient async transform (hereafter referred to as transform matrix MN)
|
|
|
|
M's CSS transform (hereafter referred to as transform matrix MC)
|
2013-08-21 09:03:03 -07:00
|
|
|
...
|
2013-11-08 10:56:31 -08:00
|
|
|
R's transient async transform (hereafter referred to as transform matrix RT)
|
|
|
|
R's nontransient async transform (hereafter referred to as transform matrix RN)
|
|
|
|
R's CSS transform (hereafter referred to as transform matrix RC)
|
|
|
|
|
|
|
|
Also, for any layer, the async transform is the combination of its transient and non-transient
|
|
|
|
parts. That is, for any layer L:
|
|
|
|
LA === LT * LN
|
|
|
|
LA.Inverse() === LN.Inverse() * LT.Inverse()
|
|
|
|
|
|
|
|
If we want user input to modify L's transient async transform, we have to first convert
|
|
|
|
user input from screen space to the coordinate space of L's transient async transform. Doing
|
|
|
|
this involves applying the following transforms (in order from top to bottom):
|
2013-08-21 09:03:03 -07:00
|
|
|
RC.Inverse()
|
2013-11-08 10:56:31 -08:00
|
|
|
RN.Inverse()
|
|
|
|
RT.Inverse()
|
2013-08-21 09:03:03 -07:00
|
|
|
...
|
|
|
|
MC.Inverse()
|
2013-11-08 10:56:31 -08:00
|
|
|
MN.Inverse()
|
|
|
|
MT.Inverse()
|
|
|
|
LC.Inverse()
|
|
|
|
LN.Inverse()
|
2013-08-21 09:03:03 -07:00
|
|
|
This combined transformation is returned in the aTransformToApzcOut out-parameter.
|
|
|
|
|
|
|
|
Next, if we want user inputs sent to gecko for event-dispatching, we will need to strip
|
|
|
|
out all of the async transforms that are involved in this chain. This is because async
|
|
|
|
transforms are stored only in the compositor and gecko does not account for them when
|
2014-01-21 13:27:20 -08:00
|
|
|
doing display-list-based hit-testing for event dispatching.
|
|
|
|
Furthermore, because these input events are processed by Gecko in a FIFO queue that
|
|
|
|
includes other things (specifically paint requests), it is possible that by time the
|
|
|
|
input event reaches gecko, it will have painted something else. Therefore, we need to
|
|
|
|
apply another transform to the input events to account for the possible disparity between
|
|
|
|
what we know gecko last painted and the last paint request we sent to gecko. Let this
|
|
|
|
transform be represented by LD, MD, ... RD.
|
|
|
|
Therefore, given a user input in screen space, the following transforms need to be applied
|
|
|
|
(in order from top to bottom):
|
2013-08-21 09:03:03 -07:00
|
|
|
RC.Inverse()
|
2013-11-08 10:56:31 -08:00
|
|
|
RN.Inverse()
|
|
|
|
RT.Inverse()
|
2013-08-21 09:03:03 -07:00
|
|
|
...
|
|
|
|
MC.Inverse()
|
2013-11-08 10:56:31 -08:00
|
|
|
MN.Inverse()
|
|
|
|
MT.Inverse()
|
2013-08-21 09:03:03 -07:00
|
|
|
LC.Inverse()
|
2013-11-08 10:56:31 -08:00
|
|
|
LN.Inverse()
|
|
|
|
LT.Inverse()
|
2014-01-21 13:27:20 -08:00
|
|
|
LD
|
2013-08-21 09:03:03 -07:00
|
|
|
LC
|
2014-01-21 13:27:20 -08:00
|
|
|
MD
|
2013-08-21 09:03:03 -07:00
|
|
|
MC
|
|
|
|
...
|
2014-01-21 13:27:20 -08:00
|
|
|
RD
|
2013-08-21 09:03:03 -07:00
|
|
|
RC
|
|
|
|
This sequence can be simplified and refactored to the following:
|
|
|
|
aTransformToApzcOut
|
2013-11-08 10:56:31 -08:00
|
|
|
LT.Inverse()
|
2014-01-21 13:27:20 -08:00
|
|
|
LD
|
2013-11-08 10:56:31 -08:00
|
|
|
LC
|
2014-01-21 13:27:20 -08:00
|
|
|
MD
|
2013-08-21 09:03:03 -07:00
|
|
|
MC
|
|
|
|
...
|
2014-01-21 13:27:20 -08:00
|
|
|
RD
|
2013-08-21 09:03:03 -07:00
|
|
|
RC
|
2013-10-31 11:44:33 -07:00
|
|
|
Since aTransformToApzcOut is already one of the out-parameters, we set aTransformToGeckoOut
|
2014-01-21 13:27:20 -08:00
|
|
|
to the remaining transforms (LT.Inverse() * LD * ... * RC), so that the caller code can
|
2013-08-21 09:03:03 -07:00
|
|
|
combine it with aTransformToApzcOut to get the final transform required in this case.
|
|
|
|
|
|
|
|
Note that for many of these layers, there will be no AsyncPanZoomController attached, and
|
|
|
|
so the async transform will be the identity transform. So, in the example above, if layers
|
2014-01-21 13:27:20 -08:00
|
|
|
L and P have APZC instances attached, MT, MN, MD, NT, NN, ND, OT, ON, OD, QT, QN, QD, RT,
|
|
|
|
RN and RD will be identity transforms.
|
2013-11-08 10:56:31 -08:00
|
|
|
Additionally, for space-saving purposes, each APZC instance stores its layer's individual
|
2013-08-21 09:03:03 -07:00
|
|
|
CSS transform and the accumulation of CSS transforms to its parent APZC. So the APZC for
|
|
|
|
layer L would store LC and (MC * NC * OC), and the layer P would store PC and (QC * RC).
|
2014-01-21 13:27:20 -08:00
|
|
|
The APZC instances track the last dispatched paint request and so are able to calculate LD and
|
|
|
|
PD using those internally stored values.
|
2013-11-08 10:56:31 -08:00
|
|
|
The APZCs also obviously have LT, LN, PT, and PN, so all of the above transformation combinations
|
2013-08-21 09:03:03 -07:00
|
|
|
required can be generated.
|
|
|
|
*/
|
2013-08-21 09:03:02 -07:00
|
|
|
void
|
|
|
|
APZCTreeManager::GetInputTransforms(AsyncPanZoomController *aApzc, gfx3DMatrix& aTransformToApzcOut,
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix& aTransformToGeckoOut)
|
2013-08-21 09:03:02 -07:00
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MonitorAutoLock lock(mTreeLock);
|
|
|
|
|
2013-08-21 09:03:02 -07:00
|
|
|
// The comments below assume there is a chain of layers L..R with L and P having APZC instances as
|
2013-08-21 09:03:03 -07:00
|
|
|
// explained in the comment above. This function is called with aApzc at L, and the loop
|
2013-08-21 09:03:02 -07:00
|
|
|
// below performs one iteration, where parent is at P. The comments explain what values are stored
|
|
|
|
// in the variables at these two levels. All the comments use standard matrix notation where the
|
|
|
|
// leftmost matrix in a multiplication is applied first.
|
|
|
|
|
|
|
|
// ancestorUntransform is OC.Inverse() * NC.Inverse() * MC.Inverse()
|
|
|
|
gfx3DMatrix ancestorUntransform = aApzc->GetAncestorTransform().Inverse();
|
|
|
|
// asyncUntransform is LA.Inverse()
|
|
|
|
gfx3DMatrix asyncUntransform = gfx3DMatrix(aApzc->GetCurrentAsyncTransform()).Inverse();
|
2013-11-08 10:56:31 -08:00
|
|
|
// nontransientAsyncTransform is LN
|
|
|
|
gfx3DMatrix nontransientAsyncTransform = aApzc->GetNontransientAsyncTransform();
|
|
|
|
// transientAsyncUntransform is LT.Inverse()
|
|
|
|
gfx3DMatrix transientAsyncUntransform = nontransientAsyncTransform * asyncUntransform;
|
2013-08-21 09:03:02 -07:00
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
// aTransformToApzcOut is initialized to OC.Inverse() * NC.Inverse() * MC.Inverse() * LC.Inverse() * LN.Inverse()
|
|
|
|
aTransformToApzcOut = ancestorUntransform * aApzc->GetCSSTransform().Inverse() * nontransientAsyncTransform.Inverse();
|
2014-01-21 13:27:20 -08:00
|
|
|
// aTransformToGeckoOut is initialized to LT.Inverse() * LD * LC * MC * NC * OC
|
|
|
|
aTransformToGeckoOut = transientAsyncUntransform * aApzc->GetTransformToLastDispatchedPaint() * aApzc->GetCSSTransform() * aApzc->GetAncestorTransform();
|
2013-08-21 09:03:02 -07:00
|
|
|
|
|
|
|
for (AsyncPanZoomController* parent = aApzc->GetParent(); parent; parent = parent->GetParent()) {
|
|
|
|
// ancestorUntransform is updated to RC.Inverse() * QC.Inverse() when parent == P
|
|
|
|
ancestorUntransform = parent->GetAncestorTransform().Inverse();
|
|
|
|
// asyncUntransform is updated to PA.Inverse() when parent == P
|
|
|
|
asyncUntransform = gfx3DMatrix(parent->GetCurrentAsyncTransform()).Inverse();
|
2013-11-08 10:56:31 -08:00
|
|
|
// untransformSinceLastApzc is RC.Inverse() * QC.Inverse() * PC.Inverse() * PA.Inverse()
|
|
|
|
gfx3DMatrix untransformSinceLastApzc = ancestorUntransform * parent->GetCSSTransform().Inverse() * asyncUntransform;
|
2013-08-21 09:03:02 -07:00
|
|
|
|
2013-11-08 10:56:31 -08:00
|
|
|
// aTransformToApzcOut is RC.Inverse() * QC.Inverse() * PC.Inverse() * PA.Inverse() * OC.Inverse() * NC.Inverse() * MC.Inverse() * LC.Inverse() * LN.Inverse()
|
2013-08-21 09:03:02 -07:00
|
|
|
aTransformToApzcOut = untransformSinceLastApzc * aTransformToApzcOut;
|
2014-01-21 13:27:20 -08:00
|
|
|
// aTransformToGeckoOut is LT.Inverse() * LD * LC * MC * NC * OC * PD * PC * QC * RC
|
|
|
|
aTransformToGeckoOut = aTransformToGeckoOut * parent->GetTransformToLastDispatchedPaint() * parent->GetCSSTransform() * parent->GetAncestorTransform();
|
2013-08-21 09:03:02 -07:00
|
|
|
|
2013-10-31 11:44:33 -07:00
|
|
|
// The above values for aTransformToApzcOut and aTransformToGeckoOut when parent == P match
|
2014-01-21 13:27:20 -08:00
|
|
|
// the required output as explained in the comment above this method. Note that any missing
|
|
|
|
// terms are guaranteed to be identity transforms.
|
2013-08-21 09:03:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 08:56:57 -08:00
|
|
|
already_AddRefed<AsyncPanZoomController>
|
2013-08-21 09:03:03 -07:00
|
|
|
APZCTreeManager::CommonAncestor(AsyncPanZoomController* aApzc1, AsyncPanZoomController* aApzc2)
|
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MonitorAutoLock lock(mTreeLock);
|
|
|
|
nsRefPtr<AsyncPanZoomController> ancestor;
|
|
|
|
|
2013-08-21 09:03:03 -07:00
|
|
|
// If either aApzc1 or aApzc2 is null, min(depth1, depth2) will be 0 and this function
|
|
|
|
// will return null.
|
|
|
|
|
|
|
|
// Calculate depth of the APZCs in the tree
|
|
|
|
int depth1 = 0, depth2 = 0;
|
|
|
|
for (AsyncPanZoomController* parent = aApzc1; parent; parent = parent->GetParent()) {
|
|
|
|
depth1++;
|
|
|
|
}
|
|
|
|
for (AsyncPanZoomController* parent = aApzc2; parent; parent = parent->GetParent()) {
|
|
|
|
depth2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At most one of the following two loops will be executed; the deeper APZC pointer
|
|
|
|
// will get walked up to the depth of the shallower one.
|
|
|
|
int minDepth = depth1 < depth2 ? depth1 : depth2;
|
|
|
|
while (depth1 > minDepth) {
|
|
|
|
depth1--;
|
|
|
|
aApzc1 = aApzc1->GetParent();
|
|
|
|
}
|
|
|
|
while (depth2 > minDepth) {
|
|
|
|
depth2--;
|
|
|
|
aApzc2 = aApzc2->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk up the ancestor chains of both APZCs, always staying at the same depth for
|
|
|
|
// either APZC, and return the the first common ancestor encountered.
|
|
|
|
while (true) {
|
|
|
|
if (aApzc1 == aApzc2) {
|
2013-11-12 08:56:57 -08:00
|
|
|
ancestor = aApzc1;
|
|
|
|
break;
|
2013-08-21 09:03:03 -07:00
|
|
|
}
|
|
|
|
if (depth1 <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aApzc1 = aApzc1->GetParent();
|
|
|
|
aApzc2 = aApzc2->GetParent();
|
|
|
|
}
|
2013-11-12 08:56:57 -08:00
|
|
|
return ancestor.forget();
|
2013-08-21 09:03:03 -07:00
|
|
|
}
|
|
|
|
|
2013-11-12 08:56:57 -08:00
|
|
|
already_AddRefed<AsyncPanZoomController>
|
2013-08-22 07:40:44 -07:00
|
|
|
APZCTreeManager::RootAPZCForLayersId(AsyncPanZoomController* aApzc)
|
|
|
|
{
|
2013-11-12 08:56:57 -08:00
|
|
|
MonitorAutoLock lock(mTreeLock);
|
|
|
|
nsRefPtr<AsyncPanZoomController> apzc = aApzc;
|
|
|
|
while (apzc && !apzc->IsRootForLayersId()) {
|
|
|
|
apzc = apzc->GetParent();
|
2013-08-22 07:40:44 -07:00
|
|
|
}
|
2013-11-12 08:56:57 -08:00
|
|
|
return apzc.forget();
|
2013-08-22 07:40:44 -07:00
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
|
|
|
}
|