mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-15 11:13:29 +00:00
Implemented selection in the tree view.
This commit is contained in:
parent
829b7f8804
commit
104e6beaba
@ -20,6 +20,7 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsTreeCellFrame.h"
|
||||
#include "nsTreeFrame.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIViewManager.h"
|
||||
@ -106,8 +107,14 @@ nsTreeCellFrame::Init(nsIPresContext& aPresContext,
|
||||
}
|
||||
else mIsHeader = PR_FALSE;
|
||||
NS_IF_RELEASE(parentContext);
|
||||
|
||||
// Get the table frame.
|
||||
pRowGroupFrame->GetParent((nsIFrame*&)mTreeFrame);
|
||||
}
|
||||
}
|
||||
|
||||
mNormalContext = aContext;
|
||||
|
||||
return nsTableCellFrame::Init(aPresContext, aContent, aParent, aContext);
|
||||
}
|
||||
|
||||
@ -155,20 +162,23 @@ nsTreeCellFrame::HandleMouseDownEvent(nsIPresContext& aPresContext,
|
||||
else
|
||||
{
|
||||
// Perform a selection
|
||||
SetSelection(aPresContext);
|
||||
|
||||
if (mSelectedContext == nsnull)
|
||||
{
|
||||
nsIAtom * selectedPseudo = NS_NewAtom(":TREE-SELECTION");
|
||||
mSelectedContext = aPresContext.ResolvePseudoStyleContextFor(mContent, selectedPseudo, mStyleContext);
|
||||
NS_RELEASE(selectedPseudo);
|
||||
}
|
||||
mTreeFrame->SetSelection(aPresContext, this);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeCellFrame::SetSelection(nsIPresContext& aPresContext)
|
||||
nsTreeCellFrame::Select(nsIPresContext& aPresContext, PRBool isSelected)
|
||||
{
|
||||
nsIAtom * selectedPseudo = NS_NewAtom(":TREE-SELECTION");
|
||||
mSelectedContext = aPresContext.ResolvePseudoStyleContextFor(mContent, selectedPseudo, mStyleContext);
|
||||
SetStyleContext(&aPresContext, mSelectedContext);
|
||||
|
||||
ForceDrawFrame(this);
|
||||
|
||||
NS_RELEASE(selectedPseudo);
|
||||
if (isSelected)
|
||||
SetStyleContext(&aPresContext, mSelectedContext);
|
||||
else SetStyleContext(&aPresContext, mNormalContext);
|
||||
|
||||
ForceDrawFrame(this);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include "nsTableCellFrame.h"
|
||||
|
||||
class nsTreeFrame;
|
||||
|
||||
class nsTreeCellFrame : public nsTableCellFrame
|
||||
{
|
||||
public:
|
||||
@ -36,6 +38,8 @@ public:
|
||||
nsIFrame* aParent,
|
||||
nsIStyleContext* aContext); // Overridden to set whether we're a column header
|
||||
|
||||
void Select(nsIPresContext& presContext, PRBool isSelected);
|
||||
|
||||
protected:
|
||||
nsTreeCellFrame();
|
||||
virtual ~nsTreeCellFrame();
|
||||
@ -44,10 +48,11 @@ protected:
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
void SetSelection(nsIPresContext& aPresContext);
|
||||
|
||||
|
||||
protected:
|
||||
// Data members
|
||||
PRBool mIsHeader; // Whether or not we're a column header
|
||||
nsIStyleContext* mSelectedContext; // The style context to use when the tree item is selected
|
||||
nsIStyleContext* mNormalContext; // The style context to use normally.
|
||||
nsTreeFrame* mTreeFrame; // Our parent tree frame.
|
||||
}; // class nsTableCellFrame
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "nsTreeFrame.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
|
||||
#include "nsTreeCellFrame.h"
|
||||
|
||||
//
|
||||
// NS_NewTreeFrame
|
||||
@ -42,10 +42,27 @@ NS_NewTreeFrame (nsIFrame*& aNewFrame)
|
||||
|
||||
// Constructor
|
||||
nsTreeFrame::nsTreeFrame()
|
||||
:nsTableFrame() {}
|
||||
:nsTableFrame() { }
|
||||
|
||||
// Destructor
|
||||
nsTreeFrame::~nsTreeFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void nsTreeFrame::SetSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
|
||||
{
|
||||
ClearSelection(aPresContext);
|
||||
mSelectedItems.AppendElement(pFrame);
|
||||
pFrame->Select(aPresContext, PR_TRUE);
|
||||
}
|
||||
|
||||
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.ElementAt(i);
|
||||
pFrame->Select(aPresContext, PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
@ -18,14 +18,23 @@
|
||||
*/
|
||||
|
||||
#include "nsTableFrame.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsTreeCellFrame;
|
||||
|
||||
class nsTreeFrame : public nsTableFrame
|
||||
{
|
||||
public:
|
||||
friend nsresult NS_NewTreeFrame(nsIFrame*& aNewFrame);
|
||||
|
||||
void SetSelection(nsIPresContext& presContext, nsTreeCellFrame* pFrame);
|
||||
void ClearSelection(nsIPresContext& presContext);
|
||||
|
||||
protected:
|
||||
nsTreeFrame();
|
||||
virtual ~nsTreeFrame();
|
||||
|
||||
protected: // Data Members
|
||||
nsVoidArray mSelectedItems; // The selected cell frames.
|
||||
|
||||
}; // class nsTableFrame
|
||||
|
Loading…
Reference in New Issue
Block a user