⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 201534 in webkit


Ignore:
Timestamp:
May 31, 2016, 3:51:01 PM (10 years ago)
Author:
Chris Dumez
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.
Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201529 r201534  
     12016-05-31  Chris Dumez  <cdumez@apple.com>
     2
     3        Clean up / modernize iOS text autosizing code
     4        https://bugs.webkit.org/show_bug.cgi?id=158217
     5
     6        Reviewed by Darin Adler.
     7
     8        Clean up / modernize iOS text autosizing code.
     9
     10        I think iOS text autosizing code is too intrusive inside the RenderStyle
     11        class but I have not updated this part of the code yet to limit patch
     12        size. This patch focuses on the TextAutoSizing.* and text autosizing
     13        code in the Document class.
     14
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * dom/Document.cpp:
     17        (WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
     18        (WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
     19        Move TextAutoSizingTraits to the TextAutoSizing header to
     20        promote reuse and make the text autosizing code a little less
     21        intrusive.
     22
     23        (WebCore::Document::addAutoSizingNode):
     24        - Drop local 'key' variable as it is only used once.
     25        - Use std::make_unique<> to construct the TextAutoSizingValue
     26          as it is no longer ref-counted.
     27
     28        (WebCore::Document::validateAutoSizingNodes):
     29        Iterate over the textAutosizedNodes HashMap only once instead
     30        of twice. TextAutoSizingValue::adjustTextNodeSizes() was updated
     31        to return an enum class so we know from that value if we can
     32        remove the value from the HashSet or not, without having to rely
     33        on TextAutoSizingValue::numNodes(), which I removed in this
     34        patch.
     35
     36        (WebCore::Document::clearAutoSizingNodes):
     37        Updated the TextAutoSizingValue destructor to call reset() so
     38        we don't have to explicitly call reset() on each value before
     39        clearing the textAutosizedNodes HashMap.
     40
     41        * dom/Document.h:
     42        - Move TextAutoSizingTraits to the TextAutosizing header.
     43        - Rename resetAutosizingNodes() to clearAutoSizingNodes() as
     44          the method now only clears the textAutosizedNodes HashMap
     45          and reset() is now an implementation detail for
     46          TextAutoSizingValue.
     47
     48        * rendering/RenderElement.cpp:
     49        (WebCore::RenderElement::resetTextAutosizing):
     50        Call clearAutoSizingNodes() as it was renamed.
     51
     52        * rendering/TextAutoSizing.cpp:
     53        (WebCore::TextAutoSizingKey::TextAutoSizingKey):
     54        - Use value of -1 for std::unique_ptr m_style member for distinguishing
     55        a HashTable deleted value, instead of having an extra m_isDeleted
     56        data member for this purpose.
     57        - Take RenderStyle parameter by reference and drop the null check as the
     58          call site can never pass nullptr.
     59
     60        (WebCore::TextAutoSizingValue::addTextNode):
     61        - Rename addNode() to addTextNode() for clarity.
     62
     63        (WebCore::TextAutoSizingValue::~TextAutoSizingValue):
     64        Update destructor to call reset() so that the Document does not have to
     65        call it explicitly and can instead just clear the HashMap, which will
     66        destroy the TextAutoSizingValue objects.
     67
     68        (WebCore::TextAutoSizingValue::reset):
     69        Rename text to renderer for clarity.
     70
     71        * rendering/TextAutoSizing.h:
     72        - Make TextAutoSizingValue as fast allocated.
     73        - Update TextAutoSizingValue to no longer be refcounted as ownership is never
     74          shared. The Document owns those.
     75        - Drop the factory function for TextAutoSizingValue and make the constructor
     76          public now that the class is no longer refcounted.
     77        - Make reset() method private now that it is called from the destructor and
     78          the Document is no longer expected to explicitly call it.
     79        - Update adjustTextNodeSizes() to return a StillHasNodes enum class and the
     80          Document can rely on the determine if it can drop the TextAutoSizingValue
     81          from its HashMap (and therefore destroy the object).
     82        - Drop numNodes() method as it is no longer needed.
     83
     84
    1852016-05-31  Dave Hyatt  <hyatt@apple.com>
    286
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r201504 r201534  
    475475                0F54DCE21880F901003EEDBB /* DOMGestureEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCDF1880F901003EEDBB /* DOMGestureEventInternal.h */; };
    476476                0F54DCE51881051D003EEDBB /* TextAutoSizing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F54DCE31881051D003EEDBB /* TextAutoSizing.cpp */; };
    477                 0F54DCE61881051D003EEDBB /* TextAutoSizing.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCE41881051D003EEDBB /* TextAutoSizing.h */; };
     477                0F54DCE61881051D003EEDBB /* TextAutoSizing.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCE41881051D003EEDBB /* TextAutoSizing.h */; settings = {ATTRIBUTES = (Private, ); }; };
    478478                0F54DD081881D5F5003EEDBB /* Touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DD051881D5F5003EEDBB /* Touch.h */; };
    479479                0F54DD091881D5F5003EEDBB /* TouchEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F54DD061881D5F5003EEDBB /* TouchEvent.h */; };
  • trunk/Source/WebCore/dom/Document.cpp

    r201496 r201534  
    224224#endif
    225225
    226 #if ENABLE(IOS_TEXT_AUTOSIZING)
    227 #include "TextAutoSizing.h"
    228 #endif
    229 
    230226#if ENABLE(MATHML)
    231227#include "MathMLElement.h"
     
    425421
    426422uint64_t Document::s_globalTreeVersion = 0;
    427 
    428 #if ENABLE(IOS_TEXT_AUTOSIZING)
    429 void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot)
    430 {
    431     new (&slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
    432 }
    433 
    434 bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value)
    435 {
    436     return value.isDeleted();
    437 }
    438 #endif
    439423
    440424HashSet<Document*>& Document::allDocuments()
     
    52995283#if ENABLE(IOS_TEXT_AUTOSIZING)
    53005284
    5301 void Document::addAutoSizingNode(Text& node, float candidateSize)
    5302 {
    5303     LOG(TextAutosizing, " addAutoSizingNode %p candidateSize=%f", &node, candidateSize);
    5304 
    5305     TextAutoSizingKey key(&node.renderer()->style());
    5306     auto addResult = m_textAutoSizedNodes.ensure(WTFMove(key), [] {
    5307         return TextAutoSizingValue::create();
     5285void Document::addAutoSizedNode(Text& node, float candidateSize)
     5286{
     5287    LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize);
     5288    auto addResult = m_textAutoSizedNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr);
     5289    if (addResult.isNewEntry)
     5290        addResult.iterator->value = std::make_unique<TextAutoSizingValue>();
     5291    addResult.iterator->value->addTextNode(node, candidateSize);
     5292}
     5293
     5294void Document::updateAutoSizedNodes()
     5295{
     5296    m_textAutoSizedNodes.removeIf([](auto& keyAndValue) {
     5297        return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
    53085298    });
    5309     addResult.iterator->value->addNode(node, candidateSize);
    5310 }
    5311 
    5312 void Document::validateAutoSizingNodes()
    5313 {
    5314     Vector<TextAutoSizingKey> nodesForRemoval;
    5315     for (auto& keyValuePair : m_textAutoSizedNodes) {
    5316         TextAutoSizingValue* value = keyValuePair.value.get();
    5317         // Update all the nodes in the collection to reflect the new
    5318         // candidate size.
    5319         value->adjustNodeSizes();
    5320     }
    5321     m_textAutoSizedNodes.removeIf([](auto& keyAndValue) {
    5322         return !keyAndValue.value->numNodes();
    5323     });
    53245299}
    53255300   
    5326 void Document::resetAutoSizingNodes()
    5327 {
    5328     for (auto& value : m_textAutoSizedNodes.values())
    5329         value->reset();
     5301void Document::clearAutoSizedNodes()
     5302{
    53305303    m_textAutoSizedNodes.clear();
    53315304}
  • trunk/Source/WebCore/dom/Document.h

    r201496 r201534  
    4747#include "StyleChange.h"
    4848#include "Supplementable.h"
     49#include "TextAutoSizing.h"
    4950#include "TextResourceDecoder.h"
    5051#include "Timer.h"
     
    213214class TextAutoSizingKey;
    214215class TextAutoSizingValue;
    215 
    216 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
    217     static const bool emptyValueIsZero = true;
    218     static void constructDeletedValue(TextAutoSizingKey& slot);
    219     static bool isDeletedValue(const TextAutoSizingKey& value);
    220 };
    221216#endif
    222217
     
    16951690#if ENABLE(IOS_TEXT_AUTOSIZING)
    16961691public:
    1697     void addAutoSizingNode(Text&, float size);
    1698     void validateAutoSizingNodes();
    1699     void resetAutoSizingNodes();
     1692    void addAutoSizedNode(Text&, float size);
     1693    void updateAutoSizedNodes();
     1694    void clearAutoSizedNodes();
    17001695
    17011696private:
    1702     typedef HashMap<TextAutoSizingKey, RefPtr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> TextAutoSizingMap;
     1697    using TextAutoSizingMap = HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits>;
    17031698    TextAutoSizingMap m_textAutoSizedNodes;
    17041699#endif
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r201205 r201534  
    38183818            float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
    38193819            if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
    3820                 document().addAutoSizingNode(*text.textNode(), candidateNewSize);
     3820                document().addAutoSizedNode(*text.textNode(), candidateNewSize);
    38213821        }
    38223822
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r201205 r201534  
    22152215
    22162216    // Remove style from auto-sizing table that are no longer valid.
    2217     document->validateAutoSizingNodes();
     2217    document->updateAutoSizedNodes();
    22182218}
    22192219
     
    22262226    LOG(TextAutosizing, "RenderElement::resetTextAutosizing()");
    22272227
    2228     document->resetAutoSizingNodes();
     2228    document->clearAutoSizedNodes();
    22292229
    22302230    Vector<int> depthStack;
  • trunk/Source/WebCore/rendering/TextAutoSizing.cpp

    r201104 r201534  
    4949
    5050TextAutoSizingKey::TextAutoSizingKey(DeletedTag)
    51     : m_isDeleted(true)
    52 {
    53 }
    54 
    55 TextAutoSizingKey::TextAutoSizingKey(const RenderStyle* style)
    56     : m_style(style ? RenderStyle::clonePtr(*style) : nullptr)
    57 {
    58 }
    59 
    60 int TextAutoSizingValue::numNodes() const
    61 {
    62     return m_autoSizedNodes.size();
    63 }
    64 
    65 void TextAutoSizingValue::addNode(Text& node, float size)
     51{
     52    HashTraits<std::unique_ptr<RenderStyle>>::constructDeletedValue(m_style);
     53}
     54
     55TextAutoSizingKey::TextAutoSizingKey(const RenderStyle& style, unsigned hash)
     56    : m_style(RenderStyle::clonePtr(style)) // FIXME: This seems very inefficient.
     57    , m_hash(hash)
     58{
     59}
     60
     61void TextAutoSizingValue::addTextNode(Text& node, float size)
    6662{
    6763    node.renderer()->setCandidateComputedTextSize(size);
     
    6965}
    7066
    71 #define MAX_SCALE_INCREASE 1.7f
    72 
    73 bool TextAutoSizingValue::adjustNodeSizes()
    74 {
    75     bool didRemoveObjects = false;
    76 
    77     // Remove stale nodes.  Nodes may have had their renderers detached.  We'll
    78     // also need to remove the style from the documents m_textAutoSizedNodes
    79     // collection.  Return true indicates we need to do that removal.
     67static const float maxScaleIncrease = 1.7f;
     68
     69auto TextAutoSizingValue::adjustTextNodeSizes() -> StillHasNodes
     70{
     71    // Remove stale nodes. Nodes may have had their renderers detached. We'll also need to remove the style from the documents m_textAutoSizedNodes
     72    // collection. Return true indicates we need to do that removal.
    8073    Vector<Text*> nodesForRemoval;
    81     for (auto& node : m_autoSizedNodes) {
    82         auto* text = node->renderer();
    83         if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
    84             nodesForRemoval.append(node.get());
    85             didRemoveObjects = true;
    86         }
     74    for (auto& textNode : m_autoSizedNodes) {
     75        auto* renderer = textNode->renderer();
     76        if (!renderer || !renderer->style().textSizeAdjust().isAuto() || !renderer->candidateComputedTextSize())
     77            nodesForRemoval.append(textNode.get());
    8778    }
    8879
     
    9081        m_autoSizedNodes.remove(node);
    9182
    92     // If we only have one piece of text with the style on the page don't
    93     // adjust it's size.
     83    StillHasNodes stillHasNodes = m_autoSizedNodes.isEmpty() ? StillHasNodes::No : StillHasNodes::Yes;
     84
     85    // If we only have one piece of text with the style on the page don't adjust it's size.
    9486    if (m_autoSizedNodes.size() <= 1)
    95         return didRemoveObjects;
    96 
    97     // Compute average size
     87        return stillHasNodes;
     88
     89    // Compute average size.
    9890    float cumulativeSize = 0;
    9991    for (auto& node : m_autoSizedNodes)
    10092        cumulativeSize += node->renderer()->candidateComputedTextSize();
    10193
    102     float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
    103 
    104     // Adjust sizes
     94    float averageSize = std::round(cumulativeSize / m_autoSizedNodes.size());
     95
     96    // Adjust sizes.
    10597    bool firstPass = true;
    10698    for (auto& node : m_autoSizedNodes) {
    107         auto* text = node->renderer();
    108         if (!text || text->style().fontDescription().computedSize() == averageSize)
    109             continue;
    110 
    111         float specifiedSize = text->style().fontDescription().specifiedSize();
     99        auto& renderer = *node->renderer();
     100        if (renderer.style().fontDescription().computedSize() == averageSize)
     101            continue;
     102
     103        float specifiedSize = renderer.style().fontDescription().specifiedSize();
    112104        float scaleChange = averageSize / specifiedSize;
    113         if (scaleChange > MAX_SCALE_INCREASE && firstPass) {
     105        if (scaleChange > maxScaleIncrease && firstPass) {
    114106            firstPass = false;
    115             averageSize = roundf(specifiedSize * MAX_SCALE_INCREASE);
     107            averageSize = std::round(specifiedSize * maxScaleIncrease);
    116108            scaleChange = averageSize / specifiedSize;
    117109        }
     
    119111        LOG(TextAutosizing, "  adjust node size %p firstPass=%d averageSize=%f scaleChange=%f", node.get(), firstPass, averageSize, scaleChange);
    120112
    121         auto* parentRenderer = text->parent();
    122 
    123         auto style = cloneRenderStyleWithState(text->style());
     113        auto* parentRenderer = renderer.parent();
     114
     115        auto style = cloneRenderStyleWithState(renderer.style());
    124116        auto fontDescription = style.fontDescription();
    125117        fontDescription.setComputedSize(averageSize);
     
    162154    }
    163155
    164     return didRemoveObjects;
     156    return stillHasNodes;
     157}
     158
     159TextAutoSizingValue::~TextAutoSizingValue()
     160{
     161    reset();
    165162}
    166163
     
    168165{
    169166    for (auto& node : m_autoSizedNodes) {
    170         auto* text = node->renderer();
    171         if (!text)
    172             continue;
    173 
    174         auto* parentRenderer = text->parent();
     167        auto* renderer = node->renderer();
     168        if (!renderer)
     169            continue;
     170
     171        auto* parentRenderer = renderer->parent();
    175172        if (!parentRenderer)
    176173            continue;
    177174
    178175        // Reset the font size back to the original specified size
    179         auto fontDescription = text->style().fontDescription();
     176        auto fontDescription = renderer->style().fontDescription();
    180177        float originalSize = fontDescription.specifiedSize();
    181178        if (fontDescription.computedSize() != originalSize) {
    182179            fontDescription.setComputedSize(originalSize);
    183             auto style = cloneRenderStyleWithState(text->style());
     180            auto style = cloneRenderStyleWithState(renderer->style());
    184181            style.setFontDescription(fontDescription);
    185182            style.fontCascade().update(&node->document().fontSelector());
  • trunk/Source/WebCore/rendering/TextAutoSizing.h

    r201104 r201534  
    2424 */
    2525
    26 #ifndef TextAutoSizing_h
    27 #define TextAutoSizing_h
     26#pragma once
    2827
    2928#if ENABLE(IOS_TEXT_AUTOSIZING)
     
    3938class Text;
    4039
     40// FIXME: We can probably get rid of this class entirely and use std::unique_ptr<RenderStyle> as key
     41// as long as we use the right hash traits.
    4142class TextAutoSizingKey {
    4243public:
     
    4445    enum DeletedTag { Deleted };
    4546    explicit TextAutoSizingKey(DeletedTag);
    46     explicit TextAutoSizingKey(const RenderStyle*);
    47     TextAutoSizingKey(TextAutoSizingKey&&) = default;
     47    TextAutoSizingKey(const RenderStyle&, unsigned hash);
    4848
    49     TextAutoSizingKey& operator=(TextAutoSizingKey&&) = default;
     49    const RenderStyle* style() const { ASSERT(!isDeleted()); return m_style.get(); }
     50    bool isDeleted() const { return HashTraits<std::unique_ptr<RenderStyle>>::isDeletedValue(m_style); }
    5051
    51     const RenderStyle* style() const { return m_style.get(); }
    52     inline bool isDeleted() const { return m_isDeleted; }
     52    unsigned hash() const { return m_hash; }
    5353
    5454private:
    5555    std::unique_ptr<RenderStyle> m_style;
    56     bool m_isDeleted { false };
     56    unsigned m_hash { 0 };
    5757};
    5858
     
    6363    if (!a.style() || !b.style())
    6464        return a.style() == b.style();
    65     return a.style()->equalForTextAutosizing(b.style());
     65    return a.style()->equalForTextAutosizing(*b.style());
    6666}
    6767
    6868struct TextAutoSizingHash {
    69     static unsigned hash(const TextAutoSizingKey& key) { return key.style()->hashForTextAutosizing(); }
     69    static unsigned hash(const TextAutoSizingKey& key) { return key.hash(); }
    7070    static bool equal(const TextAutoSizingKey& a, const TextAutoSizingKey& b) { return a == b; }
    7171    static const bool safeToCompareToEmptyOrDeleted = true;
    7272};
    7373
    74 class TextAutoSizingValue : public RefCounted<TextAutoSizingValue> {
    75 public:
    76     static Ref<TextAutoSizingValue> create()
     74struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
     75    static const bool emptyValueIsZero = true;
     76    static void constructDeletedValue(TextAutoSizingKey& slot)
    7777    {
    78         return adoptRef(*new TextAutoSizingValue);
     78        new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
     79    }
     80    static bool isDeletedValue(const TextAutoSizingKey& value)
     81    {
     82        return value.isDeleted();
     83    }
     84};
     85
     86struct TextAutoSizingHashTranslator {
     87    static unsigned hash(const RenderStyle& style)
     88    {
     89        return style.hashForTextAutosizing();
    7990    }
    8091
    81     void addNode(Text&, float size);
    82     bool adjustNodeSizes();
    83     int numNodes() const;
     92    static bool equal(const TextAutoSizingKey& key, const RenderStyle& style)
     93    {
     94        if (key.isDeleted() || !key.style())
     95            return false;
     96        return key.style()->equalForTextAutosizing(style);
     97    }
     98
     99    static void translate(TextAutoSizingKey& key, const RenderStyle& style, unsigned hash)
     100    {
     101        key = { style, hash };
     102    }
     103};
     104
     105class TextAutoSizingValue {
     106    WTF_MAKE_FAST_ALLOCATED;
     107public:
     108    TextAutoSizingValue() = default;
     109    ~TextAutoSizingValue();
     110
     111    void addTextNode(Text&, float size);
     112
     113    enum class StillHasNodes { No, Yes };
     114    StillHasNodes adjustTextNodeSizes();
     115
     116private:
    84117    void reset();
    85 private:
    86     TextAutoSizingValue() { }
     118
    87119    HashSet<RefPtr<Text>> m_autoSizedNodes;
    88120};
     
    91123
    92124#endif // ENABLE(IOS_TEXT_AUTOSIZING)
    93 
    94 #endif // TextAutoSizing_h
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r201498 r201534  
    412412}
    413413
    414 bool RenderStyle::equalForTextAutosizing(const RenderStyle* other) const
    415 {
    416     return rareNonInheritedData->m_appearance == other->rareNonInheritedData->m_appearance
    417         && rareNonInheritedData->marginBeforeCollapse == other->rareNonInheritedData->marginBeforeCollapse
    418         && rareNonInheritedData->marginAfterCollapse == other->rareNonInheritedData->marginAfterCollapse
    419         && rareNonInheritedData->lineClamp == other->rareNonInheritedData->lineClamp
    420         && rareInheritedData->textSizeAdjust == other->rareInheritedData->textSizeAdjust
    421         && rareInheritedData->overflowWrap == other->rareInheritedData->overflowWrap
    422         && rareInheritedData->nbspMode == other->rareInheritedData->nbspMode
    423         && rareInheritedData->lineBreak == other->rareInheritedData->lineBreak
    424         && rareInheritedData->textSecurity == other->rareInheritedData->textSecurity
    425         && inherited->specifiedLineHeight == other->inherited->specifiedLineHeight
    426         && inherited->fontCascade.equalForTextAutoSizing(other->inherited->fontCascade)
    427         && inherited->horizontal_border_spacing == other->inherited->horizontal_border_spacing
    428         && inherited->vertical_border_spacing == other->inherited->vertical_border_spacing
    429         && inherited_flags._box_direction == other->inherited_flags._box_direction
    430         && inherited_flags.m_rtlOrdering == other->inherited_flags.m_rtlOrdering
    431         && noninherited_flags.position() == other->noninherited_flags.position()
    432         && noninherited_flags.floating() == other->noninherited_flags.floating()
    433         && rareNonInheritedData->textOverflow == other->rareNonInheritedData->textOverflow;
     414bool RenderStyle::equalForTextAutosizing(const RenderStyle& other) const
     415{
     416    return rareNonInheritedData->m_appearance == other.rareNonInheritedData->m_appearance
     417        && rareNonInheritedData->marginBeforeCollapse == other.rareNonInheritedData->marginBeforeCollapse
     418        && rareNonInheritedData->marginAfterCollapse == other.rareNonInheritedData->marginAfterCollapse
     419        && rareNonInheritedData->lineClamp == other.rareNonInheritedData->lineClamp
     420        && rareInheritedData->textSizeAdjust == other.rareInheritedData->textSizeAdjust
     421        && rareInheritedData->overflowWrap == other.rareInheritedData->overflowWrap
     422        && rareInheritedData->nbspMode == other.rareInheritedData->nbspMode
     423        && rareInheritedData->lineBreak == other.rareInheritedData->lineBreak
     424        && rareInheritedData->textSecurity == other.rareInheritedData->textSecurity
     425        && inherited->specifiedLineHeight == other.inherited->specifiedLineHeight
     426        && inherited->fontCascade.equalForTextAutoSizing(other.inherited->fontCascade)
     427        && inherited->horizontal_border_spacing == other.inherited->horizontal_border_spacing
     428        && inherited->vertical_border_spacing == other.inherited->vertical_border_spacing
     429        && inherited_flags._box_direction == other.inherited_flags._box_direction
     430        && inherited_flags.m_rtlOrdering == other.inherited_flags.m_rtlOrdering
     431        && noninherited_flags.position() == other.noninherited_flags.position()
     432        && noninherited_flags.floating() == other.noninherited_flags.floating()
     433        && rareNonInheritedData->textOverflow == other.rareNonInheritedData->textOverflow;
    434434}
    435435
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r201498 r201534  
    18631863#if ENABLE(IOS_TEXT_AUTOSIZING)
    18641864    uint32_t hashForTextAutosizing() const;
    1865     bool equalForTextAutosizing(const RenderStyle *other) const;
     1865    bool equalForTextAutosizing(const RenderStyle&) const;
    18661866#endif
    18671867
Note: See TracChangeset for help on using the changeset viewer.