Changeset 290726 in webkit


Ignore:
Timestamp:
Mar 2, 2022 6:49:22 AM (5 months ago)
Author:
Alan Bujtas
Message:

[RTL] Incorrect alt text position in right to left context
https://bugs.webkit.org/show_bug.cgi?id=237352
<rdar://problem/89657704>

Reviewed by Simon Fraser.

Source/WebCore:

Take the inline direction into account when computing the alt text location.

  • rendering/RenderImage.cpp:

(WebCore::RenderImage::paintReplaced): This is mostly moving things around/modernizing it.

LayoutTests:

  • fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html: Added.
  • fast/images/alt-text-with-right-to-left-inline-direction.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r290724 r290726  
     12022-03-02  Alan Bujtas  <zalan@apple.com>
     2
     3        [RTL] Incorrect alt text position in right to left context
     4        https://bugs.webkit.org/show_bug.cgi?id=237352
     5        <rdar://problem/89657704>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html: Added.
     10        * fast/images/alt-text-with-right-to-left-inline-direction.html: Added.
     11
    1122022-03-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r290724 r290726  
     12022-03-02  Alan Bujtas  <zalan@apple.com>
     2
     3        [RTL] Incorrect alt text position in right to left context
     4        https://bugs.webkit.org/show_bug.cgi?id=237352
     5        <rdar://problem/89657704>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Take the inline direction into account when computing the alt text location.
     10
     11        * rendering/RenderImage.cpp:
     12        (WebCore::RenderImage::paintReplaced): This is mostly moving things around/modernizing it.
     13
    1142022-03-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r288942 r290726  
    498498            LayoutUnit leftBorder = borderLeft();
    499499            LayoutUnit topBorder = borderTop();
    500             LayoutUnit leftPad = paddingLeft();
    501             LayoutUnit topPad = paddingTop();
     500            LayoutUnit leftPadding = paddingLeft();
     501            LayoutUnit topPadding = paddingTop();
    502502
    503503            bool errorPictureDrawn = false;
     
    523523                if (centerY < 0)
    524524                    centerY = 0;
    525                 imageOffset = LayoutSize(leftBorder + leftPad + centerX + missingImageBorderWidth, topBorder + topPad + centerY + missingImageBorderWidth);
     525                imageOffset = LayoutSize(leftBorder + leftPadding + centerX + missingImageBorderWidth, topBorder + topPadding + centerY + missingImageBorderWidth);
    526526
    527527                context.drawImage(*image, snapRectToDevicePixels(LayoutRect(paintOffset + imageOffset, imageSize), deviceScaleFactor), { imageOrientation() });
     
    530530
    531531            if (!m_altText.isEmpty()) {
    532                 String text = document().displayStringModifiedByEncoding(m_altText);
    533                 context.setFillColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor));
    534                 const FontCascade& font = style().fontCascade();
    535                 const FontMetrics& fontMetrics = font.metricsOfPrimaryFont();
    536                 LayoutUnit ascent = fontMetrics.ascent();
    537                 LayoutPoint altTextOffset = paintOffset;
    538                 altTextOffset.move(leftBorder + leftPad + (paddingWidth / 2) - missingImageBorderWidth, topBorder + topPad + ascent + (paddingHeight / 2) - missingImageBorderWidth);
    539 
    540                 // Only draw the alt text if it'll fit within the content box,
    541                 // and only if it fits above the error image.
    542                 TextRun textRun = RenderBlock::constructTextRun(text, style());
    543                 LayoutUnit textWidth { font.width(textRun) };
    544                 if (errorPictureDrawn) {
    545                     if (usableSize.width() >= textWidth && fontMetrics.height() <= imageOffset.height())
    546                         context.drawBidiText(font, textRun, altTextOffset);
    547                 } else if (usableSize.width() >= textWidth && usableSize.height() >= fontMetrics.height())
    548                     context.drawBidiText(font, textRun, altTextOffset);
     532                auto& font = style().fontCascade();
     533                auto& fontMetrics = font.metricsOfPrimaryFont();
     534                auto textRun = RenderBlock::constructTextRun(document().displayStringModifiedByEncoding(m_altText), style());
     535                auto textWidth = LayoutUnit { font.width(textRun) };
     536
     537                auto hasRoomForAltText = [&] {
     538                    // Only draw the alt text if it'll fit within the content box,
     539                    // and only if it fits above the error image.
     540                    if (usableSize.width() < textWidth)
     541                        return false;
     542                    return errorPictureDrawn ? fontMetrics.height() <= imageOffset.height() : usableSize.height() >= fontMetrics.height();
     543                };
     544                if (hasRoomForAltText()) {
     545                    auto altTextLocation = [&]() -> LayoutPoint {
     546                        auto contentHorizontalOffset = LayoutUnit { leftBorder + leftPadding + (paddingWidth / 2) - missingImageBorderWidth };
     547                        auto contentVerticalOffset = LayoutUnit { topBorder + topPadding + fontMetrics.ascent() + (paddingHeight / 2) - missingImageBorderWidth };
     548                        if (!style().isLeftToRightDirection())
     549                            contentHorizontalOffset += contentSize.width() - textWidth;
     550                        return paintOffset + LayoutPoint { contentHorizontalOffset, contentVerticalOffset };
     551                    };
     552                    context.setFillColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor));
     553                    context.drawBidiText(font, textRun, altTextLocation());
     554                }
    549555            }
    550556        }
Note: See TracChangeset for help on using the changeset viewer.