Changeset 294383 in webkit
- Timestamp:
- May 17, 2022, 11:26:53 PM (3 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/layout/integration/inline/InlineIteratorBox.cpp
r294279 r294383 95 95 } 96 96 97 FloatRect Box::visualRect() const 98 { 99 auto rect = visualRectIgnoringBlockDirection(); 100 containingBlock().flipForWritingMode(rect); 101 return rect; 102 } 103 97 104 RenderObject::HighlightState Box::selectionState() const 98 105 { -
trunk/Source/WebCore/layout/integration/inline/InlineIteratorBox.h
r294279 r294383 61 61 bool isRootInlineBox() const; 62 62 63 FloatRect visualRect( float formattingRootSizeInBlockDirection) const;63 FloatRect visualRect() const; 64 64 FloatRect visualRectIgnoringBlockDirection() const; 65 65 … … 86 86 87 87 const RenderObject& renderer() const; 88 const RenderBlockFlow& containingBlock() const; 88 89 const RenderStyle& style() const; 89 90 … … 100 101 101 102 LineBoxIterator lineBox() const; 103 104 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 105 const BoxModernPath& modernPath() const; 106 #endif 107 const BoxLegacyPath& legacyPath() const; 102 108 103 109 protected: … … 107 113 friend class TextBoxIterator; 108 114 109 // To help with debugging.110 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)111 const BoxModernPath& modernPath() const;112 #endif113 const BoxLegacyPath& legacyPath() const;114 115 115 PathVariant m_pathVariant; 116 116 }; … … 185 185 } 186 186 187 inline FloatRect Box::visualRect(float formattingRootSizeInBlockDirection) const188 {189 auto visualRect = visualRectIgnoringBlockDirection();190 if (!style().isFlippedBlocksWritingMode())191 return visualRect;192 193 if (style().isHorizontalWritingMode())194 visualRect.setY(formattingRootSizeInBlockDirection - visualRect.maxY());195 else196 visualRect.setX(formattingRootSizeInBlockDirection - visualRect.maxX());197 return visualRect;198 }199 200 187 inline FloatRect Box::visualRectIgnoringBlockDirection() const 201 188 { … … 244 231 return WTF::switchOn(m_pathVariant, [](auto& path) -> const RenderObject& { 245 232 return path.renderer(); 233 }); 234 } 235 236 inline const RenderBlockFlow& Box::containingBlock() const 237 { 238 return WTF::switchOn(m_pathVariant, [](auto& path) -> const RenderBlockFlow& { 239 return path.containingBlock(); 246 240 }); 247 241 } -
trunk/Source/WebCore/layout/integration/inline/InlineIteratorBoxLegacyPath.h
r294279 r294383 77 77 } 78 78 79 const RenderBlockFlow& containingBlock() const 80 { 81 return m_inlineBox->root().blockFlow(); 82 } 83 79 84 const RenderStyle& style() const 80 85 { … … 114 119 } 115 120 121 TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; } 122 bool isFirstLine() const { return !rootInlineBox().prevRootBox(); } 123 116 124 bool operator==(const BoxLegacyPath& other) const { return m_inlineBox == other.m_inlineBox; } 117 125 -
trunk/Source/WebCore/layout/integration/inline/InlineIteratorBoxModernPath.h
r294279 r294383 104 104 } 105 105 106 const RenderBlockFlow& containingBlock() const 107 { 108 return m_inlineContent->containingBlock(); 109 } 110 106 111 const RenderStyle& style() const 107 112 { … … 208 213 } 209 214 215 TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; } 216 bool isFirstLine() const { return !box().lineIndex(); } 217 210 218 bool operator==(const BoxModernPath& other) const { return m_inlineContent == other.m_inlineContent && m_boxIndex == other.m_boxIndex; } 211 219 … … 273 281 274 282 const RenderText& renderText() const { return downcast<RenderText>(renderer()); } 275 TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; }276 283 277 284 WeakPtr<const LayoutIntegration::InlineContent> m_inlineContent; -
trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp
r294279 r294383 801 801 continue; 802 802 803 TextBoxPainter painter(*m_inlineContent, box, paintInfo, paintOffset);803 ModernTextBoxPainter painter(*m_inlineContent, box, paintInfo, paintOffset); 804 804 painter.paint(); 805 805 continue; -
trunk/Source/WebCore/rendering/GlyphDisplayListCache.h
r293951 r294383 36 36 namespace WebCore { 37 37 38 class LegacyInlineTextBox; 39 40 namespace InlineDisplay { 41 struct Box; 42 } 43 38 44 template<typename LayoutRun> 39 45 class GlyphDisplayListCache { … … 43 49 static GlyphDisplayListCache& singleton() 44 50 { 51 static_assert(std::is_same_v<LayoutRun, LegacyInlineTextBox> || std::is_same_v<LayoutRun, InlineDisplay::Box>); 45 52 static NeverDestroyed<GlyphDisplayListCache> cache; 46 53 return cache; -
trunk/Source/WebCore/rendering/InlineBoxPainter.cpp
r294279 r294383 142 142 143 143 // Move x/y to our coordinates. 144 auto localRect = LayoutRect { m_inlineBox.visualRect( m_inlineBox.lineBox()->containingBlock().logicalHeight()) };144 auto localRect = LayoutRect { m_inlineBox.visualRect() }; 145 145 LayoutPoint adjustedPaintOffset = m_paintOffset + localRect.location(); 146 146 … … 218 218 219 219 // Move x/y to our coordinates. 220 auto localRect = LayoutRect { m_inlineBox.visualRect( m_inlineBox.lineBox()->containingBlock().logicalHeight()) };220 auto localRect = LayoutRect { m_inlineBox.visualRect() }; 221 221 LayoutPoint adjustedPaintoffset = m_paintOffset + localRect.location(); 222 222 GraphicsContext& context = m_paintInfo.context(); -
trunk/Source/WebCore/rendering/LegacyInlineFlowBox.cpp
r294279 r294383 927 927 logicalVisualOverflow = LayoutRect(logicalLeftVisualOverflow, logicalTopVisualOverflow, logicalRightVisualOverflow - logicalLeftVisualOverflow, logicalBottomVisualOverflow - logicalTopVisualOverflow); 928 928 929 auto documentMarkerBounds = TextBoxPainter::calculateUnionOfAllDocumentMarkerBounds(textBox);929 auto documentMarkerBounds = LegacyTextBoxPainter::calculateUnionOfAllDocumentMarkerBounds(textBox); 930 930 documentMarkerBounds.move(textBox.logicalLeft(), textBox.logicalTop()); 931 931 logicalVisualOverflow = unionRect(logicalVisualOverflow, LayoutRect(documentMarkerBounds)); -
trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp
r294279 r294383 398 398 return; 399 399 400 TextBoxPainter textBoxPainter(*this, paintInfo, paintOffset);400 LegacyTextBoxPainter textBoxPainter(*this, paintInfo, paintOffset); 401 401 textBoxPainter.paint(); 402 402 } -
trunk/Source/WebCore/rendering/LegacyInlineTextBox.h
r294279 r294383 151 151 private: 152 152 friend class InlineIterator::BoxLegacyPath; 153 friend class TextBoxPainter;154 153 155 154 const RenderCombineText* combinedText() const; -
trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp
r294279 r294383 728 728 if (!box->isText()) 729 729 continue; 730 TextBoxPainter textBoxPainter(downcast<InlineIterator::TextBoxIterator>(box), maskInfo, paintOffset); 730 if (auto* legacyTextBox = downcast<LegacyInlineTextBox>(box->legacyInlineBox())) { 731 LegacyTextBoxPainter textBoxPainter(*legacyTextBox, maskInfo, paintOffset); 732 textBoxPainter.paint(); 733 continue; 734 } 735 ModernTextBoxPainter textBoxPainter(box->modernPath().inlineContent(), box->modernPath().box(), maskInfo, paintOffset); 731 736 textBoxPainter.paint(); 732 737 } -
trunk/Source/WebCore/rendering/TextBoxPainter.cpp
r294279 r294383 46 46 namespace WebCore { 47 47 48 TextBoxPainter::TextBoxPainter(const LegacyInlineTextBox& textBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 49 : TextBoxPainter(InlineIterator::textBoxFor(&textBox), paintInfo, paintOffset) 48 static FloatRect calculateDocumentMarkerBounds(const InlineIterator::TextBoxIterator&, const MarkedText&); 49 50 LegacyTextBoxPainter::LegacyTextBoxPainter(const LegacyInlineTextBox& textBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 51 : TextBoxPainter(InlineIterator::BoxLegacyPath { &textBox }, paintInfo, paintOffset) 50 52 { 51 53 m_emphasisMarkExistsAndIsAbove = textBox.emphasisMarkExistsAndIsAbove(m_style); … … 53 55 54 56 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 55 TextBoxPainter::TextBoxPainter(const LayoutIntegration::InlineContent& inlineContent, const InlineDisplay::Box& box, PaintInfo& paintInfo, const LayoutPoint& paintOffset)56 : TextBoxPainter(InlineIterator:: textBoxFor(inlineContent, box), paintInfo, paintOffset)57 ModernTextBoxPainter::ModernTextBoxPainter(const LayoutIntegration::InlineContent& inlineContent, const InlineDisplay::Box& box, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 58 : TextBoxPainter(InlineIterator::BoxModernPath { inlineContent, inlineContent.indexForBox(box) }, paintInfo, paintOffset) 57 59 { 58 60 } 59 61 #endif 60 62 61 TextBoxPainter::TextBoxPainter(const InlineIterator::TextBoxIterator& textBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 62 : m_textBox(textBox) 63 , m_renderer(m_textBox->renderer()) 63 template<typename TextBoxPath> 64 TextBoxPainter<TextBoxPath>::TextBoxPainter(TextBoxPath&& textBox, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 65 : m_textBox(WTFMove(textBox)) 66 , m_renderer(downcast<RenderText>(m_textBox.renderer())) 64 67 , m_document(m_renderer.document()) 65 , m_style(m_textBox->style()) 66 , m_paintTextRun(m_textBox->createTextRun()) 68 , m_style(m_textBox.style()) 69 , m_logicalRect(m_textBox.isHorizontal() ? m_textBox.visualRectIgnoringBlockDirection() : m_textBox.visualRectIgnoringBlockDirection().transposedRect()) 70 , m_paintTextRun(m_textBox.createTextRun(InlineIterator::CreateTextRunMode::Painting)) 67 71 , m_paintInfo(paintInfo) 68 , m_selectableRange(m_textBox ->selectableRange())72 , m_selectableRange(m_textBox.selectableRange()) 69 73 , m_paintRect(computePaintRect(paintOffset)) 70 , m_isFirstLine(m_textBox->lineBox()->isFirst()) 74 , m_isFirstLine(m_textBox.isFirstLine()) 75 , m_isCombinedText(is<RenderCombineText>(m_renderer) && downcast<RenderCombineText>(m_renderer).isCombined()) 71 76 , m_isPrinting(m_document.printing()) 72 77 , m_haveSelection(computeHaveSelection()) … … 77 82 } 78 83 79 TextBoxPainter::~TextBoxPainter() 80 { 81 } 82 83 void TextBoxPainter::paint() 84 template<typename TextBoxPath> 85 TextBoxPainter<TextBoxPath>::~TextBoxPainter() 86 { 87 } 88 89 template<typename TextBoxPath> 90 InlineIterator::TextBoxIterator TextBoxPainter<TextBoxPath>::makeIterator() const 91 { 92 auto pathCopy = m_textBox; 93 return InlineIterator::TextBoxIterator { WTFMove(pathCopy) }; 94 } 95 96 template<typename TextBoxPath> 97 void TextBoxPainter<TextBoxPath>::paint() 84 98 { 85 99 if (m_paintInfo.phase == PaintPhase::Selection && !m_haveSelection) … … 92 106 } 93 107 94 bool shouldRotate = !textBox().isHorizontal() && ! textBox().isCombinedText();108 bool shouldRotate = !textBox().isHorizontal() && !m_isCombinedText; 95 109 if (shouldRotate) 96 110 m_paintInfo.context().concatCTM(rotation(m_paintRect, Clockwise)); … … 116 130 } 117 131 118 MarkedText TextBoxPainter::createMarkedTextFromSelectionInBox() 132 template<typename TextBoxPath> 133 MarkedText TextBoxPainter<TextBoxPath>::createMarkedTextFromSelectionInBox() 119 134 { 120 135 auto [selectionStart, selectionEnd] = m_renderer.view().selection().rangeForTextBox(m_renderer, m_selectableRange); … … 124 139 } 125 140 126 void TextBoxPainter::paintBackground() 141 template<typename TextBoxPath> 142 void TextBoxPainter<TextBoxPath>::paintBackground() 127 143 { 128 144 auto shouldPaintCompositionBackground = m_containsComposition && !m_useCustomUnderlines; … … 170 186 } 171 187 172 void TextBoxPainter::paintForegroundAndDecorations() 188 template<typename TextBoxPath> 189 void TextBoxPainter<TextBoxPath>::paintForegroundAndDecorations() 173 190 { 174 191 auto shouldPaintSelectionForeground = m_haveSelection && !m_useCustomUnderlines; … … 232 249 233 250 if (hasDecoration && m_paintInfo.phase != PaintPhase::Selection) { 234 TextRun textRun = textBox().createTextRun(); 235 unsigned length = m_selectableRange.truncation.value_or(textRun.length()); 251 unsigned length = m_selectableRange.truncation.value_or(m_paintTextRun.length()); 236 252 unsigned selectionStart = 0; 237 253 unsigned selectionEnd = 0; … … 288 304 } 289 305 290 void TextBoxPainter::paintCompositionBackground() 306 template<typename TextBoxPath> 307 void TextBoxPainter<TextBoxPath>::paintCompositionBackground() 291 308 { 292 309 auto& editor = m_renderer.frame().editor(); … … 315 332 } 316 333 317 void TextBoxPainter::paintBackground(const StyledMarkedText& markedText) 318 { 319 paintBackground(markedText.startOffset, markedText.endOffset, markedText.style.backgroundColor); 320 } 321 322 void TextBoxPainter::paintBackground(unsigned startOffset, unsigned endOffset, const Color& color, BackgroundStyle backgroundStyle) 334 template<typename TextBoxPath> 335 void TextBoxPainter<TextBoxPath>::paintBackground(const StyledMarkedText& markedText) 336 { 337 paintBackground(markedText.startOffset, markedText.endOffset, markedText.style.backgroundColor, BackgroundStyle::Normal); 338 } 339 340 template<typename TextBoxPath> 341 void TextBoxPainter<TextBoxPath>::paintBackground(unsigned startOffset, unsigned endOffset, const Color& color, BackgroundStyle backgroundStyle) 323 342 { 324 343 if (startOffset >= endOffset) … … 331 350 // Note that if the text is truncated, we let the thing being painted in the truncation 332 351 // draw its own highlight. 333 auto lineBox = textBox().lineBox();352 auto lineBox = makeIterator()->lineBox(); 334 353 auto selectionBottom = LineSelection::logicalBottom(*lineBox); 335 354 auto selectionTop = LineSelection::logicalTopAdjustedForPrecedingBlock(*lineBox); 336 355 // Use same y positioning and height as for selection, so that when the selection and this subrange are on 337 356 // the same word there are no pieces sticking out. 338 auto deltaY = LayoutUnit { m_style.isFlippedLinesWritingMode() ? selectionBottom - textBox().logicalBottom() : textBox().logicalTop() - selectionTop };357 auto deltaY = LayoutUnit { m_style.isFlippedLinesWritingMode() ? selectionBottom - m_logicalRect.maxY() : m_logicalRect.y() - selectionTop }; 339 358 auto selectionHeight = LayoutUnit { std::max(0.f, selectionBottom - selectionTop) }; 340 auto selectionRect = LayoutRect { LayoutUnit(m_paintRect.x()), LayoutUnit(m_paintRect.y() - deltaY), LayoutUnit( textBox().logicalWidth()), selectionHeight };359 auto selectionRect = LayoutRect { LayoutUnit(m_paintRect.x()), LayoutUnit(m_paintRect.y() - deltaY), LayoutUnit(m_logicalRect.width()), selectionHeight }; 341 360 fontCascade().adjustSelectionRectForText(m_paintTextRun, selectionRect, startOffset, endOffset); 342 361 … … 353 372 } 354 373 355 void TextBoxPainter::paintForeground(const StyledMarkedText& markedText) 374 template<typename TextBoxPath> 375 void TextBoxPainter<TextBoxPath>::paintForeground(const StyledMarkedText& markedText) 356 376 { 357 377 if (markedText.startOffset >= markedText.endOffset) … … 374 394 textPainter.setShadowColorFilter(&m_style.appleColorFilter()); 375 395 } 376 textPainter.setEmphasisMark(emphasisMark, emphasisMarkOffset, textBox().isCombinedText()? &downcast<RenderCombineText>(m_renderer) : nullptr);396 textPainter.setEmphasisMark(emphasisMark, emphasisMarkOffset, m_isCombinedText ? &downcast<RenderCombineText>(m_renderer) : nullptr); 377 397 if (auto* debugShadow = debugTextShadow()) 378 398 textPainter.setShadow(debugShadow); … … 383 403 updateGraphicsContext(context, markedText.style.textStyles); 384 404 385 if (auto* legacyInlineBox = textBox().legacyInlineBox())386 textPainter.setGlyphDisplayListIfNeeded( *legacyInlineBox, m_paintInfo, m_paintTextRun);405 if constexpr (std::is_same_v<TextBoxPath, InlineIterator::BoxLegacyPath>) 406 textPainter.setGlyphDisplayListIfNeeded(downcast<LegacyInlineTextBox>(*textBox().legacyInlineBox()), m_paintInfo, m_paintTextRun); 387 407 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 388 408 else 389 textPainter.setGlyphDisplayListIfNeeded( *textBox().inlineBox(), m_paintInfo, m_paintTextRun);409 textPainter.setGlyphDisplayListIfNeeded(textBox().box(), m_paintInfo, m_paintTextRun); 390 410 #endif 391 411 … … 394 414 } 395 415 396 TextDecorationPainter TextBoxPainter::createDecorationPainter(const StyledMarkedText& markedText, const FloatRect& clipOutRect, const FloatRect& snappedSelectionRect) 416 template<typename TextBoxPath> 417 TextDecorationPainter TextBoxPainter<TextBoxPath>::createDecorationPainter(const StyledMarkedText& markedText, const FloatRect& clipOutRect, const FloatRect& snappedSelectionRect) 397 418 { 398 419 GraphicsContext& context = m_paintInfo.context(); … … 417 438 textDecorations.add(TextDecorationPainter::textDecorationsInEffectForStyle(markedText.style.textDecorationStyles)); 418 439 TextDecorationPainter decorationPainter { context, textDecorations, m_renderer, m_isFirstLine, font, markedText.style.textDecorationStyles }; 419 decorationPainter.setTextBox(m _textBox);440 decorationPainter.setTextBox(makeIterator()); 420 441 decorationPainter.setWidth(snappedSelectionRect.width()); 421 442 decorationPainter.setIsHorizontal(textBox().isHorizontal()); … … 429 450 } 430 451 431 void TextBoxPainter::paintBackgroundDecorations(TextDecorationPainter& decorationPainter, const StyledMarkedText& markedText, const FloatRect& snappedSelectionRect) 432 { 433 bool isCombinedText = textBox().isCombinedText(); 434 if ( isCombinedText)452 template<typename TextBoxPath> 453 void TextBoxPainter<TextBoxPath>::paintBackgroundDecorations(TextDecorationPainter& decorationPainter, const StyledMarkedText& markedText, const FloatRect& snappedSelectionRect) 454 { 455 if (m_isCombinedText) 435 456 m_paintInfo.context().concatCTM(rotation(m_paintRect, Clockwise)); 436 457 437 458 decorationPainter.paintBackgroundDecorations(m_paintTextRun.subRun(markedText.startOffset, markedText.endOffset - markedText.startOffset), textOriginFromPaintRect(snappedSelectionRect), snappedSelectionRect.location()); 438 459 439 if ( isCombinedText)460 if (m_isCombinedText) 440 461 m_paintInfo.context().concatCTM(rotation(m_paintRect, Counterclockwise)); 441 462 } 442 463 443 void TextBoxPainter::paintForegroundDecorations(TextDecorationPainter& decorationPainter, const FloatRect& snappedSelectionRect) 444 { 445 bool isCombinedText = textBox().isCombinedText(); 446 if ( isCombinedText)464 template<typename TextBoxPath> 465 void TextBoxPainter<TextBoxPath>::paintForegroundDecorations(TextDecorationPainter& decorationPainter, const FloatRect& snappedSelectionRect) 466 { 467 if (m_isCombinedText) 447 468 m_paintInfo.context().concatCTM(rotation(m_paintRect, Clockwise)); 448 469 449 470 decorationPainter.paintForegroundDecorations(snappedSelectionRect.location()); 450 471 451 if ( isCombinedText)472 if (m_isCombinedText) 452 473 m_paintInfo.context().concatCTM(rotation(m_paintRect, Counterclockwise)); 453 474 } 454 475 455 void TextBoxPainter::paintCompositionUnderlines() 476 template<typename TextBoxPath> 477 void TextBoxPainter<TextBoxPath>::paintCompositionUnderlines() 456 478 { 457 479 for (auto& underline : m_renderer.frame().editor().customCompositionUnderlines()) { … … 481 503 } 482 504 483 static float textPosition(const InlineIterator::TextBoxIterator& textBox) 505 template<typename TextBoxPath> 506 float TextBoxPainter<TextBoxPath>::textPosition() 484 507 { 485 508 // When computing the width of a text run, RenderBlock::computeInlineDirectionPositionsForLine() doesn't include the actual offset 486 509 // from the containing block edge in its measurement. textPosition() should be consistent so the text are rendered in the same width. 487 if (! textBox->logicalLeft())510 if (!m_logicalRect.x()) 488 511 return 0; 489 return textBox->logicalLeft() - textBox->lineBox()->contentLogicalLeft(); 490 } 491 492 void TextBoxPainter::paintCompositionUnderline(const CompositionUnderline& underline) 512 return m_logicalRect.x() - makeIterator()->lineBox()->contentLogicalLeft(); 513 } 514 515 template<typename TextBoxPath> 516 void TextBoxPainter<TextBoxPath>::paintCompositionUnderline(const CompositionUnderline& underline) 493 517 { 494 518 float start = 0; // start of line to draw, relative to tx 495 float width = textBox().logicalWidth(); // how much line to draw519 float width = m_logicalRect.width(); // how much line to draw 496 520 bool useWholeWidth = true; 497 521 unsigned paintStart = textBox().start(); … … 500 524 paintStart = underline.startOffset; 501 525 useWholeWidth = false; 502 start = m_renderer.width(textBox().start(), paintStart - textBox().start(), textPosition( m_textBox), m_isFirstLine);526 start = m_renderer.width(textBox().start(), paintStart - textBox().start(), textPosition(), m_isFirstLine); 503 527 } 504 528 if (paintEnd != underline.endOffset) { … … 511 535 } 512 536 if (!useWholeWidth) { 513 width = m_renderer.width(paintStart, paintEnd - paintStart, textPosition( m_textBox) + start, m_isFirstLine);514 mirrorRTLSegment( textBox().logicalWidth(), textBox().direction(), start, width);537 width = m_renderer.width(paintStart, paintEnd - paintStart, textPosition() + start, m_isFirstLine); 538 mirrorRTLSegment(m_logicalRect.width(), textBox().direction(), start, width); 515 539 } 516 540 … … 520 544 int lineThickness = 1; 521 545 int baseline = m_style.metricsOfPrimaryFont().ascent(); 522 if (underline.thick && textBox().logicalHeight() - baseline >= 2)546 if (underline.thick && m_logicalRect.height() - baseline >= 2) 523 547 lineThickness = 2; 524 548 … … 534 558 context.setStrokeColor(underlineColor); 535 559 context.setStrokeThickness(lineThickness); 536 context.drawLineForText(FloatRect(m_paintRect.x() + start, m_paintRect.y() + textBox().logicalHeight() - lineThickness, width, lineThickness), m_document.printing()); 537 } 538 539 void TextBoxPainter::paintPlatformDocumentMarkers() 560 context.drawLineForText(FloatRect(m_paintRect.x() + start, m_paintRect.y() + m_logicalRect.height() - lineThickness, width, lineThickness), m_isPrinting); 561 } 562 563 template<typename TextBoxPath> 564 void TextBoxPainter<TextBoxPath>::paintPlatformDocumentMarkers() 540 565 { 541 566 auto markedTexts = MarkedText::collectForDocumentMarkers(m_renderer, m_selectableRange, MarkedText::PaintPhase::Decoration); … … 544 569 } 545 570 546 FloatRect TextBoxPainter::calculateUnionOfAllDocumentMarkerBounds(const LegacyInlineTextBox& textBox)571 FloatRect LegacyTextBoxPainter::calculateUnionOfAllDocumentMarkerBounds(const LegacyInlineTextBox& textBox) 547 572 { 548 573 // This must match paintPlatformDocumentMarkers(). … … 554 579 } 555 580 556 void TextBoxPainter::paintPlatformDocumentMarker(const MarkedText& markedText) 581 template<typename TextBoxPath> 582 void TextBoxPainter<TextBoxPath>::paintPlatformDocumentMarker(const MarkedText& markedText) 557 583 { 558 584 // Never print spelling/grammar markers (5327887) … … 560 586 return; 561 587 562 auto bounds = calculateDocumentMarkerBounds(m _textBox, markedText);588 auto bounds = calculateDocumentMarkerBounds(makeIterator(), markedText); 563 589 564 590 auto lineStyleForMarkedTextType = [&]() -> DocumentMarkerLineStyle { … … 588 614 } 589 615 590 FloatRect TextBoxPainter::computePaintRect(const LayoutPoint& paintOffset) 616 template<typename TextBoxPath> 617 FloatRect TextBoxPainter<TextBoxPath>::computePaintRect(const LayoutPoint& paintOffset) 591 618 { 592 619 FloatPoint localPaintOffset(paintOffset); 593 620 594 621 if (m_selectableRange.truncation) { 595 if (m_renderer.containingBlock()->style(). isLeftToRightDirection() != textBox().isLeftToRightDirection()) {622 if (m_renderer.containingBlock()->style().direction() != textBox().direction()) { 596 623 // Make the visible fragment of text hug the edge closest to the rest of the run by moving the origin 597 624 // at which we start drawing text. … … 602 629 // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the 603 630 // truncated string i.e. |Hello|CBA| -> |...lo|CBA| 604 LayoutUnit widthOfVisibleText { m_renderer.width(textBox().start(), *m_selectableRange.truncation, textPosition( m_textBox), m_isFirstLine) };605 LayoutUnit widthOfHiddenText { textBox().logicalWidth() - widthOfVisibleText };606 LayoutSize truncationOffset(textBox(). isLeftToRightDirection()? widthOfHiddenText : -widthOfHiddenText, 0_lu);631 LayoutUnit widthOfVisibleText { m_renderer.width(textBox().start(), *m_selectableRange.truncation, textPosition(), m_isFirstLine) }; 632 LayoutUnit widthOfHiddenText { m_logicalRect.width() - widthOfVisibleText }; 633 LayoutSize truncationOffset(textBox().direction() == TextDirection::LTR ? widthOfHiddenText : -widthOfHiddenText, 0_lu); 607 634 localPaintOffset.move(textBox().isHorizontal() ? truncationOffset : truncationOffset.transposedSize()); 608 635 } 609 636 } 610 637 611 localPaintOffset.move(0, m_style.isHorizontalWritingMode() ? 0 : -textBox().logicalHeight()); 612 613 auto boxOrigin = textBox().visualRect(textBox().lineBox()->containingBlock().logicalHeight()).location(); 638 localPaintOffset.move(0, m_style.isHorizontalWritingMode() ? 0 : -m_logicalRect.height()); 639 640 auto visualRect = textBox().visualRectIgnoringBlockDirection(); 641 textBox().containingBlock().flipForWritingMode(visualRect); 642 643 auto boxOrigin = visualRect.location(); 614 644 boxOrigin.moveBy(localPaintOffset); 615 return { boxOrigin, FloatSize( textBox().logicalWidth(), textBox().logicalHeight()) };616 } 617 618 FloatRect TextBoxPainter::calculateDocumentMarkerBounds(const InlineIterator::TextBoxIterator& textBox, const MarkedText& markedText)645 return { boxOrigin, FloatSize(m_logicalRect.width(), m_logicalRect.height()) }; 646 } 647 648 FloatRect calculateDocumentMarkerBounds(const InlineIterator::TextBoxIterator& textBox, const MarkedText& markedText) 619 649 { 620 650 auto& font = textBox->fontCascade(); … … 635 665 } 636 666 637 bool TextBoxPainter::computeHaveSelection() const 667 template<typename TextBoxPath> 668 bool TextBoxPainter<TextBoxPath>::computeHaveSelection() const 638 669 { 639 670 if (m_isPrinting || m_paintInfo.phase == PaintPhase::TextClip) … … 643 674 } 644 675 645 const FontCascade& TextBoxPainter::fontCascade() const 646 { 647 return m_textBox->fontCascade(); 648 } 649 650 FloatPoint TextBoxPainter::textOriginFromPaintRect(const FloatRect& paintRect) const 676 template<typename TextBoxPath> 677 const FontCascade& TextBoxPainter<TextBoxPath>::fontCascade() const 678 { 679 if (m_isCombinedText) 680 return downcast<RenderCombineText>(m_renderer).textCombineFont(); 681 682 return m_textBox.style().fontCascade(); 683 } 684 685 template<typename TextBoxPath> 686 FloatPoint TextBoxPainter<TextBoxPath>::textOriginFromPaintRect(const FloatRect& paintRect) const 651 687 { 652 688 FloatPoint textOrigin { paintRect.x(), paintRect.y() + fontCascade().metricsOfPrimaryFont().ascent() }; 653 if ( textBox().isCombinedText()) {689 if (m_isCombinedText) { 654 690 if (auto newOrigin = downcast<RenderCombineText>(m_renderer).computeTextOrigin(paintRect)) 655 691 textOrigin = newOrigin.value(); … … 662 698 } 663 699 664 const ShadowData* TextBoxPainter::debugTextShadow() const 700 template<typename TextBoxPath> 701 const ShadowData* TextBoxPainter<TextBoxPath>::debugTextShadow() const 665 702 { 666 703 if (!m_renderer.settings().legacyLineLayoutVisualCoverageEnabled()) 667 704 return nullptr; 668 if (!textBox().legacyInlineBox())705 if constexpr (std::is_same_v<TextBoxPath, InlineIterator::BoxModernPath>) 669 706 return nullptr; 670 707 … … 673 710 } 674 711 675 } 712 template class TextBoxPainter<InlineIterator::BoxModernPath>; 713 template class TextBoxPainter<InlineIterator::BoxLegacyPath>; 714 715 } -
trunk/Source/WebCore/rendering/TextBoxPainter.h
r294279 r294383 46 46 struct StyledMarkedText; 47 47 48 template<typename TextBoxPath> 48 49 class TextBoxPainter { 49 50 public: 50 TextBoxPainter(const LegacyInlineTextBox&, PaintInfo&, const LayoutPoint& paintOffset); 51 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 52 TextBoxPainter(const LayoutIntegration::InlineContent&, const InlineDisplay::Box&, PaintInfo&, const LayoutPoint& paintOffset); 53 #endif 54 TextBoxPainter(const InlineIterator::TextBoxIterator&, PaintInfo&, const LayoutPoint& paintOffset); 55 51 TextBoxPainter(TextBoxPath&&, PaintInfo&, const LayoutPoint& paintOffset); 56 52 ~TextBoxPainter(); 57 53 58 54 void paint(); 59 55 60 static FloatRect calculateUnionOfAllDocumentMarkerBounds(const LegacyInlineTextBox&); 61 62 private: 63 auto& textBox() const { return *m_textBox; } 56 protected: 57 auto& textBox() const { return m_textBox; } 58 InlineIterator::TextBoxIterator makeIterator() const; 64 59 65 60 void paintBackground(); … … 79 74 void paintPlatformDocumentMarker(const MarkedText&); 80 75 81 static FloatRect calculateDocumentMarkerBounds(const InlineIterator::TextBoxIterator&, const MarkedText&); 82 76 float textPosition(); 83 77 FloatRect computePaintRect(const LayoutPoint& paintOffset); 84 78 bool computeHaveSelection() const; … … 89 83 const ShadowData* debugTextShadow() const; 90 84 91 const InlineIterator::TextBoxIteratorm_textBox;85 const TextBoxPath m_textBox; 92 86 const RenderText& m_renderer; 93 87 const Document& m_document; 94 88 const RenderStyle& m_style; 89 const FloatRect m_logicalRect; 95 90 const TextRun m_paintTextRun; 96 91 PaintInfo& m_paintInfo; … … 98 93 const FloatRect m_paintRect; 99 94 const bool m_isFirstLine; 95 const bool m_isCombinedText; 100 96 const bool m_isPrinting; 101 97 const bool m_haveSelection; … … 105 101 }; 106 102 103 class LegacyTextBoxPainter : public TextBoxPainter<InlineIterator::BoxLegacyPath> { 104 public: 105 LegacyTextBoxPainter(const LegacyInlineTextBox&, PaintInfo&, const LayoutPoint& paintOffset); 106 107 static FloatRect calculateUnionOfAllDocumentMarkerBounds(const LegacyInlineTextBox&); 108 }; 109 110 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 111 class ModernTextBoxPainter : public TextBoxPainter<InlineIterator::BoxModernPath> { 112 public: 113 ModernTextBoxPainter(const LayoutIntegration::InlineContent&, const InlineDisplay::Box&, PaintInfo&, const LayoutPoint& paintOffset); 114 }; 115 #endif 116 107 117 }
Note:
See TracChangeset
for help on using the changeset viewer.