Skip to content

Commit

Permalink
Bug 1745529 - Use default action target to compute scroll amount. r=m…
Browse files Browse the repository at this point in the history
…asayuki

This avoids pages having different scroll amount if there are overflow:
hidden elements with different font sizes.

Running through try to see if there's any test to adjust or I need to
write one.

Differential Revision: https://phabricator.services.mozilla.com/D133671
  • Loading branch information
emilio committed Dec 14, 2021
1 parent f6d6922 commit 71f30bf
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1,023 deletions.
18 changes: 14 additions & 4 deletions dom/events/EventStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,12 @@ nsSize EventStateManager::GetScrollAmount(
MOZ_ASSERT(aPresContext);
MOZ_ASSERT(aEvent);

bool isPage = (aEvent->mDeltaMode == WheelEvent_Binding::DOM_DELTA_PAGE);
const bool isPage = aEvent->mDeltaMode == WheelEvent_Binding::DOM_DELTA_PAGE;
if (!aScrollableFrame) {
// If there is no scrollable frame, we should use root, see below.
aScrollableFrame = aPresContext->PresShell()->GetRootScrollFrameAsScrollable();
}

if (aScrollableFrame) {
return isPage ? aScrollableFrame->GetPageScrollAmount()
: aScrollableFrame->GetLineScrollAmount();
Expand All @@ -2858,7 +2863,12 @@ nsSize EventStateManager::GetScrollAmount(
return aPresContext->GetVisibleArea().Size();
}

// If there is no scrollable frame, we should use root frame's information.
// Otherwise use root frame's font metrics.
//
// FIXME(emilio): Should this use the root element's style frame? The root
// frame will always have the initial font. Then again it should never matter
// for content, we should always have a root scrollable frame in html
// documents.
nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame();
if (!rootFrame) {
return nsSize(0, 0);
Expand Down Expand Up @@ -6197,8 +6207,8 @@ void EventStateManager::DeltaAccumulator::InitLineOrPageDelta(
mIsNoLineOrPageDeltaDevice = aEvent->mIsNoLineOrPageDelta;

{
nsIFrame* frame = aESM->ComputeScrollTarget(
aTargetFrame, aEvent, COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET);
nsIFrame* frame = aESM->ComputeScrollTarget(aTargetFrame, aEvent,
COMPUTE_DEFAULT_ACTION_TARGET);
nsPresContext* pc =
frame ? frame->PresContext() : aTargetFrame->PresContext();
nsIScrollableFrame* scrollTarget = do_QueryFrame(frame);
Expand Down
Loading

0 comments on commit 71f30bf

Please sign in to comment.