Title: [274143] trunk
Revision
274143
Author
cl...@igalia.com
Date
2021-03-09 04:05:27 -0800 (Tue, 09 Mar 2021)

Log Message

Allow creation of a CSSFontSelector with a non-Document ScriptExecutionContext
https://bugs.webkit.org/show_bug.cgi?id=222735

Reviewed by Darin Adler.

Replace Document member of CSSFontSelector with a ScriptExecutionContext.
This also changes make_names.pl string header generation to allow for easier enumeration of font family strings.

No new tests as new behaviour is currently unused. Existing behaviour covered by existing tests.

* bindings/scripts/StaticString.pm:
(GenerateStrings): Revert change from bug 222552
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::m_version):
(WebCore::CSSFontSelector::fontFaceSet):
(WebCore::CSSFontSelector::addFontFaceRule):
(WebCore::CSSFontSelector::fontStyleUpdateNeeded):
(WebCore::CSSFontSelector::resolveGenericFamily):
(WebCore::CSSFontSelector::fontRangesForFamily):
(WebCore::CSSFontSelector::stopLoadingAndClearFonts):
(WebCore::CSSFontSelector::beginLoadingFontSoon):
(WebCore::CSSFontSelector::loadPendingFonts):
(WebCore::CSSFontSelector::fontLoadingTimerFired):
(WebCore::CSSFontSelector::fallbackFontCount):
(WebCore::CSSFontSelector::fallbackFontAt):
* css/CSSFontSelector.h:
* css/FontFaceSet.cpp:
(WebCore::FontFaceSet::create):
(WebCore::FontFaceSet::FontFaceSet):
* css/FontFaceSet.h:
* css/FontFaceSet.idl:
* dom/Document.h:
* dom/ScriptExecutionContext.h:
* dom/make_names.pl:
(printNamesHeaderFile): Make global string data and names accessible via a Vector and add an enum of name indices.
* platform/graphics/FontGenericFamilies.cpp:
(WebCore:: const):
* platform/graphics/FontGenericFamilies.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274142 => 274143)


--- trunk/Source/WebCore/ChangeLog	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/ChangeLog	2021-03-09 12:05:27 UTC (rev 274143)
@@ -1,3 +1,45 @@
+2021-03-09  Chris Lord  <cl...@igalia.com>
+
+        Allow creation of a CSSFontSelector with a non-Document ScriptExecutionContext
+        https://bugs.webkit.org/show_bug.cgi?id=222735
+
+        Reviewed by Darin Adler.
+
+        Replace Document member of CSSFontSelector with a ScriptExecutionContext.
+        This also changes make_names.pl string header generation to allow for easier enumeration of font family strings.
+
+        No new tests as new behaviour is currently unused. Existing behaviour covered by existing tests.
+
+        * bindings/scripts/StaticString.pm:
+        (GenerateStrings): Revert change from bug 222552
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::CSSFontSelector):
+        (WebCore::m_version):
+        (WebCore::CSSFontSelector::fontFaceSet):
+        (WebCore::CSSFontSelector::addFontFaceRule):
+        (WebCore::CSSFontSelector::fontStyleUpdateNeeded):
+        (WebCore::CSSFontSelector::resolveGenericFamily):
+        (WebCore::CSSFontSelector::fontRangesForFamily):
+        (WebCore::CSSFontSelector::stopLoadingAndClearFonts):
+        (WebCore::CSSFontSelector::beginLoadingFontSoon):
+        (WebCore::CSSFontSelector::loadPendingFonts):
+        (WebCore::CSSFontSelector::fontLoadingTimerFired):
+        (WebCore::CSSFontSelector::fallbackFontCount):
+        (WebCore::CSSFontSelector::fallbackFontAt):
+        * css/CSSFontSelector.h:
+        * css/FontFaceSet.cpp:
+        (WebCore::FontFaceSet::create):
+        (WebCore::FontFaceSet::FontFaceSet):
+        * css/FontFaceSet.h:
+        * css/FontFaceSet.idl:
+        * dom/Document.h:
+        * dom/ScriptExecutionContext.h:
+        * dom/make_names.pl:
+        (printNamesHeaderFile): Make global string data and names accessible via a Vector and add an enum of name indices.
+        * platform/graphics/FontGenericFamilies.cpp:
+        (WebCore:: const):
+        * platform/graphics/FontGenericFamilies.h:
+
 2021-03-08  Antoine Quint  <grao...@webkit.org>
 
         Select CSS properties animating as float should not allow negative values

Modified: trunk/Source/WebCore/bindings/scripts/StaticString.pm (274142 => 274143)


--- trunk/Source/WebCore/bindings/scripts/StaticString.pm	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/bindings/scripts/StaticString.pm	2021-03-09 12:05:27 UTC (rev 274143)
@@ -43,7 +43,7 @@
 
     for my $name (sort keys %strings) {
         my $value = $strings{$name};
-        push(@result, "const StringImpl::StaticStringImpl ${name}Data(\"${value}\");\n");
+        push(@result, "static constexpr StringImpl::StaticStringImpl ${name}Data(\"${value}\");\n");
     }
 
     push(@result, <<END);

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (274142 => 274143)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-09 12:05:27 UTC (rev 274143)
@@ -59,11 +59,13 @@
 
 namespace WebCore {
 
+using namespace WebKitFontFamilyNames;
+
 static unsigned fontSelectorId;
 
-CSSFontSelector::CSSFontSelector(Document& document)
-    : ActiveDOMObject(document)
-    , m_document(makeWeakPtr(document))
+CSSFontSelector::CSSFontSelector(ScriptExecutionContext& context)
+    : ActiveDOMObject(&context)
+    , m_context(makeWeakPtr(context))
     , m_cssFontFaceSet(CSSFontFaceSet::create(this))
     , m_fontModifiedObserver([this] { fontModified(); })
     , m_fontLoadingTimer(*this, &CSSFontSelector::fontLoadingTimerFired)
@@ -70,7 +72,16 @@
     , m_uniqueId(++fontSelectorId)
     , m_version(0)
 {
-    ASSERT(m_document);
+    if (is<Document>(context)) {
+        m_fontFamilyNames.reserveInitialCapacity(familyNames->size());
+        for (auto& familyName : familyNames.get())
+            m_fontFamilyNames.uncheckedConstructAndAppend(familyName);
+    } else {
+        m_fontFamilyNames.reserveInitialCapacity(familyNamesData->size());
+        for (auto& familyName : familyNamesData.get())
+            m_fontFamilyNames.uncheckedAppend(familyName);
+    }
+
     FontCache::singleton().addClient(*this);
     m_cssFontFaceSet->addFontModifiedObserver(m_fontModifiedObserver);
     LOG(Fonts, "CSSFontSelector %p ctor", this);
@@ -94,8 +105,8 @@
 FontFaceSet& CSSFontSelector::fontFaceSet()
 {
     if (!m_fontFaceSet) {
-        ASSERT(m_document);
-        m_fontFaceSet = FontFaceSet::create(*m_document, m_cssFontFaceSet.get());
+        ASSERT(m_context);
+        m_fontFaceSet = FontFaceSet::create(*m_context, m_cssFontFaceSet.get());
     }
 
     return *m_fontFaceSet;
@@ -197,7 +208,7 @@
     if (loadingBehavior)
         fontFace->setLoadingBehavior(*loadingBehavior);
 
-    CSSFontFace::appendSources(fontFace, srcList, m_document.get(), isInitiatingElementInUserAgentShadowTree);
+    CSSFontFace::appendSources(fontFace, srcList, m_context.get(), isInitiatingElementInUserAgentShadowTree);
     if (fontFace->computeFailureState())
         return;
 
@@ -231,14 +242,6 @@
     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;
@@ -269,8 +272,8 @@
 
 void CSSFontSelector::fontStyleUpdateNeeded(CSSFontFace&)
 {
-    if (m_document)
-        m_document->updateStyleIfNeeded();
+    if (is<Document>(m_context.get()))
+        downcast<Document>(*m_context).updateStyleIfNeeded();
 }
 
 void CSSFontSelector::fontCacheInvalidated()
@@ -278,32 +281,23 @@
     dispatchInvalidationCallbacks();
 }
 
-static Optional<AtomString> resolveGenericFamily(Document* document, const FontDescription& fontDescription, const AtomString& familyName)
+Optional<AtomString> CSSFontSelector::resolveGenericFamily(const FontDescription& fontDescription, const AtomString& familyName)
 {
     auto platformResult = FontDescription::platformResolveGenericFamily(fontDescription.script(), fontDescription.computedLocale(), familyName);
     if (!platformResult.isNull())
         return platformResult;
 
-    if (!document)
+    if (!m_context)
         return WTF::nullopt;
 
-    const Settings& settings = document->settings();
+    const auto& settings = m_context->settingsValues();
 
     UScriptCode script = fontDescription.script();
-    if (familyName == serifFamily)
-        return AtomString(settings.serifFontFamily(script));
-    if (familyName == sansSerifFamily)
-        return AtomString(settings.sansSerifFontFamily(script));
-    if (familyName == cursiveFamily)
-        return AtomString(settings.cursiveFontFamily(script));
-    if (familyName == fantasyFamily)
-        return AtomString(settings.fantasyFontFamily(script));
-    if (familyName == monospaceFamily)
-        return AtomString(settings.fixedFontFamily(script));
-    if (familyName == pictographFamily)
-        return AtomString(settings.pictographFontFamily(script));
-    if (familyName == standardFamily)
-        return AtomString(settings.standardFontFamily(script));
+    auto familyNameIndex = m_fontFamilyNames.find(familyName);
+    if (familyNameIndex != notFound) {
+        if (auto familyString = settings.fontGenericFamilies.fontFamily(static_cast<FamilyNamesIndex>(familyNameIndex), script))
+            return AtomString(*familyString);
+    }
 
     return WTF::nullopt;
 }
@@ -314,34 +308,31 @@
     ASSERT(!m_buildIsUnderway || m_computingRootStyleFontCount);
 
     // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too.
-    bool resolveGenericFamilyFirst = familyName == standardFamily;
+    bool resolveGenericFamilyFirst = familyName == m_fontFamilyNames[static_cast<int>(FamilyNamesIndex::StandardFamily)];
 
     AtomString familyForLookup = familyName;
     Optional<FontDescription> overrideFontDescription;
     const FontDescription* fontDescriptionForLookup = &fontDescription;
-    auto resolveGenericFamily = [&]() {
-        if (auto genericFamilyOptional = WebCore::resolveGenericFamily(m_document.get(), fontDescription, familyName))
+    auto resolveAndAssignGenericFamily = [&]() {
+        if (auto genericFamilyOptional = resolveGenericFamily(fontDescription, familyName))
             familyForLookup = *genericFamilyOptional;
     };
 
     if (resolveGenericFamilyFirst)
-        resolveGenericFamily();
+        resolveAndAssignGenericFamily();
+    Document* document = is<Document>(m_context.get()) ? &downcast<Document>(*m_context) : nullptr;
     auto* face = m_cssFontFaceSet->fontFace(fontDescriptionForLookup->fontSelectionRequest(), familyForLookup);
     if (face) {
-        if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled()) {
-            if (m_document)
-                ResourceLoadObserver::shared().logFontLoad(*m_document, familyForLookup.string(), true);
-        }
+        if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
+            ResourceLoadObserver::shared().logFontLoad(*document, familyForLookup.string(), true);
         return face->fontRanges(*fontDescriptionForLookup);
     }
 
     if (!resolveGenericFamilyFirst)
-        resolveGenericFamily();
+        resolveAndAssignGenericFamily();
     auto font = FontCache::singleton().fontForFamily(*fontDescriptionForLookup, familyForLookup);
-    if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled()) {
-        if (m_document)
-            ResourceLoadObserver::shared().logFontLoad(*m_document, familyForLookup.string(), !!font);
-    }
+    if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
+        ResourceLoadObserver::shared().logFontLoad(*document, familyForLookup.string(), !!font);
     return FontRanges { WTFMove(font) };
 }
 
@@ -356,12 +347,15 @@
     m_isStopped = true;
     m_fontLoadingTimer.stop();
 
-    CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
-    for (auto& fontHandle : m_fontsToBeginLoading) {
-        // Balances incrementRequestCount() in beginLoadingFontSoon().
-        cachedResourceLoader.decrementRequestCount(*fontHandle);
+    if (is<Document>(m_context.get())) {
+        auto& document = downcast<Document>(*m_context);
+        CachedResourceLoader& cachedResourceLoader = document.cachedResourceLoader();
+        for (auto& fontHandle : m_fontsToBeginLoading) {
+            // Balances incrementRequestCount() in beginLoadingFontSoon().
+            cachedResourceLoader.decrementRequestCount(*fontHandle);
+        }
+        m_fontsToBeginLoading.clear();
     }
-    m_fontsToBeginLoading.clear();
 
     m_cssFontFaceSet->clear();
     m_clients.clear();
@@ -369,14 +363,16 @@
 
 void CSSFontSelector::beginLoadingFontSoon(CachedFont& font)
 {
-    if (m_isStopped)
+    if (m_isStopped || !is<Document>(m_context.get()))
         return;
 
+    auto& document = downcast<Document>(*m_context);
+
     m_fontsToBeginLoading.append(&font);
     // Increment the request count now, in order to prevent didFinishLoad from being dispatched
     // after this font has been requested but before it began loading. Balanced by
     // decrementRequestCount() in fontLoadingTimerFired() and in stopLoadingAndClearFonts().
-    m_document->cachedResourceLoader().incrementRequestCount(font);
+    document.cachedResourceLoader().incrementRequestCount(font);
 
     if (!m_isFontLoadingSuspended && !m_fontLoadingTimer.isActive())
         m_fontLoadingTimer.startOneShot(0_s);
@@ -389,9 +385,11 @@
 
 void CSSFontSelector::loadPendingFonts()
 {
-    if (m_isFontLoadingSuspended)
+    if (m_isFontLoadingSuspended || !is<Document>(m_context.get()))
         return;
 
+    auto& document = downcast<Document>(*m_context);
+
     Vector<CachedResourceHandle<CachedFont>> fontsToBeginLoading;
     fontsToBeginLoading.swap(m_fontsToBeginLoading);
 
@@ -398,7 +396,7 @@
     // CSSFontSelector could get deleted via beginLoadIfNeeded() or loadDone() unless protected.
     Ref<CSSFontSelector> protectedThis(*this);
 
-    CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = document.cachedResourceLoader();
     for (auto& fontHandle : fontsToBeginLoading) {
         fontHandle->beginLoadIfNeeded(cachedResourceLoader);
         // Balances incrementRequestCount() in beginLoadingFontSoon().
@@ -408,6 +406,10 @@
 
 void CSSFontSelector::fontLoadingTimerFired()
 {
+    if (!is<Document>(m_context.get()))
+        return;
+
+    auto& document = downcast<Document>(*m_context);
     Ref<CSSFontSelector> protectedThis(*this);
 
     loadPendingFonts();
@@ -414,12 +416,12 @@
 
     // FIXME: Use SubresourceLoader instead.
     // Call FrameLoader::loadDone before FrameLoader::subresourceLoadDone to match the order in SubresourceLoader::notifyDone.
-    m_document->cachedResourceLoader().loadDone(LoadCompletionType::Finish);
+    document.cachedResourceLoader().loadDone(LoadCompletionType::Finish);
     // Ensure that if the request count reaches zero, the frame loader will know about it.
     // New font loads may be triggered by layout after the document load is complete but before we have dispatched
     // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
-    if (m_document && m_document->frame())
-        m_document->frame()->loader().checkLoadComplete();
+    if (document.frame())
+        document.frame()->loader().checkLoadComplete();
 }
 
 size_t CSSFontSelector::fallbackFontCount()
@@ -427,7 +429,7 @@
     if (m_isStopped)
         return 0;
 
-    return m_document->settings().fontFallbackPrefersPictographs() ? 1 : 0;
+    return m_context->settingsValues().fontFallbackPrefersPictographs ? 1 : 0;
 }
 
 RefPtr<Font> CSSFontSelector::fallbackFontAt(const FontDescription& fontDescription, size_t index)
@@ -437,12 +439,12 @@
     if (m_isStopped)
         return nullptr;
 
-    if (!m_document->settings().fontFallbackPrefersPictographs())
+    if (!m_context->settingsValues().fontFallbackPrefersPictographs)
         return nullptr;
-    auto& pictographFontFamily = m_document->settings().pictographFontFamily();
+    auto& pictographFontFamily = m_context->settingsValues().fontGenericFamilies.pictographFontFamily();
     auto font = FontCache::singleton().fontForFamily(fontDescription, pictographFontFamily);
-    if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
-        ResourceLoadObserver::shared().logFontLoad(*m_document, pictographFontFamily, !!font);
+    if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled() && is<Document>(m_context.get()))
+        ResourceLoadObserver::shared().logFontLoad(downcast<Document>(*m_context), pictographFontFamily, !!font);
 
     return font;
 }

Modified: trunk/Source/WebCore/css/CSSFontSelector.h (274142 => 274143)


--- trunk/Source/WebCore/css/CSSFontSelector.h	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/css/CSSFontSelector.h	2021-03-09 12:05:27 UTC (rev 274143)
@@ -45,14 +45,14 @@
 class CSSSegmentedFontFace;
 class CSSValueList;
 class CachedFont;
-class Document;
+class ScriptExecutionContext;
 class StyleRuleFontFace;
 
 class CSSFontSelector final : public FontSelector, public CSSFontFace::Client, public CanMakeWeakPtr<CSSFontSelector>, public ActiveDOMObject {
 public:
-    static Ref<CSSFontSelector> create(Document& document)
+    static Ref<CSSFontSelector> create(ScriptExecutionContext& context)
     {
-        return adoptRef(*new CSSFontSelector(document));
+        return adoptRef(*new CSSFontSelector(context));
     }
     virtual ~CSSFontSelector();
     
@@ -77,7 +77,7 @@
     void registerForInvalidationCallbacks(FontSelectorClient&) final;
     void unregisterForInvalidationCallbacks(FontSelectorClient&) final;
 
-    ScriptExecutionContext* scriptExecutionContext() const;
+    ScriptExecutionContext* scriptExecutionContext() const { return m_context.get(); }
 
     void beginLoadingFontSoon(CachedFont&);
     void suspendFontLoadingTimer();
@@ -95,12 +95,14 @@
     void deref() final { FontSelector::deref(); }
 
 private:
-    explicit CSSFontSelector(Document&);
+    explicit CSSFontSelector(ScriptExecutionContext&);
 
     void dispatchInvalidationCallbacks();
 
     void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) final;
 
+    Optional<AtomString> resolveGenericFamily(const FontDescription&, const AtomString& family);
+
     // CSSFontFace::Client
     void fontLoaded(CSSFontFace&) final;
     void fontStyleUpdateNeeded(CSSFontFace&) final;
@@ -120,7 +122,7 @@
     };
     Vector<PendingFontFaceRule> m_stagingArea;
 
-    WeakPtr<Document> m_document;
+    WeakPtr<ScriptExecutionContext> m_context;
     RefPtr<FontFaceSet> m_fontFaceSet;
     Ref<CSSFontFaceSet> m_cssFontFaceSet;
     HashSet<FontSelectorClient*> m_clients;
@@ -140,6 +142,8 @@
     bool m_creatingFont { false };
     bool m_buildIsUnderway { false };
     bool m_isStopped { false };
+
+    WTF::Vector<AtomString> m_fontFamilyNames;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/FontFaceSet.cpp (274142 => 274143)


--- trunk/Source/WebCore/css/FontFaceSet.cpp	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/css/FontFaceSet.cpp	2021-03-09 12:05:27 UTC (rev 274143)
@@ -41,22 +41,22 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(FontFaceSet);
 
-Ref<FontFaceSet> FontFaceSet::create(Document& document, const Vector<RefPtr<FontFace>>& initialFaces)
+Ref<FontFaceSet> FontFaceSet::create(ScriptExecutionContext& context, const Vector<RefPtr<FontFace>>& initialFaces)
 {
-    Ref<FontFaceSet> result = adoptRef(*new FontFaceSet(document, initialFaces));
+    Ref<FontFaceSet> result = adoptRef(*new FontFaceSet(context, initialFaces));
     result->suspendIfNeeded();
     return result;
 }
 
-Ref<FontFaceSet> FontFaceSet::create(Document& document, CSSFontFaceSet& backing)
+Ref<FontFaceSet> FontFaceSet::create(ScriptExecutionContext& context, CSSFontFaceSet& backing)
 {
-    Ref<FontFaceSet> result = adoptRef(*new FontFaceSet(document, backing));
+    Ref<FontFaceSet> result = adoptRef(*new FontFaceSet(context, backing));
     result->suspendIfNeeded();
     return result;
 }
 
-FontFaceSet::FontFaceSet(Document& document, const Vector<RefPtr<FontFace>>& initialFaces)
-    : ActiveDOMObject(document)
+FontFaceSet::FontFaceSet(ScriptExecutionContext& context, const Vector<RefPtr<FontFace>>& initialFaces)
+    : ActiveDOMObject(&context)
     , m_backing(CSSFontFaceSet::create())
     , m_readyPromise(makeUniqueRef<ReadyPromise>(*this, &FontFaceSet::readyPromiseResolve))
 {
@@ -65,13 +65,16 @@
         add(*face);
 }
 
-FontFaceSet::FontFaceSet(Document& document, CSSFontFaceSet& backing)
-    : ActiveDOMObject(document)
+FontFaceSet::FontFaceSet(ScriptExecutionContext& context, CSSFontFaceSet& backing)
+    : ActiveDOMObject(&context)
     , m_backing(backing)
     , m_readyPromise(makeUniqueRef<ReadyPromise>(*this, &FontFaceSet::readyPromiseResolve))
 {
-    if (document.frame())
-        m_isDocumentLoaded = document.loadEventFinished() && !document.processingLoadEvent();
+    if (is<Document>(context)) {
+        auto& document = downcast<Document>(context);
+        if (document.frame())
+            m_isDocumentLoaded = document.loadEventFinished() && !document.processingLoadEvent();
+    }
 
     if (m_isDocumentLoaded && !backing.hasActiveFontFaces())
         m_readyPromise->resolve(*this);

Modified: trunk/Source/WebCore/css/FontFaceSet.h (274142 => 274143)


--- trunk/Source/WebCore/css/FontFaceSet.h	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/css/FontFaceSet.h	2021-03-09 12:05:27 UTC (rev 274143)
@@ -41,8 +41,8 @@
 class FontFaceSet final : public RefCounted<FontFaceSet>, private CSSFontFaceSet::FontEventClient, public EventTargetWithInlineData, public ActiveDOMObject {
     WTF_MAKE_ISO_ALLOCATED(FontFaceSet);
 public:
-    static Ref<FontFaceSet> create(Document&, const Vector<RefPtr<FontFace>>& initialFaces);
-    static Ref<FontFaceSet> create(Document&, CSSFontFaceSet& backing);
+    static Ref<FontFaceSet> create(ScriptExecutionContext&, const Vector<RefPtr<FontFace>>& initialFaces);
+    static Ref<FontFaceSet> create(ScriptExecutionContext&, CSSFontFaceSet& backing);
     virtual ~FontFaceSet();
 
     bool has(FontFace&) const;
@@ -95,8 +95,8 @@
         bool hasReachedTerminalState { false };
     };
 
-    FontFaceSet(Document&, const Vector<RefPtr<FontFace>>&);
-    FontFaceSet(Document&, CSSFontFaceSet&);
+    FontFaceSet(ScriptExecutionContext&, const Vector<RefPtr<FontFace>>&);
+    FontFaceSet(ScriptExecutionContext&, CSSFontFaceSet&);
 
     // CSSFontFaceSet::FontEventClient
     void faceFinished(CSSFontFace&, CSSFontFace::Status) final;

Modified: trunk/Source/WebCore/css/FontFaceSet.idl (274142 => 274143)


--- trunk/Source/WebCore/css/FontFaceSet.idl	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/css/FontFaceSet.idl	2021-03-09 12:05:27 UTC (rev 274143)
@@ -32,7 +32,7 @@
     ActiveDOMObject,
     Exposed=Window
 ] interface FontFaceSet : EventTarget {
-    [CallWith=Document] constructor(sequence<FontFace> initialFaces);
+    [CallWith=ScriptExecutionContext] constructor(sequence<FontFace> initialFaces);
 
     boolean has(FontFace font);
 

Modified: trunk/Source/WebCore/dom/Document.h (274142 => 274143)


--- trunk/Source/WebCore/dom/Document.h	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/dom/Document.h	2021-03-09 12:05:27 UTC (rev 274143)
@@ -347,6 +347,9 @@
     , public CanvasObserver {
     WTF_MAKE_ISO_ALLOCATED_EXPORT(Document, WEBCORE_EXPORT);
 public:
+    using WeakValueType = EventTarget::WeakValueType;
+    using EventTarget::weakPtrFactory;
+
     static Ref<Document> create(const Settings&, const URL&);
     static Ref<Document> createNonRenderedPlaceholder(Frame&, const URL&);
     static Ref<Document> create(Document&);

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (274142 => 274143)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2021-03-09 12:05:27 UTC (rev 274143)
@@ -38,6 +38,7 @@
 #include <wtf/Function.h>
 #include <wtf/HashSet.h>
 #include <wtf/ObjectIdentifier.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace JSC {
@@ -82,7 +83,7 @@
 enum ScriptExecutionContextIdentifierType { };
 using ScriptExecutionContextIdentifier = ObjectIdentifier<ScriptExecutionContextIdentifierType>;
 
-class ScriptExecutionContext : public SecurityContext {
+class ScriptExecutionContext : public SecurityContext, public CanMakeWeakPtr<ScriptExecutionContext> {
 public:
     ScriptExecutionContext();
     virtual ~ScriptExecutionContext();

Modified: trunk/Source/WebCore/dom/make_names.pl (274142 => 274143)


--- trunk/Source/WebCore/dom/make_names.pl	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/dom/make_names.pl	2021-03-09 12:05:27 UTC (rev 274143)
@@ -100,12 +100,19 @@
     printLicenseHeader($F);
     printHeaderHead($F, "CSS", $familyNamesFileBase, <<END, "");
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Vector.h>
 #include <wtf/text/AtomString.h>
 END
 
-    printMacros($F, "extern const StringImpl::StaticStringImpl", "Data", \%parameters);
+    print F "extern LazyNeverDestroyed<Vector<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
+    print F "extern MainThreadLazyNeverDestroyed<Vector<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
+    printMacros($F, "extern MainThreadLazyNeverDestroyed<const AtomString>", "", \%parameters);
     print F "\n";
-    printMacros($F, "extern MainThreadLazyNeverDestroyed<const WTF::AtomString>", "", \%parameters);
+    print F "enum class FamilyNamesIndex {\n";
+    for my $name (sort keys %parameters) {
+        print F "    ", ucfirst(${name}), ",\n";
+    }
+    print F "};\n\n";
     print F "#endif\n\n";
 
     printInit($F, 1);
@@ -119,17 +126,32 @@
 
     print F StaticString::GenerateStrings(\%parameters);
 
-    printMacros($F, "MainThreadLazyNeverDestroyed<const WTF::AtomString>", "", \%parameters);
+    print F "LazyNeverDestroyed<Vector<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
+    print F "MainThreadLazyNeverDestroyed<Vector<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
 
+    printMacros($F, "MainThreadLazyNeverDestroyed<const AtomString>", "", \%parameters);
+
     printInit($F, 0);
 
     print F "\n";
     print F StaticString::GenerateStringAsserts(\%parameters);
 
+    print F "    familyNamesData.construct();\n";
     for my $name (sort keys %parameters) {
+        print F "    familyNamesData->uncheckedAppend(&${name}Data);\n";
+    }
+
+    print F "\n";
+    for my $name (sort keys %parameters) {
         print F "    ${name}.construct(&${name}Data);\n";
     }
 
+    print F "\n";
+    print F "    familyNames.construct();\n";
+    for my $name (sort keys %parameters) {
+        print F "    familyNames->uncheckedAppend(${name}->impl());\n";
+    }
+
     print F "}\n}\n}\n";
     close F;
     exit 0;
@@ -694,7 +716,7 @@
     my $lowercaseNamespacePrefix = lc($parameters{namespacePrefix});
 
     print F "// Namespace\n";
-    print F "WEBCORE_EXPORT extern MainThreadLazyNeverDestroyed<const WTF::AtomString> ${lowercaseNamespacePrefix}NamespaceURI;\n\n";
+    print F "WEBCORE_EXPORT extern MainThreadLazyNeverDestroyed<const AtomString> ${lowercaseNamespacePrefix}NamespaceURI;\n\n";
 
     if (keys %allTags) {
         print F "// Tags\n";

Modified: trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp (274142 => 274143)


--- trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/platform/graphics/FontGenericFamilies.cpp	2021-03-09 12:05:27 UTC (rev 274143)
@@ -30,6 +30,8 @@
 
 namespace WebCore {
 
+using namespace WebKitFontFamilyNames;
+
 static bool setGenericFontFamilyForScript(ScriptFontFamilyMap& fontMap, const String& family, UScriptCode script)
 {
     if (family.isEmpty())
@@ -180,4 +182,29 @@
     return setGenericFontFamilyForScript(m_pictographFontFamilyMap, family, script);
 }
 
+const String* FontGenericFamilies::fontFamily(FamilyNamesIndex family, UScriptCode script) const
+{
+    switch (family) {
+    case FamilyNamesIndex::CursiveFamily:
+        return &cursiveFontFamily(script);
+    case FamilyNamesIndex::FantasyFamily:
+        return &fantasyFontFamily(script);
+    case FamilyNamesIndex::MonospaceFamily:
+        return &fixedFontFamily(script);
+    case FamilyNamesIndex::PictographFamily:
+        return &pictographFontFamily(script);
+    case FamilyNamesIndex::SansSerifFamily:
+        return &sansSerifFontFamily(script);
+    case FamilyNamesIndex::SerifFamily:
+        return &serifFontFamily(script);
+    case FamilyNamesIndex::StandardFamily:
+        return &standardFontFamily(script);
+    case FamilyNamesIndex::SystemUiFamily:
+        return nullptr;
+    }
+
+    ASSERT_NOT_REACHED();
+    return nullptr;
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/FontGenericFamilies.h (274142 => 274143)


--- trunk/Source/WebCore/platform/graphics/FontGenericFamilies.h	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Source/WebCore/platform/graphics/FontGenericFamilies.h	2021-03-09 12:05:27 UTC (rev 274143)
@@ -23,9 +23,9 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef FontGenericFamilies_h
-#define FontGenericFamilies_h
+#pragma once
 
+#include "WebKitFontFamilyNames.h"
 #include <unicode/uscript.h>
 #include <wtf/HashMap.h>
 #include <wtf/text/AtomString.h>
@@ -59,6 +59,8 @@
     const String& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const;
     const String& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const;
 
+    const String* fontFamily(WebKitFontFamilyNames::FamilyNamesIndex, UScriptCode = USCRIPT_COMMON) const;
+
     bool setStandardFontFamily(const String&, UScriptCode);
     bool setFixedFontFamily(const String&, UScriptCode);
     bool setSerifFontFamily(const String&, UScriptCode);
@@ -78,5 +80,3 @@
 };
 
 }
-
-#endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp (274142 => 274143)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp	2021-03-09 11:20:22 UTC (rev 274142)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp	2021-03-09 12:05:27 UTC (rev 274143)
@@ -35,6 +35,7 @@
 #include <WebCore/ShadowRoot.h>
 #include <WebCore/SimpleRange.h>
 #include <WebCore/TextControlInnerElements.h>
+#include <WebCore/WebKitFontFamilyNames.h>
 
 // FIXME: Expose the functions tested here in WebKit internals object, then replace this test with one written in _javascript_.
 // FIXME: When doing the above, don't forget to remove the many WEBCORE_EXPORT that were added so we could compile and link this test.
@@ -51,6 +52,7 @@
 static Ref<Document> createDocument()
 {
     HTMLNames::init();
+    WebKitFontFamilyNames::init();
     auto settings = Settings::create(nullptr);
     auto document = Document::create(settings.get(), aboutBlankURL());
     auto documentElement = HTMLHtmlElement::create(document);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to