Removed VerticallyAlignChildren (it's in nsInlineReflow now)
git-svn-id: svn://10.0.0.236/trunk@10761 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -29,196 +29,6 @@
|
||||
NS_DEF_PTR(nsIStyleContext);
|
||||
NS_DEF_PTR(nsIContent);
|
||||
|
||||
// XXX what about ebina's center vs. ncsa-center?
|
||||
/*
|
||||
* Notes: It's a known fact that this doesn't do what ebina's layout
|
||||
* engine does because his code did vertical alignment on the
|
||||
* fly. Hopefully that's ok because his code generated surprising
|
||||
* results in a number of unusual cases.
|
||||
*/
|
||||
nscoord
|
||||
nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
nsIFrame* aContainer,
|
||||
const nsStyleFont* aContainerFont,
|
||||
nscoord aY0,
|
||||
nsIFrame* aFirstChild,
|
||||
PRIntn aChildCount,
|
||||
nscoord* aAscents,
|
||||
nscoord aMaxAscent)
|
||||
{
|
||||
// Determine minimum and maximum y values for the line and
|
||||
// perform alignment of all children except those requesting bottom
|
||||
// alignment. The second pass will align bottom children (if any)
|
||||
nsIFontMetrics* fm = aCX->GetMetricsFor(aContainerFont->mFont);
|
||||
nsIFrame* kid = aFirstChild;
|
||||
nsRect kidRect;
|
||||
nscoord minY = aY0;
|
||||
nscoord maxY = aY0;
|
||||
PRIntn pass2Kids = 0;
|
||||
PRIntn kidCount = aChildCount;
|
||||
nscoord* ascents = aAscents;
|
||||
while (--kidCount >= 0) {
|
||||
nscoord kidAscent = *ascents++;
|
||||
|
||||
const nsStyleText* textStyle;
|
||||
kid->GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)textStyle);
|
||||
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
|
||||
PRUint8 verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BASELINE;
|
||||
|
||||
kid->GetRect(kidRect);
|
||||
|
||||
// Vertically align the child
|
||||
nscoord kidYTop = 0;
|
||||
|
||||
PRBool isPass2Kid = PR_FALSE;
|
||||
nscoord fontParam;
|
||||
switch (verticalAlignUnit) {
|
||||
case eStyleUnit_Coord:
|
||||
// According to the spec, a positive value "raises" the box by
|
||||
// the given distance while a negative value "lowers" the box
|
||||
// by the given distance. Since Y coordinates increase towards
|
||||
// the bottom of the screen we reverse the sign. All of the
|
||||
// raising and lowering is done relative to the baseline, so
|
||||
// we start our adjustments there.
|
||||
kidYTop = aMaxAscent - kidAscent; // get baseline first
|
||||
kidYTop -= textStyle->mVerticalAlign.GetCoordValue();
|
||||
break;
|
||||
|
||||
case eStyleUnit_Percent:
|
||||
pass2Kids++;
|
||||
isPass2Kid = PR_TRUE;
|
||||
break;
|
||||
|
||||
case eStyleUnit_Enumerated:
|
||||
verticalAlignEnum = textStyle->mVerticalAlign.GetIntValue();
|
||||
switch (verticalAlignEnum) {
|
||||
default:
|
||||
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
||||
// Align the kid's baseline at the max baseline
|
||||
kidYTop = aMaxAscent - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
||||
// Align the top of the kid with the top of the line box
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUB:
|
||||
// Align the child's baseline on the superscript baseline
|
||||
fm->GetSubscriptOffset(fontParam);
|
||||
kidYTop = aMaxAscent + fontParam - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUPER:
|
||||
// Align the child's baseline on the subscript baseline
|
||||
fm->GetSuperscriptOffset(fontParam);
|
||||
kidYTop = aMaxAscent - fontParam - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
||||
pass2Kids++;
|
||||
isPass2Kid = PR_TRUE;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
||||
// Align the midpoint of the box with 1/2 the parent's x-height
|
||||
fm->GetXHeight(fontParam);
|
||||
kidYTop = aMaxAscent - (fontParam / 2) - (kidRect.height/2);
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
||||
fm->GetMaxDescent(fontParam);
|
||||
kidYTop = aMaxAscent + fontParam - kidRect.height;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
||||
fm->GetMaxAscent(fontParam);
|
||||
kidYTop = aMaxAscent - fontParam;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Align the kid's baseline at the max baseline
|
||||
kidYTop = aMaxAscent - kidAscent;
|
||||
break;
|
||||
}
|
||||
|
||||
/* XXX or grow the box - which is it? */
|
||||
if (kidYTop < 0) {
|
||||
kidYTop = 0;
|
||||
}
|
||||
|
||||
// Place kid and update min and max Y values
|
||||
if (!isPass2Kid) {
|
||||
nscoord y = aY0 + kidYTop;
|
||||
if (y < minY) minY = y;
|
||||
kid->MoveTo(kidRect.x, y);
|
||||
y += kidRect.height;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
else {
|
||||
nscoord y = aY0 + kidRect.height;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
|
||||
kid->GetNextSibling(kid);
|
||||
}
|
||||
|
||||
// Now compute the final line-height
|
||||
nscoord lineHeight = maxY - minY;
|
||||
|
||||
if (0 != pass2Kids) {
|
||||
// Position all of the bottom aligned children
|
||||
kidCount = aChildCount;
|
||||
kid = aFirstChild;
|
||||
ascents = aAscents;
|
||||
while (--kidCount >= 0) {
|
||||
nscoord kidAscent = *ascents++;
|
||||
|
||||
// Get kid's vertical align style data
|
||||
const nsStyleText* textStyle;
|
||||
kid->GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)textStyle);
|
||||
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
|
||||
|
||||
if (eStyleUnit_Percent == verticalAlignUnit) {
|
||||
// According to the spec, a positive value "raises" the box by
|
||||
// the given distance while a negative value "lowers" the box
|
||||
// by the given distance. Since Y coordinates increase towards
|
||||
// the bottom of the screen we reverse the sign. All of the
|
||||
// raising and lowering is done relative to the baseline, so
|
||||
// we start our adjustments there.
|
||||
nscoord kidYTop = aMaxAscent - kidAscent; // get baseline first
|
||||
kidYTop -=
|
||||
nscoord(textStyle->mVerticalAlign.GetPercentValue() * lineHeight);
|
||||
kid->GetRect(kidRect);
|
||||
kid->MoveTo(kidRect.x, aY0 + kidYTop);
|
||||
if (--pass2Kids == 0) {
|
||||
// Stop on last pass2 kid
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (verticalAlignUnit == eStyleUnit_Enumerated) {
|
||||
PRUint8 verticalAlignEnum = textStyle->mVerticalAlign.GetIntValue();
|
||||
// Vertically align the child
|
||||
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM == verticalAlignEnum) {
|
||||
// Place kid along the bottom
|
||||
kid->GetRect(kidRect);
|
||||
kid->MoveTo(kidRect.x, aY0 + lineHeight - kidRect.height);
|
||||
if (--pass2Kids == 0) {
|
||||
// Stop on last pass2 kid
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kid->GetNextSibling(kid);
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(fm);
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Horizontally place the children in the container frame.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user