From 82258b5c711b03c7725f447c6de1e0339232c6f0 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Tue, 29 Sep 1998 22:32:56 +0000 Subject: [PATCH] Add in a bottom-line-margin when dealing with a zero-height line that contains a BR frame --- layout/generic/nsBlockFrame.cpp | 29 +++++++++++++++++++-- layout/generic/nsBlockReflowState.cpp | 29 +++++++++++++++++++-- layout/generic/nsBlockReflowState.h | 29 +++++++++++++++++++-- layout/html/base/src/nsBlockFrame.cpp | 29 +++++++++++++++++++-- layout/html/base/src/nsBlockReflowState.cpp | 29 +++++++++++++++++++-- layout/html/base/src/nsBlockReflowState.h | 29 +++++++++++++++++++-- 6 files changed, 162 insertions(+), 12 deletions(-) diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 76d94642b49c..ebc709d69be8 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break; diff --git a/layout/generic/nsBlockReflowState.cpp b/layout/generic/nsBlockReflowState.cpp index 76d94642b49c..ebc709d69be8 100644 --- a/layout/generic/nsBlockReflowState.cpp +++ b/layout/generic/nsBlockReflowState.cpp @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break; diff --git a/layout/generic/nsBlockReflowState.h b/layout/generic/nsBlockReflowState.h index 76d94642b49c..ebc709d69be8 100644 --- a/layout/generic/nsBlockReflowState.h +++ b/layout/generic/nsBlockReflowState.h @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break; diff --git a/layout/html/base/src/nsBlockFrame.cpp b/layout/html/base/src/nsBlockFrame.cpp index 76d94642b49c..ebc709d69be8 100644 --- a/layout/html/base/src/nsBlockFrame.cpp +++ b/layout/html/base/src/nsBlockFrame.cpp @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break; diff --git a/layout/html/base/src/nsBlockReflowState.cpp b/layout/html/base/src/nsBlockReflowState.cpp index 76d94642b49c..ebc709d69be8 100644 --- a/layout/html/base/src/nsBlockReflowState.cpp +++ b/layout/html/base/src/nsBlockReflowState.cpp @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break; diff --git a/layout/html/base/src/nsBlockReflowState.h b/layout/html/base/src/nsBlockReflowState.h index 76d94642b49c..ebc709d69be8 100644 --- a/layout/html/base/src/nsBlockReflowState.h +++ b/layout/html/base/src/nsBlockReflowState.h @@ -3134,6 +3134,31 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, ir.HorizontalAlignFrames(aLine->mBounds); ir.RelativePositionFrames(); + // Calculate the bottom margin for the line. + nscoord lineBottomMargin = 0; + if (0 == aLine->mBounds.height) { + nsIFrame* brFrame = aState.mLineLayout.GetBRFrame(); + if (nsnull != brFrame) { + // If a line ends in a BR and the line is empty of height then we + // make sure that the line ends up with some height anyway. Note + // that the height looks like vertical margin so that it can + // compress with other block margins. + nsIStyleContext* brSC; + nsIPresContext& px = aState.mPresContext; + nsresult rv = brFrame->GetStyleContext(&px, brSC); + if ((NS_OK == rv) && (nsnull != brSC)) { + const nsStyleFont* font = (const nsStyleFont*) + brSC->GetStyleData(eStyleStruct_Font); + nsIFontMetrics* fm = px.GetMetricsFor(font->mFont); + if (nsnull != fm) { + fm->GetHeight(lineBottomMargin); + NS_RELEASE(fm); + } + NS_RELEASE(brSC); + } + } + } + // See if the line fit. If it doesn't we need to push it. Our first // line will always fit. @@ -3143,7 +3168,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // XXX don't forget to factor in the top/bottom margin when sharing // this with the block code - nscoord newY = aState.mY + aLine->mBounds.height; + nscoord newY = aState.mY + aLine->mBounds.height + lineBottomMargin; NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW, ("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d", newY, aState.mBottomEdge, aLine->mBounds.height)); @@ -3216,8 +3241,8 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, // Based on the last child we reflowed reflow status, we may need to // clear past any floaters. if (NS_INLINE_IS_BREAK_AFTER(aReflowStatus)) { - // Apply break to the line PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(aReflowStatus); + // Apply break to the line switch (breakType) { default: break;