Title: [290726] trunk
Revision
290726
Author
[email protected]
Date
2022-03-02 06:49:22 -0800 (Wed, 02 Mar 2022)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (290725 => 290726)


--- trunk/LayoutTests/ChangeLog	2022-03-02 13:49:59 UTC (rev 290725)
+++ trunk/LayoutTests/ChangeLog	2022-03-02 14:49:22 UTC (rev 290726)
@@ -1,3 +1,14 @@
+2022-03-02  Alan Bujtas  <[email protected]>
+
+        [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.
+
+        * 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.
+
 2022-03-02  Carlos Garcia Campos  <[email protected]>
 
         REGRESSION(r216096): [GTK] Test accessibility/gtk/menu-list-unfocused-notifications.html is failing since r216096

Added: trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html (0 => 290726)


--- trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction-expected-mismatch.html	2022-03-02 14:49:22 UTC (rev 290726)
@@ -0,0 +1,17 @@
+<style>
+.container {
+  direction: ltr;
+  font-size: 10px;
+  font-family: Ahem;
+}
+
+img {
+  width: 200px;
+  height: 100px;
+}
+</style>
+<div style="width: 210px;">
+<div class=container><img src="" style="width: 210px;" alt="right to left"></div>
+<div class=container><img src="" style="padding-left: 10px;" alt="right to left"></div>
+<div class=container><img src="" style="padding-right: 10px;" alt="right to left"></div>
+</div>
\ No newline at end of file

Added: trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction.html (0 => 290726)


--- trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/alt-text-with-right-to-left-inline-direction.html	2022-03-02 14:49:22 UTC (rev 290726)
@@ -0,0 +1,17 @@
+<style>
+.container {
+  direction: rtl;
+  font-size: 10px;
+  font-family: Ahem;
+}
+
+img {
+  width: 200px;
+  height: 100px;
+}
+</style>
+<div style="width: 210px;">
+<div class=container><img src="" style="width: 210px;" alt="right to left"></div>
+<div class=container><img src="" style="padding-left: 10px;" alt="right to left"></div>
+<div class=container><img src="" style="padding-right: 10px;" alt="right to left"></div>
+</div>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (290725 => 290726)


--- trunk/Source/WebCore/ChangeLog	2022-03-02 13:49:59 UTC (rev 290725)
+++ trunk/Source/WebCore/ChangeLog	2022-03-02 14:49:22 UTC (rev 290726)
@@ -1,3 +1,16 @@
+2022-03-02  Alan Bujtas  <[email protected]>
+
+        [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.
+
+        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.
+
 2022-03-02  Carlos Garcia Campos  <[email protected]>
 
         REGRESSION(r216096): [GTK] Test accessibility/gtk/menu-list-unfocused-notifications.html is failing since r216096

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (290725 => 290726)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2022-03-02 13:49:59 UTC (rev 290725)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2022-03-02 14:49:22 UTC (rev 290726)
@@ -497,8 +497,8 @@
         if (contentSize.width() > 2 && contentSize.height() > 2) {
             LayoutUnit leftBorder = borderLeft();
             LayoutUnit topBorder = borderTop();
-            LayoutUnit leftPad = paddingLeft();
-            LayoutUnit topPad = paddingTop();
+            LayoutUnit leftPadding = paddingLeft();
+            LayoutUnit topPadding = paddingTop();
 
             bool errorPictureDrawn = false;
             LayoutSize imageOffset;
@@ -522,7 +522,7 @@
                 LayoutUnit centerY { (usableSize.height() - imageSize.height()) / 2 };
                 if (centerY < 0)
                     centerY = 0;
-                imageOffset = LayoutSize(leftBorder + leftPad + centerX + missingImageBorderWidth, topBorder + topPad + centerY + missingImageBorderWidth);
+                imageOffset = LayoutSize(leftBorder + leftPadding + centerX + missingImageBorderWidth, topBorder + topPadding + centerY + missingImageBorderWidth);
 
                 context.drawImage(*image, snapRectToDevicePixels(LayoutRect(paintOffset + imageOffset, imageSize), deviceScaleFactor), { imageOrientation() });
                 errorPictureDrawn = true;
@@ -529,23 +529,29 @@
             }
 
             if (!m_altText.isEmpty()) {
-                String text = document().displayStringModifiedByEncoding(m_altText);
-                context.setFillColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor));
-                const FontCascade& font = style().fontCascade();
-                const FontMetrics& fontMetrics = font.metricsOfPrimaryFont();
-                LayoutUnit ascent = fontMetrics.ascent();
-                LayoutPoint altTextOffset = paintOffset;
-                altTextOffset.move(leftBorder + leftPad + (paddingWidth / 2) - missingImageBorderWidth, topBorder + topPad + ascent + (paddingHeight / 2) - missingImageBorderWidth);
+                auto& font = style().fontCascade();
+                auto& fontMetrics = font.metricsOfPrimaryFont();
+                auto textRun = RenderBlock::constructTextRun(document().displayStringModifiedByEncoding(m_altText), style());
+                auto textWidth = LayoutUnit { font.width(textRun) };
 
-                // Only draw the alt text if it'll fit within the content box,
-                // and only if it fits above the error image.
-                TextRun textRun = RenderBlock::constructTextRun(text, style());
-                LayoutUnit textWidth { font.width(textRun) };
-                if (errorPictureDrawn) {
-                    if (usableSize.width() >= textWidth && fontMetrics.height() <= imageOffset.height())
-                        context.drawBidiText(font, textRun, altTextOffset);
-                } else if (usableSize.width() >= textWidth && usableSize.height() >= fontMetrics.height())
-                    context.drawBidiText(font, textRun, altTextOffset);
+                auto hasRoomForAltText = [&] {
+                    // Only draw the alt text if it'll fit within the content box,
+                    // and only if it fits above the error image.
+                    if (usableSize.width() < textWidth)
+                        return false;
+                    return errorPictureDrawn ? fontMetrics.height() <= imageOffset.height() : usableSize.height() >= fontMetrics.height();
+                };
+                if (hasRoomForAltText()) {
+                    auto altTextLocation = [&]() -> LayoutPoint {
+                        auto contentHorizontalOffset = LayoutUnit { leftBorder + leftPadding + (paddingWidth / 2) - missingImageBorderWidth };
+                        auto contentVerticalOffset = LayoutUnit { topBorder + topPadding + fontMetrics.ascent() + (paddingHeight / 2) - missingImageBorderWidth };
+                        if (!style().isLeftToRightDirection())
+                            contentHorizontalOffset += contentSize.width() - textWidth;
+                        return paintOffset + LayoutPoint { contentHorizontalOffset, contentVerticalOffset };
+                    };
+                    context.setFillColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor));
+                    context.drawBidiText(font, textRun, altTextLocation());
+                }
             }
         }
         return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to