From ec941c9f52dd06a5a399724e2c233b31faade3e6 Mon Sep 17 00:00:00 2001 From: "robert@webkit.org" Date: Tue, 27 Sep 2011 19:31:31 +0000 Subject: [PATCH] Reviewed by David Hyatt. Replaced elements squeezed when width is specified as percentage inside a table with Auto layout https://bugs.webkit.org/show_bug.cgi?id=29447 Source/WebCore: If inserting a 'replaced' element (e.g. image, plugin) in a table cell that is not descendant from a block with fixed layout then do not squeeze the element, let it use its intrinsic width and height. Test: fast/replaced/table-percent-width.html * rendering/RenderBox.cpp: (WebCore::avoidSqueezingWidth): (WebCore::avoidSqueezingHeight): (WebCore::RenderBox::containingBlockReplacedLogicalWidthForContent): (WebCore::RenderBox::computeReplacedLogicalWidthUsing): (WebCore::RenderBox::computeReplacedLogicalHeightUsing): * rendering/RenderBox.h: LayoutTests: * fast/replaced/table-percent-width.html: Added. * fast/replaced/table-percent-width-expected.txt: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96139 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 10 ++ .../fast/replaced/table-percent-width-expected.txt | 25 +++++ LayoutTests/fast/replaced/table-percent-width.html | 115 +++++++++++++++++++++ Source/WebCore/ChangeLog | 20 ++++ Source/WebCore/rendering/RenderBox.cpp | 46 +++++++-- Source/WebCore/rendering/RenderBox.h | 1 + 6 files changed, 208 insertions(+), 9 deletions(-) create mode 100644 LayoutTests/fast/replaced/table-percent-width-expected.txt create mode 100644 LayoutTests/fast/replaced/table-percent-width.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 9eb5e16..fac35f5 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2011-06-28 Robert Hogan + + Reviewed by David Hyatt. + + Replaced elements squeezed when width is specified as percentage inside a table with Auto layout + https://bugs.webkit.org/show_bug.cgi?id=29447 + + * fast/replaced/table-percent-width.html: Added. + * fast/replaced/table-percent-width-expected.txt: Added. + 2011-09-27 Simon Fraser https://bugs.webkit.org/show_bug.cgi?id=67858 diff --git a/LayoutTests/fast/replaced/table-percent-width-expected.txt b/LayoutTests/fast/replaced/table-percent-width-expected.txt new file mode 100644 index 0000000..e7f27fa --- /dev/null +++ b/LayoutTests/fast/replaced/table-percent-width-expected.txt @@ -0,0 +1,25 @@ + + + + + +This test checks that a replaced element with percentage width (and no height specified) within a table cell is squeezed to the dimensions of the table cell. +See bug #29447. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS getWidth('img-1') is '105px' +PASS getHeight('img-1') is '105px' +PASS getWidth('img-2') is '98px' +PASS getHeight('img-2') is '98px' +PASS getWidth('img-3') is '40px' +PASS getHeight('img-3') is '40px' +PASS getWidth('img-4') is '36px' +PASS getHeight('img-4') is '36px' +PASS getWidth('img-5') is '40px' +PASS getHeight('img-5') is '36px' +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/replaced/table-percent-width.html b/LayoutTests/fast/replaced/table-percent-width.html new file mode 100644 index 0000000..7f6df9b --- /dev/null +++ b/LayoutTests/fast/replaced/table-percent-width.html @@ -0,0 +1,115 @@ + + + webkit.org/b/29447: Replaced elements squeezed when width is specified as percentage inside a table with Auto layout + + + + + + + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ +
+ +

+
+ + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index ca5d048..42041d0 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,23 @@ +2011-06-28 Robert Hogan + + Reviewed by David Hyatt. + + Replaced elements squeezed when width is specified as percentage inside a table with Auto layout + https://bugs.webkit.org/show_bug.cgi?id=29447 + + If inserting a 'replaced' element (e.g. image, plugin) in a table cell that is not descendant from + a block with fixed layout then do not squeeze the element, let it use its intrinsic width and height. + + Test: fast/replaced/table-percent-width.html + + * rendering/RenderBox.cpp: + (WebCore::avoidSqueezingWidth): + (WebCore::avoidSqueezingHeight): + (WebCore::RenderBox::containingBlockReplacedLogicalWidthForContent): + (WebCore::RenderBox::computeReplacedLogicalWidthUsing): + (WebCore::RenderBox::computeReplacedLogicalHeightUsing): + * rendering/RenderBox.h: + 2011-09-27 Simon Fraser https://bugs.webkit.org/show_bug.cgi?id=67858 diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp index b1f0f9a..bc138f0 100644 --- a/Source/WebCore/rendering/RenderBox.cpp +++ b/Source/WebCore/rendering/RenderBox.cpp @@ -1216,6 +1216,37 @@ LayoutRect RenderBox::clipRect(const LayoutPoint& location) return clipRect; } +static bool avoidSqueezingWidth(RenderBlock* cb) +{ + while (cb && !cb->isRenderView()) { + if (!cb->style()->logicalWidth().isAuto() && !cb->style()->logicalWidth().isPercent()) + return false; + cb = cb->containingBlock(); + } + return true; +} + +static bool avoidSqueezingHeight(RenderBlock* cb) +{ + while (cb && !cb->isRenderView()) { + if (!cb->style()->logicalHeight().isAuto() && !cb->style()->logicalHeight().isPercent()) + return false; + cb = cb->containingBlock(); + } + return true; +} + +int RenderBox::containingBlockReplacedLogicalWidthForContent() const +{ + RenderBlock* cb = containingBlock(); + // Don't let table cells squeeze percent-height replaced elements + // + if (cb->isTableCell() && avoidSqueezingWidth(cb)) + return max(shrinkToAvoidFloats() ? cb->availableLogicalWidthForLine(y(), false) : cb->availableLogicalWidth(), intrinsicLogicalWidth()); + + return containingBlockLogicalWidthForContent(); +} + LayoutUnit RenderBox::containingBlockLogicalWidthForContent() const { RenderBlock* cb = containingBlock(); @@ -2014,7 +2045,7 @@ LayoutUnit RenderBox::computeReplacedLogicalWidthUsing(Length logicalWidth) cons // FIXME: containingBlockLogicalWidthForContent() is wrong if the replaced element's block-flow is perpendicular to the // containing block's block-flow. // https://bugs.webkit.org/show_bug.cgi?id=46496 - const LayoutUnit cw = isPositioned() ? containingBlockLogicalWidthForPositioned(toRenderBoxModelObject(container())) : containingBlockLogicalWidthForContent(); + const LayoutUnit cw = isPositioned() ? containingBlockLogicalWidthForPositioned(toRenderBoxModelObject(container())) : containingBlockReplacedLogicalWidthForContent(); if (cw > 0) return computeContentBoxLogicalWidth(logicalWidth.calcMinValue(cw)); } @@ -2074,14 +2105,11 @@ LayoutUnit RenderBox::computeReplacedLogicalHeightUsing(Length logicalHeight) co // table cells using percentage heights. // FIXME: This needs to be made block-flow-aware. If the cell and image are perpendicular block-flows, this isn't right. // https://bugs.webkit.org/show_bug.cgi?id=46997 - while (cb && !cb->isRenderView() && (cb->style()->logicalHeight().isAuto() || cb->style()->logicalHeight().isPercent())) { - if (cb->isTableCell()) { - // Don't let table cells squeeze percent-height replaced elements - // - availableHeight = max(availableHeight, intrinsicLogicalHeight()); - return logicalHeight.calcValue(availableHeight - borderAndPaddingLogicalHeight()); - } - cb = cb->containingBlock(); + if (cb->isTableCell() && avoidSqueezingHeight(toRenderBlock(cb))) { + // Don't let table cells squeeze percent-height replaced elements + // + availableHeight = max(availableHeight, intrinsicLogicalHeight()); + return logicalHeight.calcValue(availableHeight - borderAndPaddingLogicalHeight()); } } return computeContentBoxLogicalHeight(logicalHeight.calcValue(availableHeight)); diff --git a/Source/WebCore/rendering/RenderBox.h b/Source/WebCore/rendering/RenderBox.h index f01d021..8a40ed6 100644 --- a/Source/WebCore/rendering/RenderBox.h +++ b/Source/WebCore/rendering/RenderBox.h @@ -285,6 +285,7 @@ public: virtual LayoutUnit containingBlockLogicalWidthForContent() const; LayoutUnit perpendicularContainingBlockLogicalHeight() const; + int containingBlockReplacedLogicalWidthForContent() const; virtual void computeLogicalWidth(); virtual void computeLogicalHeight(); -- 2.7.4