[Extra zoom mode] Support resigning first responder status when focusing a form control
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 23:07:30 +0000 (23:07 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 23:07:30 +0000 (23:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183477
<rdar://problem/38225994>

Reviewed by Tim Horton.

Currently, when presenting an input view controller in extra zoom mode, if the web view loses first responder
status, we will blur the focused element, which dismisses all focused form control UI. For certain types of form
controls, this prevents the user from using key pieces of functionality.

To address this, disconnect the notion of first responder status from DOM element focus while the form control
overlay is shown. Later, when the active input session ends, if the web content view was first responder before
upon focusing the element, restore first responder status on the web view. This extra tweak is needed to ensure
that certain UI affordances which require first responder status on the web view continue to work after
interacting with a form control that changes the first responder.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView presentFocusedFormControlViewController:]):
(-[WKContentView dismissFocusedFormControlViewController:]):

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

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

index 2471763..3cfccab 100644 (file)
@@ -1,3 +1,26 @@
+2018-03-08  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Support resigning first responder status when focusing a form control
+        https://bugs.webkit.org/show_bug.cgi?id=183477
+        <rdar://problem/38225994>
+
+        Reviewed by Tim Horton.
+
+        Currently, when presenting an input view controller in extra zoom mode, if the web view loses first responder
+        status, we will blur the focused element, which dismisses all focused form control UI. For certain types of form
+        controls, this prevents the user from using key pieces of functionality.
+
+        To address this, disconnect the notion of first responder status from DOM element focus while the form control
+        overlay is shown. Later, when the active input session ends, if the web content view was first responder before
+        upon focusing the element, restore first responder status on the web view. This extra tweak is needed to ensure
+        that certain UI affordances which require first responder status on the web view continue to work after
+        interacting with a form control that changes the first responder.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView presentFocusedFormControlViewController:]):
+        (-[WKContentView dismissFocusedFormControlViewController:]):
+
 2018-03-08  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Revert defaults read of zero values
index a7910e7..10834d8 100644 (file)
@@ -255,6 +255,8 @@ struct WKAutoCorrectionData {
     RetainPtr<WKNumberPadViewController> _numberPadViewController;
     RetainPtr<WKSelectMenuViewController> _selectMenuViewController;
     RetainPtr<WKTimePickerViewController> _timePickerViewController;
+
+    BOOL _shouldRestoreFirstResponderStatusAfterLosingFocus;
 #endif
 }
 
index 6d6f89a..4091944 100644 (file)
@@ -4205,6 +4205,9 @@ static bool isAssistableInputType(InputType type)
     if (_focusedFormControlViewController)
         return;
 
+    ++_webView->_activeFocusedStateRetainCount;
+    _shouldRestoreFirstResponderStatusAfterLosingFocus = self.isFirstResponder;
+
     _focusedFormControlViewController = adoptNS([[WKFocusedFormControlViewController alloc] init]);
     [_focusedFormControlViewController setDelegate:self];
     [[UIViewController _viewControllerForFullScreenPresentationFromView:self] presentViewController:_focusedFormControlViewController.get() animated:animated completion:nil];
@@ -4225,6 +4228,13 @@ static bool isAssistableInputType(InputType type)
     if (!_focusedFormControlViewController)
         return;
 
+    --_webView->_activeFocusedStateRetainCount;
+
+    if (_shouldRestoreFirstResponderStatusAfterLosingFocus && !self.isFirstResponder) {
+        _shouldRestoreFirstResponderStatusAfterLosingFocus = NO;
+        [self becomeFirstResponder];
+    }
+
     [_focusedFormControlViewController dismissViewControllerAnimated:animated completion:nil];
     _focusedFormControlViewController = nil;
     [self setInputDelegate:nil];