Changeset 290726 in webkit
- Timestamp:
- Mar 2, 2022 6:49:22 AM (5 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html (added)
-
LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/rendering/RenderImage.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r290724 r290726 1 2022-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 1 12 2022-03-02 Carlos Garcia Campos <cgarcia@igalia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r290724 r290726 1 2022-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 1 14 2022-03-02 Carlos Garcia Campos <cgarcia@igalia.com> 2 15 -
trunk/Source/WebCore/rendering/RenderImage.cpp
r288942 r290726 498 498 LayoutUnit leftBorder = borderLeft(); 499 499 LayoutUnit topBorder = borderTop(); 500 LayoutUnit leftPad = paddingLeft();501 LayoutUnit topPad = paddingTop();500 LayoutUnit leftPadding = paddingLeft(); 501 LayoutUnit topPadding = paddingTop(); 502 502 503 503 bool errorPictureDrawn = false; … … 523 523 if (centerY < 0) 524 524 centerY = 0; 525 imageOffset = LayoutSize(leftBorder + leftPad + centerX + missingImageBorderWidth, topBorder + topPad+ centerY + missingImageBorderWidth);525 imageOffset = LayoutSize(leftBorder + leftPadding + centerX + missingImageBorderWidth, topBorder + topPadding + centerY + missingImageBorderWidth); 526 526 527 527 context.drawImage(*image, snapRectToDevicePixels(LayoutRect(paintOffset + imageOffset, imageSize), deviceScaleFactor), { imageOrientation() }); … … 530 530 531 531 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 } 549 555 } 550 556 }
Note: See TracChangeset
for help on using the changeset viewer.