⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 292274 in webkit


Ignore:
Timestamp:
Apr 2, 2022, 10:39:31 PM (4 years ago)
Author:
mmaxfield@apple.com
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:
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r292270 r292274  
     12022-04-02  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Automatically relayout the page when new fonts are installed
     4        https://bugs.webkit.org/show_bug.cgi?id=238483
     5        <rdar://problem/80544133>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * TestExpectations:
     10        * fast/text/install-font-style-recalc-expected.txt: Added.
     11        * fast/text/install-font-style-recalc.html: Added.
     12        * platform/ios-wk2/TestExpectations:
     13        * platform/mac-wk2/TestExpectations:
     14
    1152022-04-02  Alan Bujtas  <zalan@apple.com>
    216
  • trunk/LayoutTests/TestExpectations

    r292270 r292274  
    52055205# Only certain ports have WebGPU implementations.
    52065206http/tests/webgpu [ Failure ImageOnlyFailure Pass Timeout ]
     5207
     5208# Only some ports automatically relayout if a font is installed while the page is open
     5209fast/text/install-font-style-recalc.html [ Failure ]
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r292250 r292274  
    22532253
    22542254webkit.org/b/238634 media/video-object-fit.html [ ImageOnlyFailure ]
     2255
     2256fast/text/install-font-style-recalc.html [ Pass ]
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r292246 r292274  
    17031703webkit.org/b/233621 http/tests/webgpu [ Skip ]
    17041704
    1705 webkit.org/b/238641 fast/text/install-font-style-recalc.html [ Pass ]
     1705fast/text/install-font-style-recalc.html [ Pass ]
  • trunk/Source/WebCore/ChangeLog

    r292273 r292274  
     12022-04-02  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Automatically relayout the page when new fonts are installed
     4        https://bugs.webkit.org/show_bug.cgi?id=238483
     5        <rdar://problem/80544133>
     6
     7        Reviewed by Chris Dumez.
     8
     9        This patch simply calls setNeedsRecalcStyleInAllFrames on every Page when we receive a
     10        kCTFontManagerRegisteredFontsChangedNotification.
     11
     12        FontCache::invalidateAllFontCaches() can't do this directly because it's in platform/ and
     13        therefore isn't allowed to know what Pages are. Instead, this patch takes a process-global
     14        callback and calls that instead. This callback is set at initialization time.
     15
     16        Test: fast/text/install-font-style-recalc.html
     17
     18        * page/Page.cpp:
     19        (WebCore::m_contentSecurityPolicyModeForExtension):
     20        (WebCore::Page::firstTimeInitialization):
     21        * page/Page.h:
     22        * platform/graphics/FontCache.cpp:
     23        (WebCore::Function<void):
     24        (WebCore::FontCache::registerFontCacheInvalidationCallback):
     25        (WebCore::FontCache::invalidateAllFontCaches):
     26        * platform/graphics/FontCache.h:
     27
    1282022-04-02  Simon Fraser  <simon.fraser@apple.com>
    229
  • trunk/Source/WebCore/page/Page.cpp

    r292264 r292274  
    357357    m_visitedLinkStore->addPage(*this);
    358358
    359     static bool addedListener;
    360     if (!addedListener) {
    361         platformStrategies()->loaderStrategy()->addOnlineStateChangeListener(&networkStateChanged);
    362         addedListener = true;
     359    static bool firstTimeInitializationRan = false;
     360    if (!firstTimeInitializationRan) {
     361        firstTimeInitialization();
     362        firstTimeInitializationRan = true;
    363363    }
    364364
     
    432432    m_userContentProvider->removePage(*this);
    433433    m_visitedLinkStore->removePage(*this);
     434}
     435
     436void Page::firstTimeInitialization()
     437{
     438    platformStrategies()->loaderStrategy()->addOnlineStateChangeListener(&networkStateChanged);
     439
     440    FontCache::registerFontCacheInvalidationCallback([] {
     441        forEachPage([](auto& page) {
     442            page.setNeedsRecalcStyleInAllFrames();
     443        });
     444    });
    434445}
    435446
  • trunk/Source/WebCore/page/Page.h

    r292264 r292274  
    968968    void logNavigation(const Navigation&);
    969969
     970    static void firstTimeInitialization();
     971
    970972    WEBCORE_EXPORT void initGroup();
    971973
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r292245 r292274  
    490490}
    491491
     492static Function<void()>& fontCacheInvalidationCallback()
     493{
     494    static NeverDestroyed<Function<void()>> callback;
     495    return callback.get();
     496}
     497
     498void FontCache::registerFontCacheInvalidationCallback(Function<void()>&& callback)
     499{
     500    fontCacheInvalidationCallback() = WTFMove(callback);
     501}
     502
    492503void FontCache::invalidateAllFontCaches()
    493504{
     
    496507    // FIXME: Invalidate FontCaches in workers too.
    497508    FontCache::forCurrentThread().invalidate();
     509
     510    if (fontCacheInvalidationCallback())
     511        fontCacheInvalidationCallback()();
    498512}
    499513
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r292245 r292274  
    329329    unsigned short generation() const { return m_generation; }
    330330    WEBCORE_EXPORT void invalidate();
     331    static void registerFontCacheInvalidationCallback(Function<void()>&&);
    331332    WEBCORE_EXPORT static void invalidateAllFontCaches();
    332333
  • trunk/Tools/ChangeLog

    r292271 r292274  
     12022-04-02  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Automatically relayout the page when new fonts are installed
     4        https://bugs.webkit.org/show_bug.cgi?id=238483
     5        <rdar://problem/80544133>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Make TestRunner::dumpResourceLoadStatistics() clear any currently-recorded statistics.
     10        This avoids the problem where spurious layouts during the time when the page has been created but
     11        before the test has begun record irrelevant statistics.
     12
     13        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     14        (WTR::InjectedBundle::beginTesting):
     15        (WTR::InjectedBundle::clearResourceLoadStatistics):
     16        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     17        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     18        (WTR::TestRunner::dumpResourceLoadStatistics):
     19
    1202022-04-02  Andres Gonzalez  <andresg_22@apple.com>
    221
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r292251 r292274  
    544544    WKBundlePageClearApplicationCache(page()->page());
    545545    WKBundleResetOriginAccessAllowLists(m_bundle.get());
    546     WKBundleClearResourceLoadStatistics(m_bundle.get());
     546    clearResourceLoadStatistics();
    547547
    548548    // [WK2] REGRESSION(r128623): It made layout tests extremely slow
     
    575575
    576576    m_state = Idle;
     577}
     578
     579void InjectedBundle::clearResourceLoadStatistics()
     580{
     581    WKBundleClearResourceLoadStatistics(m_bundle.get());
    577582}
    578583
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r292251 r292274  
    151151    size_t userScriptInjectedCount() const { return m_userScriptInjectedCount; }
    152152
     153    void clearResourceLoadStatistics();
     154
    153155private:
    154156    InjectedBundle() = default;
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r291737 r292274  
    13471347void TestRunner::dumpResourceLoadStatistics()
    13481348{
     1349    InjectedBundle::singleton().clearResourceLoadStatistics();
    13491350    postSynchronousPageMessage("dumpResourceLoadStatistics");
    13501351}
Note: See TracChangeset for help on using the changeset viewer.