Changeset 292948 in webkit
- Timestamp:
- Apr 17, 2022 6:32:42 AM (2 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r292947 r292948 1 2022-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 1 19 2022-04-16 Ryosuke Niwa <rniwa@webkit.org> 2 20 -
trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
r292691 r292948 986 986 } 987 987 988 static int getHeightForLineCount(const RenderBlockFlow& block, int lineCount, bool includeBottom, int& count)988 static std::optional<LayoutUnit> getHeightForLineCount(const RenderBlockFlow& block, size_t lineCount, bool includeBottom, size_t& count) 989 989 { 990 990 if (block.style().visibility() != Visibility::Visible) 991 return -1;991 return { }; 992 992 993 993 if (block.childrenInline()) { … … 1000 1000 for (auto* obj = block.firstChildBox(); obj; obj = obj->nextSiblingBox()) { 1001 1001 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); 1005 1004 } else if (!obj->isFloatingOrOutOfFlowPositioned()) 1006 1005 normalFlowChildWithoutLines = obj; … … 1010 1009 } 1011 1010 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 1014 static 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 { }; 1019 1020 } 1020 1021 … … 1038 1039 void RenderDeprecatedFlexibleBox::applyLineClamp(FlexBoxIterator& iterator, bool relayoutChildren) 1039 1040 { 1040 int maxLineCount = 0;1041 size_t maxLineCount = 0; 1041 1042 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 1042 1043 if (childDoesNotAffectWidthOrFlexing(child)) … … 1056 1057 child->layoutIfNeeded(); 1057 1058 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))); 1059 1060 } 1060 1061 1061 1062 // Get the number of lines and then alter all block flow children with auto height to use the 1062 1063 // 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 } 1065 1072 if (numVisibleLines >= maxLineCount) 1066 1073 return; … … 1071 1078 1072 1079 RenderBlockFlow& blockChild = downcast<RenderBlockFlow>(*child); 1073 intlineCount = lineCountFor(blockChild);1080 auto lineCount = lineCountFor(blockChild); 1074 1081 if (lineCount <= numVisibleLines) 1075 1082 continue; 1076 1083 1077 LayoutUnitnewHeight = heightForLineCount(blockChild, numVisibleLines);1084 auto newHeight = heightForLineCount(blockChild, numVisibleLines); 1078 1085 if (newHeight == child->height()) 1079 1086 continue;
Note: See TracChangeset
for help on using the changeset viewer.