Diff
Modified: trunk/Source/WebCore/ChangeLog (270706 => 270707)
--- trunk/Source/WebCore/ChangeLog 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/ChangeLog 2020-12-11 21:36:48 UTC (rev 270707)
@@ -1,3 +1,29 @@
+2020-12-11 Zalan Bujtas <[email protected]>
+
+ [LFC][IFC] InlineTextItem::isCollapsible might be misleading
+ https://bugs.webkit.org/show_bug.cgi?id=219796
+
+ Reviewed by Antti Koivisto.
+
+ This change makes the code more aligned with the spec language.
+ ::isCollapsed (which maps to RenderStyle::collapseWhiteSpace) is not always about collapsing subsequent
+ whitespace content but also about preserving tab stops.
+
+ * layout/inlineformatting/InlineLine.cpp:
+ (WebCore::Layout::Line::appendTextContent):
+ * layout/inlineformatting/InlineLine.h:
+ (WebCore::Layout::Line::Run::trailingWhitespaceType const):
+ * layout/inlineformatting/InlineLineBuilder.cpp:
+ (WebCore::Layout::LineBuilder::inlineItemWidth const):
+ * layout/inlineformatting/InlineTextItem.cpp:
+ (WebCore::Layout::InlineTextItem::shouldPreserveSpacesAndTabs):
+ * layout/inlineformatting/InlineTextItem.h:
+ (WebCore::Layout::InlineTextItem::isWhitespace const):
+ (WebCore::Layout::InlineTextItem::InlineTextItem):
+ (WebCore::Layout::InlineTextItem::isCollapsible const): Deleted.
+ * layout/inlineformatting/text/TextUtil.cpp:
+ (WebCore::Layout::TextUtil::width):
+
2020-12-11 Aditya Keerthi <[email protected]>
Unreviewed. Address post-review comments after r270678.
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp 2020-12-11 21:36:48 UTC (rev 270707)
@@ -39,7 +39,6 @@
uint8_t enum2;
bool widthBool;
bool softHyphenBool;
- bool isCollapsible;
bool isWordSeparator;
InlineLayoutUnit width;
unsigned start;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineItem.h (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineItem.h 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineItem.h 2020-12-11 21:36:48 UTC (rev 270707)
@@ -62,7 +62,6 @@
TextItemType m_textItemType { TextItemType::Undefined };
bool m_hasWidth { false };
bool m_hasTrailingSoftHyphen { false };
- bool m_isCollapsible { false };
bool m_isWordSeparator { false };
InlineLayoutUnit m_width { };
unsigned m_length { 0 };
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp 2020-12-11 21:36:48 UTC (rev 270707)
@@ -250,8 +250,10 @@
auto willCollapseCompletely = [&] {
if (inlineTextItem.isEmptyContent())
return true;
- if (!inlineTextItem.isCollapsible())
+ if (!inlineTextItem.isWhitespace())
return false;
+ if (InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem))
+ return false;
// Check if the last item is collapsed as well.
for (auto& run : WTF::makeReversedRange(m_runs)) {
if (run.isBox())
@@ -266,7 +268,7 @@
ASSERT(run.isInlineBoxStart() || run.isInlineBoxEnd() || run.isWordBreakOpportunity());
}
// Leading whitespace.
- return !isWhitespacePreserved(style);
+ return true;
};
if (willCollapseCompletely())
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h 2020-12-11 21:36:48 UTC (rev 270707)
@@ -193,7 +193,7 @@
{
if (!inlineTextItem.isWhitespace())
return TrailingWhitespace::None;
- if (!inlineTextItem.isCollapsible())
+ if (InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem))
return TrailingWhitespace::NotCollapsible;
if (inlineTextItem.length() == 1)
return TrailingWhitespace::Collapsible;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp 2020-12-11 21:36:48 UTC (rev 270707)
@@ -208,8 +208,9 @@
auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
if (auto contentWidth = inlineTextItem.width())
return *contentWidth;
- auto end = inlineTextItem.isCollapsible() ? inlineTextItem.start() + 1 : inlineTextItem.end();
- return TextUtil::width(inlineTextItem, inlineTextItem.start(), end, contentLogicalLeft);
+ if (!inlineTextItem.isWhitespace() || InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem))
+ return TextUtil::width(inlineTextItem, contentLogicalLeft);
+ return TextUtil::width(inlineTextItem, inlineTextItem.start(), inlineTextItem.start() + 1, contentLogicalLeft);
}
if (inlineItem.isLineBreak() || inlineItem.isWordBreakOpportunity())
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp 2020-12-11 21:36:48 UTC (rev 270707)
@@ -157,6 +157,13 @@
return !m_length || (m_length == 1 && inlineTextBox().content()[start()] == zeroWidthSpace);
}
+bool InlineTextItem::shouldPreserveSpacesAndTabs(const InlineTextItem& inlineTextItem)
+{
+ ASSERT(inlineTextItem.isWhitespace());
+ auto whitespace = inlineTextItem.style().whiteSpace();
+ return whitespace == WhiteSpace::Pre || whitespace == WhiteSpace::PreWrap || whitespace == WhiteSpace::BreakSpaces;
}
+
}
+}
#endif
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h 2020-12-11 21:36:48 UTC (rev 270707)
@@ -44,7 +44,6 @@
unsigned length() const { return m_length; }
bool isWhitespace() const { return m_textItemType == TextItemType::Whitespace; }
- bool isCollapsible() const { return m_isCollapsible; }
bool isWordSeparator() const { return m_isWordSeparator; }
bool hasTrailingSoftHyphen() const { return m_hasTrailingSoftHyphen; }
Optional<InlineLayoutUnit> width() const { return m_hasWidth ? makeOptional(m_width) : Optional<InlineLayoutUnit> { }; }
@@ -55,6 +54,8 @@
InlineTextItem left(unsigned length) const;
InlineTextItem right(unsigned length) const;
+ static bool shouldPreserveSpacesAndTabs(const InlineTextItem&);
+
private:
using InlineItem::TextItemType;
@@ -88,7 +89,6 @@
m_length = length;
m_hasWidth = !!width;
m_hasTrailingSoftHyphen = hasTrailingSoftHyphen;
- m_isCollapsible = textItemType == TextItemType::Whitespace && inlineTextBox.style().collapseWhiteSpace();
m_isWordSeparator = isWordSeparator;
m_width = width.valueOr(0);
m_textItemType = textItemType;
Modified: trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp (270706 => 270707)
--- trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp 2020-12-11 21:05:39 UTC (rev 270706)
+++ trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp 2020-12-11 21:36:48 UTC (rev 270707)
@@ -40,7 +40,7 @@
InlineLayoutUnit TextUtil::width(const InlineTextItem& inlineTextItem, InlineLayoutUnit contentLogicalLeft)
{
- return TextUtil::width(inlineTextItem, inlineTextItem.start(), inlineTextItem.end() - 1, contentLogicalLeft);
+ return TextUtil::width(inlineTextItem, inlineTextItem.start(), inlineTextItem.end(), contentLogicalLeft);
}
InlineLayoutUnit TextUtil::width(const InlineTextItem& inlineTextItem, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft)
@@ -47,8 +47,8 @@
{
RELEASE_ASSERT(from >= inlineTextItem.start());
RELEASE_ASSERT(to <= inlineTextItem.end());
- if (inlineTextItem.isCollapsible()) {
- // Fast path for collapsed whitespace.
+ if (inlineTextItem.isWhitespace() && !InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem)) {
+ // Fast path for non-preserved whitespace.
auto& font = inlineTextItem.style().fontCascade();
return font.spaceWidth() + font.wordSpacing();
}