Bug 1194851 - Add helper functions HasDisplayPort() and HasCriticalDisplayPort(). r=kats
This makes it clearer whether we're just checking if a displayport exists,
or we're actually consuming its value.
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -157,17 +157,17 @@ static void
SetDisplayPortMargins(nsIPresShell* aPresShell,
nsIContent* aContent,
const FrameMetrics& aMetrics)
{
if (!aContent) {
return;
}
- bool hadDisplayPort = nsLayoutUtils::GetDisplayPort(aContent);
+ bool hadDisplayPort = nsLayoutUtils::HasDisplayPort(aContent);
ScreenMargin margins = aMetrics.GetDisplayPortMargins();
nsLayoutUtils::SetDisplayPortMargins(aContent, aPresShell, margins, 0);
if (!hadDisplayPort) {
nsLayoutUtils::SetZeroMarginDisplayPortOnAsyncScrollableAncestors(
aContent->GetPrimaryFrame(), nsLayoutUtils::RepaintMode::Repaint);
}
CSSRect baseCSS = aMetrics.CalculateCompositedRectInCssPixels();
@@ -227,17 +227,17 @@ APZCCallbackHelper::UpdateRootFrame(Fram
* aMetrics.GetAsyncZoom().scale;
shell->SetResolutionAndScaleTo(presShellResolution);
}
// Do this as late as possible since scrolling can flush layout. It also
// adjusts the display port margins, so do it before we set those.
ScrollFrame(content, aMetrics);
- MOZ_ASSERT(nsLayoutUtils::GetDisplayPort(content));
+ MOZ_ASSERT(nsLayoutUtils::HasDisplayPort(content));
SetDisplayPortMargins(shell, content, aMetrics);
}
void
APZCCallbackHelper::UpdateSubFrame(FrameMetrics& aMetrics)
{
if (aMetrics.GetScrollId() == FrameMetrics::NULL_SCROLL_ID) {
return;
@@ -636,17 +636,17 @@ PrepareForSetTargetAPZCNotification(nsIW
APZCCH_LOG("For event at %s found scrollable element %p (%s)\n",
Stringify(aRefPoint).c_str(), dpElement.get(),
NS_LossyConvertUTF16toASCII(dpElementDesc).get());
bool guidIsValid = APZCCallbackHelper::GetOrCreateScrollIdentifiers(
dpElement, &(guid.mPresShellId), &(guid.mScrollId));
aTargets->AppendElement(guid);
- if (!guidIsValid || nsLayoutUtils::GetDisplayPort(dpElement, nullptr)) {
+ if (!guidIsValid || nsLayoutUtils::HasDisplayPort(dpElement)) {
return false;
}
if (!scrollAncestor) {
MOZ_ASSERT(false); // If you hit this, please file a bug with STR.
// Attempt some sort of graceful handling based on a theory as to why we
// reach this point...
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -217,17 +217,17 @@ MobileViewportManager::UpdateSPCSPS(cons
MVM_LOG("%p: Setting SPCSPS %s\n", this, Stringify(compSize).c_str());
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(mPresShell, compSize);
}
void
MobileViewportManager::UpdateDisplayPortMargins()
{
if (nsIFrame* root = mPresShell->GetRootScrollFrame()) {
- bool hasDisplayPort = nsLayoutUtils::GetDisplayPort(root->GetContent(), nullptr);
+ bool hasDisplayPort = nsLayoutUtils::HasDisplayPort(root->GetContent());
bool hasResolution = mPresShell->ScaleToResolution() &&
mPresShell->GetResolution() != 1.0f;
if (!hasDisplayPort && !hasResolution) {
// We only want to update the displayport if there is one already, or
// add one if there's a resolution on the document (see bug 1225508
// comment 1).
return;
}
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -1694,17 +1694,17 @@ already_AddRefed<LayerManager> nsDisplay
// NS_WARNING is debug-only, so don't even bother checking the conditions in
// a release build.
#ifdef DEBUG
bool usingDisplayport = false;
if (nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame()) {
nsIContent* content = rootScrollFrame->GetContent();
if (content) {
- usingDisplayport = nsLayoutUtils::GetDisplayPort(content, nullptr);
+ usingDisplayport = nsLayoutUtils::HasDisplayPort(content);
}
}
if (usingDisplayport &&
!(root->GetContentFlags() & Layer::CONTENT_OPAQUE) &&
SpammyLayoutWarningsEnabled()) {
// See bug 693938, attachment 567017
NS_WARNING("Transparent content with displayports can be expensive.");
}
@@ -4423,17 +4423,17 @@ already_AddRefed<Layer>
nsDisplaySubDocument::BuildLayer(nsDisplayListBuilder* aBuilder,
LayerManager* aManager,
const ContainerLayerParameters& aContainerParameters) {
nsPresContext* presContext = mFrame->PresContext();
nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
ContainerLayerParameters params = aContainerParameters;
if ((mFlags & GENERATE_SCROLLABLE_LAYER) &&
rootScrollFrame->GetContent() &&
- nsLayoutUtils::GetCriticalDisplayPort(rootScrollFrame->GetContent(), nullptr)) {
+ nsLayoutUtils::HasCriticalDisplayPort(rootScrollFrame->GetContent())) {
params.mInLowPrecisionDisplayPort = true;
}
RefPtr<Layer> layer = nsDisplayOwnLayer::BuildLayer(aBuilder, aManager, params);
layer->AsContainerLayer()->SetEventRegionsOverride(mForceDispatchToContentRegion
? EventRegionsOverride::ForceDispatchToContent
: EventRegionsOverride::NoOverride);
return layer.forget();
@@ -4452,17 +4452,17 @@ nsDisplaySubDocument::ComputeFrameMetric
bool isRootContentDocument = presContext->IsRootContentDocument();
nsIPresShell* presShell = presContext->PresShell();
ContainerLayerParameters params(
aContainerParameters.mXScale * presShell->GetResolution(),
aContainerParameters.mYScale * presShell->GetResolution(),
nsIntPoint(), aContainerParameters);
if ((mFlags & GENERATE_SCROLLABLE_LAYER) &&
rootScrollFrame->GetContent() &&
- nsLayoutUtils::GetCriticalDisplayPort(rootScrollFrame->GetContent(), nullptr)) {
+ nsLayoutUtils::HasCriticalDisplayPort(rootScrollFrame->GetContent())) {
params.mInLowPrecisionDisplayPort = true;
}
nsRect viewport = mFrame->GetRect() -
mFrame->GetPosition() +
mFrame->GetOffsetToCrossDoc(ReferenceFrame());
return MakeUnique<FrameMetrics>(
@@ -4721,17 +4721,17 @@ nsDisplayScrollInfoLayer::BuildLayer(nsD
// create a scroll info layer.
if (aManager->SupportsMixBlendModes(mContainedBlendModes)) {
return nullptr;
}
}
ContainerLayerParameters params = aContainerParameters;
if (mScrolledFrame->GetContent() &&
- nsLayoutUtils::GetCriticalDisplayPort(mScrolledFrame->GetContent(), nullptr)) {
+ nsLayoutUtils::HasCriticalDisplayPort(mScrolledFrame->GetContent())) {
params.mInLowPrecisionDisplayPort = true;
}
return aManager->GetLayerBuilder()->
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
params, nullptr,
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR);
}
@@ -4745,17 +4745,17 @@ nsDisplayScrollInfoLayer::GetLayerState(
}
UniquePtr<FrameMetrics>
nsDisplayScrollInfoLayer::ComputeFrameMetrics(Layer* aLayer,
const ContainerLayerParameters& aContainerParameters)
{
ContainerLayerParameters params = aContainerParameters;
if (mScrolledFrame->GetContent() &&
- nsLayoutUtils::GetCriticalDisplayPort(mScrolledFrame->GetContent(), nullptr)) {
+ nsLayoutUtils::HasCriticalDisplayPort(mScrolledFrame->GetContent())) {
params.mInLowPrecisionDisplayPort = true;
}
nsRect viewport = mScrollFrame->GetRect() -
mScrollFrame->GetPosition() +
mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
return UniquePtr<FrameMetrics>(new FrameMetrics(
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1073,16 +1073,21 @@ bool
nsLayoutUtils::GetDisplayPort(nsIContent* aContent, nsRect *aResult)
{
if (gfxPrefs::UseLowPrecisionBuffer()) {
return GetDisplayPortImpl(aContent, aResult, 1.0f / gfxPrefs::LowPrecisionResolution());
}
return GetDisplayPortImpl(aContent, aResult, 1.0f);
}
+bool
+nsLayoutUtils::HasDisplayPort(nsIContent* aContent) {
+ return GetDisplayPort(aContent, nullptr);
+}
+
/* static */ bool
nsLayoutUtils::GetDisplayPortForVisibilityTesting(nsIContent* aContent,
nsRect* aResult)
{
return GetDisplayPortImpl(aContent, aResult, 1.0f);
}
bool
@@ -1156,16 +1161,22 @@ bool
nsLayoutUtils::GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult)
{
if (gfxPrefs::UseLowPrecisionBuffer()) {
return GetDisplayPortImpl(aContent, aResult, 1.0f);
}
return false;
}
+bool
+nsLayoutUtils::HasCriticalDisplayPort(nsIContent* aContent)
+{
+ return GetCriticalDisplayPort(aContent, nullptr);
+}
+
nsContainerFrame*
nsLayoutUtils::LastContinuationWithChild(nsContainerFrame* aFrame)
{
NS_PRECONDITION(aFrame, "NULL frame pointer");
nsIFrame* f = aFrame->LastContinuation();
while (!f->GetFirstPrincipalChild() && f->GetPrevContinuation()) {
f = f->GetPrevContinuation();
}
@@ -3072,17 +3083,17 @@ nsLayoutUtils::SetZeroMarginDisplayPortO
if (!scrollAncestor) {
break;
}
frame = do_QueryFrame(scrollAncestor);
MOZ_ASSERT(frame);
MOZ_ASSERT(scrollAncestor->WantAsyncScroll() ||
frame->PresContext()->PresShell()->GetRootScrollFrame() == frame);
if (nsLayoutUtils::AsyncPanZoomEnabled(frame) &&
- !nsLayoutUtils::GetDisplayPort(frame->GetContent())) {
+ !nsLayoutUtils::HasDisplayPort(frame->GetContent())) {
nsLayoutUtils::SetDisplayPortMargins(
frame->GetContent(), frame->PresContext()->PresShell(), ScreenMargin(), 0,
aRepaintMode);
}
}
}
nsresult
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -162,17 +162,22 @@ public:
/**
* Find the scrollable frame for a given ID.
*/
static nsIScrollableFrame* FindScrollableFrameFor(ViewID aId);
/**
* Get display port for the given element.
*/
- static bool GetDisplayPort(nsIContent* aContent, nsRect *aResult = nullptr);
+ static bool GetDisplayPort(nsIContent* aContent, nsRect *aResult);
+
+ /**
+ * Check whether the given element has a displayport.
+ */
+ static bool HasDisplayPort(nsIContent* aContent);
/**
* @return the display port for the given element which should be used for
* visibility testing purposes.
*
* If low-precision buffers are enabled, this is the critical display port;
* otherwise, it's the same display port returned by GetDisplayPort().
*/
@@ -212,17 +217,22 @@ public:
* the display port base to aBase if no display port base is currently set.
*/
static void SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase);
static void SetDisplayPortBaseIfNotSet(nsIContent* aContent, const nsRect& aBase);
/**
* Get the critical display port for the given element.
*/
- static bool GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult = nullptr);
+ static bool GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult);
+
+ /**
+ * Check whether the given element has a critical display port.
+ */
+ static bool HasCriticalDisplayPort(nsIContent* aContent);
/**
* Use heuristics to figure out the child list that
* aChildFrame is currently in.
*/
static mozilla::layout::FrameChildListID GetChildListNameFor(nsIFrame* aChildFrame);
/**
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -2142,17 +2142,17 @@ ScrollFrameHelper::ScrollToWithOrigin(ns
// The animation will be handled in the compositor, pass the
// information needed to start the animation and skip the main-thread
// animation for this scroll.
mLastSmoothScrollOrigin = aOrigin;
mApzSmoothScrollDestination = mDestination;
mScrollGeneration = ++sScrollGenerationCounter;
- if (!nsLayoutUtils::GetDisplayPort(mOuter->GetContent())) {
+ if (!nsLayoutUtils::HasDisplayPort(mOuter->GetContent())) {
// If this frame doesn't have a displayport then there won't be an
// APZC instance for it and so there won't be anything to process
// this smooth scroll request. We should set a displayport on this
// frame to force an APZC which can handle the request.
nsLayoutUtils::CalculateAndSetDisplayPortMargins(
mOuter->GetScrollTargetFrame(),
nsLayoutUtils::RepaintMode::DoNotRepaint);
nsIFrame* frame = do_QueryFrame(mOuter->GetScrollTargetFrame());
@@ -2898,17 +2898,17 @@ ScrollFrameHelper::BuildDisplayList(nsDi
// of the viewport, so most layer implementations would create a layer buffer
// that's much larger than necessary. Creating independent layers for each
// scrollbar works around the problem.
bool createLayersForScrollbars = mIsRoot &&
mOuter->PresContext()->IsRootContentDocument();
if (aBuilder->GetIgnoreScrollFrame() == mOuter || IsIgnoringViewportClipping()) {
bool usingDisplayPort = aBuilder->IsPaintingToWindow() &&
- nsLayoutUtils::GetDisplayPort(mOuter->GetContent());
+ nsLayoutUtils::HasDisplayPort(mOuter->GetContent());
// Root scrollframes have FrameMetrics and clipping on their container
// layers, so don't apply clipping again.
mAddClipRectToLayer = false;
// If we are a root scroll frame that has a display port we want to add
// scrollbars, they will be children of the scrollable layer, but they get
// adjusted by the APZC automatically.
@@ -2949,17 +2949,17 @@ ScrollFrameHelper::BuildDisplayList(nsDi
// MarkOutOfFlowChildrenForDisplayList, so it's safe to restrict our
// dirty rect here.
nsRect dirtyRect = aDirtyRect.Intersect(mScrollPort);
Unused << DecideScrollableLayer(aBuilder, &dirtyRect,
/* aAllowCreateDisplayPort = */ !mIsRoot);
bool usingDisplayPort = aBuilder->IsPaintingToWindow() &&
- nsLayoutUtils::GetDisplayPort(mOuter->GetContent());
+ nsLayoutUtils::HasDisplayPort(mOuter->GetContent());
// Whether we might want to build a scrollable layer for this scroll frame
// at some point in the future. This controls whether we add the information
// to the layer tree (a scroll info layer if necessary, and add the right
// area to the dispatch to content layer event regions) necessary to activate
// a scroll frame so it creates a scrollable layer.
bool couldBuildLayer = false;
if (mWillBuildScrollableLayer) {
@@ -3186,17 +3186,17 @@ ScrollFrameHelper::DecideScrollableLayer
{
// Save and check if this changes so we can recompute the current agr.
bool oldWillBuildScrollableLayer = mWillBuildScrollableLayer;
bool wasUsingDisplayPort = false;
bool usingDisplayPort = false;
nsIContent* content = mOuter->GetContent();
if (aBuilder->IsPaintingToWindow()) {
- wasUsingDisplayPort = nsLayoutUtils::GetDisplayPort(content);
+ wasUsingDisplayPort = nsLayoutUtils::HasDisplayPort(content);
nsRect displayportBase = *aDirtyRect;
nsPresContext* pc = mOuter->PresContext();
if (mIsRoot && (pc->IsRootContentDocument() || !pc->GetParentPresContext())) {
displayportBase =
nsRect(nsPoint(0, 0), nsLayoutUtils::CalculateCompositionSizeForFrame(mOuter));
}
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -938,17 +938,17 @@ nsSliderFrame::StartAPZDrag(WidgetGUIEve
uint32_t presShellId = PresContext()->PresShell()->GetPresShellId();
AsyncDragMetrics dragMetrics(scrollTargetId, presShellId, inputblockId,
NSAppUnitsToIntPixels(mDragStart,
float(AppUnitsPerCSSPixel())),
sliderTrackCSS,
IsHorizontal() ? AsyncDragMetrics::HORIZONTAL :
AsyncDragMetrics::VERTICAL);
- if (!nsLayoutUtils::GetDisplayPort(scrollableContent)) {
+ if (!nsLayoutUtils::HasDisplayPort(scrollableContent)) {
return false;
}
// When we start an APZ drag, we wont get mouse events for the drag.
// APZ will consume them all and only notify us of the new scroll position.
this->GetNearestWidget()->StartAsyncScrollbarDrag(dragMetrics);
return true;
}