2020-10-04 00:07:34 +03:00
|
|
|
/* -*- 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 "DisplayPortUtils.h"
|
|
|
|
|
|
|
|
#include "FrameMetrics.h"
|
2021-06-15 04:49:32 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2020-12-14 00:02:25 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "mozilla/layers/APZPublicUtils.h"
|
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
2021-09-15 21:48:17 +03:00
|
|
|
#include "mozilla/layers/LayersMessageUtils.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
#include "mozilla/layers/PAPZ.h"
|
2020-12-14 00:02:25 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
#include "mozilla/StaticPrefs_layers.h"
|
2022-08-18 01:08:00 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsSubDocumentFrame.h"
|
|
|
|
#include "RetainedDisplayListBuilder.h"
|
2021-10-18 02:00:47 +03:00
|
|
|
#include "WindowRenderer.h"
|
2020-10-04 00:07:34 +03:00
|
|
|
|
2020-10-08 01:35:07 +03:00
|
|
|
#include <ostream>
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using gfx::IntSize;
|
|
|
|
|
|
|
|
using layers::FrameMetrics;
|
|
|
|
using layers::ScrollableLayerGuid;
|
|
|
|
|
|
|
|
typedef ScrollableLayerGuid::ViewID ViewID;
|
|
|
|
|
|
|
|
static LazyLogModule sDisplayportLog("apz.displayport");
|
|
|
|
|
2020-10-08 01:35:07 +03:00
|
|
|
/* static */
|
2020-10-27 02:26:59 +03:00
|
|
|
DisplayPortMargins DisplayPortMargins::FromAPZ(
|
2020-10-08 01:35:07 +03:00
|
|
|
const ScreenMargin& aMargins, const CSSPoint& aVisualOffset,
|
|
|
|
const CSSPoint& aLayoutOffset, const CSSToScreenScale2D& aScale) {
|
|
|
|
return DisplayPortMargins{aMargins, aVisualOffset, aLayoutOffset, aScale};
|
|
|
|
}
|
|
|
|
|
2020-10-29 01:13:14 +03:00
|
|
|
CSSToScreenScale2D ComputeDisplayportScale(nsIScrollableFrame* aScrollFrame) {
|
|
|
|
// The calculation here is equivalent to
|
|
|
|
// CalculateBasicFrameMetrics(aScrollFrame).DisplayportPixelsPerCSSPixel(),
|
|
|
|
// but we don't calculate the entire frame metrics.
|
|
|
|
if (!aScrollFrame) {
|
|
|
|
return CSSToScreenScale2D(1.0, 1.0);
|
|
|
|
}
|
|
|
|
nsIFrame* frame = do_QueryFrame(aScrollFrame);
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
PresShell* presShell = presContext->PresShell();
|
2021-10-05 12:28:57 +03:00
|
|
|
|
2020-10-29 01:13:14 +03:00
|
|
|
return presContext->CSSToDevPixelScale() *
|
2021-10-05 12:28:57 +03:00
|
|
|
LayoutDeviceToLayerScale(presShell->GetCumulativeResolution()) *
|
|
|
|
LayerToParentLayerScale(1.0) *
|
|
|
|
nsLayoutUtils::GetTransformToAncestorScaleCrossProcessForFrameMetrics(
|
|
|
|
frame);
|
2020-10-29 01:13:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
DisplayPortMargins DisplayPortMargins::ForScrollFrame(
|
|
|
|
nsIScrollableFrame* aScrollFrame, const ScreenMargin& aMargins,
|
|
|
|
const Maybe<CSSToScreenScale2D>& aScale) {
|
|
|
|
CSSPoint visualOffset;
|
|
|
|
CSSPoint layoutOffset;
|
|
|
|
if (aScrollFrame) {
|
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(aScrollFrame);
|
|
|
|
PresShell* presShell = scrollFrame->PresShell();
|
|
|
|
layoutOffset = CSSPoint::FromAppUnits(aScrollFrame->GetScrollPosition());
|
2022-02-27 16:09:27 +03:00
|
|
|
if (aScrollFrame->IsRootScrollFrameOfDocument()) {
|
2020-10-29 01:13:14 +03:00
|
|
|
visualOffset =
|
|
|
|
CSSPoint::FromAppUnits(presShell->GetVisualViewportOffset());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
visualOffset = layoutOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DisplayPortMargins{aMargins, visualOffset, layoutOffset,
|
|
|
|
aScale.valueOrFrom([&] {
|
|
|
|
return ComputeDisplayportScale(aScrollFrame);
|
|
|
|
})};
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:35:07 +03:00
|
|
|
/* static */
|
2020-10-29 01:13:14 +03:00
|
|
|
DisplayPortMargins DisplayPortMargins::ForContent(
|
|
|
|
nsIContent* aContent, const ScreenMargin& aMargins) {
|
|
|
|
return ForScrollFrame(
|
|
|
|
aContent ? nsLayoutUtils::FindScrollableFrameFor(aContent) : nullptr,
|
|
|
|
aMargins, Nothing());
|
2020-10-08 01:35:07 +03:00
|
|
|
}
|
|
|
|
|
2020-10-08 01:36:57 +03:00
|
|
|
ScreenMargin DisplayPortMargins::GetRelativeToLayoutViewport(
|
2023-03-30 06:59:05 +03:00
|
|
|
ContentGeometryType aGeometryType, nsIScrollableFrame* aScrollableFrame,
|
|
|
|
const CSSToScreenScale2D& aDisplayportScale) const {
|
2020-10-08 01:36:57 +03:00
|
|
|
// APZ wants |mMargins| applied relative to the visual viewport.
|
|
|
|
// The main-thread painting code applies margins relative to
|
|
|
|
// the layout viewport. To get the main thread to paint the
|
|
|
|
// area APZ wants, apply a translation between the two. The
|
|
|
|
// magnitude of the translation depends on whether we are
|
|
|
|
// applying the displayport to scrolled or fixed content.
|
|
|
|
CSSPoint scrollDeltaCss =
|
|
|
|
ComputeAsyncTranslation(aGeometryType, aScrollableFrame);
|
2023-03-30 06:59:05 +03:00
|
|
|
ScreenPoint scrollDelta = scrollDeltaCss * aDisplayportScale;
|
2020-10-08 01:35:07 +03:00
|
|
|
ScreenMargin margins = mMargins;
|
|
|
|
margins.left -= scrollDelta.x;
|
|
|
|
margins.right += scrollDelta.x;
|
|
|
|
margins.top -= scrollDelta.y;
|
|
|
|
margins.bottom += scrollDelta.y;
|
|
|
|
return margins;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& aOs,
|
|
|
|
const DisplayPortMargins& aMargins) {
|
|
|
|
if (aMargins.mVisualOffset == CSSPoint() &&
|
|
|
|
aMargins.mLayoutOffset == CSSPoint()) {
|
|
|
|
aOs << aMargins.mMargins;
|
|
|
|
} else {
|
|
|
|
aOs << "{" << aMargins.mMargins << "," << aMargins.mVisualOffset << ","
|
|
|
|
<< aMargins.mLayoutOffset << "}";
|
|
|
|
}
|
|
|
|
return aOs;
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:36:57 +03:00
|
|
|
CSSPoint DisplayPortMargins::ComputeAsyncTranslation(
|
|
|
|
ContentGeometryType aGeometryType,
|
|
|
|
nsIScrollableFrame* aScrollableFrame) const {
|
|
|
|
// If we are applying the displayport to scrolled content, the
|
|
|
|
// translation is the entire difference between the visual and
|
|
|
|
// layout offsets.
|
|
|
|
if (aGeometryType == ContentGeometryType::Scrolled) {
|
|
|
|
return mVisualOffset - mLayoutOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are applying the displayport to fixed content, only
|
|
|
|
// part of the difference between the visual and layout offsets
|
|
|
|
// should be applied. This is because fixed content remains fixed
|
|
|
|
// to the layout viewport, and some of the async delta between
|
|
|
|
// the visual and layout offsets can drag the layout viewport
|
|
|
|
// with it. We want only the remaining delta, i.e. the offset of
|
|
|
|
// the visual viewport relative to the (async-scrolled) layout
|
|
|
|
// viewport.
|
|
|
|
if (!aScrollableFrame) {
|
|
|
|
// Displayport on a non-scrolling frame for some reason.
|
|
|
|
// There will be no divergence between the two viewports.
|
|
|
|
return CSSPoint();
|
|
|
|
}
|
|
|
|
// Fixed content is always fixed to an RSF.
|
|
|
|
MOZ_ASSERT(aScrollableFrame->IsRootScrollFrameOfDocument());
|
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(aScrollableFrame);
|
|
|
|
if (!scrollFrame->PresShell()->IsVisualViewportSizeSet()) {
|
|
|
|
// Zooming is disabled, so the layout viewport tracks the
|
|
|
|
// visual viewport completely.
|
|
|
|
return CSSPoint();
|
|
|
|
}
|
|
|
|
// Use KeepLayoutViewportEnclosingViewportVisual() to compute
|
|
|
|
// an async layout viewport the way APZ would.
|
|
|
|
const CSSRect visualViewport{
|
|
|
|
mVisualOffset,
|
|
|
|
// TODO: There are probably some edge cases here around async zooming
|
|
|
|
// that are not currently being handled properly. For proper handling,
|
|
|
|
// we'd likely need to save APZ's async zoom when populating
|
|
|
|
// mVisualOffset, and using it to adjust the visual viewport size here.
|
|
|
|
// Note that any incorrectness caused by this will only occur transiently
|
|
|
|
// during async zooming.
|
|
|
|
CSSSize::FromAppUnits(scrollFrame->PresShell()->GetVisualViewportSize())};
|
|
|
|
const CSSRect scrollableRect = CSSRect::FromAppUnits(
|
|
|
|
nsLayoutUtils::CalculateExpandedScrollableRect(scrollFrame));
|
|
|
|
CSSRect asyncLayoutViewport{
|
|
|
|
mLayoutOffset,
|
|
|
|
CSSSize::FromAppUnits(aScrollableFrame->GetScrollPortRect().Size())};
|
|
|
|
FrameMetrics::KeepLayoutViewportEnclosingVisualViewport(
|
|
|
|
visualViewport, scrollableRect, /* out */ asyncLayoutViewport);
|
|
|
|
return mVisualOffset - asyncLayoutViewport.TopLeft();
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
static nsRect GetDisplayPortFromRectData(nsIContent* aContent,
|
2022-07-14 21:39:34 +03:00
|
|
|
DisplayPortPropertyData* aRectData) {
|
2020-10-04 00:07:34 +03:00
|
|
|
// In the case where the displayport is set as a rect, we assume it is
|
|
|
|
// already aligned and clamped as necessary. The burden to do that is
|
|
|
|
// on the setter of the displayport. In practice very few places set the
|
2022-07-14 21:39:34 +03:00
|
|
|
// displayport directly as a rect (mostly tests).
|
|
|
|
return aRectData->mRect;
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsRect GetDisplayPortFromMarginsData(
|
|
|
|
nsIContent* aContent, DisplayPortMarginsPropertyData* aMarginsData,
|
2022-07-14 21:39:34 +03:00
|
|
|
const DisplayPortOptions& aOptions) {
|
2020-10-04 00:07:34 +03:00
|
|
|
// In the case where the displayport is set via margins, we apply the margins
|
|
|
|
// to a base rect. Then we align the expanded rect based on the alignment
|
2022-07-14 21:39:34 +03:00
|
|
|
// requested, and finally, clamp it to the size of the scrollable rect.
|
2020-10-04 00:07:34 +03:00
|
|
|
|
|
|
|
nsRect base;
|
|
|
|
if (nsRect* baseData = static_cast<nsRect*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPortBase))) {
|
|
|
|
base = *baseData;
|
|
|
|
} else {
|
|
|
|
// In theory we shouldn't get here, but we do sometimes (see bug 1212136).
|
|
|
|
// Fall through for graceful handling.
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = nsLayoutUtils::GetScrollFrameFromContent(aContent);
|
|
|
|
if (!frame) {
|
|
|
|
// Turns out we can't really compute it. Oops. We still should return
|
2022-07-14 21:39:34 +03:00
|
|
|
// something sane.
|
2020-10-04 00:07:34 +03:00
|
|
|
NS_WARNING(
|
|
|
|
"Attempting to get a displayport from a content with no primary "
|
|
|
|
"frame!");
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isRoot = false;
|
|
|
|
if (aContent->OwnerDoc()->GetRootElement() == aContent) {
|
|
|
|
isRoot = true;
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:36:57 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame = frame->GetScrollTargetFrame();
|
2020-10-04 00:07:34 +03:00
|
|
|
nsPoint scrollPos;
|
2020-10-08 01:36:57 +03:00
|
|
|
if (scrollableFrame) {
|
2020-10-04 00:07:34 +03:00
|
|
|
scrollPos = scrollableFrame->GetScrollPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
|
2021-10-05 12:28:58 +03:00
|
|
|
LayoutDeviceToScreenScale2D res =
|
|
|
|
LayoutDeviceToParentLayerScale(
|
|
|
|
presContext->PresShell()->GetCumulativeResolution()) *
|
|
|
|
nsLayoutUtils::GetTransformToAncestorScaleCrossProcessForFrameMetrics(
|
|
|
|
frame);
|
2020-10-04 00:07:34 +03:00
|
|
|
|
|
|
|
// Calculate the expanded scrollable rect, which we'll be clamping the
|
|
|
|
// displayport to.
|
|
|
|
nsRect expandedScrollableRect =
|
|
|
|
nsLayoutUtils::CalculateExpandedScrollableRect(frame);
|
|
|
|
|
|
|
|
// GetTransformToAncestorScale() can return 0. In this case, just return the
|
|
|
|
// base rect (clamped to the expanded scrollable rect), as other calculations
|
|
|
|
// would run into divisions by zero.
|
|
|
|
if (res == LayoutDeviceToScreenScale2D(0, 0)) {
|
|
|
|
// Make sure the displayport remains within the scrollable rect.
|
|
|
|
return base.MoveInsideAndClamp(expandedScrollableRect - scrollPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// First convert the base rect to screen pixels
|
|
|
|
LayoutDeviceToScreenScale2D parentRes = res;
|
|
|
|
if (isRoot) {
|
|
|
|
// the base rect for root scroll frames is specified in the parent document
|
|
|
|
// coordinate space, so it doesn't include the local resolution.
|
|
|
|
float localRes = presContext->PresShell()->GetResolution();
|
|
|
|
parentRes.xScale /= localRes;
|
|
|
|
parentRes.yScale /= localRes;
|
|
|
|
}
|
|
|
|
ScreenRect screenRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(base, auPerDevPixel) * parentRes;
|
|
|
|
|
|
|
|
// Note on the correctness of applying the alignment in Screen space:
|
|
|
|
// The correct space to apply the alignment in would be Layer space, but
|
|
|
|
// we don't necessarily know the scale to convert to Layer space at this
|
|
|
|
// point because Layout may not yet have chosen the resolution at which to
|
|
|
|
// render (it chooses that in FrameLayerBuilder, but this can be called
|
|
|
|
// during display list building). Therefore, we perform the alignment in
|
|
|
|
// Screen space, which basically assumes that Layout chose to render at
|
|
|
|
// screen resolution; since this is what Layout does most of the time,
|
|
|
|
// this is a good approximation. A proper solution would involve moving
|
|
|
|
// the choosing of the resolution to display-list building time.
|
|
|
|
ScreenSize alignment;
|
|
|
|
|
|
|
|
PresShell* presShell = presContext->PresShell();
|
|
|
|
MOZ_ASSERT(presShell);
|
|
|
|
|
2020-10-08 01:36:57 +03:00
|
|
|
ScreenMargin margins = aMarginsData->mMargins.GetRelativeToLayoutViewport(
|
2023-03-30 06:59:05 +03:00
|
|
|
aOptions.mGeometryType, scrollableFrame,
|
|
|
|
presContext->CSSToDevPixelScale() * res);
|
2020-10-08 01:35:07 +03:00
|
|
|
|
2021-02-04 14:16:44 +03:00
|
|
|
if (presShell->IsDisplayportSuppressed() ||
|
|
|
|
aContent->GetProperty(nsGkAtoms::MinimalDisplayPort)) {
|
2020-10-04 00:07:34 +03:00
|
|
|
alignment = ScreenSize(1, 1);
|
2021-10-05 04:29:57 +03:00
|
|
|
} else {
|
2020-10-04 00:07:34 +03:00
|
|
|
// Moving the displayport is relatively expensive with WR so we use a larger
|
|
|
|
// alignment that causes the displayport to move less frequently. The
|
|
|
|
// alignment scales up with the size of the base rect so larger scrollframes
|
|
|
|
// use a larger alignment, but we clamp the alignment to a power of two
|
|
|
|
// between 128 and 1024 (inclusive).
|
|
|
|
// This naturally also increases the size of the displayport compared to
|
|
|
|
// always using a 128 alignment, so the displayport multipliers are also
|
|
|
|
// correspondingly smaller when WR is enabled to prevent the displayport
|
|
|
|
// from becoming too big.
|
|
|
|
IntSize multiplier =
|
|
|
|
layers::apz::GetDisplayportAlignmentMultiplier(screenRect.Size());
|
|
|
|
alignment = ScreenSize(128 * multiplier.width, 128 * multiplier.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid division by zero.
|
|
|
|
if (alignment.width == 0) {
|
|
|
|
alignment.width = 128;
|
|
|
|
}
|
|
|
|
if (alignment.height == 0) {
|
|
|
|
alignment.height = 128;
|
|
|
|
}
|
|
|
|
|
2021-10-05 04:29:57 +03:00
|
|
|
// Expand the rect by the margins
|
|
|
|
screenRect.Inflate(margins);
|
2020-10-04 00:07:34 +03:00
|
|
|
|
|
|
|
ScreenPoint scrollPosScreen =
|
|
|
|
LayoutDevicePoint::FromAppUnits(scrollPos, auPerDevPixel) * res;
|
|
|
|
|
|
|
|
// Align the display port.
|
|
|
|
screenRect += scrollPosScreen;
|
|
|
|
float x = alignment.width * floor(screenRect.x / alignment.width);
|
|
|
|
float y = alignment.height * floor(screenRect.y / alignment.height);
|
|
|
|
float w = alignment.width * ceil(screenRect.width / alignment.width + 1);
|
|
|
|
float h = alignment.height * ceil(screenRect.height / alignment.height + 1);
|
|
|
|
screenRect = ScreenRect(x, y, w, h);
|
|
|
|
screenRect -= scrollPosScreen;
|
|
|
|
|
|
|
|
// Convert the aligned rect back into app units.
|
|
|
|
nsRect result = LayoutDeviceRect::ToAppUnits(screenRect / res, auPerDevPixel);
|
|
|
|
|
|
|
|
// Make sure the displayport remains within the scrollable rect.
|
|
|
|
result = result.MoveInsideAndClamp(expandedScrollableRect - scrollPos);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetDisplayPortData(
|
|
|
|
nsIContent* aContent, DisplayPortPropertyData** aOutRectData,
|
|
|
|
DisplayPortMarginsPropertyData** aOutMarginsData) {
|
|
|
|
MOZ_ASSERT(aOutRectData && aOutMarginsData);
|
|
|
|
|
|
|
|
*aOutRectData = static_cast<DisplayPortPropertyData*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPort));
|
|
|
|
*aOutMarginsData = static_cast<DisplayPortMarginsPropertyData*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
|
|
|
|
|
|
|
if (!*aOutRectData && !*aOutMarginsData) {
|
|
|
|
// This content element has no displayport data at all
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*aOutRectData && *aOutMarginsData) {
|
|
|
|
// choose margins if equal priority
|
|
|
|
if ((*aOutRectData)->mPriority > (*aOutMarginsData)->mPriority) {
|
|
|
|
*aOutMarginsData = nullptr;
|
|
|
|
} else {
|
|
|
|
*aOutRectData = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION((*aOutRectData == nullptr) != (*aOutMarginsData == nullptr),
|
|
|
|
"Only one of aOutRectData or aOutMarginsData should be set!");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetWasDisplayPortPainted(nsIContent* aContent) {
|
|
|
|
DisplayPortPropertyData* rectData = nullptr;
|
|
|
|
DisplayPortMarginsPropertyData* marginsData = nullptr;
|
|
|
|
|
|
|
|
if (!GetDisplayPortData(aContent, &rectData, &marginsData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rectData ? rectData->mPainted : marginsData->mPainted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::IsMissingDisplayPortBaseRect(nsIContent* aContent) {
|
|
|
|
DisplayPortPropertyData* rectData = nullptr;
|
|
|
|
DisplayPortMarginsPropertyData* marginsData = nullptr;
|
|
|
|
|
|
|
|
if (GetDisplayPortData(aContent, &rectData, &marginsData) && marginsData) {
|
|
|
|
return !aContent->GetProperty(nsGkAtoms::DisplayPortBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:08:19 +03:00
|
|
|
static void TranslateFromScrollPortToScrollFrame(nsIContent* aContent,
|
|
|
|
nsRect* aRect) {
|
|
|
|
MOZ_ASSERT(aRect);
|
|
|
|
if (nsIScrollableFrame* scrollableFrame =
|
|
|
|
nsLayoutUtils::FindScrollableFrameFor(aContent)) {
|
|
|
|
*aRect += scrollableFrame->GetScrollPortRect().TopLeft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:35:20 +03:00
|
|
|
static bool GetDisplayPortImpl(nsIContent* aContent, nsRect* aResult,
|
|
|
|
const DisplayPortOptions& aOptions) {
|
2020-10-04 00:07:34 +03:00
|
|
|
DisplayPortPropertyData* rectData = nullptr;
|
|
|
|
DisplayPortMarginsPropertyData* marginsData = nullptr;
|
|
|
|
|
|
|
|
if (!GetDisplayPortData(aContent, &rectData, &marginsData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = aContent->GetPrimaryFrame();
|
|
|
|
if (frame && !frame->PresShell()->AsyncPanZoomEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aResult) {
|
|
|
|
// We have displayport data, but the caller doesn't want the actual
|
|
|
|
// rect, so we don't need to actually compute it.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDisplayportSuppressed = false;
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
MOZ_ASSERT(presContext);
|
|
|
|
PresShell* presShell = presContext->PresShell();
|
|
|
|
MOZ_ASSERT(presShell);
|
|
|
|
isDisplayportSuppressed = presShell->IsDisplayportSuppressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect result;
|
|
|
|
if (rectData) {
|
2022-07-14 21:39:34 +03:00
|
|
|
result = GetDisplayPortFromRectData(aContent, rectData);
|
2020-10-04 00:07:34 +03:00
|
|
|
} else if (isDisplayportSuppressed ||
|
2021-02-04 14:16:44 +03:00
|
|
|
nsLayoutUtils::ShouldDisableApzForElement(aContent) ||
|
|
|
|
aContent->GetProperty(nsGkAtoms::MinimalDisplayPort)) {
|
2021-01-24 07:08:00 +03:00
|
|
|
// Make a copy of the margins data but set the margins to empty.
|
|
|
|
// Do not create a new DisplayPortMargins object with
|
|
|
|
// DisplayPortMargins::Empty(), because that will record the visual
|
|
|
|
// and layout scroll offsets in place right now on the DisplayPortMargins,
|
|
|
|
// and those are only meant to be recorded when the margins are stored.
|
|
|
|
DisplayPortMarginsPropertyData noMargins = *marginsData;
|
|
|
|
noMargins.mMargins.mMargins = ScreenMargin();
|
2022-07-14 21:39:34 +03:00
|
|
|
result = GetDisplayPortFromMarginsData(aContent, &noMargins, aOptions);
|
2020-10-04 00:07:34 +03:00
|
|
|
} else {
|
2022-07-14 21:39:34 +03:00
|
|
|
result = GetDisplayPortFromMarginsData(aContent, marginsData, aOptions);
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
2020-10-04 00:08:19 +03:00
|
|
|
if (aOptions.mRelativeTo == DisplayportRelativeTo::ScrollFrame) {
|
|
|
|
TranslateFromScrollPortToScrollFrame(aContent, &result);
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
*aResult = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:08:12 +03:00
|
|
|
bool DisplayPortUtils::GetDisplayPort(nsIContent* aContent, nsRect* aResult,
|
|
|
|
const DisplayPortOptions& aOptions) {
|
2022-07-14 21:39:34 +03:00
|
|
|
return GetDisplayPortImpl(aContent, aResult, aOptions);
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::HasDisplayPort(nsIContent* aContent) {
|
|
|
|
return GetDisplayPort(aContent, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::HasPaintedDisplayPort(nsIContent* aContent) {
|
|
|
|
DisplayPortPropertyData* rectData = nullptr;
|
|
|
|
DisplayPortMarginsPropertyData* marginsData = nullptr;
|
|
|
|
GetDisplayPortData(aContent, &rectData, &marginsData);
|
|
|
|
if (rectData) {
|
|
|
|
return rectData->mPainted;
|
|
|
|
}
|
|
|
|
if (marginsData) {
|
|
|
|
return marginsData->mPainted;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::MarkDisplayPortAsPainted(nsIContent* aContent) {
|
|
|
|
DisplayPortPropertyData* rectData = nullptr;
|
|
|
|
DisplayPortMarginsPropertyData* marginsData = nullptr;
|
|
|
|
GetDisplayPortData(aContent, &rectData, &marginsData);
|
|
|
|
MOZ_ASSERT(rectData || marginsData,
|
|
|
|
"MarkDisplayPortAsPainted should only be called for an element "
|
|
|
|
"with a displayport");
|
|
|
|
if (rectData) {
|
|
|
|
rectData->mPainted = true;
|
|
|
|
}
|
|
|
|
if (marginsData) {
|
|
|
|
marginsData->mPainted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 14:16:59 +03:00
|
|
|
bool DisplayPortUtils::HasNonMinimalDisplayPort(nsIContent* aContent) {
|
|
|
|
return HasDisplayPort(aContent) &&
|
|
|
|
!aContent->GetProperty(nsGkAtoms::MinimalDisplayPort);
|
|
|
|
}
|
|
|
|
|
2021-02-09 04:41:00 +03:00
|
|
|
bool DisplayPortUtils::HasNonMinimalNonZeroDisplayPort(nsIContent* aContent) {
|
|
|
|
if (!HasDisplayPort(aContent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aContent->GetProperty(nsGkAtoms::MinimalDisplayPort)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayPortMarginsPropertyData* currentData =
|
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
|
|
|
|
|
|
|
if (!currentData) {
|
|
|
|
// We have a display port, so if we don't have margin data we must have rect
|
|
|
|
// data. We consider such as non zero and non minimal, it's probably not too
|
|
|
|
// important as display port rects are only used in tests.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentData->mMargins.mMargins != ScreenMargin()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
/* static */
|
2020-10-04 00:07:54 +03:00
|
|
|
bool DisplayPortUtils::GetDisplayPortForVisibilityTesting(nsIContent* aContent,
|
|
|
|
nsRect* aResult) {
|
2020-10-04 00:07:34 +03:00
|
|
|
MOZ_ASSERT(aResult);
|
2021-10-18 10:48:11 +03:00
|
|
|
return GetDisplayPortImpl(
|
2022-07-14 21:39:34 +03:00
|
|
|
aContent, aResult,
|
2021-10-18 10:48:11 +03:00
|
|
|
DisplayPortOptions().With(DisplayportRelativeTo::ScrollFrame));
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::InvalidateForDisplayPortChange(
|
|
|
|
nsIContent* aContent, bool aHadDisplayPort, const nsRect& aOldDisplayPort,
|
|
|
|
const nsRect& aNewDisplayPort, RepaintMode aRepaintMode) {
|
|
|
|
if (aRepaintMode != RepaintMode::Repaint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool changed =
|
|
|
|
!aHadDisplayPort || !aOldDisplayPort.IsEqualEdges(aNewDisplayPort);
|
|
|
|
|
|
|
|
nsIFrame* frame = nsLayoutUtils::GetScrollFrameFromContent(aContent);
|
|
|
|
if (frame) {
|
|
|
|
frame = do_QueryFrame(frame->GetScrollTargetFrame());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed && frame) {
|
|
|
|
// It is important to call SchedulePaint on the same frame that we set the
|
|
|
|
// dirty rect properties on so we can find the frame later to remove the
|
|
|
|
// properties.
|
|
|
|
frame->SchedulePaint();
|
|
|
|
|
2022-05-30 17:20:58 +03:00
|
|
|
if (!nsLayoutUtils::AreRetainedDisplayListsEnabled()) {
|
2020-10-04 00:07:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-22 05:37:31 +03:00
|
|
|
if (StaticPrefs::layout_display_list_retain_sc()) {
|
|
|
|
// DisplayListBuildingDisplayPortRect property is not used when retain sc
|
|
|
|
// mode is enabled.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-30 17:20:58 +03:00
|
|
|
auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(frame);
|
|
|
|
if (!builder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
bool found;
|
|
|
|
nsRect* rect = frame->GetProperty(
|
|
|
|
nsDisplayListBuilder::DisplayListBuildingDisplayPortRect(), &found);
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
rect = new nsRect();
|
|
|
|
frame->AddProperty(
|
|
|
|
nsDisplayListBuilder::DisplayListBuildingDisplayPortRect(), rect);
|
|
|
|
frame->SetHasOverrideDirtyRegion(true);
|
|
|
|
|
2022-05-30 17:20:58 +03:00
|
|
|
DL_LOGV("Adding display port building rect for frame %p\n", frame);
|
|
|
|
RetainedDisplayListData* data = builder->Data();
|
2022-01-20 03:21:15 +03:00
|
|
|
data->Flags(frame) += RetainedDisplayListData::FrameFlag::HasProps;
|
2020-10-04 00:07:34 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(rect, "this property should only store non-null values");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aHadDisplayPort) {
|
|
|
|
// We only need to build a display list for any new areas added
|
|
|
|
nsRegion newRegion(aNewDisplayPort);
|
|
|
|
newRegion.SubOut(aOldDisplayPort);
|
|
|
|
rect->UnionRect(*rect, newRegion.GetBounds());
|
|
|
|
} else {
|
|
|
|
rect->UnionRect(*rect, aNewDisplayPort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 14:16:44 +03:00
|
|
|
bool DisplayPortUtils::SetDisplayPortMargins(
|
|
|
|
nsIContent* aContent, PresShell* aPresShell,
|
|
|
|
const DisplayPortMargins& aMargins,
|
|
|
|
ClearMinimalDisplayPortProperty aClearMinimalDisplayPortProperty,
|
|
|
|
uint32_t aPriority, RepaintMode aRepaintMode) {
|
2020-10-04 00:07:34 +03:00
|
|
|
MOZ_ASSERT(aContent);
|
|
|
|
MOZ_ASSERT(aContent->GetComposedDoc() == aPresShell->GetDocument());
|
|
|
|
|
|
|
|
DisplayPortMarginsPropertyData* currentData =
|
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
|
|
|
if (currentData && currentData->mPriority > aPriority) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-14 23:26:55 +03:00
|
|
|
if (currentData && currentData->mMargins.mVisualOffset != CSSPoint() &&
|
|
|
|
aMargins.mVisualOffset == CSSPoint()) {
|
|
|
|
// If we hit this, then it's possible that we're setting a displayport
|
|
|
|
// that is wrong because the old one had a layout/visual adjustment and
|
|
|
|
// the new one does not.
|
|
|
|
MOZ_LOG(sDisplayportLog, LogLevel::Warning,
|
|
|
|
("Dropping visual offset %s",
|
|
|
|
ToString(currentData->mMargins.mVisualOffset).c_str()));
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
nsIFrame* scrollFrame = nsLayoutUtils::GetScrollFrameFromContent(aContent);
|
|
|
|
|
|
|
|
nsRect oldDisplayPort;
|
|
|
|
bool hadDisplayPort = false;
|
|
|
|
bool wasPainted = GetWasDisplayPortPainted(aContent);
|
|
|
|
if (scrollFrame) {
|
|
|
|
// We only use the two return values from this function to call
|
|
|
|
// InvalidateForDisplayPortChange. InvalidateForDisplayPortChange does
|
|
|
|
// nothing if aContent does not have a frame. So getting the displayport is
|
|
|
|
// useless if the content has no frame, so we avoid calling this to avoid
|
|
|
|
// triggering a warning about not having a frame.
|
2021-10-07 08:41:19 +03:00
|
|
|
hadDisplayPort = GetDisplayPort(aContent, &oldDisplayPort);
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aContent->SetProperty(
|
|
|
|
nsGkAtoms::DisplayPortMargins,
|
|
|
|
new DisplayPortMarginsPropertyData(aMargins, aPriority, wasPainted),
|
|
|
|
nsINode::DeleteProperty<DisplayPortMarginsPropertyData>);
|
|
|
|
|
2021-02-04 14:16:44 +03:00
|
|
|
if (aClearMinimalDisplayPortProperty ==
|
|
|
|
ClearMinimalDisplayPortProperty::Yes) {
|
|
|
|
if (MOZ_LOG_TEST(sDisplayportLog, LogLevel::Debug) &&
|
|
|
|
aContent->GetProperty(nsGkAtoms::MinimalDisplayPort)) {
|
|
|
|
mozilla::layers::ScrollableLayerGuid::ViewID viewID =
|
|
|
|
mozilla::layers::ScrollableLayerGuid::NULL_SCROLL_ID;
|
|
|
|
nsLayoutUtils::FindIDFor(aContent, &viewID);
|
|
|
|
MOZ_LOG(sDisplayportLog, LogLevel::Debug,
|
|
|
|
("SetDisplayPortMargins removing MinimalDisplayPort prop on "
|
|
|
|
"scrollId=%" PRIu64 "\n",
|
|
|
|
viewID));
|
|
|
|
}
|
|
|
|
aContent->RemoveProperty(nsGkAtoms::MinimalDisplayPort);
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:07:34 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame =
|
|
|
|
scrollFrame ? scrollFrame->GetScrollTargetFrame() : nullptr;
|
|
|
|
if (!scrollableFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect newDisplayPort;
|
2021-10-07 08:41:19 +03:00
|
|
|
DebugOnly<bool> hasDisplayPort = GetDisplayPort(aContent, &newDisplayPort);
|
2020-10-04 00:07:34 +03:00
|
|
|
MOZ_ASSERT(hasDisplayPort);
|
|
|
|
|
|
|
|
if (MOZ_LOG_TEST(sDisplayportLog, LogLevel::Debug)) {
|
|
|
|
mozilla::layers::ScrollableLayerGuid::ViewID viewID =
|
|
|
|
mozilla::layers::ScrollableLayerGuid::NULL_SCROLL_ID;
|
|
|
|
nsLayoutUtils::FindIDFor(aContent, &viewID);
|
|
|
|
if (!hadDisplayPort) {
|
|
|
|
MOZ_LOG(sDisplayportLog, LogLevel::Debug,
|
|
|
|
("SetDisplayPortMargins %s on scrollId=%" PRIu64 ", newDp=%s\n",
|
|
|
|
ToString(aMargins).c_str(), viewID,
|
|
|
|
ToString(newDisplayPort).c_str()));
|
|
|
|
} else {
|
|
|
|
// Use verbose level logging for when an existing displayport got its
|
|
|
|
// margins updated.
|
|
|
|
MOZ_LOG(sDisplayportLog, LogLevel::Verbose,
|
|
|
|
("SetDisplayPortMargins %s on scrollId=%" PRIu64 ", newDp=%s\n",
|
|
|
|
ToString(aMargins).c_str(), viewID,
|
|
|
|
ToString(newDisplayPort).c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateForDisplayPortChange(aContent, hadDisplayPort, oldDisplayPort,
|
|
|
|
newDisplayPort, aRepaintMode);
|
|
|
|
|
|
|
|
scrollableFrame->TriggerDisplayPortExpiration();
|
|
|
|
|
|
|
|
// Display port margins changing means that the set of visible frames may
|
|
|
|
// have drastically changed. Check if we should schedule an update.
|
|
|
|
hadDisplayPort =
|
|
|
|
scrollableFrame->GetDisplayPortAtLastApproximateFrameVisibilityUpdate(
|
|
|
|
&oldDisplayPort);
|
|
|
|
|
|
|
|
bool needVisibilityUpdate = !hadDisplayPort;
|
|
|
|
// Check if the total size has changed by a large factor.
|
|
|
|
if (!needVisibilityUpdate) {
|
|
|
|
if ((newDisplayPort.width > 2 * oldDisplayPort.width) ||
|
|
|
|
(oldDisplayPort.width > 2 * newDisplayPort.width) ||
|
|
|
|
(newDisplayPort.height > 2 * oldDisplayPort.height) ||
|
|
|
|
(oldDisplayPort.height > 2 * newDisplayPort.height)) {
|
|
|
|
needVisibilityUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if it's moved by a significant amount.
|
|
|
|
if (!needVisibilityUpdate) {
|
|
|
|
if (nsRect* baseData = static_cast<nsRect*>(
|
|
|
|
aContent->GetProperty(nsGkAtoms::DisplayPortBase))) {
|
|
|
|
nsRect base = *baseData;
|
|
|
|
if ((std::abs(newDisplayPort.X() - oldDisplayPort.X()) > base.width) ||
|
|
|
|
(std::abs(newDisplayPort.XMost() - oldDisplayPort.XMost()) >
|
|
|
|
base.width) ||
|
|
|
|
(std::abs(newDisplayPort.Y() - oldDisplayPort.Y()) > base.height) ||
|
|
|
|
(std::abs(newDisplayPort.YMost() - oldDisplayPort.YMost()) >
|
|
|
|
base.height)) {
|
|
|
|
needVisibilityUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needVisibilityUpdate) {
|
|
|
|
aPresShell->ScheduleApproximateFrameVisibilityUpdateNow();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::SetDisplayPortBase(nsIContent* aContent,
|
|
|
|
const nsRect& aBase) {
|
|
|
|
if (MOZ_LOG_TEST(sDisplayportLog, LogLevel::Verbose)) {
|
|
|
|
ViewID viewId = nsLayoutUtils::FindOrCreateIDFor(aContent);
|
|
|
|
MOZ_LOG(sDisplayportLog, LogLevel::Verbose,
|
|
|
|
("Setting base rect %s for scrollId=%" PRIu64 "\n",
|
|
|
|
ToString(aBase).c_str(), viewId));
|
|
|
|
}
|
|
|
|
aContent->SetProperty(nsGkAtoms::DisplayPortBase, new nsRect(aBase),
|
|
|
|
nsINode::DeleteProperty<nsRect>);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::SetDisplayPortBaseIfNotSet(nsIContent* aContent,
|
|
|
|
const nsRect& aBase) {
|
|
|
|
if (!aContent->GetProperty(nsGkAtoms::DisplayPortBase)) {
|
|
|
|
SetDisplayPortBase(aContent, aBase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::RemoveDisplayPort(nsIContent* aContent) {
|
|
|
|
aContent->RemoveProperty(nsGkAtoms::DisplayPort);
|
|
|
|
aContent->RemoveProperty(nsGkAtoms::DisplayPortMargins);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::ViewportHasDisplayPort(nsPresContext* aPresContext) {
|
|
|
|
nsIFrame* rootScrollFrame = aPresContext->PresShell()->GetRootScrollFrame();
|
|
|
|
return rootScrollFrame && HasDisplayPort(rootScrollFrame->GetContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::IsFixedPosFrameInDisplayPort(const nsIFrame* aFrame) {
|
|
|
|
// Fixed-pos frames are parented by the viewport frame or the page content
|
|
|
|
// frame. We'll assume that printing/print preview don't have displayports for
|
|
|
|
// their pages!
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (!parent || parent->GetParent() ||
|
|
|
|
aFrame->StyleDisplay()->mPosition != StylePositionProperty::Fixed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ViewportHasDisplayPort(aFrame->PresContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to this return true for the scroll frame, but not the
|
|
|
|
// scrolled frame (which has the same content).
|
|
|
|
bool DisplayPortUtils::FrameHasDisplayPort(nsIFrame* aFrame,
|
|
|
|
const nsIFrame* aScrolledFrame) {
|
|
|
|
if (!aFrame->GetContent() || !HasDisplayPort(aFrame->GetContent())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(aFrame);
|
|
|
|
if (sf) {
|
|
|
|
if (aScrolledFrame && aScrolledFrame != sf->GetScrolledFrame()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::CalculateAndSetDisplayPortMargins(
|
|
|
|
nsIScrollableFrame* aScrollFrame, RepaintMode aRepaintMode) {
|
|
|
|
nsIFrame* frame = do_QueryFrame(aScrollFrame);
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
MOZ_ASSERT(content);
|
|
|
|
|
|
|
|
FrameMetrics metrics =
|
|
|
|
nsLayoutUtils::CalculateBasicFrameMetrics(aScrollFrame);
|
|
|
|
ScreenMargin displayportMargins = layers::apz::CalculatePendingDisplayPort(
|
|
|
|
metrics, ParentLayerPoint(0.0f, 0.0f));
|
|
|
|
PresShell* presShell = frame->PresContext()->GetPresShell();
|
Bug 1669982 - Keep the margin adjustment when calculating margins on the main thread. r=botond
The code in CalculateAndSetDisplayPortMargins computes metrics for the content,
which may be the RCD and therefore have separate visual and layout scroll offsets.
The code then uses CalculatePendingDisplayPort to compute displayport margins,
but that function computes the margins based on the visual scroll offset. The
code then uses that as the final margins, when in fact those margins might
need adjusting so that they can be applied to the base rect (which is based
on the layout scroll offset).
This function is invoked by MobileViewportManager after load complete, at
which point the displayport may already be set and the layout and visual offsets
may have diverged. This can happen if, for example, the user manipulates the
visual viewport early during page load, or if a visual viewport is restored
after navigating backwards. In these scenarios the existing "with adjustment"
displayport margins are clobbered by the new, incorrect "with no adjustment"
margins. This patch corrects this by specifying the necessary adjustment.
All the other call sites of this function only call it to initialize the
displayport for the first time, so they cannot run into this problem of
"clobbering" an existing margins. However, I kept this patch general enough
so that if any of those call sites were to change in the future, it wouldn't
run into the same problem.
Differential Revision: https://phabricator.services.mozilla.com/D93494
2020-10-14 23:30:30 +03:00
|
|
|
|
2020-10-29 01:13:14 +03:00
|
|
|
DisplayPortMargins margins = DisplayPortMargins::ForScrollFrame(
|
|
|
|
aScrollFrame, displayportMargins,
|
|
|
|
Some(metrics.DisplayportPixelsPerCSSPixel()));
|
Bug 1669982 - Keep the margin adjustment when calculating margins on the main thread. r=botond
The code in CalculateAndSetDisplayPortMargins computes metrics for the content,
which may be the RCD and therefore have separate visual and layout scroll offsets.
The code then uses CalculatePendingDisplayPort to compute displayport margins,
but that function computes the margins based on the visual scroll offset. The
code then uses that as the final margins, when in fact those margins might
need adjusting so that they can be applied to the base rect (which is based
on the layout scroll offset).
This function is invoked by MobileViewportManager after load complete, at
which point the displayport may already be set and the layout and visual offsets
may have diverged. This can happen if, for example, the user manipulates the
visual viewport early during page load, or if a visual viewport is restored
after navigating backwards. In these scenarios the existing "with adjustment"
displayport margins are clobbered by the new, incorrect "with no adjustment"
margins. This patch corrects this by specifying the necessary adjustment.
All the other call sites of this function only call it to initialize the
displayport for the first time, so they cannot run into this problem of
"clobbering" an existing margins. However, I kept this patch general enough
so that if any of those call sites were to change in the future, it wouldn't
run into the same problem.
Differential Revision: https://phabricator.services.mozilla.com/D93494
2020-10-14 23:30:30 +03:00
|
|
|
|
2021-02-04 14:16:44 +03:00
|
|
|
return SetDisplayPortMargins(content, presShell, margins,
|
|
|
|
ClearMinimalDisplayPortProperty::Yes, 0,
|
|
|
|
aRepaintMode);
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
bool DisplayPortUtils::MaybeCreateDisplayPort(
|
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aScrollFrame,
|
|
|
|
nsIScrollableFrame* aScrollFrameAsScrollable, RepaintMode aRepaintMode) {
|
2020-10-04 00:07:34 +03:00
|
|
|
nsIContent* content = aScrollFrame->GetContent();
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
if (!content) {
|
2020-10-04 00:07:34 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-09 04:41:00 +03:00
|
|
|
bool haveDisplayPort = HasNonMinimalNonZeroDisplayPort(content);
|
2020-10-04 00:07:34 +03:00
|
|
|
|
|
|
|
// We perform an optimization where we ensure that at least one
|
|
|
|
// async-scrollable frame (i.e. one that WantsAsyncScroll()) has a
|
|
|
|
// displayport. If that's not the case yet, and we are async-scrollable, we
|
|
|
|
// will get a displayport.
|
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
|
|
|
nsLayoutUtils::AsyncPanZoomEnabled(aScrollFrame) &&
|
|
|
|
!aBuilder->HaveScrollableDisplayPort() &&
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
aScrollFrameAsScrollable->WantAsyncScroll()) {
|
2020-10-04 00:07:34 +03:00
|
|
|
// If we don't already have a displayport, calculate and set one.
|
|
|
|
if (!haveDisplayPort) {
|
|
|
|
// We only use the viewId for logging purposes, but create it
|
|
|
|
// unconditionally to minimize impact of enabling logging. If we don't
|
|
|
|
// assign a viewId here it will get assigned later anyway so functionally
|
|
|
|
// there should be no difference.
|
|
|
|
ViewID viewId = nsLayoutUtils::FindOrCreateIDFor(content);
|
|
|
|
MOZ_LOG(
|
|
|
|
sDisplayportLog, LogLevel::Debug,
|
|
|
|
("Setting DP on first-encountered scrollId=%" PRIu64 "\n", viewId));
|
|
|
|
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
CalculateAndSetDisplayPortMargins(aScrollFrameAsScrollable, aRepaintMode);
|
2020-10-04 00:07:34 +03:00
|
|
|
#ifdef DEBUG
|
2021-02-04 14:16:59 +03:00
|
|
|
haveDisplayPort = HasNonMinimalDisplayPort(content);
|
2020-10-04 00:07:34 +03:00
|
|
|
MOZ_ASSERT(haveDisplayPort,
|
|
|
|
"should have a displayport after having just set it");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record that the we now have a scrollable display port.
|
|
|
|
aBuilder->SetHaveScrollableDisplayPort();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void DisplayPortUtils::SetZeroMarginDisplayPortOnAsyncScrollableAncestors(
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
2020-12-22 07:00:51 +03:00
|
|
|
frame = nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(frame);
|
2020-10-04 00:07:34 +03:00
|
|
|
if (!frame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIScrollableFrame* scrollAncestor =
|
|
|
|
nsLayoutUtils::GetAsyncScrollableAncestorFrame(frame);
|
|
|
|
if (!scrollAncestor) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = do_QueryFrame(scrollAncestor);
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
MOZ_ASSERT(scrollAncestor->WantAsyncScroll() ||
|
|
|
|
frame->PresShell()->GetRootScrollFrame() == frame);
|
|
|
|
if (nsLayoutUtils::AsyncPanZoomEnabled(frame) &&
|
2021-02-07 00:12:46 +03:00
|
|
|
!HasDisplayPort(frame->GetContent())) {
|
2020-10-04 00:07:34 +03:00
|
|
|
SetDisplayPortMargins(frame->GetContent(), frame->PresShell(),
|
2021-02-04 14:16:44 +03:00
|
|
|
DisplayPortMargins::Empty(frame->GetContent()),
|
2021-02-07 00:12:46 +03:00
|
|
|
ClearMinimalDisplayPortProperty::No, 0,
|
2020-10-08 01:35:07 +03:00
|
|
|
RepaintMode::Repaint);
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayPortUtils::MaybeCreateDisplayPortInFirstScrollFrameEncountered(
|
|
|
|
nsIFrame* aFrame, nsDisplayListBuilder* aBuilder) {
|
2022-02-16 23:20:49 +03:00
|
|
|
// Don't descend into the tab bar in chrome, it can be very large and does not
|
|
|
|
// contain any async scrollable elements.
|
|
|
|
if (XRE_IsParentProcess() && aFrame->GetContent() &&
|
|
|
|
aFrame->GetContent()->GetID() == nsGkAtoms::tabbrowser_arrowscrollbox) {
|
|
|
|
return false;
|
|
|
|
}
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
if (nsIScrollableFrame* sf = do_QueryFrame(aFrame)) {
|
|
|
|
if (MaybeCreateDisplayPort(aBuilder, aFrame, sf, RepaintMode::Repaint)) {
|
2023-03-08 21:39:04 +03:00
|
|
|
// If this was the first displayport found in the first scroll frame
|
|
|
|
// encountered, mark the scroll frame with the current paint sequence
|
|
|
|
// number. This is used later to ensure the displayport created is
|
|
|
|
// never expired. When there is a scrollable frame with a first
|
|
|
|
// scrollable sequence number found that does not match the current
|
|
|
|
// paint sequence number (may occur if the dom was mutated in some way),
|
|
|
|
// the value will be reset.
|
|
|
|
sf->SetIsFirstScrollableFrameSequenceNumber(
|
|
|
|
Some(nsDisplayListBuilder::GetPaintSequenceNumber()));
|
2020-10-04 00:07:34 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aFrame->IsPlaceholderFrame()) {
|
|
|
|
nsPlaceholderFrame* placeholder = static_cast<nsPlaceholderFrame*>(aFrame);
|
|
|
|
if (MaybeCreateDisplayPortInFirstScrollFrameEncountered(
|
|
|
|
placeholder->GetOutOfFlowFrame(), aBuilder)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aFrame->IsSubDocumentFrame()) {
|
|
|
|
PresShell* presShell = static_cast<nsSubDocumentFrame*>(aFrame)
|
|
|
|
->GetSubdocumentPresShellForPainting(0);
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
if (nsIFrame* root = presShell ? presShell->GetRootFrame() : nullptr) {
|
2020-10-04 00:07:34 +03:00
|
|
|
if (MaybeCreateDisplayPortInFirstScrollFrameEncountered(root, aBuilder)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Bug 1689816 - Implement <tabpanels> and <deck> without XUL layout. r=Gijs,Jamie,morgan,preferences-reviewers,mconley,TYLin
Gijs for front-end bits, layout for the new CSS properties and the
removal of nsDeckFrame / nsStackLayout, Jamie and Morgan for the a11y
changes.
As discussed in the bug, the main tricky part here is handling a11y
correctly. For <deck>, that's trivial (just use `visibility: hidden` to
hide the panels visually, while removing the unselected panels from the
a11y tree).
For <tabpanels> however we need to do something special. We do want to
hide stuff visually, but we want to preserve the contents in the a11y
tree.
For that, the easiest fix is introducing a new privileged CSS property
(-moz-subtree-hidden-only-visually), which takes care of not painting
the frame, but marks stuff offscreen in the accessibility tree. This is
not intended to be a property used widely.
Other than that, the changes are relatively straight-forward, though
some of the accessible/mac changes I could get a sanity-check on.
Differential Revision: https://phabricator.services.mozilla.com/D157875
2022-09-27 07:18:16 +03:00
|
|
|
if (aFrame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
|
|
|
|
// Only descend the visible card of deck / tabpanels
|
|
|
|
return false;
|
2020-10-04 00:07:34 +03:00
|
|
|
}
|
|
|
|
for (nsIFrame* child : aFrame->PrincipalChildList()) {
|
|
|
|
if (MaybeCreateDisplayPortInFirstScrollFrameEncountered(child, aBuilder)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayPortUtils::ExpireDisplayPortOnAsyncScrollableAncestor(
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
2021-06-24 01:05:31 +03:00
|
|
|
frame = nsLayoutUtils::GetCrossDocParentFrameInProcess(frame);
|
2020-10-04 00:07:34 +03:00
|
|
|
if (!frame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIScrollableFrame* scrollAncestor =
|
|
|
|
nsLayoutUtils::GetAsyncScrollableAncestorFrame(frame);
|
|
|
|
if (!scrollAncestor) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = do_QueryFrame(scrollAncestor);
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
if (!frame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(scrollAncestor->WantAsyncScroll() ||
|
|
|
|
frame->PresShell()->GetRootScrollFrame() == frame);
|
|
|
|
if (HasDisplayPort(frame->GetContent())) {
|
|
|
|
scrollAncestor->TriggerDisplayPortExpiration();
|
|
|
|
// Stop after the first trigger. If it failed, there's no point in
|
|
|
|
// continuing because all the rest of the frames we encounter are going
|
|
|
|
// to be ancestors of |scrollAncestor| which will keep its displayport.
|
|
|
|
// If the trigger succeeded, we stop because when the trigger executes
|
|
|
|
// it will call this function again to trigger the next ancestor up the
|
|
|
|
// chain.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 04:49:32 +03:00
|
|
|
Maybe<nsRect> DisplayPortUtils::GetRootDisplayportBase(PresShell* aPresShell) {
|
|
|
|
DebugOnly<nsPresContext*> pc = aPresShell->GetPresContext();
|
|
|
|
MOZ_ASSERT(pc, "this function should be called after PresShell::Init");
|
|
|
|
MOZ_ASSERT(pc->IsRootContentDocumentCrossProcess() ||
|
|
|
|
!pc->GetParentPresContext());
|
|
|
|
|
|
|
|
dom::BrowserChild* browserChild = dom::BrowserChild::GetFrom(aPresShell);
|
|
|
|
if (browserChild && !browserChild->IsTopLevel()) {
|
|
|
|
// If this is an in-process root in on OOP iframe, use the visible rect if
|
|
|
|
// it's been set.
|
|
|
|
return browserChild->GetVisibleRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = aPresShell->GetRootScrollFrame();
|
|
|
|
if (!frame) {
|
|
|
|
frame = aPresShell->GetRootFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect baseRect;
|
|
|
|
if (frame) {
|
|
|
|
baseRect = nsRect(nsPoint(0, 0),
|
|
|
|
nsLayoutUtils::CalculateCompositionSizeForFrame(frame));
|
|
|
|
} else {
|
|
|
|
baseRect = nsRect(nsPoint(0, 0),
|
|
|
|
aPresShell->GetPresContext()->GetVisibleArea().Size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Some(baseRect);
|
|
|
|
}
|
|
|
|
|
Bug 1669982 - Keep the margin adjustment when calculating margins on the main thread. r=botond
The code in CalculateAndSetDisplayPortMargins computes metrics for the content,
which may be the RCD and therefore have separate visual and layout scroll offsets.
The code then uses CalculatePendingDisplayPort to compute displayport margins,
but that function computes the margins based on the visual scroll offset. The
code then uses that as the final margins, when in fact those margins might
need adjusting so that they can be applied to the base rect (which is based
on the layout scroll offset).
This function is invoked by MobileViewportManager after load complete, at
which point the displayport may already be set and the layout and visual offsets
may have diverged. This can happen if, for example, the user manipulates the
visual viewport early during page load, or if a visual viewport is restored
after navigating backwards. In these scenarios the existing "with adjustment"
displayport margins are clobbered by the new, incorrect "with no adjustment"
margins. This patch corrects this by specifying the necessary adjustment.
All the other call sites of this function only call it to initialize the
displayport for the first time, so they cannot run into this problem of
"clobbering" an existing margins. However, I kept this patch general enough
so that if any of those call sites were to change in the future, it wouldn't
run into the same problem.
Differential Revision: https://phabricator.services.mozilla.com/D93494
2020-10-14 23:30:30 +03:00
|
|
|
} // namespace mozilla
|