2001-09-29 00:14:13 +04:00
|
|
|
/* -*- 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
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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 ***** */
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-07-11 04:00:31 +04:00
|
|
|
#include "nsVoidArray.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCellMap.h"
|
1998-07-07 05:06:51 +04:00
|
|
|
#include "nsTableFrame.h"
|
1998-09-19 02:37:14 +04:00
|
|
|
#include "nsTableCellFrame.h"
|
2000-01-13 08:29:38 +03:00
|
|
|
#include "nsTableRowGroupFrame.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
// colspan=0 gets a minimum number of cols initially to make computations easier
|
|
|
|
#define MIN_NUM_COLS_FOR_ZERO_COLSPAN 2
|
|
|
|
|
1999-08-24 16:01:31 +04:00
|
|
|
// CellData
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(CellData)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
CellData::CellData(nsTableCellFrame* aOrigCell)
|
1999-08-24 16:01:31 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(CellData);
|
2000-01-13 08:29:38 +03:00
|
|
|
mOrigCell = aOrigCell;
|
1999-08-24 16:01:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CellData::~CellData()
|
1999-10-09 00:41:19 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(CellData);
|
|
|
|
}
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsCellMap)
|
1999-08-24 16:01:31 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
// nsTableCellMap
|
1999-08-24 16:01:31 +04:00
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
nsTableCellMap::nsTableCellMap(nsIPresContext* aPresContext, nsTableFrame& aTableFrame)
|
2001-05-17 16:40:27 +04:00
|
|
|
:mTableFrame(aTableFrame), mFirstMap(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
MOZ_COUNT_CTOR(nsTableCellMap);
|
2000-09-14 10:49:47 +04:00
|
|
|
|
2001-09-07 01:11:44 +04:00
|
|
|
nsAutoVoidArray orderedRowGroups;
|
2000-09-14 10:49:47 +04:00
|
|
|
PRUint32 numRowGroups;
|
|
|
|
aTableFrame.OrderRowGroups(orderedRowGroups, numRowGroups);
|
|
|
|
|
|
|
|
for (PRUint32 rgX = 0; rgX < numRowGroups; rgX++) {
|
|
|
|
nsTableRowGroupFrame* rgFrame =
|
|
|
|
aTableFrame.GetRowGroupFrame((nsIFrame*)orderedRowGroups.ElementAt(rgX));
|
|
|
|
if (rgFrame) {
|
|
|
|
nsTableRowGroupFrame* prior = (0 == rgX)
|
|
|
|
? nsnull : aTableFrame.GetRowGroupFrame((nsIFrame*)orderedRowGroups.ElementAt(rgX - 1));
|
|
|
|
InsertGroupCellMap(*rgFrame, prior);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
nsTableCellMap::~nsTableCellMap()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
MOZ_COUNT_DTOR(nsTableCellMap);
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
nsCellMap* next = cellMap->GetNextSibling();
|
|
|
|
delete cellMap;
|
|
|
|
cellMap = next;
|
|
|
|
}
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
PRInt32 colCount = mCols.Count();
|
2000-01-13 08:29:38 +03:00
|
|
|
for (PRInt32 colX = 0; colX < colCount; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
nsColInfo* colInfo = (nsColInfo *)mCols.ElementAt(colX);
|
|
|
|
if (colInfo) {
|
|
|
|
delete colInfo;
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-12-16 04:51:06 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void
|
|
|
|
nsTableCellMap::InsertGroupCellMap(nsCellMap* aPrevMap,
|
|
|
|
nsCellMap& aNewMap)
|
1999-07-28 12:09:02 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
nsCellMap* next;
|
|
|
|
if (aPrevMap) {
|
|
|
|
next = aPrevMap->GetNextSibling();
|
|
|
|
aPrevMap->SetNextSibling(&aNewMap);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next = mFirstMap;
|
|
|
|
mFirstMap = &aNewMap;
|
|
|
|
}
|
|
|
|
aNewMap.SetNextSibling(next);
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
2000-09-14 10:49:47 +04:00
|
|
|
void nsTableCellMap::InsertGroupCellMap(nsTableRowGroupFrame& aNewGroup,
|
|
|
|
nsTableRowGroupFrame*& aPrevGroup)
|
1999-07-28 12:09:02 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
nsCellMap* newMap = new nsCellMap(aNewGroup);
|
|
|
|
if (newMap) {
|
|
|
|
nsCellMap* prevMap = nsnull;
|
|
|
|
if (aPrevGroup) {
|
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
|
|
|
if (map->GetRowGroup() == aPrevGroup) {
|
|
|
|
prevMap = map;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
map = map->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
2000-09-14 10:49:47 +04:00
|
|
|
if (!prevMap) {
|
|
|
|
aPrevGroup = nsnull;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
InsertGroupCellMap(prevMap, *newMap);
|
|
|
|
}
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsTableCellMap::RemoveGroupCellMap(nsTableRowGroupFrame* aGroup)
|
|
|
|
{
|
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
nsCellMap* prior = nsnull;
|
|
|
|
while (map) {
|
|
|
|
if (map->GetRowGroup() == aGroup) {
|
|
|
|
nsCellMap* next = map->GetNextSibling();
|
|
|
|
if (mFirstMap == map) {
|
|
|
|
mFirstMap = next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prior->SetNextSibling(next);
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
delete map;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prior = map;
|
|
|
|
map = map->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-17 16:40:27 +04:00
|
|
|
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32
|
2000-02-01 06:23:29 +03:00
|
|
|
nsTableCellMap::GetEffectiveRowSpan(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowIndex = aRowIndex;
|
2000-01-13 08:29:38 +03:00
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
2000-02-01 06:23:29 +03:00
|
|
|
if (map->GetRowCount() > rowIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroRowSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
return map->GetRowSpan(*this, rowIndex, aColIndex, PR_TRUE, zeroRowSpan);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
rowIndex -= map->GetRowCount();
|
|
|
|
map = map->GetNextSibling();
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2000-02-01 06:23:29 +03:00
|
|
|
nsTableCellMap::GetEffectiveColSpan(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowIndex = aRowIndex;
|
2000-01-13 08:29:38 +03:00
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
2000-02-01 06:23:29 +03:00
|
|
|
if (map->GetRowCount() > rowIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroColSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
return map->GetEffectiveColSpan(*this, rowIndex, aColIndex, zeroColSpan);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
rowIndex -= map->GetRowCount();
|
|
|
|
map = map->GetNextSibling();
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2000-01-15 23:10:00 +03:00
|
|
|
nsTableCellFrame*
|
|
|
|
nsTableCellMap::GetCellFrame(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
CellData& aData,
|
|
|
|
PRBool aUseRowIfOverlap) const
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowIndex = aRowIndex;
|
2000-01-13 08:29:38 +03:00
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
2000-02-01 06:23:29 +03:00
|
|
|
if (map->GetRowCount() > rowIndex) {
|
|
|
|
return map->GetCellFrame(rowIndex, aColIndex, aData, aUseRowIfOverlap);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
rowIndex -= map->GetRowCount();
|
|
|
|
map = map->GetNextSibling();
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
nsColInfo*
|
|
|
|
nsTableCellMap::GetColInfoAt(PRInt32 aColIndex)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
|
|
|
PRInt32 numColsToAdd = aColIndex + 1 - mCols.Count();
|
|
|
|
if (numColsToAdd > 0) {
|
|
|
|
AddColsAtEnd(numColsToAdd);
|
|
|
|
}
|
|
|
|
return (nsColInfo*)mCols.ElementAt(aColIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsTableCellMap::GetRowCount() const
|
|
|
|
{
|
|
|
|
PRInt32 numRows = 0;
|
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
|
|
|
numRows += map->GetRowCount();
|
|
|
|
map = map->GetNextSibling();
|
|
|
|
}
|
|
|
|
return numRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
CellData*
|
|
|
|
nsTableCellMap::GetCellAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* map = mFirstMap;
|
|
|
|
while (map) {
|
|
|
|
if (map->GetRowCount() > rowIndex) {
|
2000-02-01 06:23:29 +03:00
|
|
|
return map->GetCellAt(*this, rowIndex, aColIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
rowIndex -= map->GetRowCount();
|
|
|
|
map = map->GetNextSibling();
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableCellMap::AddColsAtEnd(PRUint32 aNumCols)
|
|
|
|
{
|
2001-09-07 01:11:44 +04:00
|
|
|
// XXX We really should have a way to say "make this voidarray at least
|
|
|
|
// N entries long" to avoid reallocating N times. On the other hand, the
|
|
|
|
// number of likely allocations here isn't TOO gigantic, and we may not
|
|
|
|
// know about many of them at a time.
|
2001-05-17 16:40:27 +04:00
|
|
|
for (PRUint32 numX = 1; numX <= aNumCols; numX++) {
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo = new nsColInfo();
|
|
|
|
if (colInfo) {
|
|
|
|
mCols.AppendElement(colInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-17 16:40:27 +04:00
|
|
|
void
|
|
|
|
nsTableCellMap::RemoveColsAtEnd()
|
|
|
|
{
|
|
|
|
// Remove the cols at the end which don't have originating cells or cells spanning
|
|
|
|
// into them. Only do this if the col was created as eColAnonymousCell
|
|
|
|
PRInt32 numCols = GetColCount();
|
|
|
|
PRInt32 lastGoodColIndex = mTableFrame.GetIndexOfLastRealCol();
|
|
|
|
for (PRInt32 colX = numCols - 1; (colX >= 0) && (colX > lastGoodColIndex); colX--) {
|
|
|
|
nsColInfo* colInfo = (nsColInfo*)mCols.ElementAt(colX);
|
|
|
|
if (colInfo) {
|
|
|
|
if ((colInfo->mNumCellsOrig <= 0) && (colInfo->mNumCellsSpan <= 0)) {
|
|
|
|
mCols.RemoveElementAt(colX);
|
|
|
|
}
|
|
|
|
else break; // only remove until we encounter the 1st valid one
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(0, "null entry in column info array");
|
|
|
|
mCols.RemoveElementAt(colX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsTableCellMap::InsertRows(nsIPresContext* aPresContext,
|
|
|
|
nsTableRowGroupFrame& aParent,
|
2000-01-13 08:29:38 +03:00
|
|
|
nsVoidArray& aRows,
|
|
|
|
PRInt32 aFirstRowIndex,
|
|
|
|
PRBool aConsiderSpans)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((aRows.Count() > 0) && (aFirstRowIndex >= 0), "nsTableCellMap::InsertRows called incorrectly");
|
|
|
|
PRInt32 rowIndex = aFirstRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowGroup() == &aParent) {
|
2000-01-22 04:16:50 +03:00
|
|
|
cellMap->InsertRows(aPresContext, *this, aRows, rowIndex, aConsiderSpans);
|
2001-11-20 03:58:53 +03:00
|
|
|
//Dump("after InsertRows");
|
2000-01-13 08:29:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2000-01-13 23:58:24 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(PR_FALSE, "Attempt to insert row into wrong map.");
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsTableCellMap::RemoveRows(nsIPresContext* aPresContext,
|
|
|
|
PRInt32 aFirstRowIndex,
|
|
|
|
PRInt32 aNumRowsToRemove,
|
|
|
|
PRBool aConsiderSpans)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aFirstRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
2000-01-22 04:16:50 +03:00
|
|
|
cellMap->RemoveRows(aPresContext, *this, rowIndex, aNumRowsToRemove, aConsiderSpans);
|
2000-01-13 08:29:38 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2001-11-20 03:58:53 +03:00
|
|
|
//Dump("after RemoveRows");
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
2000-05-11 05:04:39 +04:00
|
|
|
PRInt32
|
|
|
|
nsTableCellMap::GetNumCellsOriginatingInRow(PRInt32 aRowIndex)
|
|
|
|
{
|
2001-11-05 03:15:51 +03:00
|
|
|
PRInt32 originCount = 0;
|
|
|
|
|
|
|
|
CellData* cellData;
|
|
|
|
PRInt32 colIndex = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
cellData = GetCellAt(aRowIndex, colIndex);
|
|
|
|
if (cellData && cellData->GetCellFrame())
|
|
|
|
originCount++;
|
|
|
|
colIndex++;
|
|
|
|
} while(cellData);
|
|
|
|
|
|
|
|
return originCount;
|
2000-05-11 05:04:39 +04:00
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32
|
2000-01-15 23:10:00 +03:00
|
|
|
nsTableCellMap::AppendCell(nsTableCellFrame& aCellFrame,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRBool aRebuildIfNecessary)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-01-15 23:10:00 +03:00
|
|
|
NS_ASSERTION(&aCellFrame == aCellFrame.GetFirstInFlow(), "invalid call on continuing frame");
|
2001-03-29 01:25:13 +04:00
|
|
|
nsIFrame* rgFrame = nsnull;
|
|
|
|
aCellFrame.GetParent(&rgFrame); // get the row
|
|
|
|
if (!rgFrame) return 0;
|
|
|
|
rgFrame->GetParent(&rgFrame); // get the row group
|
|
|
|
if (!rgFrame) return 0;
|
|
|
|
|
2001-11-20 03:58:53 +03:00
|
|
|
PRInt32 result = 0;
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
2001-03-29 01:25:13 +04:00
|
|
|
if (cellMap->GetRowGroup() == rgFrame) {
|
2001-11-20 03:58:53 +03:00
|
|
|
result = cellMap->AppendCell(*this, aCellFrame, rowIndex, aRebuildIfNecessary);
|
|
|
|
break;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2001-11-20 03:58:53 +03:00
|
|
|
//Dump("after AppendCell");
|
|
|
|
return result;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableCellMap::InsertCells(nsVoidArray& aCellFrames,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndexBefore)
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
|
|
|
cellMap->InsertCells(*this, aCellFrames, rowIndex, aColIndexBefore);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2001-11-20 03:58:53 +03:00
|
|
|
//Dump("after InsertCells");
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTableCellMap::RemoveCell(nsTableCellFrame* aCellFrame,
|
|
|
|
PRInt32 aRowIndex)
|
|
|
|
{
|
2000-01-15 23:10:00 +03:00
|
|
|
NS_ASSERTION(aCellFrame == (nsTableCellFrame *)aCellFrame->GetFirstInFlow(),
|
|
|
|
"invalid call on continuing frame");
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
|
|
|
cellMap->RemoveCell(*this, aCellFrame, rowIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2001-11-20 03:58:53 +03:00
|
|
|
//Dump("after RemoveCell");
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsTableCellMap::GetNumCellsOriginatingInCol(PRInt32 aColIndex) const
|
|
|
|
{
|
|
|
|
PRInt32 colCount = mCols.Count();
|
|
|
|
if ((aColIndex >= 0) && (aColIndex < colCount)) {
|
|
|
|
return ((nsColInfo *)mCols.ElementAt(aColIndex))->mNumCellsOrig;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(PR_FALSE, "nsCellMap::GetNumCellsOriginatingInCol - bad col index");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void
|
2001-11-20 03:58:53 +03:00
|
|
|
nsTableCellMap::Dump(char* aString) const
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2001-11-20 03:58:53 +03:00
|
|
|
if (aString)
|
|
|
|
printf("%s \n", aString);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("***** START TABLE CELL MAP DUMP ***** %p\n", this);
|
2000-01-13 08:29:38 +03:00
|
|
|
// output col info
|
|
|
|
PRInt32 colCount = mCols.Count();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("cols array orig/span-> %p", this);
|
2000-01-13 08:29:38 +03:00
|
|
|
for (PRInt32 colX = 0; colX < colCount; colX++) {
|
|
|
|
nsColInfo* colInfo = (nsColInfo *)mCols.ElementAt(colX);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("%d=%d/%d ", colX, colInfo->mNumCellsOrig, colInfo->mNumCellsSpan);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
cellMap->Dump();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("***** END TABLE CELL MAP DUMP *****\n");
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsTableCellFrame*
|
|
|
|
nsTableCellMap::GetCellInfoAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool* aOriginates,
|
|
|
|
PRInt32* aColSpan)
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
2000-02-01 06:23:29 +03:00
|
|
|
return cellMap->GetCellInfoAt(*this, rowIndex, aColIndex, aOriginates, aColSpan);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool nsTableCellMap::RowIsSpannedInto(PRInt32 aRowIndex)
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
2000-02-01 06:23:29 +03:00
|
|
|
return cellMap->RowIsSpannedInto(*this, rowIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsTableCellMap::RowHasSpanningCells(PRInt32 aRowIndex)
|
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndex;
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
|
|
|
if (cellMap->GetRowCount() > rowIndex) {
|
2000-02-01 06:23:29 +03:00
|
|
|
return cellMap->RowHasSpanningCells(*this, rowIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
rowIndex -= cellMap->GetRowCount();
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsTableCellMap::ColIsSpannedInto(PRInt32 aColIndex)
|
|
|
|
{
|
2001-03-13 09:38:59 +03:00
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
PRInt32 colCount = mCols.Count();
|
|
|
|
if ((aColIndex >= 0) && (aColIndex < colCount)) {
|
|
|
|
result = (PRBool) ((nsColInfo *)mCols.ElementAt(aColIndex))->mNumCellsSpan;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2001-03-13 09:38:59 +03:00
|
|
|
return result;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsTableCellMap::ColHasSpanningCells(PRInt32 aColIndex)
|
|
|
|
{
|
|
|
|
nsCellMap* cellMap = mFirstMap;
|
|
|
|
while (cellMap) {
|
2000-02-01 06:23:29 +03:00
|
|
|
if (cellMap->ColHasSpanningCells(*this, aColIndex)) {
|
2000-01-13 08:29:38 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
cellMap = cellMap->GetNextSibling();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsTableCellMap::SizeOf(nsISizeOfHandler* aHandler,
|
|
|
|
PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT parameter pointer");
|
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
|
|
|
|
// Add in the size of the void arrays. Because we have emnbedded objects
|
|
|
|
// and not pointers to void arrays, we need to subtract out the size of the
|
|
|
|
// embedded object so it isn't double counted
|
|
|
|
PRUint32 voidArraySize;
|
|
|
|
|
|
|
|
mCols.SizeOf(aHandler, &voidArraySize);
|
|
|
|
sum += voidArraySize - sizeof(mCols);
|
|
|
|
|
|
|
|
*aResult = sum;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsCellMap
|
|
|
|
|
|
|
|
nsCellMap::nsCellMap(nsTableRowGroupFrame& aRowGroup)
|
2000-03-15 07:50:25 +03:00
|
|
|
: mRowCount(0), mRowGroupFrame(&aRowGroup), mNextSibling(nsnull)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-01-18 03:55:49 +03:00
|
|
|
MOZ_COUNT_CTOR(nsCellMap);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCellMap::~nsCellMap()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCellMap);
|
|
|
|
|
|
|
|
PRInt32 mapRowCount = mRows.Count();
|
|
|
|
for (PRInt32 rowX = 0; rowX < mapRowCount; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(rowX));
|
|
|
|
PRInt32 colCount = row->Count();
|
|
|
|
for (PRInt32 colX = 0; colX < colCount; colX++) {
|
|
|
|
CellData* data = (CellData *)(row->ElementAt(colX));
|
|
|
|
if (data) {
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-15 23:10:00 +03:00
|
|
|
nsTableCellFrame*
|
|
|
|
nsCellMap::GetCellFrame(PRInt32 aRowIndexIn,
|
|
|
|
PRInt32 aColIndexIn,
|
|
|
|
CellData& aData,
|
|
|
|
PRBool aUseRowIfOverlap) const
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
|
|
|
PRInt32 rowIndex = aRowIndexIn - aData.GetRowSpanOffset();
|
|
|
|
PRInt32 colIndex = aColIndexIn - aData.GetColSpanOffset();
|
|
|
|
if (aData.IsOverlap()) {
|
|
|
|
if (aUseRowIfOverlap) {
|
|
|
|
colIndex = aColIndexIn;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rowIndex = aRowIndexIn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsVoidArray* row = (nsVoidArray*) mRows.ElementAt(rowIndex);
|
|
|
|
if (row) {
|
|
|
|
CellData* data = (CellData*)row->ElementAt(colIndex);
|
|
|
|
if (data) {
|
|
|
|
return data->GetCellFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
1998-07-11 04:00:31 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool nsCellMap::Grow(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aNumRows,
|
|
|
|
PRInt32 aRowIndex)
|
|
|
|
{
|
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
|
|
|
PRInt32 startRowIndex = (aRowIndex >= 0) ? aRowIndex : mRows.Count();
|
|
|
|
PRInt32 endRowIndex = startRowIndex + aNumRows - 1;
|
2001-09-07 01:11:44 +04:00
|
|
|
// XXX We really should have a way to say "make this voidarray at least
|
|
|
|
// N entries long" to avoid reallocating N times. On the other hand, the
|
|
|
|
// number of likely allocations here isn't TOO gigantic, and we may not
|
|
|
|
// know about many of them at a time.
|
2000-01-13 08:29:38 +03:00
|
|
|
for (PRInt32 rowX = startRowIndex; rowX <= endRowIndex; rowX++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
nsVoidArray* row;
|
2001-09-07 01:11:44 +04:00
|
|
|
row = (0 == numCols) ? new nsVoidArray(4) : new nsVoidArray(numCols);
|
1999-08-26 01:49:18 +04:00
|
|
|
if (row) {
|
2000-01-13 08:29:38 +03:00
|
|
|
mRows.InsertElementAt(row, rowX);
|
1999-08-26 01:49:18 +04:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
else return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCellMap::GrowRow(nsVoidArray& aRow,
|
|
|
|
PRInt32 aNumCols)
|
|
|
|
|
|
|
|
{
|
2000-01-13 23:22:19 +03:00
|
|
|
for (PRInt32 colX = 0; colX < aNumCols; colX++) {
|
2000-01-13 08:29:38 +03:00
|
|
|
aRow.AppendElement(nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsCellMap::InsertRows(nsIPresContext* aPresContext,
|
|
|
|
nsTableCellMap& aMap,
|
2000-01-13 08:29:38 +03:00
|
|
|
nsVoidArray& aRows,
|
|
|
|
PRInt32 aFirstRowIndex,
|
|
|
|
PRBool aConsiderSpans)
|
1999-08-30 04:01:09 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
1999-08-30 04:01:09 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
if (aFirstRowIndex > mRowCount) {
|
2001-01-25 19:02:14 +03:00
|
|
|
// create (aFirstRowIndex - mRowCount) empty rows up to aFirstRowIndex
|
|
|
|
PRInt32 numEmptyRows = aFirstRowIndex - mRowCount;
|
|
|
|
if (!Grow(aMap, numEmptyRows, mRowCount)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// update mRowCount, since non-empty rows will be added
|
|
|
|
mRowCount += numEmptyRows;
|
1999-08-30 04:01:09 +04:00
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
if (!aConsiderSpans) {
|
2000-01-22 04:16:50 +03:00
|
|
|
ExpandWithRows(aPresContext, aMap, aRows, aFirstRowIndex);
|
1999-12-14 01:56:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if any cells span into or out of the row being inserted, then rebuild
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool spansCauseRebuild = CellsSpanInOrOut(aMap, aFirstRowIndex,
|
|
|
|
aFirstRowIndex, 0, numCols - 1);
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// if any of the new cells span out of the new rows being added, then rebuild
|
|
|
|
// XXX it would be better to only rebuild the portion of the map that follows the new rows
|
|
|
|
if (!spansCauseRebuild && (aFirstRowIndex < mRows.Count())) {
|
2000-01-22 04:16:50 +03:00
|
|
|
spansCauseRebuild = CellsSpanOut(aPresContext, aRows);
|
1999-08-30 04:01:09 +04:00
|
|
|
}
|
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
if (spansCauseRebuild) {
|
2000-01-22 04:16:50 +03:00
|
|
|
RebuildConsideringRows(aPresContext, aMap, aFirstRowIndex, &aRows);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-01-22 04:16:50 +03:00
|
|
|
ExpandWithRows(aPresContext, aMap, aRows, aFirstRowIndex);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
1999-08-30 04:01:09 +04:00
|
|
|
}
|
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsCellMap::RemoveRows(nsIPresContext* aPresContext,
|
|
|
|
nsTableCellMap& aMap,
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 aFirstRowIndex,
|
|
|
|
PRInt32 aNumRowsToRemove,
|
|
|
|
PRBool aConsiderSpans)
|
1999-08-30 04:01:09 +04:00
|
|
|
{
|
1999-12-14 01:56:31 +03:00
|
|
|
PRInt32 numRows = mRows.Count();
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
1999-08-30 04:01:09 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
if (aFirstRowIndex >= numRows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!aConsiderSpans) {
|
2000-01-13 08:29:38 +03:00
|
|
|
ShrinkWithoutRows(aMap, aFirstRowIndex, aNumRowsToRemove);
|
1999-12-14 01:56:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
PRInt32 endRowIndex = aFirstRowIndex + aNumRowsToRemove - 1;
|
|
|
|
if (endRowIndex >= numRows) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "nsCellMap::RemoveRows tried to remove too many rows");
|
|
|
|
endRowIndex = numRows - 1;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool spansCauseRebuild = CellsSpanInOrOut(aMap, aFirstRowIndex, endRowIndex,
|
|
|
|
0, numCols - 1);
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
if (spansCauseRebuild) {
|
2000-01-22 04:16:50 +03:00
|
|
|
RebuildConsideringRows(aPresContext, aMap, aFirstRowIndex, nsnull, aNumRowsToRemove);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
ShrinkWithoutRows(aMap, aFirstRowIndex, aNumRowsToRemove);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-15 23:10:00 +03:00
|
|
|
PRInt32
|
|
|
|
nsCellMap::AppendCell(nsTableCellMap& aMap,
|
|
|
|
nsTableCellFrame& aCellFrame,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRBool aRebuildIfNecessary)
|
1999-07-28 12:09:02 +04:00
|
|
|
{
|
|
|
|
PRInt32 origNumMapRows = mRows.Count();
|
2000-02-02 04:56:46 +03:00
|
|
|
PRInt32 origNumCols = aMap.GetColCount();
|
|
|
|
PRBool zeroRowSpan;
|
|
|
|
PRInt32 rowSpan = GetRowSpanForNewCell(aCellFrame, aRowIndex, zeroRowSpan);
|
|
|
|
// add new rows if necessary
|
|
|
|
PRInt32 endRowIndex = aRowIndex + rowSpan - 1;
|
|
|
|
if (endRowIndex >= origNumMapRows) {
|
|
|
|
Grow(aMap, 1 + endRowIndex - origNumMapRows);
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
// get the first null CellData in the desired row. It may be 1 past the end if there are none
|
|
|
|
PRInt32 startColIndex;
|
2000-02-02 04:56:46 +03:00
|
|
|
for (startColIndex = 0; startColIndex < origNumCols; startColIndex++) {
|
|
|
|
CellData* data = GetMapCellAt(aMap, aRowIndex, startColIndex, PR_TRUE);
|
|
|
|
if (!data) {
|
|
|
|
break; // we found the col
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-02-02 04:56:46 +03:00
|
|
|
PRBool zeroColSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 colSpan = GetColSpanForNewCell(aCellFrame, startColIndex, origNumCols, zeroColSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// if the new cell could potentially span into other rows and collide with
|
|
|
|
// originating cells there, we will play it safe and just rebuild the map
|
|
|
|
if (aRebuildIfNecessary && (aRowIndex < mRowCount - 1) && (rowSpan > 1)) {
|
2001-09-07 01:11:44 +04:00
|
|
|
nsAutoVoidArray newCellArray;
|
2000-01-13 08:29:38 +03:00
|
|
|
newCellArray.AppendElement(&aCellFrame);
|
|
|
|
RebuildConsideringCells(aMap, &newCellArray, aRowIndex, startColIndex, PR_TRUE);
|
1999-12-14 01:56:31 +03:00
|
|
|
return startColIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRowCount = PR_MAX(mRowCount, aRowIndex + 1);
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
// add new cols to the table map if necessary
|
|
|
|
PRInt32 endColIndex = startColIndex + colSpan - 1;
|
|
|
|
if (endColIndex >= origNumCols) {
|
|
|
|
aMap.AddColsAtEnd(1 + endColIndex - origNumCols);
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup CellData for this cell
|
2000-01-13 08:29:38 +03:00
|
|
|
CellData* origData = new CellData(&aCellFrame);
|
2000-11-30 18:53:55 +03:00
|
|
|
if (!origData) return startColIndex;
|
2000-01-13 08:29:38 +03:00
|
|
|
SetMapCellAt(aMap, *origData, aRowIndex, startColIndex, PR_TRUE);
|
1999-07-28 12:09:02 +04:00
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
// initialize the cell frame
|
2000-01-13 08:29:38 +03:00
|
|
|
aCellFrame.InitCellFrame(startColIndex);
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
// Create CellData objects for the rows that this cell spans. Set
|
|
|
|
// their mOrigCell to nsnull and their mSpanData to point to data.
|
2000-01-13 08:29:38 +03:00
|
|
|
for (PRInt32 rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
|
|
|
for (PRInt32 colX = startColIndex; colX <= endColIndex; colX++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
if ((rowX != aRowIndex) || (colX != startColIndex)) { // skip orig cell data done above
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* cellData = GetMapCellAt(aMap, rowX, colX, PR_FALSE);
|
1999-07-28 12:09:02 +04:00
|
|
|
if (cellData) {
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cellData->IsOrig()) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "cannot overlap originating cell");
|
|
|
|
continue;
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
if (rowX > aRowIndex) { // row spanning into cell
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cellData->IsRowSpan()) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "invalid overlap");
|
1999-08-19 23:52:37 +04:00
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
cellData->SetRowSpanOffset(rowX - aRowIndex);
|
|
|
|
if (zeroRowSpan) {
|
|
|
|
cellData->SetZeroRowSpan(PR_TRUE);
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
if (colX > startColIndex) { // col spanning into cell
|
2000-01-13 08:29:38 +03:00
|
|
|
if (!cellData->IsColSpan()) {
|
|
|
|
if (cellData->IsRowSpan()) {
|
|
|
|
cellData->SetOverlap(PR_TRUE);
|
|
|
|
}
|
|
|
|
cellData->SetColSpanOffset(colX - startColIndex);
|
|
|
|
if (zeroColSpan) {
|
|
|
|
cellData->SetZeroColSpan(PR_TRUE);
|
|
|
|
}
|
|
|
|
// only count the 1st spanned col of a zero col span
|
|
|
|
if (!zeroColSpan || (colX == startColIndex + 1)) {
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
|
|
|
colInfo->mNumCellsSpan++;
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
cellData = new CellData(nsnull);
|
2000-11-30 18:53:55 +03:00
|
|
|
if (!cellData) return startColIndex;
|
1999-12-14 01:56:31 +03:00
|
|
|
if (rowX > aRowIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
cellData->SetRowSpanOffset(rowX - aRowIndex);
|
|
|
|
}
|
|
|
|
if (zeroRowSpan) {
|
|
|
|
cellData->SetZeroRowSpan(PR_TRUE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
if (colX > startColIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
cellData->SetColSpanOffset(colX - startColIndex);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
if (zeroColSpan) {
|
|
|
|
cellData->SetZeroColSpan(PR_TRUE);
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// only count the 1st spanned col of a zero col span
|
|
|
|
SetMapCellAt(aMap, *cellData, rowX, colX, (colX == startColIndex + 1));
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
1999-02-11 09:22:33 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
//printf("appended cell=%p row=%d \n", &aCellFrame, aRowIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
//aMap.Dump();
|
1999-07-28 12:09:02 +04:00
|
|
|
return startColIndex;
|
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool nsCellMap::CellsSpanOut(nsIPresContext* aPresContext,
|
|
|
|
nsVoidArray& aRows)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
PRInt32 numNewRows = aRows.Count();
|
|
|
|
for (PRInt32 rowX = 0; rowX < numNewRows; rowX++) {
|
|
|
|
nsIFrame* rowFrame = (nsIFrame *) aRows.ElementAt(rowX);
|
|
|
|
nsIFrame* cellFrame = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
rowFrame->FirstChild(aPresContext, nsnull, &cellFrame);
|
1999-12-14 01:56:31 +03:00
|
|
|
while (cellFrame) {
|
|
|
|
nsIAtom* frameType;
|
|
|
|
cellFrame->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::tableCellFrame == frameType) {
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowSpan = GetRowSpanForNewCell((nsTableCellFrame &)*cellFrame, rowX, zeroSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
if (rowX + rowSpan > numNewRows) {
|
|
|
|
NS_RELEASE(frameType);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
cellFrame->GetNextSibling(&cellFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return PR_TRUE if any cells have rows spans into or out of the region
|
|
|
|
// defined by the row and col indices or any cells have colspans into the region
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool nsCellMap::CellsSpanInOrOut(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aStartRowIndex,
|
|
|
|
PRInt32 aEndRowIndex,
|
|
|
|
PRInt32 aStartColIndex,
|
|
|
|
PRInt32 aEndColIndex)
|
1999-07-28 12:09:02 +04:00
|
|
|
{
|
1999-12-14 01:56:31 +03:00
|
|
|
for (PRInt32 colX = aStartColIndex; colX <= aEndColIndex; colX++) {
|
|
|
|
CellData* cellData;
|
|
|
|
if (aStartRowIndex > 0) {
|
2000-02-01 06:23:29 +03:00
|
|
|
cellData = GetMapCellAt(aMap, aStartRowIndex, colX, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cellData && (cellData->IsRowSpan())) {
|
2001-01-13 02:07:54 +03:00
|
|
|
return PR_TRUE; // there is a row span into the region
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aEndRowIndex < mRowCount - 1) {
|
2000-02-01 06:23:29 +03:00
|
|
|
cellData = GetMapCellAt(aMap, aEndRowIndex + 1, colX, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if ((cellData) && (cellData->IsRowSpan())) {
|
2001-01-13 02:07:54 +03:00
|
|
|
return PR_TRUE; // there is a row span out of the region
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aStartColIndex > 0) {
|
|
|
|
for (PRInt32 rowX = aStartRowIndex; rowX <= aEndRowIndex; rowX++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* cellData = GetMapCellAt(aMap, rowX, aStartColIndex, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cellData && (cellData->IsColSpan())) {
|
2001-01-13 02:07:54 +03:00
|
|
|
return PR_TRUE; // there is a col span into the region
|
|
|
|
}
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(rowX));
|
|
|
|
if (row) {
|
|
|
|
cellData = (CellData *)(row->ElementAt(aEndColIndex + 1));
|
|
|
|
if (cellData && (cellData->IsColSpan())) {
|
|
|
|
return PR_TRUE; // there is a col span out of the region
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1998-09-01 01:23:28 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::InsertCells(nsTableCellMap& aMap,
|
|
|
|
nsVoidArray& aCellFrames,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndexBefore)
|
1999-07-28 12:09:02 +04:00
|
|
|
{
|
1999-12-14 01:56:31 +03:00
|
|
|
if (aCellFrames.Count() == 0) return;
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
if (aColIndexBefore >= numCols) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "bad arg in nsCellMap::InsertCellAt");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the starting col index of the 1st new cells
|
|
|
|
PRInt32 startColIndex;
|
|
|
|
for (startColIndex = aColIndexBefore + 1; startColIndex < numCols; startColIndex++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* data = GetMapCellAt(aMap, aRowIndex, startColIndex, PR_TRUE);
|
2000-04-29 01:05:31 +04:00
|
|
|
if (!data || data->IsOrig()) { // stop unless it is a span
|
|
|
|
break;
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// record whether inserted cells are going to cause complications due
|
|
|
|
// to existing row spans, col spans or table sizing.
|
|
|
|
PRBool spansCauseRebuild = PR_FALSE;
|
|
|
|
|
|
|
|
// check that all cells have the same row span
|
|
|
|
PRInt32 numNewCells = aCellFrames.Count();
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroRowSpan = PR_FALSE;
|
1999-12-14 01:56:31 +03:00
|
|
|
PRInt32 rowSpan = 0;
|
|
|
|
for (PRInt32 cellX = 0; cellX < numNewCells; cellX++) {
|
|
|
|
nsTableCellFrame* cell = (nsTableCellFrame*) aCellFrames.ElementAt(cellX);
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowSpan2 = GetRowSpanForNewCell(*cell, aRowIndex, zeroRowSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
if (rowSpan == 0) {
|
|
|
|
rowSpan = rowSpan2;
|
|
|
|
}
|
|
|
|
else if (rowSpan != rowSpan2) {
|
|
|
|
spansCauseRebuild = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the new cells will cause the table to add more rows
|
|
|
|
if (!spansCauseRebuild) {
|
|
|
|
if (mRows.Count() < aRowIndex + rowSpan) {
|
|
|
|
spansCauseRebuild = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!spansCauseRebuild) {
|
2000-02-01 06:23:29 +03:00
|
|
|
spansCauseRebuild = CellsSpanInOrOut(aMap, aRowIndex, aRowIndex + rowSpan - 1,
|
|
|
|
startColIndex, numCols - 1);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spansCauseRebuild) {
|
2000-01-13 08:29:38 +03:00
|
|
|
RebuildConsideringCells(aMap, &aCellFrames, aRowIndex, startColIndex, PR_TRUE);
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
ExpandWithCells(aMap, aCellFrames, aRowIndex, startColIndex, rowSpan, zeroRowSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsCellMap::ExpandWithRows(nsIPresContext* aPresContext,
|
|
|
|
nsTableCellMap& aMap,
|
2000-01-13 08:29:38 +03:00
|
|
|
nsVoidArray& aRowFrames,
|
2000-04-29 01:05:31 +04:00
|
|
|
PRInt32 aStartRowIndexIn)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
2000-04-29 01:05:31 +04:00
|
|
|
PRInt32 startRowIndex = (aStartRowIndexIn >= 0) ? aStartRowIndexIn : 0;
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numNewRows = aRowFrames.Count();
|
2000-04-29 01:05:31 +04:00
|
|
|
PRInt32 endRowIndex = startRowIndex + numNewRows - 1;
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// create the new rows first
|
2000-04-29 01:05:31 +04:00
|
|
|
if (!Grow(aMap, numNewRows, startRowIndex)) {
|
2000-01-13 08:29:38 +03:00
|
|
|
return;
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
mRowCount += numNewRows;
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 newRowIndex = 0;
|
2000-04-29 01:05:31 +04:00
|
|
|
for (PRInt32 rowX = startRowIndex; rowX <= endRowIndex; rowX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
nsTableRowFrame* rFrame = (nsTableRowFrame *)aRowFrames.ElementAt(newRowIndex);
|
|
|
|
// append cells
|
|
|
|
nsIFrame* cFrame = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
rFrame->FirstChild(aPresContext, nsnull, &cFrame);
|
1999-12-14 01:56:31 +03:00
|
|
|
while (cFrame) {
|
|
|
|
nsIAtom* cFrameType;
|
|
|
|
cFrame->GetFrameType(&cFrameType);
|
|
|
|
if (nsLayoutAtoms::tableCellFrame == cFrameType) {
|
2000-01-13 08:29:38 +03:00
|
|
|
AppendCell(aMap, (nsTableCellFrame &)*cFrame, rowX, PR_FALSE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(cFrameType);
|
|
|
|
cFrame->GetNextSibling(&cFrame);
|
|
|
|
}
|
|
|
|
newRowIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::ExpandWithCells(nsTableCellMap& aMap,
|
|
|
|
nsVoidArray& aCellFrames,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aRowSpan,
|
|
|
|
PRBool aRowSpanIsZero)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
PRInt32 endRowIndex = aRowIndex + aRowSpan - 1;
|
|
|
|
PRInt32 startColIndex = aColIndex;
|
|
|
|
PRInt32 endColIndex;
|
|
|
|
PRInt32 numCells = aCellFrames.Count();
|
|
|
|
PRInt32 totalColSpan = 0;
|
|
|
|
|
|
|
|
// add cellData entries for the space taken up by the new cells
|
|
|
|
for (PRInt32 cellX = 0; cellX < numCells; cellX++) {
|
|
|
|
nsTableCellFrame* cellFrame = (nsTableCellFrame*) aCellFrames.ElementAt(cellX);
|
2000-01-13 08:29:38 +03:00
|
|
|
CellData* origData = new CellData(cellFrame); // the originating cell
|
1999-12-14 01:56:31 +03:00
|
|
|
if (!origData) return;
|
|
|
|
|
|
|
|
// set the starting and ending col index for the new cell
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroColSpan = PR_FALSE;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 colSpan = GetColSpanForNewCell(*cellFrame, aColIndex, aMap.GetColCount(), zeroColSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
totalColSpan += colSpan;
|
|
|
|
if (cellX == 0) {
|
|
|
|
endColIndex = aColIndex + colSpan - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
startColIndex = endColIndex + 1;
|
|
|
|
endColIndex = startColIndex + colSpan - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the originating cell data and any cell data corresponding to row/col spans
|
|
|
|
for (PRInt32 rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
|
|
|
for (PRInt32 colX = aColIndex; colX <= endColIndex; colX++) {
|
|
|
|
row->InsertElementAt(nsnull, colX);
|
|
|
|
CellData* data = origData;
|
|
|
|
if ((rowX != aRowIndex) || (colX != startColIndex)) {
|
2000-01-13 08:29:38 +03:00
|
|
|
data = new CellData(nsnull);
|
1999-12-14 01:56:31 +03:00
|
|
|
if (!data) return;
|
|
|
|
if (rowX > aRowIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
data->SetRowSpanOffset(rowX - aRowIndex);
|
|
|
|
if (aRowSpanIsZero) {
|
|
|
|
data->SetZeroRowSpan(PR_TRUE);
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
if (colX > startColIndex) {
|
2000-01-13 08:29:38 +03:00
|
|
|
data->SetColSpanOffset(colX - startColIndex);
|
|
|
|
if (zeroColSpan) {
|
|
|
|
data->SetZeroColSpan(PR_TRUE);
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// only count 1st spanned col of colspan=0
|
|
|
|
SetMapCellAt(aMap, *data, rowX, colX, (colX == aColIndex + 1));
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cellFrame->InitCellFrame(startColIndex);
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 rowX;
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// update the row and col info due to shifting
|
2000-01-13 08:29:38 +03:00
|
|
|
for (rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
|
|
|
PRInt32 numCols = row->Count();
|
2000-01-04 08:31:56 +03:00
|
|
|
PRInt32 colX;
|
|
|
|
for (colX = aColIndex + totalColSpan; colX < numCols; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
|
|
|
if (data) {
|
2000-01-04 08:31:56 +03:00
|
|
|
// increase the origin and span counts beyond the spanned cols
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data->IsOrig()) {
|
1999-12-14 01:56:31 +03:00
|
|
|
// a cell that gets moved needs adjustment as well as it new orignating col
|
2000-01-13 08:29:38 +03:00
|
|
|
data->GetCellFrame()->SetColIndex(colX);
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
1999-12-14 01:56:31 +03:00
|
|
|
colInfo->mNumCellsOrig++;
|
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
// if the colspan is 0 only count the 1st spanned col
|
|
|
|
PRBool countAsSpan = PR_FALSE;
|
|
|
|
if (data->IsColSpan()) {
|
|
|
|
if ( (!data->IsZeroColSpan()) ||
|
|
|
|
((data->IsZeroColSpan()) && (colX > aColIndex + totalColSpan) &&
|
|
|
|
(!IsZeroColSpan(rowX, colX - 1)))) {
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
|
|
|
colInfo->mNumCellsSpan++;
|
|
|
|
countAsSpan = PR_TRUE;
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
2000-01-04 08:31:56 +03:00
|
|
|
|
|
|
|
// decrease the origin and span counts within the spanned cols
|
|
|
|
PRInt32 colX2 = colX - totalColSpan;
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo2 = aMap.GetColInfoAt(colX2);
|
|
|
|
if (data->IsOrig()) {
|
|
|
|
// the old originating col of a moved cell needs adjustment
|
|
|
|
colInfo2->mNumCellsOrig--;
|
|
|
|
}
|
|
|
|
else if (countAsSpan) {
|
|
|
|
colInfo2->mNumCellsSpan--;
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::ShrinkWithoutRows(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aStartRowIndex,
|
|
|
|
PRInt32 aNumRowsToRemove)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
PRInt32 endRowIndex = aStartRowIndex + aNumRowsToRemove - 1;
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 colCount = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
for (PRInt32 rowX = endRowIndex; rowX >= aStartRowIndex; rowX--) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(rowX));
|
|
|
|
PRInt32 colX;
|
|
|
|
for (colX = 0; colX < colCount; colX++) {
|
|
|
|
CellData* data = (CellData *) row->ElementAt(colX);
|
|
|
|
if (data) {
|
|
|
|
// Adjust the column counts.
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data->IsOrig()) {
|
1999-12-14 01:56:31 +03:00
|
|
|
// Decrement the column count.
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
1999-12-14 01:56:31 +03:00
|
|
|
colInfo->mNumCellsOrig--;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// colspan=0 is only counted as a spanned cell in the 1st col it spans
|
2000-01-13 08:29:38 +03:00
|
|
|
else if (data->IsColSpan()) {
|
|
|
|
if ( (!data->IsZeroColSpan()) ||
|
2000-02-01 06:23:29 +03:00
|
|
|
((data->IsZeroColSpan()) && (rowX == aStartRowIndex) && (!IsZeroColSpan(rowX, colX - 1)))) {
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
|
|
|
colInfo->mNumCellsSpan--;
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete our row information.
|
|
|
|
for (colX = 0; colX < colCount; colX++) {
|
|
|
|
CellData* data = (CellData *)(row->ElementAt(colX));
|
|
|
|
if (data) {
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mRows.RemoveElementAt(rowX);
|
|
|
|
delete row;
|
|
|
|
|
|
|
|
// Decrement our row and next available index counts.
|
|
|
|
mRowCount--;
|
|
|
|
}
|
2001-05-17 16:40:27 +04:00
|
|
|
aMap.RemoveColsAtEnd();
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 nsCellMap::GetColSpanForNewCell(nsTableCellFrame& aCellFrameToAdd,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRInt32 aNumColsInTable,
|
|
|
|
PRBool& aIsZeroColSpan)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
|
|
|
aIsZeroColSpan = PR_FALSE;
|
|
|
|
PRInt32 colSpan = aCellFrameToAdd.GetColSpan();
|
|
|
|
if (0 == colSpan) {
|
2000-02-01 06:23:29 +03:00
|
|
|
// use a min value for a zero colspan to make computations easier elsewhere
|
|
|
|
colSpan = PR_MAX(MIN_NUM_COLS_FOR_ZERO_COLSPAN, aNumColsInTable - aColIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
aIsZeroColSpan = PR_TRUE;
|
|
|
|
}
|
|
|
|
return colSpan;
|
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 nsCellMap::GetEffectiveColSpan(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool& aZeroColSpan)
|
2000-01-04 08:31:56 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
2000-01-13 08:29:38 +03:00
|
|
|
aZeroColSpan = PR_FALSE;
|
2000-01-04 08:31:56 +03:00
|
|
|
PRInt32 colSpan = 1;
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aRowIndex));
|
2000-01-13 08:29:38 +03:00
|
|
|
if (row) {
|
|
|
|
PRInt32 colX;
|
|
|
|
CellData* data;
|
2001-10-26 06:30:38 +04:00
|
|
|
PRInt32 maxCols = numColsInTable;
|
|
|
|
PRBool hitOverlap = PR_FALSE;
|
|
|
|
for (colX = aColIndex + 1; colX < maxCols; colX++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
data = GetMapCellAt(aMap, aRowIndex, colX, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data) {
|
2001-10-26 06:30:38 +04:00
|
|
|
// for an overlapping situation get the colspan from the originating cell and
|
|
|
|
// use that as the max number of cols to iterate. Since this is rare, only
|
|
|
|
// pay the price of looking up the cell's colspan here.
|
|
|
|
if (!hitOverlap && data->IsOverlap()) {
|
|
|
|
CellData* origData = GetMapCellAt(aMap, aRowIndex, aColIndex, PR_TRUE);
|
|
|
|
if (origData->IsOrig()) {
|
|
|
|
nsTableCellFrame* cellFrame = origData->GetCellFrame();
|
|
|
|
if (cellFrame) {
|
|
|
|
// possible change the number of colums to iterate
|
|
|
|
maxCols = PR_MIN(aColIndex + cellFrame->GetColSpan(), maxCols);
|
|
|
|
if (colX >= maxCols)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data->IsColSpan()) {
|
|
|
|
colSpan++;
|
|
|
|
if (data->IsZeroColSpan()) {
|
|
|
|
aZeroColSpan = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
2000-01-04 08:31:56 +03:00
|
|
|
}
|
|
|
|
return colSpan;
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32
|
2000-02-01 06:23:29 +03:00
|
|
|
nsCellMap::GetRowSpanForNewCell(nsTableCellFrame& aCellFrameToAdd,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRBool& aIsZeroRowSpan)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
|
|
|
aIsZeroRowSpan = PR_FALSE;
|
|
|
|
PRInt32 rowSpan = aCellFrameToAdd.GetRowSpan();
|
|
|
|
if (0 == rowSpan) {
|
|
|
|
// use a min value of 2 for a zero rowspan to make computations easier elsewhere
|
|
|
|
rowSpan = PR_MAX(2, mRows.Count() - aRowIndex);
|
|
|
|
aIsZeroRowSpan = PR_TRUE;
|
|
|
|
}
|
|
|
|
return rowSpan;
|
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 nsCellMap::GetRowSpan(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool aGetEffective,
|
|
|
|
PRBool& aZeroRowSpan)
|
2000-01-04 08:31:56 +03:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
aZeroRowSpan = PR_FALSE;
|
2000-01-04 08:31:56 +03:00
|
|
|
PRInt32 rowSpan = 1;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowCount = (aGetEffective) ? mRowCount : mRows.Count();
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 rowX;
|
|
|
|
for (rowX = aRowIndex + 1; rowX < rowCount; rowX++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* data = GetMapCellAt(aMap, rowX, aColIndex, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data) {
|
|
|
|
if (data->IsRowSpan()) {
|
|
|
|
rowSpan++;
|
|
|
|
if (data->IsZeroRowSpan()) {
|
|
|
|
aZeroRowSpan = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2000-01-04 08:31:56 +03:00
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
if (aZeroRowSpan && (rowX < rowCount)) {
|
2000-01-13 08:29:38 +03:00
|
|
|
rowSpan += rowCount - rowX;
|
|
|
|
}
|
2000-01-04 08:31:56 +03:00
|
|
|
return rowSpan;
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::ShrinkWithoutCell(nsTableCellMap& aMap,
|
|
|
|
nsTableCellFrame& aCellFrame,
|
1999-12-14 01:56:31 +03:00
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
|
|
|
{
|
2000-01-04 08:31:56 +03:00
|
|
|
PRInt32 colX, rowX;
|
|
|
|
|
|
|
|
// get the rowspan and colspan from the cell map since the content may have changed
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool zeroRowSpan, zeroColSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
|
|
|
PRInt32 rowSpan = GetRowSpan(aMap, aRowIndex, aColIndex, PR_FALSE, zeroRowSpan);
|
|
|
|
PRInt32 colSpan = GetEffectiveColSpan(aMap, aRowIndex, aColIndex, zeroColSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
PRInt32 endRowIndex = aRowIndex + rowSpan - 1;
|
|
|
|
PRInt32 endColIndex = aColIndex + colSpan - 1;
|
|
|
|
|
|
|
|
// adjust the col counts due to the deleted cell before removing it
|
|
|
|
for (colX = aColIndex; colX <= endColIndex; colX++) {
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
1999-12-14 01:56:31 +03:00
|
|
|
if (colX == aColIndex) {
|
|
|
|
colInfo->mNumCellsOrig--;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// a colspan=0 cell is only counted as a spanner in the 1st col it spans
|
|
|
|
else if (!zeroColSpan || (zeroColSpan && (colX == aColIndex + 1))) {
|
1999-12-14 01:56:31 +03:00
|
|
|
colInfo->mNumCellsSpan--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the deleted cell and cellData entries for it
|
|
|
|
for (rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
2000-01-04 08:31:56 +03:00
|
|
|
for (colX = endColIndex; colX >= aColIndex; colX--) {
|
1999-12-14 01:56:31 +03:00
|
|
|
row->RemoveElementAt(colX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
numCols = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// update the row and col info due to shifting
|
|
|
|
for (rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
2000-01-03 03:56:12 +03:00
|
|
|
for (colX = aColIndex; colX < numCols - colSpan; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
|
|
|
if (data) {
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data->IsOrig()) {
|
1999-12-14 01:56:31 +03:00
|
|
|
// a cell that gets moved to the left needs adjustment in its new location
|
2000-01-13 08:29:38 +03:00
|
|
|
data->GetCellFrame()->SetColIndex(colX);
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
1999-12-14 01:56:31 +03:00
|
|
|
colInfo->mNumCellsOrig++;
|
|
|
|
// a cell that gets moved to the left needs adjustment in its old location
|
2000-01-13 08:29:38 +03:00
|
|
|
colInfo = aMap.GetColInfoAt(colX + colSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
if (colInfo) {
|
|
|
|
colInfo->mNumCellsOrig--;
|
|
|
|
}
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// a colspan=0 cell is only counted as a spanner in the 1st col it spans
|
2000-01-13 08:29:38 +03:00
|
|
|
else if (data->IsColSpan()) {
|
|
|
|
if ( (!data->IsZeroColSpan()) ||
|
2000-02-01 06:23:29 +03:00
|
|
|
((data->IsZeroColSpan()) && (rowX == aRowIndex) && (!IsZeroColSpan(rowX, colX - 1)))) {
|
2000-01-13 08:29:38 +03:00
|
|
|
// a cell that gets moved to the left needs adjustment in its new location
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
|
|
|
colInfo->mNumCellsSpan++;
|
|
|
|
// a cell that gets moved to the left needs adjustment in its old location
|
|
|
|
colInfo = aMap.GetColInfoAt(colX + colSpan);
|
|
|
|
if (colInfo) {
|
|
|
|
colInfo->mNumCellsSpan--;
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-17 16:40:27 +04:00
|
|
|
aMap.RemoveColsAtEnd();
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void
|
|
|
|
nsCellMap::RemoveCol(PRInt32 aColIndex)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numMapRows = mRows.Count();
|
|
|
|
// remove the col from each of the rows
|
|
|
|
for (PRInt32 rowX = 0; rowX < numMapRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
|
|
|
CellData* data = (CellData*) row->ElementAt(aColIndex);
|
|
|
|
row->RemoveElementAt(aColIndex);
|
|
|
|
delete data;
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-22 04:16:50 +03:00
|
|
|
nsCellMap::RebuildConsideringRows(nsIPresContext* aPresContext,
|
|
|
|
nsTableCellMap& aMap,
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 aStartRowIndex,
|
|
|
|
nsVoidArray* aRowsToInsert,
|
|
|
|
PRBool aNumRowsToRemove)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
// copy the old cell map into a new array
|
|
|
|
PRInt32 numOrigRows = mRows.Count();
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numOrigCols = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
void** origRows = new void*[numOrigRows];
|
|
|
|
if (!origRows) return;
|
2000-01-03 03:56:12 +03:00
|
|
|
PRInt32 rowX, colX;
|
1999-12-14 01:56:31 +03:00
|
|
|
// copy the orig rows
|
|
|
|
for (rowX = 0; rowX < numOrigRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
|
|
|
origRows[rowX] = row;
|
|
|
|
}
|
2000-01-03 03:56:12 +03:00
|
|
|
for (colX = 0; colX < numOrigCols; colX++) {
|
2000-01-13 08:29:38 +03:00
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(colX);
|
1999-12-14 01:56:31 +03:00
|
|
|
colInfo->mNumCellsOrig = 0;
|
|
|
|
}
|
|
|
|
mRows.Clear();
|
|
|
|
mRowCount = 0;
|
2000-01-13 08:29:38 +03:00
|
|
|
if (aRowsToInsert) {
|
|
|
|
Grow(aMap, numOrigRows);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// put back the rows before the affected ones just as before
|
|
|
|
for (rowX = 0; rowX < aStartRowIndex; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)origRows[rowX];
|
|
|
|
PRInt32 numCols = row->Count();
|
2000-01-03 03:56:12 +03:00
|
|
|
for (colX = 0; colX < numCols; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
// put in the original cell from the cell map
|
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data && data->IsOrig()) {
|
|
|
|
AppendCell(aMap, *data->GetCellFrame(), rowX, PR_FALSE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRInt32 copyStartRowIndex;
|
|
|
|
if (aRowsToInsert) {
|
|
|
|
// add in the new cells and create rows if necessary
|
|
|
|
PRInt32 numNewRows = aRowsToInsert->Count();
|
|
|
|
rowX = aStartRowIndex;
|
|
|
|
for (PRInt32 newRowX = 0; newRowX < numNewRows; newRowX++) {
|
|
|
|
nsTableRowFrame* rFrame = (nsTableRowFrame *)aRowsToInsert->ElementAt(newRowX);
|
|
|
|
nsIFrame* cFrame = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
rFrame->FirstChild(aPresContext, nsnull, &cFrame);
|
1999-12-14 01:56:31 +03:00
|
|
|
while (cFrame) {
|
|
|
|
nsIAtom* cFrameType;
|
|
|
|
cFrame->GetFrameType(&cFrameType);
|
|
|
|
if (nsLayoutAtoms::tableCellFrame == cFrameType) {
|
2000-01-13 08:29:38 +03:00
|
|
|
AppendCell(aMap, (nsTableCellFrame &)*cFrame, rowX, PR_FALSE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(cFrameType);
|
|
|
|
cFrame->GetNextSibling(&cFrame);
|
|
|
|
}
|
|
|
|
rowX++;
|
|
|
|
}
|
|
|
|
copyStartRowIndex = aStartRowIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rowX = aStartRowIndex;
|
|
|
|
copyStartRowIndex = aStartRowIndex + aNumRowsToRemove;
|
|
|
|
}
|
|
|
|
// put back the rows after the affected ones just as before
|
|
|
|
PRInt32 copyEndRowIndex = numOrigRows - 1;
|
|
|
|
for (PRInt32 copyRowX = copyStartRowIndex; copyRowX <= copyEndRowIndex; copyRowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)origRows[copyRowX];
|
|
|
|
PRInt32 numCols = row->Count();
|
2000-01-03 03:56:12 +03:00
|
|
|
for (colX = 0; colX < numCols; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
// put in the original cell from the cell map
|
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data && data->IsOrig()) {
|
|
|
|
AppendCell(aMap, *data->GetCellFrame(), rowX, PR_FALSE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rowX++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the old cell map
|
|
|
|
for (rowX = 0; rowX < numOrigRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)origRows[rowX];
|
|
|
|
PRInt32 len = row->Count();
|
2000-01-03 03:56:12 +03:00
|
|
|
for (colX = 0; colX < len; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
delete row;
|
|
|
|
}
|
|
|
|
delete [] origRows;
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::RebuildConsideringCells(nsTableCellMap& aMap,
|
|
|
|
nsVoidArray* aCellFrames,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool aInsert)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
// copy the old cell map into a new array
|
2000-03-16 05:21:43 +03:00
|
|
|
PRInt32 mRowCountOrig = mRowCount;
|
|
|
|
PRInt32 numOrigRows = mRows.Count();
|
|
|
|
PRInt32 numOrigCols = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
void** origRows = new void*[numOrigRows];
|
|
|
|
if (!origRows) return;
|
|
|
|
PRInt32 rowX;
|
|
|
|
for (rowX = 0; rowX < numOrigRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowX);
|
|
|
|
origRows[rowX] = row;
|
|
|
|
}
|
|
|
|
// reinitialize data members
|
|
|
|
mRows.Clear();
|
|
|
|
mRowCount = 0;
|
2000-03-16 05:21:43 +03:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
Grow(aMap, numOrigRows);
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
PRInt32 numNewCells = (aCellFrames) ? aCellFrames->Count() : 0;
|
|
|
|
// build the new cell map
|
|
|
|
for (rowX = 0; rowX < numOrigRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)origRows[rowX];
|
2000-01-13 08:29:38 +03:00
|
|
|
for (PRInt32 colX = 0; colX < numOrigCols; colX++) {
|
1999-12-14 01:56:31 +03:00
|
|
|
if ((rowX == aRowIndex) && (colX == aColIndex)) {
|
|
|
|
if (aInsert) { // put in the new cells
|
|
|
|
for (PRInt32 cellX = 0; cellX < numNewCells; cellX++) {
|
|
|
|
nsTableCellFrame* cell = (nsTableCellFrame*)aCellFrames->ElementAt(cellX);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cell) {
|
|
|
|
AppendCell(aMap, *cell, rowX, PR_FALSE);
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue; // do not put the deleted cell back
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// put in the original cell from the cell map
|
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data && data->IsOrig()) {
|
|
|
|
AppendCell(aMap, *data->GetCellFrame(), rowX, PR_FALSE);
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-16 05:21:43 +03:00
|
|
|
// For for cell deletion, since the row is not being deleted,
|
|
|
|
// keep mRowCount the same as before.
|
|
|
|
if (!aInsert) {
|
|
|
|
mRowCount = mRowCountOrig;
|
|
|
|
}
|
|
|
|
|
1999-12-14 01:56:31 +03:00
|
|
|
// delete the old cell map
|
|
|
|
for (rowX = 0; rowX < numOrigRows; rowX++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)origRows[rowX];
|
|
|
|
PRInt32 len = row->Count();
|
|
|
|
for (PRInt32 colX = 0; colX < len; colX++) {
|
|
|
|
CellData* data = (CellData*) row->ElementAt(colX);
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
delete row;
|
|
|
|
}
|
|
|
|
delete [] origRows;
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
void nsCellMap::RemoveCell(nsTableCellMap& aMap,
|
|
|
|
nsTableCellFrame* aCellFrame,
|
2000-01-04 08:31:56 +03:00
|
|
|
PRInt32 aRowIndex)
|
1999-12-14 01:56:31 +03:00
|
|
|
{
|
|
|
|
PRInt32 numRows = mRows.Count();
|
|
|
|
if ((aRowIndex < 0) || (aRowIndex >= numRows)) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "bad arg in nsCellMap::RemoveCell");
|
|
|
|
return;
|
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 numCols = aMap.GetColCount();
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
// get the starting col index of the cell to remove
|
|
|
|
PRInt32 startColIndex;
|
|
|
|
for (startColIndex = 0; startColIndex < numCols; startColIndex++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* data = GetMapCellAt(aMap, aRowIndex, startColIndex, PR_FALSE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data && (data->IsOrig()) && (aCellFrame == data->GetCellFrame())) {
|
1999-12-14 01:56:31 +03:00
|
|
|
break; // we found the col index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool isZeroRowSpan;
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 rowSpan = GetRowSpan(aMap, aRowIndex, startColIndex, PR_FALSE, isZeroRowSpan);
|
1999-12-14 01:56:31 +03:00
|
|
|
// record whether removing the cells is going to cause complications due
|
|
|
|
// to existing row spans, col spans or table sizing.
|
2000-03-16 05:21:43 +03:00
|
|
|
PRBool spansCauseRebuild = CellsSpanInOrOut(aMap, aRowIndex, aRowIndex + rowSpan - 1,
|
|
|
|
startColIndex, numCols - 1);
|
2001-01-13 02:07:54 +03:00
|
|
|
// XXX if the cell has a col span to the end of the map, and the end has no originating
|
|
|
|
// cells, we need to assume that this the only such cell, and rebuild so that there are
|
|
|
|
// no extraneous cols at the end. The same is true for removing rows.
|
1999-12-14 01:56:31 +03:00
|
|
|
|
|
|
|
if (spansCauseRebuild) {
|
2000-01-13 08:29:38 +03:00
|
|
|
RebuildConsideringCells(aMap, nsnull, aRowIndex, startColIndex, PR_FALSE);
|
1999-08-26 01:49:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
ShrinkWithoutCell(aMap, *aCellFrame, aRowIndex, startColIndex);
|
1999-08-26 01:49:18 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void nsCellMap::Dump() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n ***** START GROUP CELL MAP DUMP ***** %p\n", this);
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 mapRowCount = mRows.Count();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" mapRowCount=%d tableRowCount=%d \n", mapRowCount, mRowCount);
|
1999-07-28 12:09:02 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 rowIndex, colIndex;
|
1999-08-26 01:49:18 +04:00
|
|
|
for (rowIndex = 0; rowIndex < mapRowCount; rowIndex++) {
|
1999-07-28 12:09:02 +04:00
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rowIndex);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" row %d : ", rowIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 colCount = row->Count();
|
1999-07-28 12:09:02 +04:00
|
|
|
for (colIndex = 0; colIndex < colCount; colIndex++) {
|
|
|
|
CellData* cd = (CellData *)row->ElementAt(colIndex);
|
|
|
|
if (cd) {
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd->IsOrig()) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("C%d,%d ", rowIndex, colIndex);
|
1999-07-28 12:09:02 +04:00
|
|
|
} else {
|
1999-08-19 23:52:37 +04:00
|
|
|
nsTableCellFrame* cell = nsnull;
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd->IsRowSpan()) {
|
|
|
|
cell = GetCellFrame(rowIndex, colIndex, *cd, PR_TRUE);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("R ");
|
1999-08-19 23:52:37 +04:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd->IsColSpan()) {
|
|
|
|
cell = GetCellFrame(rowIndex, colIndex, *cd, PR_FALSE);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("C ");
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
if (!(cd->IsRowSpan() && cd->IsColSpan())) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("---- ");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-09-01 01:23:28 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-09 02:07:15 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// output info mapping Ci,j to cell address
|
|
|
|
PRInt32 cellCount = 0;
|
|
|
|
for (PRInt32 rIndex = 0; rIndex < mapRowCount; rIndex++) {
|
|
|
|
nsVoidArray* row = (nsVoidArray *)mRows.ElementAt(rIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
PRInt32 colCount = row->Count();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-07-28 12:09:02 +04:00
|
|
|
for (colIndex = 0; colIndex < colCount; colIndex++) {
|
|
|
|
CellData* cd = (CellData *)row->ElementAt(colIndex);
|
|
|
|
if (cd) {
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd->IsOrig()) {
|
|
|
|
nsTableCellFrame* cellFrame = cd->GetCellFrame();
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 cellFrameColIndex;
|
|
|
|
cellFrame->GetColIndex(cellFrameColIndex);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("C%d,%d=%p(%d) ", rIndex, colIndex, cellFrame, cellFrameColIndex);
|
1999-07-28 12:09:02 +04:00
|
|
|
cellCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ***** END GROUP CELL MAP DUMP *****\n");
|
1998-09-01 01:23:28 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
#endif
|
1998-09-01 01:23:28 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
PRBool
|
|
|
|
nsCellMap::IsZeroColSpan(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex) const
|
1998-09-01 01:23:28 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
nsVoidArray* row = (nsVoidArray*)mRows.ElementAt(aRowIndex);
|
|
|
|
if (row) {
|
|
|
|
CellData* data = (CellData*)row->ElementAt(aColIndex);
|
|
|
|
if (data && data->IsZeroColSpan()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-02-01 06:23:29 +03:00
|
|
|
nsCellMap::AdjustForZeroSpan(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
|
|
|
CellData* data = GetMapCellAt(aMap, aRowIndex, aColIndex, PR_FALSE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
nsTableCellFrame* cell = (data->IsOrig()) ? data->GetCellFrame() : nsnull;
|
|
|
|
if (!cell) return;
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 cellRowSpan = cell->GetRowSpan();
|
|
|
|
PRInt32 cellColSpan = cell->GetColSpan();
|
|
|
|
|
|
|
|
PRInt32 endRowIndex = (0 == cell->GetRowSpan()) ? mRows.Count() - 1 : aRowIndex + cellRowSpan - 1;
|
|
|
|
PRInt32 endColIndex = (0 == cell->GetColSpan()) ? numColsInTable - 1 : aColIndex + cellColSpan - 1;
|
|
|
|
// if there is both a rowspan=0 and colspan=0 then only expand the cols to a minimum
|
|
|
|
if ((0 == cellRowSpan) && (0 == cellColSpan)) {
|
|
|
|
endColIndex = aColIndex + MIN_NUM_COLS_FOR_ZERO_COLSPAN - 1;
|
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
|
|
|
|
// Create span CellData objects filling out the rows to the end of the
|
|
|
|
// map if the rowspan is 0, and/or filling out the cols to the end of
|
2000-02-01 06:23:29 +03:00
|
|
|
// table if the colspan is 0. If there is both a rowspan=0 and colspan=0
|
|
|
|
// then only fill out the cols to a minimum value.
|
|
|
|
for (PRInt32 colX = aColIndex; colX <= endColIndex; colX++) {
|
|
|
|
PRInt32 rowX;
|
|
|
|
// check to see if there is any cells originating after the cols
|
|
|
|
PRBool cellsOrig = PR_FALSE;
|
|
|
|
if (colX >= aColIndex + MIN_NUM_COLS_FOR_ZERO_COLSPAN - 1) {
|
|
|
|
for (rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
2000-03-15 07:50:25 +03:00
|
|
|
CellData* cellData = GetMapCellAt(aMap, rowX, colX, PR_FALSE);
|
|
|
|
if (cellData && cellData->IsOrig()) {
|
2000-02-01 06:23:29 +03:00
|
|
|
cellsOrig = PR_TRUE;
|
|
|
|
break; // there are cells in this col, so don't consider it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cellsOrig) break;
|
|
|
|
for (rowX = aRowIndex; rowX <= endRowIndex; rowX++) {
|
|
|
|
if ((colX > aColIndex) || (rowX > aRowIndex)) {
|
|
|
|
CellData* oldData = GetMapCellAt(aMap, rowX, colX, PR_FALSE);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (!oldData) {
|
|
|
|
CellData* newData = new CellData(nsnull);
|
|
|
|
if (!newData) return;
|
|
|
|
if (colX > aColIndex) {
|
|
|
|
newData->SetColSpanOffset(colX - aColIndex);
|
|
|
|
newData->SetZeroColSpan(PR_TRUE);
|
|
|
|
}
|
|
|
|
if (rowX > aRowIndex) {
|
|
|
|
newData->SetRowSpanOffset(rowX - aRowIndex);
|
|
|
|
newData->SetZeroRowSpan(PR_TRUE);
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
// colspan=0 is only counted as spanning the 1st col to the right of its origin
|
|
|
|
SetMapCellAt(aMap, *newData, rowX, colX, (colX == aColIndex + 1));
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-12-14 01:56:31 +03:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CellData*
|
2000-02-01 06:23:29 +03:00
|
|
|
nsCellMap::GetMapCellAt(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aMapRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool aUpdateZeroSpan)
|
2000-01-13 08:29:38 +03:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
|
|
|
if ((aMapRowIndex < 0) || (aMapRowIndex >= mRows.Count())) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aMapRowIndex));
|
2000-02-01 06:23:29 +03:00
|
|
|
if (!row) return nsnull;
|
|
|
|
|
|
|
|
CellData* data = (CellData *)(row->ElementAt(aColIndex));
|
|
|
|
if (!data && aUpdateZeroSpan) {
|
|
|
|
PRBool didZeroExpand = PR_FALSE;
|
|
|
|
// check for special zero row span
|
|
|
|
PRInt32 prevRowX = aMapRowIndex - 1;
|
|
|
|
// find the last non null data in the same col
|
|
|
|
for ( ; prevRowX > 0; prevRowX--) {
|
|
|
|
nsVoidArray* prevRow = (nsVoidArray *)(mRows.ElementAt(prevRowX));
|
|
|
|
CellData* prevData = (CellData *)(prevRow->ElementAt(aColIndex));
|
|
|
|
if (prevData) {
|
|
|
|
if (prevData->IsZeroRowSpan()) {
|
|
|
|
PRInt32 rowIndex = prevRowX - prevData->GetRowSpanOffset();
|
|
|
|
PRInt32 colIndex = 0;
|
|
|
|
// if there is a colspan and no overlap then the rowspan offset
|
|
|
|
// and colspan offset point to the same cell
|
|
|
|
if ((prevData->IsColSpan()) && (!prevData->IsOverlap())) {
|
|
|
|
colIndex = prevData->GetColSpanOffset();
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
AdjustForZeroSpan(aMap, rowIndex, colIndex);
|
|
|
|
didZeroExpand = PR_TRUE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
break;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for special zero col span
|
|
|
|
if (!didZeroExpand && (aColIndex > 0) && (aColIndex < numColsInTable)) {
|
|
|
|
PRInt32 prevColX = aColIndex - 1;
|
|
|
|
// find the last non null data in the same row
|
|
|
|
for ( ; prevColX > 0; prevColX--) {
|
|
|
|
CellData* prevData = GetMapCellAt(aMap, aMapRowIndex, prevColX, PR_FALSE);
|
|
|
|
if (prevData) {
|
|
|
|
if (prevData->IsZeroColSpan()) {
|
|
|
|
PRInt32 colIndex = prevColX - prevData->GetColSpanOffset();
|
|
|
|
// if there were also a rowspan, it would have been handled above
|
|
|
|
AdjustForZeroSpan(aMap, aMapRowIndex, colIndex);
|
|
|
|
didZeroExpand = PR_TRUE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
break;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
|
|
|
|
// if zero span adjustments were made the data may be available now
|
|
|
|
if (!data && didZeroExpand) {
|
|
|
|
data = GetMapCellAt(aMap, aMapRowIndex, aColIndex, PR_FALSE);
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
2000-01-13 08:29:38 +03:00
|
|
|
return data;
|
1998-09-01 01:23:28 +04:00
|
|
|
}
|
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
CellData*
|
2000-02-01 06:23:29 +03:00
|
|
|
nsCellMap::GetCellAt(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex)
|
1998-09-01 01:23:28 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
if ((0 > aRowIndex) || (aRowIndex >= mRowCount)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
return GetMapCellAt(aMap, aRowIndex, aColIndex, PR_TRUE);
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
// only called if the cell at aMapRowIndex, aColIndex is null
|
|
|
|
void nsCellMap::SetMapCellAt(nsTableCellMap& aMap,
|
|
|
|
CellData& aNewCell,
|
|
|
|
PRInt32 aMapRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
PRBool aCountZeroSpanAsSpan)
|
|
|
|
{
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aMapRowIndex));
|
|
|
|
if (row) {
|
|
|
|
// the table map may need cols added
|
|
|
|
PRInt32 numColsToAdd = aColIndex + 1 - aMap.GetColCount();
|
|
|
|
if (numColsToAdd > 0) {
|
|
|
|
aMap.AddColsAtEnd(numColsToAdd);
|
|
|
|
}
|
|
|
|
// the row may need cols added
|
|
|
|
numColsToAdd = aColIndex + 1 - row->Count();
|
|
|
|
if (numColsToAdd > 0) {
|
|
|
|
GrowRow(*row, numColsToAdd);
|
|
|
|
}
|
|
|
|
row->ReplaceElementAt(&aNewCell, aColIndex);
|
|
|
|
// update the originating cell counts if cell originates in this row, col
|
|
|
|
nsColInfo* colInfo = aMap.GetColInfoAt(aColIndex);
|
|
|
|
if (colInfo) {
|
|
|
|
if (aNewCell.IsOrig()) {
|
|
|
|
colInfo->mNumCellsOrig++;
|
|
|
|
}
|
|
|
|
else if ((aNewCell.IsColSpan()) &&
|
|
|
|
(!aNewCell.IsZeroColSpan() || aCountZeroSpanAsSpan)) {
|
|
|
|
colInfo->mNumCellsSpan++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "SetMapCellAt called with col index > table map num cols");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "SetMapCellAt called with row index > num rows");
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
2000-01-13 08:29:38 +03:00
|
|
|
nsTableCellFrame*
|
2000-02-01 06:23:29 +03:00
|
|
|
nsCellMap::GetCellInfoAt(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowX,
|
|
|
|
PRInt32 aColX,
|
|
|
|
PRBool* aOriginates,
|
|
|
|
PRInt32* aColSpan)
|
1999-08-19 23:52:37 +04:00
|
|
|
{
|
2000-01-13 08:29:38 +03:00
|
|
|
if (aOriginates) {
|
1999-08-19 23:52:37 +04:00
|
|
|
*aOriginates = PR_FALSE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* data = GetCellAt(aMap, aRowX, aColX);
|
1999-08-19 23:52:37 +04:00
|
|
|
nsTableCellFrame* cellFrame = nsnull;
|
|
|
|
if (data) {
|
2000-01-13 08:29:38 +03:00
|
|
|
if (data->IsOrig()) {
|
|
|
|
cellFrame = data->GetCellFrame();
|
1999-08-19 23:52:37 +04:00
|
|
|
if (aOriginates)
|
|
|
|
*aOriginates = PR_TRUE;
|
2000-01-15 23:10:00 +03:00
|
|
|
if (cellFrame && aColSpan) {
|
1999-08-19 23:52:37 +04:00
|
|
|
PRInt32 initialColIndex;
|
|
|
|
cellFrame->GetColIndex(initialColIndex);
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool zeroSpan;
|
|
|
|
*aColSpan = GetEffectiveColSpan(aMap, aRowX, initialColIndex, zeroSpan);
|
1999-08-19 23:52:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-01-13 08:29:38 +03:00
|
|
|
cellFrame = GetCellFrame(aRowX, aColX, *data, PR_TRUE);
|
1999-08-19 23:52:37 +04:00
|
|
|
if (aColSpan)
|
|
|
|
*aColSpan = 0;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
return cellFrame;
|
1998-06-09 02:07:15 +04:00
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
1998-07-24 20:51:16 +04:00
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool nsCellMap::RowIsSpannedInto(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex)
|
1998-09-19 02:37:14 +04:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
1999-08-23 03:56:39 +04:00
|
|
|
if ((0 > aRowIndex) || (aRowIndex >= mRowCount)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-02-01 06:23:29 +03:00
|
|
|
for (PRInt32 colIndex = 0; colIndex < numColsInTable; colIndex++) {
|
|
|
|
CellData* cd = GetCellAt(aMap, aRowIndex, colIndex);
|
1999-07-28 12:09:02 +04:00
|
|
|
if (cd) { // there's really a cell at (aRowIndex, colIndex)
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd->IsSpan()) { // the cell at (aRowIndex, colIndex) is the result of a span
|
|
|
|
if (cd->IsRowSpan() && GetCellFrame(aRowIndex, colIndex, *cd, PR_TRUE)) { // XXX why the last check
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_TRUE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_FALSE;
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool nsCellMap::RowHasSpanningCells(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aRowIndex)
|
1998-09-19 02:37:14 +04:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
1999-08-23 03:56:39 +04:00
|
|
|
if ((0 > aRowIndex) || (aRowIndex >= mRowCount)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
if (aRowIndex != mRowCount - 1) {
|
|
|
|
// aRowIndex is not the last row, so we check the next row after aRowIndex for spanners
|
2000-02-01 06:23:29 +03:00
|
|
|
for (PRInt32 colIndex = 0; colIndex < numColsInTable; colIndex++) {
|
|
|
|
CellData* cd = GetCellAt(aMap, aRowIndex, colIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd && (cd->IsOrig())) { // cell originates
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* cd2 = GetCellAt(aMap, aRowIndex + 1, colIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd2 && cd2->IsRowSpan()) { // cd2 is spanned by a row
|
|
|
|
if (cd->GetCellFrame() == GetCellFrame(aRowIndex + 1, colIndex, *cd2, PR_TRUE)) {
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_TRUE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_FALSE;
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
2000-02-01 06:23:29 +03:00
|
|
|
PRBool nsCellMap::ColHasSpanningCells(nsTableCellMap& aMap,
|
|
|
|
PRInt32 aColIndex)
|
1998-09-19 02:37:14 +04:00
|
|
|
{
|
2000-02-01 06:23:29 +03:00
|
|
|
PRInt32 numColsInTable = aMap.GetColCount();
|
|
|
|
NS_PRECONDITION (aColIndex < numColsInTable, "bad col index arg");
|
|
|
|
if ((0 > aColIndex) || (aColIndex >= numColsInTable - 1))
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_FALSE;
|
1999-08-23 03:56:39 +04:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
for (PRInt32 rowIndex = 0; rowIndex < mRowCount; rowIndex++) {
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* cd = GetCellAt(aMap, rowIndex, aColIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd && (cd->IsOrig())) { // cell originates
|
2000-02-01 06:23:29 +03:00
|
|
|
CellData* cd2 = GetCellAt(aMap, rowIndex + 1, aColIndex);
|
2000-01-13 08:29:38 +03:00
|
|
|
if (cd2 && cd2->IsColSpan()) { // cd2 is spanned by a col
|
|
|
|
if (cd->GetCellFrame() == GetCellFrame(rowIndex + 1, aColIndex, *cd2, PR_FALSE)) {
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_TRUE;
|
2000-01-13 08:29:38 +03:00
|
|
|
}
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-19 23:52:37 +04:00
|
|
|
return PR_FALSE;
|
1998-09-19 02:37:14 +04:00
|
|
|
}
|
|
|
|
|
1999-10-02 04:02:54 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void nsCellMap::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
1999-10-02 06:51:03 +04:00
|
|
|
NS_PRECONDITION(aResult, "null OUT parameter pointer");
|
1999-10-02 04:02:54 +04:00
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
|
|
|
|
// Add in the size of the void arrays. Because we have emnbedded objects
|
|
|
|
// and not pointers to void arrays, we need to subtract out the size of the
|
|
|
|
// embedded object so it isn't double counted
|
|
|
|
PRUint32 voidArraySize;
|
|
|
|
|
|
|
|
mRows.SizeOf(aHandler, &voidArraySize);
|
|
|
|
sum += voidArraySize - sizeof(mRows);
|
|
|
|
|
|
|
|
*aResult = sum;
|
|
|
|
}
|
|
|
|
#endif
|