Skip to content

Commit

Permalink
[iPadOS] Align scroll position to origin on resize in Multitasking mode
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=240815
rdar://92888214

Reviewed by Devin Rousso.

Make a minor adjustment to avoid re-centering the target unobscured content rect on the hit-tested
node in the center of the viewport, when multitasking mode is enabled; instead, we can simply
preserve the existing unobscured content rect offset.

* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:

We can also avoid this hit-test when `usesMultitaskingModeViewportBehaviors()` is enabled, since we
only need to anchor to the origin of the current unobscured rect.

(WebKit::WebPage::dynamicViewportSizeUpdate):

Canonical link: https://commits.webkit.org/250894@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294690 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed May 23, 2022
1 parent 68fb4b5 commit e00d2ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Expand Up @@ -3643,6 +3643,7 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
FrameView& frameView = *m_page->mainFrame().view();
IntSize oldContentSize = frameView.contentsSize();
float oldPageScaleFactor = m_page->pageScaleFactor();
auto oldUnobscuredContentRect = frameView.unobscuredContentRect();
bool wasAtInitialScale = areEssentiallyEqualAsFloat(oldPageScaleFactor, m_viewportConfiguration.initialScale());

m_dynamicSizeUpdateHistory.add(std::make_pair(oldContentSize, oldPageScaleFactor), frameView.scrollPosition());
Expand All @@ -3651,7 +3652,7 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
double visibleHorizontalFraction = 1;
float relativeHorizontalPositionInNodeAtCenter = 0;
float relativeVerticalPositionInNodeAtCenter = 0;
{
if (!usesMultitaskingModeViewportBehaviors()) {
visibleHorizontalFraction = frameView.unobscuredContentSize().width() / oldContentSize.width();
IntPoint unobscuredContentRectCenter = frameView.unobscuredContentRect().center();

Expand Down Expand Up @@ -3705,8 +3706,15 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
double scaleDifference = targetScale / scale;
double newUnobscuredRectWidth = targetUnobscuredRect.width() * scaleDifference;
double newUnobscuredRectHeight = targetUnobscuredRect.height() * scaleDifference;
double newUnobscuredRectX = targetUnobscuredRect.x() - (newUnobscuredRectWidth - targetUnobscuredRect.width()) / 2;
double newUnobscuredRectY = targetUnobscuredRect.y() - (newUnobscuredRectHeight - targetUnobscuredRect.height()) / 2;
double newUnobscuredRectX;
double newUnobscuredRectY;
if (usesMultitaskingModeViewportBehaviors()) {
newUnobscuredRectX = oldUnobscuredContentRect.x();
newUnobscuredRectY = oldUnobscuredContentRect.y();
} else {
newUnobscuredRectX = targetUnobscuredRect.x() - (newUnobscuredRectWidth - targetUnobscuredRect.width()) / 2;
newUnobscuredRectY = targetUnobscuredRect.y() - (newUnobscuredRectHeight - targetUnobscuredRect.height()) / 2;
}
newUnobscuredContentRect = FloatRect(newUnobscuredRectX, newUnobscuredRectY, newUnobscuredRectWidth, newUnobscuredRectHeight);

// 2) Extend our new unobscuredRect by the obscured margins to get a new exposed rect.
Expand Down

0 comments on commit e00d2ca

Please sign in to comment.