Added ComputeMargin() member function that takes the containing block width

as an argument. This is necessary for absolutely positioned elements which use
the padding edge and not the content edge for the containing block
This commit is contained in:
troy%netscape.com 1999-03-05 22:24:27 +00:00
Родитель 3b004d1419
Коммит e3d132ed9c
3 изменённых файлов: 172 добавлений и 36 удалений

Просмотреть файл

@ -689,24 +689,6 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
computedOffsets.SizeTo(0, 0, 0, 0);
}
// Compute margins from the specified margin style information. These
// become the default computed values, and may be adjusted below
// XXX fix to provide 0,0 for the top&bottom margins for
// inline-non-replaced elements
// XXX Make into non-static methods?
ComputeMarginFor(frame, parentReflowState, computedMargin);
#ifdef DEBUG_kipp
NS_ASSERTION((computedMargin.left > -200000) &&
(computedMargin.left < 200000), "oy");
NS_ASSERTION((computedMargin.right > -200000) &&
(computedMargin.right < 200000), "oy");
#endif
ComputeBorderFor(frame, mComputedBorderPadding);
ComputePaddingFor(frame, parentReflowState, mComputedPadding);
mComputedBorderPadding += mComputedPadding;
// Get the containing block width and height. We'll need them when
// calculating the computed width and height. For all elements other
// than absolutely positioned elements, the containing block is formed
@ -746,6 +728,21 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
}
}
// Compute margins from the specified margin style information. These
// become the default computed values, and may be adjusted below
// XXX fix to provide 0,0 for the top&bottom margins for
// inline-non-replaced elements
ComputeMargin(containingBlockWidth);
#ifdef DEBUG_kipp
NS_ASSERTION((computedMargin.left > -200000) &&
(computedMargin.left < 200000), "oy");
NS_ASSERTION((computedMargin.right > -200000) &&
(computedMargin.right < 200000), "oy");
#endif
ComputeBorderFor(frame, mComputedBorderPadding);
ComputePaddingFor(frame, parentReflowState, mComputedPadding);
mComputedBorderPadding += mComputedPadding;
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
@ -1199,6 +1196,75 @@ nsHTMLReflowState::ComputeMarginFor(nsIFrame* aFrame,
}
}
void
nsHTMLReflowState::ComputeMargin(nscoord aContainingBlockWidth)
{
// If style style can provide us the margin directly, then use it.
#if 0
if (!mStyleSpacing->GetMargin(aResult) && (nsnull != aParentRS))
#else
mStyleSpacing->CalcMarginFor(frame, computedMargin);
if ((eStyleUnit_Percent == mStyleSpacing->mMargin.GetTopUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetRightUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetBottomUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetLeftUnit()))
#endif
{
// We have to compute the value (because it's uncomputable by
// the style code).
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
computedMargin.left = 0;
computedMargin.right = 0;
} else {
nsStyleCoord left, right;
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetLeftUnit(),
mStyleSpacing->mMargin.GetLeft(left),
computedMargin.left);
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetRightUnit(),
mStyleSpacing->mMargin.GetRight(right),
computedMargin.right);
}
const nsHTMLReflowState* rs2 = GetPageBoxReflowState(parentReflowState);
nsStyleCoord top, bottom;
if (nsnull != rs2) {
// According to the CSS2 spec, margin percentages are
// calculated with respect to the *height* of the containing
// block when in a paginated context.
ComputeVerticalValue(rs2->computedHeight,
mStyleSpacing->mMargin.GetTopUnit(),
mStyleSpacing->mMargin.GetTop(top),
computedMargin.top);
ComputeVerticalValue(rs2->computedHeight,
mStyleSpacing->mMargin.GetBottomUnit(),
mStyleSpacing->mMargin.GetBottom(bottom),
computedMargin.bottom);
}
else {
// According to the CSS2 spec, margin percentages are
// calculated with respect to the *width* of the containing
// block, even for margin-top and margin-bottom.
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
computedMargin.top = 0;
computedMargin.bottom = 0;
} else {
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetTopUnit(),
mStyleSpacing->mMargin.GetTop(top),
computedMargin.top);
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetBottomUnit(),
mStyleSpacing->mMargin.GetBottom(bottom),
computedMargin.bottom);
}
}
}
}
void
nsHTMLReflowState::ComputePaddingFor(nsIFrame* aFrame,
const nsReflowState* aParentRS,

Просмотреть файл

@ -689,24 +689,6 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
computedOffsets.SizeTo(0, 0, 0, 0);
}
// Compute margins from the specified margin style information. These
// become the default computed values, and may be adjusted below
// XXX fix to provide 0,0 for the top&bottom margins for
// inline-non-replaced elements
// XXX Make into non-static methods?
ComputeMarginFor(frame, parentReflowState, computedMargin);
#ifdef DEBUG_kipp
NS_ASSERTION((computedMargin.left > -200000) &&
(computedMargin.left < 200000), "oy");
NS_ASSERTION((computedMargin.right > -200000) &&
(computedMargin.right < 200000), "oy");
#endif
ComputeBorderFor(frame, mComputedBorderPadding);
ComputePaddingFor(frame, parentReflowState, mComputedPadding);
mComputedBorderPadding += mComputedPadding;
// Get the containing block width and height. We'll need them when
// calculating the computed width and height. For all elements other
// than absolutely positioned elements, the containing block is formed
@ -746,6 +728,21 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
}
}
// Compute margins from the specified margin style information. These
// become the default computed values, and may be adjusted below
// XXX fix to provide 0,0 for the top&bottom margins for
// inline-non-replaced elements
ComputeMargin(containingBlockWidth);
#ifdef DEBUG_kipp
NS_ASSERTION((computedMargin.left > -200000) &&
(computedMargin.left < 200000), "oy");
NS_ASSERTION((computedMargin.right > -200000) &&
(computedMargin.right < 200000), "oy");
#endif
ComputeBorderFor(frame, mComputedBorderPadding);
ComputePaddingFor(frame, parentReflowState, mComputedPadding);
mComputedBorderPadding += mComputedPadding;
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
@ -1199,6 +1196,75 @@ nsHTMLReflowState::ComputeMarginFor(nsIFrame* aFrame,
}
}
void
nsHTMLReflowState::ComputeMargin(nscoord aContainingBlockWidth)
{
// If style style can provide us the margin directly, then use it.
#if 0
if (!mStyleSpacing->GetMargin(aResult) && (nsnull != aParentRS))
#else
mStyleSpacing->CalcMarginFor(frame, computedMargin);
if ((eStyleUnit_Percent == mStyleSpacing->mMargin.GetTopUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetRightUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetBottomUnit()) ||
(eStyleUnit_Percent == mStyleSpacing->mMargin.GetLeftUnit()))
#endif
{
// We have to compute the value (because it's uncomputable by
// the style code).
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
computedMargin.left = 0;
computedMargin.right = 0;
} else {
nsStyleCoord left, right;
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetLeftUnit(),
mStyleSpacing->mMargin.GetLeft(left),
computedMargin.left);
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetRightUnit(),
mStyleSpacing->mMargin.GetRight(right),
computedMargin.right);
}
const nsHTMLReflowState* rs2 = GetPageBoxReflowState(parentReflowState);
nsStyleCoord top, bottom;
if (nsnull != rs2) {
// According to the CSS2 spec, margin percentages are
// calculated with respect to the *height* of the containing
// block when in a paginated context.
ComputeVerticalValue(rs2->computedHeight,
mStyleSpacing->mMargin.GetTopUnit(),
mStyleSpacing->mMargin.GetTop(top),
computedMargin.top);
ComputeVerticalValue(rs2->computedHeight,
mStyleSpacing->mMargin.GetBottomUnit(),
mStyleSpacing->mMargin.GetBottom(bottom),
computedMargin.bottom);
}
else {
// According to the CSS2 spec, margin percentages are
// calculated with respect to the *width* of the containing
// block, even for margin-top and margin-bottom.
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
computedMargin.top = 0;
computedMargin.bottom = 0;
} else {
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetTopUnit(),
mStyleSpacing->mMargin.GetTop(top),
computedMargin.top);
ComputeHorizontalValue(aContainingBlockWidth,
mStyleSpacing->mMargin.GetBottomUnit(),
mStyleSpacing->mMargin.GetBottom(bottom),
computedMargin.bottom);
}
}
}
}
void
nsHTMLReflowState::ComputePaddingFor(nsIFrame* aFrame,
const nsReflowState* aParentRS,

Просмотреть файл

@ -344,6 +344,10 @@ protected:
static nsCSSFrameType DetermineFrameType(nsIFrame* aFrame,
const nsStylePosition* aPosition,
const nsStyleDisplay* aDisplay);
// Computes margins from the specified margin style information, and
// fills in the mComputedMargin member
void ComputeMargin(nscoord aContainingBlockWidth);
};
//----------------------------------------------------------------------