Teaching the fixed layout strategy how to deal with relative/proportional specified

widths.


git-svn-id: svn://10.0.0.236/trunk@45035 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hyatt%netscape.com 1999-08-29 06:00:32 +00:00
parent 49a54c8870
commit 61f02a1d7b
2 changed files with 88 additions and 36 deletions

View File

@ -76,7 +76,11 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
nscoord totalColWidth = 0; // the sum of the widths of the columns
nscoord* colWidths = new PRBool[mNumCols];
nsCRT::memset(colWidths, -1, mNumCols*sizeof(nscoord));
nsCRT::memset(colWidths, WIDTH_NOT_SET, mNumCols*sizeof(nscoord));
nscoord* propInfo = new PRBool[mNumCols];
nsCRT::memset(propInfo, 0, mNumCols*sizeof(nscoord));
nscoord propTotal = 0;
// for every column, determine its specified width
for (colX = 0; colX < mNumCols; colX++) {
@ -101,6 +105,11 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
float percent = colPosition->mWidth.GetPercentValue();
colWidths[colX] = NSToCoordRound(percent * (float)availWidth);
}
else if (eStyleUnit_Proportional == colPosition->mWidth.GetUnit() &&
colPosition->mWidth.GetIntValue() > 0) {
propInfo[colX] = colPosition->mWidth.GetIntValue();
propTotal += propInfo[colX];
}
else { // get width from the cell
nsTableCellFrame* cellFrame = mTableFrame->GetCellFrameAt(0, colX);
if (nsnull != cellFrame) {
@ -133,29 +142,42 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
remainingWidth = 100;
}
if (tableIsFixedWidth && (0 < remainingWidth)) {
if (mNumCols > specifiedCols) {
// allocate the extra space to the columns which have no width specified
nscoord colAlloc = NSToCoordRound( ((float)remainingWidth) / (((float)mNumCols) - ((float)specifiedCols)));
if (0 < remainingWidth) {
if (propTotal > 0) {
for (colX = 0; colX < mNumCols; colX++) {
if (-1 == colWidths[colX]) {
colWidths[colX] = colAlloc;
totalColWidth += colAlloc;
if (propInfo[colX] > 0) {
// We're proportional
float percent = ((float)propInfo[colX])/((float)propTotal);
colWidths[colX] = NSToCoordRound(percent * (float)remainingWidth);
totalColWidth += colWidths[colX];
lastColAllocated = colX;
}
}
}
}
else { // allocate the extra space to the columns which have width specified
float divisor = (float)totalColWidth;
for (colX = 0; colX < mNumCols; colX++) {
if (colWidths[colX] > 0) {
nscoord colAlloc = NSToCoordRound(remainingWidth * colWidths[colX] / divisor);
colWidths[colX] += colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
else if (tableIsFixedWidth) {
if (mNumCols > specifiedCols) {
// allocate the extra space to the columns which have no width specified
nscoord colAlloc = NSToCoordRound( ((float)remainingWidth) / (((float)mNumCols) - ((float)specifiedCols)));
for (colX = 0; colX < mNumCols; colX++) {
if (-1 == colWidths[colX]) {
colWidths[colX] = colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
}
}
}
}
else { // allocate the extra space to the columns which have width specified
float divisor = (float)totalColWidth;
for (colX = 0; colX < mNumCols; colX++) {
if (colWidths[colX] > 0) {
nscoord colAlloc = NSToCoordRound(remainingWidth * colWidths[colX] / divisor);
colWidths[colX] += colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
}
}
}
}
}
nscoord overAllocation = (availWidth >= 0)
@ -179,6 +201,10 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
if (nsnull != colWidths) {
delete [] colWidths;
}
if (nsnull != propInfo) {
delete [] propInfo;
}
return PR_TRUE;
}

View File

@ -76,7 +76,11 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
nscoord totalColWidth = 0; // the sum of the widths of the columns
nscoord* colWidths = new PRBool[mNumCols];
nsCRT::memset(colWidths, -1, mNumCols*sizeof(nscoord));
nsCRT::memset(colWidths, WIDTH_NOT_SET, mNumCols*sizeof(nscoord));
nscoord* propInfo = new PRBool[mNumCols];
nsCRT::memset(propInfo, 0, mNumCols*sizeof(nscoord));
nscoord propTotal = 0;
// for every column, determine its specified width
for (colX = 0; colX < mNumCols; colX++) {
@ -101,6 +105,11 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
float percent = colPosition->mWidth.GetPercentValue();
colWidths[colX] = NSToCoordRound(percent * (float)availWidth);
}
else if (eStyleUnit_Proportional == colPosition->mWidth.GetUnit() &&
colPosition->mWidth.GetIntValue() > 0) {
propInfo[colX] = colPosition->mWidth.GetIntValue();
propTotal += propInfo[colX];
}
else { // get width from the cell
nsTableCellFrame* cellFrame = mTableFrame->GetCellFrameAt(0, colX);
if (nsnull != cellFrame) {
@ -133,29 +142,42 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
remainingWidth = 100;
}
if (tableIsFixedWidth && (0 < remainingWidth)) {
if (mNumCols > specifiedCols) {
// allocate the extra space to the columns which have no width specified
nscoord colAlloc = NSToCoordRound( ((float)remainingWidth) / (((float)mNumCols) - ((float)specifiedCols)));
if (0 < remainingWidth) {
if (propTotal > 0) {
for (colX = 0; colX < mNumCols; colX++) {
if (-1 == colWidths[colX]) {
colWidths[colX] = colAlloc;
totalColWidth += colAlloc;
if (propInfo[colX] > 0) {
// We're proportional
float percent = ((float)propInfo[colX])/((float)propTotal);
colWidths[colX] = NSToCoordRound(percent * (float)remainingWidth);
totalColWidth += colWidths[colX];
lastColAllocated = colX;
}
}
}
}
else { // allocate the extra space to the columns which have width specified
float divisor = (float)totalColWidth;
for (colX = 0; colX < mNumCols; colX++) {
if (colWidths[colX] > 0) {
nscoord colAlloc = NSToCoordRound(remainingWidth * colWidths[colX] / divisor);
colWidths[colX] += colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
else if (tableIsFixedWidth) {
if (mNumCols > specifiedCols) {
// allocate the extra space to the columns which have no width specified
nscoord colAlloc = NSToCoordRound( ((float)remainingWidth) / (((float)mNumCols) - ((float)specifiedCols)));
for (colX = 0; colX < mNumCols; colX++) {
if (-1 == colWidths[colX]) {
colWidths[colX] = colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
}
}
}
}
else { // allocate the extra space to the columns which have width specified
float divisor = (float)totalColWidth;
for (colX = 0; colX < mNumCols; colX++) {
if (colWidths[colX] > 0) {
nscoord colAlloc = NSToCoordRound(remainingWidth * colWidths[colX] / divisor);
colWidths[colX] += colAlloc;
totalColWidth += colAlloc;
lastColAllocated = colX;
}
}
}
}
}
nscoord overAllocation = (availWidth >= 0)
@ -179,6 +201,10 @@ PRBool FixedTableLayoutStrategy::AssignPreliminaryColumnWidths(nscoord aComputed
if (nsnull != colWidths) {
delete [] colWidths;
}
if (nsnull != propInfo) {
delete [] propInfo;
}
return PR_TRUE;
}