From 8df67b73a5a42b315b65a620079579ebf170bfb8 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 15 Aug 2002 23:00:23 +0000 Subject: [PATCH] Fix placement of positioned elements with auto "top". Bug 44508, patch by Mats Palmgren (mats.palmgren@bredband.net), r=dbaron, sr=bzbarsky. git-svn-id: svn://10.0.0.236/trunk@127417 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsRuleNode.cpp | 3 +++ mozilla/content/shared/public/nsStyleStruct.h | 1 + mozilla/content/shared/src/nsStyleStruct.cpp | 2 ++ mozilla/layout/generic/nsHTMLReflowState.cpp | 7 +++++-- mozilla/layout/html/base/src/nsHTMLReflowState.cpp | 7 +++++-- mozilla/layout/style/nsRuleNode.cpp | 3 +++ mozilla/layout/style/nsStyleStruct.cpp | 2 ++ mozilla/layout/style/nsStyleStruct.h | 1 + 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index e9347d09a67..5edd6fc7ff3 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -2884,6 +2884,9 @@ nsRuleNode::ComputeDisplayData(nsStyleStruct* aStartStruct, const nsCSSStruct& a // 2) if position is 'absolute' or 'fixed' then display must be 'block and float must be 'none' // XXX - see note for fixup 1) above... if (display->IsAbsolutelyPositioned() && display->mDisplay != NS_STYLE_DISPLAY_NONE) { + // Backup original display value for calculation of a hypothetical box (CSS2 10.6.4/10.6.5) + // See nsHTMLReflowState::CalculateHypotheticalBox + display->mOriginalDisplay = display->mDisplay; EnsureBlockDisplay(display->mDisplay); display->mFloats = NS_STYLE_FLOAT_NONE; } diff --git a/mozilla/content/shared/public/nsStyleStruct.h b/mozilla/content/shared/public/nsStyleStruct.h index 9f83d7f95b4..89c84d03e99 100644 --- a/mozilla/content/shared/public/nsStyleStruct.h +++ b/mozilla/content/shared/public/nsStyleStruct.h @@ -710,6 +710,7 @@ struct nsStyleDisplay : public nsStyleStruct { PRInt32 CalcDifference(const nsStyleDisplay& aOther) const; PRUint8 mDisplay; // [reset] see nsStyleConsts.h NS_STYLE_DISPLAY_* + PRUint8 mOriginalDisplay; // [reset] saved mDisplay for position:absolute/fixed PRUint8 mAppearance; // [reset] nsString mBinding; // [reset] absolute url string PRUint8 mPosition; // [reset] see nsStyleConsts.h diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index c9660ee1377..a90b99094d2 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -1023,6 +1023,7 @@ nsStyleDisplay::nsStyleDisplay() { mAppearance = 0; mDisplay = NS_STYLE_DISPLAY_INLINE; + mOriginalDisplay = NS_STYLE_DISPLAY_NONE; mPosition = NS_STYLE_POSITION_NORMAL; mFloats = NS_STYLE_FLOAT_NONE; mBreakType = NS_STYLE_CLEAR_NONE; @@ -1037,6 +1038,7 @@ nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource) { mAppearance = aSource.mAppearance; mDisplay = aSource.mDisplay; + mOriginalDisplay = aSource.mOriginalDisplay; mBinding = aSource.mBinding; mPosition = aSource.mPosition; mFloats = aSource.mFloats; diff --git a/mozilla/layout/generic/nsHTMLReflowState.cpp b/mozilla/layout/generic/nsHTMLReflowState.cpp index 1136f8781ca..199371e5db5 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.cpp +++ b/mozilla/layout/generic/nsHTMLReflowState.cpp @@ -781,6 +781,9 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, nsIFrame* aAbsoluteContainingBlockFrame, nsHypotheticalBox& aHypotheticalBox) { + NS_ASSERTION(mStyleDisplay->mOriginalDisplay != NS_STYLE_DISPLAY_NONE, + "mOriginalDisplay has not been properly initialized"); + // If it's a replaced element and it has a 'auto' value for 'width', see if we // can get the intrinsic size. This will allow us to exactly determine both the // left and right edges @@ -796,7 +799,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, // element had been in the flow nscoord boxWidth; PRBool knowBoxWidth = PR_FALSE; - if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) && + if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) && !NS_FRAME_IS_REPLACED(mFrameType)) { // For non-replaced inline-level elements the 'width' property doesn't apply, // so we don't know what the width would have been without reflowing it @@ -841,7 +844,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, // How we determine the hypothetical box depends on whether the element // would have been inline-level or block-level - if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) { + if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) { nsPoint placeholderOffset; // Get the placeholder x-offset and y-offset in the coordinate diff --git a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp index 1136f8781ca..199371e5db5 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp @@ -781,6 +781,9 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, nsIFrame* aAbsoluteContainingBlockFrame, nsHypotheticalBox& aHypotheticalBox) { + NS_ASSERTION(mStyleDisplay->mOriginalDisplay != NS_STYLE_DISPLAY_NONE, + "mOriginalDisplay has not been properly initialized"); + // If it's a replaced element and it has a 'auto' value for 'width', see if we // can get the intrinsic size. This will allow us to exactly determine both the // left and right edges @@ -796,7 +799,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, // element had been in the flow nscoord boxWidth; PRBool knowBoxWidth = PR_FALSE; - if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) && + if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) && !NS_FRAME_IS_REPLACED(mFrameType)) { // For non-replaced inline-level elements the 'width' property doesn't apply, // so we don't know what the width would have been without reflowing it @@ -841,7 +844,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext, // How we determine the hypothetical box depends on whether the element // would have been inline-level or block-level - if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) { + if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) { nsPoint placeholderOffset; // Get the placeholder x-offset and y-offset in the coordinate diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index e9347d09a67..5edd6fc7ff3 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -2884,6 +2884,9 @@ nsRuleNode::ComputeDisplayData(nsStyleStruct* aStartStruct, const nsCSSStruct& a // 2) if position is 'absolute' or 'fixed' then display must be 'block and float must be 'none' // XXX - see note for fixup 1) above... if (display->IsAbsolutelyPositioned() && display->mDisplay != NS_STYLE_DISPLAY_NONE) { + // Backup original display value for calculation of a hypothetical box (CSS2 10.6.4/10.6.5) + // See nsHTMLReflowState::CalculateHypotheticalBox + display->mOriginalDisplay = display->mDisplay; EnsureBlockDisplay(display->mDisplay); display->mFloats = NS_STYLE_FLOAT_NONE; } diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index c9660ee1377..a90b99094d2 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -1023,6 +1023,7 @@ nsStyleDisplay::nsStyleDisplay() { mAppearance = 0; mDisplay = NS_STYLE_DISPLAY_INLINE; + mOriginalDisplay = NS_STYLE_DISPLAY_NONE; mPosition = NS_STYLE_POSITION_NORMAL; mFloats = NS_STYLE_FLOAT_NONE; mBreakType = NS_STYLE_CLEAR_NONE; @@ -1037,6 +1038,7 @@ nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource) { mAppearance = aSource.mAppearance; mDisplay = aSource.mDisplay; + mOriginalDisplay = aSource.mOriginalDisplay; mBinding = aSource.mBinding; mPosition = aSource.mPosition; mFloats = aSource.mFloats; diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index 9f83d7f95b4..89c84d03e99 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -710,6 +710,7 @@ struct nsStyleDisplay : public nsStyleStruct { PRInt32 CalcDifference(const nsStyleDisplay& aOther) const; PRUint8 mDisplay; // [reset] see nsStyleConsts.h NS_STYLE_DISPLAY_* + PRUint8 mOriginalDisplay; // [reset] saved mDisplay for position:absolute/fixed PRUint8 mAppearance; // [reset] nsString mBinding; // [reset] absolute url string PRUint8 mPosition; // [reset] see nsStyleConsts.h