Bug 1382682 - Move ViewIDForASR into nsLayoutUtils for reuse. r?mstange
MozReview-Commit-ID: IcYqDO1D2SB
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -830,16 +830,23 @@ nsLayoutUtils::FindContentFor(ViewID aId
if (exists) {
return content;
} else {
return nullptr;
}
}
+ViewID
+nsLayoutUtils::ViewIDForASR(const mozilla::ActiveScrolledRoot* aASR)
+{
+ nsIContent* content = aASR->mScrollableFrame->GetScrolledFrame()->GetContent();
+ return nsLayoutUtils::FindOrCreateIDFor(content);
+}
+
nsIFrame*
GetScrollFrameFromContent(nsIContent* aContent)
{
nsIFrame* frame = aContent->GetPrimaryFrame();
if (aContent->OwnerDoc()->GetRootElement() == aContent) {
nsIPresShell* presShell = frame ? frame->PresContext()->PresShell() : nullptr;
if (!presShell) {
presShell = aContent->OwnerDoc()->GetShell();
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -67,16 +67,17 @@ namespace mozilla {
enum class CSSPseudoElementType : uint8_t;
class EventListenerManager;
enum class LayoutFrameType : uint8_t;
struct IntrinsicSize;
struct ContainerLayerParameters;
class WritingMode;
class DisplayItemClip;
class EffectSet;
+struct ActiveScrolledRoot;
namespace dom {
class CanvasRenderingContext2D;
class DOMRectList;
class Element;
class HTMLImageElement;
class HTMLCanvasElement;
class HTMLVideoElement;
class OffscreenCanvas;
@@ -179,16 +180,22 @@ public:
static ViewID FindOrCreateIDFor(nsIContent* aContent);
/**
* Find content for given ID.
*/
static nsIContent* FindContentFor(ViewID aId);
/**
+ * Find the view ID (or generate a new one) for the content element
+ * corresponding to the ASR.
+ */
+ static ViewID ViewIDForASR(const mozilla::ActiveScrolledRoot* aASR);
+
+ /**
* Find the scrollable frame for a given ID.
*/
static nsIScrollableFrame* FindScrollableFrameFor(ViewID aId);
/**
* Find the ID for a given scrollable frame.
*/
static ViewID FindIDForScrollableFrame(nsIScrollableFrame* aScrollable);
--- a/layout/painting/FrameLayerBuilder.cpp
+++ b/layout/painting/FrameLayerBuilder.cpp
@@ -4981,23 +4981,16 @@ FindDirectChildASR(const ActiveScrolledR
const ActiveScrolledRoot* directChild = aDescendant;
while (directChild->mParent != aParent) {
directChild = directChild->mParent;
MOZ_RELEASE_ASSERT(directChild, "this must not be null");
}
return directChild;
}
-static FrameMetrics::ViewID
-ViewIDForASR(const ActiveScrolledRoot* aASR)
-{
- nsIContent* content = aASR->mScrollableFrame->GetScrolledFrame()->GetContent();
- return nsLayoutUtils::FindOrCreateIDFor(content);
-}
-
static void
FixUpFixedPositionLayer(Layer* aLayer,
const ActiveScrolledRoot* aTargetASR,
const ActiveScrolledRoot* aLeafScrollMetadataASR,
const ActiveScrolledRoot* aContainerScrollMetadataASR,
const ActiveScrolledRoot* aContainerCompositorASR,
bool aIsFixedToRootScrollFrame)
{
@@ -5036,17 +5029,17 @@ FixUpFixedPositionLayer(Layer* aLayer,
aLeafScrollMetadataASR == aContainerScrollMetadataASR
? aContainerCompositorASR
: aLeafScrollMetadataASR;
// The goal of the annotation is to have the layer move with aTargetASR.
if (compositorASR && aTargetASR != compositorASR) {
// Mark this layer as fixed with respect to the child scroll frame of aTargetASR.
aLayer->SetFixedPositionData(
- ViewIDForASR(FindDirectChildASR(aTargetASR, compositorASR)),
+ nsLayoutUtils::ViewIDForASR(FindDirectChildASR(aTargetASR, compositorASR)),
aLayer->GetFixedPositionAnchor(),
aLayer->GetFixedPositionSides());
} else {
// Remove the fixed annotation from the layer, unless this layers is fixed
// to the document's root scroll frame - in that case, the annotation is
// needed for hit testing, because fixed layers in iframes should scroll
// the iframe, even though their position is not affected by scrolling in
// the iframe. (The APZ hit testing code has a special case for this.)