Modified: trunk/Source/WebCore/ChangeLog (272125 => 272126)
--- trunk/Source/WebCore/ChangeLog 2021-01-31 20:24:46 UTC (rev 272125)
+++ trunk/Source/WebCore/ChangeLog 2021-01-31 20:31:24 UTC (rev 272126)
@@ -1,3 +1,16 @@
+2021-01-31 Zalan Bujtas <[email protected]>
+
+ [LFC][IFC] Do not use a max value to indicate infinite available space in InlineContentBreaker::tryBreakingTextRun
+ https://bugs.webkit.org/show_bug.cgi?id=221188
+
+ Reviewed by Antti Koivisto.
+
+ * layout/inlineformatting/InlineContentBreaker.cpp:
+ (WebCore::Layout::InlineContentBreaker::processOverflowingTextContent const):
+ (WebCore::Layout::InlineContentBreaker::tryBreakingTextRun const): add fast paths for cases when the available space is zero.
+ Note that there's a difference between returning nullopt and an empty value.
+ * layout/inlineformatting/InlineContentBreaker.h:
+
2021-01-31 Sam Weinig <[email protected]>
Add support for color(prophoto-rgb ...) as part of CSS Color 4
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp (272125 => 272126)
--- trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp 2021-01-31 20:24:46 UTC (rev 272125)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp 2021-01-31 20:31:24 UTC (rev 272126)
@@ -318,7 +318,7 @@
accumulatedRunWidth -= run.logicalWidth;
if (isBreakableRun(run)) {
ASSERT(run.inlineItem.isText());
- if (auto partialRun = tryBreakingTextRun(run, lineStatus.contentLogicalRight + accumulatedRunWidth, maxInlineLayoutUnit())) {
+ if (auto partialRun = tryBreakingTextRun(run, lineStatus.contentLogicalRight + accumulatedRunWidth, { })) {
// We know this run fits, so if wrapping is allowed on the run, it should return a non-empty left-side.
ASSERT(partialRun->length);
return TrailingTextContent { index, false, partialRun };
@@ -355,12 +355,12 @@
return WordBreakRule::NoBreak;
}
-Optional<InlineContentBreaker::PartialRun> InlineContentBreaker::tryBreakingTextRun(const ContinuousContent::Run& overflowingRun, InlineLayoutUnit logicalLeft, InlineLayoutUnit availableWidth) const
+Optional<InlineContentBreaker::PartialRun> InlineContentBreaker::tryBreakingTextRun(const ContinuousContent::Run& overflowingRun, InlineLayoutUnit logicalLeft, Optional<InlineLayoutUnit> availableWidth) const
{
ASSERT(overflowingRun.inlineItem.isText());
auto& inlineTextItem = downcast<InlineTextItem>(overflowingRun.inlineItem);
auto& style = inlineTextItem.style();
- auto findLastBreakablePosition = availableWidth == maxInlineLayoutUnit();
+ auto availableSpaceIsInfinite = !availableWidth.hasValue();
auto breakRule = wordBreakBehavior(style);
if (breakRule == WordBreakRule::AtArbitraryPosition) {
@@ -368,14 +368,17 @@
// Empty text runs may be breakable based on style, but in practice we can't really split them any further.
return PartialRun { };
}
- if (findLastBreakablePosition) {
- // When the run can be split at arbitrary position,
- // let's just return the entire run when it is intended to fit on the line.
+ if (availableSpaceIsInfinite) {
+ // When the run can be split at arbitrary position let's just return the entire run when it is intended to fit on the line.
ASSERT(inlineTextItem.length());
auto trailingPartialRunWidth = TextUtil::width(inlineTextItem, logicalLeft);
- return PartialRun { inlineTextItem.length() - 1, trailingPartialRunWidth };
+ return PartialRun { inlineTextItem.length(), trailingPartialRunWidth };
}
- auto splitData = TextUtil::split(inlineTextItem, overflowingRun.logicalWidth, availableWidth, logicalLeft);
+ if (!*availableWidth) {
+ // Fast path for cases when there's no room at all. The content is breakable but we don't have space for it.
+ return PartialRun { };
+ }
+ auto splitData = TextUtil::split(inlineTextItem, overflowingRun.logicalWidth, *availableWidth, logicalLeft);
return PartialRun { splitData.length, splitData.logicalWidth };
}
@@ -383,6 +386,10 @@
// Find the hyphen position as follows:
// 1. Split the text by taking the hyphen width into account
// 2. Find the last hyphen position before the split position
+ if (!availableSpaceIsInfinite && !*availableWidth) {
+ // We won't be able to find hyphen location when there's no available space.
+ return { };
+ }
auto runLength = inlineTextItem.length();
unsigned limitBefore = style.hyphenationLimitBefore() == RenderStyle::initialHyphenationLimitBefore() ? 0 : style.hyphenationLimitBefore();
unsigned limitAfter = style.hyphenationLimitAfter() == RenderStyle::initialHyphenationLimitAfter() ? 0 : style.hyphenationLimitAfter();
@@ -393,8 +400,8 @@
unsigned leftSideLength = runLength;
auto& fontCascade = style.fontCascade();
auto hyphenWidth = InlineLayoutUnit { fontCascade.width(TextRun { StringView { style.hyphenString() } }) };
- if (!findLastBreakablePosition) {
- auto availableWidthExcludingHyphen = availableWidth - hyphenWidth;
+ if (!availableSpaceIsInfinite) {
+ auto availableWidthExcludingHyphen = *availableWidth - hyphenWidth;
if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen, fontCascade.pixelSize()))
return { };
leftSideLength = TextUtil::split(inlineTextItem, overflowingRun.logicalWidth, availableWidthExcludingHyphen, logicalLeft).length;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.h (272125 => 272126)
--- trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.h 2021-01-31 20:24:46 UTC (rev 272125)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.h 2021-01-31 20:31:24 UTC (rev 272126)
@@ -119,7 +119,7 @@
private:
Result processOverflowingContent(const ContinuousContent&, const LineStatus&) const;
Optional<TrailingTextContent> processOverflowingTextContent(const ContinuousContent&, const LineStatus&) const;
- Optional<PartialRun> tryBreakingTextRun(const ContinuousContent::Run& overflowRun, InlineLayoutUnit logicalLeft, InlineLayoutUnit availableWidth) const;
+ Optional<PartialRun> tryBreakingTextRun(const ContinuousContent::Run& overflowRun, InlineLayoutUnit logicalLeft, Optional<InlineLayoutUnit> availableWidth) const;
enum class WordBreakRule {
NoBreak,