Added support for snapping a tree widget to a certain row height. r=pavlov
git-svn-id: svn://10.0.0.236/trunk@57990 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
bc9cf9adc0
commit
dc1f512c08
@ -367,7 +367,7 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext* aPresC
|
||||
nsSize* pKidMaxElementSize = (nsnull != aDesiredSize.maxElementSize) ? &kidMaxElementSize : nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!ContinueReflow(aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
if (!ContinueReflow(nsnull, aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
return rv;
|
||||
|
||||
nsIFrame* kidFrame;
|
||||
@ -488,7 +488,7 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext* aPresC
|
||||
if (PR_FALSE==aDoSiblings)
|
||||
break;
|
||||
|
||||
if (!ContinueReflow(aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
if (!ContinueReflow(kidFrame, aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
break;
|
||||
|
||||
// Get the next child
|
||||
|
||||
@ -190,7 +190,7 @@ public:
|
||||
|
||||
virtual PRBool RowGroupReceivesExcessSpace() { return PR_TRUE; }
|
||||
|
||||
virtual PRBool ContinueReflow(nsIPresContext* aPresContext, nscoord y, nscoord height) { return PR_TRUE; }
|
||||
virtual PRBool ContinueReflow(nsIFrame* aFrame, nsIPresContext* aPresContext, nscoord y, nscoord height) { return PR_TRUE; }
|
||||
|
||||
void GetMaxElementSize(nsSize& aMaxElementSize) const;
|
||||
|
||||
|
||||
@ -367,7 +367,7 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext* aPresC
|
||||
nsSize* pKidMaxElementSize = (nsnull != aDesiredSize.maxElementSize) ? &kidMaxElementSize : nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!ContinueReflow(aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
if (!ContinueReflow(nsnull, aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
return rv;
|
||||
|
||||
nsIFrame* kidFrame;
|
||||
@ -488,7 +488,7 @@ NS_METHOD nsTableRowGroupFrame::ReflowMappedChildren(nsIPresContext* aPresC
|
||||
if (PR_FALSE==aDoSiblings)
|
||||
break;
|
||||
|
||||
if (!ContinueReflow(aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
if (!ContinueReflow(kidFrame, aPresContext, aReflowState.y, aReflowState.availSize.height))
|
||||
break;
|
||||
|
||||
// Get the next child
|
||||
|
||||
@ -190,7 +190,7 @@ public:
|
||||
|
||||
virtual PRBool RowGroupReceivesExcessSpace() { return PR_TRUE; }
|
||||
|
||||
virtual PRBool ContinueReflow(nsIPresContext* aPresContext, nscoord y, nscoord height) { return PR_TRUE; }
|
||||
virtual PRBool ContinueReflow(nsIFrame* aFrame, nsIPresContext* aPresContext, nscoord y, nscoord height) { return PR_TRUE; }
|
||||
|
||||
void GetMaxElementSize(nsSize& aMaxElementSize) const;
|
||||
|
||||
|
||||
@ -75,7 +75,10 @@ NS_NewTreeFrame (nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
|
||||
// Constructor
|
||||
nsTreeFrame::nsTreeFrame()
|
||||
:nsTableFrame(),mSlatedForReflow(PR_FALSE), mTwistyListener(nsnull), mGeneration(0), mUseGeneration(PR_TRUE) { }
|
||||
:nsTableFrame(),mSlatedForReflow(PR_FALSE), mTwistyListener(nsnull), mGeneration(0), mUseGeneration(PR_TRUE),
|
||||
mFixedRows(-1), mReflowStopped(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
// Destructor
|
||||
nsTreeFrame::~nsTreeFrame()
|
||||
@ -493,6 +496,36 @@ nsTreeFrame::Reflow(nsIPresContext* aPresContext,
|
||||
|
||||
aDesiredSize.ascent = aDesiredSize.height;
|
||||
|
||||
if (mFixedRows != -1) {
|
||||
PRInt32 totalRows = mCellMap->GetRowCount();
|
||||
if (totalRows < mFixedRows) {
|
||||
if (totalRows == 0) aDesiredSize.height = 0 +
|
||||
aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;;
|
||||
|
||||
// Get a single cell and use it as a multiplicative factor.
|
||||
nsTableCellFrame* cellFrame = GetCellInfoAt(0, 0);
|
||||
nsRect rect;
|
||||
cellFrame->GetRect(rect);
|
||||
aDesiredSize.height = (mFixedRows*rect.height) +
|
||||
aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;;
|
||||
}
|
||||
else {
|
||||
// Find out the total height of our frame children.
|
||||
nsIFrame* child = mFrames.FirstChild();
|
||||
PRInt32 height = 0;
|
||||
while (child) {
|
||||
nsRect rect;
|
||||
child->GetRect(rect);
|
||||
height += rect.height;
|
||||
|
||||
child->GetNextSibling(&child);
|
||||
}
|
||||
|
||||
aDesiredSize.height = height +
|
||||
aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
if (!UseGeneration())
|
||||
SetUseGeneration(PR_TRUE);
|
||||
|
||||
@ -551,6 +584,16 @@ nsTreeFrame::Init(nsIPresContext* aPresContext,
|
||||
|
||||
target->AddEventListener("mousedown", mTwistyListener, PR_TRUE);
|
||||
|
||||
nsAutoString value;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mContent);
|
||||
element->GetAttribute("rows", value);
|
||||
|
||||
if (value != "") {
|
||||
PRInt32 dummy;
|
||||
PRInt32 count = value.ToInteger(&dummy);
|
||||
mFixedRows = count;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,11 @@ public:
|
||||
// nsITreeFrame.h
|
||||
NS_IMETHOD EnsureRowIsVisible(PRInt32 aRowIndex);
|
||||
|
||||
PRInt32 GetFixedRowSize() { return mFixedRows; };
|
||||
|
||||
void HaltReflow(PRBool aHalt = PR_TRUE) { mReflowStopped = aHalt; };
|
||||
PRBool IsReflowHalted() { return mReflowStopped; };
|
||||
|
||||
protected:
|
||||
nsTreeFrame();
|
||||
virtual ~nsTreeFrame();
|
||||
@ -110,4 +115,6 @@ protected: // Data Members
|
||||
PRInt32 mGeneration;
|
||||
PRBool mUseGeneration;
|
||||
PRBool mSuppressReflow;
|
||||
PRInt32 mFixedRows;
|
||||
PRBool mReflowStopped;
|
||||
}; // class nsTreeFrame
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsXULAtoms.h"
|
||||
#include "nsBoxFrame.h"
|
||||
#include "nsTreeFrame.h"
|
||||
|
||||
//
|
||||
// NS_NewTreeOuterFrame
|
||||
@ -121,7 +122,26 @@ nsTreeOuterFrame::Reflow(nsIPresContext* aPresContext,
|
||||
|
||||
//printf("TOF Width: %d, TOF Height: %d\n", aReflowState.mComputedWidth, aReflowState.mComputedHeight);
|
||||
|
||||
return nsTableOuterFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
||||
nsresult rv = nsTableOuterFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
||||
|
||||
nsITreeFrame* tree = FindTreeFrame();
|
||||
nsTreeFrame* treeFrame = (nsTreeFrame*)tree;
|
||||
if (treeFrame->GetFixedRowSize() != -1) {
|
||||
// The tree had a rows attribute that altered its dimensions. We
|
||||
// do not want to use the computed width and height passed in in this
|
||||
// case.
|
||||
nsRect rect;
|
||||
treeFrame->GetRect(rect);
|
||||
|
||||
// XXX This is not sufficient. Will eventually have to deal with margins and padding
|
||||
// and also with the presence of captions. For now, though, punt on those and
|
||||
// hope nobody tries to do this with a row-based tree.
|
||||
aDesiredSize.width = rect.width;
|
||||
aDesiredSize.height = rect.height;
|
||||
}
|
||||
|
||||
treeFrame->HaltReflow(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1124,6 +1124,8 @@ nsTreeRowGroupFrame::ReflowAfterRowLayout(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, mScrollbar,
|
||||
kidAvailSize, aReason);
|
||||
|
||||
if (mRowGroupHeight == -1) // This happens when a fixed row tree wishes to alter the scrollbar's height
|
||||
mRowGroupHeight = aReflowState.y;
|
||||
kidReflowState.mComputedHeight = mRowGroupHeight;
|
||||
rv = ReflowChild(mScrollbar, aPresContext, desiredSize, kidReflowState,
|
||||
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
||||
@ -1276,7 +1278,6 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext* aPresContext)
|
||||
|
||||
nsCOMPtr<nsIContent> topRowContent;
|
||||
PRInt32 delta = 1;
|
||||
|
||||
FindPreviousRowContent(delta, rowContent, nsnull, getter_AddRefs(topRowContent));
|
||||
|
||||
PRInt32 numColsAdded = AddRowToMap(tableFrame, *aPresContext, topRowContent, mTopFrame);
|
||||
@ -1347,6 +1348,7 @@ nsTreeRowGroupFrame::GetNextFrameForReflow(nsIPresContext* aPresContext, nsIFram
|
||||
prevFrame = aFrame;
|
||||
isAppend = PR_FALSE;
|
||||
}
|
||||
|
||||
mFrameConstructor->CreateTreeWidgetContent(aPresContext, this, prevFrame, nextContent,
|
||||
aResult, isAppend, PR_FALSE,
|
||||
nsnull);
|
||||
@ -1358,6 +1360,7 @@ nsTreeRowGroupFrame::GetNextFrameForReflow(nsIPresContext* aPresContext, nsIFram
|
||||
nsCOMPtr<nsIContent> topRowContent;
|
||||
PRInt32 delta = 1;
|
||||
FindPreviousRowContent(delta, nextContent, nsnull, getter_AddRefs(topRowContent));
|
||||
|
||||
PRInt32 numColsAdded = AddRowToMap(tableFrame, *aPresContext, topRowContent, (*aResult));
|
||||
if (numColsAdded > 0) {
|
||||
MarkTreeAsDirty(aPresContext, (nsTreeFrame*) tableFrame);
|
||||
@ -1385,11 +1388,31 @@ nsTreeRowGroupFrame::TreeAppendFrames(nsIFrame* aFrameList)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool nsTreeRowGroupFrame::ContinueReflow(nsIPresContext* aPresContext, nscoord y, nscoord height)
|
||||
PRBool nsTreeRowGroupFrame::ContinueReflow(nsIFrame* aFrame, nsIPresContext* aPresContext, nscoord y, nscoord height)
|
||||
{
|
||||
//printf("Y is: %d\n", y);
|
||||
//printf("Height is: %d\n", height);
|
||||
if (height <= 0) {
|
||||
nsTableFrame* tableFrame;
|
||||
nsTableFrame::GetTableFrame(this, tableFrame);
|
||||
nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame;
|
||||
|
||||
PRInt32 rowSize = treeFrame->GetFixedRowSize();
|
||||
|
||||
// Let's figure out if we want to halt the reflow.
|
||||
if (IsTableRowFrame(aFrame)) {
|
||||
// Cast it and get the row index.
|
||||
PRInt32 rowIndex = ((nsTableRowFrame*)aFrame)->GetRowIndex();
|
||||
if (rowSize != -1 && rowIndex == (rowSize-1)) {
|
||||
treeFrame->HaltReflow();
|
||||
|
||||
// Get our running height total and clear the row group's mRowGroupHeight
|
||||
mOuterFrame->ClearRowGroupHeight();
|
||||
}
|
||||
}
|
||||
|
||||
PRBool reflowStopped = treeFrame->IsReflowHalted();
|
||||
|
||||
if ((rowSize == -1 && height <= 0) || reflowStopped) {
|
||||
mIsFull = PR_TRUE;
|
||||
nsIFrame* lastChild = GetLastFrame();
|
||||
nsIFrame* startingPoint = mBottomFrame;
|
||||
@ -1415,8 +1438,6 @@ PRBool nsTreeRowGroupFrame::ContinueReflow(nsIPresContext* aPresContext, nscoord
|
||||
|
||||
// remove the rows from the table after removing from the sibling chain
|
||||
if ((startRowIndex >= 0) && (numRows > 0)) {
|
||||
nsTableFrame* tableFrame;
|
||||
nsTableFrame::GetTableFrame(this, tableFrame);
|
||||
tableFrame->RemoveRows(*aPresContext, startRowIndex, numRows, PR_FALSE);
|
||||
tableFrame->InvalidateColumnWidths();
|
||||
}
|
||||
@ -1890,6 +1911,7 @@ nsTreeRowGroupFrame::AddRowToMap(nsTableFrame* aTableFrame,
|
||||
insertionIndex, PR_FALSE);
|
||||
}
|
||||
|
||||
|
||||
return numNewCols;
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ public:
|
||||
|
||||
NS_IMETHOD Destroy(nsIPresContext* aPresContext);
|
||||
|
||||
PRBool ContinueReflow(nsIPresContext* aPresContext, nscoord y, nscoord height);
|
||||
PRBool ContinueReflow(nsIFrame* aFrame, nsIPresContext* aPresContext, nscoord y, nscoord height);
|
||||
|
||||
PRBool IsFull() { return mIsFull; };
|
||||
|
||||
@ -192,6 +192,8 @@ public:
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aCurrentFrame);
|
||||
|
||||
void ClearRowGroupHeight() { mRowGroupHeight = -1; }
|
||||
|
||||
static PRBool IsTableRowGroupFrame(nsIFrame*);
|
||||
static PRBool IsTableRowFrame(nsIFrame*);
|
||||
|
||||
|
||||
@ -31,13 +31,12 @@ Rights Reserved.
|
||||
<!-- Addressing Widget -->
|
||||
<box id="addressingWidget"
|
||||
align="vertical"
|
||||
style="border:solid black 1px">
|
||||
>
|
||||
|
||||
<!-- for fixed height: style="height:5em" -->
|
||||
<tree id="addressingWidgetTree"
|
||||
class="addressingWidget"
|
||||
style="height:5em"
|
||||
onclick="awClickRow()">
|
||||
rows="3"
|
||||
onclick="awClickRow()" style="width:0px;height:0px;border:solid black 1px">
|
||||
|
||||
<treecol style="width:9em"/>
|
||||
<treecol style="width:2em"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user