Make it possible to disable animated keyboard scrolling behavior
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2018 01:15:13 +0000 (01:15 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2018 01:15:13 +0000 (01:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192331
<rdar://problem/45586859>

Reviewed by Simon Fraser.

* UIProcess/API/Cocoa/WKWebView.mm:
* UIProcess/ios/WKKeyboardScrollingAnimator.mm:
(-[WKKeyboardScrollingAnimator invalidate]):
(-[WKKeyboardScrollingAnimator beginWithEvent:]):
(-[WKKeyboardScrollingAnimator stopAnimatedScroll]):
(-[WKKeyboardScrollingAnimator willStartInteractiveScroll]):
(-[WKKeyboardScrollingAnimator startRepeatTimerIfNeeded]):
(-[WKKeyboardScrollingAnimator stopRepeatTimer]):
(-[WKKeyboardScrollingAnimator performDiscreteScroll]):
(-[WKKeyboardScrollViewAnimator scrollToContentOffset:animated:]):
(-[WKKeyboardScrollViewAnimator scrollWithScrollToExtentAnimationTo:]):
* WebKit.xcodeproj/project.pbxproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238834 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index a5c9993..b9c0349 100644 (file)
@@ -1,3 +1,24 @@
+2018-12-03  Tim Horton  <timothy_horton@apple.com>
+
+        Make it possible to disable animated keyboard scrolling behavior
+        https://bugs.webkit.org/show_bug.cgi?id=192331
+        <rdar://problem/45586859>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        * UIProcess/ios/WKKeyboardScrollingAnimator.mm:
+        (-[WKKeyboardScrollingAnimator invalidate]):
+        (-[WKKeyboardScrollingAnimator beginWithEvent:]):
+        (-[WKKeyboardScrollingAnimator stopAnimatedScroll]):
+        (-[WKKeyboardScrollingAnimator willStartInteractiveScroll]):
+        (-[WKKeyboardScrollingAnimator startRepeatTimerIfNeeded]):
+        (-[WKKeyboardScrollingAnimator stopRepeatTimer]):
+        (-[WKKeyboardScrollingAnimator performDiscreteScroll]):
+        (-[WKKeyboardScrollViewAnimator scrollToContentOffset:animated:]):
+        (-[WKKeyboardScrollViewAnimator scrollWithScrollToExtentAnimationTo:]):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2018-12-03  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Remove "using namespace WebKit" under Source/WebKit/WebProcess/InjectedBundle/API
diff --git a/Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h b/Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h
new file mode 100644 (file)
index 0000000..32dfac0
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(APPLE_INTERNAL_SDK)
+// FIXME (46432011): We shouldn't need to wrap this include in extern "C".
+WTF_EXTERN_C_BEGIN
+#include <AccessibilitySupport.h>
+WTF_EXTERN_C_END
+#endif
+
+WTF_EXTERN_C_BEGIN
+
+extern Boolean _AXSKeyRepeatEnabled();
+extern CFTimeInterval _AXSKeyRepeatDelay();
+extern CFStringRef kAXSWebAccessibilityEventsEnabledNotification;
+extern Boolean _AXSWebAccessibilityEventsEnabled();
+
+WTF_EXTERN_C_END
index acd0fca..7405871 100644 (file)
@@ -196,15 +196,8 @@ static const Seconds delayBeforeNoVisibleContentsRectsLogging = 1_s;
 #endif // PLATFORM(MAC)
 
 #if ENABLE(ACCESSIBILITY_EVENTS)
-#include <wtf/darwin/WeakLinking.h>
-#if __has_include(<AccessibilitySupport.h>)
-#include <AccessibilitySupport.h>
-#else
-extern "C" {
-CFStringRef kAXSWebAccessibilityEventsEnabledNotification;
-Boolean _AXSWebAccessibilityEventsEnabled();
-}
-#endif
+#import "AccessibilitySupportSPI.h"
+#import <wtf/darwin/WeakLinking.h>
 #endif
 
 #if PLATFORM(MAC) && ENABLE(DRAG_SUPPORT)
index 3257190..98547c7 100644 (file)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 
+#import "AccessibilitySupportSPI.h"
 #import "UIKitSPI.h"
 #import <QuartzCore/CADisplayLink.h>
 #import <WebCore/FloatPoint.h>
@@ -107,6 +108,10 @@ struct KeyboardScrollParameters {
     WebCore::FloatPoint _idealPosition;
     WebCore::FloatPoint _currentPosition;
     WebCore::FloatPoint _idealPositionForMinimumTravel;
+
+#if !ENABLE(ANIMATED_KEYBOARD_SCROLLING)
+    RetainPtr<NSTimer> _repeatTimer;
+#endif
 }
 
 - (instancetype)init
@@ -134,7 +139,9 @@ struct KeyboardScrollParameters {
 - (void)invalidate
 {
     [self stopAnimatedScroll];
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
     [self stopDisplayLink];
+#endif
     _scrollable = nil;
 }
 
@@ -152,6 +159,7 @@ static WebCore::FloatSize unitVector(WebKit::ScrollingDirection direction)
     }
 }
 
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
 static WebCore::FloatSize perpendicularAbsoluteUnitVector(WebKit::ScrollingDirection direction)
 {
     switch (direction) {
@@ -163,6 +171,7 @@ static WebCore::FloatSize perpendicularAbsoluteUnitVector(WebKit::ScrollingDirec
         return { 0, 1 };
     }
 }
+#endif
 
 static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
 {
@@ -295,6 +304,7 @@ static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
     _hasPressedScrollingKey = YES;
     _currentScroll = scroll;
 
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
     if (scroll->increment == WebKit::ScrollingIncrement::Document) {
         _velocity = { };
         [self stopAnimatedScroll];
@@ -308,6 +318,10 @@ static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
     _currentPosition = WebCore::FloatPoint([_scrollable contentOffset]);
     _velocity += WebCore::FloatSize([_scrollable interactiveScrollVelocity]);
     _idealPositionForMinimumTravel = _currentPosition + _currentScroll->offset;
+#else
+    [self startRepeatTimerIfNeeded];
+    [self performDiscreteScroll];
+#endif
 
     return YES;
 }
@@ -362,8 +376,25 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     _idealPosition = [_scrollable boundedContentOffset:farthestPointInDirection(_currentPosition + displacement, _idealPositionForMinimumTravel, _currentScroll->direction)];
 
     _currentScroll = std::nullopt;
+
+#if !ENABLE(ANIMATED_KEYBOARD_SCROLLING)
+    [self stopRepeatTimer];
+#endif
 }
 
+- (void)willStartInteractiveScroll
+{
+    // If the user touches the screen to start an interactive scroll, stop everything.
+    _velocity = { };
+    [self stopAnimatedScroll];
+
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
+    [self stopDisplayLink];
+#endif
+}
+
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
+
 - (void)startDisplayLinkIfNeeded
 {
     if (_displayLink)
@@ -379,14 +410,6 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     _displayLink = nil;
 }
 
-- (void)willStartInteractiveScroll
-{
-    // If the user touches the screen to start an interactive scroll, stop everything.
-    _velocity = { };
-    [self stopAnimatedScroll];
-    [self stopDisplayLink];
-}
-
 - (void)displayLinkFired:(CADisplayLink *)sender
 {
     WebCore::FloatSize force;
@@ -442,6 +465,34 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     }
 }
 
+#else
+
+- (void)startRepeatTimerIfNeeded
+{
+    if (_repeatTimer)
+        return;
+
+    if (!_AXSKeyRepeatEnabled())
+        return;
+
+    _repeatTimer = [NSTimer scheduledTimerWithTimeInterval:_AXSKeyRepeatDelay() target:self selector:@selector(performDiscreteScroll) userInfo:nil repeats:YES];
+}
+
+- (void)stopRepeatTimer
+{
+    [_repeatTimer invalidate];
+    _repeatTimer = nil;
+}
+
+- (void)performDiscreteScroll
+{
+    _currentPosition = WebCore::FloatPoint([_scrollable contentOffset]);
+    _idealPositionForMinimumTravel = _currentPosition + _currentScroll->offset;
+    [_scrollable scrollToContentOffset:[_scrollable boundedContentOffset:_idealPositionForMinimumTravel] animated:YES];
+}
+
+#endif
+
 @end
 
 @interface WKKeyboardScrollViewAnimator () <WKKeyboardScrollableInternal>
@@ -553,14 +604,18 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     if (_delegateRespondsToWillScroll)
         [_delegate keyboardScrollViewAnimatorWillScroll:self];
     [scrollView setContentOffset:contentOffsetDelta animated:animated];
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
     [scrollView _flashScrollIndicatorsPersistingPreviousFlashes:YES];
+#endif
 }
 
 - (void)scrollWithScrollToExtentAnimationTo:(CGPoint)offset
 {
     auto scrollView = _scrollView.getAutoreleased();
     [scrollView _setContentOffsetWithDecelerationAnimation:offset];
+#if ENABLE(ANIMATED_KEYBOARD_SCROLLING)
     [scrollView flashScrollIndicators];
+#endif
 }
 
 - (CGPoint)contentOffset
index d797156..627c52b 100644 (file)
                2DABA7761A82B42100EF0F1A /* APIHistoryClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DABA7751A82B42100EF0F1A /* APIHistoryClient.h */; };
                2DACE64E18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DACE64D18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h */; };
                2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */; };
+               2DB7667121B5E48A0045DDB1 /* AccessibilitySupportSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DB7667021B5E48A0045DDB1 /* AccessibilitySupportSPI.h */; };
                2DC18FAD218910490025A88D /* WKDrawingView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC18FAB218910480025A88D /* WKDrawingView.h */; };
                2DC18FB0218912640025A88D /* PencilKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC18FAF218912640025A88D /* PencilKitSPI.h */; };
                2DC18FB3218A6E9E0025A88D /* RemoteLayerTreeViews.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC18FB1218A6E9E0025A88D /* RemoteLayerTreeViews.h */; };
                2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SmartMagnificationController.mm; path = ios/SmartMagnificationController.mm; sourceTree = "<group>"; };
                2DAF06D818BD23BA0081CEB1 /* SmartMagnificationController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = SmartMagnificationController.messages.in; path = ios/SmartMagnificationController.messages.in; sourceTree = "<group>"; };
                2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ViewGestureController.cpp; sourceTree = "<group>"; };
+               2DB7667021B5E48A0045DDB1 /* AccessibilitySupportSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilitySupportSPI.h; sourceTree = "<group>"; };
                2DC18FAB218910480025A88D /* WKDrawingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKDrawingView.h; path = ios/WKDrawingView.h; sourceTree = "<group>"; };
                2DC18FAC218910480025A88D /* WKDrawingView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKDrawingView.mm; path = ios/WKDrawingView.mm; sourceTree = "<group>"; };
                2DC18FAF218912640025A88D /* PencilKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PencilKitSPI.h; sourceTree = "<group>"; };
                CE1A0BCB1A48E6C60054EF74 /* ios */ = {
                        isa = PBXGroup;
                        children = (
+                               2DB7667021B5E48A0045DDB1 /* AccessibilitySupportSPI.h */,
                                CE1A0BCC1A48E6C60054EF74 /* AssertionServicesSPI.h */,
                                CDA041F31ACE2105004A13EC /* BackBoardServicesSPI.h */,
                                07A8F3861E64A8F900B668E8 /* CelestialSPI.h */,
                                A115DC72191D82DA00DA8072 /* _WKWebViewPrintFormatter.h in Headers */,
                                A19DD3C01D07D16800AC823B /* _WKWebViewPrintFormatterInternal.h in Headers */,
                                A182D5B51BE6BD250087A7CC /* AccessibilityIOS.h in Headers */,
+                               2DB7667121B5E48A0045DDB1 /* AccessibilitySupportSPI.h in Headers */,
                                A7D792D81767CCA300881CBE /* ActivityAssertion.h in Headers */,
                                634842511FB26E7100946E3C /* APIApplicationManifest.h in Headers */,
                                BC64697011DBE603006455B0 /* APIArray.h in Headers */,