mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Checking in the modified tree widget. It now uses the new selection APIs on the
tree DOM element.
This commit is contained in:
parent
46340eebe5
commit
e0ed866b30
@ -276,39 +276,9 @@ nsTreeCellFrame::HandleDoubleClickEvent(nsIPresContext& aPresContext,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void nsTreeCellFrame::Select(nsIPresContext& aPresContext, PRBool isSelected, PRBool notifyForReflow)
|
||||
{
|
||||
nsCOMPtr<nsIAtom> kSelectedCellAtom(dont_AddRef(NS_NewAtom("selectedcell")));
|
||||
nsCOMPtr<nsIAtom> kSelectedRowAtom(dont_AddRef(NS_NewAtom("selectedrow")));
|
||||
nsCOMPtr<nsIAtom> kSelectedAtom(dont_AddRef(NS_NewAtom("selected")));
|
||||
|
||||
nsCOMPtr<nsIContent> rowContent;
|
||||
nsCOMPtr<nsIContent> itemContent;
|
||||
mContent->GetParent(*getter_AddRefs(rowContent));
|
||||
rowContent->GetParent(*getter_AddRefs(itemContent));
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
// We're selecting the node.
|
||||
mContent->SetAttribute(kNameSpaceID_None, kSelectedCellAtom, "true", notifyForReflow);
|
||||
rowContent->SetAttribute(kNameSpaceID_None, kSelectedRowAtom, "true", notifyForReflow);
|
||||
itemContent->SetAttribute(kNameSpaceID_None, kSelectedAtom, "true", notifyForReflow);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're deselecting the node.
|
||||
mContent->UnsetAttribute(kNameSpaceID_None, kSelectedCellAtom, notifyForReflow);
|
||||
rowContent->UnsetAttribute(kNameSpaceID_None, kSelectedRowAtom, notifyForReflow);
|
||||
itemContent->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, notifyForReflow);
|
||||
}
|
||||
}
|
||||
|
||||
void nsTreeCellFrame::Hover(nsIPresContext& aPresContext, PRBool isHover, PRBool notifyForReflow)
|
||||
{
|
||||
nsCOMPtr<nsIAtom> kHoverCellAtom(dont_AddRef(NS_NewAtom("Hovercell")));
|
||||
nsCOMPtr<nsIAtom> kHoverRowAtom(dont_AddRef(NS_NewAtom("Hoverrow")));
|
||||
nsCOMPtr<nsIAtom> kHoverAtom(dont_AddRef(NS_NewAtom("Hover")));
|
||||
nsCOMPtr<nsIAtom> kHoverAtom(dont_AddRef(NS_NewAtom("hover")));
|
||||
|
||||
nsCOMPtr<nsIContent> rowContent;
|
||||
nsCOMPtr<nsIContent> itemContent;
|
||||
@ -318,15 +288,15 @@ void nsTreeCellFrame::Hover(nsIPresContext& aPresContext, PRBool isHover, PRBool
|
||||
if (isHover)
|
||||
{
|
||||
// We're selecting the node.
|
||||
mContent->SetAttribute(kNameSpaceID_None, kHoverCellAtom, "true", notifyForReflow);
|
||||
rowContent->SetAttribute(kNameSpaceID_None, kHoverRowAtom, "true", notifyForReflow);
|
||||
mContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
|
||||
rowContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
|
||||
itemContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're deselecting the node.
|
||||
mContent->UnsetAttribute(kNameSpaceID_None, kHoverCellAtom, notifyForReflow);
|
||||
rowContent->UnsetAttribute(kNameSpaceID_None, kHoverRowAtom, notifyForReflow);
|
||||
mContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
|
||||
rowContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
|
||||
itemContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
|
||||
}
|
||||
}
|
||||
@ -334,6 +304,5 @@ void nsTreeCellFrame::Hover(nsIPresContext& aPresContext, PRBool isHover, PRBool
|
||||
NS_IMETHODIMP
|
||||
nsTreeCellFrame::Destroy(nsIPresContext& aPresContext)
|
||||
{
|
||||
mTreeFrame->RemoveFromSelection(aPresContext, this);
|
||||
return nsTableCellFrame::Destroy(aPresContext);
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ public:
|
||||
|
||||
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
|
||||
|
||||
void Select(nsIPresContext& presContext, PRBool isSelected, PRBool notifyForReflow = PR_TRUE);
|
||||
void Hover(nsIPresContext& presContext, PRBool isHover, PRBool notifyForReflow = PR_TRUE);
|
||||
|
||||
nsTableFrame* GetTreeFrame();
|
||||
|
@ -17,12 +17,14 @@
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTreeFrame.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsCSSRendering.h"
|
||||
#include "nsTreeCellFrame.h"
|
||||
#include "nsCellMap.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
|
||||
//
|
||||
// NS_NewTreeFrame
|
||||
@ -57,127 +59,49 @@ nsTreeFrame::~nsTreeFrame()
|
||||
|
||||
void nsTreeFrame::SetSelection(nsIPresContext& aPresContext, nsTreeCellFrame* aFrame)
|
||||
{
|
||||
PRInt32 count = mSelectedItems.Count();
|
||||
if (count == 1) {
|
||||
// See if we're already selected.
|
||||
nsTreeCellFrame* frame = (nsTreeCellFrame*)mSelectedItems[0];
|
||||
if (frame == aFrame)
|
||||
return;
|
||||
}
|
||||
|
||||
ClearSelection(aPresContext);
|
||||
mSelectedItems.AppendElement(aFrame);
|
||||
aFrame->Select(aPresContext, PR_TRUE);
|
||||
nsCOMPtr<nsIContent> cellContent;
|
||||
aFrame->GetContent(getter_AddRefs(cellContent));
|
||||
|
||||
nsCOMPtr<nsIContent> rowContent;
|
||||
cellContent->GetParent(*getter_AddRefs(rowContent));
|
||||
|
||||
nsCOMPtr<nsIContent> itemContent;
|
||||
rowContent->GetParent(*getter_AddRefs(itemContent));
|
||||
|
||||
nsCOMPtr<nsIDOMXULTreeElement> treeElement = do_QueryInterface(mContent);
|
||||
nsCOMPtr<nsIDOMXULElement> cellElement = do_QueryInterface(cellContent);
|
||||
nsCOMPtr<nsIDOMXULElement> itemElement = do_QueryInterface(itemContent);
|
||||
treeElement->SelectItem(itemElement);
|
||||
treeElement->SelectCell(cellElement);
|
||||
|
||||
FireChangeHandler(aPresContext);
|
||||
}
|
||||
|
||||
void nsTreeFrame::ToggleSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
|
||||
void nsTreeFrame::ToggleSelection(nsIPresContext& aPresContext, nsTreeCellFrame* aFrame)
|
||||
{
|
||||
PRInt32 inArray = mSelectedItems.IndexOf((void*)pFrame);
|
||||
if (inArray == -1)
|
||||
{
|
||||
// Add this row to our array of items.
|
||||
PRInt32 count = mSelectedItems.Count();
|
||||
if (count > 0)
|
||||
{
|
||||
// Some column is already selected. This means we want to select the
|
||||
// cell in our row that is found in this column.
|
||||
nsTreeCellFrame* pOtherFrame = (nsTreeCellFrame*)mSelectedItems[0];
|
||||
|
||||
PRInt32 colIndex;
|
||||
pOtherFrame->GetColIndex(colIndex);
|
||||
PRInt32 rowIndex;
|
||||
pFrame->GetRowIndex(rowIndex);
|
||||
nsCOMPtr<nsIContent> cellContent;
|
||||
aFrame->GetContent(getter_AddRefs(cellContent));
|
||||
|
||||
// We now need to find the cell at this particular row and column.
|
||||
// This is the cell we should really select.
|
||||
nsTableCellFrame *cellFrame = mCellMap->GetCellInfoAt(rowIndex, colIndex);
|
||||
nsCOMPtr<nsIContent> rowContent;
|
||||
cellContent->GetParent(*getter_AddRefs(rowContent));
|
||||
|
||||
// Select this cell frame.
|
||||
mSelectedItems.AppendElement(cellFrame);
|
||||
((nsTreeCellFrame*)cellFrame)->Select(aPresContext, PR_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSelectedItems.AppendElement(pFrame);
|
||||
pFrame->Select(aPresContext, PR_TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove this from our array of items.
|
||||
mSelectedItems.RemoveElementAt(inArray);
|
||||
pFrame->Select(aPresContext, PR_FALSE);
|
||||
}
|
||||
nsCOMPtr<nsIContent> itemContent;
|
||||
rowContent->GetParent(*getter_AddRefs(itemContent));
|
||||
|
||||
nsCOMPtr<nsIDOMXULTreeElement> treeElement = do_QueryInterface(mContent);
|
||||
nsCOMPtr<nsIDOMXULElement> cellElement = do_QueryInterface(cellContent);
|
||||
nsCOMPtr<nsIDOMXULElement> itemElement = do_QueryInterface(itemContent);
|
||||
|
||||
treeElement->ToggleItemSelection(itemElement);
|
||||
treeElement->ToggleCellSelection(cellElement);
|
||||
|
||||
FireChangeHandler(aPresContext);
|
||||
}
|
||||
|
||||
void nsTreeFrame::RangedSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pEndFrame)
|
||||
{
|
||||
nsTreeCellFrame* pStartFrame = nsnull;
|
||||
PRInt32 count = mSelectedItems.Count();
|
||||
if (count == 0)
|
||||
pStartFrame = pEndFrame;
|
||||
else
|
||||
pStartFrame = (nsTreeCellFrame*)mSelectedItems[0];
|
||||
|
||||
ClearSelection(aPresContext);
|
||||
|
||||
// Select all cells between the two frames, but only in the start frame's column.
|
||||
PRInt32 colIndex;
|
||||
pStartFrame->GetColIndex(colIndex); // The column index of the selection.
|
||||
PRInt32 startRow;
|
||||
pStartFrame->GetRowIndex(startRow); // The starting row for the selection.
|
||||
PRInt32 endRow;
|
||||
pEndFrame->GetRowIndex(endRow); // The ending row for the selection.
|
||||
|
||||
PRInt32 start = startRow > endRow ? endRow : startRow;
|
||||
PRInt32 end = startRow > endRow ? startRow : endRow;
|
||||
|
||||
for (PRInt32 i = start; i <= end; i++)
|
||||
{
|
||||
// Select the cell at the appropriate index
|
||||
nsTableCellFrame *cellFrame = mCellMap->GetCellInfoAt(i, colIndex);
|
||||
|
||||
// We now have the cell that should be selected.
|
||||
nsTreeCellFrame* pTreeCell = NS_STATIC_CAST(nsTreeCellFrame*, cellFrame);
|
||||
mSelectedItems.AppendElement(pTreeCell);
|
||||
pTreeCell->Select(aPresContext, PR_TRUE);
|
||||
}
|
||||
|
||||
FireChangeHandler(aPresContext);
|
||||
}
|
||||
|
||||
void nsTreeFrame::ClearSelection(nsIPresContext& aPresContext)
|
||||
{
|
||||
PRInt32 count = mSelectedItems.Count();
|
||||
for (PRInt32 i = 0; i < count; i++)
|
||||
{
|
||||
// Tell the tree cell to clear its selection.
|
||||
nsTreeCellFrame* pFrame = (nsTreeCellFrame*)mSelectedItems[i];
|
||||
pFrame->Select(aPresContext, PR_FALSE);
|
||||
}
|
||||
|
||||
mSelectedItems.Clear();
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeFrame::RemoveFromSelection(nsIPresContext& aPresContext, nsTreeCellFrame* frame)
|
||||
{
|
||||
PRInt32 count = mSelectedItems.Count();
|
||||
for (PRInt32 i = 0; i < count; i++)
|
||||
{
|
||||
// Remove the tree cell from the selection.
|
||||
nsTreeCellFrame* theFrame = (nsTreeCellFrame*)mSelectedItems[i];
|
||||
if (theFrame == frame) {
|
||||
mSelectedItems.RemoveElementAt(i);
|
||||
FireChangeHandler(aPresContext);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Re-implement!
|
||||
// FireChangeHandler(aPresContext);
|
||||
}
|
||||
|
||||
void nsTreeFrame::MoveUp(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
|
||||
@ -261,7 +185,6 @@ void nsTreeFrame::FireChangeHandler(nsIPresContext& aPresContext)
|
||||
NS_IMETHODIMP
|
||||
nsTreeFrame::Destroy(nsIPresContext& aPresContext)
|
||||
{
|
||||
ClearSelection(aPresContext);
|
||||
return nsTableFrame::Destroy(aPresContext);
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,9 @@ public:
|
||||
friend nsresult NS_NewTreeFrame(nsIFrame** aNewFrame);
|
||||
|
||||
void SetSelection(nsIPresContext& presContext, nsTreeCellFrame* pFrame);
|
||||
void ClearSelection(nsIPresContext& presContext);
|
||||
void ToggleSelection(nsIPresContext& presContext, nsTreeCellFrame* pFrame);
|
||||
void RangedSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pEndFrame);
|
||||
void RemoveFromSelection(nsIPresContext& aPresContext, nsTreeCellFrame* frame);
|
||||
|
||||
|
||||
void MoveUp(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
|
||||
void MoveDown(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
|
||||
void MoveLeft(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
|
||||
@ -59,8 +57,6 @@ protected:
|
||||
virtual ~nsTreeFrame();
|
||||
|
||||
protected: // Data Members
|
||||
nsVoidArray mSelectedItems; // The selected cell frames.
|
||||
|
||||
PRBool mSlatedForReflow; // If set, don't waste time scheduling excess reflows.
|
||||
|
||||
}; // class nsTreeFrame
|
||||
|
Loading…
Reference in New Issue
Block a user