Skip to content

Commit 6079da9

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
<marquee> stretches a table and causes layout issues
https://bugs.webkit.org/show_bug.cgi?id=41562 rdar://problem/99826593 Reviewed by Alan Baradlay. This patch aligns WebKit with Gecko / Firefox and Blink / Chromium. The special case in RenderBlockFlow::computeIntrinsicLogicalWidths() that sets minLogicalWidth to 0 for horizontal marquees was incorrectly gated behind a childrenInline() check. This caused marquees containing block children (e.g., a <div>) to use their content's preferred width instead of being treated as having no minimum width. Horizontal marquees scroll their content and should not constrain their container's width, regardless of whether their children are inline or block elements. The autoWrap() check already ensures this code only runs for marquees (which set white-space: nowrap). This fixes tables with fixed widths being incorrectly expanded when they contain marquees with block children. While here, we also wrapped the logic into `resetMinimumWidthForMarqueeIfApplicable` lambda (thanks to Alan). Test: fast/table/marquee-block-child-table-width.html * Source/WebCore/rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::computeIntrinsicLogicalWidths const): Remove the childrenInline() check from the horizontal marquee special case, and update the comment to reflect that this applies to all horizontal marquees and wrap the logic in lambda. Canonical link: https://commits.webkit.org/306059@main
1 parent 7300a75 commit 6079da9

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Text that has to wrap at a width of 200px!!!!
2+
3+
PASS Horizontal marquee with block children does not expand parent table width
4+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Horizontal marquee with block children should not expand table width</title>
5+
<script src="../../resources/testharness.js"></script>
6+
<script src="../../resources/testharnessreport.js"></script>
7+
</head>
8+
<body>
9+
<table id="test-table" width="200" style="background:red">
10+
<tr>
11+
<td>
12+
<marquee><div>Text that has to wrap at a width of 200px!!!!</div></marquee>
13+
</td>
14+
</tr>
15+
</table>
16+
17+
<script>
18+
test(function() {
19+
var table = document.getElementById('test-table');
20+
var computedWidth = parseFloat(window.getComputedStyle(table).width);
21+
assert_equals(computedWidth, 200,
22+
"Table width should be 200px despite marquee containing wide block content");
23+
}, "Horizontal marquee with block children does not expand parent table width");
24+
</script>
25+
</body>
26+
</html>

Source/WebCore/rendering/RenderBlockFlow.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (C) 1999 Lars Knoll ([email protected])
33
* (C) 1999 Antti Koivisto ([email protected])
44
* (C) 2007 David Smith ([email protected])
5-
* Copyright (C) 2003-2025 Apple Inc. All rights reserved.
5+
* Copyright (C) 2003-2026 Apple Inc. All rights reserved.
66
* Copyright (C) 2014-2016 Google Inc. All rights reserved.
77
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
88
*
@@ -358,12 +358,16 @@ void RenderBlockFlow::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
358358
if (needAdjustIntrinsicLogicalWidthsForColumns)
359359
adjustIntrinsicLogicalWidthsForColumns(minLogicalWidth, maxLogicalWidth);
360360

361-
if (!style().autoWrap() && childrenInline()) {
362-
// A horizontal marquee with inline children has no minimum width.
363-
CheckedPtr scrollableArea = layer() ? layer()->scrollableArea() : nullptr;
364-
if (scrollableArea && scrollableArea->marquee() && scrollableArea->marquee()->isHorizontal())
365-
minLogicalWidth = 0;
366-
}
361+
auto resetMinimumWidthForMarqueeIfApplicable = [&] {
362+
if (style().autoWrap() || !layer())
363+
return;
364+
CheckedPtr scrollableArea = layer()->scrollableArea();
365+
if (!scrollableArea || !scrollableArea->marquee() || !scrollableArea->marquee()->isHorizontal())
366+
return;
367+
// A horizontal marquee has no minimum width.
368+
minLogicalWidth = { };
369+
};
370+
resetMinimumWidthForMarqueeIfApplicable();
367371

368372
if (auto* cell = dynamicDowncast<RenderTableCell>(*this)) {
369373
auto [ tableCellWidth, usedZoom ] = cell->styleOrColLogicalWidth();

0 commit comments

Comments
 (0)