Changeset 200593 in webkit


Ignore:
Timestamp:
May 9, 2016 2:57:43 PM (8 years ago)
Author:
Simon Fraser
Message:

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

Reviewed by Zalan Bujtas.

Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
to take references.

Use downcast<> more.

Whitespace cleanup.

  • rendering/RenderBlockFlow.cpp:

(WebCore::isNonBlocksOrNonFixedHeightListItems):

  • rendering/RenderElement.cpp:

(WebCore::includeNonFixedHeight):

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::traverseNext):

  • rendering/RenderObject.h:
  • rendering/TextAutoSizing.cpp:

(WebCore::TextAutoSizingValue::adjustNodeSizes):
(WebCore::TextAutoSizingValue::reset):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r200591 r200593  
     12016-05-09  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Clean up iOS text autosizing code
     4        https://bugs.webkit.org/show_bug.cgi?id=157489
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
     9        to take references.
     10       
     11        Use downcast<> more.
     12       
     13        Whitespace cleanup.
     14
     15        * rendering/RenderBlockFlow.cpp:
     16        (WebCore::isNonBlocksOrNonFixedHeightListItems):
     17        * rendering/RenderElement.cpp:
     18        (WebCore::includeNonFixedHeight):
     19        * rendering/RenderObject.cpp:
     20        (WebCore::RenderObject::traverseNext):
     21        * rendering/RenderObject.h:
     22        * rendering/TextAutoSizing.cpp:
     23        (WebCore::TextAutoSizingValue::adjustNodeSizes):
     24        (WebCore::TextAutoSizingValue::reset):
     25
    1262016-05-09  Anders Carlsson  <andersca@apple.com>
    227
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r200534 r200593  
    37403740}
    37413741
    3742 static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render)
    3743 {
    3744     if (!render->isRenderBlock())
     3742static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& render)
     3743{
     3744    if (!render.isRenderBlock())
    37453745        return true;
    3746     if (render->isListItem())
    3747         return render->style().height().type() != Fixed;
     3746    if (render.isListItem())
     3747        return render.style().height().type() != Fixed;
    37483748    return false;
    37493749}
     
    37913791    for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
    37923792        if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
    3793             RenderText& text = downcast<RenderText>(*descendent);
     3793            auto& text = downcast<RenderText>(*descendent);
    37943794            auto& oldStyle = text.style();
    37953795            auto fontDescription = oldStyle.fontDescription();
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r200588 r200593  
    21702170
    21712171#if ENABLE(IOS_TEXT_AUTOSIZING)
    2172 static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject* renderer)
    2173 {
    2174     const RenderStyle& style = renderer->style();
     2172static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject& renderer)
     2173{
     2174    const RenderStyle& style = renderer.style();
    21752175    if (style.height().type() == Fixed) {
    2176         if (is<RenderBlock>(*renderer)) {
     2176        if (is<RenderBlock>(renderer)) {
    21772177            // For fixed height styles, if the overflow size of the element spills out of the specified
    21782178            // height, assume we can apply text auto-sizing.
    21792179            if (style.overflowY() == OVISIBLE
    2180                 && style.height().value() < downcast<RenderBlock>(renderer)->layoutOverflowRect().maxY())
     2180                && style.height().value() < downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())
    21812181                return RenderObject::OverflowHeight;
    21822182        }
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r200534 r200593  
    326326    // Check for suitable children.
    327327    for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
    328         overflowType = inclusionFunction(child);
     328        overflowType = inclusionFunction(*child);
    329329        if (overflowType != FixedHeight) {
    330330            currentDepth++;
     
    350350            return nullptr;
    351351        for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
    352             overflowType = inclusionFunction(sibling);
     352            overflowType = inclusionFunction(*sibling);
    353353            if (overflowType != FixedHeight) {
    354354                if (overflowType == OverflowHeight)
     
    370370{
    371371    for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
    372         if (inclusionFunction(child)) {
     372        if (inclusionFunction(*child)) {
    373373            ASSERT(!stayWithin || child->isDescendantOf(stayWithin));
    374374            return child;
     
    380380
    381381    for (RenderObject* sibling = nextSibling(); sibling; sibling = sibling->nextSibling()) {
    382         if (inclusionFunction(sibling)) {
     382        if (inclusionFunction(*sibling)) {
    383383            ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin));
    384384            return sibling;
     
    392392        if (n) {
    393393            for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
    394                 if (inclusionFunction(sibling)) {
     394                if (inclusionFunction(*sibling)) {
    395395                    ASSERT(!stayWithin || !n->nextSibling() || n->nextSibling()->isDescendantOf(stayWithin));
    396396                    return sibling;
  • trunk/Source/WebCore/rendering/RenderObject.h

    r200534 r200593  
    191191
    192192    RenderObject* traverseNext(const RenderObject* stayWithin) const;
    193     typedef bool (*TraverseNextInclusionFunction)(const RenderObject*);
    194     typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject*);
     193    typedef bool (*TraverseNextInclusionFunction)(const RenderObject&);
     194    typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject&);
    195195
    196196    RenderObject* traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction) const;
  • trunk/Source/WebCore/rendering/TextAutoSizing.cpp

    r200534 r200593  
    7575{
    7676    bool objectsRemoved = false;
    77    
     77
    7878    // Remove stale nodes.  Nodes may have had their renderers detached.  We'll
    7979    // also need to remove the style from the documents m_textAutoSizedNodes
     
    8181    Vector<RefPtr<Node> > nodesForRemoval;
    8282    for (auto& autoSizingNode : m_autoSizedNodes) {
    83         RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
     83        auto* text = downcast<RenderText>(autoSizingNode->renderer());
    8484        if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
    8585            // remove node.
     
    8888        }
    8989    }
    90    
     90
    9191    for (auto& node : nodesForRemoval)
    9292        m_autoSizedNodes.remove(node);
    93    
     93
    9494    // If we only have one piece of text with the style on the page don't
    9595    // adjust it's size.
    9696    if (m_autoSizedNodes.size() <= 1)
    9797        return objectsRemoved;
    98    
     98
    9999    // Compute average size
    100100    float cumulativeSize = 0;
    101101    for (auto& autoSizingNode : m_autoSizedNodes) {
    102         RenderText* renderText = static_cast<RenderText*>(autoSizingNode->renderer());
    103         cumulativeSize += renderText->candidateComputedTextSize();
    104     }
    105    
     102        RenderText& renderText = downcast<RenderText>(*autoSizingNode->renderer());
     103        cumulativeSize += renderText.candidateComputedTextSize();
     104    }
     105
    106106    float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
    107    
     107
    108108    // Adjust sizes
    109109    bool firstPass = true;
    110110    for (auto& autoSizingNode : m_autoSizedNodes) {
    111         RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
     111        auto* text = downcast<RenderText>(autoSizingNode->renderer());
    112112        if (text && text->style().fontDescription().computedSize() != averageSize) {
    113113            float specifiedSize = text->style().fontDescription().specifiedSize();
     
    127127            style.fontCascade().update(&autoSizingNode->document().fontSelector());
    128128            text->parent()->setStyle(WTFMove(style));
    129            
     129
    130130            RenderElement* parentRenderer = text->parent();
    131131            if (parentRenderer->isAnonymousBlock())
    132132                parentRenderer = parentRenderer->parent();
    133            
     133
    134134            // If we have a list we should resize ListMarkers separately.
    135135            RenderObject* listMarkerRenderer = parentRenderer->firstChild();
     
    140140                downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style));
    141141            }
    142            
     142
    143143            // Resize the line height of the parent.
    144             const RenderStyle& parentStyle = parentRenderer->style();
     144            auto& parentStyle = parentRenderer->style();
    145145            Length lineHeightLength = parentStyle.specifiedLineHeight();
    146            
     146
    147147            int specifiedLineHeight = 0;
    148148            if (lineHeightLength.isPercent())
     
    150150            else
    151151                specifiedLineHeight = lineHeightLength.value();
    152            
     152
    153153            int lineHeight = specifiedLineHeight * scaleChange;
    154154            if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) {
     
    162162        }
    163163    }
    164    
     164
    165165    return objectsRemoved;
    166166}
     
    169169{
    170170    for (auto& autoSizingNode : m_autoSizedNodes) {
    171         RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
     171        auto* text = downcast<RenderText>(autoSizingNode->renderer());
    172172        if (!text)
    173173            continue;
     
    186186        if (!parentRenderer)
    187187            continue;
    188        
     188
    189189        if (parentRenderer->isAnonymousBlock())
    190190            parentRenderer = parentRenderer->parent();
    191        
    192         const RenderStyle& parentStyle = parentRenderer->style();
     191
     192        auto& parentStyle = parentRenderer->style();
    193193        Length originalLineHeight = parentStyle.specifiedLineHeight();
    194194        if (originalLineHeight != parentStyle.lineHeight()) {
Note: See TracChangeset for help on using the changeset viewer.