Make it possible to set suggestions in extra zoom mode.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Feb 2018 20:14:01 +0000 (20:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Feb 2018 20:14:01 +0000 (20:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183154
<rdar://problem/35227450>

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2018-02-27
Reviewed by Tim Horton.

In extra zoom mode, when presenting WKFocusedFormControlViewController, make it the inputDelegate for
WKContentView. This is needed to ensure we can capture/cache the suggestions when _WKInputSession's
suggestions is updated. Later, when we present WKTextInputViewController, we can pass the cached
suggestions.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView presentFocusedFormControlViewController:]): Set _focusedFormControlViewController as
    the inputDelegate for WKContentView.
(-[WKContentView dismissFocusedFormControlViewController:]): Null the inputDelegate on dismissal.
(-[WKContentView presentTextInputViewController:]): Pass the suggestions from WKFocusedFormControlViewController to
    WKTextInputViewController when the latter is presented.
(-[WKContentView textInputController:didCommitText:]): Call the new delegate method textInputController:didCommitText:withSuggestion:.
(-[WKContentView textInputController:didCommitText:withSuggestion:]): When a suggestions is selected, insert the
    suggestion which will notify the client.
(-[WKContentView focusedFormControllerDidUpdateSuggestions:]): Called when the suggestion is updated after the input
    view controller is presented.

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

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

index a2680a2..4bd71e8 100644 (file)
@@ -1,3 +1,28 @@
+2018-02-27  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Make it possible to set suggestions in extra zoom mode.
+        https://bugs.webkit.org/show_bug.cgi?id=183154
+        <rdar://problem/35227450>
+
+        Reviewed by Tim Horton.
+
+        In extra zoom mode, when presenting WKFocusedFormControlViewController, make it the inputDelegate for
+        WKContentView. This is needed to ensure we can capture/cache the suggestions when _WKInputSession's
+        suggestions is updated. Later, when we present WKTextInputViewController, we can pass the cached
+        suggestions.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView presentFocusedFormControlViewController:]): Set _focusedFormControlViewController as
+            the inputDelegate for WKContentView.
+        (-[WKContentView dismissFocusedFormControlViewController:]): Null the inputDelegate on dismissal.
+        (-[WKContentView presentTextInputViewController:]): Pass the suggestions from WKFocusedFormControlViewController to
+            WKTextInputViewController when the latter is presented.
+        (-[WKContentView textInputController:didCommitText:]): Call the new delegate method textInputController:didCommitText:withSuggestion:.
+        (-[WKContentView textInputController:didCommitText:withSuggestion:]): When a suggestions is selected, insert the
+            suggestion which will notify the client.
+        (-[WKContentView focusedFormControllerDidUpdateSuggestions:]): Called when the suggestion is updated after the input
+            view controller is presented.
+
 2018-02-27  Tim Horton  <timothy_horton@apple.com>
 
         Stop using deprecated CADisplay SPI
index c58041a..0d4d585 100644 (file)
@@ -4208,6 +4208,7 @@ static bool isAssistableInputType(InputType type)
     _focusedFormControlViewController = adoptNS([[WKFocusedFormControlViewController alloc] init]);
     [_focusedFormControlViewController setDelegate:self];
     [[UIViewController _viewControllerForFullScreenPresentationFromView:self] presentViewController:_focusedFormControlViewController.get() animated:animated completion:nil];
+    [self setInputDelegate:_focusedFormControlViewController.get()];
 }
 
 - (void)dismissNumberPadViewController:(BOOL)animated
@@ -4226,6 +4227,7 @@ static bool isAssistableInputType(InputType type)
 
     [_focusedFormControlViewController dismissViewControllerAnimated:animated completion:nil];
     _focusedFormControlViewController = nil;
+    [self setInputDelegate:nil];
 }
 
 - (void)presentNumberPadViewController:(BOOL)animated
@@ -4273,6 +4275,8 @@ static bool isAssistableInputType(InputType type)
     _textInputViewController = adoptNS([[WKTextInputViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
     [_textInputViewController setDelegate:self];
     [_focusedFormControlViewController presentViewController:_textInputViewController.get() animated:animated completion:nil];
+
+    [_textInputViewController setSuggestions:[_focusedFormControlViewController suggestions]];
 }
 
 - (void)dismissTextInputViewController:(BOOL)animated
@@ -4286,7 +4290,15 @@ static bool isAssistableInputType(InputType type)
 
 - (void)textInputController:(WKTextFormControlViewController *)controller didCommitText:(NSString *)text
 {
-    _page->setTextAsync(text);
+    [self textInputController:controller didCommitText:text withSuggestion:nil];
+}
+
+- (void)textInputController:(WKTextFormControlViewController *)controller didCommitText:(NSString *)text withSuggestion:(UITextSuggestion *)suggestion
+{
+    if (suggestion)
+        [self insertTextSuggestion:suggestion];
+    else
+        _page->setTextAsync(text);
 
     if (![self actionNameForFocusedFormControlController:_focusedFormControlViewController.get()] && !_assistedNodeInformation.hasNextNode && !_assistedNodeInformation.hasPreviousNode) {
         // In this case, there's no point in collapsing down to the form control focus UI because there's nothing the user could potentially do
@@ -4371,6 +4383,11 @@ static bool isAssistableInputType(InputType type)
     return _assistedNodeInformation.hasPreviousNode;
 }
 
+- (void)focusedFormControllerDidUpdateSuggestions:(WKFocusedFormControlViewController *)controller
+{
+    [_textInputViewController setSuggestions:controller.suggestions];
+}
+
 #pragma mark - WKSelectMenuViewControllerDelegate
 
 - (void)selectMenu:(WKSelectMenuViewController *)selectMenu didSelectItemAtIndex:(NSUInteger)index