Changeset 251843 in webkit


Ignore:
Timestamp:
Oct 31, 2019 7:51:34 AM (4 years ago)
Author:
Alan Bujtas
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251841 r251843  
     12019-10-31  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Preserved segment breaks should produce ForcedLineBreak type of InlineItems
     4        https://bugs.webkit.org/show_bug.cgi?id=203645
     5        <rdar://problem/56763606>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This patch turns preserved segment breaks (e.g. \n) into a ForcedLineBreak. Non-preserved segments breaks are treated as whitespace characters.
     10        It fixes a small type mismatch of having an InlineTextItem representing a non-text content (line break).
     11
     12        * layout/inlineformatting/InlineFormattingContext.cpp:
     13        (WebCore::Layout::InlineFormattingContext::collectInlineContent):
     14        * layout/inlineformatting/InlineItem.cpp:
     15        (WebCore::Layout::InlineItem::InlineItem):
     16        (WebCore::Layout::InlineItem::isForcedLineBreak const): Deleted.
     17        (WebCore::Layout::InlineItem::isText const): Deleted.
     18        * layout/inlineformatting/InlineItem.h:
     19        (WebCore::Layout::InlineItem::isText const):
     20        (WebCore::Layout::InlineItem::isForcedLineBreak const):
     21        (WebCore::Layout::InlineItem::InlineItem): Deleted.
     22        * layout/inlineformatting/InlineTextItem.cpp:
     23        (WebCore::Layout::InlineTextItem::createAndAppendTextItems):
     24        (WebCore::Layout::InlineTextItem::left const):
     25        (WebCore::Layout::InlineTextItem::right const):
     26        (WebCore::Layout::InlineTextItem::isWhitespace const): Deleted.
     27        * layout/inlineformatting/InlineTextItem.h:
     28        (WebCore::Layout::InlineTextItem::isWhitespace const):
     29
    1302019-10-31  Antti Koivisto  <antti@apple.com>
    231
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r251633 r251843  
    354354                formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::ContainerEnd));
    355355            else if (layoutBox.isLineBreakBox())
    356                 formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::LineBreakBox));
     356                formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::ForcedLineBreak));
    357357            else if (layoutBox.isFloatingPositioned())
    358358                formattingState.addInlineItem(makeUnique<InlineItem>(layoutBox, InlineItem::Type::Float));
  • trunk/Source/WebCore/layout/inlineformatting/InlineItem.cpp

    r251590 r251843  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
    31 #include "InlineTextItem.h"
    32 
    3331namespace WebCore {
    3432namespace Layout {
    3533
    36 bool InlineItem::isForcedLineBreak() const
     34InlineItem::InlineItem(const Box& layoutBox, Type type)
     35    : m_layoutBox(layoutBox)
     36    , m_type(type)
    3737{
    38     if (type() == Type::LineBreakBox)
    39         return true;
    40     if (type() != Type::Text || !static_cast<const InlineTextItem*>(this)->isSegmentBreak())
    41         return false;
    42     // Segment break with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line)
    43     return style().preserveNewline();
    44 }
    45 
    46 bool InlineItem::isText() const
    47 {
    48     // If this setup turns out to be a perf hit, we could easily switch over to generate-the-narrow-type way.
    49     return type() == Type::Text && !isForcedLineBreak();
    5038}
    5139
  • trunk/Source/WebCore/layout/inlineformatting/InlineItem.h

    r251590 r251843  
    3737    WTF_MAKE_FAST_ALLOCATED;
    3838public:
    39     enum class Type { Text, LineBreakBox, Box, Float, ContainerStart, ContainerEnd };
     39    enum class Type { Text, ForcedLineBreak, Box, Float, ContainerStart, ContainerEnd };
    4040    InlineItem(const Box& layoutBox, Type);
    4141
     
    4444    const RenderStyle& style() const { return m_layoutBox.style(); }
    4545
    46     bool isText() const;
     46    bool isText() const { return type() == Type::Text; }
    4747    bool isBox() const { return type() == Type::Box; }
    4848    bool isFloat() const { return type() == Type::Float; }
    49     bool isForcedLineBreak() const;
     49    bool isForcedLineBreak() const { return type() == Type::ForcedLineBreak; }
    5050    bool isContainerStart() const { return type() == Type::ContainerStart; }
    5151    bool isContainerEnd() const { return type() == Type::ContainerEnd; }
     
    5555    const Type m_type;
    5656};
    57 
    58 inline InlineItem::InlineItem(const Box& layoutBox, Type type)
    59     : m_layoutBox(layoutBox)
    60     , m_type(type)
    61 {
    62 }
    6357
    6458#define SPECIALIZE_TYPE_TRAITS_INLINE_ITEM(ToValueTypeName, predicate) \
  • trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp

    r251554 r251843  
    9696
    9797        if (isSegmentBreakCandidate(text[currentPosition])) {
    98             inlineContent.append(InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
     98            // Segment breaks with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line) compute to forced line break. 
     99            inlineContent.append(style.preserveNewline() ? makeUnique<InlineItem>(inlineBox, Type::ForcedLineBreak)
     100                : InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
    99101            ++currentPosition;
    100102            continue;
     
    149151{
    150152    RELEASE_ASSERT(length <= this->length());
    151     ASSERT(!isSegmentBreak());
    152153    ASSERT(m_textItemType != TextItemType::Undefined);
    153154    return makeUnique<InlineTextItem>(layoutBox(), start(), length, m_textItemType);
     
    157158{
    158159    RELEASE_ASSERT(length <= this->length());
    159     ASSERT(!isSegmentBreak());
    160160    ASSERT(m_textItemType != TextItemType::Undefined);
    161161    return makeUnique<InlineTextItem>(layoutBox(), end() - length, length, m_textItemType);
    162 }
    163 
    164 bool InlineTextItem::isWhitespace() const
    165 {
    166     if (isSegmentBreak())
    167         return !style().preserveNewline();
    168     return m_textItemType == TextItemType::Whitespace;
    169162}
    170163
  • trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h

    r251590 r251843  
    4747    unsigned length() const { return m_length; }
    4848
    49     bool isWhitespace() const;
     49    bool isWhitespace() const { return m_textItemType == TextItemType::Whitespace || isSegmentBreak(); }
    5050    bool isCollapsible() const { return isWhitespace() && style().collapseWhiteSpace(); }
    5151    bool isSegmentBreak() const { return m_textItemType == TextItemType::SegmentBreak; }
Note: See TracChangeset for help on using the changeset viewer.