Title: [292948] trunk/Source/WebCore
Revision
292948
Author
za...@apple.com
Date
2022-04-17 06:32:42 -0700 (Sun, 17 Apr 2022)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292947 => 292948)


--- trunk/Source/WebCore/ChangeLog	2022-04-17 08:08:00 UTC (rev 292947)
+++ trunk/Source/WebCore/ChangeLog	2022-04-17 13:32:42 UTC (rev 292948)
@@ -1,3 +1,21 @@
+2022-04-17  Alan Bujtas  <za...@apple.com>
+
+        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):
+
 2022-04-16  Ryosuke Niwa  <rn...@webkit.org>
 
         Make release assertion in Document::updateLayout more precise for FrameSelection::setSelection

Modified: trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp (292947 => 292948)


--- trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp	2022-04-17 08:08:00 UTC (rev 292947)
+++ trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp	2022-04-17 13:32:42 UTC (rev 292948)
@@ -985,10 +985,10 @@
     return nullptr;
 }
 
-static int getHeightForLineCount(const RenderBlockFlow& block, int lineCount, bool includeBottom, int& count)
+static std::optional<LayoutUnit> getHeightForLineCount(const RenderBlockFlow& block, size_t lineCount, bool includeBottom, size_t& count)
 {
     if (block.style().visibility() != Visibility::Visible)
-        return -1;
+        return { };
 
     if (block.childrenInline()) {
         for (auto* box = block.firstRootBox(); box; box = box->nextRootBox()) {
@@ -999,9 +999,8 @@
         RenderBox* normalFlowChildWithoutLines = nullptr;
         for (auto* obj = block.firstChildBox(); obj; obj = obj->nextSiblingBox()) {
             if (is<RenderBlockFlow>(*obj) && shouldIncludeLinesForParentLineCount(downcast<RenderBlockFlow>(*obj))) {
-                int result = getHeightForLineCount(downcast<RenderBlockFlow>(*obj), lineCount, false, count);
-                if (result != -1)
-                    return result + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : 0_lu);
+                if (auto height = getHeightForLineCount(downcast<RenderBlockFlow>(*obj), lineCount, false, count))
+                    return *height + obj->y() + (includeBottom ? (block.borderBottom() + block.paddingBottom()) : 0_lu);
             } else if (!obj->isFloatingOrOutOfFlowPositioned())
                 normalFlowChildWithoutLines = obj;
         }
@@ -1009,13 +1008,15 @@
             return normalFlowChildWithoutLines->y() + normalFlowChildWithoutLines->height();
     }
 
-    return -1;
+    return { };
 }
 
-static int heightForLineCount(const RenderBlockFlow& flow, int lineCount)
+static LayoutUnit heightForLineCount(const RenderBlockFlow& flow, size_t lineCount)
 {
-    int count = 0;
-    return getHeightForLineCount(flow, lineCount, true, count);
+    size_t count = 0;
+    if (auto height = getHeightForLineCount(flow, lineCount, true, count))
+        return *height;
+    return { };
 }
 
 static size_t lineCountFor(const RenderBlockFlow& blockFlow)
@@ -1037,7 +1038,7 @@
 
 void RenderDeprecatedFlexibleBox::applyLineClamp(FlexBoxIterator& iterator, bool relayoutChildren)
 {
-    int maxLineCount = 0;
+    size_t maxLineCount = 0;
     for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
         if (childDoesNotAffectWidthOrFlexing(child))
             continue;
@@ -1055,13 +1056,19 @@
         }
         child->layoutIfNeeded();
         if (child->style().height().isAuto() && is<RenderBlockFlow>(*child))
-            maxLineCount = std::max<int>(maxLineCount, lineCountFor(downcast<RenderBlockFlow>(*child)));
+            maxLineCount = std::max(maxLineCount, lineCountFor(downcast<RenderBlockFlow>(*child)));
     }
 
     // Get the number of lines and then alter all block flow children with auto height to use the
     // specified height. We always try to leave room for at least one line.
-    LineClampValue lineClamp = style().lineClamp();
-    int numVisibleLines = lineClamp.isPercentage() ? std::max(1, (maxLineCount + 1) * lineClamp.value() / 100) : lineClamp.value();
+    auto lineClamp = style().lineClamp();
+    ASSERT(!lineClamp.isNone());
+
+    size_t numVisibleLines = lineClamp.value();
+    if (lineClamp.isPercentage()) {
+        float percentValue = lineClamp.value();
+        numVisibleLines = std::max<size_t>(1, (maxLineCount + 1) * percentValue / 100.f);
+    }
     if (numVisibleLines >= maxLineCount)
         return;
 
@@ -1070,11 +1077,11 @@
             continue;
 
         RenderBlockFlow& blockChild = downcast<RenderBlockFlow>(*child);
-        int lineCount = lineCountFor(blockChild);
+        auto lineCount = lineCountFor(blockChild);
         if (lineCount <= numVisibleLines)
             continue;
 
-        LayoutUnit newHeight = heightForLineCount(blockChild, numVisibleLines);
+        auto newHeight = heightForLineCount(blockChild, numVisibleLines);
         if (newHeight == child->height())
             continue;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to