Skip to content
Permalink
Browse files
[LFC][IFC] text-overflow: ellipsis changes the text content to renderer
https://bugs.webkit.org/show_bug.cgi?id=244130

Reviewed by Antti Koivisto.

When truncating the text box for overflow: ellipsis, we need to adjust the "rendered" content as well as the size of the text box to make room for the trailing ellipsis box.

* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h:
(WebCore::InlineDisplay::Box::truncate):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::processOverflownRunsForEllipsis):

Canonical link: https://commits.webkit.org/253607@main
  • Loading branch information
alanbaradlay committed Aug 19, 2022
1 parent 6ca6aad commit cdc3e0787e7e05dbf5adc8285e5ecbf46a7f4ec0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
@@ -46,14 +46,18 @@ struct Box {
size_t start() const { return m_start; }
size_t end() const { return start() + length(); }
size_t length() const { return m_length; }
std::optional<size_t> truncatedLength() const { return m_truncatedLength; }
StringView originalContent() const { return StringView(m_originalContent).substring(m_start, m_length); }
StringView renderedContent() const { return m_adjustedContentToRender.isNull() ? originalContent() : m_adjustedContentToRender; }

bool hasHyphen() const { return m_hasHyphen; }

private:
friend struct Box;

size_t m_start { 0 };
size_t m_length { 0 };
std::optional<size_t> m_truncatedLength { };
bool m_hasHyphen { false };
String m_originalContent;
String m_adjustedContentToRender;
@@ -120,7 +124,7 @@ struct Box {
m_inkOverflow.move({ offset, { } });
}
void adjustInkOverflow(const FloatRect& childBorderBox) { return m_inkOverflow.uniteEvenIfEmpty(childBorderBox); }
void truncate(float truncatedwidth = 0.f);
void truncate(float truncatedWidth = 0.f, std::optional<size_t> truncatedLength = std::nullopt);
void setLeft(float pysicalLeft)
{
auto offset = pysicalLeft - left();
@@ -211,9 +215,15 @@ inline Box::Text::Text(size_t start, size_t length, const String& originalConten
{
}

inline void Box::truncate(float truncatedwidth)
inline void Box::truncate(float truncatedWidth, std::optional<size_t> truncatedLength)
{
m_unflippedVisualRect.setWidth(truncatedwidth);
if (m_text) {
ASSERT(!truncatedLength || m_text->m_length > *truncatedLength);
m_text->m_truncatedLength = truncatedLength.value_or(0);
m_text->m_hasHyphen = false;
}

m_unflippedVisualRect.setWidth(truncatedWidth);
m_inkOverflow.shiftMaxXEdgeTo(m_unflippedVisualRect.maxY());
}

@@ -786,13 +786,14 @@ void InlineDisplayContentBuilder::processOverflownRunsForEllipsis(DisplayBoxes&
continue;
}

auto truncatedWidth = InlineLayoutUnit { };
if (displayBox.isText()) {
auto text = *displayBox.text();
// FIXME: Check if it needs adjustment for RTL direction.
truncatedWidth = TextUtil::breakWord(downcast<InlineTextBox>(displayBox.layoutBox()), text.start(), text.length(), displayBox.width(), availableRoomForEllipsis - ellipsisWidth, { }, displayBox.style().fontCascade()).logicalWidth;
}
displayBox.truncate(truncatedWidth);
auto truncatedContent = TextUtil::breakWord(downcast<InlineTextBox>(displayBox.layoutBox()), text.start(), text.length(), displayBox.width(), availableRoomForEllipsis - ellipsisWidth, { }, displayBox.style().fontCascade());
displayBox.truncate(truncatedContent.logicalWidth, truncatedContent.length);
} else
displayBox.truncate();

firstTruncatedBoxIndex = index;
break;
}

0 comments on commit cdc3e07

Please sign in to comment.