- Revision
- 292072
- Author
- [email protected]
- Date
- 2022-03-29 14:49:38 -0700 (Tue, 29 Mar 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_attachmentElementClient):
* platform/graphics/FontCache.cpp:
(WebCore::Function<void):
(WebCore::FontCache::registerFontCacheInvalidationCallback):
(WebCore::FontCache::invalidateAllFontCaches):
* platform/graphics/FontCache.h:
LayoutTests:
* fast/text/install-font-style-recalc-expected.txt: Added.
* fast/text/install-font-style-recalc.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (292071 => 292072)
--- trunk/LayoutTests/ChangeLog 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/LayoutTests/ChangeLog 2022-03-29 21:49:38 UTC (rev 292072)
@@ -1,3 +1,14 @@
+2022-03-29 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.
+
+ * fast/text/install-font-style-recalc-expected.txt: Added.
+ * fast/text/install-font-style-recalc.html: Added.
+
2022-03-29 Arcady Goldmints-Orlov <[email protected]>
[GLIB] Update test expectations and baselines. Unreviewed test gardening.
Modified: trunk/LayoutTests/TestExpectations (292071 => 292072)
--- trunk/LayoutTests/TestExpectations 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/LayoutTests/TestExpectations 2022-03-29 21:49:38 UTC (rev 292072)
@@ -5208,3 +5208,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 => 292072)
--- trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/text/install-font-style-recalc-expected.txt 2022-03-29 21:49:38 UTC (rev 292072)
@@ -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 => 292072)
--- trunk/LayoutTests/fast/text/install-font-style-recalc.html (rev 0)
+++ trunk/LayoutTests/fast/text/install-font-style-recalc.html 2022-03-29 21:49:38 UTC (rev 292072)
@@ -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/TestExpectations (292071 => 292072)
--- trunk/LayoutTests/platform/ios/TestExpectations 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2022-03-29 21:49:38 UTC (rev 292072)
@@ -3567,3 +3567,5 @@
# iOS has a WebGPU implementation.
http/tests/webgpu [ Pass ]
+
+fast/text/install-font-style-recalc.html [ Pass ]
Modified: trunk/LayoutTests/platform/mac/TestExpectations (292071 => 292072)
--- trunk/LayoutTests/platform/mac/TestExpectations 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/LayoutTests/platform/mac/TestExpectations 2022-03-29 21:49:38 UTC (rev 292072)
@@ -2415,3 +2415,5 @@
# macOS has a WebGPU implementation.
http/tests/webgpu [ Pass ]
+
+fast/text/install-font-style-recalc.html [ Pass ]
Modified: trunk/Source/WebCore/ChangeLog (292071 => 292072)
--- trunk/Source/WebCore/ChangeLog 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/Source/WebCore/ChangeLog 2022-03-29 21:49:38 UTC (rev 292072)
@@ -1,3 +1,28 @@
+2022-03-29 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_attachmentElementClient):
+ * platform/graphics/FontCache.cpp:
+ (WebCore::Function<void):
+ (WebCore::FontCache::registerFontCacheInvalidationCallback):
+ (WebCore::FontCache::invalidateAllFontCaches):
+ * platform/graphics/FontCache.h:
+
2022-03-29 Alex Christensen <[email protected]>
Navigation Timing data is corrupt in WebView (UIWebView/WKWebView)
Modified: trunk/Source/WebCore/page/Page.cpp (292071 => 292072)
--- trunk/Source/WebCore/page/Page.cpp 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/Source/WebCore/page/Page.cpp 2022-03-29 21:49:38 UTC (rev 292072)
@@ -388,6 +388,16 @@
if (m_lowPowerModeNotifier->isLowPowerModeEnabled())
m_throttlingReasons.add(ThrottlingReason::LowPowerMode);
+
+ static bool fontCacheInvalidationCallbackRegistered = false;
+ if (!fontCacheInvalidationCallbackRegistered) {
+ FontCache::registerFontCacheInvalidationCallback([] {
+ forEachPage([](auto& page) {
+ page.setNeedsRecalcStyleInAllFrames();
+ });
+ });
+ fontCacheInvalidationCallbackRegistered = true;
+ }
}
Page::~Page()
Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (292071 => 292072)
--- trunk/Source/WebCore/platform/graphics/FontCache.cpp 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp 2022-03-29 21:49:38 UTC (rev 292072)
@@ -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 (292071 => 292072)
--- trunk/Source/WebCore/platform/graphics/FontCache.h 2022-03-29 21:37:31 UTC (rev 292071)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h 2022-03-29 21:49:38 UTC (rev 292072)
@@ -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();