Backed out 2 changesets (bug 1871760) for causing Wr failures on window-scrollBy-display-change.html CLOSED TREE

Backed out changeset 0824e173f725 (bug 1871760)
Backed out changeset 4075109d54d0 (bug 1871760)
This commit is contained in:
Norisz Fay 2024-02-09 14:46:05 +02:00
Родитель ce60a9024f
Коммит c9baa82308
10 изменённых файлов: 86 добавлений и 24 удалений

Просмотреть файл

@ -147,10 +147,12 @@ CSSSize FrameMetrics::CalculateCompositedSizeInCssPixels(
return aCompositionBounds.Size() / aZoom;
}
bool FrameMetrics::ApplyScrollUpdateFrom(const ScrollPositionUpdate& aUpdate) {
std::pair<bool, CSSPoint> FrameMetrics::ApplyAbsoluteScrollUpdateFrom(
const ScrollPositionUpdate& aUpdate) {
CSSPoint oldVisualOffset = GetVisualScrollOffset();
// In applying a main-thread scroll update, try to preserve the relative
// offset between the visual and layout viewports.
CSSPoint relativeOffset = GetVisualScrollOffset() - GetLayoutScrollOffset();
CSSPoint relativeOffset = oldVisualOffset - GetLayoutScrollOffset();
MOZ_ASSERT(IsRootContent() || relativeOffset == CSSPoint());
// We need to set the two offsets together, otherwise a subsequent
// RecalculateLayoutViewportOffset() could see divergent layout and
@ -158,7 +160,7 @@ bool FrameMetrics::ApplyScrollUpdateFrom(const ScrollPositionUpdate& aUpdate) {
bool offsetChanged = SetLayoutScrollOffset(aUpdate.GetDestination());
offsetChanged |=
ClampAndSetVisualScrollOffset(aUpdate.GetDestination() + relativeOffset);
return offsetChanged;
return {offsetChanged, GetVisualScrollOffset() - oldVisualOffset};
}
CSSPoint FrameMetrics::ApplyRelativeScrollUpdateFrom(
@ -166,7 +168,7 @@ CSSPoint FrameMetrics::ApplyRelativeScrollUpdateFrom(
MOZ_ASSERT(aUpdate.GetType() == ScrollUpdateType::Relative);
CSSPoint origin = GetVisualScrollOffset();
CSSPoint delta = (aUpdate.GetDestination() - aUpdate.GetSource());
SetVisualScrollOffset(origin + delta);
ClampAndSetVisualScrollOffset(origin + delta);
return GetVisualScrollOffset() - origin;
}

Просмотреть файл

@ -243,9 +243,11 @@ struct FrameMetrics {
}
/*
* Returns true if the layout scroll offset or visual scroll offset changed.
* Returns true if the layout scroll offset or visual scroll offset changed
* and returns the visual scroll offset change delta.
*/
bool ApplyScrollUpdateFrom(const ScrollPositionUpdate& aUpdate);
std::pair<bool, CSSPoint> ApplyAbsoluteScrollUpdateFrom(
const ScrollPositionUpdate& aUpdate);
/**
* Applies the relative scroll offset update contained in aOther to the

Просмотреть файл

@ -5581,6 +5581,17 @@ void AsyncPanZoomController::NotifyLayersUpdated(
aScrollMetadata.GetOverscrollBehavior());
}
if (needToReclampScroll) {
// Whenever scrollable rect or composition bounds has changed, we need to
// re-clamp the scroll offset since it may be out of bounds. Also note that
// we need to re-clamp before updating new scroll offsets from content since
// we will use the last scroll offset to reflect the new offsets.
ClampAndSetVisualScrollOffset(Metrics().GetVisualScrollOffset());
for (auto& sampledState : mSampledState) {
sampledState.ClampVisualScrollOffset(Metrics());
}
}
bool instantScrollMayTriggerTransform = false;
bool scrollOffsetUpdated = false;
bool smoothScrollRequested = false;
@ -5727,11 +5738,20 @@ void AsyncPanZoomController::NotifyLayersUpdated(
relativeDelta =
Some(Metrics().ApplyPureRelativeScrollUpdateFrom(scrollUpdate));
Metrics().RecalculateLayoutViewportOffset();
} else if (scrollUpdate.GetType() == ScrollUpdateType::MergeableAbsolute) {
APZC_LOG("%p mergeable updating scroll offset from %s to %s\n", this,
ToString(Metrics().GetVisualScrollOffset()).c_str(),
ToString(scrollUpdate.GetDestination()).c_str());
relativeDelta =
Some(Metrics().ApplyAbsoluteScrollUpdateFrom(scrollUpdate).second);
Metrics().RecalculateLayoutViewportOffset();
scrollOffsetUpdated = true;
} else {
APZC_LOG("%p updating scroll offset from %s to %s\n", this,
ToString(Metrics().GetVisualScrollOffset()).c_str(),
ToString(scrollUpdate.GetDestination()).c_str());
bool offsetChanged = Metrics().ApplyScrollUpdateFrom(scrollUpdate);
auto [offsetChanged, _] =
Metrics().ApplyAbsoluteScrollUpdateFrom(scrollUpdate);
Metrics().RecalculateLayoutViewportOffset();
if (offsetChanged || scrollUpdate.GetMode() != ScrollMode::Instant ||
@ -5768,15 +5788,6 @@ void AsyncPanZoomController::NotifyLayersUpdated(
}
}
if (needToReclampScroll) {
// The scrollable rect or composition bounds may have changed in a way that
// makes our local scroll offset out of bounds, so clamp it.
ClampAndSetVisualScrollOffset(Metrics().GetVisualScrollOffset());
for (auto& sampledState : mSampledState) {
sampledState.ClampVisualScrollOffset(Metrics());
}
}
if (scrollOffsetUpdated) {
for (auto& sampledState : mSampledState) {
if (!didCancelAnimation && cumulativeRelativeDelta.isSome()) {

Просмотреть файл

@ -520,7 +520,7 @@ template <>
struct ParamTraits<mozilla::ScrollUpdateType>
: public ContiguousEnumSerializerInclusive<
mozilla::ScrollUpdateType, mozilla::ScrollUpdateType::Absolute,
mozilla::ScrollUpdateType::PureRelative> {};
mozilla::ScrollUpdateType::MergeableAbsolute> {};
template <>
struct ParamTraits<mozilla::ScrollMode>

Просмотреть файл

@ -539,8 +539,11 @@ void ScrollAnchorContainer::ApplyAdjustments() {
MOZ_RELEASE_ASSERT(!mApplyingAnchorAdjustment);
// We should use AutoRestore here, but that doesn't work with bitfields
mApplyingAnchorAdjustment = true;
Frame()->ScrollToInternal(Frame()->GetScrollPosition() + physicalAdjustment,
ScrollMode::Instant, ScrollOrigin::Relative);
Frame()->ScrollToInternal(
Frame()->GetScrollPosition() + physicalAdjustment, ScrollMode::Instant,
StaticPrefs::layout_css_scroll_anchoring_absolute_update()
? ScrollOrigin::AnchorAdjustment
: ScrollOrigin::Relative);
mApplyingAnchorAdjustment = false;
if (Frame()->mIsRoot) {

Просмотреть файл

@ -33,6 +33,8 @@ enum class ScrollOrigin : uint8_t {
// The scroll came from an attempt by the main thread to re-clamp the scroll
// position after a reflow.
Clamp,
// The scroll came from a scroll adjustment triggered by scroll anchoring.
AnchorAdjustment,
// The following scroll origins also are associated with prefs of the form
// general.smoothScroll.<origin>(.*)

Просмотреть файл

@ -93,6 +93,20 @@ ScrollPositionUpdate ScrollPositionUpdate::NewPureRelativeScroll(
return ret;
}
/*static*/
ScrollPositionUpdate ScrollPositionUpdate::NewMergeableScroll(
ScrollOrigin aOrigin, nsPoint aDestination) {
MOZ_ASSERT(aOrigin == ScrollOrigin::AnchorAdjustment);
ScrollPositionUpdate ret;
ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
ret.mType = ScrollUpdateType::MergeableAbsolute;
ret.mScrollMode = ScrollMode::Instant;
ret.mScrollOrigin = aOrigin;
ret.mDestination = CSSPoint::FromAppUnits(aDestination);
return ret;
}
bool ScrollPositionUpdate::operator==(
const ScrollPositionUpdate& aOther) const {
// instances are immutable, and all the fields are set when the generation
@ -112,6 +126,7 @@ ScrollOrigin ScrollPositionUpdate::GetOrigin() const { return mScrollOrigin; }
CSSPoint ScrollPositionUpdate::GetDestination() const {
MOZ_ASSERT(mType == ScrollUpdateType::Absolute ||
mType == ScrollUpdateType::MergeableAbsolute ||
mType == ScrollUpdateType::Relative);
return mDestination;
}

Просмотреть файл

@ -34,6 +34,9 @@ enum class ScrollUpdateType {
// The delta should be applied to whatever the current scroll position is
// on the receiver side.
PureRelative,
// Similar to |Absolute|, but even if there's an active async scroll animation
// the position update will NOT cancel the async scroll animation.
MergeableAbsolute,
};
enum class ScrollTriggeredByScript : bool { No, Yes };
@ -83,6 +86,9 @@ class ScrollPositionUpdate {
ScrollMode aMode,
const nsPoint& aDelta);
static ScrollPositionUpdate NewMergeableScroll(ScrollOrigin aOrigin,
nsPoint aDestination);
bool operator==(const ScrollPositionUpdate& aOther) const;
MainThreadScrollGeneration GetGeneration() const;

Просмотреть файл

@ -2235,7 +2235,12 @@ void nsHTMLScrollFrame::AsyncScroll::InitSmoothScroll(
case ScrollOrigin::Apz:
// Likewise we should never get APZ-triggered scrolls here, and if that
// changes something is likely broken somewhere.
MOZ_ASSERT(false);
MOZ_ASSERT_UNREACHABLE(
"APZ scroll position updates should never be smooth");
break;
case ScrollOrigin::AnchorAdjustment:
MOZ_ASSERT_UNREACHABLE(
"scroll anchor adjustments should never be smooth");
break;
default:
break;
@ -3011,6 +3016,7 @@ void nsHTMLScrollFrame::ScrollToImpl(
(mLastScrollOrigin != ScrollOrigin::None &&
mLastScrollOrigin != ScrollOrigin::NotSpecified &&
mLastScrollOrigin != ScrollOrigin::Relative &&
mLastScrollOrigin != ScrollOrigin::AnchorAdjustment &&
mLastScrollOrigin != ScrollOrigin::Apz)) {
aOrigin = ScrollOrigin::Other;
}
@ -3063,8 +3069,10 @@ void nsHTMLScrollFrame::ScrollToImpl(
// may simplify this a bit and should be fine from the APZ side.
if (mApzSmoothScrollDestination && aOrigin != ScrollOrigin::Clamp) {
if (aOrigin == ScrollOrigin::Relative) {
AppendScrollUpdate(
ScrollPositionUpdate::NewRelativeScroll(mApzScrollPos, pt));
AppendScrollUpdate(ScrollPositionUpdate::NewRelativeScroll(
// Clamp |mApzScrollPos| here. See the comment for this clamping
// reason below NewRelativeScroll call.
GetLayoutScrollRange().ClampPoint(mApzScrollPos), pt));
mApzScrollPos = pt;
} else if (aOrigin != ScrollOrigin::Apz) {
ScrollOrigin origin =
@ -3151,8 +3159,15 @@ void nsHTMLScrollFrame::ScrollToImpl(
if (aOrigin == ScrollOrigin::Relative) {
MOZ_ASSERT(!isScrollOriginDowngrade);
MOZ_ASSERT(mLastScrollOrigin == ScrollOrigin::Relative);
AppendScrollUpdate(
ScrollPositionUpdate::NewRelativeScroll(mApzScrollPos, pt));
AppendScrollUpdate(ScrollPositionUpdate::NewRelativeScroll(
// It's possible that |mApzScrollPos| is no longer within the scroll
// range, we need to clamp it to the current scroll range, otherwise
// calculating a relative scroll distance from the outside point will
// result a point far from the desired point.
GetLayoutScrollRange().ClampPoint(mApzScrollPos), pt));
mApzScrollPos = pt;
} else if (aOrigin == ScrollOrigin::AnchorAdjustment) {
AppendScrollUpdate(ScrollPositionUpdate::NewMergeableScroll(aOrigin, pt));
mApzScrollPos = pt;
} else if (aOrigin != ScrollOrigin::Apz) {
AppendScrollUpdate(ScrollPositionUpdate::NewScroll(mLastScrollOrigin, pt));

Просмотреть файл

@ -9210,6 +9210,12 @@
value: true
mirror: always
# Handle scroll-anchoring adjustments as absolute scroll position updates.
- name: layout.css.scroll-anchoring.absolute-update
type: bool
value: true
mirror: always
# Are shared memory User Agent style sheets enabled?
- name: layout.css.shared-memory-ua-sheets.enabled
type: bool