Changeset 237323 in webkit
- Timestamp:
- Oct 22, 2018 9:02:48 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r237321 r237323 1 2018-10-22 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Add (right, center)text-align support. 4 https://bugs.webkit.org/show_bug.cgi?id=190745 5 6 Reviewed by Antti Koivisto. 7 8 Adjust the logical left of each run while closing the line. 9 10 * layout/Verification.cpp: 11 (WebCore::Layout::outputMismatchingSimpleLineInformationIfNeeded): 12 (WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded): 13 * layout/inlineformatting/InlineFormattingContext.cpp: 14 (WebCore::Layout::trimLeadingRun): 15 (WebCore::Layout::InlineFormattingContext::layoutInlineContent const): 16 * layout/inlineformatting/InlineFormattingContext.h: 17 (WebCore::Layout::InlineFormattingContext::Line::hasContent const): 18 (WebCore::Layout::InlineFormattingContext::Line::contentLogicalLeft const): Deleted. 19 * layout/inlineformatting/InlineLineBreaker.cpp: 20 (WebCore::Layout::InlineLineBreaker::nextRun): 21 (WebCore::Layout::InlineLineBreaker::splitRun): 22 * layout/inlineformatting/InlineLineBreaker.h: 23 * layout/inlineformatting/InlineRun.h: 24 (WebCore::Layout::InlineRun::setLogicalLeft): 25 (WebCore::Layout::InlineRun::TextContext::start const): 26 (WebCore::Layout::InlineRun::createRun): 27 (WebCore::Layout::InlineRun::createTextRun): 28 (WebCore::Layout::InlineRun::InlineRun): 29 (WebCore::Layout::InlineRun::TextContext::TextContext): 30 (WebCore::Layout::InlineRun::TextContext::position const): Deleted. 31 * layout/inlineformatting/Line.cpp: 32 (WebCore::Layout::InlineFormattingContext::Line::Line): 33 (WebCore::Layout::InlineFormattingContext::Line::init): 34 (WebCore::Layout::adjustedLineLogicalLeft): 35 (WebCore::Layout::InlineFormattingContext::Line::contentLogicalRight): 36 (WebCore::Layout::InlineFormattingContext::Line::appendContent): 37 (WebCore::Layout::InlineFormattingContext::Line::close): 38 (WebCore::Layout::InlineFormattingContext::Line::setConstraints): Deleted. 39 * layout/layouttree/LayoutTreeBuilder.cpp: 40 (WebCore::Layout::outputInlineRuns): 41 1 42 2018-10-22 Zalan Bujtas <zalan@apple.com> 2 43 -
trunk/Source/WebCore/layout/Verification.cpp
r237289 r237323 74 74 auto matchingRuns = areEssentiallyEqual(simpleRun.logicalLeft, inlineRun.logicalLeft()) && areEssentiallyEqual(simpleRun.logicalRight, inlineRun.logicalRight()); 75 75 if (matchingRuns) 76 matchingRuns = (simpleRun.start == inlineRun.textContext()-> position() && simpleRun.end == (inlineRun.textContext()->position() + inlineRun.textContext()->length()));76 matchingRuns = (simpleRun.start == inlineRun.textContext()->start() && simpleRun.end == (inlineRun.textContext()->start() + inlineRun.textContext()->length())); 77 77 if (matchingRuns) 78 78 continue; 79 79 80 stream << "Mismatching: simple run(" << simpleRun.start << ", " << simpleRun.end << ") (" << simpleRun.logicalLeft << ", " << simpleRun.logicalRight << ") layout run(" << inlineRun.textContext()-> position() << ", " << inlineRun.textContext()->position() + inlineRun.textContext()->length() << ") (" << inlineRun.logicalLeft() << ", " << inlineRun.logicalRight() << ")";80 stream << "Mismatching: simple run(" << simpleRun.start << ", " << simpleRun.end << ") (" << simpleRun.logicalLeft << ", " << simpleRun.logicalRight << ") layout run(" << inlineRun.textContext()->start() << ", " << inlineRun.textContext()->start() + inlineRun.textContext()->length() << ") (" << inlineRun.logicalLeft() << ", " << inlineRun.logicalRight() << ")"; 81 81 stream.nextLine(); 82 82 mismatched = true; … … 108 108 if (matchingRuns && inlineTextBox) { 109 109 ASSERT(inlineRun.textContext()); 110 matchingRuns = inlineTextBox->start() == inlineRun.textContext()-> position() && inlineTextBox->end() + 1 == (inlineRun.textContext()->position() + inlineRun.textContext()->length());110 matchingRuns = inlineTextBox->start() == inlineRun.textContext()->start() && inlineTextBox->end() + 1 == (inlineRun.textContext()->start() + inlineRun.textContext()->length()); 111 111 } 112 112 … … 120 120 stream << "layout run "; 121 121 if (inlineRun.textContext()) 122 stream << "(" << inlineRun.textContext()-> position() << ", " << inlineRun.textContext()->position() + inlineRun.textContext()->length() << ") ";122 stream << "(" << inlineRun.textContext()->start() << ", " << inlineRun.textContext()->start() + inlineRun.textContext()->length() << ") "; 123 123 stream << "(" << inlineRun.logicalLeft() << ", " << inlineRun.logicalRight() << ")"; 124 124 stream.nextLine(); -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
r237288 r237323 96 96 ASSERT(run.position == InlineLineBreaker::Run::Position::LineBegin); 97 97 98 auto& inlineRun = run.inlineRun; 99 if (!inlineRun.isWhitespace()) 98 if (!run.content.isWhitespace()) 100 99 return false; 101 100 102 return inlineRun.style().collapseWhiteSpace();101 return run.content.style().collapseWhiteSpace(); 103 102 } 104 103 … … 112 111 auto previousRunPositionIsLineEnd = false; 113 112 114 Line line(inlineFormattingState );115 line. setConstraints(lineLogicalLeft, availableWidth);113 Line line(inlineFormattingState, root()); 114 line.init(lineLogicalLeft, availableWidth); 116 115 117 116 InlineLineBreaker lineBreaker(layoutContext, inlineFormattingState.inlineContent(), inlineRunProvider.runs()); 118 while (auto run = lineBreaker.nextRun(line.contentLogical Left(), line.availableWidth(), !line.hasContent())) {117 while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) { 119 118 120 119 if (run->position == InlineLineBreaker::Run::Position::LineBegin) { … … 124 123 if (!previousRunPositionIsLineEnd) { 125 124 line.close(); 126 line. setConstraints(lineLogicalLeft, availableWidth);125 line.init(lineLogicalLeft, availableWidth); 127 126 } 128 127 // Skip leading whitespace. … … 138 137 // Move over to the next line. 139 138 line.close(); 140 line. setConstraints(lineLogicalLeft, availableWidth);139 line.init(lineLogicalLeft, availableWidth); 141 140 continue; 142 141 } -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
r237288 r237323 50 50 class Line { 51 51 public: 52 Line(InlineFormattingState& );52 Line(InlineFormattingState&, const Box& formattingRoot); 53 53 54 void setConstraints(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth);54 void init(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth); 55 55 void appendContent(const InlineLineBreaker::Run&); 56 56 void close(); 57 bool hasContent() const { return !m_isEmpty; } 58 LayoutUnit contentLogicalLeft() const { return m_contentLogicalLeft; } 57 58 bool hasContent() const { return m_firstRunIndex.has_value(); } 59 LayoutUnit contentLogicalRight(); 59 60 LayoutUnit availableWidth() const { return m_availableWidth; } 60 61 … … 65 66 }; 66 67 std::optional<TrailingTrimmableContent> m_trailingTrimmableContent; 67 InlineFormattingState& m_inlineFormattingState; 68 LayoutUnit m_contentLogicalLeft; 68 bool m_lastRunIsNotCollapsedText { true }; 69 70 InlineFormattingState& m_formattingState; 71 const Box& m_formattingRoot; 72 73 LayoutUnit m_lineLogicalLeft; 69 74 LayoutUnit m_availableWidth; 70 bool m_isEmpty { true }; 71 bool m_lastRunIsNotCollapsedText { true }; 75 LayoutUnit m_lineWidth; 76 77 std::optional<unsigned> m_firstRunIndex; 72 78 }; 73 79 -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp
r237288 r237323 61 61 if (currentInlineRun.isLineBreak()) { 62 62 ++m_currentRunIndex; 63 return Run { Run::Position::LineEnd, currentInlineRun, 0};63 return Run { Run::Position::LineEnd, 0, currentInlineRun }; 64 64 } 65 65 … … 68 68 if (contentWidth <= availableWidth) { 69 69 ++m_currentRunIndex; 70 return Run { lineIsEmpty ? Run::Position::LineBegin : Run::Position::Undetermined, c urrentInlineRun, contentWidth};70 return Run { lineIsEmpty ? Run::Position::LineBegin : Run::Position::Undetermined, contentWidth, currentInlineRun }; 71 71 } 72 72 … … 74 74 if (availableWidth <= 0) { 75 75 ++m_currentRunIndex; 76 return Run { Run::Position::LineBegin, c urrentInlineRun, contentWidth};76 return Run { Run::Position::LineBegin, contentWidth, currentInlineRun }; 77 77 } 78 78 … … 81 81 if (breakingBehavior == LineBreakingBehavior::Keep) { 82 82 ++m_currentRunIndex; 83 return Run { lineIsEmpty ? Run::Position::LineBegin : Run::Position::Undetermined, c urrentInlineRun, contentWidth};83 return Run { lineIsEmpty ? Run::Position::LineBegin : Run::Position::Undetermined, contentWidth, currentInlineRun }; 84 84 } 85 85 86 86 if (breakingBehavior == LineBreakingBehavior::WrapToNextLine) { 87 87 ++m_currentRunIndex; 88 return Run { Run::Position::LineBegin, c urrentInlineRun, contentWidth};88 return Run { Run::Position::LineBegin, contentWidth, currentInlineRun }; 89 89 } 90 90 … … 155 155 InlineLineBreaker::Run InlineLineBreaker::splitRun(const InlineRunProvider::Run& inlineRun, LayoutUnit, LayoutUnit, bool) 156 156 { 157 return { Run::Position::Undetermined, inlineRun, { }};157 return { Run::Position::Undetermined, { }, inlineRun }; 158 158 } 159 159 -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h
r237288 r237323 43 43 enum class Position { Undetermined, LineBegin, LineEnd }; 44 44 Position position; 45 InlineRunProvider::Run inlineRun;46 45 LayoutUnit width; 46 InlineRunProvider::Run content; 47 47 }; 48 48 std::optional<Run> nextRun(LayoutUnit contentLogicalLeft, LayoutUnit availableWidth, bool lineIsEmpty); -
trunk/Source/WebCore/layout/inlineformatting/InlineRun.h
r237288 r237323 35 35 36 36 struct InlineRun { 37 InlineRun(LayoutUnit logcialLeft, LayoutUnit width, const InlineItem&);38 InlineRun(LayoutUnit logcialLeft, LayoutUnit width, ItemPosition, unsigned length, const InlineItem&);37 static InlineRun createRun(LayoutUnit logcialLeft, LayoutUnit width, const InlineItem&); 38 static InlineRun createTextRun(LayoutUnit logcialLeft, LayoutUnit width, ItemPosition, unsigned length, const InlineItem&); 39 39 40 40 LayoutUnit logicalLeft() const { return m_logicalLeft; } … … 43 43 44 44 void setWidth(LayoutUnit width) { m_width = width; } 45 void setLogicalLeft(LayoutUnit logicalLeft) { m_logicalLeft = logicalLeft; } 45 46 void setLogicalRight(LayoutUnit logicalRight) { m_width -= (this->logicalRight() - logicalRight); } 46 47 … … 49 50 TextContext(ItemPosition, unsigned length); 50 51 51 ItemPosition position() const { return m_position; }52 ItemPosition start() const { return m_start; } 52 53 unsigned length() const { return m_length; } 53 54 … … 55 56 56 57 private: 57 ItemPosition m_ position;58 ItemPosition m_start; 58 59 unsigned m_length; 59 60 }; … … 62 63 63 64 private: 65 InlineRun(LayoutUnit logcialLeft, LayoutUnit width, const InlineItem&); 66 InlineRun(LayoutUnit logcialLeft, LayoutUnit width, ItemPosition, unsigned length, const InlineItem&); 67 64 68 LayoutUnit m_logicalLeft; 65 69 LayoutUnit m_width; … … 71 75 using InlineRuns = Vector<InlineRun>; 72 76 77 inline InlineRun InlineRun::createRun(LayoutUnit logicalLeft, LayoutUnit width, const InlineItem& inlineItem) 78 { 79 return { logicalLeft, width, inlineItem }; 80 } 81 82 inline InlineRun InlineRun::createTextRun(LayoutUnit logicalLeft, LayoutUnit width, ItemPosition start, unsigned length, const InlineItem& inlineItem) 83 { 84 return { logicalLeft, width, start, length, inlineItem }; 85 } 86 73 87 inline InlineRun::InlineRun(LayoutUnit logicalLeft, LayoutUnit width, const InlineItem& inlineItem) 74 88 : m_logicalLeft(logicalLeft) … … 78 92 } 79 93 80 inline InlineRun::InlineRun(LayoutUnit logicalLeft, LayoutUnit width, ItemPosition position, unsigned length, const InlineItem& inlineItem)94 inline InlineRun::InlineRun(LayoutUnit logicalLeft, LayoutUnit width, ItemPosition start, unsigned length, const InlineItem& inlineItem) 81 95 : m_logicalLeft(logicalLeft) 82 96 , m_width(width) 83 97 , m_inlineItem(inlineItem) 84 , m_textContext(TextContext { position, length })98 , m_textContext(TextContext { start, length }) 85 99 { 86 100 } 87 101 88 inline InlineRun::TextContext::TextContext(ItemPosition position, unsigned length)89 : m_ position(position)102 inline InlineRun::TextContext::TextContext(ItemPosition start, unsigned length) 103 : m_start(start) 90 104 , m_length(length) 91 105 { -
trunk/Source/WebCore/layout/inlineformatting/Line.cpp
r237288 r237323 34 34 namespace Layout { 35 35 36 InlineFormattingContext::Line::Line(InlineFormattingState& inlineFormattingState) 37 : m_inlineFormattingState(inlineFormattingState) 36 InlineFormattingContext::Line::Line(InlineFormattingState& formattingState, const Box& formattingRoot) 37 : m_formattingState(formattingState) 38 , m_formattingRoot(formattingRoot) 38 39 { 39 40 } 40 41 41 void InlineFormattingContext::Line:: setConstraints(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth)42 void InlineFormattingContext::Line::init(LayoutUnit lineLogicalLeft, LayoutUnit availableWidth) 42 43 { 43 m_contentLogicalLeft = lineLogicalLeft; 44 m_lineLogicalLeft = lineLogicalLeft; 45 m_lineWidth = availableWidth; 44 46 m_availableWidth = availableWidth; 47 m_firstRunIndex = { }; 48 } 49 50 static LayoutUnit adjustedLineLogicalLeft(TextAlignMode align, LayoutUnit lineLogicalLeft, LayoutUnit remainingWidth) 51 { 52 switch (align) { 53 case TextAlignMode::Left: 54 case TextAlignMode::WebKitLeft: 55 case TextAlignMode::Start: 56 return lineLogicalLeft; 57 case TextAlignMode::Right: 58 case TextAlignMode::WebKitRight: 59 case TextAlignMode::End: 60 return lineLogicalLeft + std::max(remainingWidth, LayoutUnit()); 61 case TextAlignMode::Center: 62 case TextAlignMode::WebKitCenter: 63 return lineLogicalLeft + std::max(remainingWidth / 2, LayoutUnit()); 64 case TextAlignMode::Justify: 65 ASSERT_NOT_REACHED(); 66 break; 67 } 68 ASSERT_NOT_REACHED(); 69 return lineLogicalLeft; 45 70 } 46 71 … … 55 80 } 56 81 82 LayoutUnit InlineFormattingContext::Line::contentLogicalRight() 83 { 84 if (!m_firstRunIndex.has_value()) 85 return m_lineLogicalLeft; 86 87 return m_formattingState.inlineRuns().last().logicalRight(); 88 } 89 57 90 void InlineFormattingContext::Line::appendContent(const InlineLineBreaker::Run& run) 58 91 { 59 92 auto lastRunWasNotCollapsedText = m_lastRunIsNotCollapsedText; 60 auto hadContent = hasContent();61 auto contentLogicalLeft = m_contentLogicalLeft;62 93 m_trailingTrimmableContent = { }; 94 m_availableWidth -= run.width; 63 95 64 auto& inlineRun = run.inlineRun; 65 m_availableWidth -= run.width; 66 m_lastRunIsNotCollapsedText = isNonCollapsedText(inlineRun); 67 m_isEmpty = false; 68 m_contentLogicalLeft += run.width; 96 auto& content = run.content; 97 m_lastRunIsNotCollapsedText = isNonCollapsedText(content); 69 98 70 99 // Append this text run to the end of the last text run, if the last run is continuous. 71 if (inlineRun.isText()) { 72 auto textContext = inlineRun.textContext(); 100 std::optional<InlineRun::TextContext> textRun; 101 if (content.isText()) { 102 auto textContext = content.textContext(); 73 103 auto runLength = textContext->isCollapsed() ? 1 : textContext->length(); 74 104 75 if (isTrimmableContent( inlineRun))105 if (isTrimmableContent(content)) 76 106 m_trailingTrimmableContent = TrailingTrimmableContent { run.width, runLength }; 77 107 78 if (ha dContent&& lastRunWasNotCollapsedText) {79 auto& inlineRun = m_ inlineFormattingState.inlineRuns().last();108 if (hasContent() && lastRunWasNotCollapsedText) { 109 auto& inlineRun = m_formattingState.inlineRuns().last(); 80 110 inlineRun.setWidth(inlineRun.width() + run.width); 81 111 inlineRun.textContext()->setLength(inlineRun.textContext()->length() + runLength); 82 112 return; 83 113 } 84 85 return m_inlineFormattingState.appendInlineRun({ contentLogicalLeft, run.width, textContext->start(), runLength, inlineRun.inlineItem()}); 114 textRun = InlineRun::TextContext { textContext->start(), runLength }; 86 115 } 87 116 88 m_inlineFormattingState.appendInlineRun({ contentLogicalLeft, run.width, inlineRun.inlineItem() }); 117 if (textRun) 118 m_formattingState.appendInlineRun(InlineRun::createTextRun(contentLogicalRight(), run.width, textRun->start(), textRun->length(), content.inlineItem())); 119 else 120 m_formattingState.appendInlineRun(InlineRun::createRun(contentLogicalRight(), run.width, content.inlineItem())); 121 m_firstRunIndex = m_firstRunIndex.value_or(m_formattingState.inlineRuns().size() - 1); 89 122 } 90 123 … … 96 129 return; 97 130 98 auto& lastInlineRun = m_ inlineFormattingState.inlineRuns().last();131 auto& lastInlineRun = m_formattingState.inlineRuns().last(); 99 132 lastInlineRun.setWidth(lastInlineRun.width() - m_trailingTrimmableContent->width); 100 133 lastInlineRun.textContext()->setLength(lastInlineRun.textContext()->length() - m_trailingTrimmableContent->length); 101 134 102 if (!lastInlineRun.textContext()->length()) 103 m_inlineFormattingState.inlineRuns().removeLast(); 135 if (!lastInlineRun.textContext()->length()) { 136 m_formattingState.inlineRuns().removeLast(); 137 if (m_firstRunIndex.value()) 138 --*m_firstRunIndex; 139 else 140 m_firstRunIndex = { }; 141 } 104 142 m_availableWidth += m_trailingTrimmableContent->width; 105 143 m_trailingTrimmableContent = { }; 106 144 }; 107 145 146 auto alignRuns = [&]() { 147 148 if (!hasContent()) 149 return; 150 151 auto adjustedLogicalLeft = adjustedLineLogicalLeft(m_formattingRoot.style().textAlign(), m_lineLogicalLeft, m_availableWidth); 152 if (m_lineLogicalLeft == adjustedLogicalLeft) 153 return; 154 155 auto& inlineRuns = m_formattingState.inlineRuns(); 156 auto delta = adjustedLogicalLeft - m_lineLogicalLeft; 157 for (auto runIndex = *m_firstRunIndex; runIndex < inlineRuns.size(); ++runIndex) 158 inlineRuns[runIndex].setLogicalLeft(inlineRuns[runIndex].logicalLeft() + delta); 159 }; 160 161 if (!hasContent()) 162 return; 163 108 164 trimTrailingContent(); 109 m_isEmpty = true;165 alignRuns(); 110 166 } 111 167 -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
r237321 r237323 148 148 stream << "run"; 149 149 if (inlineRun.textContext()) 150 stream << "(" << inlineRun.textContext()-> position() << ", " << inlineRun.textContext()->position() + inlineRun.textContext()->length() << ") ";150 stream << "(" << inlineRun.textContext()->start() << ", " << inlineRun.textContext()->start() + inlineRun.textContext()->length() << ") "; 151 151 stream << "(" << inlineRun.logicalLeft() << ", " << inlineRun.logicalRight() << ")"; 152 152 stream.nextLine();
Note: See TracChangeset
for help on using the changeset viewer.