Title: [266802] trunk/Source
Revision
266802
Author
wenson_hs...@apple.com
Date
2020-09-09 15:19:10 -0700 (Wed, 09 Sep 2020)

Log Message

Text copied and pasted from Mac Catalyst apps appears larger than expected
https://bugs.webkit.org/show_bug.cgi?id=215971
<rdar://problem/65768907>

Reviewed by Tim Horton.

Source/WebKit:

Various pieces of platform logic in Mac Catalyst depend on the user interface idiom (i.e. Mac or iPad) of the
app, as well as the application-wide "scale factor". In the context of this bug, NSAttributedString to RTF data
conversion methods in `UIFoundation` consult the scale factor of `UIiOSMacIdiomManager` to determine whether to
emit 0 (standard) or 1 (iOS) for the `\cocoatextscaling` attribute. The fact that the web process' scale factor
may be out of sync with the UI process' scale factor leads to copied RTF data in the web process appearing
either larger or smaller than expected, due to an incorrect `NSTextScalingType` value.

To mitigate this (as well as any other issues), we add a mechanism for the UI process to forward the global
scale factor and user interface idiom to the web process inside of the web process creation parameters, and then
use new UIKit SPI to override the scale factor and idiom within the web process.

* Scripts/process-entitlements.sh:

Add a new entitlement needed to use `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):

Use `_UIApplicationCatalystUserInterfaceIdiom` and `_UIApplicationCatalystScaleFactor` to grab the global user
interface idiom and scale factor, respectively.

* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Override the idiom and scale factor in the web process with the idiom and scale factor from the UI process,
using the new SPI `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`. As this function hasn't landed
yet, we soft link the function for now to avoid causing the web process to instantly crash on any builds without
the fix for <rdar://problem/68524148>.

Source/WTF:

Add a new flag to guard the presence of `_UIApplicationCatalystUserInterfaceIdiom`,
`_UIApplicationCatalystScaleFactor`, and `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`.

* wtf/PlatformHave.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (266801 => 266802)


--- trunk/Source/WTF/ChangeLog	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WTF/ChangeLog	2020-09-09 22:19:10 UTC (rev 266802)
@@ -1,3 +1,16 @@
+2020-09-09  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Text copied and pasted from Mac Catalyst apps appears larger than expected
+        https://bugs.webkit.org/show_bug.cgi?id=215971
+        <rdar://problem/65768907>
+
+        Reviewed by Tim Horton.
+
+        Add a new flag to guard the presence of `_UIApplicationCatalystUserInterfaceIdiom`,
+        `_UIApplicationCatalystScaleFactor`, and `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`.
+
+        * wtf/PlatformHave.h:
+
 2020-09-08  Ryosuke Niwa  <rn...@webkit.org>
 
         Node flags should be an OptionSet

Modified: trunk/Source/WTF/wtf/PlatformHave.h (266801 => 266802)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-09-09 22:19:10 UTC (rev 266802)
@@ -750,3 +750,7 @@
     || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 140000)
 #define HAVE_CTFONTDESCRIPTOR_CREATE_WITH_TEXT_STYLE_AND_ATTRIBUTES 1
 #endif
+
+#if PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000
+#define HAVE_CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR 1
+#endif

Modified: trunk/Source/WebKit/ChangeLog (266801 => 266802)


--- trunk/Source/WebKit/ChangeLog	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/ChangeLog	2020-09-09 22:19:10 UTC (rev 266802)
@@ -1,3 +1,44 @@
+2020-09-09  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Text copied and pasted from Mac Catalyst apps appears larger than expected
+        https://bugs.webkit.org/show_bug.cgi?id=215971
+        <rdar://problem/65768907>
+
+        Reviewed by Tim Horton.
+
+        Various pieces of platform logic in Mac Catalyst depend on the user interface idiom (i.e. Mac or iPad) of the
+        app, as well as the application-wide "scale factor". In the context of this bug, NSAttributedString to RTF data
+        conversion methods in `UIFoundation` consult the scale factor of `UIiOSMacIdiomManager` to determine whether to
+        emit 0 (standard) or 1 (iOS) for the `\cocoatextscaling` attribute. The fact that the web process' scale factor
+        may be out of sync with the UI process' scale factor leads to copied RTF data in the web process appearing
+        either larger or smaller than expected, due to an incorrect `NSTextScalingType` value.
+
+        To mitigate this (as well as any other issues), we add a mechanism for the UI process to forward the global
+        scale factor and user interface idiom to the web process inside of the web process creation parameters, and then
+        use new UIKit SPI to override the scale factor and idiom within the web process.
+
+        * Scripts/process-entitlements.sh:
+
+        Add a new entitlement needed to use `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+
+        Use `_UIApplicationCatalystUserInterfaceIdiom` and `_UIApplicationCatalystScaleFactor` to grab the global user
+        interface idiom and scale factor, respectively.
+
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
+        Override the idiom and scale factor in the web process with the idiom and scale factor from the UI process,
+        using the new SPI `_UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor`. As this function hasn't landed
+        yet, we soft link the function for now to avoid causing the web process to instantly crash on any builds without
+        the fix for <rdar://problem/68524148>.
+
 2020-09-09  Brady Eidson  <beid...@apple.com>
 
         Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.

Modified: trunk/Source/WebKit/Scripts/process-entitlements.sh (266801 => 266802)


--- trunk/Source/WebKit/Scripts/process-entitlements.sh	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/Scripts/process-entitlements.sh	2020-09-09 22:19:10 UTC (rev 266802)
@@ -110,6 +110,7 @@
     then
         plistbuddy Add :com.apple.pac.shared_region_id string WebContent
         plistbuddy Add :com.apple.private.pac.exception bool YES
+        plistbuddy Add :com.apple.UIKit.view-service-wants-custom-idiom-and-scale bool YES
     fi
 }
 

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (266801 => 266802)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-09-09 22:19:10 UTC (rev 266802)
@@ -192,6 +192,10 @@
 #if PLATFORM(GTK)
     encoder << useSystemAppearanceForScrollbars;
 #endif
+
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+    encoder << overrideUserInterfaceIdiomAndScale;
+#endif
 }
 
 bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreationParameters& parameters)
@@ -517,6 +521,14 @@
     parameters.useSystemAppearanceForScrollbars = WTFMove(*useSystemAppearanceForScrollbars);
 #endif
 
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+    Optional<std::pair<int64_t, double>> overrideUserInterfaceIdiomAndScale;
+    decoder >> overrideUserInterfaceIdiomAndScale;
+    if (!overrideUserInterfaceIdiomAndScale)
+        return false;
+    parameters.overrideUserInterfaceIdiomAndScale = WTFMove(*overrideUserInterfaceIdiomAndScale);
+#endif
+
     return true;
 }
 

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (266801 => 266802)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-09-09 22:19:10 UTC (rev 266802)
@@ -235,6 +235,10 @@
 #if PLATFORM(GTK)
     bool useSystemAppearanceForScrollbars { false };
 #endif
+
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+    std::pair<int64_t, double> overrideUserInterfaceIdiomAndScale;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (266801 => 266802)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-09-09 22:19:10 UTC (rev 266802)
@@ -480,6 +480,10 @@
             startObservingPreferenceChanges();
     }
 #endif
+
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+    parameters.overrideUserInterfaceIdiomAndScale = { _UIApplicationCatalystUserInterfaceIdiom(), _UIApplicationCatalystScaleFactor() };
+#endif
 }
 
 void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (266801 => 266802)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-09-09 22:13:54 UTC (rev 266801)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-09-09 22:19:10 UTC (rev 266802)
@@ -134,6 +134,12 @@
 
 #import <pal/cocoa/AVFoundationSoftLink.h>
 
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+// FIXME: This is only for binary compatibility with versions of UIKit in macOS 11 that are missing the change in <rdar://problem/68524148>.
+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebKit, UIKit, _UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor, void, (UIUserInterfaceIdiom idiom, CGFloat scaleFactor), (idiom, scaleFactor))
+#endif
+
 SOFT_LINK_FRAMEWORK(CoreServices)
 SOFT_LINK_CLASS(CoreServices, _LSDService)
 SOFT_LINK_CLASS(CoreServices, _LSDOpenService)
@@ -167,6 +173,13 @@
 
 void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
 {
+#if HAVE(CATALYST_USER_INTERFACE_IDIOM_AND_SCALE_FACTOR)
+    if (canLoad_UIKit__UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor()) {
+        auto [overrideUserInterfaceIdiom, overrideScaleFactor] = parameters.overrideUserInterfaceIdiomAndScale;
+        softLink_UIKit__UIApplicationCatalystRequestViewServiceIdiomAndScaleFactor(static_cast<UIUserInterfaceIdiom>(overrideUserInterfaceIdiom), overrideScaleFactor);
+    }
+#endif
+
     if (parameters.mobileGestaltExtensionHandle) {
         if (auto extension = SandboxExtension::create(WTFMove(*parameters.mobileGestaltExtensionHandle))) {
             bool ok = extension->consume();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to