Added CalcLineHeight and apply it to inline non-replaced elements as a constrained height

This commit is contained in:
kipp%netscape.com 1998-12-15 00:14:36 +00:00
Родитель 5557226135
Коммит 8b61e19c33
1 изменённых файлов: 80 добавлений и 0 удалений

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

@ -185,11 +185,23 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
minWidth = 0;
minHeight = 0;
mLineHeight = CalcLineHeight(aPresContext, frame);
// Some frame types are not constrained by width/height style
// attributes. Return if the frame is one of those types.
switch (frameType) {
case eCSSFrameType_Unknown:
return;
case eCSSFrameType_Inline:
if (mLineHeight >= 0) {
#if 0
minHeight = maxSize.height = mLineHeight;
#else
minHeight = mLineHeight;
#endif
heightConstraint = eHTMLFrameConstraint_FixedContent;
}
return;
default:
@ -290,6 +302,74 @@ nsHTMLReflowState::InitConstraints(nsIPresContext& aPresContext)
// (section 10.3/10.6 of the spec)
}
nscoord
nsHTMLReflowState::CalcLineHeight(nsIPresContext& aPresContext,
nsIFrame* aFrame)
{
nscoord lineHeight = -1;
nsIStyleContext* sc;
aFrame->GetStyleContext(sc);
const nsStyleFont* elementFont = nsnull;
if (nsnull != sc) {
elementFont = (const nsStyleFont*)sc->GetStyleData(eStyleStruct_Font);
for (;;) {
const nsStyleText* text = (const nsStyleText*)
sc->GetStyleData(eStyleStruct_Text);
if (nsnull != text) {
nsStyleUnit unit = text->mLineHeight.GetUnit();
#ifdef NOISY_VERTICAL_ALIGN
printf(" styleUnit=%d\n", unit);
#endif
if (eStyleUnit_Enumerated == unit) {
// Normal value; we use 1.0 for normal
// XXX could come from somewhere else
break;
} else if (eStyleUnit_Factor == unit) {
if (nsnull != elementFont) {
// CSS2 spec says that the number is inherited, not the
// computed value. Therefore use the font size of the
// element times the inherited number.
nscoord size = elementFont->mFont.size;
lineHeight = nscoord(size * text->mLineHeight.GetFactorValue());
}
break;
}
else if (eStyleUnit_Coord == unit) {
lineHeight = text->mLineHeight.GetCoordValue();
break;
}
else if (eStyleUnit_Percent == unit) {
// XXX This could arguably be the font-metrics actual height
// instead since the spec says use the computed height.
const nsStyleFont* font = (const nsStyleFont*)
sc->GetStyleData(eStyleStruct_Font);
nscoord size = font->mFont.size;
lineHeight = nscoord(size * text->mLineHeight.GetPercentValue());
break;
}
else if (eStyleUnit_Inherit == unit) {
nsIStyleContext* parentSC;
parentSC = sc->GetParent();
if (nsnull == parentSC) {
// Note: Break before releasing to avoid double-releasing sc
break;
}
NS_RELEASE(sc);
sc = parentSC;
}
else {
// other units are not part of the spec so don't bother
// looping
break;
}
}
}
NS_RELEASE(sc);
}
return lineHeight;
}
void
nsHTMLReflowState::ComputeHorizontalValue(const nsHTMLReflowState& aRS,
nsStyleUnit aUnit,