Title: [254402] trunk/Source/WebCore
Revision
254402
Author
[email protected]
Date
2020-01-11 15:47:56 -0800 (Sat, 11 Jan 2020)

Log Message

[LFC][IFC] Visually collapse hanging pre-wrap content.
https://bugs.webkit.org/show_bug.cgi?id=206133
<rdar://problem/58505750>

Reviewed by Antti Koivisto.

This change is to comply with other rendering engines when it comes to visually collapsing hanging pre-wrap content.

https://www.w3.org/TR/css-text-3/#white-space-phase-2
"If white-space is set to pre-wrap, the UA must (unconditionally) hang this sequence, unless the sequence
is followed by a forced line break, in which case it must conditionally hang the sequence is instead.
It ___may___ also visually collapse the character advance widths of any that would otherwise overflow."

* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::close):
(WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):
* layout/inlineformatting/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::InlineItemRun::adjustLogicalWidth):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (254401 => 254402)


--- trunk/Source/WebCore/ChangeLog	2020-01-11 18:07:04 UTC (rev 254401)
+++ trunk/Source/WebCore/ChangeLog	2020-01-11 23:47:56 UTC (rev 254402)
@@ -1,3 +1,24 @@
+2020-01-11  Zalan Butjtas  <[email protected]>
+
+        [LFC][IFC] Visually collapse hanging pre-wrap content.
+        https://bugs.webkit.org/show_bug.cgi?id=206133
+        <rdar://problem/58505750>
+
+        Reviewed by Antti Koivisto.
+
+        This change is to comply with other rendering engines when it comes to visually collapsing hanging pre-wrap content.
+
+        https://www.w3.org/TR/css-text-3/#white-space-phase-2
+        "If white-space is set to pre-wrap, the UA must (unconditionally) hang this sequence, unless the sequence
+        is followed by a forced line break, in which case it must conditionally hang the sequence is instead.
+        It ___may___ also visually collapse the character advance widths of any that would otherwise overflow."
+
+        * layout/inlineformatting/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::close):
+        (WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):
+        * layout/inlineformatting/InlineLineBuilder.h:
+        (WebCore::Layout::LineBuilder::InlineItemRun::adjustLogicalWidth):
+
 2020-01-10  Dean Jackson  <[email protected]>
 
         [WebGL] Clarify USE_OPENGL_ES_3

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (254401 => 254402)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-01-11 18:07:04 UTC (rev 254401)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-01-11 23:47:56 UTC (rev 254402)
@@ -234,6 +234,7 @@
     // 2. Join text runs together when possible [foo][ ][bar] -> [foo bar].
     // 3. Align merged runs both vertically and horizontally.
     removeTrailingCollapsibleContent();
+    visuallyCollapsePreWrapOverflowContent();
     auto hangingContent = collectHangingContent(isLastLineWithInlineContent);
 
     auto mergedInlineItemRuns = [&] {
@@ -508,6 +509,41 @@
     m_lineIsVisuallyEmptyBeforeCollapsibleContent = { };
 }
 
+void LineBuilder::visuallyCollapsePreWrapOverflowContent()
+{
+    ASSERT(m_collapsibleContent.isEmpty());
+    // If white-space is set to pre-wrap, the UA must
+    // ...
+    // It may also visually collapse the character advance widths of any that would otherwise overflow.
+    auto overflowWidth = -availableWidth();
+    if (overflowWidth <= 0)
+        return;
+    // Let's just find the trailing pre-wrap whitespace content for now (e.g check if there are multiple trailing runs with
+    // different set of white-space values and decide if the in-between pre-wrap content should be collapsed as well.)
+    InlineLayoutUnit trimmedContentWidth = 0;
+    for (auto& inlineItemRun : WTF::makeReversedRange(m_inlineItemRuns)) {
+        if (inlineItemRun.style().whiteSpace() != WhiteSpace::PreWrap) {
+            // We are only interested in pre-wrap trailing content.
+            break;
+        }
+        auto preWrapVisuallyCollapsibleInlineItem = inlineItemRun.isContainerStart() || inlineItemRun.isContainerEnd() || inlineItemRun.isWhitespace();
+        if (!preWrapVisuallyCollapsibleInlineItem)
+            break;
+        auto runLogicalWidth = inlineItemRun.logicalWidth();
+        // Never partially collapse inline container start/end items.
+        auto isPartialCollapsingAllowed = inlineItemRun.isText();
+        // FIXME: We should always collapse the run at a glyph boundary as the spec indicates: "collapse the character advance widths of any that would otherwise overflow"
+        auto runLogicalWidthAfterCollapsing = isPartialCollapsingAllowed ? std::max<InlineLayoutUnit>(0, runLogicalWidth - overflowWidth) : 0;
+        auto trimmed = runLogicalWidth - runLogicalWidthAfterCollapsing;
+        trimmedContentWidth += trimmed;
+        overflowWidth -= trimmed;
+        inlineItemRun.adjustLogicalWidth(runLogicalWidthAfterCollapsing);
+        if (overflowWidth <= 0)
+            break;
+    }
+    m_lineBox.shrinkHorizontally(trimmedContentWidth);
+}
+
 HangingContent LineBuilder::collectHangingContent(IsLastLineWithInlineContent isLastLineWithInlineContent)
 {
     auto hangingContent = HangingContent { };

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h (254401 => 254402)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-01-11 18:07:04 UTC (rev 254401)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-01-11 23:47:56 UTC (rev 254402)
@@ -142,6 +142,7 @@
     void appendLineBreak(const InlineItem&);
 
     void removeTrailingCollapsibleContent();
+    void visuallyCollapsePreWrapOverflowContent();
     HangingContent collectHangingContent(IsLastLineWithInlineContent);
     void alignHorizontally(RunList&, const HangingContent&, IsLastLineWithInlineContent);
     void alignContentVertically(RunList&);
@@ -179,6 +180,7 @@
         bool isCollapsed() const { return m_isCollapsed; }
 
         void moveHorizontally(InlineLayoutUnit offset) { m_logicalLeft += offset; }
+        void adjustLogicalWidth(InlineLayoutUnit adjustedWidth) { m_logicalWidth = adjustedWidth; }
 
         bool isCollapsibleWhitespace() const;
         bool hasTrailingLetterSpacing() const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to