From 7a528da36c19a8f66e368f76588ae63c8686901b Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 24 Aug 1999 08:51:55 +0000 Subject: [PATCH] More fun with keyboard navigation. git-svn-id: svn://10.0.0.236/trunk@44274 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/xul/base/src/nsTreeFrame.cpp | 6 +- .../xul/base/src/nsTreeRowGroupFrame.cpp | 62 +++++++++++++++++-- .../layout/xul/base/src/nsTreeRowGroupFrame.h | 10 ++- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/mozilla/layout/xul/base/src/nsTreeFrame.cpp b/mozilla/layout/xul/base/src/nsTreeFrame.cpp index 4a3bf86836e..5d4d159732a 100644 --- a/mozilla/layout/xul/base/src/nsTreeFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTreeFrame.cpp @@ -168,19 +168,19 @@ nsTreeFrame::HandleEvent(nsIPresContext& aPresContext, nsCOMPtr node; cellNodeList->Item(0, getter_AddRefs(node)); nsCOMPtr content = do_QueryInterface(node); - treeRowGroup->IndexOfCell(content, rowIndex, cellIndex); + treeRowGroup->IndexOfCell(aPresContext, content, rowIndex, cellIndex); } else if (cellLength == 0 && itemLength != 0) { nsCOMPtr node; itemNodeList->Item(0, getter_AddRefs(node)); nsCOMPtr content = do_QueryInterface(node); - treeRowGroup->IndexOfRow(content, rowIndex); + treeRowGroup->IndexOfRow(aPresContext, content, rowIndex); } else if (cellLength != 0 && itemLength != 0) { nsCOMPtr node; cellNodeList->Item(0, getter_AddRefs(node)); nsCOMPtr content = do_QueryInterface(node); - treeRowGroup->IndexOfCell(content, rowIndex, cellIndex); + treeRowGroup->IndexOfCell(aPresContext, content, rowIndex, cellIndex); } // We now have a valid row and cell index for the current selection. Based on the diff --git a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp index 6a8f41c56a8..8b1f0c24cac 100644 --- a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -67,7 +67,7 @@ nsTreeRowGroupFrame::nsTreeRowGroupFrame() :nsTableRowGroupFrame(), mScrollbar(nsnull), mFrameConstructor(nsnull), mTopFrame(nsnull), mBottomFrame(nsnull), mIsLazy(PR_FALSE), mIsFull(PR_FALSE), mContentChain(nsnull), mLinkupFrame(nsnull), mShouldHaveScrollbar(PR_FALSE), - mRowGroupHeight(0) + mRowGroupHeight(0), mRowCount(0), mCurrentIndex(0) { } // Destructor @@ -413,6 +413,8 @@ nsTreeRowGroupFrame::PositionChanged(nsIPresContext& aPresContext, PRInt32 aOldI if (aOldIndex == aNewIndex) return NS_OK; + mCurrentIndex = aNewIndex; + //printf("The position changed! The new index is: %d\n", aNewIndex); if (mContentChain) { @@ -655,14 +657,13 @@ nsTreeRowGroupFrame::ReflowAfterRowLayout(nsIPresContext& aPresContext, if (!mScrollbar) CreateScrollbar(aPresContext); - PRInt32 rowCount = 0; - ComputeVisibleRowCount(rowCount, mContent); // XXX This sucks! Needs to be cheap! + ComputeVisibleRowCount(mRowCount, mContent); // XXX This sucks! Needs to be cheap! // Set the maxpos of the scrollbar. nsCOMPtr scrollbarContent; mScrollbar->GetContent(getter_AddRefs(scrollbarContent)); - rowCount--; + PRInt32 rowCount = mRowCount-1; if (rowCount < 0) rowCount = 0; @@ -1093,19 +1094,51 @@ void nsTreeRowGroupFrame::CreateScrollbar(nsIPresContext& aPresContext) } void -nsTreeRowGroupFrame::IndexOfCell(nsIContent* aCellContent, PRInt32& aRowIndex, PRInt32& aColIndex) +nsTreeRowGroupFrame::IndexOfCell(nsIPresContext& aPresContext, + nsIContent* aCellContent, PRInt32& aRowIndex, PRInt32& aColIndex) { + // Get the index of our parent row. + nsCOMPtr row; + aCellContent->GetParent(*getter_AddRefs(row)); + IndexOfRow(aPresContext, row, aRowIndex); + if (aRowIndex == -1) + return; + + // To determine the column index, just ask what our indexOf is. + row->IndexOf(aCellContent, aColIndex); } void -nsTreeRowGroupFrame::IndexOfRow(nsIContent* aRowContent, PRInt32& aRowIndex) +nsTreeRowGroupFrame::IndexOfRow(nsIPresContext& aPresContext, + nsIContent* aRowContent, PRInt32& aRowIndex) { + // Use GetPrimaryFrameFor to retrieve the frame. + // This crawls only the frame tree, and will be much faster for the case + // where the frame is onscreen. + nsCOMPtr shell; + aPresContext.GetShell(getter_AddRefs(shell)); + nsIFrame* result = nsnull; + shell->GetPrimaryFrameFor(aRowContent, &result); + + if (result) { + // We found a frame. This is good news. It means we can look at our row + // index and just adjust based on our current offset index. + nsTableRowFrame* row = (nsTableRowFrame*)result; + PRInt32 screenRowIndex = row->GetRowIndex(); + aRowIndex = screenRowIndex + mCurrentIndex; + } + else { + // We didn't find a frame. This mean we have no choice but to crawl + // the row group. + } } PRBool nsTreeRowGroupFrame::IsValidRow(PRInt32 aRowIndex) { + if (aRowIndex >= 0 && aRowIndex < mRowCount) + return PR_TRUE; return PR_FALSE; } @@ -1119,6 +1152,23 @@ void nsTreeRowGroupFrame::GetCellFrameAtIndex(PRInt32 aRowIndex, PRInt32 aColIndex, nsTreeCellFrame** aResult) { + // The screen index = (aRowIndex - mCurrentIndex) + PRInt32 screenIndex = aRowIndex - mCurrentIndex; + // Get the table frame. + nsTableFrame* tableFrame; + nsTableFrame::GetTableFrame(this, tableFrame); + + nsTableCellFrame* cellFrame; + + nsCellMap * cellMap = tableFrame->GetCellMap(); + CellData* cellData = cellMap->GetCellAt(screenIndex, aColIndex); + nsRect cellRect; + if (cellData) { + cellFrame = cellData->mOrigCell; + if (cellFrame) { // the cell originates at (rowX, colX) + *aResult = (nsTreeCellFrame*)cellFrame; // XXX I am evil. + } + } } diff --git a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h index 4d8552144f3..e47b18cbcd7 100644 --- a/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h +++ b/mozilla/layout/xul/base/src/nsTreeRowGroupFrame.h @@ -119,11 +119,12 @@ public: // Tells you the row and index of a cell (given only the content node). // This method is expensive. - void IndexOfCell(nsIContent* aCellContent, PRInt32& aRowIndex, PRInt32& aColIndex); + void IndexOfCell(nsIPresContext& aPresContext, nsIContent* aCellContent, + PRInt32& aRowIndex, PRInt32& aColIndex); // Tells you the row index of a row (given only the content node). // This method is expensive. - void IndexOfRow(nsIContent* aRowContent, PRInt32& aRowIndex); + void IndexOfRow(nsIPresContext& aPresContext, nsIContent* aRowContent, PRInt32& aRowIndex); // Whether or not the row is valid. This is a cheap method, since the total row count // is cached. @@ -138,6 +139,8 @@ public: // cell is onscreen (use EnsureRowIsVisible to guarantee this). void GetCellFrameAtIndex(PRInt32 aRowIndex, PRInt32 aColIndex, nsTreeCellFrame** aResult); + PRInt32 GetVisibleRowCount() { return mRowCount; }; + protected: // Data Members nsIFrame* mTopFrame; // The current topmost frame in the view. nsIFrame* mBottomFrame; // The current bottom frame in the view. @@ -156,4 +159,7 @@ protected: // Data Members nscoord mRowGroupHeight; // The height of the row group. + PRInt32 mCurrentIndex; // Our current scrolled index. + PRInt32 mRowCount; // The current number of visible rows. + }; // class nsTreeRowGroupFrame