Document should be a FontSelectorClient.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jan 2015 21:39:28 +0000 (21:39 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jan 2015 21:39:28 +0000 (21:39 +0000)
<https://webkit.org/b/140833>

Reviewed by Antti Koivisto.

Make Document a FontSelectorClient so it can listen to the invalidation
callbacks from FontSelector instead of having code in FontSelector that
calls out to Document on invalidation.

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::dispatchInvalidationCallbacks):
* dom/Document.cpp:
(WebCore::Document::fontsNeedUpdate):
(WebCore::Document::fontSelector):
(WebCore::Document::clearStyleResolver):
* dom/Document.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179025 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h

index c0eaafd..7c0825a 100644 (file)
@@ -1,3 +1,22 @@
+2015-01-23  Andreas Kling  <akling@apple.com>
+
+        Document should be a FontSelectorClient.
+        <https://webkit.org/b/140833>
+
+        Reviewed by Antti Koivisto.
+
+        Make Document a FontSelectorClient so it can listen to the invalidation
+        callbacks from FontSelector instead of having code in FontSelector that
+        calls out to Document on invalidation.
+
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::dispatchInvalidationCallbacks):
+        * dom/Document.cpp:
+        (WebCore::Document::fontsNeedUpdate):
+        (WebCore::Document::fontSelector):
+        (WebCore::Document::clearStyleResolver):
+        * dom/Document.h:
+
 2015-01-23  Chris Dumez  <cdumez@apple.com>
 
         Leverage CSSValuePool's font family cache in CSSComputedStyleDeclaration
index d21b8a1..638c1c9 100644 (file)
@@ -338,15 +338,6 @@ void CSSFontSelector::dispatchInvalidationCallbacks()
     copyToVector(m_clients, clients);
     for (size_t i = 0; i < clients.size(); ++i)
         clients[i]->fontsNeedUpdate(this);
-
-    // FIXME: Make Document a FontSelectorClient so that it can simply register for invalidation callbacks.
-    if (!m_document)
-        return;
-    if (StyleResolver* styleResolver = m_document->styleResolverIfExists())
-        styleResolver->invalidateMatchedPropertiesCache();
-    if (m_document->inPageCache() || !m_document->renderView())
-        return;
-    m_document->scheduleForcedStyleRecalc();
 }
 
 void CSSFontSelector::fontLoaded()
index 649a260..aa71226 100644 (file)
@@ -1942,10 +1942,21 @@ void Document::createStyleResolver()
     m_styleSheetCollection.combineCSSFeatureFlags();
 }
 
+void Document::fontsNeedUpdate(FontSelector*)
+{
+    if (m_styleResolver)
+        m_styleResolver->invalidateMatchedPropertiesCache();
+    if (inPageCache() || !renderView())
+        return;
+    scheduleForcedStyleRecalc();
+}
+
 CSSFontSelector& Document::fontSelector()
 {
-    if (!m_fontSelector)
+    if (!m_fontSelector) {
         m_fontSelector = CSSFontSelector::create(*this);
+        m_fontSelector->registerForInvalidationCallbacks(this);
+    }
     return *m_fontSelector;
 }
 
@@ -1956,6 +1967,7 @@ void Document::clearStyleResolver()
     // FIXME: It would be better if the FontSelector could survive this operation.
     if (m_fontSelector) {
         m_fontSelector->clearDocument();
+        m_fontSelector->unregisterForInvalidationCallbacks(this);
         m_fontSelector = nullptr;
     }
 }
index decc601..0f3f9ad 100644 (file)
@@ -35,6 +35,7 @@
 #include "DocumentStyleSheetCollection.h"
 #include "DocumentTiming.h"
 #include "FocusDirection.h"
+#include "FontSelector.h"
 #include "IconURL.h"
 #include "MutationObserver.h"
 #include "PageVisibilityState.h"
@@ -256,7 +257,7 @@ enum class DocumentCompatibilityMode : unsigned char {
     LimitedQuirksMode = 1 << 2
 };
 
-class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
+class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext, public FontSelectorClient {
 public:
     static Ref<Document> create(Frame* frame, const URL& url)
     {
@@ -1307,6 +1308,9 @@ private:
     typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data);
     void processArguments(const String& features, void* data, ArgumentsCallback);
 
+    // FontSelectorClient
+    virtual void fontsNeedUpdate(FontSelector*) override final;
+
     virtual bool isDocument() const override final { return true; }
 
     virtual void childrenChanged(const ChildChange&) override final;