[iOS][WK2] Distant focusable element may not be scrolled into view when focused using...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jun 2014 04:31:25 +0000 (04:31 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jun 2014 04:31:25 +0000 (04:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134309
<rdar://problem/17427385>

Reviewed by Darin Adler.

.:
Add a manual test to ensure that we scroll to a distant focused text field when it's focused
using the keyboard.

* ManualTests/ios/scroll-to-distant-keyboard-focused-text-field.html: Added.

Source/WebKit2:
Fixes an issue where the focusable element may not be scrolled into view when it's focused by
using the keyboard accessory (i.e. the < and > buttons). In particular, we don't scroll a
keyboard focused text field into view when it's positioned significantly outside the visible region.

* UIProcess/ios/WKContentViewInteraction.h: Added an instance variable called _didAccessoryTabInitiateFocus
to track whether an accessory tab initiated the focus of the focusable element.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanupInteraction]): Clear _didAccessoryTabInitiateFocus so that we're in a good state
should the WebProcess crash between the time the UIProcess receives the accessory tab request and the
WebProcess calls back to the UIProcess to zoom/scroll to the newly focused element.
(-[WKContentView _displayFormNodeInputView]): Modified to pass an empty rectangle for the selection
rectangle to -_zoomToFocusRect to avoid constraining the scroll to the newly focused element when it
was focused using the keyboard accessory tab buttons
(-[WKContentView accessoryTab:]): Modified to set _didAccessoryTabInitiateFocus to YES. We'll set
this boolean to NO in -_displayFormNodeInputView.

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

ChangeLog
ManualTests/ios/scroll-to-distant-keyboard-focused-text-field.html [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index 9a53398..a103146 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2014-06-26  Daniel Bates  <dabates@apple.com>
+
+        [iOS][WK2] Distant focusable element may not be scrolled into view when focused using keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=134309
+        <rdar://problem/17427385>
+
+        Reviewed by Darin Adler.
+
+        Add a manual test to ensure that we scroll to a distant focused text field when it's focused
+        using the keyboard.
+
+        * ManualTests/ios/scroll-to-distant-keyboard-focused-text-field.html: Added.
+
 2014-06-25  Laszlo Gombos  <l.gombos@samsung.com>
 
         Remove build guard for progress element
diff --git a/ManualTests/ios/scroll-to-distant-keyboard-focused-text-field.html b/ManualTests/ios/scroll-to-distant-keyboard-focused-text-field.html
new file mode 100644 (file)
index 0000000..ea5c802
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name="viewport" content="height=device-height">
+<style>
+#input1 {
+    position: absolute;
+    top: 880px;
+    left: 200px;
+}
+
+body {
+    height: 900px;
+}
+</style>
+</head>
+<body>
+<p>This test can be used to ensure that we scroll to the newly focused field when using the keyboard to switch focus from a text field positioned at the bottom of the page to a text field positioned at the top of the page.</p>
+<ol>
+    <li>Scroll all the way to the bottom of the page.</li>
+    <li>Tap the text field with text &quot;Field 2&quot;</li>
+    <li>Tap the '&lt;' above the keyboard to move the focus to the previous text field on the page, &quot;Field 1&quot;.</li>
+</ol>
+<p>This test PASSED if we scroll to &quot;Field 1&quot; such that it's visible.</p>
+<input type="text" id="input0" value="Field 1">
+<input type="text" id="input1" value="Field 2">
+</body>
+</html>
index 46b0f93..e5621de 100644 (file)
@@ -1,3 +1,27 @@
+2014-06-26  Daniel Bates  <dabates@apple.com>
+
+        [iOS][WK2] Distant focusable element may not be scrolled into view when focused using keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=134309
+        <rdar://problem/17427385>
+
+        Reviewed by Darin Adler.
+
+        Fixes an issue where the focusable element may not be scrolled into view when it's focused by
+        using the keyboard accessory (i.e. the < and > buttons). In particular, we don't scroll a
+        keyboard focused text field into view when it's positioned significantly outside the visible region.
+
+        * UIProcess/ios/WKContentViewInteraction.h: Added an instance variable called _didAccessoryTabInitiateFocus
+        to track whether an accessory tab initiated the focus of the focusable element.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView cleanupInteraction]): Clear _didAccessoryTabInitiateFocus so that we're in a good state
+        should the WebProcess crash between the time the UIProcess receives the accessory tab request and the
+        WebProcess calls back to the UIProcess to zoom/scroll to the newly focused element.
+        (-[WKContentView _displayFormNodeInputView]): Modified to pass an empty rectangle for the selection
+        rectangle to -_zoomToFocusRect to avoid constraining the scroll to the newly focused element when it
+        was focused using the keyboard accessory tab buttons
+        (-[WKContentView accessoryTab:]): Modified to set _didAccessoryTabInitiateFocus to YES. We'll set
+        this boolean to NO in -_displayFormNodeInputView.
+
 2014-06-26  Timothy Horton  <timothy_horton@apple.com>
 
         [iOS][WK2] Implement WKPDFView smart magnification
index 883010b..bd55365 100644 (file)
@@ -139,6 +139,7 @@ struct WKAutoCorrectionData {
     BOOL _selectionNeedsUpdate;
     BOOL _usingGestureForSelection;
     BOOL _inspectorNodeSearchEnabled;
+    BOOL _didAccessoryTabInitiateFocus;
 }
 
 @end
index a663d20..36b9544 100644 (file)
@@ -263,6 +263,7 @@ static UIWebSelectionMode toUIWebSelectionMode(WKSelectionGranularity granularit
     _textSelectionAssistant = nil;
     _actionSheetAssistant = nil;
     _smartMagnificationController = nil;
+    _didAccessoryTabInitiateFocus = NO;
     [_formInputSession invalidate];
     _formInputSession = nil;
     [_highlightView removeFromSuperview];
@@ -638,12 +639,13 @@ static inline bool highlightedQuadsAreSmallerThanRect(const Vector<FloatQuad>& q
 - (void)_displayFormNodeInputView
 {
     [self _zoomToFocusRect:_assistedNodeInformation.elementRect
-             selectionRect:_assistedNodeInformation.selectionRect
+             selectionRect: _didAccessoryTabInitiateFocus ? IntRect() : _assistedNodeInformation.selectionRect
                   fontSize:_assistedNodeInformation.nodeFontSize
               minimumScale:_assistedNodeInformation.minimumScaleFactor
               maximumScale:_assistedNodeInformation.maximumScaleFactor
               allowScaling:(_assistedNodeInformation.allowsUserScaling && !UICurrentUserInterfaceIdiomIsPad())
                forceScroll:[self requiresAccessoryView]];
+    _didAccessoryTabInitiateFocus = NO;
     [self _updateAccessory];
 }
 
@@ -1729,6 +1731,7 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
 
 - (void)accessoryTab:(BOOL)isNext
 {
+    _didAccessoryTabInitiateFocus = YES; // Will be cleared in either -_displayFormNodeInputView or -cleanupInteraction.
     _page->focusNextAssistedNode(isNext);
 }