Title: [251843] trunk/Source/WebCore
Revision
251843
Author
[email protected]
Date
2019-10-31 07:51:34 -0700 (Thu, 31 Oct 2019)

Log Message

[LFC][IFC] Preserved segment breaks should produce ForcedLineBreak type of InlineItems
https://bugs.webkit.org/show_bug.cgi?id=203645
<rdar://problem/56763606>

Reviewed by Antti Koivisto.

This patch turns preserved segment breaks (e.g. \n) into a ForcedLineBreak. Non-preserved segments breaks are treated as whitespace characters.
It fixes a small type mismatch of having an InlineTextItem representing a non-text content (line break).

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::collectInlineContent):
* layout/inlineformatting/InlineItem.cpp:
(WebCore::Layout::InlineItem::InlineItem):
(WebCore::Layout::InlineItem::isForcedLineBreak const): Deleted.
(WebCore::Layout::InlineItem::isText const): Deleted.
* layout/inlineformatting/InlineItem.h:
(WebCore::Layout::InlineItem::isText const):
(WebCore::Layout::InlineItem::isForcedLineBreak const):
(WebCore::Layout::InlineItem::InlineItem): Deleted.
* layout/inlineformatting/InlineTextItem.cpp:
(WebCore::Layout::InlineTextItem::createAndAppendTextItems):
(WebCore::Layout::InlineTextItem::left const):
(WebCore::Layout::InlineTextItem::right const):
(WebCore::Layout::InlineTextItem::isWhitespace const): Deleted.
* layout/inlineformatting/InlineTextItem.h:
(WebCore::Layout::InlineTextItem::isWhitespace const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (251842 => 251843)


--- trunk/Source/WebCore/ChangeLog	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/ChangeLog	2019-10-31 14:51:34 UTC (rev 251843)
@@ -1,3 +1,32 @@
+2019-10-31  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Preserved segment breaks should produce ForcedLineBreak type of InlineItems
+        https://bugs.webkit.org/show_bug.cgi?id=203645
+        <rdar://problem/56763606>
+
+        Reviewed by Antti Koivisto.
+
+        This patch turns preserved segment breaks (e.g. \n) into a ForcedLineBreak. Non-preserved segments breaks are treated as whitespace characters.
+        It fixes a small type mismatch of having an InlineTextItem representing a non-text content (line break).
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::collectInlineContent):
+        * layout/inlineformatting/InlineItem.cpp:
+        (WebCore::Layout::InlineItem::InlineItem):
+        (WebCore::Layout::InlineItem::isForcedLineBreak const): Deleted.
+        (WebCore::Layout::InlineItem::isText const): Deleted.
+        * layout/inlineformatting/InlineItem.h:
+        (WebCore::Layout::InlineItem::isText const):
+        (WebCore::Layout::InlineItem::isForcedLineBreak const):
+        (WebCore::Layout::InlineItem::InlineItem): Deleted.
+        * layout/inlineformatting/InlineTextItem.cpp:
+        (WebCore::Layout::InlineTextItem::createAndAppendTextItems):
+        (WebCore::Layout::InlineTextItem::left const):
+        (WebCore::Layout::InlineTextItem::right const):
+        (WebCore::Layout::InlineTextItem::isWhitespace const): Deleted.
+        * layout/inlineformatting/InlineTextItem.h:
+        (WebCore::Layout::InlineTextItem::isWhitespace const):
+
 2019-10-31  Antti Koivisto  <[email protected]>
 
         Rename StyleBuilder to Style::BuilderGenerated

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (251842 => 251843)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-10-31 14:51:34 UTC (rev 251843)
@@ -353,7 +353,7 @@
             if (treatAsInlineContainer(layoutBox))
                 formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::ContainerEnd));
             else if (layoutBox.isLineBreakBox())
-                formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::LineBreakBox));
+                formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::ForcedLineBreak));
             else if (layoutBox.isFloatingPositioned())
                 formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::Float));
             else {

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp (251842 => 251843)


--- trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp	2019-10-31 14:51:34 UTC (rev 251843)
@@ -28,27 +28,15 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
-#include "InlineTextItem.h"
-
 namespace WebCore {
 namespace Layout {
 
-bool InlineItem::isForcedLineBreak() const
+InlineItem::InlineItem(const Box& layoutBox, Type type)
+    : m_layoutBox(layoutBox)
+    , m_type(type)
 {
-    if (type() == Type::LineBreakBox)
-        return true;
-    if (type() != Type::Text || !static_cast<const InlineTextItem*>(this)->isSegmentBreak())
-        return false;
-    // Segment break with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line)
-    return style().preserveNewline();
 }
 
-bool InlineItem::isText() const
-{
-    // If this setup turns out to be a perf hit, we could easily switch over to generate-the-narrow-type way.
-    return type() == Type::Text && !isForcedLineBreak();
 }
-
 }
-}
 #endif

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineItem.h (251842 => 251843)


--- trunk/Source/WebCore/layout/inlineformatting/InlineItem.h	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineItem.h	2019-10-31 14:51:34 UTC (rev 251843)
@@ -36,7 +36,7 @@
 class InlineItem : public CanMakeWeakPtr<InlineItem> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    enum class Type { Text, LineBreakBox, Box, Float, ContainerStart, ContainerEnd };
+    enum class Type { Text, ForcedLineBreak, Box, Float, ContainerStart, ContainerEnd };
     InlineItem(const Box& layoutBox, Type);
 
     Type type() const { return m_type; }
@@ -43,10 +43,10 @@
     const Box& layoutBox() const { return m_layoutBox; }
     const RenderStyle& style() const { return m_layoutBox.style(); }
 
-    bool isText() const;
+    bool isText() const { return type() == Type::Text; }
     bool isBox() const { return type() == Type::Box; }
     bool isFloat() const { return type() == Type::Float; }
-    bool isForcedLineBreak() const;
+    bool isForcedLineBreak() const { return type() == Type::ForcedLineBreak; }
     bool isContainerStart() const { return type() == Type::ContainerStart; }
     bool isContainerEnd() const { return type() == Type::ContainerEnd; }
 
@@ -55,12 +55,6 @@
     const Type m_type;
 };
 
-inline InlineItem::InlineItem(const Box& layoutBox, Type type)
-    : m_layoutBox(layoutBox)
-    , m_type(type)
-{
-}
-
 #define SPECIALIZE_TYPE_TRAITS_INLINE_ITEM(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Layout::ToValueTypeName) \
     static bool isType(const WebCore::Layout::InlineItem& inlineItem) { return inlineItem.predicate; } \

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp (251842 => 251843)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-10-31 14:51:34 UTC (rev 251843)
@@ -95,7 +95,9 @@
         };
 
         if (isSegmentBreakCandidate(text[currentPosition])) {
-            inlineContent.append(InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
+            // Segment breaks with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line) compute to forced line break.  
+            inlineContent.append(style.preserveNewline() ? makeUnique<InlineItem>(inlineBox, Type::ForcedLineBreak)
+                : InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
             ++currentPosition;
             continue;
         }
@@ -148,7 +150,6 @@
 std::unique_ptr<InlineTextItem> InlineTextItem::left(unsigned length) const
 {
     RELEASE_ASSERT(length <= this->length());
-    ASSERT(!isSegmentBreak());
     ASSERT(m_textItemType != TextItemType::Undefined);
     return makeUnique<InlineTextItem>(layoutBox(), start(), length, m_textItemType);
 }
@@ -156,18 +157,10 @@
 std::unique_ptr<InlineTextItem> InlineTextItem::right(unsigned length) const
 {
     RELEASE_ASSERT(length <= this->length());
-    ASSERT(!isSegmentBreak());
     ASSERT(m_textItemType != TextItemType::Undefined);
     return makeUnique<InlineTextItem>(layoutBox(), end() - length, length, m_textItemType);
 }
 
-bool InlineTextItem::isWhitespace() const
-{
-    if (isSegmentBreak())
-        return !style().preserveNewline();
-    return m_textItemType == TextItemType::Whitespace;
 }
-
 }
-}
 #endif

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h (251842 => 251843)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-10-31 14:39:30 UTC (rev 251842)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-10-31 14:51:34 UTC (rev 251843)
@@ -46,7 +46,7 @@
     unsigned end() const { return start() + length(); }
     unsigned length() const { return m_length; }
 
-    bool isWhitespace() const;
+    bool isWhitespace() const { return m_textItemType == TextItemType::Whitespace || isSegmentBreak(); }
     bool isCollapsible() const { return isWhitespace() && style().collapseWhiteSpace(); }
     bool isSegmentBreak() const { return m_textItemType == TextItemType::SegmentBreak; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to