Skip to content

Commit

Permalink
Bug 1701597.When zooming to a rect horizontally center it. r=botond
Browse files Browse the repository at this point in the history
We already vertically center the rect, but not horizontally. We generally try to zoom to the width of an element already, so the width of the zoom to rect will usually occupy the whole viewport and hence be centered. But if the width of the element is too small so that we can't zoom in so that it fills the viewport it will end up left aligned. This doesn't come up very often on mobile, but happens more so on desktop.

Differential Revision: https://phabricator.services.mozilla.com/D110063
  • Loading branch information
tnikkel committed Apr 8, 2021
1 parent 4b5ce0c commit 8a3c4a2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gfx/layers/apz/src/AsyncPanZoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5482,6 +5482,14 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect, const uint32_t aFlags) {
}
}

// Horizontally center the zoomed element in the screen.
if (!zoomOut && (sizeAfterZoom.width > aRect.Width())) {
aRect.MoveByX(-(sizeAfterZoom.width - aRect.Width()) * 0.5f);
if (aRect.X() < 0.0f) {
aRect.MoveToX(0.0f);
}
}

// If either of these conditions are met, the page will be
// overscrolled after zoomed
if (aRect.Y() + sizeAfterZoom.height > cssPageRect.Height()) {
Expand Down

0 comments on commit 8a3c4a2

Please sign in to comment.