Title: [245998] trunk
Revision
245998
Author
wenson_hs...@apple.com
Date
2019-05-31 16:36:30 -0700 (Fri, 31 May 2019)

Log Message

[iOS] Autocorrection menu font is Times New Roman when using font-family: UICTFontTextStyle*
https://bugs.webkit.org/show_bug.cgi?id=198427
<rdar://problem/50031825>

Reviewed by Tim Horton.

Source/WebKit:

When UICTFontTextStyle* is specified as the font-family in an editable element, text in autocorrection bubbles
always uses Times New Roman font. This is because we send a font family name, font size, and font attributes to
the UI process when computing autocorrection data for UIKit, and then assemble this information into a UIFont
object via +[UIFont fontWithFamilyName:traits:size:]. However, in the case where UICTFontTextStyle* is specified
as the font-family in CSS, the font family that we send to the UI process ends up being ".AppleSystemUIFont",
which +fontWithFamilyName:traits:size: fails to map to the system font as intended.

To fix this, we propagate font information to the UI process by encoding the UIFont itself via IPC, which
serializes the font descriptor, and then deserializes into a UIFont in the UI process. This allows the system
font to be returned in -fontForCaretSelection, which is invoked by UIKit when determining the font for the
autocorrection bubble. See below for more details.

Test: AutocorrectionTests.FontAtCaretWhenUsingUICTFontTextStyle

* Shared/ios/WebAutocorrectionData.h: Copied from Source/WebKit/UIProcess/AutoCorrectionCallback.h.
* Shared/ios/WebAutocorrectionData.mm: Renamed from Source/WebKit/UIProcess/AutoCorrectionCallback.h.
(WebKit::WebAutocorrectionData::encode const):
(WebKit::WebAutocorrectionData::decode):

Introduce WebAutocorrectionData, a struct containing information used to show autocorrection UI on iOS (i.e.
highlights and the bubble). This consists of a list of rects, along with a UIFont.

* SourcesCocoa.txt:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

Refactor requestAutocorrectionData to request a WebAutocorrectionData instead, and also use the new async IPC
reply mechanism.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
(-[WKContentView fontForCaretSelection]):

Grab the UIFont directly from the WebAutocorrectionData. Also, address a FIXME by scaling the font size by the
content scale.

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::requestAutocorrectionData):
(WebKit::WebPageProxy::autocorrectionDataCallback): Deleted.
(WebKit::WebPageProxy::autocorrectionContextCallback): Deleted.

Remove some IPC callbacks that are now unused.

* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestAutocorrectionData):

Tools:

Add a new API test to verify that -fontForCaretSelection returns the system font when using UICTFontTextStyle
in an editable web view.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm: Added.
(-[TestWKWebView autocorrectionRectsForString:]):
(checkCGRectIsEqualToCGRectWithLogging):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (245997 => 245998)


--- trunk/Source/WebKit/ChangeLog	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/ChangeLog	2019-05-31 23:36:30 UTC (rev 245998)
@@ -1,3 +1,61 @@
+2019-05-31  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] Autocorrection menu font is Times New Roman when using font-family: UICTFontTextStyle*
+        https://bugs.webkit.org/show_bug.cgi?id=198427
+        <rdar://problem/50031825>
+
+        Reviewed by Tim Horton.
+
+        When UICTFontTextStyle* is specified as the font-family in an editable element, text in autocorrection bubbles
+        always uses Times New Roman font. This is because we send a font family name, font size, and font attributes to
+        the UI process when computing autocorrection data for UIKit, and then assemble this information into a UIFont
+        object via +[UIFont fontWithFamilyName:traits:size:]. However, in the case where UICTFontTextStyle* is specified
+        as the font-family in CSS, the font family that we send to the UI process ends up being ".AppleSystemUIFont",
+        which +fontWithFamilyName:traits:size: fails to map to the system font as intended.
+
+        To fix this, we propagate font information to the UI process by encoding the UIFont itself via IPC, which
+        serializes the font descriptor, and then deserializes into a UIFont in the UI process. This allows the system
+        font to be returned in -fontForCaretSelection, which is invoked by UIKit when determining the font for the
+        autocorrection bubble. See below for more details.
+
+        Test: AutocorrectionTests.FontAtCaretWhenUsingUICTFontTextStyle
+
+        * Shared/ios/WebAutocorrectionData.h: Copied from Source/WebKit/UIProcess/AutoCorrectionCallback.h.
+        * Shared/ios/WebAutocorrectionData.mm: Renamed from Source/WebKit/UIProcess/AutoCorrectionCallback.h.
+        (WebKit::WebAutocorrectionData::encode const):
+        (WebKit::WebAutocorrectionData::decode):
+
+        Introduce WebAutocorrectionData, a struct containing information used to show autocorrection UI on iOS (i.e.
+        highlights and the bubble). This consists of a list of rects, along with a UIFont.
+
+        * SourcesCocoa.txt:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        Refactor requestAutocorrectionData to request a WebAutocorrectionData instead, and also use the new async IPC
+        reply mechanism.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
+        (-[WKContentView fontForCaretSelection]):
+
+        Grab the UIFont directly from the WebAutocorrectionData. Also, address a FIXME by scaling the font size by the
+        content scale.
+
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::requestAutocorrectionData):
+        (WebKit::WebPageProxy::autocorrectionDataCallback): Deleted.
+        (WebKit::WebPageProxy::autocorrectionContextCallback): Deleted.
+
+        Remove some IPC callbacks that are now unused.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestAutocorrectionData):
+
 2019-05-31  Ryosuke Niwa  <rn...@webkit.org>
 
         [iOS] Reveal the focused element when it's immediately above software keyboard

Copied: trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.h (from rev 245995, trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h) (0 => 245998)


--- trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(IOS_FAMILY)
+
+#include <wtf/Optional.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+
+namespace IPC {
+class Decoder;
+class Encoder;
+}
+
+namespace WebCore {
+class FloatRect;
+}
+
+OBJC_CLASS UIFont;
+
+namespace WebKit {
+
+struct WebAutocorrectionData {
+    Vector<WebCore::FloatRect> textRects;
+    RetainPtr<UIFont> font;
+
+    void encode(IPC::Encoder&) const;
+    static Optional<WebAutocorrectionData> decode(IPC::Decoder&);
+};
+
+} // namespace WebKit
+
+#endif // PLATFORM(IOS_FAMILY)

Copied: trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.mm (from rev 245995, trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h) (0 => 245998)


--- trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.mm	                        (rev 0)
+++ trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.mm	2019-05-31 23:36:30 UTC (rev 245998)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebAutocorrectionData.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "ArgumentCodersCocoa.h"
+#import "Decoder.h"
+#import "Encoder.h"
+#import "WebCoreArgumentCoders.h"
+#import <WebCore/FloatRect.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+void WebAutocorrectionData::encode(IPC::Encoder& encoder) const
+{
+    encoder << textRects;
+    IPC::encode(encoder, font.get());
+}
+
+Optional<WebAutocorrectionData> WebAutocorrectionData::decode(IPC::Decoder& decoder)
+{
+    Optional<Vector<FloatRect>> textRects;
+    decoder >> textRects;
+    if (!textRects)
+        return WTF::nullopt;
+
+    RetainPtr<UIFont> font;
+    if (!IPC::decode(decoder, font, @[ UIFont.class ]))
+        return WTF::nullopt;
+
+    return {{ *textRects, font }};
+}
+
+} // namespace WebKit
+
+#endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/SourcesCocoa.txt (245997 => 245998)


--- trunk/Source/WebKit/SourcesCocoa.txt	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2019-05-31 23:36:30 UTC (rev 245998)
@@ -172,6 +172,7 @@
 Shared/ios/NativeWebMouseEventIOS.mm
 Shared/ios/NativeWebTouchEventIOS.mm
 Shared/ios/QuickLookDocumentData.cpp
+Shared/ios/WebAutocorrectionData.mm
 Shared/ios/WebIconUtilities.mm
 Shared/ios/WebIOSEventFactory.mm
 Shared/ios/WebPlatformTouchPointIOS.cpp

Deleted: trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef AutoCorrectionCallback_h
-#define AutoCorrectionCallback_h
-
-#include "APIError.h"
-#include "GenericCallback.h"
-#include "WKAPICast.h"
-#include <wtf/HashMap.h>
-#include <wtf/RefCounted.h>
-
-namespace WebKit {
-
-struct WebAutocorrectionContext;
-
-typedef GenericCallback<const Vector<WebCore::FloatRect>&, const String&, double, uint64_t> AutocorrectionDataCallback;
-typedef GenericCallback<const WebAutocorrectionContext&> AutocorrectionContextCallback;
-typedef GenericCallback<const String&, const String&, const String&> SelectionContextCallback;
-
-} // namespace WebKit
-
-#endif // AutoCorrectionCallback_h

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -26,7 +26,6 @@
 #pragma once
 
 #include "APIObject.h"
-#include "AutoCorrectionCallback.h"
 #include "Connection.h"
 #include "ContextMenuContextData.h"
 #include "DownloadID.h"
@@ -291,6 +290,7 @@
 struct PlatformPopupMenuData;
 struct PrintInfo;
 struct TextInputContext;
+struct WebAutocorrectionData;
 struct WebPopupItem;
 struct URLSchemeTaskParameters;
 
@@ -307,6 +307,7 @@
 typedef GenericCallback<const String&> StringCallback;
 typedef GenericCallback<API::SerializedScriptValue*, bool, const WebCore::ExceptionDetails&> ScriptValueCallback;
 typedef GenericCallback<const WebCore::FontAttributes&> FontAttributesCallback;
+typedef GenericCallback<const String&, const String&, const String&> SelectionContextCallback;
 
 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
 using LayerHostingContextID = uint32_t;
@@ -678,7 +679,7 @@
     void beginSelectionInDirection(WebCore::SelectionDirection, WTF::Function<void (uint64_t, CallbackBase::Error)>&&);
     void updateSelectionWithExtentPoint(const WebCore::IntPoint, bool isInteractingWithFocusedElement, WTF::Function<void(uint64_t, CallbackBase::Error)>&&);
     void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint, WebCore::TextGranularity, bool isInteractingWithFocusedElement, WTF::Function<void(uint64_t, CallbackBase::Error)>&&);
-    void requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&&);
+    void requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&&);
     void applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&&);
     bool applyAutocorrection(const String& correction, const String& originalText);
     void requestAutocorrectionContext();
@@ -1869,8 +1870,6 @@
 #if PLATFORM(IOS_FAMILY)
     void gestureCallback(const WebCore::IntPoint&, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID);
     void touchesCallback(const WebCore::IntPoint&, uint32_t touches, uint32_t flags, CallbackID);
-    void autocorrectionDataCallback(const Vector<WebCore::FloatRect>&, const String& fontName, float fontSize, uint64_t fontTraits, CallbackID);
-    void autocorrectionContextCallback(const WebAutocorrectionContext&, CallbackID);
     void selectionContextCallback(const String& selectedText, const String& beforeText, const String& afterText, CallbackID);
     void interpretKeyEvent(const EditorState&, bool isCharEvent, CompletionHandler<void(bool)>&&);
     void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect, WebCore::RouteSharingPolicy, const String&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-05-31 23:36:30 UTC (rev 245998)
@@ -186,8 +186,6 @@
 #if PLATFORM(IOS_FAMILY)
     GestureCallback(WebCore::IntPoint point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, WebKit::CallbackID callbackID)
     TouchesCallback(WebCore::IntPoint point, uint32_t touches, uint32_t flags, WebKit::CallbackID callbackID)
-    AutocorrectionDataCallback(Vector<WebCore::FloatRect> textRects, String fontName, double fontSize, uint64_t traits, WebKit::CallbackID callbackID)
-    AutocorrectionContextCallback(struct WebKit::WebAutocorrectionContext context, WebKit::CallbackID callbackID)
     SelectionContextCallback(String selectedText, String beforeText, String afterText, WebKit::CallbackID callbackID)
     InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled) Synchronous
     DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -181,9 +181,7 @@
 WTF::TextStream& operator<<(WTF::TextStream&, const WKSelectionDrawingInfo&);
 
 struct WKAutoCorrectionData {
-    String fontName;
-    CGFloat fontSize;
-    uint64_t fontTraits;
+    RetainPtr<UIFont> font;
     CGRect textFirstRect;
     CGRect textLastRect;
 };

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-05-31 23:36:30 UTC (rev 245998)
@@ -65,6 +65,7 @@
 #import "WKWebViewInternal.h"
 #import "WKWebViewPrivate.h"
 #import "WebAutocorrectionContext.h"
+#import "WebAutocorrectionData.h"
 #import "WebDataListSuggestionsDropdownIOS.h"
 #import "WebEvent.h"
 #import "WebIOSEventFactory.h"
@@ -3529,9 +3530,10 @@
         return;
     }
 
-    _page->requestAutocorrectionData(input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& rects, auto& fontName, double fontSize, uint64_t traits, auto) {
+    _page->requestAutocorrectionData(input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto data) {
         CGRect firstRect;
         CGRect lastRect;
+        auto& rects = data.textRects;
         if (rects.isEmpty()) {
             firstRect = CGRectZero;
             lastRect = CGRectZero;
@@ -3540,9 +3542,7 @@
             lastRect = rects.last();
         }
 
-        view->_autocorrectionData.fontName = fontName;
-        view->_autocorrectionData.fontSize = fontSize;
-        view->_autocorrectionData.fontTraits = traits;
+        view->_autocorrectionData.font = data.font;
         view->_autocorrectionData.textFirstRect = firstRect;
         view->_autocorrectionData.textLastRect = lastRect;
 
@@ -4900,11 +4900,9 @@
 
 - (UIFont *)fontForCaretSelection
 {
-    CGFloat zoomScale = 1.0;    // FIXME: retrieve the actual document scale factor.
-    CGFloat scaledSize = _autocorrectionData.fontSize;
-    if (CGFAbs(zoomScale - 1.0) > FLT_EPSILON)
-        scaledSize *= zoomScale;
-    return [UIFont fontWithFamilyName:_autocorrectionData.fontName traits:(UIFontTrait)_autocorrectionData.fontTraits size:scaledSize];
+    UIFont *font = _autocorrectionData.font.get();
+    double zoomScale = self._contentZoomScale;
+    return std::abs(zoomScale - 1) > FLT_EPSILON ? [font fontWithSize:font.pointSize * zoomScale] : font;
 }
 
 - (BOOL)hasSelection

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (245997 => 245998)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2019-05-31 23:36:30 UTC (rev 245998)
@@ -52,6 +52,7 @@
 #import "ViewUpdateDispatcherMessages.h"
 #import "WKBrowsingContextControllerInternal.h"
 #import "WebAutocorrectionContext.h"
+#import "WebAutocorrectionData.h"
 #import "WebPageMessages.h"
 #import "WebProcessPool.h"
 #import "WebProcessProxy.h"
@@ -160,17 +161,6 @@
     callback->performCallbackWithReturnValue(point, touches, flags);
 }
 
-void WebPageProxy::autocorrectionDataCallback(const Vector<WebCore::FloatRect>& rects, const String& fontName, float fontSize, uint64_t fontTraits, CallbackID callbackID)
-{
-    auto callback = m_callbacks.take<AutocorrectionDataCallback>(callbackID);
-    if (!callback) {
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    callback->performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
-}
-
 void WebPageProxy::selectionContextCallback(const String& selectedText, const String& beforeText, const String& afterText, CallbackID callbackID)
 {
     auto callback = m_callbacks.take<SelectionContextCallback>(callbackID);
@@ -182,17 +172,6 @@
     callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
 }
 
-void WebPageProxy::autocorrectionContextCallback(const WebAutocorrectionContext& context, CallbackID callbackID)
-{
-    auto callback = m_callbacks.take<AutocorrectionContextCallback>(callbackID);
-    if (!callback) {
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    callback->performCallbackWithReturnValue(context);
-}
-
 void WebPageProxy::selectionRectsCallback(const Vector<WebCore::SelectionRect>& selectionRects, CallbackID callbackID)
 {
     auto callback = m_callbacks.take<SelectionRectsCallback>(callbackID);
@@ -464,15 +443,13 @@
     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
 }
 
-void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&& callbackFunction)
+void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&& callback)
 {
     if (!hasRunningProcess()) {
-        callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
+        callback({ });
         return;
     }
-
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
-    m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
+    m_process->connection()->sendWithAsyncReply(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection), WTFMove(callback), m_pageID);
 }
 
 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (245997 => 245998)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-05-31 23:36:30 UTC (rev 245998)
@@ -1195,7 +1195,6 @@
 		7CBB81211AA0F970006B1942 /* WKBundleFileHandleRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CBB811F1AA0F970006B1942 /* WKBundleFileHandleRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CC99A3618EF7CBC0048C8B4 /* WKScriptMessageInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC99A3518EF7CBC0048C8B4 /* WKScriptMessageInternal.h */; };
 		7CCCC8FB1A5F50FD008FB0DA /* WebNavigationState.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CCCC8F91A5F50FD008FB0DA /* WebNavigationState.h */; };
-		7CD102DA1866770600ED429D /* AutoCorrectionCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD102D91866770600ED429D /* AutoCorrectionCallback.h */; };
 		7CD3A4831A5D02FA009623B8 /* APINavigation.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD3A4811A5D02FA009623B8 /* APINavigation.h */; };
 		7CD5EBB91746A15B000C1C45 /* WKObjCTypeWrapperRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD5EBB71746A15B000C1C45 /* WKObjCTypeWrapperRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7CD5EBBB1746A83E000C1C45 /* WKBaseMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD5EBBA1746A83E000C1C45 /* WKBaseMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1656,6 +1655,7 @@
 		ECA680D81E690E2500731D20 /* WebProcessCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = ECA680D71E690DF800731D20 /* WebProcessCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		F42D634122A0EFDF00D2FB3A /* WebAutocorrectionData.h in Headers */ = {isa = PBXBuildFile; fileRef = F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */; };
 		F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */; };
 		F430E94422473DFF005FE053 /* WebCompatibilityMode.h in Headers */ = {isa = PBXBuildFile; fileRef = F430E94322473DB8005FE053 /* WebCompatibilityMode.h */; };
 		F438CD1C2241421400DE6DDA /* WKWebpagePreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -3734,7 +3734,6 @@
 		7CC99A3518EF7CBC0048C8B4 /* WKScriptMessageInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKScriptMessageInternal.h; sourceTree = "<group>"; };
 		7CCCC8F81A5F50FD008FB0DA /* WebNavigationState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNavigationState.cpp; sourceTree = "<group>"; };
 		7CCCC8F91A5F50FD008FB0DA /* WebNavigationState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNavigationState.h; sourceTree = "<group>"; };
-		7CD102D91866770600ED429D /* AutoCorrectionCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoCorrectionCallback.h; sourceTree = "<group>"; };
 		7CD3A4801A5D02FA009623B8 /* APINavigation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APINavigation.cpp; sourceTree = "<group>"; };
 		7CD3A4811A5D02FA009623B8 /* APINavigation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APINavigation.h; sourceTree = "<group>"; };
 		7CD5EBB61746A15B000C1C45 /* WKObjCTypeWrapperRef.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObjCTypeWrapperRef.mm; sourceTree = "<group>"; };
@@ -4630,6 +4629,8 @@
 		F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDragDestinationAction.h; sourceTree = "<group>"; };
 		F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
 		F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
+		F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionData.h; path = ios/WebAutocorrectionData.h; sourceTree = "<group>"; };
+		F42D634022A0EFD300D2FB3A /* WebAutocorrectionData.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebAutocorrectionData.mm; path = ios/WebAutocorrectionData.mm; sourceTree = "<group>"; };
 		F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsiteMetaViewportPolicy.h; sourceTree = "<group>"; };
 		F430E94322473DB8005FE053 /* WebCompatibilityMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCompatibilityMode.h; sourceTree = "<group>"; };
 		F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferences.h; sourceTree = "<group>"; };
@@ -5920,6 +5921,8 @@
 				A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */,
 				4459984122833E6000E61373 /* SyntheticEditingCommandType.h */,
 				F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */,
+				F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */,
+				F42D634022A0EFD300D2FB3A /* WebAutocorrectionData.mm */,
 				F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */,
 				F44DFEB11E9E752F0038D196 /* WebIconUtilities.mm */,
 				2DA944991884E4F000ED86DB /* WebIOSEventFactory.h */,
@@ -7527,7 +7530,6 @@
 				1AAF089E192681AC00B6390C /* UserContent */,
 				57608294202BD84900116678 /* WebAuthentication */,
 				1A53C2A31A325691004E8C70 /* WebsiteData */,
-				7CD102D91866770600ED429D /* AutoCorrectionCallback.h */,
 				E1513C64166EABB200149FCB /* AuxiliaryProcessProxy.cpp */,
 				E1513C65166EABB200149FCB /* AuxiliaryProcessProxy.h */,
 				46A2B6061E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.cpp */,
@@ -9194,7 +9196,6 @@
 				57DCEDB1214C60480016B847 /* Authenticator.h in Headers */,
 				57DCEDAF214C603B0016B847 /* AuthenticatorManager.h in Headers */,
 				57DCEDB0214C60420016B847 /* AuthenticatorTransportService.h in Headers */,
-				7CD102DA1866770600ED429D /* AutoCorrectionCallback.h in Headers */,
 				9955A6EF1C79810800EB6A93 /* Automation.json in Headers */,
 				9955A6F51C7986E000EB6A93 /* AutomationBackendDispatchers.h in Headers */,
 				99C81D5A1C20E7E2005C4C82 /* AutomationClient.h in Headers */,
@@ -9596,6 +9597,7 @@
 				57DCED6F2142EE630016B847 /* WebAuthenticatorCoordinatorMessages.h in Headers */,
 				57DCEDB3214C60530016B847 /* WebAuthenticatorCoordinatorProxy.h in Headers */,
 				57DCED712142EE6C0016B847 /* WebAuthenticatorCoordinatorProxyMessages.h in Headers */,
+				F42D634122A0EFDF00D2FB3A /* WebAutocorrectionData.h in Headers */,
 				9955A6EC1C7980C200EB6A93 /* WebAutomationSession.h in Headers */,
 				99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */,
 				1C0A19581C90068F00FE0EBB /* WebAutomationSessionMessages.h in Headers */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (245997 => 245998)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -264,6 +264,7 @@
 struct LoadParameters;
 struct PrintInfo;
 struct TextInputContext;
+struct WebAutocorrectionData;
 struct WebAutocorrectionContext;
 struct WebPageCreationParameters;
 struct WebPreferencesStore;
@@ -657,7 +658,7 @@
     void requestDictationContext(CallbackID);
     void replaceDictatedText(const String& oldText, const String& newText);
     void replaceSelectedText(const String& oldText, const String& newText);
-    void requestAutocorrectionData(const String& textForAutocorrection, CallbackID);
+    void requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&& reply);
     void applyAutocorrection(const String& correction, const String& originalText, CallbackID);
     void syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&&);
     void requestAutocorrectionContext();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (245997 => 245998)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2019-05-31 23:36:30 UTC (rev 245998)
@@ -77,7 +77,7 @@
     RequestDictationContext(WebKit::CallbackID callbackID)
     ReplaceDictatedText(String oldText, String newText)
     ReplaceSelectedText(String oldText, String newText)
-    RequestAutocorrectionData(String textForAutocorrection, WebKit::CallbackID callbackID)
+    RequestAutocorrectionData(String textForAutocorrection) -> (struct WebKit::WebAutocorrectionData data) Async
     ApplyAutocorrection(String correction, String originalText, WebKit::CallbackID callbackID)
     SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) Synchronous
     RequestAutocorrectionContext()

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (245997 => 245998)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-05-31 23:36:30 UTC (rev 245998)
@@ -50,6 +50,7 @@
 #import "VisibleContentRectUpdateInfo.h"
 #import "WKAccessibilityWebPageObjectIOS.h"
 #import "WebAutocorrectionContext.h"
+#import "WebAutocorrectionData.h"
 #import "WebChromeClient.h"
 #import "WebCoreArgumentCoders.h"
 #import "WebFrame.h"
@@ -2244,22 +2245,22 @@
     frame.editor().setIgnoreSelectionChanges(false);
 }
 
-void WebPage::requestAutocorrectionData(const String& textForAutocorrection, CallbackID callbackID)
+void WebPage::requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&& reply)
 {
-    Frame& frame = m_page->focusController().focusedOrMainFrame();
+    auto& frame = m_page->focusController().focusedOrMainFrame();
     if (!frame.selection().isCaret()) {
-        send(Messages::WebPageProxy::AutocorrectionDataCallback(Vector<FloatRect>(), String(), 0, 0, callbackID));
+        reply({ });
         return;
     }
 
     VisiblePosition position = frame.selection().selection().start();
-    RefPtr<Range> range = wordRangeFromPosition(position);
+    auto range = wordRangeFromPosition(position);
     if (!range) {
-        send(Messages::WebPageProxy::AutocorrectionDataCallback(Vector<FloatRect>(), String(), 0, 0, callbackID));
+        reply({ });
         return;
     }
 
-    String textForRange = plainTextReplacingNoBreakSpace(range.get());
+    auto textForRange = plainTextReplacingNoBreakSpace(range.get());
     const unsigned maxSearchAttempts = 5;
     for (size_t i = 0;  i < maxSearchAttempts && textForRange != textForAutocorrection; ++i)
     {
@@ -2286,10 +2287,7 @@
     if (auto* coreFont = frame.editor().fontForSelection(multipleFonts))
         font = coreFont->getCTFont();
 
-    CGFloat fontSize = CTFontGetSize(font);
-    uint64_t fontTraits = CTFontGetSymbolicTraits(font);
-    RetainPtr<NSString> fontName = adoptNS((NSString *)CTFontCopyFamilyName(font));
-    send(Messages::WebPageProxy::AutocorrectionDataCallback(rectsForText, fontName.get(), fontSize, fontTraits, callbackID));
+    reply({ WTFMove(rectsForText), (__bridge UIFont *)font });
 }
 
 void WebPage::applyAutocorrection(const String& correction, const String& originalText, CallbackID callbackID)

Modified: trunk/Tools/ChangeLog (245997 => 245998)


--- trunk/Tools/ChangeLog	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Tools/ChangeLog	2019-05-31 23:36:30 UTC (rev 245998)
@@ -1,3 +1,21 @@
+2019-05-31  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] Autocorrection menu font is Times New Roman when using font-family: UICTFontTextStyle*
+        https://bugs.webkit.org/show_bug.cgi?id=198427
+        <rdar://problem/50031825>
+
+        Reviewed by Tim Horton.
+
+        Add a new API test to verify that -fontForCaretSelection returns the system font when using UICTFontTextStyle
+        in an editable web view.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm: Added.
+        (-[TestWKWebView autocorrectionRectsForString:]):
+        (checkCGRectIsEqualToCGRectWithLogging):
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2019-05-31  Tim Horton  <timothy_hor...@apple.com>
 
         REGRESSION: WebKit.InteractionDeadlockAfterCrash and SynchronousTimeoutTests.UnresponsivePageDoesNotCausePositionInformationToHangUI API tests are failing

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (245997 => 245998)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-05-31 23:36:30 UTC (rev 245998)
@@ -896,6 +896,7 @@
 		F41AB9A81EF4696B0083FA08 /* prevent-operation.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F41AB9941EF4692C0083FA08 /* prevent-operation.html */; };
 		F41AB9A91EF4696B0083FA08 /* prevent-start.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F41AB99A1EF4692C0083FA08 /* prevent-start.html */; };
 		F41AB9AA1EF4696B0083FA08 /* textarea-to-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F41AB9951EF4692C0083FA08 /* textarea-to-input.html */; };
+		F42D634422A1729F00D2FB3A /* AutocorrectionTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */; };
 		F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
 		F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */; };
 		F43E3BC120DADBC500A4E7ED /* fixed-nav-bar.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */; };
@@ -2289,6 +2290,7 @@
 		F41AB99C1EF4692C0083FA08 /* contenteditable-and-textarea.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "contenteditable-and-textarea.html"; sourceTree = "<group>"; };
 		F41AB99D1EF4692C0083FA08 /* link-and-target-div.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "link-and-target-div.html"; sourceTree = "<group>"; };
 		F41AB99E1EF4692C0083FA08 /* div-and-large-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "div-and-large-image.html"; sourceTree = "<group>"; };
+		F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutocorrectionTestsIOS.mm; sourceTree = "<group>"; };
 		F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKitCocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
 		F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKScrollViewTests.mm; sourceTree = "<group>"; };
 		F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "fixed-nav-bar.html"; sourceTree = "<group>"; };
@@ -2873,6 +2875,7 @@
 				A1C4FB6F1BACCEFA003742D0 /* Resources */,
 				2E205BA31F527746005952DD /* AccessibilityTestsIOS.mm */,
 				F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */,
+				F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */,
 				F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */,
 				F4BC0B132146C849002A0478 /* FocusPreservationTests.mm */,
 				F45E15722112CE2900307E82 /* KeyboardInputTestsIOS.mm */,
@@ -4084,6 +4087,7 @@
 				7CCE7EB41A411A7E00447C4C /* AttributedString.mm in Sources */,
 				3760C4F1211249AF00233ACC /* AttrStyle.mm in Sources */,
 				CDC8E48D1BC5CB4500594FEC /* AudioSessionCategoryIOS.mm in Sources */,
+				F42D634422A1729F00D2FB3A /* AutocorrectionTestsIOS.mm in Sources */,
 				7C83E0B91D0A64F100FEBCF3 /* AutoLayoutIntegration.mm in Sources */,
 				07CD32F62065B5430064A4BE /* AVFoundationPreference.mm in Sources */,
 				0711DF52226A95FC003DD2F7 /* AVFoundationSoftLinkTest.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm (0 => 245998)


--- trunk/Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm	2019-05-31 23:36:30 UTC (rev 245998)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "TestInputDelegate.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+#import <WebKit/WKWebViewPrivate.h>
+
+@interface TestWKWebView (AutocorrectionTests)
+- (UIWKAutocorrectionRects *)autocorrectionRectsForString:(NSString *)string;
+@end
+
+@implementation TestWKWebView (AutocorrectionTests)
+
+- (UIWKAutocorrectionRects *)autocorrectionRectsForString:(NSString *)string
+{
+    RetainPtr<UIWKAutocorrectionRects> result;
+    bool done = false;
+    [self.textInputContentView requestAutocorrectionRectsForString:string withCompletionHandler:[&] (UIWKAutocorrectionRects *rects) {
+        result = rects;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    return result.autorelease();
+}
+
+@end
+
+static void checkCGRectIsEqualToCGRectWithLogging(CGRect expected, CGRect observed)
+{
+    BOOL isEqual = CGRectEqualToRect(expected, observed);
+    EXPECT_TRUE(isEqual);
+    if (!isEqual)
+        NSLog(@"Expected: %@ but observed: %@", NSStringFromCGRect(expected), NSStringFromCGRect(observed));
+}
+
+TEST(AutocorrectionTests, FontAtCaretWhenUsingUICTFontTextStyle)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] init]);
+    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
+    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
+
+    [webView _setInputDelegate:inputDelegate.get()];
+    [webView _setEditable:YES];
+    [webView synchronouslyLoadHTMLString:@"<meta name='viewport' content='width=device-width, initial-scale=1'><body style='font-size: 16px; font-family: UICTFontTextStyleBody'>Wulk</body>"];
+    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
+    [webView _executeEditCommand:@"MoveToEndOfLine" argument:nil completion:nil];
+
+    auto autocorrectionRects = retainPtr([webView autocorrectionRectsForString:@"Wulk"]);
+    checkCGRectIsEqualToCGRectWithLogging(CGRectMake(8, 8, 36, 21), [autocorrectionRects firstRect]);
+    checkCGRectIsEqualToCGRectWithLogging(CGRectMake(8, 8, 36, 21), [autocorrectionRects lastRect]);
+
+    auto contentView = [webView textInputContentView];
+    UIFont *fontBeforeScaling = [contentView fontForCaretSelection];
+    UIFont *size16SystemFont = [UIFont systemFontOfSize:16];
+    EXPECT_WK_STREQ(size16SystemFont.fontName, fontBeforeScaling.fontName);
+    EXPECT_WK_STREQ(size16SystemFont.familyName, fontBeforeScaling.familyName);
+    EXPECT_EQ(16, fontBeforeScaling.pointSize);
+
+    [webView scrollView].zoomScale = 2;
+    UIFont *fontAfterScaling = [contentView fontForCaretSelection];
+    UIFont *size32SystemFont = [UIFont systemFontOfSize:32];
+    EXPECT_WK_STREQ(size32SystemFont.fontName, fontAfterScaling.fontName);
+    EXPECT_WK_STREQ(size32SystemFont.familyName, fontAfterScaling.familyName);
+    EXPECT_EQ(32, fontAfterScaling.pointSize);
+}
+
+#endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (245997 => 245998)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -32,6 +32,7 @@
 @class _WKActivatedElementInfo;
 @protocol UITextInputMultiDocument;
 @protocol UITextInputPrivate;
+@protocol UIWKInteractionViewProtocol;
 #endif
 
 @interface WKWebView (AdditionalDeclarations)
@@ -84,7 +85,7 @@
 @end
 
 @interface TestWKWebView (IOSOnly)
-@property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputMultiDocument> *textInputContentView;
+@property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputMultiDocument, UIWKInteractionViewProtocol> *textInputContentView;
 @property (nonatomic, readonly) RetainPtr<NSArray> selectionRectsAfterPresentationUpdate;
 @property (nonatomic, readonly) CGRect caretViewRectInContentCoordinates;
 @property (nonatomic, readonly) NSArray<NSValue *> *selectionViewRectsInContentCoordinates;

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (245997 => 245998)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-05-31 23:25:04 UTC (rev 245997)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-05-31 23:36:30 UTC (rev 245998)
@@ -83,6 +83,7 @@
 - (void)handleKeyWebEvent:(WebEvent *)theEvent withCompletionHandler:(void (^)(WebEvent *, BOOL))completionHandler;
 - (BOOL)_shouldSuppressSelectionCommands;
 - (NSDictionary *)_autofillContext;
+- (UIFont *)fontForCaretSelection;
 @end
 
 @interface UIWebFormAccessory : UIInputView
@@ -142,6 +143,15 @@
 
 @end
 
+@interface UIWKAutocorrectionRects : NSObject
+@property (nonatomic) CGRect firstRect;
+@property (nonatomic) CGRect lastRect;
+@end
+
+@protocol UIWKInteractionViewProtocol
+- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
+@end
+
 #endif
 
 #if __has_include(<UIKit/UITextAutofillSuggestion.h>)
@@ -175,7 +185,7 @@
 + (BOOL)isInHardwareKeyboardMode;
 @end
 
-@protocol UIWKInteractionViewProtocol_Staging_49236384
+@protocol UIWKInteractionViewProtocol_Staging_49236384 <UIWKInteractionViewProtocol>
 - (void)pasteWithCompletionHandler:(void (^)(void))completionHandler;
 @end
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to