changed nsStyleText to use nsStyleCoord

This commit is contained in:
peterl 1998-04-28 23:57:01 +00:00
Родитель e7b269d828
Коммит e680905372
8 изменённых файлов: 172 добавлений и 116 удалений

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

@ -65,59 +65,75 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
kid->GetStyleContext(aCX, kidSC.AssignRef());
kid->GetContent(kidContent.AssignRef());
nsStyleText* textStyle = (nsStyleText*)kidSC->GetData(kStyleTextSID);
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
PRUint8 verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BASELINE;
kid->GetRect(kidRect);
// Vertically align the child
nscoord kidYTop = 0;
switch (verticalAlignFlags) {
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;
switch (verticalAlignUnit) {
case eStyleUnit_Twips:
kidYTop = aMaxAscent + textStyle->mVerticalAlign.GetCoordValue();
break;
case NS_STYLE_VERTICAL_ALIGN_SUB:
// Move baseline by 1/2 the ascent of the child.
// NOTE: CSSx doesn't seem to specify what subscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent + (kidAscent/2) - kidAscent;
break;
case eStyleUnit_Percent:
pass2Kids++;
break;
case NS_STYLE_VERTICAL_ALIGN_SUPER:
// Move baseline by 1/2 the ascent of the child
// NOTE: CSSx doesn't seem to specify what superscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent - (kidAscent/2) - kidAscent;
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_BOTTOM:
case NS_STYLE_VERTICAL_ALIGN_PERCENT:
pass2Kids++;
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_MIDDLE:
// XXX spec says use the 'x' height but our font api doesn't give us
// that information.
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
break;
case NS_STYLE_VERTICAL_ALIGN_SUB:
// Move baseline by 1/2 the ascent of the child.
// NOTE: CSSx doesn't seem to specify what subscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent + (kidAscent/2) - kidAscent;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
break;
case NS_STYLE_VERTICAL_ALIGN_SUPER:
// Move baseline by 1/2 the ascent of the child
// NOTE: CSSx doesn't seem to specify what superscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent - (kidAscent/2) - kidAscent;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
kidYTop = aMaxAscent - fm->GetMaxAscent();
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
pass2Kids++;
break;
case NS_STYLE_VERTICAL_ALIGN_LENGTH:
kidYTop = aMaxAscent + textStyle->mVerticalAlign.coord;
break;
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
// XXX spec says use the 'x' height but our font api doesn't give us
// that information.
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
kidYTop = aMaxAscent - fm->GetMaxAscent();
break;
}
break;
default:
// Align the kid's baseline at the max baseline
kidYTop = aMaxAscent - kidAscent;
break;
}
// Place kid and update min and max Y values
@ -144,21 +160,11 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
kid->GetStyleContext(aCX, kidSC.AssignRef());
kid->GetContent(kidContent.AssignRef());
nsStyleText* textStyle = (nsStyleText*)kidSC->GetData(kStyleTextSID);
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
// Vertically align the child
if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_BOTTOM) {
// 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;
}
}
else if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_PERCENT) {
if (eStyleUnit_Percent == verticalAlignUnit) {
nscoord kidYTop = aMaxAscent +
nscoord(textStyle->mVerticalAlign.percent * lineHeight);
nscoord(textStyle->mVerticalAlign.GetFloatValue() * lineHeight);
kid->GetRect(kidRect);
kid->MoveTo(kidRect.x, aY0 + kidYTop);
if (--pass2Kids == 0) {
@ -166,6 +172,19 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
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);
}

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

@ -565,7 +565,7 @@ void ImagePart::MapAttributesInto(nsIStyleContext* aContext,
display->mFloats = NS_STYLE_FLOAT_RIGHT;
break;
default:
text->mVerticalAlignFlags = mAlign;
text->mVerticalAlign.Set(mAlign, eStyleUnit_Enumerated);
break;
}
}

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

@ -65,59 +65,75 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
kid->GetStyleContext(aCX, kidSC.AssignRef());
kid->GetContent(kidContent.AssignRef());
nsStyleText* textStyle = (nsStyleText*)kidSC->GetData(kStyleTextSID);
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
PRUint8 verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BASELINE;
kid->GetRect(kidRect);
// Vertically align the child
nscoord kidYTop = 0;
switch (verticalAlignFlags) {
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;
switch (verticalAlignUnit) {
case eStyleUnit_Twips:
kidYTop = aMaxAscent + textStyle->mVerticalAlign.GetCoordValue();
break;
case NS_STYLE_VERTICAL_ALIGN_SUB:
// Move baseline by 1/2 the ascent of the child.
// NOTE: CSSx doesn't seem to specify what subscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent + (kidAscent/2) - kidAscent;
break;
case eStyleUnit_Percent:
pass2Kids++;
break;
case NS_STYLE_VERTICAL_ALIGN_SUPER:
// Move baseline by 1/2 the ascent of the child
// NOTE: CSSx doesn't seem to specify what superscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent - (kidAscent/2) - kidAscent;
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_BOTTOM:
case NS_STYLE_VERTICAL_ALIGN_PERCENT:
pass2Kids++;
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_MIDDLE:
// XXX spec says use the 'x' height but our font api doesn't give us
// that information.
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
break;
case NS_STYLE_VERTICAL_ALIGN_SUB:
// Move baseline by 1/2 the ascent of the child.
// NOTE: CSSx doesn't seem to specify what subscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent + (kidAscent/2) - kidAscent;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
break;
case NS_STYLE_VERTICAL_ALIGN_SUPER:
// Move baseline by 1/2 the ascent of the child
// NOTE: CSSx doesn't seem to specify what superscripting does
// so we are using ebina's logic
kidYTop = aMaxAscent - (kidAscent/2) - kidAscent;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
kidYTop = aMaxAscent - fm->GetMaxAscent();
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
pass2Kids++;
break;
case NS_STYLE_VERTICAL_ALIGN_LENGTH:
kidYTop = aMaxAscent + textStyle->mVerticalAlign.coord;
break;
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
// XXX spec says use the 'x' height but our font api doesn't give us
// that information.
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
break;
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
kidYTop = aMaxAscent - fm->GetMaxAscent();
break;
}
break;
default:
// Align the kid's baseline at the max baseline
kidYTop = aMaxAscent - kidAscent;
break;
}
// Place kid and update min and max Y values
@ -144,21 +160,11 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
kid->GetStyleContext(aCX, kidSC.AssignRef());
kid->GetContent(kidContent.AssignRef());
nsStyleText* textStyle = (nsStyleText*)kidSC->GetData(kStyleTextSID);
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
// Vertically align the child
if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_BOTTOM) {
// 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;
}
}
else if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_PERCENT) {
if (eStyleUnit_Percent == verticalAlignUnit) {
nscoord kidYTop = aMaxAscent +
nscoord(textStyle->mVerticalAlign.percent * lineHeight);
nscoord(textStyle->mVerticalAlign.GetFloatValue() * lineHeight);
kid->GetRect(kidRect);
kid->MoveTo(kidRect.x, aY0 + kidYTop);
if (--pass2Kids == 0) {
@ -166,6 +172,19 @@ nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
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);
}

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

@ -137,7 +137,11 @@ void nsTableCaptionFrame::VerticallyAlignChild(nsIPresContext* aPresContext)
nscoord topInset = spacing->mBorderPadding.top;
nscoord bottomInset = spacing->mBorderPadding.bottom;
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
}
nscoord height = mRect.height;

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

@ -95,7 +95,11 @@ void nsTableCellFrame::VerticallyAlignChild(nsIPresContext* aPresContext)
nscoord topInset = spacing->mBorderPadding.top;
nscoord bottomInset = spacing->mBorderPadding.bottom;
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
}
nscoord height = mRect.height;
nsRect kidRect;

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

@ -892,7 +892,8 @@ nsTableOuterFrame::ReflowChild( nsIFrame* aKidFrame,
nsStyleText* captionStyle =
(nsStyleText*)captionStyleContext->GetData(kStyleTextSID);
NS_ASSERTION(nsnull != captionStyle, "null style molecule for caption");
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{
if (PR_TRUE==gsDebug) printf("reflowChild called with a bottom caption\n");
status = ResizeReflowBottomCaptionsPass2(aPresContext, aDesiredSize,
@ -976,7 +977,8 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext)
captionFrame->SetStyleContext(captionStyleContext);
mChildCount++;
// Link child frame into the list of children
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{ // bottom captions get added to the end of the outer frame child list
prevKidFrame->SetNextSibling(captionFrame);
prevKidFrame = captionFrame;
@ -1061,7 +1063,8 @@ nsTableOuterFrame::ResizeReflowTopCaptionsPass2(nsIPresContext* aPresContext,
(nsStyleText*)captionStyleContext->GetData(kStyleTextSID);
NS_ASSERTION(nsnull != captionStyle, "null style molecule for caption");
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{
}
else

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

@ -95,7 +95,11 @@ void nsTableCellFrame::VerticallyAlignChild(nsIPresContext* aPresContext)
nscoord topInset = spacing->mBorderPadding.top;
nscoord bottomInset = spacing->mBorderPadding.bottom;
PRUint8 verticalAlignFlags = textStyle->mVerticalAlignFlags;
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
}
nscoord height = mRect.height;
nsRect kidRect;

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

@ -892,7 +892,8 @@ nsTableOuterFrame::ReflowChild( nsIFrame* aKidFrame,
nsStyleText* captionStyle =
(nsStyleText*)captionStyleContext->GetData(kStyleTextSID);
NS_ASSERTION(nsnull != captionStyle, "null style molecule for caption");
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{
if (PR_TRUE==gsDebug) printf("reflowChild called with a bottom caption\n");
status = ResizeReflowBottomCaptionsPass2(aPresContext, aDesiredSize,
@ -976,7 +977,8 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext)
captionFrame->SetStyleContext(captionStyleContext);
mChildCount++;
// Link child frame into the list of children
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{ // bottom captions get added to the end of the outer frame child list
prevKidFrame->SetNextSibling(captionFrame);
prevKidFrame = captionFrame;
@ -1061,7 +1063,8 @@ nsTableOuterFrame::ResizeReflowTopCaptionsPass2(nsIPresContext* aPresContext,
(nsStyleText*)captionStyleContext->GetData(kStyleTextSID);
NS_ASSERTION(nsnull != captionStyle, "null style molecule for caption");
if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlignFlags)
if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) &&
(NS_STYLE_VERTICAL_ALIGN_BOTTOM==captionStyle->mVerticalAlign.GetIntValue()))
{
}
else