More fun with keyboard navigation.

This commit is contained in:
hyatt%netscape.com 1999-08-24 08:51:55 +00:00
parent 895a69acc1
commit 57c8c89d89
3 changed files with 67 additions and 11 deletions

View File

@ -168,19 +168,19 @@ nsTreeFrame::HandleEvent(nsIPresContext& aPresContext,
nsCOMPtr<nsIDOMNode> node;
cellNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
treeRowGroup->IndexOfCell(content, rowIndex, cellIndex);
treeRowGroup->IndexOfCell(aPresContext, content, rowIndex, cellIndex);
}
else if (cellLength == 0 && itemLength != 0) {
nsCOMPtr<nsIDOMNode> node;
itemNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
treeRowGroup->IndexOfRow(content, rowIndex);
treeRowGroup->IndexOfRow(aPresContext, content, rowIndex);
}
else if (cellLength != 0 && itemLength != 0) {
nsCOMPtr<nsIDOMNode> node;
cellNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> 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

View File

@ -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<nsIContent> 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<nsIContent> 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<nsIPresShell> 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.
}
}
}

View File

@ -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