Changeset 245961 in webkit
- Timestamp:
- May 31, 2019, 5:58:35 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
layout/inlineformatting/InlineFormattingContextLineLayout.cpp (modified) (5 diffs)
-
layout/inlineformatting/InlineLine.cpp (modified) (8 diffs)
-
layout/inlineformatting/InlineLine.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245960 r245961 1 2019-05-31 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Move final runs to a dedicated class (Line::Content) 4 https://bugs.webkit.org/show_bug.cgi?id=198360 5 <rdar://problem/51247717> 6 7 Reviewed by Antti Koivisto. 8 9 It decouples the line and the final line content. So when we process the runs after closing the line, 10 LineContent should be able to answer all the content and geometry related questions. 11 This is also in preparation for 12 transfering the ownership of the line content when calling Line::close(). 13 14 * WebCore.xcodeproj/project.pbxproj: 15 * layout/inlineformatting/InlineFormattingContextLineLayout.cpp: 16 (WebCore::Layout::InlineFormattingContext::LineLayout::processInlineRuns const): 17 * layout/inlineformatting/InlineLine.cpp: 18 (WebCore::Layout::Line::Content::isVisuallyEmpty const): 19 (WebCore::Layout::Line::Content::Run::Run): 20 (WebCore::Layout::Line::reset): 21 (WebCore::Layout::Line::close): 22 (WebCore::Layout::Line::moveLogicalLeft): 23 (WebCore::Layout::Line::appendNonBreakableSpace): 24 (WebCore::Layout::Line::appendTextContent): 25 (WebCore::Layout::Line::appendNonReplacedInlineBox): 26 (WebCore::Layout::Line::appendHardLineBreak): 27 (WebCore::Layout::Line::LineItem::LineItem): Deleted. 28 (WebCore::Layout::Line::hasContent const): Deleted. 29 * layout/inlineformatting/InlineLine.h: 30 (WebCore::Layout::Line::Content::runs const): 31 (WebCore::Layout::Line::Content::isEmpty const): 32 (WebCore::Layout::Line::Content::logicalTop const): 33 (WebCore::Layout::Line::Content::logicalLeft const): 34 (WebCore::Layout::Line::Content::logicalRight const): 35 (WebCore::Layout::Line::Content::logicalBottom const): 36 (WebCore::Layout::Line::Content::logicalWidth const): 37 (WebCore::Layout::Line::Content::logicalHeight const): 38 (WebCore::Layout::Line::Content::setLogicalRect): 39 (WebCore::Layout::Line::Content::runs): 40 (WebCore::Layout::Line::hasContent const): 41 (WebCore::Layout::Line::availableWidth const): 42 (WebCore::Layout::Line::contentLogicalRight const): 43 (WebCore::Layout::Line::logicalTop const): 44 (WebCore::Layout::Line::logicalBottom const): 45 (WebCore::Layout::Line::logicalLeft const): 46 (WebCore::Layout::Line::logicalRight const): 47 (WebCore::Layout::Line::logicalWidth const): 48 (WebCore::Layout::Line::logicalHeight const): 49 (WebCore::Layout::Line::contentLogicalWidth const): 50 * page/FrameViewLayoutContext.cpp: 51 (WebCore::layoutUsingFormattingContext): 52 1 53 2019-05-31 Joonghun Park <jh718.park@samsung.com> 2 54 -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
r245850 r245961 217 217 void InlineFormattingContext::LineLayout::processInlineRuns(Line& line) const 218 218 { 219 auto& line Items= line.close();220 if (line Items.isEmpty()) {219 auto& lineContent = line.close(); 220 if (lineContent.isEmpty()) { 221 221 // Spec tells us to create a zero height, empty line box. 222 auto lineBox = Display::Rect { line .logicalTop(), line.logicalLeft(), 0 , 0 };222 auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 }; 223 223 m_formattingState.addLineBox({ lineBox }); 224 224 return; … … 231 231 232 232 // Ignore the initial strut. 233 auto lineBox = Display::Rect { line .logicalTop(), line.logicalLeft(), 0 , line.hasContent() ? line.logicalHeight() : LayoutUnit { } };233 auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } }; 234 234 // Create final display runs. 235 for (unsigned index = 0; index < lineItems.size(); ++index) { 236 auto& lineItem = lineItems.at(index); 237 238 auto& inlineItem = lineItem->inlineItem; 239 auto& inlineRun = lineItem->inlineRun; 235 auto& lineRuns = lineContent.runs(); 236 for (unsigned index = 0; index < lineRuns.size(); ++index) { 237 auto& lineRun = lineRuns.at(index); 238 239 auto& inlineItem = lineRun->inlineItem; 240 auto& inlineRun = lineRun->inlineRun; 240 241 auto& layoutBox = inlineItem.layoutBox(); 241 242 auto& displayBox = layoutState().displayBoxForLayoutBox(layoutBox); … … 285 286 // Text content. Try to join multiple text runs when possible. 286 287 ASSERT(inlineRun.textContext()); 287 const Line:: LineItem* previousLineItem = !index ? nullptr : lineItems[index - 1].get();288 if (!line Item->isCollapsed) {288 const Line::Content::Run* previousLineRun = !index ? nullptr : lineRuns[index - 1].get(); 289 if (!lineRun->isCollapsed) { 289 290 auto& inlineTextItem = downcast<InlineTextItem>(inlineItem); 290 auto previousRunCanBeExtended = previousLine Item ? previousLineItem->canBeExtended : false;291 auto requiresNewRun = !index || !previousRunCanBeExtended || &layoutBox != &previousLine Item->inlineItem.layoutBox();291 auto previousRunCanBeExtended = previousLineRun ? previousLineRun->canBeExtended : false; 292 auto requiresNewRun = !index || !previousRunCanBeExtended || &layoutBox != &previousLineRun->inlineItem.layoutBox(); 292 293 if (requiresNewRun) 293 294 m_formattingState.addInlineRun(std::make_unique<Display::Run>(inlineRun)); … … 300 301 } 301 302 // FIXME take content breaking into account when part of the layout box is on the previous line. 302 auto firstInlineRunForLayoutBox = !previousLine Item || &previousLineItem->inlineItem.layoutBox() != &layoutBox;303 auto firstInlineRunForLayoutBox = !previousLineRun || &previousLineRun->inlineItem.layoutBox() != &layoutBox; 303 304 if (firstInlineRunForLayoutBox) { 304 305 // Setup display box for the associated layout box. 305 306 displayBox.setTopLeft(inlineRun.logicalTopLeft()); 306 displayBox.setContentBoxWidth(line Item->isCollapsed ? LayoutUnit() : inlineRun.logicalWidth());307 displayBox.setContentBoxWidth(lineRun->isCollapsed ? LayoutUnit() : inlineRun.logicalWidth()); 307 308 displayBox.setContentBoxHeight(inlineRun.logicalHeight()); 308 } else if (!line Item->isCollapsed) {309 } else if (!lineRun->isCollapsed) { 309 310 // FIXME fix it for multirun/multiline. 310 311 displayBox.setContentBoxWidth(displayBox.contentBoxWidth() + inlineRun.logicalWidth()); … … 313 314 // FIXME linebox needs to be ajusted after content alignment. 314 315 m_formattingState.addLineBox({ lineBox }); 315 if ( line.hasContent())316 if (!lineContent.isVisuallyEmpty()) 316 317 alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, line.availableWidth()); 317 318 } -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp
r245850 r245961 32 32 namespace Layout { 33 33 34 Line::LineItem::LineItem(Display::Run inlineRun, const InlineItem& inlineItem, bool isCollapsed, bool canBeExtended) 34 bool Line::Content::isVisuallyEmpty() const 35 { 36 // Return true for empty inline containers like <span></span>. 37 for (auto& run : m_runs) { 38 if (run->inlineItem.isContainerStart() || run->inlineItem.isContainerEnd()) 39 continue; 40 if (!run->isCollapsed) 41 return false; 42 } 43 return true; 44 } 45 46 Line::Content::Run::Run(Display::Run inlineRun, const InlineItem& inlineItem, bool isCollapsed, bool canBeExtended) 35 47 : inlineRun(inlineRun) 36 48 , inlineItem(inlineItem) … … 53 65 m_contentLogicalWidth = { }; 54 66 55 m_lineItems.clear(); 67 m_content = { }; 68 56 69 m_trimmableContent.clear(); 57 70 } 58 71 59 const Line:: LineItems& Line::close()72 const Line::Content& Line::close() 60 73 { 61 74 removeTrailingTrimmableContent(); 62 75 // Convert inline run geometry from relative to the baseline to relative to logical top. 63 for (auto& lineItem : m_lineItems) {64 auto adjustedLogicalTop = lineItem->inlineRun.logicalTop() + m_logicalHeight.height + m_logicalTopLeft.y();65 lineItem->inlineRun.setLogicalTop(adjustedLogicalTop);76 for (auto& run : m_content.runs()) { 77 auto adjustedLogicalTop = run->inlineRun.logicalTop() + m_logicalHeight.height + m_logicalTopLeft.y(); 78 run->inlineRun.setLogicalTop(adjustedLogicalTop); 66 79 } 67 return m_lineItems; 80 m_content.setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() }); 81 return m_content; 68 82 } 69 83 … … 87 101 m_logicalTopLeft.move(delta, 0); 88 102 m_lineLogicalWidth -= delta; 89 for (auto& lineItem : m_lineItems)90 lineItem->inlineRun.moveHorizontally(delta);103 for (auto& run : m_content.runs()) 104 run->inlineRun.moveHorizontally(delta); 91 105 } 92 106 … … 105 119 } 106 120 107 bool Line::hasContent() const108 {109 // Return false for empty containers like <span></span>.110 if (m_lineItems.isEmpty())111 return false;112 for (auto& lineItem : m_lineItems) {113 if (lineItem->inlineItem.isContainerStart() || lineItem->inlineItem.isContainerEnd())114 continue;115 if (!lineItem->isCollapsed)116 return true;117 }118 return false;119 }120 121 121 void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect) 122 122 { 123 m_ lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));123 m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false)); 124 124 m_contentLogicalWidth += inlineItem.width(); 125 125 } … … 166 166 return false; 167 167 // Leading whitespace. 168 if (m_lineItems.isEmpty()) 168 auto& runs = m_content.runs(); 169 if (runs.isEmpty()) 169 170 return true; 170 171 // Check if the last item is trimmable as well. 171 for (int index = m_lineItems.size() - 1; index >= 0; --index) {172 auto& inlineItem = m_lineItems[index]->inlineItem;172 for (int index = runs.size() - 1; index >= 0; --index) { 173 auto& inlineItem = runs[index]->inlineItem; 173 174 if (inlineItem.isBox()) 174 175 return false; … … 187 188 auto displayRun = Display::Run(logicalRect, textContext); 188 189 189 auto lineItem = std::make_unique< LineItem>(displayRun, inlineItem, isCompletelyCollapsed, canBeExtended);190 auto lineItem = std::make_unique<Content::Run>(displayRun, inlineItem, isCompletelyCollapsed, canBeExtended); 190 191 if (isTrimmable) 191 192 m_trimmableContent.add(lineItem.get()); 192 193 193 m_ lineItems.append(WTFMove(lineItem));194 m_content.runs().append(WTFMove(lineItem)); 194 195 m_contentLogicalWidth += isCompletelyCollapsed ? LayoutUnit() : runSize.width(); 195 196 } … … 219 220 auto logicalRect = Display::Rect { logicalTop, contentLogicalRight() + horizontalMargin.start, runSize.width(), runSize.height() }; 220 221 221 m_ lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));222 m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false)); 222 223 m_contentLogicalWidth += (runSize.width() + horizontalMargin.start + horizontalMargin.end); 223 224 m_trimmableContent.clear(); … … 234 235 auto ascent = inlineItem.layoutBox().style().fontMetrics().ascent(); 235 236 auto logicalRect = Display::Rect { -ascent, contentLogicalRight(), { }, logicalHeight() }; 236 m_ lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));237 m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false)); 237 238 } 238 239 -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.h
r245850 r245961 40 40 void reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset); 41 41 42 struct LineItem { 43 LineItem(Display::Run, const InlineItem&, bool isCollapsed, bool canBeExtended); 42 class Content { 43 public: 44 struct Run { 45 Run(Display::Run, const InlineItem&, bool isCollapsed, bool canBeExtended); 44 46 45 // Relative to the baseline. 46 Display::Run inlineRun; 47 const InlineItem& inlineItem; 48 bool isCollapsed { false }; 49 bool canBeExtended { false }; 47 // Relative to the baseline. 48 Display::Run inlineRun; 49 const InlineItem& inlineItem; 50 bool isCollapsed { false }; 51 bool canBeExtended { false }; 52 }; 53 using Runs = Vector<std::unique_ptr<Run>>; 54 const Runs& runs() const { return m_runs; } 55 bool isEmpty() const { return m_runs.isEmpty(); } 56 // Not in painting sense though. 57 bool isVisuallyEmpty() const; 58 59 LayoutUnit logicalTop() const { return m_logicalRect.top(); } 60 LayoutUnit logicalLeft() const { return m_logicalRect.left(); } 61 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); } 62 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); } 63 LayoutUnit logicalWidth() const { return m_logicalRect.width(); } 64 LayoutUnit logicalHeight() const { return m_logicalRect.height(); } 65 66 private: 67 friend class Line; 68 69 void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; } 70 Runs& runs() { return m_runs; } 71 72 Display::Rect m_logicalRect; 73 Runs m_runs; 50 74 }; 51 52 using LineItems = Vector<std::unique_ptr<LineItem>>; 53 const LineItems& close(); 75 const Content& close(); 54 76 55 77 void appendTextContent(const InlineTextItem&, LayoutSize); … … 60 82 void appendHardLineBreak(const InlineItem&); 61 83 62 bool hasContent() const ;84 bool hasContent() const { return !m_content.isVisuallyEmpty(); } 63 85 64 86 LayoutUnit trailingTrimmableWidth() const; … … 68 90 69 91 LayoutUnit availableWidth() const { return logicalWidth() - contentLogicalWidth(); } 70 71 92 LayoutUnit contentLogicalRight() const { return logicalLeft() + contentLogicalWidth(); } 72 LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }73 74 93 LayoutUnit logicalTop() const { return m_logicalTopLeft.y(); } 75 LayoutUnit logicalLeft() const { return m_logicalTopLeft.x(); }76 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }77 94 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); } 78 LayoutUnit logicalWidth() const { return m_lineLogicalWidth; }79 LayoutUnit logicalHeight() const { return m_logicalHeight.height + m_logicalHeight.depth; }80 95 81 96 struct UsedHeightAndDepth { … … 86 101 87 102 private: 103 LayoutUnit logicalLeft() const { return m_logicalTopLeft.x(); } 104 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); } 105 106 LayoutUnit logicalWidth() const { return m_lineLogicalWidth; } 107 LayoutUnit logicalHeight() const { return m_logicalHeight.height + m_logicalHeight.depth; } 108 109 LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; } 110 88 111 void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect); 89 112 void removeTrailingTrimmableContent(); 90 113 91 114 const LayoutState& m_layoutState; 92 LineItems m_lineItems;93 ListHashSet< LineItem*> m_trimmableContent;115 Content m_content; 116 ListHashSet<Content::Run*> m_trimmableContent; 94 117 95 118 LayoutPoint m_logicalTopLeft;
Note:
See TracChangeset
for help on using the changeset viewer.