Fixes for bugs

#34079 (context menus)
#34673 (grid crashes)
(Crash opening many of the editor dialogs)

-r hyatt -a leaf
This commit is contained in:
evaughan%netscape.com 2000-04-05 23:46:48 +00:00
parent 47f3d9c6cc
commit 34cd8c8082
8 changed files with 150 additions and 62 deletions

View File

@ -58,7 +58,8 @@ void nsBoxSizeListNodeImpl::SetNext(nsBoxLayoutState& aState, nsBoxSizeList* aNe
}
mNext = aNext;
aNext->AddRef();
if (mNext)
aNext->AddRef();
}
void
@ -69,7 +70,7 @@ nsBoxSizeListNodeImpl::Append(nsBoxLayoutState& aState, nsBoxSizeList* aChild)
nsBoxSizeListNodeImpl::nsBoxSizeListNodeImpl(nsIBox* aBox):mNext(nsnull),
mParent(nsnull),
mRefCount(1),
mRefCount(0),
mBox(aBox),
mIsSet(PR_FALSE)
{
@ -147,9 +148,6 @@ nsBoxSizeListImpl::GetBoxSize(nsBoxLayoutState& aState)
nsBoxSizeList* node = mFirst;
PRBool isHorizontal = PR_FALSE;
mBox->GetOrientation(isHorizontal);
while(node) {
nsBoxSize size = node->GetBoxSize(aState);
@ -189,8 +187,9 @@ nsBoxSizeListNodeImpl::GetBoxSize(nsBoxLayoutState& aState)
mBox->GetMaxSize(aState, max);
mBox->GetAscent(aState, ascent);
mBox->GetFlex(aState, flex);
nsBox::AddMargin(mBox, pref);
size.Add(min, pref, max, ascent, flex, isHorizontal);
size.Add(min, pref, max, ascent, flex, !isHorizontal);
return size;
}
@ -243,13 +242,13 @@ nsMonumentLayout::GetParentMonument(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox,
nsCOMPtr<nsIBoxLayout> layout;
nsCOMPtr<nsIMonument> parentMonument;
nsresult rv = NS_OK;
aParentMonument = nsnull;
*aParentMonument = nsnull;
aBox->GetParentBox(&aBox);
while (aBox) {
aBox->GetLayoutManager(getter_AddRefs(layout));
parentMonument = do_QueryInterface(layout, &rv);
if (NS_SUCCEEDED(rv) && aParentMonument) {
if (NS_SUCCEEDED(rv) && parentMonument) {
aParentBox = aBox;
*aParentMonument = parentMonument.get();
NS_IF_ADDREF(*aParentMonument);
@ -368,7 +367,7 @@ nsMonumentLayout::CountMonuments(PRInt32& aCount)
NS_IMETHODIMP
nsMonumentLayout::BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize*& aFirst, nsBoxSize*& aLast)
{
aFirst = aLast = new nsBoxSize();
aFirst = aLast = new (aState) nsBoxSize();
nsSize pref(0,0);
nsSize min(0,0);
@ -391,9 +390,9 @@ nsMonumentLayout::BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBox
PRBool isHorizontal = PR_FALSE;
aBox->GetOrientation(isHorizontal);
(aFirst)->Add(min, pref, max, ascent, flex, isHorizontal);
(aFirst)->Add(borderPadding,isHorizontal);
(aFirst)->Add(margin,isHorizontal);
(aFirst)->Add(min, pref, max, ascent, flex, !isHorizontal);
(aFirst)->Add(borderPadding,!isHorizontal);
(aFirst)->Add(margin,!isHorizontal);
return NS_OK;
}

View File

@ -80,11 +80,12 @@ nsObeliskLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSi
PRBool isHorizontal = PR_FALSE;
aBox->GetOrientation(isHorizontal);
nscoord totalWidth = 0;
//nscoord totalWidth = 0;
if (node) {
// for each info
while(node)
{
//while(node)
//{
// if the infos pref width is greater than aSize's use it.
// if the infos min width is greater than aSize's use it.
// if the infos max width is smaller than aSizes then set it.
@ -96,14 +97,14 @@ nsObeliskLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSi
if (s > s2)
s2 = s;
totalWidth += size.pref;
//totalWidth += size.pref;
node = node->GetNext();
//node = node->GetNext();
}
nscoord& width = GET_WIDTH(aSize, isHorizontal);
if (totalWidth > width)
width = totalWidth;
//nscoord& width = GET_WIDTH(aSize, isHorizontal);
//if (totalWidth > width)
// width = totalWidth;
return NS_OK;
}
@ -120,9 +121,10 @@ nsObeliskLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSiz
PRBool isHorizontal = PR_FALSE;
aBox->GetOrientation(isHorizontal);
if (node) {
// for each info
while(node)
{
//while(node)
//{
// if the infos pref width is greater than aSize's use it.
// if the infos min width is greater than aSize's use it.
// if the infos max width is smaller than aSizes then set it.
@ -134,7 +136,7 @@ nsObeliskLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSiz
if (s > s2)
s2 = s;
node = node->GetNext();
// node = node->GetNext();
}
return NS_OK;
@ -152,9 +154,10 @@ nsObeliskLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSiz
PRBool isHorizontal = PR_FALSE;
aBox->GetOrientation(isHorizontal);
if (node) {
// for each info
while(node)
{
// while(node)
//{
// if the infos pref width is greater than aSize's use it.
// if the infos min width is greater than aSize's use it.
// if the infos max width is smaller than aSizes then set it.
@ -166,7 +169,7 @@ nsObeliskLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSiz
if (s > s2)
s2 = s;
node = node->GetNext();
// node = node->GetNext();
}
return NS_OK;
@ -201,6 +204,7 @@ nsObeliskLayout::ChildNeedsLayout(nsIBox* aBox, nsIBoxLayout* aChild)
}
}
/*
void
nsObeliskLayout::ComputeChildSizes(nsIBox* aBox,
nsBoxLayoutState& aState,
@ -227,5 +231,77 @@ nsObeliskLayout::ComputeChildSizes(nsIBox* aBox,
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
}
}
*/
void
nsObeliskLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize*& aBoxSizes, nsComputedBoxSize*& aComputedBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes)
{
nsTempleLayout* temple = nsnull;
nsIBox* aTempleBox = nsnull;
GetOtherTemple(aBox, &temple, &aTempleBox);
if (temple) {
// substitute our sizes for the other temples obelisk sizes.
nsBoxSize* first = nsnull;
nsBoxSize* last = nsnull;
temple->BuildBoxSizeList(aTempleBox, aState, first, last);
aBoxSizes = first;
} else {
nsSprocketLayout::PopulateBoxSizes(aBox, aState, aBoxSizes, aComputedBoxSizes, aMinSize, aMaxSize, aFlexes);
return;
}
aMinSize = 0;
aMaxSize = NS_INTRINSICSIZE;
PRBool isHorizontal = PR_FALSE;
aBox->GetOrientation(isHorizontal);
aFlexes = 0;
nsIBox* child = nsnull;
aBox->GetChildBox(&child);
while(child)
{
nscoord flex = 0;
child->GetFlex(aState, flex);
if (flex > 0)
aFlexes++;
nsSize pref(0,0);
nsSize min(0,0);
nsSize max(0,0);
nscoord ascent = 0;
child->GetPrefSize(aState, pref);
child->GetAscent(aState, ascent);
nsMargin margin;
child->GetMargin(margin);
child->GetMinSize(aState, min);
child->GetMaxSize(aState, max);
nsBox::BoundsCheck(min, pref, max);
AddMargin(child, pref);
AddMargin(child, min);
AddMargin(child, max);
if (!isHorizontal) {
if (min.width > aMinSize)
aMinSize = min.width;
if (max.width < aMaxSize)
aMaxSize = max.width;
} else {
if (min.height > aMinSize)
aMinSize = min.height;
if (max.height < aMaxSize)
aMaxSize = max.height;
}
child->GetNextBox(&child);
}
}

View File

@ -49,11 +49,15 @@ protected:
void ChildNeedsLayout(nsIBox* aBox, nsIBoxLayout* aChild);
virtual void UpdateMonuments(nsIBox* aBox, nsBoxLayoutState& aState);
/*
virtual void ComputeChildSizes(nsIBox* aBox,
nsBoxLayoutState& aState,
nscoord& aGivenSize,
nsBoxSize* aBoxSizes,
nsComputedBoxSize*& aComputedBoxSizes);
*/
virtual void PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsBoxSize*& aBoxSizes, nsComputedBoxSize*& aComputedBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes);
nsObeliskLayout(nsIPresShell* aShell);

View File

@ -223,12 +223,16 @@ nsPopupSetFrame::Layout(nsBoxLayoutState& aState)
BoundsCheck(minSize, prefSize, maxSize);
AddMargin(ibox, prefSize);
// lay it out
LayoutChildAt(aState, ibox, nsRect(0,0,prefSize.width, prefSize.height));
}
SyncLayout(aState);
LayoutFinished(aState);
return rv;
}
@ -357,9 +361,8 @@ nsPopupSetFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDeb
NS_IMETHODIMP
nsPopupSetFrame::DidReflow(nsIPresContext* aPresContext,
nsDidReflowStatus aStatus)
void
nsPopupSetFrame::LayoutFinished(nsBoxLayoutState& aState)
{
// Sync up the view.
nsIFrame* activeChild = GetActiveChild();
@ -377,10 +380,9 @@ nsPopupSetFrame::DidReflow(nsIPresContext* aPresContext,
if (popupAlign.IsEmpty())
popupAlign = "topleft";
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(aPresContext, popupAnchor, popupAlign, mElementFrame, mXPos, mYPos);
nsIPresContext* presContext = aState.GetPresContext();
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(presContext, popupAnchor, popupAlign, mElementFrame, mXPos, mYPos);
}
return nsBoxFrame::DidReflow(aPresContext, aStatus);
}
NS_IMETHODIMP

View File

@ -73,8 +73,7 @@ public:
NS_IMETHOD Destroy(nsIPresContext* aPresContext);
// Reflow methods
NS_IMETHOD DidReflow(nsIPresContext* aPresContext,
nsDidReflowStatus aStatus);
void LayoutFinished(nsBoxLayoutState& aState);
NS_IMETHOD AppendFrames(nsIPresContext* aPresContext,
nsIPresShell& aPresShell,

View File

@ -46,19 +46,6 @@
nsCOMPtr<nsIBoxLayout> nsSprocketLayout::gInstance = new nsSprocketLayout();
class nsBoxSizeSpecial : public nsBoxSize
{
public:
void* operator new(size_t sz, nsBoxLayoutState& aState);
void operator delete(void* aPtr, size_t sz);
};
class nsComputedBoxSizeSpecial : public nsComputedBoxSize
{
public:
void* operator new(size_t sz, nsBoxLayoutState& aState);
void operator delete(void* aPtr, size_t sz);
};
#define DEBUG_SPRING_SIZE 8
#define DEBUG_BORDER_SIZE 2
@ -458,14 +445,14 @@ nsSprocketLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aState)
while(boxSizes)
{
nsBoxSizeSpecial* toDelete = (nsBoxSizeSpecial*)boxSizes;
nsBoxSize* toDelete = boxSizes;
boxSizes = boxSizes->next;
delete toDelete;
}
while(computedBoxSizes)
{
nsComputedBoxSizeSpecial* toDelete = (nsComputedBoxSizeSpecial*)computedBoxSizes;
nsComputedBoxSize* toDelete = computedBoxSizes;
computedBoxSizes = computedBoxSizes->next;
delete toDelete;
}
@ -595,13 +582,13 @@ nsSprocketLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBox
while(child)
{
if (!currentBox) {
aBoxSizes = new (aState) nsBoxSizeSpecial();
aBoxSizes = new (aState) nsBoxSize();
//aComputedBoxSizes = new (aState) nsComputedBoxSizeSpecial();
currentBox = aBoxSizes;
//currentComputed = aComputedBoxSizes;
} else {
currentBox->next = new (aState) nsBoxSizeSpecial();
currentBox->next = new (aState) nsBoxSize();
//currentComputed->next = new (aState) nsComputedBoxSizeSpecial();
currentBox = currentBox->next;
@ -796,6 +783,7 @@ nsSprocketLayout::ChildResized(nsIBox* aBox,
nsSize max(0,0);
aChild->GetMaxSize(aState, max);
AddMargin(aChild, max);
if (isHorizontal)
childActualHeight = max.height < childActualHeight ? max.height : childActualHeight;
@ -830,6 +818,7 @@ nsSprocketLayout::ChildResized(nsIBox* aBox,
if (childActualWidth > childLayoutWidth) {
nsSize max(0,0);
aChild->GetMaxSize(aState, max);
AddMargin(aChild, max);
// our width now becomes the new size
@ -899,7 +888,7 @@ nsSprocketLayout::ComputeChildSizes(nsIBox* aBox,
// ----- calculate the springs constants and the size remaining -----
if (aBoxSizes && !aComputedBoxSizes)
aComputedBoxSizes = new (aState) nsComputedBoxSizeSpecial();
aComputedBoxSizes = new (aState) nsComputedBoxSize();
nsBoxSize* boxSizes = aBoxSizes;
nsComputedBoxSize* computedBoxSizes = aComputedBoxSizes;
@ -939,7 +928,7 @@ nsSprocketLayout::ComputeChildSizes(nsIBox* aBox,
boxSizes = boxSizes->next;
if (boxSizes && !computedBoxSizes->next)
computedBoxSizes->next = new (aState) nsComputedBoxSizeSpecial();
computedBoxSizes->next = new (aState) nsComputedBoxSize();
computedBoxSizes = computedBoxSizes->next;
count++;
@ -1337,8 +1326,11 @@ nsBoxSize::Add(const nsSize& minSize,
max = max2;
flex = aFlex;
if (aAscent > ascent)
ascent = aAscent;
if (!aIsHorizontal) {
if (aAscent > ascent)
ascent = aAscent;
}
}
void
@ -1388,7 +1380,7 @@ nsBoxSize::Clear()
void*
nsBoxSizeSpecial::operator new(size_t sz, nsBoxLayoutState& aState)
nsBoxSize::operator new(size_t sz, nsBoxLayoutState& aState)
{
void* mem = 0;
aState.AllocateStackMemory(sz,&mem);
@ -1397,13 +1389,13 @@ nsBoxSizeSpecial::operator new(size_t sz, nsBoxLayoutState& aState)
void
nsBoxSizeSpecial::operator delete(void* aPtr, size_t sz)
nsBoxSize::operator delete(void* aPtr, size_t sz)
{
}
void*
nsComputedBoxSizeSpecial::operator new(size_t sz, nsBoxLayoutState& aState)
nsComputedBoxSize::operator new(size_t sz, nsBoxLayoutState& aState)
{
void* mem = 0;
@ -1412,6 +1404,6 @@ nsComputedBoxSizeSpecial::operator new(size_t sz, nsBoxLayoutState& aState)
}
void
nsComputedBoxSizeSpecial::operator delete(void* aPtr, size_t sz)
nsComputedBoxSize::operator delete(void* aPtr, size_t sz)
{
}

View File

@ -55,6 +55,9 @@ public:
PRBool aIsHorizontal);
void Add(const nsMargin& aMargin, PRBool aIsHorizontal);
void* operator new(size_t sz, nsBoxLayoutState& aState);
void operator delete(void* aPtr, size_t sz);
};
class nsComputedBoxSize
@ -68,8 +71,10 @@ public:
nsComputedBoxSize* next;
void Clear();
};
void* operator new(size_t sz, nsBoxLayoutState& aState);
void operator delete(void* aPtr, size_t sz);
};
#define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height)
#define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width)

View File

@ -87,16 +87,27 @@ nsTempleLayout::GetMonumentList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSiz
{
if (!mMonuments) {
mMonuments = new nsBoxSizeListImpl(box);
mMonuments->AddRef();
}
current = mMonuments;
nsBoxSizeList* node = nsnull;
monument->GetMonumentList(box, aState, &node);
if (node)
node->AddRef();
while(node)
{
current->Append(aState, node);
node = node->GetNext();
node->Release(aState);
nsBoxSizeList* tmp = node->GetNext();
if (tmp)
tmp->AddRef();
node->SetNext(aState, nsnull);
node = tmp;
if (node && !current->GetNext()) {
nsBoxSizeList* newOne = new nsBoxSizeListImpl(box);
@ -167,7 +178,7 @@ void
nsTempleLayout::DesecrateMonuments(nsBoxLayoutState& aState)
{
mMonuments->Clear(aState);
delete mMonuments;
mMonuments->Release(aState);
mMonuments = nsnull;
}