Changeset 220685 in webkit


Ignore:
Timestamp:
Aug 14, 2017 6:20:47 AM (7 years ago)
Author:
Antti Koivisto
Message:

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:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220646 r220685  
     12017-08-14  Antti Koivisto  <antti@apple.com>
     2
     3        Factor text autosizing into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=175530
     5
     6        Reviewed by Andreas Kling.
     7
     8        Move the remaining parts out of Document.
     9
     10        * css/StyleBuilderCustom.h:
     11        (WebCore::computeLineHeightMultiplierDueToFontSize):
     12        * dom/Document.cpp:
     13        (WebCore::Document::destroyRenderTree):
     14        (WebCore::Document::textAutoSizing):
     15        (WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted.
     16        (WebCore::TextAutoSizingTraits::isDeletedValue): Deleted.
     17        (WebCore::Document::addAutoSizedNode): Deleted.
     18        (WebCore::Document::updateAutoSizedNodes): Deleted.
     19        (WebCore::Document::clearAutoSizedNodes): Deleted.
     20        * dom/Document.h:
     21        * rendering/RenderBlockFlow.cpp:
     22        (WebCore::RenderBlockFlow::adjustComputedFontSizes):
     23        * rendering/RenderElement.cpp:
     24        (WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
     25        (WebCore::RenderElement::resetTextAutosizing):
     26        * rendering/TextAutoSizing.cpp:
     27        (WebCore::TextAutoSizingTraits::constructDeletedValue):
     28        (WebCore::TextAutoSizingTraits::isDeletedValue):
     29        (WebCore::TextAutoSizing::addTextNode):
     30        (WebCore::TextAutoSizing::updateRenderTree):
     31        (WebCore::TextAutoSizing::reset):
     32        * rendering/TextAutoSizing.h:
     33
    1342017-08-14  Antti Koivisto  <antti@apple.com>
    235
  • trunk/Source/WebCore/css/StyleBuilderCustom.h

    r219665 r220685  
    681681
    682682                // This calculation matches the line-height computed size calculation in
    683                 // TextAutoSizingValue::adjustTextNodeSizes().
     683                // TextAutoSizing::Value::adjustTextNodeSizes().
    684684                auto scaleChange = minimumFontSize / specifiedFontSize;
    685685                return scaleChange;
  • trunk/Source/WebCore/dom/Document.cpp

    r220539 r220685  
    428428}
    429429
    430 #if ENABLE(TEXT_AUTOSIZING)
    431 
    432 void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot)
    433 {
    434     new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);
    435 }
    436 
    437 bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value)
    438 {
    439     return value.isDeleted();
    440 }
    441 
    442 #endif
    443 
    444430uint64_t Document::s_globalTreeVersion = 0;
    445431
     
    22652251
    22662252#if ENABLE(TEXT_AUTOSIZING)
    2267     // Do this before the arena is cleared, which is needed to deref the RenderStyle on TextAutoSizingKey.
    2268     m_textAutoSizedNodes.clear();
     2253    m_textAutoSizing = nullptr;
    22692254#endif
    22702255
     
    55595544
    55605545#if ENABLE(TEXT_AUTOSIZING)
    5561 
    5562 void Document::addAutoSizedNode(Text& node, float candidateSize)
    5563 {
    5564     LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize);
    5565     auto addResult = m_textAutoSizedNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr);
    5566     if (addResult.isNewEntry)
    5567         addResult.iterator->value = std::make_unique<TextAutoSizingValue>();
    5568     addResult.iterator->value->addTextNode(node, candidateSize);
    5569 }
    5570 
    5571 void Document::updateAutoSizedNodes()
    5572 {
    5573     m_textAutoSizedNodes.removeIf([](auto& keyAndValue) {
    5574         return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
    5575     });
    5576 }
    5577    
    5578 void Document::clearAutoSizedNodes()
    5579 {
    5580     m_textAutoSizedNodes.clear();
    5581 }
    5582 
     5546TextAutoSizing& Document::textAutoSizing()
     5547{
     5548    if (!m_textAutoSizing)
     5549        m_textAutoSizing = std::make_unique<TextAutoSizing>();
     5550    return *m_textAutoSizing;
     5551}
    55835552#endif // ENABLE(TEXT_AUTOSIZING)
    55845553
  • trunk/Source/WebCore/dom/Document.h

    r220539 r220685  
    208208
    209209#if ENABLE(TEXT_AUTOSIZING)
    210 struct TextAutoSizingHash;
    211 class TextAutoSizingKey;
    212 class TextAutoSizingValue;
    213 
    214 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
    215     static const bool emptyValueIsZero = true;
    216     static void constructDeletedValue(TextAutoSizingKey& slot);
    217     static bool isDeletedValue(const TextAutoSizingKey& value);
    218 };
     210class TextAutoSizing;
    219211#endif
    220212
     
    13631355    void releaseEvents() { }
    13641356
     1357#if ENABLE(TEXT_AUTOSIZING)
     1358    TextAutoSizing& textAutoSizing();
     1359#endif
     1360
    13651361protected:
    13661362    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     
    16661662
    16671663#if ENABLE(TEXT_AUTOSIZING)
    1668 public:
    1669     void addAutoSizedNode(Text&, float size);
    1670     void updateAutoSizedNodes();
    1671     void clearAutoSizedNodes();
    1672 
    1673 private:
    1674     using TextAutoSizingMap = HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits>;
    1675     TextAutoSizingMap m_textAutoSizedNodes;
     1664    std::unique_ptr<TextAutoSizing> m_textAutoSizing;
    16761665#endif
    16771666
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r220535 r220685  
    5454#include "SimpleLineLayoutFunctions.h"
    5555#include "SimpleLineLayoutPagination.h"
     56#include "TextAutoSizing.h"
    5657#include "VerticalPositionCache.h"
    5758#include "VisiblePosition.h"
     
    39073908            float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
    39083909            if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
    3909                 document().addAutoSizedNode(*text.textNode(), candidateNewSize);
     3910                document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize);
    39103911        }
    39113912
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r220073 r220685  
    7575#include "StylePendingResources.h"
    7676#include "StyleResolver.h"
     77#include "TextAutoSizing.h"
    7778#include <wtf/MathExtras.h>
    7879#include <wtf/StackStats.h>
     
    23152316
    23162317    // Remove style from auto-sizing table that are no longer valid.
    2317     document->updateAutoSizedNodes();
     2318    document->textAutoSizing().updateRenderTree();
    23182319}
    23192320
     
    23262327    LOG(TextAutosizing, "RenderElement::resetTextAutosizing()");
    23272328
    2328     document->clearAutoSizedNodes();
     2329    document->textAutoSizing().reset();
    23292330
    23302331    Vector<int> depthStack;
  • trunk/Source/WebCore/rendering/TextAutoSizing.cpp

    r220646 r220685  
    216216}
    217217
     218void TextAutoSizing::addTextNode(Text& node, float candidateSize)
     219{
     220    LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize);
     221    auto addResult = m_textNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr);
     222    if (addResult.isNewEntry)
     223        addResult.iterator->value = std::make_unique<TextAutoSizingValue>();
     224    addResult.iterator->value->addTextNode(node, candidateSize);
     225}
     226
     227void TextAutoSizing::updateRenderTree()
     228{
     229    m_textNodes.removeIf([](auto& keyAndValue) {
     230        return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No;
     231    });
     232}
     233
     234void TextAutoSizing::reset()
     235{
     236    m_textNodes.clear();
     237}
     238
    218239} // namespace WebCore
    219240
  • trunk/Source/WebCore/rendering/TextAutoSizing.h

    r206395 r220685  
    2929
    3030#include "RenderStyle.h"
     31#include <wtf/HashMap.h>
    3132#include <wtf/HashSet.h>
    3233#include <wtf/RefCounted.h>
     
    108109};
    109110
     111struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> {
     112    static const bool emptyValueIsZero = true;
     113    static void constructDeletedValue(TextAutoSizingKey& slot) { new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); }
     114    static bool isDeletedValue(const TextAutoSizingKey& value) { return value.isDeleted(); }
     115};
     116
     117class TextAutoSizing {
     118    WTF_MAKE_FAST_ALLOCATED;
     119public:
     120    TextAutoSizing() = default;
     121
     122    void addTextNode(Text&, float size);
     123    void updateRenderTree();
     124    void reset();
     125
     126private:
     127    HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> m_textNodes;
     128};
     129
    110130} // namespace WebCore
    111131
Note: See TracChangeset for help on using the changeset viewer.