Title: [292274] trunk
Revision
292274
Author
[email protected]
Date
2022-04-02 22:39:31 -0700 (Sat, 02 Apr 2022)

Log Message

[Cocoa] Automatically relayout the page when new fonts are installed
https://bugs.webkit.org/show_bug.cgi?id=238483
<rdar://problem/80544133>

Reviewed by Chris Dumez.

Source/WebCore:

This patch simply calls setNeedsRecalcStyleInAllFrames on every Page when we receive a
kCTFontManagerRegisteredFontsChangedNotification.

FontCache::invalidateAllFontCaches() can't do this directly because it's in platform/ and
therefore isn't allowed to know what Pages are. Instead, this patch takes a process-global
callback and calls that instead. This callback is set at initialization time.

Test: fast/text/install-font-style-recalc.html

* page/Page.cpp:
(WebCore::m_contentSecurityPolicyModeForExtension):
(WebCore::Page::firstTimeInitialization):
* page/Page.h:
* platform/graphics/FontCache.cpp:
(WebCore::Function<void):
(WebCore::FontCache::registerFontCacheInvalidationCallback):
(WebCore::FontCache::invalidateAllFontCaches):
* platform/graphics/FontCache.h:

Tools:

Make TestRunner::dumpResourceLoadStatistics() clear any currently-recorded statistics.
This avoids the problem where spurious layouts during the time when the page has been created but
before the test has begun record irrelevant statistics.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::beginTesting):
(WTR::InjectedBundle::clearResourceLoadStatistics):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::dumpResourceLoadStatistics):

LayoutTests:

* TestExpectations:
* fast/text/install-font-style-recalc-expected.txt: Added.
* fast/text/install-font-style-recalc.html: Added.
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (292273 => 292274)


--- trunk/LayoutTests/ChangeLog	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/LayoutTests/ChangeLog	2022-04-03 05:39:31 UTC (rev 292274)
@@ -1,3 +1,17 @@
+2022-04-02  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Automatically relayout the page when new fonts are installed
+        https://bugs.webkit.org/show_bug.cgi?id=238483
+        <rdar://problem/80544133>
+
+        Reviewed by Chris Dumez.
+
+        * TestExpectations:
+        * fast/text/install-font-style-recalc-expected.txt: Added.
+        * fast/text/install-font-style-recalc.html: Added.
+        * platform/ios-wk2/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+
 2022-04-02  Alan Bujtas  <[email protected]>
 
         [Ruby] Remove incorrect implicit integral floor in RenderRubyText::adjustInlineDirectionLineBounds

Modified: trunk/LayoutTests/TestExpectations (292273 => 292274)


--- trunk/LayoutTests/TestExpectations	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/LayoutTests/TestExpectations	2022-04-03 05:39:31 UTC (rev 292274)
@@ -5204,3 +5204,6 @@
 
 # Only certain ports have WebGPU implementations.
 http/tests/webgpu [ Failure ImageOnlyFailure Pass Timeout ]
+
+# Only some ports automatically relayout if a font is installed while the page is open
+fast/text/install-font-style-recalc.html [ Failure ]

Added: trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt (0 => 292274)


--- trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt	2022-04-03 05:39:31 UTC (rev 292274)
@@ -0,0 +1,11 @@
+This test makes sure that installing a font causes a style recalc. The test only runs in DumpRenderTree/WebKitTestRunner. It passes if the text above is rendered as black boxes (aka in Ahem).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS target.offsetWidth became 200
+PASS The font was used.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+rrrr
Property changes on: trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Author Date Id Rev URL \ No newline at end of property

Added: trunk/LayoutTests/fast/text/install-font-style-recalc.html (0 => 292274)


--- trunk/LayoutTests/fast/text/install-font-style-recalc.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/install-font-style-recalc.html	2022-04-03 05:39:31 UTC (rev 292274)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<span id="target" style="font: 50px 'Helvetica2';">rrrr</span>
+<script>
+description("This test makes sure that installing a font causes a style recalc. The test only runs in DumpRenderTree/WebKitTestRunner. It passes if the text above is rendered as black boxes (aka in Ahem).");
+window.jsTestIsAsync = true;
+let target = document.getElementById("target");
+target.offsetWidth; // Force a font lookup
+if (window.testRunner)
+    testRunner.installFakeHelvetica("Helvetica2-400");
+shouldBecomeEqual("target.offsetWidth", "200", function() {
+    testPassed("The font was used.");
+    finishJSTest();
+});
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (292273 => 292274)


--- trunk/LayoutTests/platform/ios-wk2/TestExpectations	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations	2022-04-03 05:39:31 UTC (rev 292274)
@@ -2252,3 +2252,5 @@
 webkit.org/b/237849 imported/w3c/web-platform-tests/css/filter-effects/filters-drop-shadow-003.html [ ImageOnlyFailure ]
 
 webkit.org/b/238634 media/video-object-fit.html [ ImageOnlyFailure ]
+
+fast/text/install-font-style-recalc.html [ Pass ]

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (292273 => 292274)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2022-04-03 05:39:31 UTC (rev 292274)
@@ -1702,4 +1702,4 @@
 
 webkit.org/b/233621 http/tests/webgpu [ Skip ]
 
-webkit.org/b/238641 fast/text/install-font-style-recalc.html [ Pass ]
\ No newline at end of file
+fast/text/install-font-style-recalc.html [ Pass ]

Modified: trunk/Source/WebCore/ChangeLog (292273 => 292274)


--- trunk/Source/WebCore/ChangeLog	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Source/WebCore/ChangeLog	2022-04-03 05:39:31 UTC (rev 292274)
@@ -1,3 +1,30 @@
+2022-04-02  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Automatically relayout the page when new fonts are installed
+        https://bugs.webkit.org/show_bug.cgi?id=238483
+        <rdar://problem/80544133>
+
+        Reviewed by Chris Dumez.
+
+        This patch simply calls setNeedsRecalcStyleInAllFrames on every Page when we receive a
+        kCTFontManagerRegisteredFontsChangedNotification.
+
+        FontCache::invalidateAllFontCaches() can't do this directly because it's in platform/ and
+        therefore isn't allowed to know what Pages are. Instead, this patch takes a process-global
+        callback and calls that instead. This callback is set at initialization time.
+
+        Test: fast/text/install-font-style-recalc.html
+
+        * page/Page.cpp:
+        (WebCore::m_contentSecurityPolicyModeForExtension):
+        (WebCore::Page::firstTimeInitialization):
+        * page/Page.h:
+        * platform/graphics/FontCache.cpp:
+        (WebCore::Function<void):
+        (WebCore::FontCache::registerFontCacheInvalidationCallback):
+        (WebCore::FontCache::invalidateAllFontCaches):
+        * platform/graphics/FontCache.h:
+
 2022-04-02  Simon Fraser  <[email protected]>
 
         Plumb the IOSurfacePool through to ImageBufferBackend creation via ImageBuffer::CreationContext

Modified: trunk/Source/WebCore/page/Page.cpp (292273 => 292274)


--- trunk/Source/WebCore/page/Page.cpp	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Source/WebCore/page/Page.cpp	2022-04-03 05:39:31 UTC (rev 292274)
@@ -356,10 +356,10 @@
     m_userContentProvider->addPage(*this);
     m_visitedLinkStore->addPage(*this);
 
-    static bool addedListener;
-    if (!addedListener) {
-        platformStrategies()->loaderStrategy()->addOnlineStateChangeListener(&networkStateChanged);
-        addedListener = true;
+    static bool firstTimeInitializationRan = false;
+    if (!firstTimeInitializationRan) {
+        firstTimeInitialization();
+        firstTimeInitializationRan = true;
     }
 
     ASSERT(!allPages().contains(this));
@@ -433,6 +433,17 @@
     m_visitedLinkStore->removePage(*this);
 }
 
+void Page::firstTimeInitialization()
+{
+    platformStrategies()->loaderStrategy()->addOnlineStateChangeListener(&networkStateChanged);
+
+    FontCache::registerFontCacheInvalidationCallback([] {
+        forEachPage([](auto& page) {
+            page.setNeedsRecalcStyleInAllFrames();
+        });
+    });
+}
+
 void Page::clearPreviousItemFromAllPages(HistoryItem* item)
 {
     for (auto* page : allPages()) {

Modified: trunk/Source/WebCore/page/Page.h (292273 => 292274)


--- trunk/Source/WebCore/page/Page.h	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Source/WebCore/page/Page.h	2022-04-03 05:39:31 UTC (rev 292274)
@@ -967,6 +967,8 @@
     };
     void logNavigation(const Navigation&);
 
+    static void firstTimeInitialization();
+
     WEBCORE_EXPORT void initGroup();
 
     void setIsInWindowInternal(bool);

Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (292273 => 292274)


--- trunk/Source/WebCore/platform/graphics/FontCache.cpp	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp	2022-04-03 05:39:31 UTC (rev 292274)
@@ -489,6 +489,17 @@
     purgeInactiveFontData();
 }
 
+static Function<void()>& fontCacheInvalidationCallback()
+{
+    static NeverDestroyed<Function<void()>> callback;
+    return callback.get();
+}
+
+void FontCache::registerFontCacheInvalidationCallback(Function<void()>&& callback)
+{
+    fontCacheInvalidationCallback() = WTFMove(callback);
+}
+
 void FontCache::invalidateAllFontCaches()
 {
     ASSERT(isMainThread());
@@ -495,6 +506,9 @@
 
     // FIXME: Invalidate FontCaches in workers too.
     FontCache::forCurrentThread().invalidate();
+
+    if (fontCacheInvalidationCallback())
+        fontCacheInvalidationCallback()();
 }
 
 #if !PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (292273 => 292274)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2022-04-03 05:39:31 UTC (rev 292274)
@@ -328,6 +328,7 @@
 
     unsigned short generation() const { return m_generation; }
     WEBCORE_EXPORT void invalidate();
+    static void registerFontCacheInvalidationCallback(Function<void()>&&);
     WEBCORE_EXPORT static void invalidateAllFontCaches();
 
     WEBCORE_EXPORT size_t fontCount();

Modified: trunk/Tools/ChangeLog (292273 => 292274)


--- trunk/Tools/ChangeLog	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Tools/ChangeLog	2022-04-03 05:39:31 UTC (rev 292274)
@@ -1,3 +1,22 @@
+2022-04-02  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Automatically relayout the page when new fonts are installed
+        https://bugs.webkit.org/show_bug.cgi?id=238483
+        <rdar://problem/80544133>
+
+        Reviewed by Chris Dumez.
+
+        Make TestRunner::dumpResourceLoadStatistics() clear any currently-recorded statistics.
+        This avoids the problem where spurious layouts during the time when the page has been created but
+        before the test has begun record irrelevant statistics.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::beginTesting):
+        (WTR::InjectedBundle::clearResourceLoadStatistics):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::dumpResourceLoadStatistics):
+
 2022-04-02  Andres Gonzalez  <[email protected]>
 
         Add to MiniBrowser the ability to log a textual representation of the AX trees for the current page.

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (292273 => 292274)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2022-04-03 05:39:31 UTC (rev 292274)
@@ -543,7 +543,7 @@
     WKBundleClearAllDatabases(m_bundle.get());
     WKBundlePageClearApplicationCache(page()->page());
     WKBundleResetOriginAccessAllowLists(m_bundle.get());
-    WKBundleClearResourceLoadStatistics(m_bundle.get());
+    clearResourceLoadStatistics();
 
     // [WK2] REGRESSION(r128623): It made layout tests extremely slow
     // https://bugs.webkit.org/show_bug.cgi?id=96862
@@ -576,6 +576,11 @@
     m_state = Idle;
 }
 
+void InjectedBundle::clearResourceLoadStatistics()
+{
+    WKBundleClearResourceLoadStatistics(m_bundle.get());
+}
+
 void InjectedBundle::dumpBackForwardListsForAllPages(StringBuilder& stringBuilder)
 {
     size_t size = m_pages.size();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (292273 => 292274)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2022-04-03 05:39:31 UTC (rev 292274)
@@ -150,6 +150,8 @@
     void increaseUserScriptInjectedCount() { ++m_userScriptInjectedCount; }
     size_t userScriptInjectedCount() const { return m_userScriptInjectedCount; }
 
+    void clearResourceLoadStatistics();
+
 private:
     InjectedBundle() = default;
     ~InjectedBundle();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (292273 => 292274)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-04-03 05:24:35 UTC (rev 292273)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2022-04-03 05:39:31 UTC (rev 292274)
@@ -1346,6 +1346,7 @@
     
 void TestRunner::dumpResourceLoadStatistics()
 {
+    InjectedBundle::singleton().clearResourceLoadStatistics();
     postSynchronousPageMessage("dumpResourceLoadStatistics");
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to