Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: b32dad0669e5ac9124d50dfe8036704e0f6c6aea https://github.com/WebKit/WebKit/commit/b32dad0669e5ac9124d50dfe8036704e0f6c6aea Author: Wenson Hsieh <wenson_hs...@apple.com> Date: 2024-04-18 (Thu, 18 Apr 2024)
Changed paths: M Source/WebCore/platform/KeyboardScrollingAnimator.h M Source/WebCore/platform/ScrollAnimator.h M Source/WebCore/plugins/PluginViewBase.h M Source/WebCore/testing/Internals.cpp M Source/WebCore/testing/Internals.h M Source/WebCore/testing/Internals.idl M Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h M Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h M Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm M Source/WebKit/WebProcess/Plugins/PluginView.cpp M Source/WebKit/WebProcess/Plugins/PluginView.h M Tools/TestWebKitAPI/SourcesCocoa.txt M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj A Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIAction.mm M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIMenus.mm M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebRequest.mm A Tools/TestWebKitAPI/Tests/WebKitCocoa/multiple-pages.pdf M Tools/TestWebKitAPI/cocoa/TestWKWebView.h M Tools/TestWebKitAPI/cocoa/TestWKWebView.mm Log Message: ----------- [Unified PDF] [macOS] Can't use the arrow keys to navigate between pages in Single page mode https://bugs.webkit.org/show_bug.cgi?id=272828 rdar://123193004 Reviewed by Abrar Protyasha. Implement keyboard scrolling when viewing PDFs in Single Page mode. The behavior (mostly) matches that in prior macOS versions, but with the added nicety that keyboard scrolling is now smoothly animated (rather than discrete). Test: UnifiedPDF.KeyboardScrollingInSinglePageMode * Source/WebCore/platform/KeyboardScrollingAnimator.h: * Source/WebCore/platform/ScrollAnimator.h: `WEBCORE_EXPORT` several helper methods, so we can use them to service keyboard scrolling in `UnifiedPDFPlugin`. * Source/WebCore/plugins/PluginViewBase.h: (WebCore::PluginViewBase::setPDFDisplayModeForTesting): * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::setPDFDisplayModeForTesting const): * Source/WebCore/testing/Internals.h: * Source/WebCore/testing/Internals.idl: Add an `internals` testing hook to set the current PDF display mode. The arguments are strings that match the internal `enum class` names: ``` SinglePageDiscrete SinglePageContinuous TwoUpDiscrete TwoUpContinuous ``` * Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h: (WebKit::PDFPluginBase::annotationRectsForTesting const): (WebKit::PDFPluginBase::setPDFDisplayModeForTesting): * Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h: * Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm: (WebKit::UnifiedPDFPlugin::didChangeScrollOffset): See comments in `handleKeyboardEventForDiscreteDisplayMode` below. (WebKit::UnifiedPDFPlugin::isInDiscreteDisplayMode const): Rename this to `isInDiscreteDisplayMode`, since it's now used to guard keyboard scrolling behaviors that are specific to discrete display modes (both two-up and single). (WebKit::UnifiedPDFPlugin::isShowingTwoPages const): Add a helper method that returns whether or not we're in two-up mode. Currently, only used in a couple places to determine the offset of the next set of pages when scrolling with arrow keys, if the page is (/pages are) shorter than the viewport. (WebKit::UnifiedPDFPlugin::pageBoundsInContentsSpace const): Pull this out into a helper method, so we can use it from multiple places. (WebKit::UnifiedPDFPlugin::updateSnapOffsets): Make a slight adjustment here to snap to the *closest* snap offset rather than the first offset past the current scroll position. This ensures that the `m_currentlySnappedPage` doesn't prematurely jump to the previous page in `handleKeyboardEventForDiscreteDisplayMode` when determining whether we're near a snap point. (WebKit::UnifiedPDFPlugin::determineCurrentlySnappedPage): (WebKit::UnifiedPDFPlugin::shouldDisplayPage): (WebKit::UnifiedPDFPlugin::checkedKeyboardScrollingAnimator const): (WebKit::UnifiedPDFPlugin::handleKeyboardCommand): Factor this out into a separate method to make the code easier to follow. (WebKit::UnifiedPDFPlugin::handleKeyboardEventForDiscreteDisplayMode): Implement the main keyboard scrolling logic here — if the page is shorter than the viewport, we want to instantly jump to the next or previous page (or set of 2 pages). If the page is taller than the viewport (e.g. when zooming within a page in Single Page mode), we want to allow the user to scroll within the page, and clamp scrolling to the edges of the page. To achieve this, we detect when the user is about to scroll near either the top or bottom page extent — in this case, we: 1. Stop animated keyboard scrolling immediately. 2. Scroll (with animation) to the edge of the page. Note that in order for this to work, we also need logic within `didChangeScrollOffset` to also drive this "snap to edge" animation. This is because we aren't guaranteed to receive key events in `handleKeyboardEvent` when the user is about to scroll past the end of the page, if the user has disabled key repeat in macOS preferences, so we can't rely (solely) on the logic here to snap to the edge. That said, we *additionally* need logic here to prevent key events from starting animated keyboard scrolling (and snap to the edge instead), otherwise we end up with a stuttering scroll offset if the user tries to scroll against the edge of the page with arrow keys. (WebKit::UnifiedPDFPlugin::snapToNearbyPageExtentForKeyboardScrolling): (WebKit::UnifiedPDFPlugin::animatedScrollDidEnd): (WebKit::UnifiedPDFPlugin::handleKeyboardEvent): (WebKit::UnifiedPDFPlugin::performContextMenuAction): (WebKit::UnifiedPDFPlugin::setPDFDisplayModeForTesting): (WebKit::UnifiedPDFPlugin::setDisplayModeAndUpdateLayout): (WebKit::UnifiedPDFPlugin::shouldUseScrollSnapping const): Deleted. * Source/WebKit/WebProcess/Plugins/PluginView.cpp: (WebKit::PluginView::setPDFDisplayModeForTesting): * Source/WebKit/WebProcess/Plugins/PluginView.h: * Tools/TestWebKitAPI/SourcesCocoa.txt: * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm: Added. (TestWebKitAPI::sampleColorsInWebView): (TestWebKitAPI::TEST(UnifiedPDF, KeyboardScrollingInSinglePageMode)): Add a test to verify that keyboard scrolling works in single page mode (both vertical and horizontal scrolling), when zoomed in. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIAction.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIMenus.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebRequest.mm: Add missing includes in unrelated API tests, which now cause build failures when adding the new test source file. * Tools/TestWebKitAPI/Tests/WebKitCocoa/multiple-pages.pdf: Added. * Tools/TestWebKitAPI/cocoa/TestWKWebView.h: * Tools/TestWebKitAPI/cocoa/TestWKWebView.mm: (-[TestWKWebView sendKey:code:isDown:modifiers:]): (-[TestWKWebView typeCharacter:modifiers:]): Split this out into another helper method that only sends keydown or keyup. Canonical link: https://commits.webkit.org/277656@main To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes