iOS: Using ⌥ to scroll horizontally is no different than arrow key
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Mar 2019 02:54:55 +0000 (02:54 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Mar 2019 02:54:55 +0000 (02:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195268
<rdar://problem/48326682>

Reviewed by Brent Fulgham.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView keyboardScrollViewAnimator:distanceForIncrement:inDirection:]):
(-[WKContentView keyboardScrollViewAnimator:distanceForIncrement:]): Deleted.
* UIProcess/ios/WKKeyboardScrollingAnimator.h:
* UIProcess/ios/WKKeyboardScrollingAnimator.mm:
(-[WKKeyboardScrollingAnimator keyboardScrollForEvent:]):
(-[WKKeyboardScrollViewAnimator setDelegate:]):
(-[WKKeyboardScrollViewAnimator distanceForIncrement:inDirection:]):
(-[WKKeyboardScrollViewAnimator distanceForIncrement:]): Deleted.
Add a direction parameter to -distanceForIncrement:, so the client
can return a different page/document size based on the scrolling axis.
Adopt it both in the default implementation and in WKContentViewInteraction.
Make the option key scroll by page when scrolling horizontally, like it
does when scrolling vertically.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.h
Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm

index c9baf3e..a09154b 100644 (file)
@@ -1,3 +1,26 @@
+2019-03-10  Tim Horton  <timothy_horton@apple.com>
+
+        iOS: Using ⌥ to scroll horizontally is no different than arrow key
+        https://bugs.webkit.org/show_bug.cgi?id=195268
+        <rdar://problem/48326682>
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView keyboardScrollViewAnimator:distanceForIncrement:inDirection:]):
+        (-[WKContentView keyboardScrollViewAnimator:distanceForIncrement:]): Deleted.
+        * UIProcess/ios/WKKeyboardScrollingAnimator.h:
+        * UIProcess/ios/WKKeyboardScrollingAnimator.mm:
+        (-[WKKeyboardScrollingAnimator keyboardScrollForEvent:]):
+        (-[WKKeyboardScrollViewAnimator setDelegate:]):
+        (-[WKKeyboardScrollViewAnimator distanceForIncrement:inDirection:]):
+        (-[WKKeyboardScrollViewAnimator distanceForIncrement:]): Deleted.
+        Add a direction parameter to -distanceForIncrement:, so the client
+        can return a different page/document size based on the scrolling axis.
+        Adopt it both in the default implementation and in WKContentViewInteraction.
+        Make the option key scroll by page when scrolling horizontally, like it
+        does when scrolling vertically.
+
 2019-03-10  David Quesada  <david_quesada@apple.com>
 
         ASSERT(m_downloads.isEmpty()) fails in DownloadProxyMap::~DownloadProxyMap()
index 867cc8a..134d24b 100644 (file)
@@ -4432,13 +4432,19 @@ static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
     return YES;
 }
 
-- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment
+- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction
 {
+    BOOL directionIsHorizontal = direction == WebKit::ScrollingDirection::Left || direction == WebKit::ScrollingDirection::Right;
+
     switch (increment) {
-    case WebKit::ScrollingIncrement::Document:
-        return [self convertRect:self.bounds toView:_webView].size.height;
-    case WebKit::ScrollingIncrement::Page:
-        return [self convertSize:CGSizeMake(0, WebCore::Scrollbar::pageStep(_page->unobscuredContentRect().height(), self.bounds.size.height)) toView:_webView].height;
+    case WebKit::ScrollingIncrement::Document: {
+        CGSize documentSize = [self convertRect:self.bounds toView:_webView].size;
+        return directionIsHorizontal ? documentSize.width : documentSize.height;
+    }
+    case WebKit::ScrollingIncrement::Page: {
+        CGSize pageSize = [self convertSize:CGSizeMake(0, WebCore::Scrollbar::pageStep(_page->unobscuredContentRect().height(), self.bounds.size.height)) toView:_webView];
+        return directionIsHorizontal ? pageSize.width : pageSize.height;
+    }
     case WebKit::ScrollingIncrement::Line:
         return [self convertSize:CGSizeMake(0, WebCore::Scrollbar::pixelsPerLineStep()) toView:_webView].height;
     }
index 6ba6cad..c7b3041 100644 (file)
@@ -37,6 +37,13 @@ enum class ScrollingIncrement : uint8_t {
     Line
 };
 
+enum class ScrollingDirection : uint8_t {
+    Up,
+    Down,
+    Left,
+    Right
+};
+
 }
 
 @class UIScrollView;
@@ -62,7 +69,7 @@ enum class ScrollingIncrement : uint8_t {
 @protocol WKKeyboardScrollViewAnimatorDelegate <NSObject>
 @optional
 - (BOOL)isScrollableForKeyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator;
-- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment;
+- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction;
 - (void)keyboardScrollViewAnimatorWillScroll:(WKKeyboardScrollViewAnimator *)animator;
 - (void)keyboardScrollViewAnimatorDidFinishScrolling:(WKKeyboardScrollViewAnimator *)animator;
 
index e30fa8b..d87e65d 100644 (file)
@@ -42,8 +42,6 @@
 
 namespace WebKit {
 
-enum class ScrollingDirection : uint8_t { Up, Down, Left, Right };
-
 struct KeyboardScroll {
     WebCore::FloatSize offset; // Points per increment.
     WebCore::FloatSize maximumVelocity; // Points per second.
@@ -69,7 +67,7 @@ struct KeyboardScrollParameters {
 @protocol WKKeyboardScrollableInternal <NSObject>
 @required
 - (BOOL)isKeyboardScrollable;
-- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment;
+- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction;
 - (void)scrollToContentOffset:(WebCore::FloatPoint)offset animated:(BOOL)animated;
 - (void)scrollWithScrollToExtentAnimationTo:(CGPoint)offset;
 - (CGPoint)contentOffset;
@@ -233,6 +231,8 @@ static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
         switch (key) {
         case Key::LeftArrow:
         case Key::RightArrow:
+            if (altPressed)
+                return WebKit::ScrollingIncrement::Page;
             return WebKit::ScrollingIncrement::Line;
         case Key::UpArrow:
         case Key::DownArrow:
@@ -271,7 +271,7 @@ static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
         };
     }();
 
-    CGFloat scrollDistance = [_scrollable distanceForIncrement:increment];
+    CGFloat scrollDistance = [_scrollable distanceForIncrement:increment inDirection:direction];
 
     WebKit::KeyboardScroll scroll;
     scroll.offset = unitVector(direction).scaled(scrollDistance);
@@ -544,7 +544,7 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     _delegate = delegate;
 
     _delegateRespondsToIsKeyboardScrollable = [_delegate respondsToSelector:@selector(isScrollableForKeyboardScrollViewAnimator:)];
-    _delegateRespondsToDistanceForIncrement = [_delegate respondsToSelector:@selector(keyboardScrollViewAnimator:distanceForIncrement:)];
+    _delegateRespondsToDistanceForIncrement = [_delegate respondsToSelector:@selector(keyboardScrollViewAnimator:distanceForIncrement:inDirection:)];
     _delegateRespondsToWillScroll = [_delegate respondsToSelector:@selector(keyboardScrollViewAnimatorWillScroll:)];
     _delegateRespondsToDidFinishScrolling = [_delegate respondsToSelector:@selector(keyboardScrollViewAnimatorDidFinishScrolling:)];
 }
@@ -571,7 +571,7 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     return [_delegate isScrollableForKeyboardScrollViewAnimator:self];
 }
 
-- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment
+- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction
 {
     auto scrollView = _scrollView.getAutoreleased();
     if (!scrollView)
@@ -580,12 +580,14 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
     const CGFloat defaultPageScrollFraction = 0.8;
     const CGFloat defaultLineScrollHeight = 40;
 
+    BOOL directionIsHorizontal = direction == WebKit::ScrollingDirection::Left || direction == WebKit::ScrollingDirection::Right;
+
     if (!_delegateRespondsToDistanceForIncrement) {
         switch (increment) {
         case WebKit::ScrollingIncrement::Document:
-            return scrollView.contentSize.height;
+            return directionIsHorizontal ? scrollView.contentSize.width : scrollView.contentSize.height;
         case WebKit::ScrollingIncrement::Page:
-            return scrollView.frame.size.height * defaultPageScrollFraction;
+            return (directionIsHorizontal ? scrollView.frame.size.width : scrollView.frame.size.height) * defaultPageScrollFraction;
         case WebKit::ScrollingIncrement::Line:
             return defaultLineScrollHeight * scrollView.zoomScale;
         }
@@ -593,7 +595,7 @@ static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCo
         return 0;
     }
 
-    return [_delegate keyboardScrollViewAnimator:self distanceForIncrement:increment];
+    return [_delegate keyboardScrollViewAnimator:self distanceForIncrement:increment inDirection:direction];
 }
 
 - (void)scrollToContentOffset:(WebCore::FloatPoint)contentOffsetDelta animated:(BOOL)animated