This commit is contained in:
evaughan%netscape.com 2001-10-19 20:47:36 +00:00
Родитель 5f0f71898c
Коммит 0ae5c59884
20 изменённых файлов: 1265 добавлений и 278 удалений

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

@ -44,6 +44,9 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= \
nsGridLayout2.cpp \
nsGridRowLayout.cpp \
nsGridRowLeafLayout.cpp \
nsGridRowLeafFrame.cpp \
nsGridRowGroupFrame.cpp \
nsGridRowLeaf.cpp \
nsGridRowGroupLayout.cpp \
nsGrid.cpp \
@ -55,6 +58,8 @@ CPP_OBJS= \
.\$(OBJDIR)\nsGridLayout2.obj \
.\$(OBJDIR)\nsGridRowLayout.obj \
.\$(OBJDIR)\nsGridRowLeafLayout.obj \
.\$(OBJDIR)\nsGridRowLeafFrame.obj \
.\$(OBJDIR)\nsGridRowGroupFrame.obj \
.\$(OBJDIR)\nsGridRowGroupLayout.obj \
.\$(OBJDIR)\nsGrid.obj \
.\$(OBJDIR)\nsGridRow.obj \
@ -75,6 +80,7 @@ LINCS= \
EXPORTS = nsGridLayout2.h \
nsGridRowLayout.h \
nsGridRowLeafLayout.h \
nsGridRowLeafFrame.h \
nsGridRowGroupLayout.h \
nsIGridPart.h \
nsGrid.h \

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

@ -105,9 +105,9 @@ example 3:
</grid>
The columns are first and the rows are second, so the rows will be drawn on top of the columns.
Usually the columns are first and the rows are second, so the rows will be drawn on top of the columns.
You can reverse this by defining the rows first.
Other tags are then placed in the <row> or <column> tags causing the grid to accommodate everyone.
Other tags are then placed in the <row> or <column> tags causing the grid to accommodate everyone.
It does this by creating 3 things: A cellmap, a row list, and a column list. The cellmap is a 2
dimensional array of nsGridCells. Each cell contains 2 boxes. One cell from the column list
and one from the row list. When a cell is asked for its size it returns that smallest size it can
@ -158,11 +158,10 @@ nsGrid::NeedsRebuild(nsBoxLayoutState& aState)
// iterate through columns and rows and dirty them
mNeedsRebuild = PR_TRUE;
// free the map
FreeMap();
// find the new row and column box. They could have
// been changed.
mRowBox = nsnull;
mColumnBox = nsnull;
FindRowsAndColumns(&mRowBox, &mColumnBox);
// tell all the rows and columns they are dirty
@ -171,90 +170,6 @@ nsGrid::NeedsRebuild(nsBoxLayoutState& aState)
}
/**
* Run through the rows in the given box and mark them dirty so they
* will get recalculated and get a layout.
*/
void
nsGrid::DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState)
{
// make sure we prevent others from dirtying things.
mMarkingDirty = PR_TRUE;
// if the box is a grid part have it recursively hand it.
if (aRowBox) {
nsCOMPtr<nsIBoxLayout> layout;
aRowBox->GetLayoutManager(getter_AddRefs(layout));
if (layout) {
nsCOMPtr<nsIGridPart> part( do_QueryInterface(layout) );
if (part)
part->DirtyRows(aRowBox, aState);
}
}
mMarkingDirty = PR_FALSE;
}
nsGridRow* nsGrid::GetColumns()
{
RebuildIfNeeded();
return mColumns;
}
nsGridRow* nsGrid::GetRows()
{
RebuildIfNeeded();
return mRows;
}
nsGridRow*
nsGrid::GetColumnAt(PRInt32 aIndex, PRBool aIsRow)
{
return GetRowAt(aIndex, !aIsRow);
}
nsGridRow*
nsGrid::GetRowAt(PRInt32 aIndex, PRBool aIsRow)
{
RebuildIfNeeded();
if (aIsRow) {
NS_ASSERTION(aIndex < mRowCount || aIndex >= 0, "Index out of range");
return &mRows[aIndex];
} else {
NS_ASSERTION(aIndex < mColumnCount || aIndex >= 0, "Index out of range");
return &mColumns[aIndex];
}
}
nsGridCell*
nsGrid::GetCellAt(PRInt32 aX, PRInt32 aY)
{
RebuildIfNeeded();
NS_ASSERTION(aY < mRowCount && aY >= 0, "Index out of range");
NS_ASSERTION(aX < mColumnCount && aX >= 0, "Index out of range");
return &mCellMap[aY*mColumnCount+aX];
}
PRInt32
nsGrid::GetExtraColumnCount(PRBool aIsRow)
{
return GetExtraRowCount(!aIsRow);
}
PRInt32
nsGrid::GetExtraRowCount(PRBool aIsRow)
{
RebuildIfNeeded();
if (aIsRow)
return mExtraRowCount;
else
return mExtraColumnCount;
}
/**
* If we are marked for rebuild. Then build everything
@ -273,8 +188,11 @@ nsGrid::RebuildIfNeeded()
// count the rows and columns
PRInt32 computedRowCount = 0;
PRInt32 computedColumnCount = 0;
CountRowsColumns(mRowBox, mRowCount, computedColumnCount);
CountRowsColumns(mColumnBox, mColumnCount, computedRowCount);
PRInt32 rowCount = 0;
PRInt32 columnCount = 0;
CountRowsColumns(mRowBox, rowCount, computedColumnCount);
CountRowsColumns(mColumnBox, columnCount, computedRowCount);
// computedRowCount are the actual number of rows as determined by the
// columns children.
@ -302,22 +220,25 @@ nsGrid::RebuildIfNeeded()
// So in this case we need to make 1 extra column.
//
if (computedColumnCount > mColumnCount) {
mExtraColumnCount = computedColumnCount - mColumnCount;
mColumnCount = computedColumnCount;
if (computedColumnCount > columnCount) {
mExtraColumnCount = computedColumnCount - columnCount;
columnCount = computedColumnCount;
}
if (computedRowCount > mRowCount) {
mExtraRowCount = computedRowCount - mRowCount;
mRowCount = computedRowCount;
if (computedRowCount > rowCount) {
mExtraRowCount = computedRowCount - rowCount;
rowCount = computedRowCount;
}
// build and poplulate row and columns arrays
BuildRows(mRowBox, mRowCount, &mRows, PR_TRUE);
BuildRows(mColumnBox, mColumnCount, &mColumns, PR_FALSE);
BuildRows(mRowBox, rowCount, &mRows, PR_TRUE);
BuildRows(mColumnBox, columnCount, &mColumns, PR_FALSE);
// build and populate the cell map
BuildCellMap(mRowCount, mColumnCount, &mCellMap);
BuildCellMap(rowCount, columnCount, &mCellMap);
mRowCount = rowCount;
mColumnCount = columnCount;
// populate the cell map from column and row children
PopulateCellMap(mRows, mColumns, mRowCount, mColumnCount, PR_TRUE);
@ -436,7 +357,31 @@ nsGrid::BuildRows(nsIBox* aBox, PRBool aRowCount, nsGridRow** aRows, PRBool aIsR
// create the array
PRInt32 count = 0;
nsGridRow* row = new nsGridRow[aRowCount];
nsGridRow* row;
// only create new rows if we have to. Reuse old rows.
if (aIsRow)
{
if (aRowCount > mRowCount) {
delete[] mRows;
row = new nsGridRow[aRowCount];
} else {
for (PRInt32 i=0; i < mRowCount; i++)
mRows[i].Init(nsnull, PR_FALSE);
row = mRows;
}
} else {
if (aRowCount > mColumnCount) {
delete[] mColumns;
row = new nsGridRow[aRowCount];
} else {
for (PRInt32 i=0; i < mColumnCount; i++)
mColumns[i].Init(nsnull, PR_FALSE);
row = mColumns;
}
}
// populate it if we can. If not it will contain only dynamic columns
if (aBox)
@ -463,10 +408,24 @@ void
nsGrid::BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells)
{
PRInt32 size = aRows*aColumns;
PRInt32 oldsize = mRowCount*mColumnCount;
if (size == 0)
(*aCells) = nsnull;
else
(*aCells) = new nsGridCell[size];
else {
if (size > oldsize) {
delete[] mCellMap;
(*aCells) = new nsGridCell[size];
} else {
// clear out cellmap
for (PRInt32 i=0; i < oldsize; i++)
{
mCellMap[i].SetBoxInRow(nsnull);
mCellMap[i].SetBoxInColumn(nsnull);
}
(*aCells) = mCellMap;
}
}
}
/**
@ -520,6 +479,92 @@ nsGrid::PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount
}
}
/**
* Run through the rows in the given box and mark them dirty so they
* will get recalculated and get a layout.
*/
void
nsGrid::DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState)
{
// make sure we prevent others from dirtying things.
mMarkingDirty = PR_TRUE;
// if the box is a grid part have it recursively hand it.
if (aRowBox) {
nsCOMPtr<nsIBoxLayout> layout;
aRowBox->GetLayoutManager(getter_AddRefs(layout));
if (layout) {
nsCOMPtr<nsIGridPart> part( do_QueryInterface(layout) );
if (part)
part->DirtyRows(aRowBox, aState);
}
}
mMarkingDirty = PR_FALSE;
}
nsGridRow* nsGrid::GetColumns()
{
RebuildIfNeeded();
return mColumns;
}
nsGridRow* nsGrid::GetRows()
{
RebuildIfNeeded();
return mRows;
}
nsGridRow*
nsGrid::GetColumnAt(PRInt32 aIndex, PRBool aIsRow)
{
return GetRowAt(aIndex, !aIsRow);
}
nsGridRow*
nsGrid::GetRowAt(PRInt32 aIndex, PRBool aIsRow)
{
RebuildIfNeeded();
if (aIsRow) {
NS_ASSERTION(aIndex < mRowCount || aIndex >= 0, "Index out of range");
return &mRows[aIndex];
} else {
NS_ASSERTION(aIndex < mColumnCount || aIndex >= 0, "Index out of range");
return &mColumns[aIndex];
}
}
nsGridCell*
nsGrid::GetCellAt(PRInt32 aX, PRInt32 aY)
{
RebuildIfNeeded();
NS_ASSERTION(aY < mRowCount && aY >= 0, "Index out of range");
NS_ASSERTION(aX < mColumnCount && aX >= 0, "Index out of range");
return &mCellMap[aY*mColumnCount+aX];
}
PRInt32
nsGrid::GetExtraColumnCount(PRBool aIsRow)
{
return GetExtraRowCount(!aIsRow);
}
PRInt32
nsGrid::GetExtraRowCount(PRBool aIsRow)
{
RebuildIfNeeded();
if (aIsRow)
return mExtraRowCount;
else
return mExtraColumnCount;
}
/**
* These methods return the preferred, min, max sizes for a given row index.
* aIsRow if aIsRow is PR_TRUE. If you pass PR_FALSE you will get the inverse.
@ -528,9 +573,9 @@ nsGrid::PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount
nsresult
nsGrid::GetPrefRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
{
//NS_ASSERTION(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow), "Row index out of range!");
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
return NS_OK;
NS_ASSERTION(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow), "Row index out of range!");
//if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
// return NS_OK;
nscoord height = 0;
GetPrefRowHeight(aState, aRowIndex, height, aIsRow);
@ -542,8 +587,10 @@ nsGrid::GetPrefRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSiz
nsresult
nsGrid::GetMinRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
{
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
return NS_OK;
NS_ASSERTION(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow), "Row index out of range!");
// if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
// return NS_OK;
nscoord height = 0;
GetMinRowHeight(aState, aRowIndex, height, aIsRow);
@ -555,8 +602,10 @@ nsGrid::GetMinRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize
nsresult
nsGrid::GetMaxRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
{
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
return NS_OK;
NS_ASSERTION(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow), "Row index out of range!");
// if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
// return NS_OK;
nscoord height = 0;
GetMaxRowHeight(aState, aRowIndex, height, aIsRow);
@ -565,6 +614,205 @@ nsGrid::GetMaxRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize
return NS_OK;
}
void
nsGrid::GetPartFromBox(nsIBox* aBox, nsIGridPart** aPart)
{
*aPart = nsnull;
if (aBox) {
nsCOMPtr<nsIBoxLayout> layout;
aBox->GetLayoutManager(getter_AddRefs(layout));
if (layout) {
nsCOMPtr<nsIGridPart> part( do_QueryInterface(layout) );
if (part) {
*aPart = part.get();
NS_IF_ADDREF(*aPart);
}
}
}
}
void
nsGrid::GetBoxTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow)
{
// walk the boxes parent chain getting the border/padding/margin of our parent rows
// first get the layour manager
nsCOMPtr<nsIGridPart> part;
nsCOMPtr<nsIGridPart> parent;
GetPartFromBox(aBox, getter_AddRefs(part));
if (part)
part->GetTotalMargin(aBox, aMargin, aIsRow);
}
/**
* A row can have a top and bottom offset. Usually this is just the top and bottom border/padding.
* However if the row is the first or last it could be affected by the fact a column or columns could
* have a top or bottom margin.
*/
void
nsGrid::GetRowOffsets(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aTop, nscoord& aBottom, PRBool aIsRow)
{
RebuildIfNeeded();
nsGridRow* row = GetRowAt(aIndex, aIsRow);
if (row->IsOffsetSet())
{
aTop = row->mTop;
aBottom = row->mBottom;
return;
}
PRInt32 lastRow = GetRowCount(aIsRow)-1;
// first get the rows top and bottom border and padding
nsIBox* box = row->GetBox();
// add up all the padding
nsMargin margin(0,0,0,0);
nsMargin inset(0,0,0,0);
nsMargin border(0,0,0,0);
nsMargin padding(0,0,0,0);
nsMargin totalBorderPadding(0,0,0,0);
nsMargin totalMargin(0,0,0,0);
// if there is a box and its not bogus take its
// borders padding and insets into account
if (box && !row->mIsBogus)
{
box->GetInset(inset);
// get real border and padding. GetBorderAndPadding
// is redefined on nsGridRowLeafFrame. If we called it here
// we would be in finite recurson.
box->GetBorder(border);
box->GetPadding(padding);
totalBorderPadding += inset;
totalBorderPadding += border;
totalBorderPadding += padding;
box->GetMargin(margin);
// if we are the first or last row
// take into account <rows> tags around us
// that could have borders or margins.
// fortunately they only affect the first
// and last row inside the <rows> tag
GetBoxTotalMargin(box, margin, aIsRow);
totalMargin = margin;
}
if (aIsRow) {
row->mTop = totalBorderPadding.top;
row->mBottom = totalBorderPadding.bottom;
row->mTopMargin = totalMargin.top;
row->mBottomMargin = totalMargin.bottom;
} else {
row->mTop = totalBorderPadding.left;
row->mBottom = totalBorderPadding.right;
row->mTopMargin = totalMargin.left;
row->mBottomMargin = totalMargin.right;
}
// if we are the first or last row take into account the top and bottom borders
// of each columns.
// If we are the first row then get the largest top border/padding in
// our columns. If thats larger than the rows top border/padding use it.
// If we are the last row then get the largest bottom border/padding in
// our columns. If thats larger than the rows bottom border/padding use it.
if (lastRow >= 0 && (aIndex == 0 || aIndex == lastRow)) {
nscoord maxTop = 0;
nscoord maxBottom = 0;
// run through the columns. Look at each column
// pick the largest top border or bottom border
PRInt32 count = GetColumnCount(aIsRow);
PRBool isCollapsed = PR_FALSE;
for (PRInt32 i=0; i < count; i++)
{
nsMargin totalChildBorderPadding(0,0,0,0);
nsGridRow* column = GetColumnAt(i,aIsRow);
nsIBox* box = column->GetBox();
if (box)
{
// ignore collapsed children
box->IsCollapsed(aState, isCollapsed);
if (!isCollapsed)
{
// include the margin of the columns. To the row
// at this point border/padding and margins all added
// up to more needed space.
GetBoxTotalMargin(box, margin, !aIsRow);
box->GetInset(inset);
// get real border and padding. GetBorderAndPadding
// is redefined on nsGridRowLeafFrame. If we called it here
// we would be in finite recurson.
box->GetBorder(border);
box->GetPadding(padding);
totalChildBorderPadding += inset;
totalChildBorderPadding += border;
totalChildBorderPadding += padding;
totalChildBorderPadding += margin;
}
nscoord top;
nscoord bottom;
// pick the largest top margin
if (aIndex == 0) {
if (aIsRow) {
top = totalChildBorderPadding.top;
} else {
top = totalChildBorderPadding.left;
}
if (top > maxTop)
maxTop = top;
}
// pick the largest bottom margin
if (aIndex == lastRow) {
if (aIsRow) {
bottom = totalChildBorderPadding.bottom;
} else {
bottom = totalChildBorderPadding.right;
}
if (bottom > maxBottom)
maxBottom = bottom;
}
}
// If the biggest top border/padding the columns is larger than this rows top border/padding
// the use it.
if (aIndex == 0) {
if (maxTop > (row->mTop + row->mTopMargin))
row->mTop = maxTop - row->mTopMargin;
}
// If the biggest bottom border/padding the columns is larger than this rows bottom border/padding
// the use it.
if (aIndex == lastRow) {
if (maxBottom > (row->mBottom + row->mBottomMargin))
row->mBottom = maxBottom - row->mBottomMargin;
}
}
}
aTop = row->mTop;
aBottom = row->mBottom;
}
/**
* These methods return the preferred, min, max coord for a given row index if
* aIsRow is PR_TRUE. If you pass PR_FALSE you will get the inverse.
@ -591,8 +839,6 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSiz
cssSize.width = -1;
cssSize.height = -1;
nsIBox::AddCSSPrefSize(aState, box, cssSize);
// TBD subtract our borders and padding place them in
// left and right padding
row->mPref = GET_HEIGHT(cssSize, aIsRow);
@ -604,6 +850,12 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSiz
}
}
// get the offsets so they are cached.
nscoord top;
nscoord bottom;
GetRowOffsets(aState, aIndex, top, bottom, aIsRow);
// is the row bogus? If so then just ask it for its size
// it should not be affected by cells in the grid.
if (row->mIsBogus)
@ -650,7 +902,8 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSiz
}
}
row->mPref = GET_HEIGHT(size, aIsRow);
row->mPref = GET_HEIGHT(size, aIsRow) + top + bottom;
aSize = row->mPref;
@ -678,8 +931,6 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
cssSize.width = -1;
cssSize.height = -1;
nsIBox::AddCSSMinSize(aState, box, cssSize);
// TBD subtract our borders and padding place them in
// left and right padding
row->mMin = GET_HEIGHT(cssSize, aIsRow);
@ -691,6 +942,11 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
}
}
// get the offsets so they are cached.
nscoord top;
nscoord bottom;
GetRowOffsets(aState, aIndex, top, bottom, aIsRow);
// is the row bogus? If so then just ask it for its size
// it should not be affected by cells in the grid.
if (row->mIsBogus)
@ -703,7 +959,7 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
nsStackLayout::AddOffset(aState, box, size);
}
row->mMin = GET_HEIGHT(size, aIsRow);
row->mMin = GET_HEIGHT(size, aIsRow) + top + bottom;
aSize = row->mMin;
return NS_OK;
@ -765,9 +1021,7 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
cssSize.width = -1;
cssSize.height = -1;
nsIBox::AddCSSMaxSize(aState, box, cssSize);
// TBD subtract our borders and padding place them in
// left and right padding
row->mMax = GET_HEIGHT(cssSize, aIsRow);
// yep do nothing.
@ -778,7 +1032,12 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
}
}
// is the row bogus? If so then just ask it for its size
// get the offsets so they are cached.
nscoord top;
nscoord bottom;
GetRowOffsets(aState, aIndex, top, bottom, aIsRow);
// is the row bogus? If so then just ask it for its size
// it should not be affected by cells in the grid.
if (row->mIsBogus)
{
@ -824,13 +1083,38 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize
}
}
row->mMax = GET_HEIGHT(size, aIsRow);
row->mMax = GET_HEIGHT(size, aIsRow) + top + bottom;
aSize = row->mMax;
return NS_OK;
}
PRBool
nsGrid::IsGrid(nsIBox* aBox)
{
if (!aBox)
return PR_FALSE;
nsCOMPtr<nsIGridPart> part;
GetPartFromBox(aBox, getter_AddRefs(part));
if (!part)
return PR_FALSE;
nsGridLayout2* grid = nsnull;
part->CastToGridLayout(&grid);
if (grid)
return PR_TRUE;
return PR_FALSE;
}
/**
* This get the flexibilty of the row at aIndex. Its not trivial. There are a few
* things we need to look at. Specifically we need to see if any <rows> or <columns>
* tags are around us. Their flexibilty will affect ours.
*/
nsresult
nsGrid::GetRowFlex(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aFlex, PRBool aIsRow)
{
@ -848,10 +1132,88 @@ nsGrid::GetRowFlex(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aFlex, PRB
row->mFlex = 0;
if (box) {
// We need our flex but a inflexible row could be around us. If so
// neither are we. However if its the row tag just inside the grid it won't
// affect us. We need to do this for this case:
// <grid>
// <rows>
// <rows> // this is not flexible. So our children should not be flexible
// <row flex="1"/>
// <row flex="1"/>
// </rows>
// <row/>
// </rows>
// </grid>
//
// or..
//
// <grid>
// <rows>
// <rows> // this is not flexible. So our children should not be flexible
// <rows flex="1">
// <row flex="1"/>
// <row flex="1"/>
// </rows>
// <row/>
// </rows>
// </row>
// </grid>
// So here is how it looks
//
// <grid>
// <rows> // parentsParent
// <rows> // parent
// <row flex="1"/>
// <row flex="1"/>
// </rows>
// <row/>
// </rows>
// </grid>
// so the answer is simple: 1) Walk our parent chain. 2) If we find
// someone who is not flexible and they aren't the rows immediately in
// the grid. 3) Then we are not flexible
nsIBox* parent=nsnull;
nsIBox* parentsParent=nsnull;
box = GetScrollBox(box);
box->GetParentBox(&parent);
while(parent)
{
parent = GetScrollBox(parent);
parent->GetParentBox(&parentsParent);
// if our parents parent is not a grid
// the get its flex. If its 0 then we are
// not flexible.
if (parentsParent) {
if (!IsGrid(parentsParent)) {
PRInt32 flex = 0;
parent->GetFlex(aState, flex);
nsIBox::AddCSSFlex(aState, parent, flex);
if (flex == 0) {
row->mFlex = 0;
aFlex = 0;
return NS_OK;
}
} else
break;
}
parent = parentsParent;
}
// get the row flex.
box->GetFlex(aState, row->mFlex);
nsIBox::AddCSSFlex(aState, box, row->mFlex);
}
aFlex = row->mFlex;
return NS_OK;
@ -918,7 +1280,7 @@ nsGrid::RowChildIsDirty(nsBoxLayoutState& aState, PRInt32 aRowIndex, PRInt32 aCo
return;
}
// dirty our 2 outer nsGridRowGroups. (one for columns and one for rows)
// dirty our 2 outer nsGridRows. (one for columns and one for rows)
// we need to do this because the rows and column we are given may be Extra ones
// and may not have any Box associated with them. If you dirtied them then
// corresponding nsGridRowGroup around them would never get dirty. So lets just
@ -955,13 +1317,14 @@ nsGrid::RowIsDirty(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
}
/*
* a Cell in the given row or columns at the given index has had a child added or removed
* A cell in the given row or columns at the given index has had a child added or removed
*/
void
nsGrid::CellAddedOrRemoved(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
{
// see if the cell will fit in our current row. If it will
// just add it. If not rebuild everything.
// TBD see if the cell will fit in our current row. If it will
// just add it in.
// but for now rebuild everything.
if (mMarkingDirty)
return;
@ -974,13 +1337,72 @@ nsGrid::CellAddedOrRemoved(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsR
void
nsGrid::RowAddedOrRemoved(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
{
// see if we have extra room in the table and just add the new row in
// TBD see if we have extra room in the table and just add the new row in
// for now rebuild the world
if (mMarkingDirty)
return;
NeedsRebuild(aState);
}
/*
* Scrollframes are tranparent. If this is given a scrollframe is will return the
* frame inside. If there is no scrollframe it does nothing.
*/
nsIBox*
nsGrid::GetScrolledBox(nsIBox* aChild)
{
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(aChild);
if (scrollFrame) {
nsIFrame* scrolledFrame = nsnull;
scrollFrame->GetScrolledFrame(nsnull, scrolledFrame);
NS_ASSERTION(scrolledFrame,"Error no scroll frame!!");
nsCOMPtr<nsIBox> box = do_QueryInterface(scrolledFrame);
return box;
}
return aChild;
}
/*
* Scrollframes are tranparent. If this is given a child in a scrollframe is will return the
* scrollframe ourside it. If there is no scrollframe it does nothing.
*/
nsIBox*
nsGrid::GetScrollBox(nsIBox* aChild)
{
// get parent
nsIBox* parent = nsnull;
nsCOMPtr<nsIBoxLayout> layout;
nsCOMPtr<nsIGridPart> parentGridRow;
aChild->GetParentBox(&parent);
// walk up until we find a scrollframe or a part
// if its a scrollframe return it.
// if its a parent then the child passed does not
// have a scroll frame immediately wrapped around it.
while (parent) {
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(parent);
// scrollframe? Yep return it.
if (scrollFrame)
return parent;
parent->GetLayoutManager(getter_AddRefs(layout));
parentGridRow = do_QueryInterface(layout);
// if a part then just return the child
if (parentGridRow)
break;
parent->GetParentBox(&parent);
}
return aChild;
}
#ifdef DEBUG_grid
void
nsGrid::PrintCellMap()
@ -1002,19 +1424,6 @@ nsGrid::PrintCellMap()
}
printf("\n");
/*
printf("-----CellMap------\n");
for (int y=0; y < mRowCount; y++)
{
for (int x=0; x < mColumnCount; x++)
{
nsGridCell* cell = GetCellAt(x,y);
//printf("(%d)@%p[@%p,@%p] ", y*mColumnCount+x, cell, cell->GetBoxInRow(), cell->GetBoxInColumn());
printf("p=%d, ", y*mColumnCount+x, cell, cell->GetBoxInRow(), cell->GetBoxInColumn());
}
printf("\n");
}
*/
}
#endif

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

@ -54,57 +54,66 @@ class nsGridRowLayout;
class nsBoxLayoutState;
class nsGridCell;
//#define DEBUG_grid 1
class nsGrid
{
public:
nsGrid();
~nsGrid();
virtual void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
virtual nsGridRow* GetColumnAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
virtual nsGridRow* GetRowAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
virtual nsGridCell* GetCellAt(PRInt32 aX, PRInt32 aY);
virtual void RebuildIfNeeded();
nsGridRow* GetColumnAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
nsGridRow* GetRowAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
nsGridCell* GetCellAt(PRInt32 aX, PRInt32 aY);
virtual nsresult GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
virtual nsresult GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
virtual nsresult GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
virtual nsresult GetRowFlex(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aSize, PRBool aIsRow = PR_TRUE);
void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
void RebuildIfNeeded();
virtual nsresult GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
virtual nsresult GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
virtual nsresult GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
nsresult GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
nsresult GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
nsresult GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow = PR_TRUE);
nsresult GetRowFlex(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aSize, PRBool aIsRow = PR_TRUE);
virtual void RowChildIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, PRInt32 aColumnIndex, PRBool aIsRow = PR_TRUE);
virtual void RowIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
virtual void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
virtual void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
virtual void DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState);
nsresult GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
nsresult GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
nsresult GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
void GetRowOffsets(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aTop, nscoord& aBottom, PRBool aIsRow = PR_TRUE);
void RowChildIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, PRInt32 aColumnIndex, PRBool aIsRow = PR_TRUE);
void RowIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
void DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState);
#ifdef DEBUG_grid
virtual void PrintCellMap();
void PrintCellMap();
#endif
virtual PRInt32 GetExtraColumnCount(PRBool aIsRow = PR_TRUE);
virtual PRInt32 GetExtraRowCount(PRBool aIsRow = PR_TRUE);
PRInt32 GetExtraColumnCount(PRBool aIsRow = PR_TRUE);
PRInt32 GetExtraRowCount(PRBool aIsRow = PR_TRUE);
// accessors
virtual void SetBox(nsIBox* aBox) { mBox = aBox; }
virtual nsIBox* GetBox() { return mBox; }
virtual nsGridRow* GetColumns();
virtual nsGridRow* GetRows();
virtual PRInt32 GetRowCount(PRInt32 aIsRow);
virtual PRInt32 GetColumnCount(PRInt32 aIsRow);
void SetBox(nsIBox* aBox) { mBox = aBox; }
nsIBox* GetBox() { return mBox; }
nsGridRow* GetColumns();
nsGridRow* GetRows();
PRInt32 GetRowCount(PRInt32 aIsRow = PR_TRUE);
PRInt32 GetColumnCount(PRInt32 aIsRow = PR_TRUE);
protected:
virtual void FreeMap();
virtual void FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns);
virtual void BuildRows(nsIBox* aBox, PRBool aSize, nsGridRow** aColumnsRows, PRBool aIsRow = PR_TRUE);
virtual void BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells);
virtual void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, PRBool aIsRow = PR_TRUE);
virtual void CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
virtual void SetLargestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow = PR_TRUE);
virtual void SetSmallestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow = PR_TRUE);
static nsIBox* GetScrolledBox(nsIBox* aChild);
static nsIBox* GetScrollBox(nsIBox* aChild);
private:
void GetPartFromBox(nsIBox* aBox, nsIGridPart** aPart);
void GetBoxTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow = PR_TRUE);
void FreeMap();
void FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns);
void BuildRows(nsIBox* aBox, PRBool aSize, nsGridRow** aColumnsRows, PRBool aIsRow = PR_TRUE);
void BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells);
void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, PRBool aIsRow = PR_TRUE);
void CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
void SetLargestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow = PR_TRUE);
void SetSmallestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow = PR_TRUE);
PRBool IsGrid(nsIBox* aBox);
// the box that implement the <grid> tag
nsIBox* mBox;

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

@ -131,8 +131,8 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState, nsSize& aMax)
aMax.height = NS_INTRINSICSIZE;
// take ours 2 children and add them up.
// we are as wide as the widest child plus its left offset
// we are tall as the tallest child plus its top offset
// we are as wide as the smallest child plus its left offset
// we are tall as the shortest child plus its top offset
nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE);

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

@ -51,22 +51,30 @@ class nsBoxLayoutState;
struct nsSize;
class nsIBox;
/*
* Grid cell is what makes up the cellmap in the grid. Each GridCell contains
* 2 pointers. One to the matching box in the columns and one to the matching box
* in the rows. Remember that you can put content in both rows and columns.
* When asked for preferred/min/max sizes it works like a stack and takes the
* biggest sizes.
*/
class nsGridCell
{
public:
nsGridCell();
virtual ~nsGridCell();
virtual nsresult GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aPref);
virtual nsresult GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMin);
virtual nsresult GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMax);
virtual nsresult IsCollapsed(nsBoxLayoutState& aBoxLayoutState, PRBool& aIsCollapsed);
nsresult GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aPref);
nsresult GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMin);
nsresult GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMax);
nsresult IsCollapsed(nsBoxLayoutState& aBoxLayoutState, PRBool& aIsCollapsed);
// accessors
virtual nsIBox* GetBoxInColumn() { return mBoxInColumn; }
virtual nsIBox* GetBoxInRow() { return mBoxInRow; }
virtual void SetBoxInRow(nsIBox* aBox) { mBoxInRow = aBox; }
virtual void SetBoxInColumn(nsIBox* aBox) { mBoxInColumn = aBox; }
nsIBox* GetBoxInColumn() { return mBoxInColumn; }
nsIBox* GetBoxInRow() { return mBoxInRow; }
void SetBoxInRow(nsIBox* aBox) { mBoxInRow = aBox; }
void SetBoxInColumn(nsIBox* aBox) { mBoxInColumn = aBox; }
private:
nsIBox* mBoxInColumn;

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

@ -82,7 +82,7 @@ nsGridLayout2::GetGrid(nsIBox* aBox, nsGrid** aGrid, PRInt32* aIndex, nsGridRowL
}
NS_IMETHODIMP
nsGridLayout2::GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow)
nsGridLayout2::GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridRow)
{
NS_ERROR("Should not be called");
return NS_ERROR_FAILURE;
@ -141,6 +141,25 @@ nsGridLayout2::CastToGridLayout(nsGridLayout2** aGridLayout)
return NS_OK;
}
NS_IMETHODIMP
nsGridLayout2::GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow)
{
aMargin.left = 0;
aMargin.right = 0;
aMargin.top = 0;
aMargin.bottom = 0;
return NS_OK;
}
NS_IMETHODIMP
nsGridLayout2::GetRowCount(PRInt32& aRowCount)
{
NS_ERROR("Should not be called");
return NS_OK;
}
NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout);
NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout);

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

@ -70,13 +70,15 @@ public:
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup);
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid);
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull);
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridPart);
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridPart);
NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
NS_IMETHOD GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow);
NS_IMETHOD GetRowCount(PRInt32& aRowCount);
protected:
nsGridLayout2(nsIPresShell* aShell);

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

@ -50,7 +50,11 @@ nsGridRow::nsGridRow():mBox(nsnull),
mFlex(-1),
mPref(-1),
mMin(-1),
mMax(-1)
mMax(-1),
mTop(-1),
mBottom(-1),
mTopMargin(0),
mBottomMargin(0)
{
MOZ_COUNT_CTOR(nsGridRow);
@ -61,6 +65,14 @@ nsGridRow::Init(nsIBox* aBox, PRBool aIsBogus)
{
mBox = aBox;
mIsBogus = aIsBogus;
mFlex = -1;
mPref = -1;
mMin = -1;
mMax = -1;
mTop = -1;
mBottom = -1;
mTopMargin = 0;
mBottomMargin = 0;
}
nsGridRow::~nsGridRow()
@ -74,6 +86,9 @@ nsGridRow::MarkDirty(nsBoxLayoutState& aState)
mPref = -1;
mMin = -1;
mMax = -1;
mFlex = -1;
mTop = -1;
mBottom = -1;
if (mBox)
mBox->MarkDirty(aState);

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

@ -66,6 +66,7 @@ public:
virtual PRBool IsMinSet() { return (mMin != -1); }
virtual PRBool IsMaxSet() { return (mMax != -1); }
virtual PRBool IsFlexSet() { return (mFlex != -1); }
virtual PRBool IsOffsetSet() { return (mTop != -1 && mBottom != -1); }
public:
@ -75,6 +76,11 @@ public:
nscoord mPref;
nscoord mMin;
nscoord mMax;
nscoord mTop;
nscoord mBottom;
nscoord mTopMargin;
nscoord mBottomMargin;
};

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

@ -0,0 +1,113 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsGridRowGroupFrame.h"
#include "nsGridRowLeafLayout.h"
#include "nsGridRow.h"
#include "nsBoxLayoutState.h"
#include "nsGridLayout2.h"
nsresult
NS_NewGridRowGroupFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsGridRowGroupFrame* it = new (aPresShell) nsGridRowGroupFrame (aPresShell, aIsRoot, aLayoutManager);
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
nsGridRowGroupFrame::nsGridRowGroupFrame(nsIPresShell* aPresShell, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
:nsBoxFrame(aPresShell, aIsRoot, aLayoutManager)
{
}
/**
* This is redefined because row groups have a funny property. If they are flexible
* then their flex must be equal to the sum of their children's flexes.
*/
NS_IMETHODIMP
nsGridRowGroupFrame::GetFlex(nsBoxLayoutState& aState, nscoord& aFlex)
{
// if we are flexible out flexibility is determined by our columns.
// so first get the our flex. If not 0 then our flex is the sum of
// our columns flexes.
if (!DoesNeedRecalc(mFlex)) {
aFlex = mFlex;
return NS_OK;
}
nsBoxFrame::GetFlex(aState, aFlex);
if (aFlex == 0)
return NS_OK;
// ok we are flexible add up our children
nscoord totalFlex = 0;
nsIBox* child = nsnull;
GetChildBox(&child);
while (child)
{
PRInt32 flex = 0;
child->GetFlex(aState, flex);
totalFlex += flex;;
child->GetNextBox(&child);
}
aFlex = totalFlex;
mFlex = aFlex;
return NS_OK;
}

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

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
Eric D Vaughan
A frame that can have multiple children. Only one child may be displayed at one time. So the
can be flipped though like a deck of cards.
**/
#ifndef nsGridRowGroupFrame_h___
#define nsGridRowGroupFrame_h___
#include "nsBoxFrame.h"
class nsGridRowGroupFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewGridRowGroupFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager);
#ifdef NS_DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const
{
return MakeFrameName("nsGridRowGroup", aResult);
}
#endif
nsGridRowGroupFrame(nsIPresShell* aPresShell, PRBool aIsRoot, nsIBoxLayout* aLayoutManager);
NS_IMETHOD GetFlex(nsBoxLayoutState& aBoxLayoutState, nscoord& aFlex);
}; // class nsGridRowGroupFrame
#endif

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

@ -65,7 +65,7 @@ NS_NewGridRowGroupLayout( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout)
}
nsGridRowGroupLayout::nsGridRowGroupLayout(nsIPresShell* aPresShell):nsGridRowLayout(aPresShell)
nsGridRowGroupLayout::nsGridRowGroupLayout(nsIPresShell* aPresShell):nsGridRowLayout(aPresShell), mRowCount(0)
{
}
@ -190,32 +190,6 @@ nsGridRowGroupLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize&
return rv;
}
NS_IMETHODIMP
nsGridRowGroupLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
{
return nsGridRowLayout::Layout(aBox, aBoxLayoutState);
}
/*
* Scrollframes are tranparent. We should always walk down into them.
*/
nsIBox*
nsGridRowGroupLayout::CheckForScrollFrame(nsIBox* aChild)
{
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(aChild);
if (scrollFrame) {
nsIFrame* scrolledFrame = nsnull;
scrollFrame->GetScrolledFrame(nsnull, scrolledFrame);
NS_ASSERTION(scrolledFrame,"Error no scroll frame!!");
nsCOMPtr<nsIBox> box = do_QueryInterface(scrolledFrame);
return box;
}
return aChild;
}
/*
* Run down through our children dirtying them recursively.
*/
@ -233,7 +207,7 @@ nsGridRowGroupLayout::DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)
while(child) {
// walk into scrollframes
deepChild = CheckForScrollFrame(child);
deepChild = nsGrid::GetScrolledBox(child);
// walk into other monuments
nsCOMPtr<nsIBoxLayout> layout;
@ -257,6 +231,8 @@ NS_IMETHODIMP
nsGridRowGroupLayout::CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
{
if (aBox) {
PRInt32 startCount = aRowCount;
nsIBox* child = nsnull;
aBox->GetChildBox(&child);
nsIBox* deepChild = child;
@ -265,7 +241,7 @@ nsGridRowGroupLayout::CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32
while(child) {
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
deepChild = CheckForScrollFrame(child);
deepChild = nsGrid::GetScrolledBox(child);
nsCOMPtr<nsIBoxLayout> layout;
deepChild->GetLayoutManager(getter_AddRefs(layout));
@ -285,11 +261,20 @@ nsGridRowGroupLayout::CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32
// if not a monument. Then count it. It will be a bogus row
aRowCount++;
}
mRowCount = aRowCount - startCount;
}
return NS_OK;
}
NS_IMETHODIMP
nsGridRowGroupLayout::GetRowCount(PRInt32& aRowCount)
{
aRowCount = mRowCount;
return NS_OK;
}
/**
* Fill out the given row structure recursively
@ -307,7 +292,7 @@ nsGridRowGroupLayout::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
while(child) {
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
deepChild = CheckForScrollFrame(child);
deepChild = nsGrid::GetScrolledBox(child);
nsCOMPtr<nsIBoxLayout> layout;
deepChild->GetLayoutManager(getter_AddRefs(layout));
@ -345,4 +330,27 @@ nsGridRowGroupLayout::CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)
return NS_OK;
}
NS_IMETHODIMP
nsGridRowGroupLayout::GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow)
{
// group have border and padding added to the total margin
nsresult rv = nsGridRowLayout::GetTotalMargin(aBox, aMargin, aIsRow);
// make sure we have the scrollframe on the outside if it has one.
// thats where the border it.
aBox = nsGrid::GetScrollBox(aBox);
// add our border/padding to it
nsMargin borderPadding(0,0,0,0);
aBox->GetBorderAndPadding(borderPadding);
aMargin += borderPadding;
aBox->GetInset(borderPadding);
aMargin += borderPadding;
return rv;
}

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

@ -57,21 +57,22 @@ public:
NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
NS_IMETHOD GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow);
NS_IMETHOD GetRowCount(PRInt32& aRowCount);
protected:
nsGridRowGroupLayout(nsIPresShell* aShell);
virtual ~nsGridRowGroupLayout();
NS_IMETHOD ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState);
virtual nsIBox* CheckForScrollFrame(nsIBox* aChild);
virtual void AddWidth(nsSize& aSize, nscoord aSize2, PRBool aIsRow);
static void AddWidth(nsSize& aSize, nscoord aSize2, PRBool aIsRow);
private:
nsGridRow* mRowColumn;
PRInt32 mRowCount;
};
#endif

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

@ -48,6 +48,7 @@
#include "nsIScrollableFrame.h"
#include "nsBox.h"
#include "nsStackLayout.h"
#include "nsGrid.h"
nsGridRowLayout::nsGridRowLayout(nsIPresShell* aPresShell):nsSprocketLayout()
{
@ -78,7 +79,7 @@ nsGridRowLayout::ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aCh
}
NS_IMETHODIMP
nsGridRowLayout::GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridPart)
nsGridRowLayout::GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridPart)
{
// go up and find our parent gridRow. Skip and non gridRow
// parents.
@ -86,22 +87,26 @@ nsGridRowLayout::GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, n
nsCOMPtr<nsIGridPart> parentGridRow;
nsresult rv = NS_OK;
*aParentGridPart = nsnull;
aBox->GetParentBox(&aBox);
while (aBox) {
aBox->GetLayoutManager(getter_AddRefs(layout));
parentGridRow = do_QueryInterface(layout, &rv);
if (NS_SUCCEEDED(rv) && parentGridRow) {
aParentBox = aBox;
// walk up through any scrollboxes
aBox = nsGrid::GetScrollBox(aBox);
// get the parent
aBox->GetParentBox(&aBox);
if (aBox)
{
aBox->GetLayoutManager(getter_AddRefs(layout));
parentGridRow = do_QueryInterface(layout);
*aParentGridPart = parentGridRow.get();
*aParentBox = aBox;
NS_IF_ADDREF(*aParentGridPart);
return rv;
}
aBox->GetParentBox(&aBox);
return NS_OK;
}
aParentBox = nsnull;
*aParentGridPart = nsnull;
*aParentBox = nsnull;
return rv;
}
@ -113,8 +118,8 @@ nsGridRowLayout::GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRo
if (aRequestor == nsnull)
{
nsCOMPtr<nsIGridPart> parent;
nsCOMPtr<nsIBox> parentBox;
GetParentGridPart(aBox, parentBox, getter_AddRefs(parent));
nsIBox* parentBox; // nsIBox is implemented by nsIFrame and is not refcounted.
GetParentGridPart(aBox, &parentBox, getter_AddRefs(parent));
if (parent)
return parent->GetGrid(parentBox, aList, aIndex, this);
else
@ -130,15 +135,7 @@ nsGridRowLayout::GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRo
while(child)
{
// if there is a scrollframe walk inside it to its child
nsCOMPtr<nsIBox> childBox = child;
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(child, &rv);
if (scrollFrame) {
nsIFrame* childFrame = nsnull;
scrollFrame->GetScrolledFrame(nsnull, childFrame);
if (!childFrame)
return NS_ERROR_FAILURE;
childBox = do_QueryInterface(childFrame);
}
nsIBox* childBox = nsGrid::GetScrolledBox(child);
nsCOMPtr<nsIBoxLayout> layout;
childBox->GetLayoutManager(getter_AddRefs(layout));
@ -151,10 +148,13 @@ nsGridRowLayout::GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRo
index = count;
break;
}
}
// add the index.
count++;
PRInt32 c = 0;
gridRow->GetRowCount(c);
count += c;
} else
count++;
child->GetNextBox(&child);
}
@ -170,8 +170,8 @@ nsGridRowLayout::GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRo
(*aIndex) += index;
nsCOMPtr<nsIGridPart> parent;
nsCOMPtr<nsIBox> parentBox;
GetParentGridPart(aBox, parentBox, getter_AddRefs(parent));
nsIBox* parentBox; // nsIBox is implemented by nsIFrame and is not refcounted.
GetParentGridPart(aBox, &parentBox, getter_AddRefs(parent));
if (parent)
parent->GetGrid(parentBox, aList, aIndex, this);
@ -193,6 +193,67 @@ nsGridRowLayout::CastToGridLayout(nsGridLayout2** aGridLayout)
return NS_OK;
}
NS_IMETHODIMP
nsGridRowLayout::GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow)
{
// get our parents margin
nsMargin margin(0,0,0,0);
nsCOMPtr<nsIGridPart> part;
nsIBox* parent = nsnull;
GetParentGridPart(aBox, &parent, getter_AddRefs(part));
if (part && parent) {
// if we are the first or last child walk upward and add margins.
nsIBox* next = nsnull;
nsIBox* child = nsnull;
// make sure we check for a scrollbox
aBox = nsGrid::GetScrollBox(aBox);
// see if we have a next to see if we are last
aBox->GetNextBox(&next);
// get the parent first child to see if we are first
parent->GetChildBox(&child);
part->GetTotalMargin(parent,margin,aIsRow);
// if first or last
if (child == aBox || next == nsnull) {
// if its not the first child remove the top margin
// we don't need it.
if (child != aBox)
{
if (aIsRow)
margin.top = 0;
else
margin.left = 0;
}
// if its not the last child remove the bottom margin
// we don't need it.
if (next != nsnull)
{
if (aIsRow)
margin.bottom = 0;
else
margin.right = 0;
}
}
}
aMargin = margin;
// add ours to it.
aBox->GetMargin(margin);
aMargin += margin;
return NS_OK;
}
NS_IMPL_ADDREF_INHERITED(nsGridRowLayout, nsBoxLayout);
NS_IMPL_RELEASE_INHERITED(nsGridRowLayout, nsBoxLayout);

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

@ -62,11 +62,12 @@ public:
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup);
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid);
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull);
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow);
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridRow);
NS_IMETHOD ChildrenInserted(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aPrevBox, nsIBox* aChildList);
NS_IMETHOD ChildrenAppended(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
NS_IMETHOD ChildrenRemoved(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
NS_IMETHOD ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
NS_IMETHOD GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow);
protected:
NS_IMETHOD ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState)=0;

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

@ -0,0 +1,147 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsGridRowLeafFrame.h"
#include "nsGridRowLeafLayout.h"
#include "nsGridRow.h"
#include "nsBoxLayoutState.h"
#include "nsGridLayout2.h"
nsresult
NS_NewGridRowLeafFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsGridRowLeafFrame* it = new (aPresShell) nsGridRowLeafFrame (aPresShell, aIsRoot, aLayoutManager);
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
nsGridRowLeafFrame::nsGridRowLeafFrame(nsIPresShell* aPresShell, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
:nsBoxFrame(aPresShell, aIsRoot, aLayoutManager)
{
}
/*
* Our border and padding could be affected by our columns or rows
* Lets go check it out.
*/
NS_IMETHODIMP
nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding)
{
// if our columns have made our padding larger add it in.
nsMargin borderPadding(0,0,0,0);
nsresult rv = nsBoxFrame::GetBorderAndPadding(aBorderAndPadding);
nsCOMPtr<nsIBoxLayout> layout;
GetLayoutManager(getter_AddRefs(layout));
if (!layout)
return rv;
nsCOMPtr<nsIGridPart> part = do_QueryInterface(layout);
if (!part)
return rv;
nsGrid* grid = nsnull;
PRInt32 index = 0;
part->GetGrid(this, &grid, &index);
if (!grid)
return rv;
PRInt32 isRow = IsHorizontal();
nsBoxLayoutState state((nsIPresContext*)nsnull);
// only the first and last rows can be affected.
nsGridRow* row = grid->GetRowAt(0, isRow);
if (row && row->GetBox() == this) {
nscoord top = 0;
nscoord bottom = 0;
//grid->GetRowTopBottomPadding(index, top, PR_TRUE, isRow);
grid->GetRowOffsets(state, 0, top, bottom, isRow);
if (isRow) {
if (top > aBorderAndPadding.top)
aBorderAndPadding.top = top;
} else {
if (top > aBorderAndPadding.left)
aBorderAndPadding.left = top;
}
}
nscoord count = grid->GetRowCount(isRow);
if (count == 0)
return rv;
row = grid->GetRowAt(count-1, isRow);
if (row && row->GetBox() == this) {
nscoord top = 0;
nscoord bottom = 0;
//grid->GetRowTopBottomPadding(index, bottom, PR_FALSE, isRow);
grid->GetRowOffsets(state, count-1, top, bottom, isRow);
if (isRow) {
if (bottom > aBorderAndPadding.bottom)
aBorderAndPadding.bottom = bottom;
} else {
if (bottom > aBorderAndPadding.right)
aBorderAndPadding.right = bottom;
}
}
return rv;
}

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

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
Eric D Vaughan
A frame that can have multiple children. Only one child may be displayed at one time. So the
can be flipped though like a deck of cards.
**/
#ifndef nsGridRowLeafFrame_h___
#define nsGridRowLeafFrame_h___
#include "nsBoxFrame.h"
class nsGridRowLeafFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewGridRowLeafFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager);
#ifdef NS_DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const
{
return MakeFrameName("nsGridRowLeaf", aResult);
}
#endif
nsGridRowLeafFrame(nsIPresShell* aPresShell, PRBool aIsRoot, nsIBoxLayout* aLayoutManager);
NS_IMETHOD GetBorderAndPadding(nsMargin& aBorderAndPadding);
}; // class nsGridRowLeafFrame
#endif

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

@ -90,8 +90,8 @@ nsGridRowLeafLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize&
return nsGridRowLayout::GetPrefSize(aBox, aState, aSize);
else {
nsresult rv = grid->GetPrefRowSize(aState, index, aSize, isRow);
AddBorderAndPadding(aBox, aSize);
AddInset(aBox, aSize);
//AddBorderAndPadding(aBox, aSize);
//AddInset(aBox, aSize);
return rv;
}
}
@ -207,25 +207,60 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, ns
nscoord min = 0;
nscoord max = 0;
nscoord flex = 0;
nscoord left = 0;
nscoord right = 0;
current = new (aState) nsBoxSize();
// !isRow is passed in to invert the behavor of these methods.
grid->GetPrefRowHeight(aState, i, pref, !isRow); // GetPrefColumnWidth
grid->GetMinRowHeight(aState, i, min, !isRow); // GetMinColumnWidth
grid->GetMaxRowHeight(aState, i, max, !isRow); // GetMaxColumnWidth
grid->GetRowFlex(aState, i, flex, !isRow); // GetColumnFlex
grid->GetRowOffsets(aState, i, left, right, !isRow); // GetColumnOffsets
current = new (aState) nsBoxSize();
pref = pref - (left + right);
if (pref < 0)
pref = 0;
// if this is the first or last column. Take into account that
// our row could have a border that could affect our left or right
// padding from our columns. If the row has padding subtract it.
// would should always be able to garentee that our margin is smaller
// or equal to our left or right
if (i == 0 || i == count-1) {
nsMargin offset(0,0,0,0);
GetTotalMargin(aBox, offset, isRow);
// subtract from out left and right
if (i == 0)
{
if (isRow)
left -= offset.left;
else
left -= offset.top;
}
if (i == count-1)
{
if (isRow)
right -= offset.right;
else
right -= offset.bottom;
}
}
// initialize the box size here
nsBox::BoundsCheck(min, pref, max);
current->pref = pref;
current->min = min;
current->max = max;
current->flex = flex;
current->bogus = column->mIsBogus;
current->left = left + column->mTopMargin;
current->right = right + column->mBottomMargin;
if (!start) {
start = current;
last = start;
@ -234,6 +269,9 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, ns
last = current;
}
if (child)
child->GetNextBox(&child);
}
aBoxSizes = start;
}
@ -256,12 +294,11 @@ nsGridRowLeafLayout::ComputeChildSizes(nsIBox* aBox,
PRBool isRow = PR_FALSE;
aBox->GetOrientation(isRow);
nsIBox* scrollbox = nsnull;
aBox->GetParentBox(&aBox);
while (aBox)
{
scrollbox = nsGrid::GetScrollBox(aBox);
nsCOMPtr<nsIScrollableFrame> scrollable = do_QueryInterface(aBox);
nsCOMPtr<nsIScrollableFrame> scrollable = do_QueryInterface(scrollbox);
if (scrollable) {
// get the clip rect and compare its size to the scrollframe.
@ -272,7 +309,12 @@ nsGridRowLeafLayout::ComputeChildSizes(nsIBox* aBox,
nscoord diff = 0;
nsRect ourRect;
aBox->GetBounds(ourRect);
nsMargin padding(0,0,0,0);
scrollbox->GetBounds(ourRect);
scrollbox->GetBorderAndPadding(padding);
ourRect.Deflate(padding);
scrollbox->GetInset(padding);
ourRect.Deflate(padding);
if (isRow) {
diff = ourRect.width - clipSize.width;
@ -298,25 +340,9 @@ nsGridRowLeafLayout::ComputeChildSizes(nsIBox* aBox,
if (last)
last->size -= diff;
}
} else {
nsCOMPtr<nsIBoxLayout> layout;
aBox->GetLayoutManager(getter_AddRefs(layout));
nsCOMPtr<nsIGridPart> part = do_QueryInterface(layout);
if (part) {
nsGridLayout2* gridLayout = nsnull;
part->CastToGridLayout(&gridLayout);
if (gridLayout)
{
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
return;
}
}
}
aBox->GetParentBox(&aBox);
}
}
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
}
@ -376,5 +402,10 @@ nsGridRowLeafLayout::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
return NS_OK;
}
NS_IMETHODIMP
nsGridRowLeafLayout::GetRowCount(PRInt32& aRowCount)
{
aRowCount = 1;
return NS_OK;
}

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

@ -65,6 +65,7 @@ public:
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
NS_IMETHOD GetRowCount(PRInt32& aRowCount);
protected:
@ -78,6 +79,7 @@ protected:
nsGridRowLeafLayout(nsIPresShell* aShell);
virtual ~nsGridRowLeafLayout();
//virtual void AddBorderAndPadding(nsIBox* aBox, nsSize& aSize);
private:

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

@ -61,11 +61,14 @@ public:
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)=0;
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid)=0;
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull)=0;
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow)=0;
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridRow)=0;
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)=0;
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)=0;
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)=0;
NS_IMETHOD GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsRow)=0;
NS_IMETHOD GetRowCount(PRInt32& aRowCount)=0;
};
#endif