Changeset 245850 in webkit
- Timestamp:
- May 29, 2019, 9:07:19 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 8 edited
-
ChangeLog (modified) (1 diff)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
-
layout/displaytree/DisplayRun.h (modified) (1 diff)
-
layout/inlineformatting/InlineFormattingContextLineLayout.cpp (modified) (4 diffs)
-
layout/inlineformatting/InlineLine.cpp (added)
-
layout/inlineformatting/InlineLine.h (added)
-
layout/inlineformatting/InlineTextItem.h (modified) (1 diff)
-
layout/inlineformatting/text/TextUtil.cpp (modified) (1 diff)
-
layout/inlineformatting/text/TextUtil.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245849 r245850 1 2019-05-29 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Move Line class to a dedicated file 4 https://bugs.webkit.org/show_bug.cgi?id=198332 5 <rdar://problem/51221403> 6 7 Reviewed by Antti Koivisto. 8 9 An upcoming refactoring requires the Line class to be in a .h. 10 11 * Sources.txt: 12 * WebCore.xcodeproj/project.pbxproj: 13 * layout/displaytree/DisplayRun.h: 14 * layout/inlineformatting/InlineFormattingContextLineLayout.cpp: 15 (WebCore::Layout::InlineFormattingContext::LineLayout::initializeLine const): 16 (WebCore::Layout::InlineFormattingContext::LineLayout::computedIntrinsicWidth const): 17 (WebCore::Layout::halfLeadingMetrics): Deleted. 18 (WebCore::Layout::Line::availableWidth const): Deleted. 19 (WebCore::Layout::Line::contentLogicalRight const): Deleted. 20 (WebCore::Layout::Line::contentLogicalWidth const): Deleted. 21 (WebCore::Layout::Line::logicalTop const): Deleted. 22 (WebCore::Layout::Line::logicalLeft const): Deleted. 23 (WebCore::Layout::Line::logicalRight const): Deleted. 24 (WebCore::Layout::Line::logicalBottom const): Deleted. 25 (WebCore::Layout::Line::logicalWidth const): Deleted. 26 (WebCore::Layout::Line::logicalHeight const): Deleted. 27 (WebCore::Layout::Line::LineItem::LineItem): Deleted. 28 (WebCore::Layout::Line::Line): Deleted. 29 (WebCore::Layout::Line::reset): Deleted. 30 (WebCore::Layout::Line::close): Deleted. 31 (WebCore::Layout::Line::removeTrailingTrimmableContent): Deleted. 32 (WebCore::Layout::Line::moveLogicalLeft): Deleted. 33 (WebCore::Layout::Line::moveLogicalRight): Deleted. 34 (WebCore::Layout::isTrimmableContent): Deleted. 35 (WebCore::Layout::Line::trailingTrimmableWidth const): Deleted. 36 (WebCore::Layout::Line::hasContent const): Deleted. 37 (WebCore::Layout::Line::appendNonBreakableSpace): Deleted. 38 (WebCore::Layout::Line::appendInlineContainerStart): Deleted. 39 (WebCore::Layout::Line::appendInlineContainerEnd): Deleted. 40 (WebCore::Layout::Line::appendTextContent): Deleted. 41 (WebCore::Layout::Line::appendNonReplacedInlineBox): Deleted. 42 (WebCore::Layout::Line::appendReplacedInlineBox): Deleted. 43 (WebCore::Layout::Line::appendHardLineBreak): Deleted. 44 * layout/inlineformatting/InlineTextItem.h: 45 * layout/inlineformatting/text/TextUtil.cpp: 46 (WebCore::Layout::TextUtil::isTrimmableContent): 47 * layout/inlineformatting/text/TextUtil.h: 48 1 49 2019-05-29 Ludovico de Nittis <ludovico.denittis@collabora.com> 2 50 -
trunk/Source/WebCore/Sources.txt
r245838 r245850 1350 1350 layout/inlineformatting/InlineFormattingState.cpp 1351 1351 layout/inlineformatting/InlineInvalidation.cpp 1352 layout/inlineformatting/InlineLine.cpp 1352 1353 layout/inlineformatting/InlineLineBreaker.cpp 1353 1354 layout/inlineformatting/InlineTextItem.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r245838 r245850 2017 2017 6ED8C37A183BFF8C009E53BD /* BoxShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 6ED8C378183BFF8C009E53BD /* BoxShape.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2018 2018 6EE8A77310F803F3005A4A24 /* JSWebGLContextAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EE8A77110F803F3005A4A24 /* JSWebGLContextAttributes.h */; }; 2019 6F0CD695229ED32700C5994E /* InlineLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F0CD694229ED32700C5994E /* InlineLine.h */; }; 2019 2020 6F1CC1DE225F8B4900720AD2 /* InlineTextItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F1CC1DD225F8B4200720AD2 /* InlineTextItem.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2020 2021 6F222B761AB52D8A0094651A /* WebGLVertexArrayObjectBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6F222B751AB52D8A0094651A /* WebGLVertexArrayObjectBase.cpp */; }; … … 9128 9129 6EE8A77110F803F3005A4A24 /* JSWebGLContextAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLContextAttributes.h; sourceTree = "<group>"; }; 9129 9130 6F0830DF20B46951008A945B /* BlockFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockFormattingContextGeometry.cpp; sourceTree = "<group>"; }; 9131 6F0CD692229ED31900C5994E /* InlineLine.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineLine.cpp; sourceTree = "<group>"; }; 9132 6F0CD694229ED32700C5994E /* InlineLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineLine.h; sourceTree = "<group>"; }; 9130 9133 6F1CC1DC225F8B4100720AD2 /* InlineTextItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineTextItem.cpp; sourceTree = "<group>"; }; 9131 9134 6F1CC1DD225F8B4200720AD2 /* InlineTextItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InlineTextItem.h; sourceTree = "<group>"; }; … … 16381 16384 isa = PBXGroup; 16382 16385 children = ( 16386 6F0CD694229ED32700C5994E /* InlineLine.h */, 16387 6F0CD692229ED31900C5994E /* InlineLine.cpp */, 16383 16388 6FE7DDDD20EC6E8B008B5B4E /* text */, 16384 16389 6F7CA3C9208C2B2E002F29AB /* InlineFormattingContext.cpp */, … … 28181 28186 714C7C671FDAD2A900F2BEE1 /* AnimationPlaybackEventInit.h in Headers */, 28182 28187 71025ECD1F99F0CE004A250C /* AnimationTimeline.h in Headers */, 28188 6F0CD695229ED32700C5994E /* InlineLine.h in Headers */, 28183 28189 0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */, 28184 28190 57152B5A21CB3E88000C37CA /* ApduCommand.h in Headers */, -
trunk/Source/WebCore/layout/displaytree/DisplayRun.h
r245776 r245850 28 28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 29 30 #include "DisplayRect.h" 30 31 #include "InlineItem.h" 31 32 #include "LayoutUnit.h" -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
r245812 r245850 32 32 #include "FloatingState.h" 33 33 #include "InlineFormattingState.h" 34 #include "InlineLine.h" 34 35 #include "InlineLineBreaker.h" 35 36 #include "LayoutBox.h" … … 40 41 namespace WebCore { 41 42 namespace Layout { 42 43 struct UsedHeightAndDepth {44 LayoutUnit height;45 LayoutUnit depth;46 };47 48 static UsedHeightAndDepth halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)49 {50 auto ascent = fontMetrics.ascent();51 auto descent = fontMetrics.descent();52 // 10.8.1 Leading and half-leading53 auto leading = lineLogicalHeight - (ascent + descent);54 // Inline tree is all integer based.55 auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0);56 auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0);57 return { adjustedAscent, adjustedDescent };58 }59 60 class Line {61 public:62 Line(const LayoutState&);63 64 void reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset);65 66 struct LineItem {67 LineItem(Display::Run, const InlineItem&, bool isCollapsed, bool canBeExtended);68 69 // Relative to the baseline.70 Display::Run inlineRun;71 const InlineItem& inlineItem;72 bool isCollapsed { false };73 bool canBeExtended { false };74 };75 76 using LineItems = Vector<std::unique_ptr<LineItem>>;77 const LineItems& close();78 79 void appendTextContent(const InlineTextItem&, LayoutSize);80 void appendNonReplacedInlineBox(const InlineItem&, LayoutSize);81 void appendReplacedInlineBox(const InlineItem&, LayoutSize);82 void appendInlineContainerStart(const InlineItem&);83 void appendInlineContainerEnd(const InlineItem&);84 void appendHardLineBreak(const InlineItem&);85 86 bool hasContent() const;87 88 LayoutUnit trailingTrimmableWidth() const;89 90 void moveLogicalLeft(LayoutUnit);91 void moveLogicalRight(LayoutUnit);92 93 LayoutUnit availableWidth() const { return logicalWidth() - contentLogicalWidth(); }94 95 LayoutUnit contentLogicalRight() const { return logicalLeft() + contentLogicalWidth(); }96 LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }97 98 LayoutUnit logicalTop() const { return m_logicalTopLeft.y(); }99 LayoutUnit logicalLeft() const { return m_logicalTopLeft.x(); }100 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }101 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }102 LayoutUnit logicalWidth() const { return m_lineLogicalWidth; }103 LayoutUnit logicalHeight() const { return m_logicalHeight.height + m_logicalHeight.depth; }104 105 private:106 void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);107 void removeTrailingTrimmableContent();108 109 const LayoutState& m_layoutState;110 LineItems m_lineItems;111 ListHashSet<LineItem*> m_trimmableContent;112 113 LayoutPoint m_logicalTopLeft;114 LayoutUnit m_contentLogicalWidth;115 116 UsedHeightAndDepth m_logicalHeight;117 LayoutUnit m_lineLogicalWidth;118 };119 120 Line::LineItem::LineItem(Display::Run inlineRun, const InlineItem& inlineItem, bool isCollapsed, bool canBeExtended)121 : inlineRun(inlineRun)122 , inlineItem(inlineItem)123 , isCollapsed(isCollapsed)124 , canBeExtended(canBeExtended)125 {126 }127 128 Line::Line(const LayoutState& layoutState)129 : m_layoutState(layoutState)130 {131 }132 133 void Line::reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumHeight, LayoutUnit baselineOffset)134 {135 m_logicalTopLeft = topLeft;136 m_lineLogicalWidth = availableWidth;137 m_logicalHeight = { baselineOffset, minimumHeight - baselineOffset };138 139 m_contentLogicalWidth = { };140 141 m_lineItems.clear();142 m_trimmableContent.clear();143 }144 145 const Line::LineItems& Line::close()146 {147 removeTrailingTrimmableContent();148 // Convert inline run geometry from relative to the baseline to relative to logical top.149 for (auto& lineItem : m_lineItems) {150 auto adjustedLogicalTop = lineItem->inlineRun.logicalTop() + m_logicalHeight.height + m_logicalTopLeft.y();151 lineItem->inlineRun.setLogicalTop(adjustedLogicalTop);152 }153 return m_lineItems;154 }155 156 void Line::removeTrailingTrimmableContent()157 {158 // Collapse trimmable trailing content159 LayoutUnit trimmableWidth;160 for (auto* trimmableRun : m_trimmableContent) {161 trimmableRun->isCollapsed = true;162 trimmableWidth += trimmableRun->inlineRun.logicalWidth();163 }164 m_contentLogicalWidth -= trimmableWidth;165 }166 167 void Line::moveLogicalLeft(LayoutUnit delta)168 {169 if (!delta)170 return;171 ASSERT(delta > 0);172 // Shrink the line and move the items.173 m_logicalTopLeft.move(delta, 0);174 m_lineLogicalWidth -= delta;175 for (auto& lineItem : m_lineItems)176 lineItem->inlineRun.moveHorizontally(delta);177 }178 179 void Line::moveLogicalRight(LayoutUnit delta)180 {181 ASSERT(delta > 0);182 m_lineLogicalWidth -= delta;183 }184 185 static bool isTrimmableContent(const InlineItem& inlineItem)186 {187 if (!is<InlineTextItem>(inlineItem))188 return false;189 auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);190 return inlineTextItem.isWhitespace() && inlineTextItem.style().collapseWhiteSpace();191 }192 193 LayoutUnit Line::trailingTrimmableWidth() const194 {195 LayoutUnit trimmableWidth;196 for (auto* trimmableRun : m_trimmableContent)197 trimmableWidth += trimmableRun->inlineRun.logicalWidth();198 return trimmableWidth;199 }200 201 bool Line::hasContent() const202 {203 // Return false for empty containers like <span></span>.204 if (m_lineItems.isEmpty())205 return false;206 for (auto& lineItem : m_lineItems) {207 if (lineItem->inlineItem.isContainerStart() || lineItem->inlineItem.isContainerEnd())208 continue;209 if (!lineItem->isCollapsed)210 return true;211 }212 return false;213 }214 215 void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect)216 {217 m_lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));218 m_contentLogicalWidth += inlineItem.width();219 }220 221 void Line::appendInlineContainerStart(const InlineItem& inlineItem)222 {223 auto& layoutBox = inlineItem.layoutBox();224 auto& style = layoutBox.style();225 auto& fontMetrics = style.fontMetrics();226 227 auto alignAndAdjustLineHeight = [&] {228 LayoutUnit inlineBoxHeight = style.computedLineHeight();229 230 auto halfLeading = halfLeadingMetrics(fontMetrics, inlineBoxHeight);231 if (halfLeading.depth > 0)232 m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);233 if (halfLeading.height > 0)234 m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);235 };236 237 alignAndAdjustLineHeight();238 auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);239 auto containerHeight = fontMetrics.height() + displayBox.verticalBorder() + displayBox.verticalPadding().valueOr(0);240 auto logicalTop = -fontMetrics.ascent() - displayBox.borderTop() - displayBox.paddingTop().valueOr(0);241 auto logicalRect = Display::Rect { logicalTop, contentLogicalRight(), inlineItem.width(), containerHeight };242 appendNonBreakableSpace(inlineItem, logicalRect);243 }244 245 void Line::appendInlineContainerEnd(const InlineItem& inlineItem)246 {247 // This is really just a placeholder to mark the end of the inline level container.248 auto logicalRect = Display::Rect { 0, contentLogicalRight(), inlineItem.width(), 0 };249 appendNonBreakableSpace(inlineItem, logicalRect);250 }251 252 void Line::appendTextContent(const InlineTextItem& inlineItem, LayoutSize runSize)253 {254 auto isTrimmable = isTrimmableContent(inlineItem);255 if (!isTrimmable)256 m_trimmableContent.clear();257 258 auto shouldCollapseCompletely = [&] {259 if (!isTrimmable)260 return false;261 // Leading whitespace.262 if (m_lineItems.isEmpty())263 return true;264 // Check if the last item is trimmable as well.265 for (int index = m_lineItems.size() - 1; index >= 0; --index) {266 auto& inlineItem = m_lineItems[index]->inlineItem;267 if (inlineItem.isBox())268 return false;269 if (inlineItem.isText())270 return inlineItem.isText() && isTrimmableContent(downcast<InlineTextItem>(inlineItem));271 ASSERT(inlineItem.isContainerStart() || inlineItem.isContainerEnd());272 }273 return true;274 };275 276 // Collapsed line items don't contribute to the line width.277 auto isCompletelyCollapsed = shouldCollapseCompletely();278 auto canBeExtended = !isCompletelyCollapsed && !inlineItem.isCollapsed();279 auto logicalRect = Display::Rect { -inlineItem.style().fontMetrics().ascent(), contentLogicalRight(), runSize.width(), runSize.height() };280 auto textContext = Display::Run::TextContext { inlineItem.start(), inlineItem.isCollapsed() ? 1 : inlineItem.length() };281 auto displayRun = Display::Run(logicalRect, textContext);282 283 auto lineItem = std::make_unique<LineItem>(displayRun, inlineItem, isCompletelyCollapsed, canBeExtended);284 if (isTrimmable)285 m_trimmableContent.add(lineItem.get());286 287 m_lineItems.append(WTFMove(lineItem));288 m_contentLogicalWidth += isCompletelyCollapsed ? LayoutUnit() : runSize.width();289 }290 291 void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutSize runSize)292 {293 auto alignAndAdjustLineHeight = [&] {294 auto inlineBoxHeight = runSize.height();295 // FIXME: We need to look inside the inline-block's formatting context and check the lineboxes (if any) to be able to baseline align.296 if (inlineItem.layoutBox().establishesInlineFormattingContext()) {297 if (inlineBoxHeight == logicalHeight())298 return;299 // FIXME: This fails when the line height difference comes from font-size diff.300 m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);301 m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);302 return;303 }304 // 0 descent -> baseline aligment for now.305 m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);306 m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);307 };308 309 alignAndAdjustLineHeight();310 auto& displayBox = m_layoutState.displayBoxForLayoutBox(inlineItem.layoutBox());311 auto logicalTop = -runSize.height();312 auto horizontalMargin = displayBox.horizontalMargin();313 auto logicalRect = Display::Rect { logicalTop, contentLogicalRight() + horizontalMargin.start, runSize.width(), runSize.height() };314 315 m_lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));316 m_contentLogicalWidth += (runSize.width() + horizontalMargin.start + horizontalMargin.end);317 m_trimmableContent.clear();318 }319 320 void Line::appendReplacedInlineBox(const InlineItem& inlineItem, LayoutSize runSize)321 {322 // FIXME Surely replaced boxes behave differently.323 appendNonReplacedInlineBox(inlineItem, runSize);324 }325 326 void Line::appendHardLineBreak(const InlineItem& inlineItem)327 {328 auto ascent = inlineItem.layoutBox().style().fontMetrics().ascent();329 auto logicalRect = Display::Rect { -ascent, contentLogicalRight(), { }, logicalHeight() };330 m_lineItems.append(std::make_unique<LineItem>(Display::Run { logicalRect }, inlineItem, false, false));331 }332 43 333 44 struct UncommittedContent { … … 396 107 auto& formattingRootStyle = m_formattingRoot.style(); 397 108 auto mimimumLineHeight = formattingRootStyle.computedLineHeight(); 398 auto baselineOffset = halfLeadingMetrics(formattingRootStyle.fontMetrics(), mimimumLineHeight).height;109 auto baselineOffset = Line::halfLeadingMetrics(formattingRootStyle.fontMetrics(), mimimumLineHeight).height; 399 110 line.reset({ lineLogicalLeft, lineLogicalTop }, availableWidth, mimimumLineHeight, baselineOffset); 400 111 } … … 492 203 lineLogicalRight = { }; 493 204 } 494 if ( isTrimmableContent(*inlineItem)) {205 if (TextUtil::isTrimmableContent(*inlineItem)) { 495 206 // Skip leading whitespace. 496 207 if (!lineLogicalRight) -
trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h
r245776 r245850 28 28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 29 30 #include "InlineFormattingState.h" 30 31 #include "InlineItem.h" 31 32 -
trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp
r245776 r245850 90 90 } 91 91 92 bool TextUtil::isTrimmableContent(const InlineItem& inlineItem) 93 { 94 if (!is<InlineTextItem>(inlineItem)) 95 return false; 96 auto& inlineTextItem = downcast<InlineTextItem>(inlineItem); 97 return inlineTextItem.isWhitespace() && inlineTextItem.style().collapseWhiteSpace(); 98 } 99 92 100 } 93 101 } -
trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h
r245776 r245850 37 37 static LayoutUnit width(const InlineBox&, unsigned from, unsigned to, LayoutUnit contentLogicalLeft); 38 38 static Optional<unsigned> hyphenPositionBefore(const InlineItem&, unsigned from, unsigned length); 39 static bool isTrimmableContent(const InlineItem&); 39 40 40 41 private:
Note:
See TracChangeset
for help on using the changeset viewer.