Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c48b2af7092c5e7b62355010f2c66e704fc64a7f
      
https://github.com/WebKit/WebKit/commit/c48b2af7092c5e7b62355010f2c66e704fc64a7f
  Author: Aditya Keerthi <[email protected]>
  Date:   2025-06-13 (Fri, 13 Jun 2025)

  Changed paths:
    M Source/WebCore/platform/ScrollView.h
    M Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h
    M Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm

  Log Message:
  -----------
  [UnifiedPDF][iOS] Relative scroll position is not preserved in zoomed 
content, following a viewport update
https://bugs.webkit.org/show_bug.cgi?id=294472
rdar://153191283

Reviewed by Wenson Hsieh and Abrar Rahman Protyasha.

On iOS, the contents size of the frame view is changed to "fit" a displayed PDF.
In general, when the contents size of the frame view changes, 
`ScrollView::setContentsSize`
may update the scroll position underneath `ScrollView::updateScrollbars`.

`updateScrollbars` adjusts the desired position to fit with the new minimum and
maximum positions, and requests a programmatic scroll if the adjusted position
is different from the current position. When zoomed and scrolled, a viewport
update may reduce the maximum position, resulting in the x-coordinate of the
desired position getting clamped. At the time of the content size update in the
web process, the y-coordinate is still the same value as it was before the
content size update.

Consequently, the adjusted position differs in the x-coordinate, and a
programmatic scroll request is made. Before the request is serviced, the logic
added in 295715@main kicks in and attempts to preserve the relative scroll
position. However, the scroll request is then serviced, pulling the y-coordinate
back to the old value, negating the fix in 295715@main.

To fix, simply prohibit scrolling due to content size changes in the web 
process.
The scroll position is already corrected in the UI process for PDFs, making the
other logic unnecessary and risky.

* Source/WebCore/platform/ScrollView.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:

Use an existing mechanism to prohibit scrolling due to content size changes.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm:
(TestWebKitAPI::UNIFIED_PDF_TEST(KeepRelativeScrollPositionAfterZoomingAndViewportUpdate)):

Swizzle `-[UIPinchGestureRecognizer state]` to simulate a user pinch zooming.
This is necessary, as otherwise the initial scale of 1 is restored when the
layout size is changed programmatically.

Canonical link: https://commits.webkit.org/296222@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to