Changeset 295455 in webkit


Ignore:
Timestamp:
Jun 10, 2022 10:09:37 AM (2 years ago)
Author:
Alan Bujtas
Message:

Should be able to compute decoration overflow without InlineIterator::TextBoxIterator
https://bugs.webkit.org/show_bug.cgi?id=241490

Reviewed by Antti Koivisto.

This patch enables IFC codebase to compute visual overflow for decoration (even when TextBoxIterator is not available).

  • Source/WebCore/rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::changeAffectsVisualOverflow const):

  • Source/WebCore/style/InlineTextBoxStyle.cpp:

(WebCore::visualOverflowForDecorations):

  • Source/WebCore/style/InlineTextBoxStyle.h:

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

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r295211 r295455  
    686686        if (textUnderlinePosition() == TextUnderlinePosition::Under || other.textUnderlinePosition() == TextUnderlinePosition::Under)
    687687            return true;
    688         return visualOverflowForDecorations(*this, { }) != visualOverflowForDecorations(other, { });
     688        return visualOverflowForDecorations(*this) != visualOverflowForDecorations(other);
    689689    }
    690690
  • trunk/Source/WebCore/style/InlineTextBoxStyle.cpp

    r295453 r295455  
    173173}
    174174
    175 GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, const InlineIterator::TextBoxIterator& textRun)
    176 {
    177     ASSERT(!textRun || textRun->style() == lineStyle);
    178    
     175GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, std::optional<float> underlineOffset)
     176{
    179177    auto decoration = lineStyle.textDecorationsInEffect();
    180178    if (decoration.isEmpty())
     
    184182    WavyStrokeParameters wavyStrokeParameters;
    185183    float wavyOffset = 0;
    186        
     184
    187185    TextDecorationStyle decorationStyle = lineStyle.textDecorationStyle();
    188186    float height = lineStyle.fontCascade().metricsOfPrimaryFont().floatHeight();
    189187    GlyphOverflow overflowResult;
    190    
     188
    191189    if (decorationStyle == TextDecorationStyle::Wavy) {
    192190        wavyStrokeParameters = getWavyStrokeParameters(lineStyle.computedFontPixelSize());
     
    199197    // FIXME: Share the code in TextDecorationPainter::paintBackgroundDecorations() so we can just query it for the painted geometry.
    200198    if (decoration & TextDecorationLine::Underline) {
    201         // Compensate for the integral ceiling in GraphicsContext::computeLineBoundsAndAntialiasingModeForText()
    202         int underlineOffset = 1;
    203         float textDecorationBaseFontSize = 16;
    204         auto defaultGap = lineStyle.computedFontSize() / textDecorationBaseFontSize;
    205         // FIXME: RenderStyle calls us with empty textRun but only when TextUnderlinePosition is not Under.
    206         ASSERT(textRun || lineStyle.textUnderlinePosition() != TextUnderlinePosition::Under);
    207         if (!textRun)
    208             underlineOffset += computeUnderlineOffset({ lineStyle, defaultGap });
    209         else {
    210             underlineOffset += computeUnderlineOffset({ lineStyle
    211                 , defaultGap
    212                 , UnderlineOffsetArguments::TextUnderlinePositionUnder { textRun->lineBox()->baselineType(), textRun->logicalBottom() - textRun->logicalTop(), textRunLogicalOffsetFromLineBottom(textRun) }
    213             });
    214         }
    215 
     199        ASSERT(underlineOffset);
    216200        if (decorationStyle == TextDecorationStyle::Wavy) {
    217             overflowResult.extendBottom(underlineOffset + wavyOffset + wavyStrokeParameters.controlPointDistance + strokeThickness - height);
    218             overflowResult.extendTop(-(underlineOffset + wavyOffset - wavyStrokeParameters.controlPointDistance - strokeThickness));
     201            overflowResult.extendBottom(*underlineOffset + wavyOffset + wavyStrokeParameters.controlPointDistance + strokeThickness - height);
     202            overflowResult.extendTop(-(*underlineOffset + wavyOffset - wavyStrokeParameters.controlPointDistance - strokeThickness));
    219203        } else {
    220             overflowResult.extendBottom(underlineOffset + strokeThickness - height);
    221             overflowResult.extendTop(-underlineOffset);
     204            overflowResult.extendBottom(*underlineOffset + strokeThickness - height);
     205            overflowResult.extendTop(-*underlineOffset);
    222206        }
    223207    }
     
    251235    return overflowResult;
    252236}
     237
     238GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, const InlineIterator::TextBoxIterator& textRun)
     239{
     240    ASSERT(!textRun || textRun->style() == lineStyle);
     241
     242    if (!lineStyle.textDecorationsInEffect().contains(TextDecorationLine::Underline))
     243        return visualOverflowForDecorations(lineStyle, std::optional<float> { });
     244
     245    // Compensate for the integral ceiling in GraphicsContext::computeLineBoundsAndAntialiasingModeForText()
     246    int underlineOffset = 1;
     247    float textDecorationBaseFontSize = 16;
     248    auto defaultGap = lineStyle.computedFontSize() / textDecorationBaseFontSize;
     249    // FIXME: RenderStyle calls us with empty textRun but only when TextUnderlinePosition is not Under.
     250    ASSERT(textRun || lineStyle.textUnderlinePosition() != TextUnderlinePosition::Under);
     251    if (!textRun)
     252        underlineOffset += computeUnderlineOffset({ lineStyle, defaultGap });
     253    else {
     254        underlineOffset += computeUnderlineOffset({ lineStyle
     255            , defaultGap
     256            , UnderlineOffsetArguments::TextUnderlinePositionUnder { textRun->lineBox()->baselineType(), textRun->logicalBottom() - textRun->logicalTop(), textRunLogicalOffsetFromLineBottom(textRun) }
     257        });
     258    }
     259    return visualOverflowForDecorations(lineStyle, underlineOffset);
     260}
     261
     262GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle)
     263{
     264    return visualOverflowForDecorations(lineStyle, InlineIterator::TextBoxIterator { });
     265}
    253266   
    254267}
  • trunk/Source/WebCore/style/InlineTextBoxStyle.h

    r295453 r295455  
    5454};
    5555WavyStrokeParameters getWavyStrokeParameters(float fontSize);
     56GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle);
    5657GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, const InlineIterator::TextBoxIterator&);
     58GlyphOverflow visualOverflowForDecorations(const RenderStyle& lineStyle, std::optional<float> underlineOffset);
    5759
    5860struct UnderlineOffsetArguments {
Note: See TracChangeset for help on using the changeset viewer.