Changeset 87801 in webkit


Ignore:
Timestamp:
Jun 1, 2011 7:10:15 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

2011-06-01 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Rob Buis.

Remove duplicated code in various computeReplacedLogical*() functions
https://bugs.webkit.org/show_bug.cgi?id=61860

Centralize this calculation in RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth:
int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());

int maxLogicalWidth = !includeMaxWidth
style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());

return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));

Centralize this calculation in RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight:
int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));

Use the new helper methods where possible, deduplicating lots of code.

  • rendering/RenderBox.cpp: (WebCore::RenderBox::computeReplacedLogicalWidth): (WebCore::RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth): (WebCore::RenderBox::computeReplacedLogicalHeight): (WebCore::RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight):
  • rendering/RenderBox.h:
  • rendering/RenderImage.cpp: (WebCore::RenderImage::computeReplacedLogicalWidth): (WebCore::RenderImage::computeReplacedLogicalHeight):
  • rendering/RenderPart.cpp: (WebCore::RenderPart::computeEmbeddedDocumentReplacedWidth): (WebCore::RenderPart::computeEmbeddedDocumentReplacedHeight): (WebCore::RenderPart::computeReplacedLogicalWidth): (WebCore::RenderPart::computeReplacedLogicalHeight):
  • rendering/RenderPart.h:
  • rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::computeReplacedLogicalWidth): (WebCore::RenderReplaced::computeReplacedLogicalHeight):
  • rendering/svg/RenderSVGRoot.cpp: (WebCore::RenderSVGRoot::computeReplacedLogicalWidth): (WebCore::RenderSVGRoot::computeReplacedLogicalHeight):
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87799 r87801  
     12011-06-01  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Rob Buis.
     4
     5        Remove duplicated code in various computeReplacedLogical*() functions
     6        https://bugs.webkit.org/show_bug.cgi?id=61860
     7
     8        Centralize this calculation in RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth:
     9        int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
     10        int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
     11        return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
     12
     13        Centralize this calculation in RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight:
     14        int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
     15        int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
     16        return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
     17
     18        Use the new helper methods where possible, deduplicating lots of code.
     19
     20        * rendering/RenderBox.cpp:
     21        (WebCore::RenderBox::computeReplacedLogicalWidth):
     22        (WebCore::RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth):
     23        (WebCore::RenderBox::computeReplacedLogicalHeight):
     24        (WebCore::RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight):
     25        * rendering/RenderBox.h:
     26        * rendering/RenderImage.cpp:
     27        (WebCore::RenderImage::computeReplacedLogicalWidth):
     28        (WebCore::RenderImage::computeReplacedLogicalHeight):
     29        * rendering/RenderPart.cpp:
     30        (WebCore::RenderPart::computeEmbeddedDocumentReplacedWidth):
     31        (WebCore::RenderPart::computeEmbeddedDocumentReplacedHeight):
     32        (WebCore::RenderPart::computeReplacedLogicalWidth):
     33        (WebCore::RenderPart::computeReplacedLogicalHeight):
     34        * rendering/RenderPart.h:
     35        * rendering/RenderReplaced.cpp:
     36        (WebCore::RenderReplaced::computeReplacedLogicalWidth):
     37        (WebCore::RenderReplaced::computeReplacedLogicalHeight):
     38        * rendering/svg/RenderSVGRoot.cpp:
     39        (WebCore::RenderSVGRoot::computeReplacedLogicalWidth):
     40        (WebCore::RenderSVGRoot::computeReplacedLogicalHeight):
     41
    1422011-06-01  Sheriff Bot  <webkit.review.bot@gmail.com>
    243
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r87467 r87801  
    19461946int RenderBox::computeReplacedLogicalWidth(bool includeMaxWidth) const
    19471947{
    1948     int logicalWidth = computeReplacedLogicalWidthUsing(style()->logicalWidth());
     1948    return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogicalWidthUsing(style()->logicalWidth()), includeMaxWidth);
     1949}
     1950
     1951int RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth(int logicalWidth, bool includeMaxWidth) const
     1952{
    19491953    int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
    19501954    int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
    1951 
    19521955    return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
    19531956}
     
    19741977int RenderBox::computeReplacedLogicalHeight() const
    19751978{
    1976     int logicalHeight = computeReplacedLogicalHeightUsing(style()->logicalHeight());
     1979    return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLogicalHeightUsing(style()->logicalHeight()));
     1980}
     1981
     1982int RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight(int logicalHeight) const
     1983{
    19771984    int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
    19781985    int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
    1979 
    19801986    return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
    19811987}
  • trunk/Source/WebCore/rendering/RenderBox.h

    r87467 r87801  
    309309    int computeLogicalHeightUsing(const Length& height);
    310310    int computeReplacedLogicalWidthUsing(Length width) const;
     311    int computeReplacedLogicalWidthRespectingMinMaxWidth(int logicalWidth, bool includeMaxWidth = true) const;
    311312    int computeReplacedLogicalHeightUsing(Length height) const;
     313    int computeReplacedLogicalHeightRespectingMinMaxHeight(int logicalHeight) const;
    312314
    313315    virtual int computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r87152 r87801  
    478478        logicalWidth = calcAspectRatioLogicalWidth();
    479479
    480     int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
    481     int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
    482 
    483     return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
     480    return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, includeMaxWidth);
    484481}
    485482
     
    497494        logicalHeight = calcAspectRatioLogicalHeight();
    498495
    499     int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
    500     int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
    501 
    502     return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
     496    return computeReplacedLogicalHeightRespectingMinMaxHeight(logicalHeight);
    503497}
    504498
  • trunk/Source/WebCore/rendering/RenderPart.cpp

    r87779 r87801  
    113113}
    114114
    115 int RenderPart::computeEmbeddedDocumentReplacedWidth(bool includeMaxWidth, RenderStyle* contentRenderStyle) const
    116 {
    117     int logicalWidth = computeReplacedLogicalWidthUsing(contentRenderStyle->logicalWidth());
    118     int minLogicalWidth = computeReplacedLogicalWidthUsing(contentRenderStyle->logicalMinWidth());
    119     int maxLogicalWidth = !includeMaxWidth || contentRenderStyle->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(contentRenderStyle->logicalMaxWidth());
    120     int width = max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
    121     return width;
    122 }
    123 
    124 int RenderPart::computeEmbeddedDocumentReplacedHeight(RenderStyle* contentRenderStyle) const
    125 {
    126     int logicalHeight = computeReplacedLogicalHeightUsing(contentRenderStyle->logicalHeight());
    127     int minLogicalHeight = computeReplacedLogicalHeightUsing(contentRenderStyle->logicalMinHeight());
    128     int maxLogicalHeight = contentRenderStyle->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(contentRenderStyle->logicalMaxHeight());
    129     int height = max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
    130     return height;
     115int RenderPart::computeEmbeddedDocumentReplacedWidth(RenderSVGRoot* contentRenderer, bool includeMaxWidth) const
     116{
     117    ASSERT(contentRenderer);
     118    ASSERT(contentRenderer->style());
     119    return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogicalWidthUsing(contentRenderer->style()->logicalWidth()), includeMaxWidth);
     120}
     121
     122int RenderPart::computeEmbeddedDocumentReplacedHeight(RenderSVGRoot* contentRenderer) const
     123{
     124    ASSERT(contentRenderer);
     125    ASSERT(contentRenderer->style());
     126    return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLogicalHeightUsing(contentRenderer->style()->logicalHeight()));
    131127}
    132128
     
    150146        // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.
    151147        if (heightIsAuto && hasIntrinsicWidth)
    152             return computeEmbeddedDocumentReplacedWidth(includeMaxWidth, contentRenderStyle);
     148            return computeEmbeddedDocumentReplacedWidth(contentRenderer, includeMaxWidth);
    153149   
    154150        bool hasIntrinsicHeight = contentRenderStyle->height().isFixed();
     
    176172        // Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'.
    177173        if (hasIntrinsicWidth)
    178             return computeEmbeddedDocumentReplacedWidth(includeMaxWidth, contentRenderStyle);
     174            return computeEmbeddedDocumentReplacedWidth(contentRenderer, includeMaxWidth);
    179175    }
    180176
     
    203199        // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
    204200        if (widthIsAuto && hasIntrinsicHeight)
    205             return computeEmbeddedDocumentReplacedHeight(contentRenderStyle);
     201            return computeEmbeddedDocumentReplacedHeight(contentRenderer);
    206202   
    207203        // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic ratio then the used value of 'height' is:
     
    214210        // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic height, then that intrinsic height is the used value of 'height'.
    215211        if (hasIntrinsicHeight)
    216             return computeEmbeddedDocumentReplacedHeight(contentRenderStyle);
     212            return computeEmbeddedDocumentReplacedHeight(contentRenderer);
    217213    }
    218214
  • trunk/Source/WebCore/rendering/RenderPart.h

    r87526 r87801  
    5050#if ENABLE(SVG)
    5151    RenderSVGRoot* embeddedSVGContentRenderer() const;
    52     int computeEmbeddedDocumentReplacedWidth(bool includeMaxWidth, RenderStyle* contentRenderStyle) const;
    53     int computeEmbeddedDocumentReplacedHeight(RenderStyle* contentRenderStyle) const;
     52    int computeEmbeddedDocumentReplacedWidth(RenderSVGRoot* contentRenderer, bool includeMaxWidth) const;
     53    int computeEmbeddedDocumentReplacedHeight(RenderSVGRoot* contentRenderer) const;
    5454    virtual int computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
    5555    virtual int computeReplacedLogicalHeight() const;
  • trunk/Source/WebCore/rendering/RenderReplaced.cpp

    r87526 r87801  
    203203        logicalWidth = intrinsicLogicalWidth();
    204204
    205     int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
    206     int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
    207 
    208     return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
     205    return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, includeMaxWidth);
    209206}
    210207
     
    219216        logicalHeight = intrinsicLogicalHeight();
    220217
    221     int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
    222     int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
    223 
    224     return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
     218    return computeReplacedLogicalHeightRespectingMinMaxHeight(logicalHeight);
    225219}
    226220
  • trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp

    r87779 r87801  
    191191    //
    192192    // Under these conditions, the positioning properties establish the viewport's width.
    193     int logicalWidth = ownerRenderer->computeReplacedLogicalWidthUsing(ownerWidth);
    194     int minLogicalWidth = ownerRenderer->computeReplacedLogicalWidthUsing(ownerRendererStyle->logicalMinWidth());
    195     int maxLogicalWidth = !includeMaxWidth || ownerRendererStyle->logicalMaxWidth().isUndefined() ? logicalWidth : ownerRenderer->computeReplacedLogicalWidthUsing(ownerRendererStyle->logicalMaxWidth());
    196     return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
     193    return ownerRenderer->computeReplacedLogicalWidthRespectingMinMaxWidth(ownerRenderer->computeReplacedLogicalWidthUsing(ownerWidth), includeMaxWidth);
    197194}
    198195
     
    223220    // are sufficient to establish the height of the viewport, then these positioning properties establish the viewport's height;
    224221    // otherwise, the ‘height’ attribute on the outermost svg element establishes the viewport's height.
    225     int logicalHeight = ownerRenderer->computeReplacedLogicalHeightUsing(ownerHeight);
    226     int minLogicalHeight = ownerRenderer->computeReplacedLogicalHeightUsing(ownerRendererStyle->logicalMinHeight());
    227     int maxLogicalHeight = ownerRendererStyle->logicalMaxHeight().isUndefined() ? logicalHeight : ownerRenderer->computeReplacedLogicalHeightUsing(ownerRendererStyle->logicalMaxHeight());
    228     return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
     222    return ownerRenderer->computeReplacedLogicalHeightRespectingMinMaxHeight(ownerRenderer->computeReplacedLogicalHeightUsing(ownerHeight));
    229223}
    230224
Note: See TracChangeset for help on using the changeset viewer.