diff --git a/gfx/layers/composite/APZCTreeManager.cpp b/gfx/layers/composite/APZCTreeManager.cpp index c4a669562d52..2fa3a7cc1b1a 100644 --- a/gfx/layers/composite/APZCTreeManager.cpp +++ b/gfx/layers/composite/APZCTreeManager.cpp @@ -121,6 +121,22 @@ APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor, apzc = container->GetAsyncPanZoomController(); + // 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; + } + } + } + // 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 diff --git a/gfx/layers/ipc/AsyncPanZoomController.cpp b/gfx/layers/ipc/AsyncPanZoomController.cpp index 6f2f8fc32af0..e46e8fa0b3d2 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.cpp +++ b/gfx/layers/ipc/AsyncPanZoomController.cpp @@ -1535,9 +1535,7 @@ void AsyncPanZoomController::UpdateScrollOffset(const CSSPoint& aScrollOffset) bool AsyncPanZoomController::Matches(const ScrollableLayerGuid& aGuid) { - // TODO: also check the presShellId, once that is fully propagated - // everywhere in RenderFrameParent and AndroidJNI. - return aGuid.mLayersId == mLayersId && aGuid.mScrollId == mFrameMetrics.mScrollId; + return aGuid == ScrollableLayerGuid(mLayersId, mFrameMetrics); } void AsyncPanZoomController::GetGuid(ScrollableLayerGuid* aGuidOut)