⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245285 in webkit


Ignore:
Timestamp:
May 14, 2019, 9:43:51 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[iOS] Cannot scroll to beginning of document after scrolling to end of document and vice versa via key commands
https://bugs.webkit.org/show_bug.cgi?id=197848
<rdar://problem/49523065>

Patch by Daniel Bates <dabates@apple.com> on 2019-05-14
Reviewed by Brent Fulgham.

Source/WebKit:

Following the fix for <rdar://problem/49523065>, UIKit no longer emits a keyup event for a Command-
modified key. This breaks WebKit's own implementation of key command handling for scrolling to the
beginning or end of the document (triggered using Command + Arrow Up and Command + Arrow Down,
respectively) because it watches for keyup events to reset state after initiating a scroll. If state
is not reset then the scroll key command logic becomes confused and may not perform a subsequent scroll.
It seems like we can actually get away with supporting these key commands and future Command modified
commands by preemptively reseting state on keydown if the Command modifier is held down. If this does
not work out then we can do something more complicated.

  • UIProcess/ios/WKKeyboardScrollingAnimator.mm:

(-[WKKeyboardScrollingAnimator handleKeyEvent:]):

LayoutTests:

Add a test to ensure that key commands can be used to scroll to the end of the page and then
to the beginning of the page.

  • fast/scrolling/ios/scroll-to-beginning-and-end-of-document-expected.txt: Added.
  • fast/scrolling/ios/scroll-to-beginning-and-end-of-document.html: Added.
  • resources/ui-helper.js:

(window.UIHelper.callFunctionAndWaitForScrollToFinish): Added. Convenience function that invokes the
specified function and returns a Promise that is resolved once the page has finished scrolling. To know
if the page has finished scrolling we listen for DOM scroll events and repeatedly reset a 300ms timer.
The delay of 300ms was chosen to be > 250ms (to give some margin of error), which is the upper bound
delay between scroll event firings, last I recall. When the timer expires we assume that page has
finished scrolling.
(window.UIHelper):

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245280 r245285  
     12019-05-14  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Cannot scroll to beginning of document after scrolling to end of document and vice versa via key commands
     4        https://bugs.webkit.org/show_bug.cgi?id=197848
     5        <rdar://problem/49523065>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Add a test to ensure that key commands can be used to scroll to the end of the page and then
     10        to the beginning of the page.
     11
     12        * fast/scrolling/ios/scroll-to-beginning-and-end-of-document-expected.txt: Added.
     13        * fast/scrolling/ios/scroll-to-beginning-and-end-of-document.html: Added.
     14        * resources/ui-helper.js:
     15        (window.UIHelper.callFunctionAndWaitForScrollToFinish): Added. Convenience function that invokes the
     16        specified function and returns a Promise that is resolved once the page has finished scrolling. To know
     17        if the page has finished scrolling we listen for DOM scroll events and repeatedly reset a 300ms timer.
     18        The delay of 300ms was chosen to be > 250ms (to give some margin of error), which is the upper bound
     19        delay between scroll event firings, last I recall. When the timer expires we assume that page has
     20        finished scrolling.
     21        (window.UIHelper):
     22
    1232019-05-14  Said Abou-Hallawa  <sabouhallawa@apple.com>
    224
  • trunk/LayoutTests/resources/ui-helper.js

    r245062 r245285  
    885885            await this.activateAt(menuRect.left + menuRect.width / 2, menuRect.top + menuRect.height / 2);
    886886    }
     887
     888    static callFunctionAndWaitForScrollToFinish(functionToCall, ...theArguments)
     889    {
     890        return new Promise((resolved) => {
     891            function scrollDidFinish() {
     892                window.removeEventListener("scroll", handleScroll, true);
     893                resolved();
     894            }
     895
     896            let lastScrollTimerId = 0; // When the timer with this id fires then the page has finished scrolling.
     897            function handleScroll() {
     898                if (lastScrollTimerId) {
     899                    window.clearTimeout(lastScrollTimerId);
     900                    lastScrollTimerId = 0;
     901                }
     902                lastScrollTimerId = window.setTimeout(scrollDidFinish, 300); // Over 250ms to give some room for error.
     903            }
     904            window.addEventListener("scroll", handleScroll, true);
     905
     906            functionToCall.apply(this, theArguments);
     907        });
     908    }
    887909}
  • trunk/Source/WebKit/ChangeLog

    r245284 r245285  
     12019-05-14  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Cannot scroll to beginning of document after scrolling to end of document and vice versa via key commands
     4        https://bugs.webkit.org/show_bug.cgi?id=197848
     5        <rdar://problem/49523065>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Following the fix for <rdar://problem/49523065>, UIKit no longer emits a keyup event for a Command-
     10        modified key. This breaks WebKit's own implementation of key command handling for scrolling to the
     11        beginning or end of the document (triggered using Command + Arrow Up and Command + Arrow Down,
     12        respectively) because it watches for keyup events to reset state after initiating a scroll. If state
     13        is not reset then the scroll key command logic becomes confused and may not perform a subsequent scroll.
     14        It seems like we can actually get away with supporting these key commands and future Command modified
     15        commands by preemptively reseting state on keydown if the Command modifier is held down. If this does
     16        not work out then we can do something more complicated.
     17
     18        * UIProcess/ios/WKKeyboardScrollingAnimator.mm:
     19        (-[WKKeyboardScrollingAnimator handleKeyEvent:]):
     20
    1212019-05-14  Brent Fulgham  <bfulgham@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm

    r244955 r245285  
    347347
    348348    auto scroll = [self keyboardScrollForEvent:event];
    349     if (!scroll || event.type == WebEventKeyUp) {
     349
     350    // UIKit does not emit a keyup event when the Command key is down. See <rdar://problem/49523065>.
     351    // For recognized key commands that include the Command key (e.g. Command + Arrow Up) we reset our
     352    // state on keydown.
     353    if (!scroll || event.type == WebEventKeyUp || (event.modifierFlags & WebEventFlagMaskCommandKey)) {
    350354        [self stopAnimatedScroll];
    351355        _scrollTriggeringKeyIsPressed = NO;
Note: See TracChangeset for help on using the changeset viewer.