Title: [272715] trunk
Revision
272715
Author
[email protected]
Date
2021-02-11 02:06:38 -0800 (Thu, 11 Feb 2021)

Log Message

Remove another use of FontSelector from within CSSFontFace
https://bugs.webkit.org/show_bug.cgi?id=221071

Reviewed by Darin Adler.

Source/WebCore:

Instead of CSSFontFace directly knowing about CSSFontSelector, we can just make CSSFontSelector
inherit from CSSFontFace::Client.

Also, clean up the callback methods a little bit.

Tests: fast/text/font-loading-multiple-documents.html
       fast/text/font-loading-multiple-sets.html

* css/CSSFontFace.cpp:
(WebCore::iterateClients):
(WebCore::CSSFontFace::CSSFontFace):
(WebCore::CSSFontFace::fontLoadEventOccurred):
(WebCore::CSSFontFace::updateStyleIfNeeded):
* css/CSSFontFace.h:
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::fontLoaded):
(WebCore::CSSFontSelector::fontStyleUpdateNeeded):
* css/CSSFontSelector.h:

LayoutTests:

* fast/text/font-loading-multiple-documents-expected.html: Added.
* fast/text/font-loading-multiple-documents.html: Added.
* fast/text/font-loading-multiple-sets-expected.txt: Added.
* fast/text/font-loading-multiple-sets.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (272714 => 272715)


--- trunk/LayoutTests/ChangeLog	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/LayoutTests/ChangeLog	2021-02-11 10:06:38 UTC (rev 272715)
@@ -1,3 +1,15 @@
+2021-02-11  Myles C. Maxfield  <[email protected]>
+
+        Remove another use of FontSelector from within CSSFontFace
+        https://bugs.webkit.org/show_bug.cgi?id=221071
+
+        Reviewed by Darin Adler.
+
+        * fast/text/font-loading-multiple-documents-expected.html: Added.
+        * fast/text/font-loading-multiple-documents.html: Added.
+        * fast/text/font-loading-multiple-sets-expected.txt: Added.
+        * fast/text/font-loading-multiple-sets.html: Added.
+
 2021-02-10  Rob Buis  <[email protected]>
 
         Use event loop to set title

Added: trunk/LayoutTests/fast/text/font-loading-multiple-documents-expected.html (0 => 272715)


--- trunk/LayoutTests/fast/text/font-loading-multiple-documents-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-loading-multiple-documents-expected.html	2021-02-11 10:06:38 UTC (rev 272715)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "WebFont";
+    src: url("../../resources/Ahem.ttf") format("truetype");
+}
+</style>
+</head>
+<body>
+<div style="font: 32px 'WebFont';">Hello</div>
+
+<iframe id="target" srcdoc="
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style='font: 32px WebFont;'>Hello</div>
+</body>
+</html>"></iframe>
+
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/font-loading-multiple-documents.html (0 => 272715)


--- trunk/LayoutTests/fast/text/font-loading-multiple-documents.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-loading-multiple-documents.html	2021-02-11 10:06:38 UTC (rev 272715)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font: 32px 'WebFont';">Hello</div>
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+</script>
+
+<iframe id="target" srcdoc="
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style='font: 32px WebFont;'>Hello</div>
+</body>
+</html>"></iframe>
+
+<script>
+var font = new FontFace("WebFont", "url('../../resources/Ahem.ttf') format('truetype')");
+document.fonts.add(font);
+document.getElementById("target").contentWindow.document.fonts.add(font);
+font.load().then(function() {
+    if (window.testRunner)
+        testRunner.notifyDone();
+});
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/font-loading-multiple-sets-expected.txt (0 => 272715)


--- trunk/LayoutTests/fast/text/font-loading-multiple-sets-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-loading-multiple-sets-expected.txt	2021-02-11 10:06:38 UTC (rev 272715)
@@ -0,0 +1,10 @@
+PASS font.status is "unloaded"
+PASS set1.status is "loaded"
+PASS set2.status is "loaded"
+PASS font.status is "loading"
+PASS set1.status is "loading"
+PASS set2.status is "loading"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/text/font-loading-multiple-sets.html (0 => 272715)


--- trunk/LayoutTests/fast/text/font-loading-multiple-sets.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/font-loading-multiple-sets.html	2021-02-11 10:06:38 UTC (rev 272715)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+if (window.internals) {
+    internals.clearMemoryCache();
+    internals.invalidateFontCache();
+}
+window.jsTestIsAsync = true;
+var font = new FontFace("WebFont", "url('../../resources/Ahem.ttf') format('truetype')");
+shouldBeEqualToString("font.status", "unloaded");
+var set1 = new FontFaceSet([font]);
+var set2 = new FontFaceSet([font]);
+shouldBeEqualToString("set1.status", "loaded");
+shouldBeEqualToString("set2.status", "loaded");
+font.load();
+shouldBeEqualToString("font.status", "loading");
+shouldBeEqualToString("set1.status", "loading");
+shouldBeEqualToString("set2.status", "loading");
+var count = 0;
+set1.ready.then(function() {
+    ++count;
+    if (count == 2)
+        finishJSTest();
+}, function() {
+    testFailed("Promise should not be rejected.");
+    finishJSTest();
+});
+set1.ready.then(function() {
+    ++count;
+    if (count == 2)
+        finishJSTest();
+}, function() {
+    testFailed("Promise should not be rejected.");
+    finishJSTest();
+});
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (272714 => 272715)


--- trunk/Source/WebCore/ChangeLog	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/Source/WebCore/ChangeLog	2021-02-11 10:06:38 UTC (rev 272715)
@@ -1,3 +1,29 @@
+2021-02-11  Myles C. Maxfield  <[email protected]>
+
+        Remove another use of FontSelector from within CSSFontFace
+        https://bugs.webkit.org/show_bug.cgi?id=221071
+
+        Reviewed by Darin Adler.
+
+        Instead of CSSFontFace directly knowing about CSSFontSelector, we can just make CSSFontSelector
+        inherit from CSSFontFace::Client.
+
+        Also, clean up the callback methods a little bit.
+
+        Tests: fast/text/font-loading-multiple-documents.html
+               fast/text/font-loading-multiple-sets.html
+
+        * css/CSSFontFace.cpp:
+        (WebCore::iterateClients):
+        (WebCore::CSSFontFace::CSSFontFace):
+        (WebCore::CSSFontFace::fontLoadEventOccurred):
+        (WebCore::CSSFontFace::updateStyleIfNeeded):
+        * css/CSSFontFace.h:
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::fontLoaded):
+        (WebCore::CSSFontSelector::fontStyleUpdateNeeded):
+        * css/CSSFontSelector.h:
+
 2021-02-11  Ziran Sun  <[email protected]>
 
         the nested grid container which has replaced item with 'max-height' has wrong width(0px).

Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (272714 => 272715)


--- trunk/Source/WebCore/css/CSSFontFace.cpp	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp	2021-02-11 10:06:38 UTC (rev 272715)
@@ -58,8 +58,8 @@
     for (auto* client : clients)
         clientsCopy.uncheckedAppend(*client);
 
-    for (auto* client : clients)
-        callback(*client);
+    for (auto& client : clientsCopy)
+        callback(client);
 }
 
 void CSSFontFace::appendSources(CSSFontFace& fontFace, CSSValueList& srcList, Document* document, bool isInitiatingElementInUserAgentShadowTree)
@@ -93,6 +93,8 @@
     : CSSFontFace(fontSelector && fontSelector->document() ? &fontSelector->document()->settings() : nullptr, cssConnection, wrapper, isLocalFallback)
 {
     m_fontSelector = makeWeakPtr(fontSelector); // FIXME: Ideally this data member would go away (https://bugs.webkit.org/show_bug.cgi?id=208351).
+    if (fontSelector)
+        addClient(*fontSelector);
 }
 
 CSSFontFace::CSSFontFace(const Settings* settings, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
@@ -352,9 +354,6 @@
     if (m_sourcesPopulated)
         pump(ExternalResourceDownloadPolicy::Forbid);
 
-    if (m_fontSelector)
-        m_fontSelector->fontLoaded();
-
     iterateClients(m_clients, [&](Client& client) {
         client.fontLoaded(*this);
     });
@@ -682,8 +681,9 @@
 
 void CSSFontFace::updateStyleIfNeeded()
 {
-    if (m_fontSelector && m_fontSelector->document())
-        m_fontSelector->document()->updateStyleIfNeeded();
+    iterateClients(m_clients, [&](Client& client) {
+        client.fontStyleUpdateNeeded(*this);
+    });
 }
 
 bool CSSFontFace::hasSVGFontFaceSource() const

Modified: trunk/Source/WebCore/css/CSSFontFace.h (272714 => 272715)


--- trunk/Source/WebCore/css/CSSFontFace.h	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/Source/WebCore/css/CSSFontFace.h	2021-02-11 10:06:38 UTC (rev 272715)
@@ -130,6 +130,7 @@
         virtual void fontLoaded(CSSFontFace&) { }
         virtual void fontStateChanged(CSSFontFace&, Status /*oldState*/, Status /*newState*/) { }
         virtual void fontPropertyChanged(CSSFontFace&, CSSValueList* /*oldFamilies*/ = nullptr) { }
+        virtual void fontStyleUpdateNeeded(CSSFontFace&) { }
         virtual void ref() = 0;
         virtual void deref() = 0;
     };

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (272714 => 272715)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-02-11 10:06:38 UTC (rev 272715)
@@ -248,7 +248,7 @@
         face->opportunisticallyStartFontDataURLLoading(*this);
 }
 
-void CSSFontSelector::fontLoaded()
+void CSSFontSelector::fontLoaded(CSSFontFace&)
 {
     dispatchInvalidationCallbacks();
 }
@@ -259,6 +259,12 @@
         dispatchInvalidationCallbacks();
 }
 
+void CSSFontSelector::fontStyleUpdateNeeded(CSSFontFace&)
+{
+    if (document())
+        document()->updateStyleIfNeeded();
+}
+
 void CSSFontSelector::fontCacheInvalidated()
 {
     dispatchInvalidationCallbacks();

Modified: trunk/Source/WebCore/css/CSSFontSelector.h (272714 => 272715)


--- trunk/Source/WebCore/css/CSSFontSelector.h	2021-02-11 09:31:51 UTC (rev 272714)
+++ trunk/Source/WebCore/css/CSSFontSelector.h	2021-02-11 10:06:38 UTC (rev 272715)
@@ -48,7 +48,7 @@
 class Document;
 class StyleRuleFontFace;
 
-class CSSFontSelector final : public FontSelector, public CanMakeWeakPtr<CSSFontSelector>, public ActiveDOMObject {
+class CSSFontSelector final : public FontSelector, public CSSFontFace::Client, public CanMakeWeakPtr<CSSFontSelector>, public ActiveDOMObject {
 public:
     static Ref<CSSFontSelector> create(Document& document)
     {
@@ -70,7 +70,6 @@
 
     void addFontFaceRule(StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
 
-    void fontLoaded();
     void fontCacheInvalidated() final;
 
     bool isEmpty() const;
@@ -91,6 +90,10 @@
 
     void loadPendingFonts();
 
+    // CSSFontFace::Client needs to be able to be held in a RefPtr.
+    void ref() final { FontSelector::ref(); }
+    void deref() final { FontSelector::deref(); }
+
 private:
     explicit CSSFontSelector(Document&);
 
@@ -98,8 +101,11 @@
 
     void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) final;
 
+    // CSSFontFace::Client
+    void fontLoaded(CSSFontFace&) final;
+    void fontStyleUpdateNeeded(CSSFontFace&) final;
+
     void fontModified();
-
     void fontLoadingTimerFired();
 
     // ActiveDOMObject
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to