Changeset 295444 in webkit


Ignore:
Timestamp:
Jun 9, 2022 8:08:10 PM (2 years ago)
Author:
Alan Bujtas
Message:

computeUnderlineOffset should not take TextRun
https://bugs.webkit.org/show_bug.cgi?id=241471

Reviewed by Antti Koivisto.

This is in preparation for taking visual overflow for decoration into account in IFC.

  • Source/WebCore/rendering/TextDecorationPainter.cpp:

(WebCore::TextDecorationPainter::paintBackgroundDecorations):

  • Source/WebCore/style/InlineTextBoxStyle.cpp:

(WebCore::computeUnderlineOffset):
(WebCore::visualOverflowForDecorations):

  • Source/WebCore/style/InlineTextBoxStyle.h:

Canonical link: https://commits.webkit.org/251450@main

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/TextDecorationPainter.cpp

    r293217 r295444  
    2929#include "HTMLAnchorElement.h"
    3030#include "HTMLFontElement.h"
     31#include "InlineIteratorLineBox.h"
    3132#include "InlineTextBoxStyle.h"
    3233#include "RenderBlock.h"
     
    280281            float textDecorationBaseFontSize = 16;
    281282            auto defaultGap = m_lineStyle.computedFontSize() / textDecorationBaseFontSize;
    282             float offset = computeUnderlineOffset(m_lineStyle.textUnderlinePosition(), m_lineStyle.textUnderlineOffset(), m_lineStyle.metricsOfPrimaryFont(), m_textBox, defaultGap);
     283            float offset = computeUnderlineOffset({ m_lineStyle
     284                , defaultGap
     285                , &m_textBox->renderer()
     286                , m_textBox->lineBox()->baselineType()
     287                , m_textBox->logicalTop()
     288                , m_textBox->logicalBottom()
     289                , m_textBox->lineBox()
     290            });
    283291            float wavyOffset = m_styles.underlineStyle == TextDecorationStyle::Wavy ? m_wavyOffset : 0;
    284292            FloatRect rect(localOrigin, FloatSize(m_width, textDecorationThickness));
  • trunk/Source/WebCore/style/InlineTextBoxStyle.cpp

    r291548 r295444  
    3030#include "HTMLAnchorElement.h"
    3131#include "HTMLNames.h"
    32 #include "InlineIteratorLineBox.h"
    3332#include "InlineIteratorTextBox.h"
    3433#include "LegacyInlineTextBox.h"
     
    102101}
    103102   
    104 float computeUnderlineOffset(TextUnderlinePosition underlinePosition, TextUnderlineOffset underlineOffset, const FontMetrics& fontMetrics, const InlineIterator::TextBoxIterator& textRun, float defaultGap)
     103float computeUnderlineOffset(const UnderlineOffsetArguments& context)
    105104{
    106105    // This represents the gap between the baseline and the closest edge of the underline.
    107     float gap = std::max<int>(1, std::ceil(defaultGap / 2.0f));
     106    float gap = std::max<int>(1, std::ceil(context.defaultGap / 2.0f));
    108107   
    109108    // FIXME: The code for visual overflow detection passes in a null inline text box. This means it is now
     
    116115    // vertical text, since we already determined the baseline type to be ideographic in that
    117116    // case.
    118    
     117    auto underlinePosition = context.lineStyle.textUnderlinePosition();
     118    auto underlineOffset = context.lineStyle.textUnderlineOffset();
     119    auto& fontMetrics = context.lineStyle.metricsOfPrimaryFont();
     120
    119121    auto resolvedUnderlinePosition = underlinePosition;
    120122    if (resolvedUnderlinePosition == TextUnderlinePosition::Auto && underlineOffset.isAuto()) {
    121         if (textRun)
    122             resolvedUnderlinePosition = textRun->lineBox()->baselineType() == IdeographicBaseline ? TextUnderlinePosition::Under : TextUnderlinePosition::Auto;
     123        if (context.renderer)
     124            resolvedUnderlinePosition = context.baselineType == IdeographicBaseline ? TextUnderlinePosition::Under : TextUnderlinePosition::Auto;
    123125        else
    124126            resolvedUnderlinePosition = TextUnderlinePosition::Auto;
     
    133135        return fontMetrics.ascent() + fontMetrics.underlinePosition() + underlineOffset.lengthOr(0);
    134136    case TextUnderlinePosition::Under: {
    135         ASSERT(textRun);
     137        ASSERT(context.lineBox && context.renderer);
    136138        // Position underline relative to the bottom edge of the lowest element's content box.
    137         auto lineBox = textRun->lineBox();
    138         auto* decorationRenderer = enclosingRendererWithTextDecoration(textRun->renderer(), TextDecorationLine::Underline, lineBox->isFirst());
     139        auto* decorationRenderer = enclosingRendererWithTextDecoration(*context.renderer, TextDecorationLine::Underline, context.lineBox->isFirst());
    139140       
    140141        float offset;
    141         if (textRun->renderer().style().isFlippedLinesWritingMode()) {
    142             offset = textRun->logicalTop();
    143             minLogicalTopForTextDecorationLine(lineBox, offset, decorationRenderer, TextDecorationLine::Underline);
    144             offset = textRun->logicalTop() - offset;
     142        if (context.renderer->style().isFlippedLinesWritingMode()) {
     143            offset = context.textRunLogicalTop;
     144            minLogicalTopForTextDecorationLine(context.lineBox, offset, decorationRenderer, TextDecorationLine::Underline);
     145            offset = context.textRunLogicalTop - offset;
    145146        } else {
    146             offset = textRun->logicalBottom();
    147             maxLogicalBottomForTextDecorationLine(lineBox, offset, decorationRenderer, TextDecorationLine::Underline);
    148             offset -= textRun->logicalBottom();
    149         }
    150         auto desiredOffset = textRun->logicalHeight() + gap + std::max(offset, 0.0f) + underlineOffset.lengthOr(0);
     147            offset = context.textRunLogicalBottom;
     148            maxLogicalBottomForTextDecorationLine(context.lineBox, offset, decorationRenderer, TextDecorationLine::Underline);
     149            offset -= context.textRunLogicalBottom;
     150        }
     151        auto textRunLogicalHeight = context.textRunLogicalBottom - context.textRunLogicalTop;
     152        auto desiredOffset = textRunLogicalHeight + gap + std::max(offset, 0.0f) + underlineOffset.lengthOr(0);
    151153        return std::max<float>(desiredOffset, fontMetrics.ascent());
    152154    }
     
    196198        float textDecorationBaseFontSize = 16;
    197199        auto defaultGap = lineStyle.computedFontSize() / textDecorationBaseFontSize;
    198         underlineOffset += computeUnderlineOffset(lineStyle.textUnderlinePosition(), lineStyle.textUnderlineOffset(), lineStyle.metricsOfPrimaryFont(), textRun, defaultGap);
     200        // FIXME: RenderStyle calls us with empty textRun but only when TextUnderlinePosition is not Under.
     201        ASSERT(textRun || lineStyle.textUnderlinePosition() != TextUnderlinePosition::Under);
     202        if (!textRun)
     203            underlineOffset += computeUnderlineOffset({ lineStyle, defaultGap });
     204        else {
     205            underlineOffset += computeUnderlineOffset({ lineStyle
     206                , defaultGap
     207                , &textRun->renderer()
     208                , textRun->lineBox()->baselineType()
     209                , textRun->logicalTop()
     210                , textRun->logicalBottom()
     211                , textRun->lineBox()
     212            });
     213        }
     214
    199215        if (decorationStyle == TextDecorationStyle::Wavy) {
    200216            overflowResult.extendBottom(underlineOffset + wavyOffset + wavyStrokeParameters.controlPointDistance + strokeThickness - height);
  • trunk/Source/WebCore/style/InlineTextBoxStyle.h

    r283443 r295444  
    2828#include "FontCascade.h"
    2929#include "InlineIteratorBox.h"
     30#include "InlineIteratorLineBox.h"
    3031#include "RenderStyleConstants.h"
    3132
     
    5455WavyStrokeParameters getWavyStrokeParameters(float fontSize);
    5556GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, const InlineIterator::TextBoxIterator&);
    56 float computeUnderlineOffset(TextUnderlinePosition, TextUnderlineOffset, const FontMetrics&, const InlineIterator::TextBoxIterator&, float textDecorationThickness);
     57
     58struct UnderlineOffsetArguments {
     59    const RenderStyle& lineStyle;
     60    float defaultGap { 0 };
     61    const RenderText* renderer { nullptr };
     62    FontBaseline baselineType { AlphabeticBaseline };
     63    float textRunLogicalTop { 0 };
     64    float textRunLogicalBottom { 0 };
     65    InlineIterator::LineBoxIterator lineBox { };
     66};
     67float computeUnderlineOffset(const UnderlineOffsetArguments&);
    5768   
    5869} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.