WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-243619-20220805172314.patch (text/plain), 11.83 KB, created by
alan
on 2022-08-05 17:23:15 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
alan
Created:
2022-08-05 17:23:15 PDT
Size:
11.83 KB
patch
obsolete
>From bee4f435a666f1746305f4e6d0e375451aeb5393 Mon Sep 17 00:00:00 2001 >From: Alan Bujtas <zalan@apple.com> >Date: Fri, 5 Aug 2022 17:13:03 -0700 >Subject: [PATCH] [Painting] Introduce DecoratingBoxStyleAndOffsetForUnderline > https://bugs.webkit.org/show_bug.cgi?id=243619 > >Reviewed by NOBODY (OOPS!). > >Let's grab the underline style (and the offset) from the decorating box and not from the RenderText itself. >This is in preparation for cases when we start drawing multiple lines for a text run with (possibly) different style. > >* Source/WebCore/rendering/TextDecorationPainter.cpp: >(WebCore::TextDecorationPainter::paintBackgroundDecorations): >* Source/WebCore/style/InlineTextBoxStyle.cpp: >(WebCore::minLogicalTopForTextDecorationLine): >(WebCore::maxLogicalBottomForTextDecorationLine): >(WebCore::textRunOffsetFromBottomMostWithinDecoratingBox): >(WebCore::textRunOffsetFromBottomMost): >(WebCore::computeUnderlineOffset): >(WebCore::underlineOffsetForTextBoxPainting): >* Source/WebCore/style/InlineTextBoxStyle.h: >--- > .../rendering/TextDecorationPainter.cpp | 12 ++-- > Source/WebCore/style/InlineTextBoxStyle.cpp | 62 ++++++++++++------- > Source/WebCore/style/InlineTextBoxStyle.h | 8 ++- > 3 files changed, 53 insertions(+), 29 deletions(-) > >diff --git a/Source/WebCore/rendering/TextDecorationPainter.cpp b/Source/WebCore/rendering/TextDecorationPainter.cpp >index d64f533fbfd6..5028892e5f71 100644 >--- a/Source/WebCore/rendering/TextDecorationPainter.cpp >+++ b/Source/WebCore/rendering/TextDecorationPainter.cpp >@@ -284,11 +284,13 @@ void TextDecorationPainter::paintBackgroundDecorations(const TextRun& textRun, c > > // These decorations should match the visual overflows computed in visualOverflowForDecorations(). > if (m_decorations.contains(TextDecorationLine::Underline)) { >- auto offset = underlineOffsetForTextBoxPainting(m_lineStyle, m_textBox); >- float wavyOffset = m_styles.underlineStyle == TextDecorationStyle::Wavy ? m_wavyOffset : 0; >- FloatRect rect(localOrigin, FloatSize(m_width, textDecorationThickness)); >- rect.move(0, offset + wavyOffset); >- paintDecoration(TextDecorationLine::Underline, m_styles.underlineStyle, m_styles.underlineColor, rect); >+ auto decoratingBoxStyleAndOffset = underlineStyleAndOffsetForTextBoxPainting(m_textBox); >+ auto underlineRect = FloatRect { localOrigin, FloatSize { m_width, decoratingBoxStyleAndOffset.thickness } }; >+ auto wavyOffset = decoratingBoxStyleAndOffset.style == TextDecorationStyle::Wavy ? m_wavyOffset : 0.f; >+ auto bottomOffset = decoratingBoxStyleAndOffset.offsetFromTextBoxLogicalBottom + wavyOffset; >+ >+ underlineRect.move(0.f, bottomOffset); >+ paintDecoration(TextDecorationLine::Underline, decoratingBoxStyleAndOffset.style, decoratingBoxStyleAndOffset.color, underlineRect); > } > if (m_decorations.contains(TextDecorationLine::Overline)) { > float wavyOffset = m_styles.overlineStyle == TextDecorationStyle::Wavy ? m_wavyOffset : 0; >diff --git a/Source/WebCore/style/InlineTextBoxStyle.cpp b/Source/WebCore/style/InlineTextBoxStyle.cpp >index b6c3b2464de3..80a07e4f0f1d 100644 >--- a/Source/WebCore/style/InlineTextBoxStyle.cpp >+++ b/Source/WebCore/style/InlineTextBoxStyle.cpp >@@ -38,7 +38,7 @@ > namespace WebCore { > > struct UnderlineOffsetArguments { >- const RenderStyle& lineStyle; >+ const RenderStyle& decoratingBoxStyle; > float defaultGap { 0 }; > std::optional<TextUnderlinePositionUnder> textUnderlinePositionUnder { }; > }; >@@ -54,7 +54,7 @@ static bool isAncestorAndWithinBlock(const RenderInline& ancestor, const RenderO > return false; > } > >-static float minLogicalTopForTextDecorationLine(const InlineIterator::LineBoxIterator& lineBox, float textRunLogicalTop, const RenderElement* decorationRenderer) >+static float minLogicalTopForTextDecorationLine(const InlineIterator::LineBoxIterator& lineBox, float textRunLogicalTop, const RenderElement& decorationRenderer) > { > auto minLogicalTop = textRunLogicalTop; > for (auto run = lineBox->firstLeafBox(); run; run.traverseNextOnLine()) { >@@ -64,7 +64,7 @@ static float minLogicalTopForTextDecorationLine(const InlineIterator::LineBoxIte > if (!run->style().textDecorationsInEffect().contains(TextDecorationLine::Underline)) > continue; // If the text decoration isn't in effect on the child, then it must be outside of |decorationRenderer|'s hierarchy. > >- if (decorationRenderer && decorationRenderer->isRenderInline() && !isAncestorAndWithinBlock(downcast<RenderInline>(*decorationRenderer), &run->renderer())) >+ if (decorationRenderer.isRenderInline() && !isAncestorAndWithinBlock(downcast<RenderInline>(decorationRenderer), &run->renderer())) > continue; > > if (run->isText() || run->style().textDecorationSkipInk() == TextDecorationSkipInk::None) >@@ -73,7 +73,7 @@ static float minLogicalTopForTextDecorationLine(const InlineIterator::LineBoxIte > return minLogicalTop; > } > >-static float maxLogicalBottomForTextDecorationLine(const InlineIterator::LineBoxIterator& lineBox, float textRunLogicalBottom, const RenderElement* decorationRenderer) >+static float maxLogicalBottomForTextDecorationLine(const InlineIterator::LineBoxIterator& lineBox, float textRunLogicalBottom, const RenderElement& decorationRenderer) > { > auto maxLogicalBottom = textRunLogicalBottom; > for (auto run = lineBox->firstLeafBox(); run; run.traverseNextOnLine()) { >@@ -83,7 +83,7 @@ static float maxLogicalBottomForTextDecorationLine(const InlineIterator::LineBox > if (!run->style().textDecorationsInEffect().contains(TextDecorationLine::Underline)) > continue; // If the text decoration isn't in effect on the child, then it must be outside of |decorationRenderer|'s hierarchy. > >- if (decorationRenderer && decorationRenderer->isRenderInline() && !isAncestorAndWithinBlock(downcast<RenderInline>(*decorationRenderer), &run->renderer())) >+ if (decorationRenderer.isRenderInline() && !isAncestorAndWithinBlock(downcast<RenderInline>(decorationRenderer), &run->renderer())) > continue; > > if (run->isText() || run->style().textDecorationSkipInk() == TextDecorationSkipInk::None) >@@ -110,18 +110,20 @@ static const RenderElement* enclosingRendererWithTextDecoration(const RenderText > return current; > } > >+static float textRunOffsetFromBottomMostWithinDecoratingBox(const InlineIterator::LineBoxIterator& lineBox, const RenderElement& decorationRenderer, bool isFlippedLinesWritingMode, float textBoxLogicalTop, float textBoxLogicalBottom) >+{ >+ if (isFlippedLinesWritingMode) >+ return textBoxLogicalTop - minLogicalTopForTextDecorationLine(lineBox, textBoxLogicalTop, decorationRenderer); >+ return maxLogicalBottomForTextDecorationLine(lineBox, textBoxLogicalBottom, decorationRenderer) - textBoxLogicalBottom; >+} >+ > static float textRunOffsetFromBottomMost(const InlineIterator::LineBoxIterator& lineBox, const RenderText& renderer, float textBoxLogicalTop, float textBoxLogicalBottom) > { >- float offset = 0.f; > auto* decorationRenderer = enclosingRendererWithTextDecoration(renderer, lineBox->isFirst()); >- if (renderer.style().isFlippedLinesWritingMode()) { >- auto minLogicalTop = minLogicalTopForTextDecorationLine(lineBox, textBoxLogicalTop, decorationRenderer); >- offset = textBoxLogicalTop - minLogicalTop; >- } else { >- offset = maxLogicalBottomForTextDecorationLine(lineBox, textBoxLogicalBottom, decorationRenderer); >- offset -= textBoxLogicalBottom; >- } >- return offset; >+ if (!decorationRenderer) >+ return 0.f; >+ >+ return textRunOffsetFromBottomMostWithinDecoratingBox(lineBox, *decorationRenderer, decorationRenderer->style().isFlippedLinesWritingMode(), textBoxLogicalTop, textBoxLogicalBottom); > } > > static inline float defaultGap(const RenderStyle& style) >@@ -144,9 +146,9 @@ static float computeUnderlineOffset(const UnderlineOffsetArguments& context) > // even if it is horizontal, but detecting this has performance implications. For now we only work with > // vertical text, since we already determined the baseline type to be ideographic in that > // case. >- auto underlinePosition = context.lineStyle.textUnderlinePosition(); >- auto underlineOffset = context.lineStyle.textUnderlineOffset(); >- auto& fontMetrics = context.lineStyle.metricsOfPrimaryFont(); >+ auto underlinePosition = context.decoratingBoxStyle.textUnderlinePosition(); >+ auto underlineOffset = context.decoratingBoxStyle.textUnderlineOffset(); >+ auto& fontMetrics = context.decoratingBoxStyle.metricsOfPrimaryFont(); > > auto resolvedUnderlinePosition = underlinePosition; > if (resolvedUnderlinePosition == TextUnderlinePosition::Auto && underlineOffset.isAuto()) { >@@ -276,14 +278,28 @@ GlyphOverflow visualOverflowForDecorations(const RenderStyle& style) > return computedVisualOverflowForDecorations(style, underlineOffset); > } > >-float underlineOffsetForTextBoxPainting(const RenderStyle& style, const InlineIterator::TextBoxIterator& textBox) >+DecoratingBoxStyleAndOffsetForUnderline underlineStyleAndOffsetForTextBoxPainting(const InlineIterator::TextBoxIterator& textBox) > { >- auto textUnderlinePositionUnder = TextUnderlinePositionUnder { >- textBox->lineBox()->baselineType(), >- textBox->logicalBottom() - textBox->logicalTop(), >- textRunOffsetFromBottomMost(textBox->lineBox(), textBox->renderer(), textBox->logicalTop(), textBox->logicalBottom()) >+ // 1. Find the decorating box for this text run (for root inline box content, it's the containing block, for text inside an inline box, it's mostly the parent inline box itself) >+ // 2. compute the offset and use the associated style to return. >+ auto lineBox = textBox->lineBox(); >+ auto isFirstLine = lineBox->isFirst(); >+ >+ auto* decorationRenderer = enclosingRendererWithTextDecoration(textBox->renderer(), isFirstLine); >+ if (!decorationRenderer) { >+ ASSERT_NOT_REACHED(); >+ return { }; >+ } >+ >+ auto& style = isFirstLine ? decorationRenderer->firstLineStyle() : decorationRenderer->style(); >+ auto textRunOffset = textRunOffsetFromBottomMostWithinDecoratingBox(lineBox, *decorationRenderer, style.isFlippedLinesWritingMode(), textBox->logicalTop(), textBox->logicalBottom()); >+ auto textBoxHeight = textBox->logicalBottom() - textBox->logicalTop(); >+ return { >+ style.textDecorationStyle(), >+ style.visitedDependentColorWithColorFilter(CSSPropertyTextDecorationColor), >+ ceilToDevicePixel(style.textDecorationThickness().resolve(style.computedFontSize(), style.metricsOfPrimaryFont()), decorationRenderer->document().deviceScaleFactor()), >+ computeUnderlineOffset({ style , defaultGap(style), TextUnderlinePositionUnder { lineBox->baselineType(), textBoxHeight, textRunOffset } }) > }; >- return computeUnderlineOffset({ style , defaultGap(style), textUnderlinePositionUnder }); > } > > } >diff --git a/Source/WebCore/style/InlineTextBoxStyle.h b/Source/WebCore/style/InlineTextBoxStyle.h >index 8b07c5a929ba..dbc5d1ddb6b8 100644 >--- a/Source/WebCore/style/InlineTextBoxStyle.h >+++ b/Source/WebCore/style/InlineTextBoxStyle.h >@@ -65,6 +65,12 @@ GlyphOverflow visualOverflowForDecorations(const RenderStyle&); > GlyphOverflow visualOverflowForDecorations(const RenderStyle&, TextUnderlinePositionUnder); > GlyphOverflow visualOverflowForDecorations(const InlineIterator::LineBoxIterator&, const RenderText&, float textBoxLogicalTop, float textBoxLogicalBottom); > >-float underlineOffsetForTextBoxPainting(const RenderStyle&, const InlineIterator::TextBoxIterator&); >+struct DecoratingBoxStyleAndOffsetForUnderline { >+ TextDecorationStyle style { TextDecorationStyle::Solid }; >+ Color color; >+ float thickness { 0.f }; >+ float offsetFromTextBoxLogicalBottom { 0.f }; >+}; >+DecoratingBoxStyleAndOffsetForUnderline underlineStyleAndOffsetForTextBoxPainting(const InlineIterator::TextBoxIterator&); > > } // namespace WebCore
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 243619
:
461434
|
461451
|
461453
|
461454
|
461457
|
461458
|
461459
|
461460