Title: [273726] trunk/Source/WebCore
Revision
273726
Author
[email protected]
Date
2021-03-02 02:13:56 -0800 (Tue, 02 Mar 2021)

Log Message

Remove document accessor on CSSFontSelector
https://bugs.webkit.org/show_bug.cgi?id=222550

Reviewed by Darin Adler.

Replace FontSelector::document() with FontSelector::scriptExecutionContext().

No new tests because there is no behavior change.

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::appendSources):
(WebCore::CSSFontFace::create):
(WebCore::CSSFontFace::CSSFontFace):
* css/CSSFontFace.h:
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::scriptExecutionContext const):
(WebCore::CSSFontSelector::fontStyleUpdateNeeded):
* css/CSSFontSelector.h:
* css/FontFace.cpp:
(WebCore::FontFace::FontFace):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273725 => 273726)


--- trunk/Source/WebCore/ChangeLog	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/ChangeLog	2021-03-02 10:13:56 UTC (rev 273726)
@@ -1,3 +1,28 @@
+2021-03-02  Chris Lord  <[email protected]>
+
+        Remove document accessor on CSSFontSelector
+        https://bugs.webkit.org/show_bug.cgi?id=222550
+
+        Reviewed by Darin Adler.
+
+        Replace FontSelector::document() with FontSelector::scriptExecutionContext().
+
+        No new tests because there is no behavior change.
+
+        * css/CSSFontFace.cpp:
+        (WebCore::CSSFontFace::appendSources):
+        (WebCore::CSSFontFace::create):
+        (WebCore::CSSFontFace::CSSFontFace):
+        * css/CSSFontFace.h:
+        * css/CSSFontFaceSet.cpp:
+        (WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::scriptExecutionContext const):
+        (WebCore::CSSFontSelector::fontStyleUpdateNeeded):
+        * css/CSSFontSelector.h:
+        * css/FontFace.cpp:
+        (WebCore::FontFace::FontFace):
+
 2021-03-01  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Move simplified baseline alignment to a dedicated function

Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (273725 => 273726)


--- trunk/Source/WebCore/css/CSSFontFace.cpp	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp	2021-03-02 10:13:56 UTC (rev 273726)
@@ -62,7 +62,7 @@
         callback(client);
 }
 
-void CSSFontFace::appendSources(CSSFontFace& fontFace, CSSValueList& srcList, Document* document, bool isInitiatingElementInUserAgentShadowTree)
+void CSSFontFace::appendSources(CSSFontFace& fontFace, CSSValueList& srcList, ScriptExecutionContext* context, bool isInitiatingElementInUserAgentShadowTree)
 {
     for (auto& src : srcList) {
         // An item in the list either specifies a string (local font name) or a URL (remote font to download).
@@ -74,11 +74,12 @@
         foundSVGFont = item.isSVGFontFaceSrc() || item.svgFontFaceElement();
         fontFaceElement = item.svgFontFaceElement();
         if (!item.isLocal()) {
-            const Settings* settings = document ? &document->settings() : nullptr;
-            bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
-            if (allowDownloading && item.isSupportedFormat() && document) {
-                if (CachedFont* cachedFont = item.cachedFont(document, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
-                    source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), document->fontSelector(), *cachedFont);
+            const auto* settings = context ? &context->settingsValues() : nullptr;
+            bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled);
+            if (allowDownloading && item.isSupportedFormat() && is<Document>(context)) {
+                auto& document = downcast<Document>(*context);
+                if (CachedFont* cachedFont = item.cachedFont(&document, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
+                    source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), document.fontSelector(), *cachedFont);
             }
         } else
             source = (fontFaceElement ? makeUnique<CSSFontFaceSource>(fontFace, item.resource(), *fontFaceElement)
@@ -92,20 +93,22 @@
 
 Ref<CSSFontFace> CSSFontFace::create(CSSFontSelector* fontSelector, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
 {
-    auto result = adoptRef(*new CSSFontFace((fontSelector && fontSelector->document()) ? &fontSelector->document()->settings() : nullptr, cssConnection, wrapper, isLocalFallback));
+    auto* context = fontSelector ? fontSelector->scriptExecutionContext() : nullptr;
+    const auto* settings = context ? &context->settingsValues() : nullptr;
+    auto result = adoptRef(*new CSSFontFace(settings, cssConnection, wrapper, isLocalFallback));
     if (fontSelector)
         result->addClient(*fontSelector);
     return result;
 }
 
-CSSFontFace::CSSFontFace(const Settings* settings, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
+CSSFontFace::CSSFontFace(const Settings::Values* settings, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
     : m_cssConnection(cssConnection)
     , m_wrapper(makeWeakPtr(wrapper))
     , m_isLocalFallback(isLocalFallback)
     , m_mayBePurged(!wrapper)
-    , m_shouldIgnoreFontLoadCompletions(settings && settings->shouldIgnoreFontLoadCompletions())
-    , m_fontLoadTimingOverride(settings ? settings->fontLoadTimingOverride() : FontLoadTimingOverride::None)
-    , m_allowUserInstalledFonts(settings && !settings->shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::No : AllowUserInstalledFonts::Yes)
+    , m_shouldIgnoreFontLoadCompletions(settings && settings->shouldIgnoreFontLoadCompletions)
+    , m_fontLoadTimingOverride(settings ? settings->fontLoadTimingOverride : FontLoadTimingOverride::None)
+    , m_allowUserInstalledFonts(settings && !settings->shouldAllowUserInstalledFonts ? AllowUserInstalledFonts::No : AllowUserInstalledFonts::Yes)
     , m_timeoutTimer(*this, &CSSFontFace::timeoutFired)
 {
 }

Modified: trunk/Source/WebCore/css/CSSFontFace.h (273725 => 273726)


--- trunk/Source/WebCore/css/CSSFontFace.h	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/CSSFontFace.h	2021-03-02 10:13:56 UTC (rev 273726)
@@ -25,17 +25,14 @@
 
 #pragma once
 
-#include "FontLoadTimingOverride.h"
 #include "FontSelectionValueInlines.h"
 #include "FontTaggedSettings.h"
+#include "Settings.h"
 #include "StyleRule.h"
 #include "TextFlags.h"
-#include "Timer.h"
 #include <memory>
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
-#include <wtf/RefCounted.h>
-#include <wtf/Vector.h>
 #include <wtf/WeakPtr.h>
 
 namespace JSC {
@@ -49,7 +46,6 @@
 class CSSSegmentedFontFace;
 class CSSValue;
 class CSSValueList;
-class Document;
 class FontDescription;
 class Font;
 class FontFace;
@@ -120,7 +116,7 @@
 
     RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, ExternalResourceDownloadPolicy);
 
-    static void appendSources(CSSFontFace&, CSSValueList&, Document*, bool isInitiatingElementInUserAgentShadowTree);
+    static void appendSources(CSSFontFace&, CSSValueList&, ScriptExecutionContext*, bool isInitiatingElementInUserAgentShadowTree);
 
     class Client {
     public:
@@ -164,7 +160,7 @@
     void setErrorState();
 
 private:
-    CSSFontFace(const Settings*, StyleRuleFontFace*, FontFace*, bool isLocalFallback);
+    CSSFontFace(const Settings::Values*, StyleRuleFontFace*, FontFace*, bool isLocalFallback);
 
     size_t pump(ExternalResourceDownloadPolicy);
     void setStatus(Status);

Modified: trunk/Source/WebCore/css/CSSFontFaceSet.cpp (273725 => 273726)


--- trunk/Source/WebCore/css/CSSFontFaceSet.cpp	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/CSSFontFaceSet.cpp	2021-03-02 10:13:56 UTC (rev 273726)
@@ -108,8 +108,8 @@
         return;
 
     AllowUserInstalledFonts allowUserInstalledFonts = AllowUserInstalledFonts::Yes;
-    if (m_owningFontSelector->document())
-        allowUserInstalledFonts = m_owningFontSelector->document()->settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
+    if (m_owningFontSelector->scriptExecutionContext())
+        allowUserInstalledFonts = m_owningFontSelector->scriptExecutionContext()->settingsValues().shouldAllowUserInstalledFonts ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
     Vector<FontSelectionCapabilities> capabilities = FontCache::singleton().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
     if (capabilities.isEmpty())
         return;

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (273725 => 273726)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-02 10:13:56 UTC (rev 273726)
@@ -231,6 +231,14 @@
     m_clients.remove(&client);
 }
 
+ScriptExecutionContext* CSSFontSelector::scriptExecutionContext() const
+{
+    // This class returns a ScriptExecutionContext despite holding a Document as preparation for a future
+    // where it will actually hold a ScriptExecutionContext (which would be either a Document or a
+    // WorkerGlobalScope, in the case of using fonts in OffscreenCanvas).
+    return m_document.get();
+}
+
 void CSSFontSelector::dispatchInvalidationCallbacks()
 {
     ++m_version;
@@ -261,8 +269,8 @@
 
 void CSSFontSelector::fontStyleUpdateNeeded(CSSFontFace&)
 {
-    if (document())
-        document()->updateStyleIfNeeded();
+    if (m_document)
+        m_document->updateStyleIfNeeded();
 }
 
 void CSSFontSelector::fontCacheInvalidated()

Modified: trunk/Source/WebCore/css/CSSFontSelector.h (273725 => 273726)


--- trunk/Source/WebCore/css/CSSFontSelector.h	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/CSSFontSelector.h	2021-03-02 10:13:56 UTC (rev 273726)
@@ -77,7 +77,7 @@
     void registerForInvalidationCallbacks(FontSelectorClient&) final;
     void unregisterForInvalidationCallbacks(FontSelectorClient&) final;
 
-    Document* document() const { return m_document.get(); }
+    ScriptExecutionContext* scriptExecutionContext() const;
 
     void beginLoadingFontSoon(CachedFont&);
     void suspendFontLoadingTimer();

Modified: trunk/Source/WebCore/css/FontFace.cpp (273725 => 273726)


--- trunk/Source/WebCore/css/FontFace.cpp	2021-03-02 09:18:12 UTC (rev 273725)
+++ trunk/Source/WebCore/css/FontFace.cpp	2021-03-02 10:13:56 UTC (rev 273726)
@@ -148,7 +148,7 @@
 }
 
 FontFace::FontFace(CSSFontSelector& fontSelector)
-    : ActiveDOMObject(fontSelector.document())
+    : ActiveDOMObject(fontSelector.scriptExecutionContext())
     , m_backing(CSSFontFace::create(&fontSelector, nullptr, this))
     , m_loadedPromise(makeUniqueRef<LoadedPromise>(*this, &FontFace::loadedPromiseResolve))
 {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to