Skip to content

Commit

Permalink
Cherry-pick 1f6aecd. rdar://120666173
Browse files Browse the repository at this point in the history
    [UIAsyncTextInput] Fix several failing iOS API tests when async text input is enabled
    https://bugs.webkit.org/show_bug.cgi?id=267064
    rdar://120438466

    Reviewed by Megan Gardner.

    Fix 4 failing API tests, when async text input is enabled:

    • DragAndDropTests.ContentEditableToContentEditable
    • DragAndDropTests.ContentEditableToTextarea

    These two tests are failing because they expect WebKit to write RTF and/or FlatRTFD upon starting a
    drag. This is no longer the case when this feature is enabled, since the system now takes care of
    lazily coercing web archive and HTML data to RTF/FlatRTFD/`NSAttributedString` as needed.

    As such, we simply adjust this test to pass as long as HTML data is placed at a higher type fidelity
    than plain text.

    • KeyboardInputTests.IsSingleLineDocument

    This actually caught a real bug, where we're failing to actually set the `singleLineDocument`
    property on the extended traits delegate (`WKSEExtendedTextInputTraits`), since the call site is
    guarded by a `-respondsToSelector:` check for `-setIsSingleLineDocument:` (the legacy name on
    private text input traits) instead of `-setSingleLineDocument:` (the new property name on the
    extended traits).

    Fix the test by fixing `-_updateTextInputTraits:`.

    • KeyboardInputTests.EditableWebViewRequiresKeyboardWhenFirstResponder

    This test failure is due to the fact that, for a fully-editable web view (i.e. if the embedder sets
    `-[WKWebView _editable]` to `YES`), `-_requiresKeyboardWhenFirstResponder` now returns `YES` instead
    of `NO` when focusing a `readonly` text field.

    Address this and restore shipping behavior by only reverting to the superclass implementation in the
    case where the web view is not fully editable.

    * Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
    (-[WKContentView _requiresKeyboardWhenFirstResponder]):
    (-[WKContentView _updateTextInputTraits:]):
    * Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
    (checkRichTextTypePrecedesPlainTextType):

    Canonical link: https://commits.webkit.org/272638@main

Canonical link: https://commits.webkit.org/271831.81@safari-7619.0.1-branch
  • Loading branch information
Dan Robson committed Jan 11, 2024
1 parent a45d162 commit e681ed9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
30 changes: 16 additions & 14 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2692,14 +2692,15 @@ - (BOOL)_disableAutomaticKeyboardUI

- (BOOL)_requiresKeyboardWhenFirstResponder
{
if ([_webView _isEditable] && !self._disableAutomaticKeyboardUI)
return YES;

BOOL webViewIsEditable = [_webView _isEditable];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
if (self.shouldUseAsyncInteractions)
if (!webViewIsEditable && self.shouldUseAsyncInteractions)
return [super _requiresKeyboardWhenFirstResponder];
#endif

if (webViewIsEditable && !self._disableAutomaticKeyboardUI)
return YES;

// FIXME: We should add the logic to handle keyboard visibility during focus redirects.
return [self _shouldShowAutomaticKeyboardUIIgnoringInputMode] || _seenHardwareKeyDownInNonEditableElement;
}
Expand Down Expand Up @@ -6796,13 +6797,13 @@ - (void)_updateTextInputTraits:(id<UITextInputTraits>)traits

auto extendedTraits = dynamic_objc_cast<WKExtendedTextInputTraits>(traits);
auto privateTraits = (id <UITextInputTraits_Private>)traits;
if ([privateTraits respondsToSelector:@selector(setIsSingleLineDocument:)]) {

BOOL isSingleLineDocument = ^{
switch (_focusedElementInformation.elementType) {
case WebKit::InputType::ContentEditable:
case WebKit::InputType::TextArea:
extendedTraits.singleLineDocument = NO;
privateTraits.isSingleLineDocument = NO;
break;
case WebKit::InputType::None:
return NO;
#if ENABLE(INPUT_TYPE_COLOR)
case WebKit::InputType::Color:
#endif
Expand All @@ -6821,13 +6822,14 @@ - (void)_updateTextInputTraits:(id<UITextInputTraits>)traits
case WebKit::InputType::Time:
case WebKit::InputType::URL:
case WebKit::InputType::Week:
extendedTraits.singleLineDocument = YES;
privateTraits.isSingleLineDocument = YES;
break;
case WebKit::InputType::None:
break;
return YES;
}
}
}();

if ([extendedTraits respondsToSelector:@selector(setSingleLineDocument:)])
extendedTraits.singleLineDocument = isSingleLineDocument;
else if ([privateTraits respondsToSelector:@selector(setIsSingleLineDocument:)])
privateTraits.isSingleLineDocument = isSingleLineDocument;

if (_focusedElementInformation.hasEverBeenPasswordField) {
if ([privateTraits respondsToSelector:@selector(setLearnsCorrections:)])
Expand Down
14 changes: 9 additions & 5 deletions Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#import <MapKit/MapKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <UIKit/NSItemProvider+UIKitAdditions.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKPreferencesRefPrivate.h>
#import <WebKit/WKProcessPoolPrivate.h>
Expand Down Expand Up @@ -128,13 +129,16 @@ static void checkCGRectIsEqualToCGRectWithLogging(CGRect expected, CGRect observ

static void checkRichTextTypePrecedesPlainTextType(DragAndDropSimulator *simulator)
{
// At least one of "com.apple.flat-rtfd" or "public.rtf" is expected to have higher precedence than "public.utf8-plain-text".
NSArray *registeredTypes = [simulator.sourceItemProviders.firstObject registeredTypeIdentifiers];
auto indexOfRTFType = [registeredTypes indexOfObject:(__bridge NSString *)kUTTypeRTF];
auto indexOfFlatRTFDType = [registeredTypes indexOfObject:(__bridge NSString *)kUTTypeFlatRTFD];
auto indexOfPlainTextType = [registeredTypes indexOfObject:(__bridge NSString *)kUTTypeUTF8PlainText];
auto indexOfHTMLType = [registeredTypes indexOfObject:UTTypeHTML.identifier];
auto indexOfRTFType = [registeredTypes indexOfObject:UTTypeRTF.identifier];
auto indexOfFlatRTFDType = [registeredTypes indexOfObject:UTTypeFlatRTFD.identifier];
auto indexOfPlainTextType = [registeredTypes indexOfObject:UTTypeUTF8PlainText.identifier];
EXPECT_NE((NSInteger)indexOfPlainTextType, NSNotFound);
EXPECT_TRUE((indexOfRTFType != NSNotFound && indexOfRTFType < indexOfPlainTextType) || (indexOfFlatRTFDType != NSNotFound && indexOfFlatRTFDType < indexOfPlainTextType));
BOOL hasHighFidelityRTF = indexOfRTFType != NSNotFound && indexOfRTFType < indexOfPlainTextType;
BOOL hasHighFidelityFlatRTFD = indexOfFlatRTFDType != NSNotFound && indexOfFlatRTFDType < indexOfPlainTextType;
BOOL hasHighFidelityHTML = indexOfHTMLType != NSNotFound && indexOfHTMLType < indexOfPlainTextType;
EXPECT_TRUE(hasHighFidelityHTML || hasHighFidelityFlatRTFD || hasHighFidelityRTF);
}

static void checkFirstTypeIsPresentAndSecondTypeIsMissing(DragAndDropSimulator *simulator, CFStringRef firstType, CFStringRef secondType)
Expand Down

0 comments on commit e681ed9

Please sign in to comment.