Factor text autosizing into a class
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2017 13:20:47 +0000 (13:20 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2017 13:20:47 +0000 (13:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175530

Reviewed by Andreas Kling.

Move the remaining parts out of Document.

* css/StyleBuilderCustom.h:
(WebCore::computeLineHeightMultiplierDueToFontSize):
* dom/Document.cpp:
(WebCore::Document::destroyRenderTree):
(WebCore::Document::textAutoSizing):
(WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
(WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
(WebCore::Document::addAutoSizedNode): Deleted.
(WebCore::Document::updateAutoSizedNodes): Deleted.
(WebCore::Document::clearAutoSizedNodes): Deleted.
* dom/Document.h:
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
(WebCore::RenderElement::resetTextAutosizing):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingTraits::constructDeletedValue):
(WebCore::TextAutoSizingTraits::isDeletedValue):
(WebCore::TextAutoSizing::addTextNode):
(WebCore::TextAutoSizing::updateRenderTree):
(WebCore::TextAutoSizing::reset):
* rendering/TextAutoSizing.h:

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

Source/WebCore/ChangeLog
Source/WebCore/css/StyleBuilderCustom.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/TextAutoSizing.cpp
Source/WebCore/rendering/TextAutoSizing.h

index 3d41419..d69be68 100644 (file)
@@ -1,5 +1,38 @@
 2017-08-14  Antti Koivisto  <antti@apple.com>
 
 2017-08-14  Antti Koivisto  <antti@apple.com>
 
+        Factor text autosizing into a class
+        https://bugs.webkit.org/show_bug.cgi?id=175530
+
+        Reviewed by Andreas Kling.
+
+        Move the remaining parts out of Document.
+
+        * css/StyleBuilderCustom.h:
+        (WebCore::computeLineHeightMultiplierDueToFontSize):
+        * dom/Document.cpp:
+        (WebCore::Document::destroyRenderTree):
+        (WebCore::Document::textAutoSizing):
+        (WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
+        (WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
+        (WebCore::Document::addAutoSizedNode): Deleted.
+        (WebCore::Document::updateAutoSizedNodes): Deleted.
+        (WebCore::Document::clearAutoSizedNodes): Deleted.
+        * dom/Document.h:
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::adjustComputedFontSizes):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
+        (WebCore::RenderElement::resetTextAutosizing):
+        * rendering/TextAutoSizing.cpp:
+        (WebCore::TextAutoSizingTraits::constructDeletedValue):
+        (WebCore::TextAutoSizingTraits::isDeletedValue):
+        (WebCore::TextAutoSizing::addTextNode):
+        (WebCore::TextAutoSizing::updateRenderTree):
+        (WebCore::TextAutoSizing::reset):
+        * rendering/TextAutoSizing.h:
+
+2017-08-14  Antti Koivisto  <antti@apple.com>
+
         [Render Tree Mutation] First letter should not mutate the render tree while in layout.
         https://bugs.webkit.org/show_bug.cgi?id=163848
 
         [Render Tree Mutation] First letter should not mutate the render tree while in layout.
         https://bugs.webkit.org/show_bug.cgi?id=163848
 
index 4d5ff1a..d3c2091 100644 (file)
@@ -680,7 +680,7 @@ static inline float computeLineHeightMultiplierDueToFontSize(const Document& doc
                 // that the minimum font size is the only thing affecting the computed font size.
 
                 // This calculation matches the line-height computed size calculation in
                 // that the minimum font size is the only thing affecting the computed font size.
 
                 // This calculation matches the line-height computed size calculation in
-                // TextAutoSizingValue::adjustTextNodeSizes().
+                // TextAutoSizing::Value::adjustTextNodeSizes().
                 auto scaleChange = minimumFontSize / specifiedFontSize;
                 return scaleChange;
             }
                 auto scaleChange = minimumFontSize / specifiedFontSize;
                 return scaleChange;
             }
index 45d8aa0..fa708ce 100644 (file)
@@ -427,20 +427,6 @@ static void printNavigationErrorMessage(Frame* frame, const URL& activeURL, cons
     frame->document()->domWindow()->printErrorMessage(message);
 }
 
     frame->document()->domWindow()->printErrorMessage(message);
 }
 
-#if ENABLE(TEXT_AUTOSIZING)
-
-void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot)
-{
-    new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
-}
-
-bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value)
-{
-    return value.isDeleted();
-}
-
-#endif
-
 uint64_t Document::s_globalTreeVersion = 0;
 
 HashSet<Document*>& Document::allDocuments()
 uint64_t Document::s_globalTreeVersion = 0;
 
 HashSet<Document*>& Document::allDocuments()
@@ -2264,8 +2250,7 @@ void Document::destroyRenderTree()
     Node::setRenderer(nullptr);
 
 #if ENABLE(TEXT_AUTOSIZING)
     Node::setRenderer(nullptr);
 
 #if ENABLE(TEXT_AUTOSIZING)
-    // Do this before the arena is cleared, which is needed to deref the RenderStyle on TextAutoSizingKey.
-    m_textAutoSizedNodes.clear();
+    m_textAutoSizing = nullptr;
 #endif
 
     if (view())
 #endif
 
     if (view())
@@ -5558,28 +5543,12 @@ HTMLCanvasElement* Document::getCSSCanvasElement(const String& name)
 }
 
 #if ENABLE(TEXT_AUTOSIZING)
 }
 
 #if ENABLE(TEXT_AUTOSIZING)
-
-void Document::addAutoSizedNode(Text& node, float candidateSize)
+TextAutoSizing& Document::textAutoSizing()
 {
 {
-    LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize);
-    auto addResult = m_textAutoSizedNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = std::make_unique<TextAutoSizingValue>();
-    addResult.iterator->value->addTextNode(node, candidateSize);
-}
-
-void Document::updateAutoSizedNodes()
-{
-    m_textAutoSizedNodes.removeIf([](auto& keyAndValue) {
-        return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
-    });
+    if (!m_textAutoSizing)
+        m_textAutoSizing = std::make_unique<TextAutoSizing>();
+    return *m_textAutoSizing;
 }
 }
-    
-void Document::clearAutoSizedNodes()
-{
-    m_textAutoSizedNodes.clear();
-}
-
 #endif // ENABLE(TEXT_AUTOSIZING)
 
 void Document::initDNSPrefetch()
 #endif // ENABLE(TEXT_AUTOSIZING)
 
 void Document::initDNSPrefetch()
index 54bc48d..cfb7205 100644 (file)
@@ -207,15 +207,7 @@ class DeviceOrientationController;
 #endif
 
 #if ENABLE(TEXT_AUTOSIZING)
 #endif
 
 #if ENABLE(TEXT_AUTOSIZING)
-struct TextAutoSizingHash;
-class TextAutoSizingKey;
-class TextAutoSizingValue;
-
-struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
-    static const bool emptyValueIsZero = true;
-    static void constructDeletedValue(TextAutoSizingKey& slot);
-    static bool isDeletedValue(const TextAutoSizingKey& value);
-};
+class TextAutoSizing;
 #endif
 
 #if ENABLE(MEDIA_SESSION)
 #endif
 
 #if ENABLE(MEDIA_SESSION)
@@ -1362,6 +1354,10 @@ public:
     // Per https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-releaseevents, this method does nothing.
     void releaseEvents() { }
 
     // Per https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-releaseevents, this method does nothing.
     void releaseEvents() { }
 
+#if ENABLE(TEXT_AUTOSIZING)
+    TextAutoSizing& textAutoSizing();
+#endif
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
@@ -1665,14 +1661,7 @@ private:
     Vector<Task> m_pendingTasks;
 
 #if ENABLE(TEXT_AUTOSIZING)
     Vector<Task> m_pendingTasks;
 
 #if ENABLE(TEXT_AUTOSIZING)
-public:
-    void addAutoSizedNode(Text&, float size);
-    void updateAutoSizedNodes();
-    void clearAutoSizedNodes();
-
-private:
-    using TextAutoSizingMap = HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits>;
-    TextAutoSizingMap m_textAutoSizedNodes;
+    std::unique_ptr<TextAutoSizing> m_textAutoSizing;
 #endif
 
     Timer m_visualUpdatesSuppressionTimer;
 #endif
 
     Timer m_visualUpdatesSuppressionTimer;
index 3b287f8..a2be462 100644 (file)
@@ -53,6 +53,7 @@
 #include "Settings.h"
 #include "SimpleLineLayoutFunctions.h"
 #include "SimpleLineLayoutPagination.h"
 #include "Settings.h"
 #include "SimpleLineLayoutFunctions.h"
 #include "SimpleLineLayoutPagination.h"
+#include "TextAutoSizing.h"
 #include "VerticalPositionCache.h"
 #include "VisiblePosition.h"
 
 #include "VerticalPositionCache.h"
 #include "VisiblePosition.h"
 
@@ -3906,7 +3907,7 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
             float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
             float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
             if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
             float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
             float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
             if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
-                document().addAutoSizedNode(*text.textNode(), candidateNewSize);
+                document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize);
         }
 
         descendant = RenderObjectTraversal::nextSkippingChildren(text, this);
         }
 
         descendant = RenderObjectTraversal::nextSkippingChildren(text, this);
index c9dc5d6..8da668d 100644 (file)
@@ -74,6 +74,7 @@
 #include "ShadowRoot.h"
 #include "StylePendingResources.h"
 #include "StyleResolver.h"
 #include "ShadowRoot.h"
 #include "StylePendingResources.h"
 #include "StyleResolver.h"
+#include "TextAutoSizing.h"
 #include <wtf/MathExtras.h>
 #include <wtf/StackStats.h>
 
 #include <wtf/MathExtras.h>
 #include <wtf/StackStats.h>
 
@@ -2314,7 +2315,7 @@ void RenderElement::adjustComputedFontSizesOnBlocks(float size, float visibleWid
     }
 
     // Remove style from auto-sizing table that are no longer valid.
     }
 
     // Remove style from auto-sizing table that are no longer valid.
-    document->updateAutoSizedNodes();
+    document->textAutoSizing().updateRenderTree();
 }
 
 void RenderElement::resetTextAutosizing()
 }
 
 void RenderElement::resetTextAutosizing()
@@ -2325,7 +2326,7 @@ void RenderElement::resetTextAutosizing()
 
     LOG(TextAutosizing, "RenderElement::resetTextAutosizing()");
 
 
     LOG(TextAutosizing, "RenderElement::resetTextAutosizing()");
 
-    document->clearAutoSizedNodes();
+    document->textAutoSizing().reset();
 
     Vector<int> depthStack;
     int currentDepth = 0;
 
     Vector<int> depthStack;
     int currentDepth = 0;
index a4eb52a..1aa8bd4 100644 (file)
@@ -215,6 +215,27 @@ void TextAutoSizingValue::reset()
     }
 }
 
     }
 }
 
+void TextAutoSizing::addTextNode(Text& node, float candidateSize)
+{
+    LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize);
+    auto addResult = m_textNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr);
+    if (addResult.isNewEntry)
+        addResult.iterator->value = std::make_unique<TextAutoSizingValue>();
+    addResult.iterator->value->addTextNode(node, candidateSize);
+}
+
+void TextAutoSizing::updateRenderTree()
+{
+    m_textNodes.removeIf([](auto& keyAndValue) {
+        return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
+    });
+}
+
+void TextAutoSizing::reset()
+{
+    m_textNodes.clear();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(TEXT_AUTOSIZING)
 } // namespace WebCore
 
 #endif // ENABLE(TEXT_AUTOSIZING)
index 7339418..bb83c39 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(TEXT_AUTOSIZING)
 
 #include "RenderStyle.h"
 #if ENABLE(TEXT_AUTOSIZING)
 
 #include "RenderStyle.h"
+#include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/HashSet.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -107,6 +108,25 @@ private:
     HashSet<RefPtr<Text>> m_autoSizedNodes;
 };
 
     HashSet<RefPtr<Text>> m_autoSizedNodes;
 };
 
+struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
+    static const bool emptyValueIsZero = true;
+    static void constructDeletedValue(TextAutoSizingKey& slot) { new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); }
+    static bool isDeletedValue(const TextAutoSizingKey& value) { return value.isDeleted(); }
+};
+
+class TextAutoSizing {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    TextAutoSizing() = default;
+
+    void addTextNode(Text&, float size);
+    void updateRenderTree();
+    void reset();
+
+private:
+    HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> m_textNodes;
+};
+
 } // namespace WebCore
 
 #endif // ENABLE(TEXT_AUTOSIZING)
 } // namespace WebCore
 
 #endif // ENABLE(TEXT_AUTOSIZING)