Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp (251329 => 251330)
--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp 2019-10-20 14:56:32 UTC (rev 251329)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp 2019-10-20 15:09:21 UTC (rev 251330)
@@ -33,20 +33,15 @@
namespace WebCore {
namespace Layout {
-static inline bool isWhitespaceCharacter(char character, bool preserveNewline)
+static inline bool isWhitespaceCharacter(char character)
{
- return character == ' ' || character == '\t' || (character == '\n' && !preserveNewline);
+ return character == ' ' || character == '\t';
}
-static inline bool isSoftLineBreak(char character, bool preserveNewline)
+static unsigned moveToNextNonWhitespacePosition(String textContent, unsigned startPosition)
{
- return preserveNewline && character == '\n';
-}
-
-static unsigned moveToNextNonWhitespacePosition(String textContent, unsigned startPosition, bool preserveNewline)
-{
auto nextNonWhiteSpacePosition = startPosition;
- while (nextNonWhiteSpacePosition < textContent.length() && isWhitespaceCharacter(textContent[nextNonWhiteSpacePosition], preserveNewline))
+ while (nextNonWhiteSpacePosition < textContent.length() && isWhitespaceCharacter(textContent[nextNonWhiteSpacePosition]))
++nextNonWhiteSpacePosition;
return nextNonWhiteSpacePosition - startPosition;
}
@@ -89,47 +84,83 @@
{
auto text = inlineBox.textContent();
if (!text.length())
- return inlineContent.append(makeUnique<InlineTextItem>(inlineBox, 0, 0, false));
+ return inlineContent.append(InlineTextItem::createEmptyItem(inlineBox));
auto& style = inlineBox.style();
- auto preserveNewline = style.preserveNewline();
LazyLineBreakIterator lineBreakIterator(text);
unsigned currentPosition = 0;
while (currentPosition < text.length()) {
- // Soft linebreak?
- if (isSoftLineBreak(text[currentPosition], preserveNewline)) {
- inlineContent.append(makeUnique<InlineTextItem>(inlineBox, currentPosition, 1, true));
+ auto isSegmentBreakCandidate = [](auto character) {
+ return character == '\n';
+ };
+
+ if (isSegmentBreakCandidate(text[currentPosition])) {
+ inlineContent.append(InlineTextItem::createSegmentBreakItem(inlineBox, currentPosition));
++currentPosition;
continue;
}
- if (isWhitespaceCharacter(text[currentPosition], preserveNewline)) {
- auto length = moveToNextNonWhitespacePosition(text, currentPosition, preserveNewline);
- inlineContent.append(makeUnique<InlineTextItem>(inlineBox, currentPosition, length, true));
+ if (isWhitespaceCharacter(text[currentPosition])) {
+ auto length = moveToNextNonWhitespacePosition(text, currentPosition);
+ inlineContent.append(InlineTextItem::createWhitespaceItem(inlineBox, currentPosition, length));
currentPosition += length;
continue;
}
auto length = moveToNextBreakablePosition(currentPosition, lineBreakIterator, style);
- inlineContent.append(makeUnique<InlineTextItem>(inlineBox, currentPosition, length, false));
+ inlineContent.append(InlineTextItem::createNonWhitespaceItem(inlineBox, currentPosition, length));
currentPosition += length;
}
}
-InlineTextItem::InlineTextItem(const Box& inlineBox, unsigned start, unsigned length, bool isWhitespace)
+std::unique_ptr<InlineTextItem> InlineTextItem::createWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length)
+{
+ return makeUnique<InlineTextItem>(inlineBox, start, length, TextItemType::Whitespace);
+}
+
+std::unique_ptr<InlineTextItem> InlineTextItem::createNonWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length)
+{
+ return makeUnique<InlineTextItem>(inlineBox, start, length, TextItemType::NonWhitespace);
+}
+
+std::unique_ptr<InlineTextItem> InlineTextItem::createSegmentBreakItem(const Box& inlineBox, unsigned position)
+{
+ return makeUnique<InlineTextItem>(inlineBox, position, 1, TextItemType::SegmentBreak);
+}
+
+std::unique_ptr<InlineTextItem> InlineTextItem::createEmptyItem(const Box& inlineBox)
+{
+ return makeUnique<InlineTextItem>(inlineBox);
+}
+
+InlineTextItem::InlineTextItem(const Box& inlineBox, unsigned start, unsigned length, TextItemType textItemType)
: InlineItem(inlineBox, Type::Text)
, m_start(start)
, m_length(length)
- , m_isWhitespace(isWhitespace)
+ , m_textItemType(textItemType)
{
}
+InlineTextItem::InlineTextItem(const Box& inlineBox)
+ : InlineItem(inlineBox, Type::Text)
+{
+}
+
std::unique_ptr<InlineTextItem> InlineTextItem::split(unsigned splitPosition, unsigned length) const
{
RELEASE_ASSERT(splitPosition >= this->start());
RELEASE_ASSERT(splitPosition + length <= end());
- return makeUnique<InlineTextItem>(layoutBox(), splitPosition, length, isWhitespace());
+ ASSERT(!isSegmentBreak());
+ ASSERT(m_textItemType != TextItemType::Undefined);
+ return makeUnique<InlineTextItem>(layoutBox(), splitPosition, 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 (251329 => 251330)
--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h 2019-10-20 14:56:32 UTC (rev 251329)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h 2019-10-20 15:09:21 UTC (rev 251330)
@@ -37,25 +37,38 @@
public:
static void createAndAppendTextItems(InlineItems&, const Box&);
- InlineTextItem(const Box&, unsigned start, unsigned length, bool isWhitespace);
+ static std::unique_ptr<InlineTextItem> createWhitespaceItem(const Box&, unsigned start, unsigned length);
+ static std::unique_ptr<InlineTextItem> createNonWhitespaceItem(const Box&, unsigned start, unsigned length);
+ static std::unique_ptr<InlineTextItem> createSegmentBreakItem(const Box&, unsigned position);
+ static std::unique_ptr<InlineTextItem> createEmptyItem(const Box&);
unsigned start() const { return m_start; }
unsigned end() const { return start() + length(); }
unsigned length() const { return m_length; }
- bool isWhitespace() const { return m_isWhitespace; }
+ bool isWhitespace() const;
bool isCollapsible() const { return isWhitespace() && style().collapseWhiteSpace(); }
+ bool isSegmentBreak() const;
std::unique_ptr<InlineTextItem> split(unsigned splitPosition, unsigned length) const;
+ enum class TextItemType { Undefined, Whitespace, NonWhitespace, SegmentBreak };
+ InlineTextItem(const Box&, unsigned start, unsigned length, TextItemType);
+ InlineTextItem(const Box&);
+
private:
unsigned m_start { 0 };
unsigned m_length { 0 };
- bool m_isWhitespace { false };
+ TextItemType m_textItemType { TextItemType::Undefined };
};
+inline bool InlineTextItem::isSegmentBreak() const
+{
+ return m_textItemType == TextItemType::SegmentBreak;
}
+
}
+}
SPECIALIZE_TYPE_TRAITS_INLINE_ITEM(InlineTextItem, isText())