document the lineiterator interface and all its current flaws. Make :GetNextSiblingOnLine more efficient. bug 388700 r/sr=roc a=mtschrep
authorbmlk@gmx.de
Sat, 09 Feb 2008 09:10:58 -0800
changeset 11464 f9c93b8192819a434b625e63f356b80f6e8b7e32
parent 11463 c2baa62dd98cb86705db7a5b680cdb07885cb901
child 11465 738602c570e02199b0c2c4afb4ebed3885adcc5e
push idunknown
push userunknown
push dateunknown
reviewersmtschrep
bugs388700
milestone1.9b4pre
document the lineiterator interface and all its current flaws. Make :GetNextSiblingOnLine more efficient. bug 388700 r/sr=roc a=mtschrep
layout/tables/nsTableRowGroupFrame.cpp
layout/tables/nsTableRowGroupFrame.h
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -1776,68 +1776,17 @@ nsTableRowGroupFrame::FindFrameAt(PRInt3
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTableRowGroupFrame::GetNextSiblingOnLine(nsIFrame*& aFrame, 
                                            PRInt32    aLineNumber)
 {
   NS_ENSURE_ARG_POINTER(aFrame);
-
-  nsITableCellLayout* cellFrame;
-  nsresult result = CallQueryInterface(aFrame, &cellFrame);
-  if (NS_FAILED(result))
-    return result;
-
-  nsTableFrame* parentFrame = nsTableFrame::GetTableFrame(this);
-  if (!parentFrame)
-    return NS_ERROR_FAILURE;
-  nsTableCellMap* cellMap = parentFrame->GetCellMap();
-  if (!cellMap)
-     return NS_ERROR_FAILURE;
-
-
-  PRInt32 colIndex;
-  PRInt32& colIndexRef = colIndex;
-  cellFrame->GetColIndex(colIndexRef);
-
-  CellData* cellData = cellMap->GetDataAt(aLineNumber, colIndex + 1);
-  
-  if (!cellData)// if this isn't a valid cell, drop down and check the next line
-  {
-    cellData = cellMap->GetDataAt(aLineNumber + 1, 0);
-    if (!cellData)
-    {
-      //*aFrame = nsnull;
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  aFrame = (nsIFrame*)cellData->GetCellFrame();
-  if (!aFrame)
-  {
-    //PRInt32 numCellsInRow = cellMap->GetNumCellsOriginatingInRow(aLineNumber) - 1;
-    PRInt32 tempCol = colIndex + 1;
-    PRInt32 tempRow = aLineNumber;
-    while ((tempCol > 0) && (!aFrame))
-    {
-      tempCol--;
-      cellData = cellMap->GetDataAt(aLineNumber, tempCol);
-      aFrame = (nsIFrame*)cellData->GetCellFrame();
-      if (!aFrame && (tempCol==0))
-      {
-        while ((tempRow > 0) && (!aFrame))
-        {
-          tempRow--;
-          cellData = cellMap->GetDataAt(tempRow, 0);
-          aFrame = (nsIFrame*)cellData->GetCellFrame();
-        }
-      }
-    }
-  }
+  aFrame = aFrame->GetNextSibling();
   return NS_OK;
 }
 
 //end nsLineIterator methods
 
 static void
 DestroyFrameCursorData(void* aObject, nsIAtom* aPropertyName,
                        void* aPropertyValue, void* aData)
--- a/layout/tables/nsTableRowGroupFrame.h
+++ b/layout/tables/nsTableRowGroupFrame.h
@@ -217,40 +217,117 @@ public:
     * @param aYTotalOffset the total amount that the rowgroup is shifted up
     * @param aWidth        new width of the rowgroup
     */
   nscoord CollapseRowGroupIfNecessary(nscoord aYTotalOffset,
                                       nscoord        aWidth);
 
 // nsILineIterator methods
 public:
+  // The table row is the equivalent to a line in block layout. 
+  // The nsILineIterator assumes that a line resides in a block, this role is
+  // fullfilled by the row group. Rows in table are counted relative to the
+  // table. The row index of row corresponds to the cellmap coordinates. The
+  // number of lines in a table might be greater than the number of rows in a
+  // single row group, as there might be multiple row groups.
+   
+  /** Get the number of rows in a table
+    * @param aResult - pointer that holds the number of lines in a table
+    *                  XXX this currently returns the number of rows in a
+    *                  rowgroup rather than that of the table.
+    */
   NS_IMETHOD GetNumLines(PRInt32* aResult);
+
+  /** @see nsILineIterator.h GetDirection
+    * @param aIsRightToLeft - true if the table is rtl
+    *                         XXX returns always false
+    */
   NS_IMETHOD GetDirection(PRBool* aIsRightToLeft);
   
+  /** Return structural information about a line. 
+    * @param aLineNumber       - the index of the row relative to the table
+    *                            If the line-number is invalid then
+    *                            aFirstFrameOnLine will be nsnull and 
+    *                            aNumFramesOnLine will be zero.
+    *                            XXX this is what nsLineIterator::GetLine does
+    *                            the code here currently returns 
+    *                            NS_ERROR_FAILURE without setting the params
+    *                            as required.
+    * @param aFirstFrameOnLine - the first cell frame that originates in row
+    *                            with a rowindex that matches a line number
+    *                            XXX now this goes up to the row with cell
+    *                            that spans into this row.
+    * @param aNumFramesOnLine  - return the numbers of cells originating in
+    *                            this row
+    * @param aLineBounds       - rect of the row
+    *                            XXX currently not implemented, nothing
+    *                            is written to aLineBounds
+    * @param aLineFlags        - unused set to 0
+    */
   NS_IMETHOD GetLine(PRInt32 aLineNumber,
                      nsIFrame** aFirstFrameOnLine,
                      PRInt32* aNumFramesOnLine,
                      nsRect& aLineBounds,
                      PRUint32* aLineFlags);
   
+  /** Given a frame that's a child of the rowgroup, find which line its on.
+    * @param aFrame       - frame, should be a row
+    * @param aIndexResult - row index if this a row frame. aIndexResult will be
+    *                       set to -1 if the frame cannot be found.
+    *                       XXX currently aIndexResult is set to 0 if aFrame is
+    *                       not a row and a error code is returned to the caller
+    *                       instead.
+    */
   NS_IMETHOD FindLineContaining(nsIFrame* aFrame, PRInt32* aLineNumberResult);
+  
+  /** not implemented
+    * the function is also not called in our tree
+    */
   NS_IMETHOD FindLineAt(nscoord aY, PRInt32* aLineNumberResult);
-  
+
+  /** Find the orginating cell frame on a row that is the nearest to the
+    * coordinate X.
+    * XXX the design is completely broken if aX points to a point between 
+    * cells or in a cell that spans from rows above, the function will return
+    * NS_ERROR_FAILURE in this case.
+    * @param aLineNumber          - the index of the row relative to the table
+    * @param aX                   - X coordinate in twips relative to the
+    *                               originof the rowgroup
+    * @param aFrameFound          - pointer to the cellframe
+    * @param aXIsBeforeFirstFrame - the point is before the first originating
+    *                               cellframe
+    * @param aXIsAfterLastFrame   - the point is after the last originating
+    *                               cellframe
+    */
   NS_IMETHOD FindFrameAt(PRInt32 aLineNumber,
                          nscoord aX,
                          nsIFrame** aFrameFound,
                          PRBool* aXIsBeforeFirstFrame,
                          PRBool* aXIsAfterLastFrame);
 
 #ifdef IBMBIDI
+   /** Check whether visual and logical order of cell frames within a line are
+     * identical. As the layout will reorder them this is always the case
+     * @param aLine        - the index of the row relative to the table
+     * @param aIsReordered - returns false
+     * @param aFirstVisual - if the table is rtl first originating cell frame
+     * @param aLastVisual  - if the table is rtl last originating cell frame
+     */
+
   NS_IMETHOD CheckLineOrder(PRInt32                  aLine,
                             PRBool                   *aIsReordered,
                             nsIFrame                 **aFirstVisual,
                             nsIFrame                 **aLastVisual);
 #endif
+
+  /** Find the next originating cell frame that originates in the row.    
+    * @param aFrame      - cell frame to start with, will return the next cell
+    *                      originating in a row
+    * @param aLineNumber - the index of the row relative to the table
+    */  
   NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, PRInt32 aLineNumber);
 
   // row cursor methods to speed up searching for the row(s)
   // containing a point. The basic idea is that we set the cursor
   // property if the rows' y and yMosts are non-decreasing (considering only
   // rows with nonempty overflowAreas --- empty overflowAreas never participate
   // in event handling or painting), and the rowgroup has sufficient number of
   // rows. The cursor property points to a "recently used" row. If we get a