Changeset 246234 in webkit
- Timestamp:
- Jun 8, 2019 11:48:41 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r246231 r246234 1 2019-06-08 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Introduce Baseline to LineBox 4 https://bugs.webkit.org/show_bug.cgi?id=198686 5 <rdar://problem/51545175> 6 7 Reviewed by Antti Koivisto. 8 9 Make baselines alignment explicit in Line. 10 This is in preparation for adding non-baseline vertical alignment support. 11 12 * layout/inlineformatting/InlineFormattingContextLineLayout.cpp: 13 (WebCore::Layout::InlineFormattingContext::LineLayout::placeInlineItems const): 14 (WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const): 15 * layout/inlineformatting/InlineLine.cpp: 16 (WebCore::Layout::Line::Line): 17 (WebCore::Layout::Line::close): 18 (WebCore::Layout::Line::adjustBaselineAndLineHeight): 19 (WebCore::Layout::Line::halfLeadingMetrics): 20 * layout/inlineformatting/InlineLine.h: 21 (WebCore::Layout::Line::Content::baseline const): 22 (WebCore::Layout::Line::Content::setBaseline): 23 (WebCore::Layout::Line::logicalHeight const): 24 (WebCore::Layout::Line::baselineAlignedContentHeight const): 25 (WebCore::Layout::Line::baselineOffset const): 26 * layout/inlineformatting/InlineLineBox.h: 27 (WebCore::Layout::LineBox::baseline const): 28 (WebCore::Layout::LineBox::LineBox): 29 1 30 2019-06-07 Said Abou-Hallawa <sabouhallawa@apple.com> 2 31 -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
r246206 r246234 131 131 if (lineInput.skipVerticalAligment == LineInput::SkipVerticalAligment::No) { 132 132 auto mimimumLineHeight = m_formattingRoot.style().computedLineHeight(); 133 auto baselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).height;134 line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, baselineOffset);133 auto initialBaselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).offset; 134 line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, initialBaselineOffset); 135 135 } else 136 136 line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft.x(), lineInput.horizontalConstraint.availableLogicalWidth); … … 302 302 // Spec tells us to create a zero height, empty line box. 303 303 auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 }; 304 m_formattingState.addLineBox({ lineBox });304 m_formattingState.addLineBox({ lineBox, lineContent.baseline() }); 305 305 return; 306 306 } … … 312 312 313 313 // Ignore the initial strut. 314 auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 314 auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0, !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } }; 315 315 // Create final display runs. 316 316 auto& lineRuns = lineContent.runs(); … … 393 393 } 394 394 // FIXME linebox needs to be ajusted after content alignment. 395 m_formattingState.addLineBox({ lineBox });395 m_formattingState.addLineBox({ lineBox, lineContent.baseline() }); 396 396 if (!lineContent.isVisuallyEmpty()) 397 397 alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth()); -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp
r246206 r246234 70 70 , m_content(std::make_unique<Line::Content>()) 71 71 , m_logicalTopLeft(topLeft) 72 , m_logicalHeight({ baselineOffset, minimumHeight - baselineOffset }) 72 , m_baseline({ baselineOffset, minimumHeight - baselineOffset, { } }) 73 , m_contentLogicalHeight(minimumHeight) 73 74 , m_lineLogicalWidth(availableWidth) 74 75 { … … 81 82 // Convert inline run geometry from relative to the baseline to relative to logical top. 82 83 for (auto& run : m_content->runs()) { 83 auto adjustedLogicalTop = run->logicalRect.top() + m_logicalHeight.height + m_logicalTopLeft.y();84 auto adjustedLogicalTop = run->logicalRect.top() + baselineOffset(); 84 85 run->logicalRect.setTop(adjustedLogicalTop); 85 86 } 86 87 } 87 88 m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() }); 89 m_content->setBaseline(m_baseline); 88 90 return WTFMove(m_content); 89 91 } … … 246 248 auto& fontMetrics = style.fontMetrics(); 247 249 auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight()); 248 if (halfLeading.depth > 0) 249 m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth); 250 if (halfLeading.height > 0) 251 m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height); 250 if (halfLeading.descent > 0) 251 m_baseline.descent = std::max(m_baseline.descent, halfLeading.descent); 252 if (halfLeading.ascent > 0) 253 m_baseline.ascent = std::max(m_baseline.ascent, halfLeading.ascent); 254 m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight()); 252 255 return; 253 256 } … … 258 261 return; 259 262 // FIXME: This fails when the line height difference comes from font-size diff. 260 m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth); 261 m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height); 263 m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent); 264 m_baseline.ascent = std::max(runHeight, m_baseline.ascent); 265 m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight()); 262 266 return; 263 267 } 264 268 // 0 descent -> baseline aligment for now. 265 m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth); 266 m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height); 269 m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent); 270 m_baseline.ascent = std::max(runHeight, m_baseline.ascent); 271 m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight()); 267 272 } 268 273 … … 291 296 } 292 297 293 Line ::UsedHeightAndDepthLine::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)298 LineBox::Baseline Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight) 294 299 { 295 300 auto ascent = fontMetrics.ascent(); … … 300 305 auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0); 301 306 auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0); 302 return { adjustedAscent, adjustedDescent };307 return { adjustedAscent, adjustedDescent, adjustedAscent }; 303 308 } 304 309 -
trunk/Source/WebCore/layout/inlineformatting/InlineLine.h
r246206 r246234 70 70 LayoutUnit logicalWidth() const { return m_logicalRect.width(); } 71 71 LayoutUnit logicalHeight() const { return m_logicalRect.height(); } 72 LineBox::Baseline baseline() const { return m_baseline; } 72 73 73 74 private: … … 75 76 76 77 void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; } 78 void setBaseline(LineBox::Baseline baseline) { m_baseline = baseline; } 77 79 Runs& runs() { return m_runs; } 78 80 79 81 Display::Rect m_logicalRect; 82 LineBox::Baseline m_baseline; 80 83 Runs m_runs; 81 84 }; … … 101 104 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); } 102 105 103 struct UsedHeightAndDepth { 104 LayoutUnit height; 105 LayoutUnit depth; 106 }; 107 static UsedHeightAndDepth halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight); 106 static LineBox::Baseline halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight); 108 107 109 108 private: … … 112 111 113 112 LayoutUnit logicalWidth() const { return m_lineLogicalWidth; } 114 LayoutUnit logicalHeight() const { return m_ logicalHeight.height + m_logicalHeight.depth; }113 LayoutUnit logicalHeight() const { return m_contentLogicalHeight; } 115 114 116 115 LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; } 116 LayoutUnit baselineAlignedContentHeight() const { return m_baseline.ascent + m_baseline.descent; } 117 LayoutUnit baselineOffset() const { return m_baseline.offset; } 117 118 118 119 void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect); … … 129 130 LayoutUnit m_contentLogicalWidth; 130 131 131 UsedHeightAndDepth m_logicalHeight; 132 LineBox::Baseline m_baseline; 133 LayoutUnit m_contentLogicalHeight; 132 134 LayoutUnit m_lineLogicalWidth; 133 135 bool m_skipVerticalAligment { false }; -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h
r245776 r246234 35 35 class LineBox { 36 36 public: 37 LineBox(Display::Rect); 37 struct Baseline { 38 LayoutUnit ascent; 39 LayoutUnit descent; 40 LayoutUnit offset; // baseline offset from line logical top. Note that offset does not necessarily equal to ascent. 41 }; 42 LineBox(Display::Rect, const Baseline&); 38 43 39 44 LayoutPoint logicalTopLeft() const { return m_rect.topLeft(); } … … 47 52 LayoutUnit logicalHeight() const { return m_rect.height(); } 48 53 54 Baseline baseline() const { return m_baseline; } 55 49 56 private: 50 57 Display::Rect m_rect; 58 Baseline m_baseline; 51 59 }; 52 60 53 inline LineBox::LineBox(Display::Rect rect )61 inline LineBox::LineBox(Display::Rect rect, const Baseline& baseline) 54 62 : m_rect(rect) 63 , m_baseline(baseline) 55 64 { 56 65 }
Note: See TracChangeset
for help on using the changeset viewer.