Title: [201534] trunk/Source/WebCore
Revision
201534
Author
[email protected]
Date
2016-05-31 15:51:01 -0700 (Tue, 31 May 2016)

Log Message

Clean up / modernize iOS text autosizing code
https://bugs.webkit.org/show_bug.cgi?id=158217

Reviewed by Darin Adler.

Clean up / modernize iOS text autosizing code.

I think iOS text autosizing code is too intrusive inside the RenderStyle
class but I have not updated this part of the code yet to limit patch
size. This patch focuses on the TextAutoSizing.* and text autosizing
code in the Document class.

* WebCore.xcodeproj/project.pbxproj:
* dom/Document.cpp:
(WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
(WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
Move TextAutoSizingTraits to the TextAutoSizing header to
promote reuse and make the text autosizing code a little less
intrusive.

(WebCore::Document::addAutoSizingNode):
- Drop local 'key' variable as it is only used once.
- Use std::make_unique<> to construct the TextAutoSizingValue
  as it is no longer ref-counted.

(WebCore::Document::validateAutoSizingNodes):
Iterate over the textAutosizedNodes HashMap only once instead
of twice. TextAutoSizingValue::adjustTextNodeSizes() was updated
to return an enum class so we know from that value if we can
remove the value from the HashSet or not, without having to rely
on TextAutoSizingValue::numNodes(), which I removed in this
patch.

(WebCore::Document::clearAutoSizingNodes):
Updated the TextAutoSizingValue destructor to call reset() so
we don't have to explicitly call reset() on each value before
clearing the textAutosizedNodes HashMap.

* dom/Document.h:
- Move TextAutoSizingTraits to the TextAutosizing header.
- Rename resetAutosizingNodes() to clearAutoSizingNodes() as
  the method now only clears the textAutosizedNodes HashMap
  and reset() is now an implementation detail for
  TextAutoSizingValue.

* rendering/RenderElement.cpp:
(WebCore::RenderElement::resetTextAutosizing):
Call clearAutoSizingNodes() as it was renamed.

* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingKey::TextAutoSizingKey):
- Use value of -1 for std::unique_ptr m_style member for distinguishing
a HashTable deleted value, instead of having an extra m_isDeleted
data member for this purpose.
- Take RenderStyle parameter by reference and drop the null check as the
  call site can never pass nullptr.

(WebCore::TextAutoSizingValue::addTextNode):
- Rename addNode() to addTextNode() for clarity.

(WebCore::TextAutoSizingValue::~TextAutoSizingValue):
Update destructor to call reset() so that the Document does not have to
call it explicitly and can instead just clear the HashMap, which will
destroy the TextAutoSizingValue objects.

(WebCore::TextAutoSizingValue::reset):
Rename text to renderer for clarity.

* rendering/TextAutoSizing.h:
- Make TextAutoSizingValue as fast allocated.
- Update TextAutoSizingValue to no longer be refcounted as ownership is never
  shared. The Document owns those.
- Drop the factory function for TextAutoSizingValue and make the constructor
  public now that the class is no longer refcounted.
- Make reset() method private now that it is called from the destructor and
  the Document is no longer expected to explicitly call it.
- Update adjustTextNodeSizes() to return a StillHasNodes enum class and the
  Document can rely on the determine if it can drop the TextAutoSizingValue
  from its HashMap (and therefore destroy the object).
- Drop numNodes() method as it is no longer needed.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201533 => 201534)


--- trunk/Source/WebCore/ChangeLog	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/ChangeLog	2016-05-31 22:51:01 UTC (rev 201534)
@@ -1,3 +1,87 @@
+2016-05-31  Chris Dumez  <[email protected]>
+
+        Clean up / modernize iOS text autosizing code
+        https://bugs.webkit.org/show_bug.cgi?id=158217
+
+        Reviewed by Darin Adler.
+
+        Clean up / modernize iOS text autosizing code.
+
+        I think iOS text autosizing code is too intrusive inside the RenderStyle
+        class but I have not updated this part of the code yet to limit patch
+        size. This patch focuses on the TextAutoSizing.* and text autosizing
+        code in the Document class.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Document.cpp:
+        (WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
+        (WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
+        Move TextAutoSizingTraits to the TextAutoSizing header to
+        promote reuse and make the text autosizing code a little less
+        intrusive.
+
+        (WebCore::Document::addAutoSizingNode):
+        - Drop local 'key' variable as it is only used once.
+        - Use std::make_unique<> to construct the TextAutoSizingValue
+          as it is no longer ref-counted.
+
+        (WebCore::Document::validateAutoSizingNodes):
+        Iterate over the textAutosizedNodes HashMap only once instead
+        of twice. TextAutoSizingValue::adjustTextNodeSizes() was updated
+        to return an enum class so we know from that value if we can
+        remove the value from the HashSet or not, without having to rely
+        on TextAutoSizingValue::numNodes(), which I removed in this
+        patch.
+
+        (WebCore::Document::clearAutoSizingNodes):
+        Updated the TextAutoSizingValue destructor to call reset() so
+        we don't have to explicitly call reset() on each value before
+        clearing the textAutosizedNodes HashMap.
+
+        * dom/Document.h:
+        - Move TextAutoSizingTraits to the TextAutosizing header.
+        - Rename resetAutosizingNodes() to clearAutoSizingNodes() as
+          the method now only clears the textAutosizedNodes HashMap
+          and reset() is now an implementation detail for
+          TextAutoSizingValue.
+
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::resetTextAutosizing):
+        Call clearAutoSizingNodes() as it was renamed.
+
+        * rendering/TextAutoSizing.cpp:
+        (WebCore::TextAutoSizingKey::TextAutoSizingKey):
+        - Use value of -1 for std::unique_ptr m_style member for distinguishing
+        a HashTable deleted value, instead of having an extra m_isDeleted
+        data member for this purpose.
+        - Take RenderStyle parameter by reference and drop the null check as the
+          call site can never pass nullptr.
+
+        (WebCore::TextAutoSizingValue::addTextNode):
+        - Rename addNode() to addTextNode() for clarity.
+
+        (WebCore::TextAutoSizingValue::~TextAutoSizingValue):
+        Update destructor to call reset() so that the Document does not have to
+        call it explicitly and can instead just clear the HashMap, which will
+        destroy the TextAutoSizingValue objects.
+
+        (WebCore::TextAutoSizingValue::reset):
+        Rename text to renderer for clarity.
+
+        * rendering/TextAutoSizing.h:
+        - Make TextAutoSizingValue as fast allocated.
+        - Update TextAutoSizingValue to no longer be refcounted as ownership is never
+          shared. The Document owns those.
+        - Drop the factory function for TextAutoSizingValue and make the constructor
+          public now that the class is no longer refcounted.
+        - Make reset() method private now that it is called from the destructor and
+          the Document is no longer expected to explicitly call it.
+        - Update adjustTextNodeSizes() to return a StillHasNodes enum class and the
+          Document can rely on the determine if it can drop the TextAutoSizingValue
+          from its HashMap (and therefore destroy the object).
+        - Drop numNodes() method as it is no longer needed.
+
+
 2016-05-31  Dave Hyatt  <[email protected]>
 
         REGRESSION(r201040): Repainting of moving overflow:hidden objects is broken.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (201533 => 201534)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-05-31 22:51:01 UTC (rev 201534)
@@ -474,7 +474,7 @@
 		0F54DCE11880F901003EEDBB /* DOMGestureEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F54DCDE1880F901003EEDBB /* DOMGestureEvent.mm */; };
 		0F54DCE21880F901003EEDBB /* DOMGestureEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCDF1880F901003EEDBB /* DOMGestureEventInternal.h */; };
 		0F54DCE51881051D003EEDBB /* TextAutoSizing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F54DCE31881051D003EEDBB /* TextAutoSizing.cpp */; };
-		0F54DCE61881051D003EEDBB /* TextAutoSizing.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCE41881051D003EEDBB /* TextAutoSizing.h */; };
+		0F54DCE61881051D003EEDBB /* TextAutoSizing.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCE41881051D003EEDBB /* TextAutoSizing.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0F54DD081881D5F5003EEDBB /* Touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DD051881D5F5003EEDBB /* Touch.h */; };
 		0F54DD091881D5F5003EEDBB /* TouchEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DD061881D5F5003EEDBB /* TouchEvent.h */; };
 		0F54DD0A1881D5F5003EEDBB /* TouchList.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DD071881D5F5003EEDBB /* TouchList.h */; };

Modified: trunk/Source/WebCore/dom/Document.cpp (201533 => 201534)


--- trunk/Source/WebCore/dom/Document.cpp	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-05-31 22:51:01 UTC (rev 201534)
@@ -223,10 +223,6 @@
 #include "GestureEvent.h"
 #endif
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-#include "TextAutoSizing.h"
-#endif
-
 #if ENABLE(MATHML)
 #include "MathMLElement.h"
 #include "MathMLElementFactory.h"
@@ -425,18 +421,6 @@
 
 uint64_t Document::s_globalTreeVersion = 0;
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot)
-{
-    new (&slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
-}
-
-bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value)
-{
-    return value.isDeleted();
-}
-#endif
-
 HashSet<Document*>& Document::allDocuments()
 {
     static NeverDestroyed<HashSet<Document*>> documents;
@@ -5298,35 +5282,24 @@
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 
-void Document::addAutoSizingNode(Text& node, float candidateSize)
+void Document::addAutoSizedNode(Text& node, float candidateSize)
 {
-    LOG(TextAutosizing, " addAutoSizingNode %p candidateSize=%f", &node, candidateSize);
-
-    TextAutoSizingKey key(&node.renderer()->style());
-    auto addResult = m_textAutoSizedNodes.ensure(WTFMove(key), [] {
-        return TextAutoSizingValue::create();
-    });
-    addResult.iterator->value->addNode(node, candidateSize);
+    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::validateAutoSizingNodes()
+void Document::updateAutoSizedNodes()
 {
-    Vector<TextAutoSizingKey> nodesForRemoval;
-    for (auto& keyValuePair : m_textAutoSizedNodes) {
-        TextAutoSizingValue* value = keyValuePair.value.get();
-        // Update all the nodes in the collection to reflect the new
-        // candidate size.
-        value->adjustNodeSizes();
-    }
     m_textAutoSizedNodes.removeIf([](auto& keyAndValue) {
-        return !keyAndValue.value->numNodes();
+        return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
     });
 }
     
-void Document::resetAutoSizingNodes()
+void Document::clearAutoSizedNodes()
 {
-    for (auto& value : m_textAutoSizedNodes.values())
-        value->reset();
     m_textAutoSizedNodes.clear();
 }
 

Modified: trunk/Source/WebCore/dom/Document.h (201533 => 201534)


--- trunk/Source/WebCore/dom/Document.h	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/dom/Document.h	2016-05-31 22:51:01 UTC (rev 201534)
@@ -46,6 +46,7 @@
 #include "StringWithDirection.h"
 #include "StyleChange.h"
 #include "Supplementable.h"
+#include "TextAutoSizing.h"
 #include "TextResourceDecoder.h"
 #include "Timer.h"
 #include "TreeScope.h"
@@ -212,12 +213,6 @@
 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);
-};
 #endif
 
 #if ENABLE(MEDIA_SESSION)
@@ -1694,12 +1689,12 @@
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 public:
-    void addAutoSizingNode(Text&, float size);
-    void validateAutoSizingNodes();
-    void resetAutoSizingNodes();
+    void addAutoSizedNode(Text&, float size);
+    void updateAutoSizedNodes();
+    void clearAutoSizedNodes();
 
 private:
-    typedef HashMap<TextAutoSizingKey, RefPtr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> TextAutoSizingMap;
+    using TextAutoSizingMap = HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits>;
     TextAutoSizingMap m_textAutoSizedNodes;
 #endif
 

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (201533 => 201534)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2016-05-31 22:51:01 UTC (rev 201534)
@@ -3817,7 +3817,7 @@
             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().addAutoSizingNode(*text.textNode(), candidateNewSize);
+                document().addAutoSizedNode(*text.textNode(), candidateNewSize);
         }
 
         descendant = RenderObjectTraversal::nextSkippingChildren(text, this);

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (201533 => 201534)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-31 22:51:01 UTC (rev 201534)
@@ -2214,7 +2214,7 @@
     }
 
     // Remove style from auto-sizing table that are no longer valid.
-    document->validateAutoSizingNodes();
+    document->updateAutoSizedNodes();
 }
 
 void RenderElement::resetTextAutosizing()
@@ -2225,7 +2225,7 @@
 
     LOG(TextAutosizing, "RenderElement::resetTextAutosizing()");
 
-    document->resetAutoSizingNodes();
+    document->clearAutoSizedNodes();
 
     Vector<int> depthStack;
     int currentDepth = 0;

Modified: trunk/Source/WebCore/rendering/TextAutoSizing.cpp (201533 => 201534)


--- trunk/Source/WebCore/rendering/TextAutoSizing.cpp	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.cpp	2016-05-31 22:51:01 UTC (rev 201534)
@@ -48,79 +48,71 @@
 }
 
 TextAutoSizingKey::TextAutoSizingKey(DeletedTag)
-    : m_isDeleted(true)
 {
+    HashTraits<std::unique_ptr<RenderStyle>>::constructDeletedValue(m_style);
 }
 
-TextAutoSizingKey::TextAutoSizingKey(const RenderStyle* style)
-    : m_style(style ? RenderStyle::clonePtr(*style) : nullptr)
+TextAutoSizingKey::TextAutoSizingKey(const RenderStyle& style, unsigned hash)
+    : m_style(RenderStyle::clonePtr(style)) // FIXME: This seems very inefficient.
+    , m_hash(hash)
 {
 }
 
-int TextAutoSizingValue::numNodes() const
+void TextAutoSizingValue::addTextNode(Text& node, float size)
 {
-    return m_autoSizedNodes.size();
-}
-
-void TextAutoSizingValue::addNode(Text& node, float size)
-{
     node.renderer()->setCandidateComputedTextSize(size);
     m_autoSizedNodes.add(&node);
 }
 
-#define MAX_SCALE_INCREASE 1.7f
+static const float maxScaleIncrease = 1.7f;
 
-bool TextAutoSizingValue::adjustNodeSizes()
+auto TextAutoSizingValue::adjustTextNodeSizes() -> StillHasNodes
 {
-    bool didRemoveObjects = false;
-
-    // Remove stale nodes.  Nodes may have had their renderers detached.  We'll
-    // also need to remove the style from the documents m_textAutoSizedNodes
-    // collection.  Return true indicates we need to do that removal.
+    // Remove stale nodes. Nodes may have had their renderers detached. We'll also need to remove the style from the documents m_textAutoSizedNodes
+    // collection. Return true indicates we need to do that removal.
     Vector<Text*> nodesForRemoval;
-    for (auto& node : m_autoSizedNodes) {
-        auto* text = node->renderer();
-        if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
-            nodesForRemoval.append(node.get());
-            didRemoveObjects = true;
-        }
+    for (auto& textNode : m_autoSizedNodes) {
+        auto* renderer = textNode->renderer();
+        if (!renderer || !renderer->style().textSizeAdjust().isAuto() || !renderer->candidateComputedTextSize())
+            nodesForRemoval.append(textNode.get());
     }
 
     for (auto& node : nodesForRemoval)
         m_autoSizedNodes.remove(node);
 
-    // If we only have one piece of text with the style on the page don't
-    // adjust it's size.
+    StillHasNodes stillHasNodes = m_autoSizedNodes.isEmpty() ? StillHasNodes::No : StillHasNodes::Yes;
+
+    // If we only have one piece of text with the style on the page don't adjust it's size.
     if (m_autoSizedNodes.size() <= 1)
-        return didRemoveObjects;
+        return stillHasNodes;
 
-    // Compute average size
+    // Compute average size.
     float cumulativeSize = 0;
     for (auto& node : m_autoSizedNodes)
         cumulativeSize += node->renderer()->candidateComputedTextSize();
 
-    float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
+    float averageSize = std::round(cumulativeSize / m_autoSizedNodes.size());
 
-    // Adjust sizes
+    // Adjust sizes.
     bool firstPass = true;
     for (auto& node : m_autoSizedNodes) {
-        auto* text = node->renderer();
-        if (!text || text->style().fontDescription().computedSize() == averageSize)
+        auto& renderer = *node->renderer();
+        if (renderer.style().fontDescription().computedSize() == averageSize)
             continue;
 
-        float specifiedSize = text->style().fontDescription().specifiedSize();
+        float specifiedSize = renderer.style().fontDescription().specifiedSize();
         float scaleChange = averageSize / specifiedSize;
-        if (scaleChange > MAX_SCALE_INCREASE && firstPass) {
+        if (scaleChange > maxScaleIncrease && firstPass) {
             firstPass = false;
-            averageSize = roundf(specifiedSize * MAX_SCALE_INCREASE);
+            averageSize = std::round(specifiedSize * maxScaleIncrease);
             scaleChange = averageSize / specifiedSize;
         }
 
         LOG(TextAutosizing, "  adjust node size %p firstPass=%d averageSize=%f scaleChange=%f", node.get(), firstPass, averageSize, scaleChange);
 
-        auto* parentRenderer = text->parent();
+        auto* parentRenderer = renderer.parent();
 
-        auto style = cloneRenderStyleWithState(text->style());
+        auto style = cloneRenderStyleWithState(renderer.style());
         auto fontDescription = style.fontDescription();
         fontDescription.setComputedSize(averageSize);
         style.setFontDescription(fontDescription);
@@ -161,26 +153,31 @@
         parentRenderer->setStyle(WTFMove(newParentStyle));
     }
 
-    return didRemoveObjects;
+    return stillHasNodes;
 }
 
+TextAutoSizingValue::~TextAutoSizingValue()
+{
+    reset();
+}
+
 void TextAutoSizingValue::reset()
 {
     for (auto& node : m_autoSizedNodes) {
-        auto* text = node->renderer();
-        if (!text)
+        auto* renderer = node->renderer();
+        if (!renderer)
             continue;
 
-        auto* parentRenderer = text->parent();
+        auto* parentRenderer = renderer->parent();
         if (!parentRenderer)
             continue;
 
         // Reset the font size back to the original specified size
-        auto fontDescription = text->style().fontDescription();
+        auto fontDescription = renderer->style().fontDescription();
         float originalSize = fontDescription.specifiedSize();
         if (fontDescription.computedSize() != originalSize) {
             fontDescription.setComputedSize(originalSize);
-            auto style = cloneRenderStyleWithState(text->style());
+            auto style = cloneRenderStyleWithState(renderer->style());
             style.setFontDescription(fontDescription);
             style.fontCascade().update(&node->document().fontSelector());
             parentRenderer->setStyle(WTFMove(style));

Modified: trunk/Source/WebCore/rendering/TextAutoSizing.h (201533 => 201534)


--- trunk/Source/WebCore/rendering/TextAutoSizing.h	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.h	2016-05-31 22:51:01 UTC (rev 201534)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef TextAutoSizing_h
-#define TextAutoSizing_h
+#pragma once
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 
@@ -38,22 +37,23 @@
 class Document;
 class Text;
 
+// FIXME: We can probably get rid of this class entirely and use std::unique_ptr<RenderStyle> as key
+// as long as we use the right hash traits.
 class TextAutoSizingKey {
 public:
     TextAutoSizingKey() = default;
     enum DeletedTag { Deleted };
     explicit TextAutoSizingKey(DeletedTag);
-    explicit TextAutoSizingKey(const RenderStyle*);
-    TextAutoSizingKey(TextAutoSizingKey&&) = default;
+    TextAutoSizingKey(const RenderStyle&, unsigned hash);
 
-    TextAutoSizingKey& operator=(TextAutoSizingKey&&) = default;
+    const RenderStyle* style() const { ASSERT(!isDeleted()); return m_style.get(); }
+    bool isDeleted() const { return HashTraits<std::unique_ptr<RenderStyle>>::isDeletedValue(m_style); }
 
-    const RenderStyle* style() const { return m_style.get(); }
-    inline bool isDeleted() const { return m_isDeleted; }
+    unsigned hash() const { return m_hash; }
 
 private:
     std::unique_ptr<RenderStyle> m_style;
-    bool m_isDeleted { false };
+    unsigned m_hash { 0 };
 };
 
 inline bool operator==(const TextAutoSizingKey& a, const TextAutoSizingKey& b)
@@ -62,33 +62,63 @@
         return false;
     if (!a.style() || !b.style())
         return a.style() == b.style();
-    return a.style()->equalForTextAutosizing(b.style());
+    return a.style()->equalForTextAutosizing(*b.style());
 }
 
 struct TextAutoSizingHash {
-    static unsigned hash(const TextAutoSizingKey& key) { return key.style()->hashForTextAutosizing(); }
+    static unsigned hash(const TextAutoSizingKey& key) { return key.hash(); }
     static bool equal(const TextAutoSizingKey& a, const TextAutoSizingKey& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = true;
 };
 
-class TextAutoSizingValue : public RefCounted<TextAutoSizingValue> {
-public:
-    static Ref<TextAutoSizingValue> create()
+struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
+    static const bool emptyValueIsZero = true;
+    static void constructDeletedValue(TextAutoSizingKey& slot)
     {
-        return adoptRef(*new TextAutoSizingValue);
+        new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
     }
+    static bool isDeletedValue(const TextAutoSizingKey& value)
+    {
+        return value.isDeleted();
+    }
+};
 
-    void addNode(Text&, float size);
-    bool adjustNodeSizes();
-    int numNodes() const;
+struct TextAutoSizingHashTranslator {
+    static unsigned hash(const RenderStyle& style)
+    {
+        return style.hashForTextAutosizing();
+    }
+
+    static bool equal(const TextAutoSizingKey& key, const RenderStyle& style)
+    {
+        if (key.isDeleted() || !key.style())
+            return false;
+        return key.style()->equalForTextAutosizing(style);
+    }
+
+    static void translate(TextAutoSizingKey& key, const RenderStyle& style, unsigned hash)
+    {
+        key = { style, hash };
+    }
+};
+
+class TextAutoSizingValue {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    TextAutoSizingValue() = default;
+    ~TextAutoSizingValue();
+
+    void addTextNode(Text&, float size);
+
+    enum class StillHasNodes { No, Yes };
+    StillHasNodes adjustTextNodeSizes();
+
+private:
     void reset();
-private:
-    TextAutoSizingValue() { }
+
     HashSet<RefPtr<Text>> m_autoSizedNodes;
 };
 
 } // namespace WebCore
 
 #endif // ENABLE(IOS_TEXT_AUTOSIZING)
-
-#endif // TextAutoSizing_h

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (201533 => 201534)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-05-31 22:51:01 UTC (rev 201534)
@@ -411,26 +411,26 @@
     return hash;
 }
 
-bool RenderStyle::equalForTextAutosizing(const RenderStyle* other) const
+bool RenderStyle::equalForTextAutosizing(const RenderStyle& other) const
 {
-    return rareNonInheritedData->m_appearance == other->rareNonInheritedData->m_appearance
-        && rareNonInheritedData->marginBeforeCollapse == other->rareNonInheritedData->marginBeforeCollapse
-        && rareNonInheritedData->marginAfterCollapse == other->rareNonInheritedData->marginAfterCollapse
-        && rareNonInheritedData->lineClamp == other->rareNonInheritedData->lineClamp
-        && rareInheritedData->textSizeAdjust == other->rareInheritedData->textSizeAdjust
-        && rareInheritedData->overflowWrap == other->rareInheritedData->overflowWrap
-        && rareInheritedData->nbspMode == other->rareInheritedData->nbspMode
-        && rareInheritedData->lineBreak == other->rareInheritedData->lineBreak
-        && rareInheritedData->textSecurity == other->rareInheritedData->textSecurity
-        && inherited->specifiedLineHeight == other->inherited->specifiedLineHeight
-        && inherited->fontCascade.equalForTextAutoSizing(other->inherited->fontCascade)
-        && inherited->horizontal_border_spacing == other->inherited->horizontal_border_spacing
-        && inherited->vertical_border_spacing == other->inherited->vertical_border_spacing
-        && inherited_flags._box_direction == other->inherited_flags._box_direction
-        && inherited_flags.m_rtlOrdering == other->inherited_flags.m_rtlOrdering
-        && noninherited_flags.position() == other->noninherited_flags.position()
-        && noninherited_flags.floating() == other->noninherited_flags.floating()
-        && rareNonInheritedData->textOverflow == other->rareNonInheritedData->textOverflow;
+    return rareNonInheritedData->m_appearance == other.rareNonInheritedData->m_appearance
+        && rareNonInheritedData->marginBeforeCollapse == other.rareNonInheritedData->marginBeforeCollapse
+        && rareNonInheritedData->marginAfterCollapse == other.rareNonInheritedData->marginAfterCollapse
+        && rareNonInheritedData->lineClamp == other.rareNonInheritedData->lineClamp
+        && rareInheritedData->textSizeAdjust == other.rareInheritedData->textSizeAdjust
+        && rareInheritedData->overflowWrap == other.rareInheritedData->overflowWrap
+        && rareInheritedData->nbspMode == other.rareInheritedData->nbspMode
+        && rareInheritedData->lineBreak == other.rareInheritedData->lineBreak
+        && rareInheritedData->textSecurity == other.rareInheritedData->textSecurity
+        && inherited->specifiedLineHeight == other.inherited->specifiedLineHeight
+        && inherited->fontCascade.equalForTextAutoSizing(other.inherited->fontCascade)
+        && inherited->horizontal_border_spacing == other.inherited->horizontal_border_spacing
+        && inherited->vertical_border_spacing == other.inherited->vertical_border_spacing
+        && inherited_flags._box_direction == other.inherited_flags._box_direction
+        && inherited_flags.m_rtlOrdering == other.inherited_flags.m_rtlOrdering
+        && noninherited_flags.position() == other.noninherited_flags.position()
+        && noninherited_flags.floating() == other.noninherited_flags.floating()
+        && rareNonInheritedData->textOverflow == other.rareNonInheritedData->textOverflow;
 }
 
 #endif // ENABLE(IOS_TEXT_AUTOSIZING)

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (201533 => 201534)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-05-31 22:44:31 UTC (rev 201533)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-05-31 22:51:01 UTC (rev 201534)
@@ -1862,7 +1862,7 @@
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     uint32_t hashForTextAutosizing() const;
-    bool equalForTextAutosizing(const RenderStyle *other) const;
+    bool equalForTextAutosizing(const RenderStyle&) const;
 #endif
 
     StyleDifference diff(const RenderStyle&, unsigned& changedContextSensitiveProperties) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to