Changeset 292948 in webkit


Ignore:
Timestamp:
Apr 17, 2022 6:32:42 AM (2 years ago)
Author:
Alan Bujtas
Message:

RenderDeprecatedFlexibleBox::applyLineClamp should use size_t
https://bugs.webkit.org/show_bug.cgi?id=239389

Reviewed by Darin Adler.

Use size_t consistently in applyLineClamp.
While LineClampValue is int based, it can also be a percent type which expands the clamping range to size_t.

getHeightForLineCount -> use size_t and drop the magic -1.
heightForLineCount -> return LayoutUnit instead of int.

  • rendering/RenderDeprecatedFlexibleBox.cpp:

(WebCore::getHeightForLineCount):
(WebCore::heightForLineCount):
(WebCore::RenderDeprecatedFlexibleBox::applyLineClamp):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r292947 r292948  
     12022-04-17  Alan Bujtas  <zalan@apple.com>
     2
     3        RenderDeprecatedFlexibleBox::applyLineClamp should use size_t
     4        https://bugs.webkit.org/show_bug.cgi?id=239389
     5
     6        Reviewed by Darin Adler.
     7
     8        Use size_t consistently in applyLineClamp.
     9        While LineClampValue is int based, it can also be a percent type which expands the clamping range to size_t.
     10
     11        getHeightForLineCount -> use size_t and drop the magic -1.
     12        heightForLineCount -> return LayoutUnit instead of int.
     13
     14        * rendering/RenderDeprecatedFlexibleBox.cpp:
     15        (WebCore::getHeightForLineCount):
     16        (WebCore::heightForLineCount):
     17        (WebCore::RenderDeprecatedFlexibleBox::applyLineClamp):
     18
    1192022-04-16  Ryosuke Niwa  <rniwa@webkit.org>
    220
  • trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp

    r292691 r292948  
    986986}
    987987
    988 static int getHeightForLineCount(const RenderBlockFlow& block, int lineCount, bool includeBottom, int& count)
     988static std::optional<LayoutUnit> getHeightForLineCount(const RenderBlockFlow& block, size_t lineCount, bool includeBottom, size_t& count)
    989989{
    990990    if (block.style().visibility() != Visibility::Visible)
    991         return -1;
     991        return { };
    992992
    993993    if (block.childrenInline()) {
     
    10001000        for (auto* obj = block.firstChildBox(); obj; obj = obj->nextSiblingBox()) {
    10011001            if (is<RenderBlockFlow>(*obj) && shouldIncludeLinesForParentLineCount(downcast<RenderBlockFlow>(*obj))) {
    1002                 int result = getHeightForLineCount(downcast<RenderBlockFlow>(*obj), lineCount, false, count);
    1003                 if (result != -1)
    1004                     return result + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : 0_lu);
     1002                if (auto height = getHeightForLineCount(downcast<RenderBlockFlow>(*obj), lineCount, false, count))
     1003                    return *height + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : 0_lu);
    10051004            } else if (!obj->isFloatingOrOutOfFlowPositioned())
    10061005                normalFlowChildWithoutLines = obj;
     
    10101009    }
    10111010
    1012     return -1;
    1013 }
    1014 
    1015 static int heightForLineCount(const RenderBlockFlow& flow, int lineCount)
    1016 {
    1017     int count = 0;
    1018     return getHeightForLineCount(flow, lineCount, true, count);
     1011    return { };
     1012}
     1013
     1014static LayoutUnit heightForLineCount(const RenderBlockFlow& flow, size_t lineCount)
     1015{
     1016    size_t count = 0;
     1017    if (auto height = getHeightForLineCount(flow, lineCount, true, count))
     1018        return *height;
     1019    return { };
    10191020}
    10201021
     
    10381039void RenderDeprecatedFlexibleBox::applyLineClamp(FlexBoxIterator& iterator, bool relayoutChildren)
    10391040{
    1040     int maxLineCount = 0;
     1041    size_t maxLineCount = 0;
    10411042    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    10421043        if (childDoesNotAffectWidthOrFlexing(child))
     
    10561057        child->layoutIfNeeded();
    10571058        if (child->style().height().isAuto() && is<RenderBlockFlow>(*child))
    1058             maxLineCount = std::max<int>(maxLineCount, lineCountFor(downcast<RenderBlockFlow>(*child)));
     1059            maxLineCount = std::max(maxLineCount, lineCountFor(downcast<RenderBlockFlow>(*child)));
    10591060    }
    10601061
    10611062    // Get the number of lines and then alter all block flow children with auto height to use the
    10621063    // specified height. We always try to leave room for at least one line.
    1063     LineClampValue lineClamp = style().lineClamp();
    1064     int numVisibleLines = lineClamp.isPercentage() ? std::max(1, (maxLineCount + 1) * lineClamp.value() / 100) : lineClamp.value();
     1064    auto lineClamp = style().lineClamp();
     1065    ASSERT(!lineClamp.isNone());
     1066
     1067    size_t numVisibleLines = lineClamp.value();
     1068    if (lineClamp.isPercentage()) {
     1069        float percentValue = lineClamp.value();
     1070        numVisibleLines = std::max<size_t>(1, (maxLineCount + 1) * percentValue / 100.f);
     1071    }
    10651072    if (numVisibleLines >= maxLineCount)
    10661073        return;
     
    10711078
    10721079        RenderBlockFlow& blockChild = downcast<RenderBlockFlow>(*child);
    1073         int lineCount = lineCountFor(blockChild);
     1080        auto lineCount = lineCountFor(blockChild);
    10741081        if (lineCount <= numVisibleLines)
    10751082            continue;
    10761083
    1077         LayoutUnit newHeight = heightForLineCount(blockChild, numVisibleLines);
     1084        auto newHeight = heightForLineCount(blockChild, numVisibleLines);
    10781085        if (newHeight == child->height())
    10791086            continue;
Note: See TracChangeset for help on using the changeset viewer.