Back to index

lightning-sunbird  0.9+nobinonly
nsCellMap.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsCellMap_h__
00038 #define nsCellMap_h__
00039 
00040 #include "nscore.h"
00041 #include "celldata.h"
00042 #include "nsVoidArray.h"
00043 #include "nsRect.h"
00044 
00045 #undef DEBUG_TABLE_CELLMAP
00046 
00047 class nsTableColFrame;
00048 class nsTableCellFrame;
00049 class nsTableRowGroupFrame;
00050 class nsTableFrame;
00051 class nsCellMap;
00052 
00053 struct nsColInfo
00054 {
00055   PRInt32 mNumCellsOrig; // number of cells originating in the col
00056   PRInt32 mNumCellsSpan; // number of cells spanning into the col via colspans (not rowspans)
00057                          // for simplicity, a colspan=0 cell is only counted as spanning the
00058                          // 1st col to the right of where it orginates
00059   nsColInfo(); 
00060   nsColInfo(PRInt32 aNumCellsOrig,
00061             PRInt32 aNumCellsSpan);
00062 };
00063 
00064 enum Corner
00065 {
00066   eTopLeft     = 0,
00067   eTopRight    = 1,
00068   eBottomRight = 2,
00069   eBottomLeft  = 3
00070 };
00071 
00072 struct BCInfo
00073 {
00074   nsVoidArray mRightBorders;
00075   nsVoidArray mBottomBorders;
00076   BCData      mLowerRightCorner;
00077 };
00078 
00079 class nsTableCellMap
00080 {
00081 public:
00082   nsTableCellMap(nsTableFrame&   aTableFrame,
00083                  PRBool          aBorderCollapse);
00084 
00088   ~nsTableCellMap();
00089   
00090   void RemoveGroupCellMap(nsTableRowGroupFrame* aRowGroup);
00091 
00092   void InsertGroupCellMap(nsTableRowGroupFrame&  aNewRowGroup,
00093                           nsTableRowGroupFrame*& aPrevRowGroup);
00094 
00095   nsCellMap* GetMapFor(nsTableRowGroupFrame& aRowGroup);
00096 
00098   void Synchronize(nsTableFrame* aTableFrame);
00099 
00100   nsTableCellFrame* GetCellFrame(PRInt32   aRowIndex,
00101                                  PRInt32   aColIndex,
00102                                  CellData& aData,
00103                                  PRBool    aUseRowIfOverlap) const;
00104 
00106   CellData* GetDataAt(PRInt32 aRowIndex, 
00107                       PRInt32 aColIndex,
00108                       PRBool  aUpdateZeroSpan = PR_TRUE);
00109 
00110   nsColInfo* GetColInfoAt(PRInt32 aColIndex);
00111 
00114   CellData* AppendCell(nsTableCellFrame&     aCellFrame,
00115                        PRInt32               aRowIndex,
00116                        PRBool                aRebuildIfNecessary,
00117                        nsRect&               aDamageArea);
00118 
00119   void InsertCells(nsVoidArray&          aCellFrames,
00120                    PRInt32               aRowIndex,
00121                    PRInt32               aColIndexBefore,
00122                    nsRect&               aDamageArea);
00123 
00124   void RemoveCell(nsTableCellFrame* aCellFrame,
00125                   PRInt32           aRowIndex,
00126                   nsRect&           aDamageArea);
00128   void ClearCols();
00129   void InsertRows(nsTableRowGroupFrame& aRowGroup,
00130                   nsVoidArray&          aRows,
00131                   PRInt32               aFirstRowIndex,
00132                   PRBool                aConsiderSpans,
00133                   nsRect&               aDamageArea);
00134 
00135   void RemoveRows(PRInt32         aFirstRowIndex,
00136                   PRInt32         aNumRowsToRemove,
00137                   PRBool          aConsiderSpans,
00138                   nsRect&               aDamageArea);
00139 
00140   PRInt32 GetNumCellsOriginatingInRow(PRInt32 aRowIndex);
00141   PRInt32 GetNumCellsOriginatingInCol(PRInt32 aColIndex) const;
00142 
00146   PRBool HasMoreThanOneCell(PRInt32 aRowIndex);
00147 
00148   PRInt32 GetEffectiveRowSpan(PRInt32 aRowIndex,
00149                               PRInt32 aColIndex);
00150   PRInt32 GetEffectiveColSpan(PRInt32 aRowIndex,
00151                               PRInt32 aColIndex);
00152 
00154   PRInt32 GetColCount() const;
00155 
00157   PRInt32 GetRowCount() const;
00158 
00159   nsTableCellFrame* GetCellInfoAt(PRInt32  aRowX, 
00160                                   PRInt32  aColX, 
00161                                   PRBool*  aOriginates = nsnull, 
00162                                   PRInt32* aColSpan = nsnull);
00163 
00164   void AddColsAtEnd(PRUint32 aNumCols);
00165   void RemoveColsAtEnd();
00166 
00167   PRBool RowIsSpannedInto(PRInt32 aRowIndex);
00168   PRBool RowHasSpanningCells(PRInt32 aRowIndex);
00169   void RebuildConsideringCells(nsCellMap*      aCellMap,
00170                                nsVoidArray*    aCellFrames,
00171                                PRInt32         aRowIndex,
00172                                PRInt32         aColIndex,
00173                                PRBool          aInsert,
00174                                nsRect&         aDamageArea);
00175   void RebuildConsideringRows(nsCellMap*      aCellMap,
00176                               PRInt32         aStartRowIndex,
00177                               nsVoidArray*    aRowsToInsert,
00178                               PRBool          aNumRowsToRemove,
00179                               nsRect&         aDamageArea);
00180   PRBool ColIsSpannedInto(PRInt32 aColIndex);
00181   PRBool ColHasSpanningCells(PRInt32 aColIndex);
00182 
00183   BCData* GetBCData(PRUint8     aSide, 
00184                     nsCellMap&  aCellMap,
00185                     PRUint32    aYPos, 
00186                     PRUint32    aXPos,
00187                     PRBool      aIsLowerRight = PR_FALSE);
00188 
00189   void SetBCBorderEdge(PRUint8       aEdge, 
00190                        nsCellMap&    aCellMap,
00191                        PRUint32      aCellMapStart,
00192                        PRUint32      aYPos, 
00193                        PRUint32      aXPos,
00194                        PRUint32      aLength,
00195                        BCBorderOwner aOwner,
00196                        nscoord       aSize,
00197                        PRBool        aChanged);
00198 
00199   void SetBCBorderCorner(Corner      aCorner,
00200                          nsCellMap&  aCellMap,
00201                          PRUint32    aCellMapStart,
00202                          PRUint32    aYPos, 
00203                          PRUint32    aXPos,
00204                          PRUint8     aOwner,
00205                          nscoord     aSubSize,
00206                          PRBool      aBevel,
00207                          PRBool      aIsBottomRight = PR_FALSE);
00208 
00210 #ifdef NS_DEBUG
00211   void Dump(char* aString = nsnull) const;
00212 #endif
00213 
00214 protected:
00215   BCData* GetRightMostBorder(PRInt32 aRowIndex);
00216   BCData* GetBottomMostBorder(PRInt32 aColIndex);
00217 
00218   friend class nsCellMap;
00219   friend class BCMapCellIterator;
00220   friend class BCMapBorderIterator;
00225   void InsertGroupCellMap(nsCellMap* aPrevMap,
00226                           nsCellMap& aNewMap);
00227   void DeleteRightBottomBorders();
00228 
00229   nsTableFrame&   mTableFrame;
00230   nsAutoVoidArray mCols;
00231   nsCellMap*      mFirstMap;
00232   // border collapsing info
00233   BCInfo*         mBCInfo;
00234 };
00235 
00249 class nsCellMap
00250 {
00251 public:
00256   nsCellMap(nsTableRowGroupFrame& aRowGroupFrame);
00257 
00261   ~nsCellMap();
00262 
00263   nsCellMap* GetNextSibling() const;
00264   void SetNextSibling(nsCellMap* aSibling);
00265 
00266   nsTableRowGroupFrame* GetRowGroup() const;
00267 
00268   nsTableCellFrame* GetCellFrame(PRInt32   aRowIndex,
00269                                  PRInt32   aColIndex,
00270                                  CellData& aData,
00271                                  PRBool    aUseRowSpanIfOverlap) const;
00272 
00291   CellData* AppendCell(nsTableCellMap&   aMap,
00292                        nsTableCellFrame* aCellFrame, 
00293                        PRInt32           aRowIndex,
00294                        PRBool            aRebuildIfNecessary,
00295                        nsRect&           aDamageArea,
00296                        PRInt32*          aBeginSearchAtCol = nsnull);
00297 
00298   void InsertCells(nsTableCellMap& aMap,
00299                    nsVoidArray&    aCellFrames,
00300                    PRInt32         aRowIndex,
00301                    PRInt32         aColIndexBefore,
00302                    nsRect&         aDamageArea);
00303 
00304   void RemoveCell(nsTableCellMap&   aMap,
00305                   nsTableCellFrame* aCellFrame,
00306                   PRInt32           aRowIndex,
00307                   nsRect&           aDamageArea);
00308 
00309   void InsertRows(nsTableCellMap& aMap,
00310                   nsVoidArray&    aRows,
00311                   PRInt32         aFirstRowIndex,
00312                   PRBool          aConsiderSpans,
00313                   nsRect&         aDamageArea);
00314 
00315   void RemoveRows(nsTableCellMap& aMap,
00316                   PRInt32         aFirstRowIndex,
00317                   PRInt32         aNumRowsToRemove,
00318                   PRBool          aConsiderSpans,
00319                   nsRect&         aDamageArea);
00320 
00321   PRInt32 GetNumCellsOriginatingInRow(PRInt32 aRowIndex) const;
00322   PRInt32 GetNumCellsOriginatingInCol(PRInt32 aColIndex) const;
00323 
00325   PRInt32 GetRowCount(PRBool aConsiderDeadRowSpanRows = PR_FALSE) const;
00326 
00327   nsTableCellFrame* GetCellInfoAt(nsTableCellMap& aMap,
00328                                   PRInt32         aRowX, 
00329                                   PRInt32         aColX,
00330                                   PRBool*         aOriginates = nsnull, 
00331                                   PRInt32*        aColSpan = nsnull);
00332 
00333   PRBool RowIsSpannedInto(nsTableCellMap& aMap,
00334                           PRInt32 aRowIndex);
00335 
00336   PRBool RowHasSpanningCells(nsTableCellMap& aMap,
00337                              PRInt32         aRowIndex);
00338 
00339   PRBool ColHasSpanningCells(nsTableCellMap& aMap,
00340                              PRInt32         aColIndex);
00341 
00345   PRBool HasMoreThanOneCell(nsTableCellMap& aMap,
00346                             PRInt32         aRowIndex);
00347 
00348   PRInt32 GetRowSpan(nsTableCellMap& aMap,
00349                      PRInt32         aRowIndex,
00350                      PRInt32         aColIndex,
00351                      PRBool          aGetEffective,
00352                      PRBool&         aIsZeroRowSpan);
00353 
00354   PRInt32 GetEffectiveColSpan(nsTableCellMap& aMap,
00355                               PRInt32         aRowIndex,
00356                               PRInt32         aColIndex,
00357                               PRBool&         aIsZeroColSpan);
00358 
00360 #ifdef NS_DEBUG
00361   void Dump(PRBool aIsBorderCollapse) const;
00362 #endif
00363 
00364 protected:
00365   friend class nsTableCellMap;
00366   friend class BCMapCellIterator;
00367   friend class BCMapBorderIterator;
00368   friend class nsTableFrame;
00369 
00370   PRBool Grow(nsTableCellMap& aMap,
00371               PRInt32         aNumRows,
00372               PRInt32         aRowIndex = -1); 
00373 
00374   void GrowRow(nsVoidArray& aRow,
00375                PRInt32      aNumCols);
00376 
00378   void SetDataAt(nsTableCellMap& aMap,
00379                  CellData&       aCellData, 
00380                  PRInt32         aMapRowIndex, 
00381                  PRInt32         aColIndex,
00382                  PRBool          aCountZeroSpanAsSpan);
00383 
00384   CellData* GetDataAt(nsTableCellMap& aMap,
00385                       PRInt32         aMapRowIndex, 
00386                       PRInt32         aColIndex,
00387                       PRBool          aUpdateZeroSpan);
00388 
00389   PRInt32 GetNumCellsIn(PRInt32 aColIndex) const;
00390 
00391   void ExpandWithRows(nsTableCellMap& aMap,
00392                       nsVoidArray&    aRowFrames,
00393                       PRInt32         aStartRowIndex,
00394                       nsRect&         aDamageArea);
00395 
00396   void ExpandWithCells(nsTableCellMap& aMap,
00397                        nsVoidArray&    aCellFrames,
00398                        PRInt32         aRowIndex,
00399                        PRInt32         aColIndex,
00400                        PRInt32         aRowSpan,
00401                        PRBool          aRowSpanIsZero,
00402                        nsRect&         aDamageArea);
00403 
00404   void ShrinkWithoutRows(nsTableCellMap& aMap,
00405                          PRInt32         aFirstRowIndex,
00406                          PRInt32         aNumRowsToRemove,
00407                          nsRect&         aDamageArea);
00408 
00409   void ShrinkWithoutCell(nsTableCellMap&   aMap,
00410                          nsTableCellFrame& aCellFrame,
00411                          PRInt32           aRowIndex,
00412                          PRInt32           aColIndex,
00413                          nsRect&           aDamageArea);
00414 
00415   void RebuildConsideringRows(nsTableCellMap& aMap,
00416                               PRInt32         aStartRowIndex,
00417                               nsVoidArray*    aRowsToInsert,
00418                               PRInt32         aNumRowsToRemove,
00419                               nsRect&         aDamageArea);
00420 
00421   void RebuildConsideringCells(nsTableCellMap& aMap,
00422                                PRInt32         aNumOrigCols,
00423                                nsVoidArray*    aCellFrames,
00424                                PRInt32         aRowIndex,
00425                                PRInt32         aColIndex,
00426                                PRBool          aInsert,
00427                                nsRect&         aDamageArea);
00428 
00429   PRBool CellsSpanOut(nsVoidArray&    aNewRows);
00430  
00443   PRBool CellsSpanInOrOut(nsTableCellMap& aMap,
00444                           PRInt32         aStartRowIndex, 
00445                           PRInt32         aEndRowIndex,
00446                           PRInt32         aStartColIndex, 
00447                           PRInt32         aEndColIndex);
00448 
00449   void ExpandForZeroSpan(nsTableCellFrame* aCellFrame,
00450                          PRInt32           aNumColsInTable);
00451 
00452   PRBool CreateEmptyRow(PRInt32 aRowIndex,
00453                         PRInt32 aNumCols);
00454 
00455   PRInt32 GetRowSpanForNewCell(nsTableCellFrame& aCellFrameToAdd, 
00456                                PRInt32           aRowIndex,
00457                                PRBool&           aIsZeroRowSpan);
00458 
00459   PRInt32 GetColSpanForNewCell(nsTableCellFrame& aCellFrameToAdd, 
00460                                PRInt32           aColIndex,
00461                                PRInt32           aNumColsInTable,
00462                                PRBool&           aIsZeroColSpan);
00463     
00464   void AdjustForZeroSpan(nsTableCellMap& aMap,
00465                          PRInt32         aRowIndex,
00466                          PRInt32         aColIndex);
00467 
00468   PRBool IsZeroColSpan(PRInt32 aRowIndex,
00469                        PRInt32 aColIndex) const;
00470 
00473   nsAutoVoidArray mRows; 
00474 
00479   PRInt32 mRowCount;
00480 
00481   // the row group that corresponds to this map
00482   nsTableRowGroupFrame* mRowGroupFrame;
00483 
00484   // the next row group cell map
00485   nsCellMap* mNextSibling;
00486 
00487 };
00488 
00489 /* ----- inline methods ----- */
00490 inline PRInt32 nsTableCellMap::GetColCount() const
00491 {
00492   return mCols.Count();
00493 }
00494 
00495 inline nsCellMap* nsCellMap::GetNextSibling() const
00496 {
00497   return mNextSibling;
00498 }
00499 
00500 inline void nsCellMap::SetNextSibling(nsCellMap* aSibling)
00501 {
00502   mNextSibling = aSibling;
00503 }
00504 
00505 inline nsTableRowGroupFrame* nsCellMap::GetRowGroup() const
00506 {
00507   return mRowGroupFrame;
00508 }
00509 
00510 inline PRInt32 nsCellMap::GetRowCount(PRBool aConsiderDeadRowSpanRows) const
00511 { 
00512   PRInt32 rowCount = (aConsiderDeadRowSpanRows) ? mRows.Count() : mRowCount;
00513   return rowCount; 
00514 }
00515 
00516 // nsColInfo
00517 
00518 inline nsColInfo::nsColInfo()
00519  :mNumCellsOrig(0), mNumCellsSpan(0) 
00520 {}
00521 
00522 inline nsColInfo::nsColInfo(PRInt32 aNumCellsOrig,
00523                             PRInt32 aNumCellsSpan)
00524  :mNumCellsOrig(aNumCellsOrig), mNumCellsSpan(aNumCellsSpan) 
00525 {}
00526 
00527 
00528 #endif