diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index aea0f94084f..641d5d526e1 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -4040,6 +4040,9 @@ nsCSSFrameConstructor::ConstructTableCellFrame(nsFrameConstructorState& aState, aNewCellOuterFrame = NS_NewMathMLmtdFrame(mPresShell, aStyleContext); else #endif + // Warning: If you change this and add a wrapper frame around table cell + // frames, make sure Bug 368554 doesn't regress! + // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp. aNewCellOuterFrame = NS_NewTableCellFrame(mPresShell, aStyleContext, IsBorderCollapse(parentFrame)); @@ -10646,6 +10649,9 @@ nsCSSFrameConstructor::CreateContinuingFrame(nsPresContext* aPresContext, } } else if (IS_TABLE_CELL(frameType)) { + // Warning: If you change this and add a wrapper frame around table cell + // frames, make sure Bug 368554 doesn't regress! + // See IsInAutoWidthTableCellForQuirk() in nsImageFrame.cpp. newFrame = NS_NewTableCellFrame(shell, styleContext, IsBorderCollapse(aParentFrame)); if (newFrame) { diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 0287eee8376..42d347ecc60 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -53,6 +53,7 @@ #include "nsIDocument.h" #include "nsINodeInfo.h" #include "nsContentUtils.h" +#include "nsCSSAnonBoxes.h" #include "nsStyleContext.h" #include "nsStyleConsts.h" #include "nsImageMap.h" @@ -1867,3 +1868,45 @@ NS_IMETHODIMP nsImageListener::FrameChanged(imgIContainer *aContainer, return mFrame->FrameChanged(aContainer, newframe, dirtyRect); } +static PRBool +IsInAutoWidthTableCellForQuirk(nsIFrame *aFrame) +{ + if (eCompatibility_NavQuirks != aFrame->PresContext()->CompatibilityMode()) + return PR_FALSE; + // Check if the parent of the closest nsBlockFrame has auto width. + nsBlockFrame *ancestor = nsLayoutUtils::FindNearestBlockAncestor(aFrame); + if (ancestor->GetStyleContext()->GetPseudoType() == nsCSSAnonBoxes::cellContent) { + // Assume direct parent is a table cell frame. + nsFrame *grandAncestor = static_cast(ancestor->GetParent()); + return grandAncestor && + grandAncestor->GetStylePosition()->mWidth.GetUnit() == eStyleUnit_Auto; + } + return PR_FALSE; +} + +/* virtual */ void +nsImageFrame::AddInlineMinWidth(nsIRenderingContext *aRenderingContext, + nsIFrame::InlineMinWidthData *aData) +{ + + NS_ASSERTION(GetParent(), "Must have a parent if we get here!"); + + PRBool canBreak = + !CanContinueTextRun() && + GetParent()->GetStyleText()->WhiteSpaceCanWrap() && + !IsInAutoWidthTableCellForQuirk(this); + + if (canBreak) + aData->OptionallyBreak(aRenderingContext); + + aData->trailingWhitespace = 0; + aData->skipWhitespace = PR_FALSE; + aData->trailingTextFrame = nsnull; + aData->currentLine += nsLayoutUtils::IntrinsicForContainer(aRenderingContext, + this, nsLayoutUtils::MIN_WIDTH); + aData->atStartOfLine = PR_FALSE; + + if (canBreak) + aData->OptionallyBreak(aRenderingContext); + +} diff --git a/layout/generic/nsImageFrame.h b/layout/generic/nsImageFrame.h index b8bef1d099c..c1e66ae4576 100644 --- a/layout/generic/nsImageFrame.h +++ b/layout/generic/nsImageFrame.h @@ -173,6 +173,9 @@ public: nsImageMap* GetImageMap(nsPresContext* aPresContext); + virtual void AddInlineMinWidth(nsIRenderingContext *aRenderingContext, + InlineMinWidthData *aData); + protected: // nsISupports NS_IMETHOD_(nsrefcnt) AddRef(void); diff --git a/layout/reftests/bugs/384322-1-ref.html b/layout/reftests/bugs/384322-1-ref.html new file mode 100644 index 00000000000..efe1c4f9bd3 --- /dev/null +++ b/layout/reftests/bugs/384322-1-ref.html @@ -0,0 +1,55 @@ + +[384322] Testcase + + + +

<img><img>Hello<img><img> + + + + + + + +
+ Hello +
+ +

<img><img>Hello

+ + + + + + + +
+ Hello +
+ +

Hello<img><img>

+ + + + + + + +
+ Hello +
+ +

<img>Hello

+ + + + + + + +
+ Hello +
+ + + diff --git a/layout/reftests/bugs/384322-1.html b/layout/reftests/bugs/384322-1.html new file mode 100644 index 00000000000..db36fe7c4e2 --- /dev/null +++ b/layout/reftests/bugs/384322-1.html @@ -0,0 +1,55 @@ + +[384322] Testcase + + + +

<img><img>Hello<img><img> + + + + + + + +
+ Hello +
+ +

<img><img>Hello

+ + + + + + + +
+ Hello +
+ +

Hello<img><img>

+ + + + + + + +
+ Hello +
+ +

<img>Hello

+ + + + + + + +
+ Hello +
+ + + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index b804b73e95b..f02de75b089 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -377,6 +377,7 @@ random-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 379316-2.html 379316-2-ref.html # bug == 383883-4.html 383883-4-ref.html == 383884-1.html 383884-1-ref.html == 383885-1.html 383885-1-ref.html +== 384322-1.html 384322-1-ref.html == 384576-1.html 384576-1-ref.html == 384762-1.html about:blank == 384876-1.html 384876-1-ref.html