[Extra zoom mode] Refactor input view controller presentation and dismissal helpers
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2018 21:00:30 +0000 (21:00 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2018 21:00:30 +0000 (21:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184020
Work towards <rdar://problem/38758727>

Reviewed by Tim Horton.

We currently have separate presentation and dismissal helpers for each type of view controller corresponding to
a focused element type. This is excessive, considering that all of these helpers are only invoked from one place
(either -presentViewControllerForCurrentAssistedNode or -dismissAllInputViewControllers), with the exception of
the focused form control overlay.

This refactoring allows us to then adjust the timing of first responder restoration logic, such that the focused
form control view controller can receive forwarded events from the web view. See below for more detail.

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

Remove logic to restore the web view as first responder.

(-[WKContentView presentViewControllerForCurrentAssistedNode]):
(-[WKContentView dismissAllInputViewControllers]):

Restore first responder after dismissing a view controller that was presented when focusing a form control, only
if the web view was first responder before presentation.

(-[WKContentView presentDatePickerViewController:]): Deleted.
(-[WKContentView dismissDatePickerViewController:]): Deleted.
(-[WKContentView presentTimePickerViewController:]): Deleted.
(-[WKContentView dismissTimePickerViewController:]): Deleted.
(-[WKContentView presentSelectMenuViewController:]): Deleted.
(-[WKContentView dismissSelectMenuViewController:]): Deleted.
(-[WKContentView dismissNumberPadViewController:]): Deleted.
(-[WKContentView presentNumberPadViewController:]): Deleted.
(-[WKContentView presentTextInputViewController:]): Deleted.
(-[WKContentView dismissTextInputViewController:]): Deleted.

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

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

index 2911a217ecfe5280fbb2af7f4c794a3540cc3fb6..9706d240c17742e55761425e77952c61115a457e 100644 (file)
@@ -1,3 +1,42 @@
+2018-03-26  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Refactor input view controller presentation and dismissal helpers
+        https://bugs.webkit.org/show_bug.cgi?id=184020
+        Work towards <rdar://problem/38758727>
+
+        Reviewed by Tim Horton.
+
+        We currently have separate presentation and dismissal helpers for each type of view controller corresponding to
+        a focused element type. This is excessive, considering that all of these helpers are only invoked from one place
+        (either -presentViewControllerForCurrentAssistedNode or -dismissAllInputViewControllers), with the exception of
+        the focused form control overlay.
+
+        This refactoring allows us to then adjust the timing of first responder restoration logic, such that the focused
+        form control view controller can receive forwarded events from the web view. See below for more detail.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView presentFocusedFormControlViewController:]):
+        (-[WKContentView dismissFocusedFormControlViewController:]):
+
+        Remove logic to restore the web view as first responder.
+
+        (-[WKContentView presentViewControllerForCurrentAssistedNode]):
+        (-[WKContentView dismissAllInputViewControllers]):
+
+        Restore first responder after dismissing a view controller that was presented when focusing a form control, only
+        if the web view was first responder before presentation.
+
+        (-[WKContentView presentDatePickerViewController:]): Deleted.
+        (-[WKContentView dismissDatePickerViewController:]): Deleted.
+        (-[WKContentView presentTimePickerViewController:]): Deleted.
+        (-[WKContentView dismissTimePickerViewController:]): Deleted.
+        (-[WKContentView presentSelectMenuViewController:]): Deleted.
+        (-[WKContentView dismissSelectMenuViewController:]): Deleted.
+        (-[WKContentView dismissNumberPadViewController:]): Deleted.
+        (-[WKContentView presentNumberPadViewController:]): Deleted.
+        (-[WKContentView presentTextInputViewController:]): Deleted.
+        (-[WKContentView dismissTextInputViewController:]): Deleted.
+
 2018-03-06  Brian Burg  <bburg@apple.com>
 
         Web Automation: provide a way to ask clients for a new tab or window
 2018-03-06  Brian Burg  <bburg@apple.com>
 
         Web Automation: provide a way to ask clients for a new tab or window
index ff34931ce73634d8729b641b8cc6bc14729c29de..504d6ce34a3101b1c85f4ed50619eee57f08b48c 100644 (file)
@@ -4182,78 +4182,12 @@ static bool isAssistableInputType(InputType type)
 
 #if ENABLE(EXTRA_ZOOM_MODE)
 
 
 #if ENABLE(EXTRA_ZOOM_MODE)
 
-- (void)dismissAllInputViewControllers
-{
-    [self dismissTextInputViewController:YES];
-    [self dismissNumberPadViewController:YES];
-    [self dismissSelectMenuViewController:YES];
-    [self dismissTimePickerViewController:YES];
-    [self dismissDatePickerViewController:YES];
-}
-
-- (void)presentDatePickerViewController:(BOOL)animated
-{
-    if (_datePickerViewController)
-        return;
-
-    _datePickerViewController = adoptNS([[WKDatePickerViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
-    [_datePickerViewController setDelegate:self];
-    [_focusedFormControlViewController presentViewController:_datePickerViewController.get() animated:animated completion:nil];
-}
-
-- (void)dismissDatePickerViewController:(BOOL)animated
-{
-    if (!_datePickerViewController)
-        return;
-
-    auto datePickerViewController = WTFMove(_datePickerViewController);
-    [datePickerViewController dismissViewControllerAnimated:animated completion:nil];
-}
-
-- (void)presentTimePickerViewController:(BOOL)animated
-{
-    if (_timePickerViewController)
-        return;
-
-    _timePickerViewController = adoptNS([[WKTimePickerViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
-    [_timePickerViewController setDelegate:self];
-    [_focusedFormControlViewController presentViewController:_timePickerViewController.get() animated:animated completion:nil];
-}
-
-- (void)dismissTimePickerViewController:(BOOL)animated
-{
-    if (!_timePickerViewController)
-        return;
-
-    auto timePickerViewController = WTFMove(_timePickerViewController);
-    [timePickerViewController dismissViewControllerAnimated:animated completion:nil];
-}
-
-- (void)presentSelectMenuViewController:(BOOL)animated
-{
-    if (_selectMenuListViewController)
-        return;
-
-    _selectMenuListViewController = adoptNS([[WKSelectMenuListViewController alloc] initWithDelegate:self]);
-    [_focusedFormControlViewController presentViewController:_selectMenuListViewController.get() animated:animated completion:nil];
-}
-
-- (void)dismissSelectMenuViewController:(BOOL)animated
-{
-    if (!_selectMenuListViewController)
-        return;
-
-    auto selectMenuListViewController = WTFMove(_selectMenuListViewController);
-    [_selectMenuListViewController dismissViewControllerAnimated:animated completion:nil];
-}
-
 - (void)presentFocusedFormControlViewController:(BOOL)animated
 {
     if (_focusedFormControlViewController)
         return;
 
     ++_webView->_activeFocusedStateRetainCount;
 - (void)presentFocusedFormControlViewController:(BOOL)animated
 {
     if (_focusedFormControlViewController)
         return;
 
     ++_webView->_activeFocusedStateRetainCount;
-    _shouldRestoreFirstResponderStatusAfterLosingFocus = self.isFirstResponder;
 
     _focusedFormControlViewController = adoptNS([[WKFocusedFormControlViewController alloc] init]);
     [_focusedFormControlViewController setDelegate:self];
 
     _focusedFormControlViewController = adoptNS([[WKFocusedFormControlViewController alloc] init]);
     [_focusedFormControlViewController setDelegate:self];
@@ -4261,15 +4195,6 @@ static bool isAssistableInputType(InputType type)
     [self setInputDelegate:_focusedFormControlViewController.get()];
 }
 
     [self setInputDelegate:_focusedFormControlViewController.get()];
 }
 
-- (void)dismissNumberPadViewController:(BOOL)animated
-{
-    if (!_numberPadViewController)
-        return;
-
-    auto numberPadViewController = WTFMove(_numberPadViewController);
-    [numberPadViewController dismissViewControllerAnimated:animated completion:nil];
-}
-
 - (void)dismissFocusedFormControlViewController:(BOOL)animated
 {
     if (!_focusedFormControlViewController)
 - (void)dismissFocusedFormControlViewController:(BOOL)animated
 {
     if (!_focusedFormControlViewController)
@@ -4277,69 +4202,81 @@ static bool isAssistableInputType(InputType type)
 
     --_webView->_activeFocusedStateRetainCount;
 
 
     --_webView->_activeFocusedStateRetainCount;
 
-    if (_shouldRestoreFirstResponderStatusAfterLosingFocus && !self.isFirstResponder) {
-        _shouldRestoreFirstResponderStatusAfterLosingFocus = NO;
-        [self becomeFirstResponder];
-    }
-
     [_focusedFormControlViewController dismissViewControllerAnimated:animated completion:nil];
     _focusedFormControlViewController = nil;
     [self setInputDelegate:nil];
 }
 
     [_focusedFormControlViewController dismissViewControllerAnimated:animated completion:nil];
     _focusedFormControlViewController = nil;
     [self setInputDelegate:nil];
 }
 
-- (void)presentNumberPadViewController:(BOOL)animated
-{
-    if (_numberPadViewController)
-        return;
-
-    _numberPadViewController = adoptNS([[WKNumberPadViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[]]);
-    [_numberPadViewController setDelegate:self];
-    [_focusedFormControlViewController presentViewController:_numberPadViewController.get() animated:animated completion:nil];
-}
-
 - (void)presentViewControllerForCurrentAssistedNode
 {
     [self dismissAllInputViewControllers];
 
 - (void)presentViewControllerForCurrentAssistedNode
 {
     [self dismissAllInputViewControllers];
 
+    _shouldRestoreFirstResponderStatusAfterLosingFocus = self.isFirstResponder;
+
     switch (_assistedNodeInformation.elementType) {
     case InputType::Number:
     case InputType::NumberPad:
     case InputType::Phone:
     switch (_assistedNodeInformation.elementType) {
     case InputType::Number:
     case InputType::NumberPad:
     case InputType::Phone:
-        [self presentNumberPadViewController:YES];
+        if (!_numberPadViewController) {
+            _numberPadViewController = adoptNS([[WKNumberPadViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[]]);
+            [_numberPadViewController setDelegate:self];
+            [_focusedFormControlViewController presentViewController:_numberPadViewController.get() animated:YES completion:nil];
+        }
         break;
     case InputType::Select:
         break;
     case InputType::Select:
-        [self presentSelectMenuViewController:YES];
+        if (!_selectMenuListViewController) {
+            _selectMenuListViewController = adoptNS([[WKSelectMenuListViewController alloc] initWithDelegate:self]);
+            [_focusedFormControlViewController presentViewController:_selectMenuListViewController.get() animated:YES completion:nil];
+        }
         break;
     case InputType::Time:
         break;
     case InputType::Time:
-        [self presentTimePickerViewController:YES];
+        if (!_timePickerViewController) {
+            _timePickerViewController = adoptNS([[WKTimePickerViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
+            [_timePickerViewController setDelegate:self];
+            [_focusedFormControlViewController presentViewController:_timePickerViewController.get() animated:YES completion:nil];
+        }
         break;
     case InputType::Date:
         break;
     case InputType::Date:
-        [self presentDatePickerViewController:YES];
+        if (!_datePickerViewController) {
+            _datePickerViewController = adoptNS([[WKDatePickerViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
+            [_datePickerViewController setDelegate:self];
+            [_focusedFormControlViewController presentViewController:_datePickerViewController.get() animated:YES completion:nil];
+        }
         break;
     case InputType::None:
         break;
     case InputType::None:
+        ASSERT_NOT_REACHED();
         break;
     default:
         break;
     default:
-        [self presentTextInputViewController:YES];
+        if (!_textInputListViewController) {
+            _textInputListViewController = adoptNS([[WKTextInputListViewController alloc] initWithDelegate:self]);
+            [_focusedFormControlViewController presentViewController:_textInputListViewController.get() animated:YES completion:nil];
+        }
         break;
     }
 }
 
         break;
     }
 }
 
-- (void)presentTextInputViewController:(BOOL)animated
+- (void)dismissAllInputViewControllers
 {
 {
-    if (_textInputListViewController)
-        return;
+    if (auto controller = WTFMove(_textInputListViewController))
+        [controller dismissViewControllerAnimated:YES completion:nil];
 
 
-    _textInputListViewController = adoptNS([[WKTextInputListViewController alloc] initWithDelegate:self]);
-    [_focusedFormControlViewController presentViewController:_textInputListViewController.get() animated:animated completion:nil];
-}
+    if (auto controller = WTFMove(_numberPadViewController))
+        [controller dismissViewControllerAnimated:YES completion:nil];
 
 
-- (void)dismissTextInputViewController:(BOOL)animated
-{
-    if (!_textInputListViewController)
-        return;
+    if (auto controller = WTFMove(_selectMenuListViewController))
+        [controller dismissViewControllerAnimated:YES completion:nil];
 
 
-    auto textInputListViewController = WTFMove(_textInputListViewController);
-    [textInputListViewController dismissViewControllerAnimated:animated completion:nil];
+    if (auto controller = WTFMove(_timePickerViewController))
+        [controller dismissViewControllerAnimated:YES completion:nil];
+
+    if (auto controller = WTFMove(_datePickerViewController))
+        [controller dismissViewControllerAnimated:YES completion:nil];
+
+    if (_shouldRestoreFirstResponderStatusAfterLosingFocus) {
+        _shouldRestoreFirstResponderStatusAfterLosingFocus = NO;
+        if (!self.isFirstResponder)
+            [self becomeFirstResponder];
+    }
 }
 
 - (void)textInputController:(WKTextFormControlViewController *)controller didCommitText:(NSString *)text
 }
 
 - (void)textInputController:(WKTextFormControlViewController *)controller didCommitText:(NSString *)text