diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/generic/nsBlockReflowState.cpp b/mozilla/layout/generic/nsBlockReflowState.cpp index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/generic/nsBlockReflowState.cpp +++ b/mozilla/layout/generic/nsBlockReflowState.cpp @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/generic/nsBlockReflowState.h b/mozilla/layout/generic/nsBlockReflowState.h index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/generic/nsBlockReflowState.h +++ b/mozilla/layout/generic/nsBlockReflowState.h @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/generic/nsHTMLContainerFrame.cpp b/mozilla/layout/generic/nsHTMLContainerFrame.cpp index c5026c6058a..4b4aad7cea5 100644 --- a/mozilla/layout/generic/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/generic/nsHTMLContainerFrame.cpp @@ -31,6 +31,7 @@ #include "nsIURL.h" static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); nsHTMLContainerFrame::nsHTMLContainerFrame(nsIContent* aContent, @@ -53,12 +54,12 @@ NS_METHOD nsHTMLContainerFrame::Paint(nsIPresContext& aPresContext, PRIntn skipSides = GetSkipSides(); nsStyleColor* color = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* border = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *color); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *mol, skipSides); + aDirtyRect, mRect, *border, skipSides); } PaintChildren(aPresContext, aRenderingContext, aDirtyRect); diff --git a/mozilla/layout/generic/nsLeafFrame.cpp b/mozilla/layout/generic/nsLeafFrame.cpp index da502bfbe0c..912178cb2db 100644 --- a/mozilla/layout/generic/nsLeafFrame.cpp +++ b/mozilla/layout/generic/nsLeafFrame.cpp @@ -19,7 +19,8 @@ #include "nsIStyleContext.h" #include "nsCSSRendering.h" -static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLESPACING_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); nsLeafFrame::nsLeafFrame(nsIContent* aContent, @@ -39,12 +40,12 @@ NS_METHOD nsLeafFrame::Paint(nsIPresContext& aPresContext, { nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); return NS_OK; } @@ -91,10 +92,10 @@ NS_METHOD nsLeafFrame::IncrementalReflow(nsIPresContext* aPresContext, void nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext, nsReflowMetrics& aDesiredSize) { - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); - aDesiredSize.width += mol->borderPadding.left + mol->borderPadding.right; - aDesiredSize.height += mol->borderPadding.top + mol->borderPadding.bottom; + nsStyleSpacing* space = + (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + aDesiredSize.width += space->mBorderPadding.left + space->mBorderPadding.right; + aDesiredSize.height += space->mBorderPadding.top + space->mBorderPadding.bottom; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; } @@ -102,14 +103,14 @@ void nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext, void nsLeafFrame::GetInnerArea(nsIPresContext* aPresContext, nsRect& aInnerArea) const { - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); - aInnerArea.x = mol->borderPadding.left; - aInnerArea.y = mol->borderPadding.top; + nsStyleSpacing* space = + (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + aInnerArea.x = space->mBorderPadding.left; + aInnerArea.y = space->mBorderPadding.top; aInnerArea.width = mRect.width - - (mol->borderPadding.left + mol->borderPadding.right); + (space->mBorderPadding.left + space->mBorderPadding.right); aInnerArea.height = mRect.height - - (mol->borderPadding.top + mol->borderPadding.bottom); + (space->mBorderPadding.top + space->mBorderPadding.bottom); } NS_METHOD nsLeafFrame::CreateContinuingFrame(nsIPresContext* aPresContext, diff --git a/mozilla/layout/html/base/src/nsBlockFrame.cpp b/mozilla/layout/html/base/src/nsBlockFrame.cpp index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.cpp +++ b/mozilla/layout/html/base/src/nsBlockFrame.cpp @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.cpp b/mozilla/layout/html/base/src/nsBlockReflowState.cpp index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowState.cpp @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.h b/mozilla/layout/html/base/src/nsBlockReflowState.h index adf886a9586..659d1358d5f 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.h +++ b/mozilla/layout/html/base/src/nsBlockReflowState.h @@ -34,6 +34,7 @@ #include "nsHTMLAtoms.h" #include "nsHTMLValue.h" #include "nsIHTMLContent.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -49,6 +50,9 @@ static NS_DEFINE_IID(kIAnchoredItemsIID, NS_IANCHOREDITEMS_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct BlockBandData : public nsBandData { nsBandTrapezoid data[5]; @@ -345,11 +349,10 @@ void nsBlockFrame::PlaceBelowCurrentLineFloaters(nsIPresContext* aCX, GetAvailableSpaceBand(aState, aY); // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - floater->GetStyleContext(aCX, styleContext); + floater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); floater->GetRect(region); region.y = mCurrentState->currentBand->trapezoids[0].yTop; @@ -853,13 +856,12 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get kid and its style // XXX How is this any different than what was passed in to us as aKidMol? - nsIContent* kid; - nsIStyleContext* kidSC; + nsIContentPtr kid; + nsIStyleContextPtr kidSC; - aKidFrame->GetContent(kid); - aKidFrame->GetStyleContext(aCX, kidSC); + aKidFrame->GetContent(kid.AssignRef()); + aKidFrame->GetStyleContext(aCX, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Figure out if kid is a block element or not PRBool isInline = PR_TRUE; @@ -899,14 +901,13 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // Get the style for the last child, and see if it wanted to clear floaters. // This handles the BR tag, which is the only inline element for which clear // applies - nsIStyleContext* lastChildSC; + nsIStyleContextPtr lastChildSC; - lastFrame->GetStyleContext(aCX, lastChildSC); + lastFrame->GetStyleContext(aCX, lastChildSC.AssignRef()); nsStyleMolecule* lastChildMol = (nsStyleMolecule*)lastChildSC->GetData(kStyleMoleculeSID); if (lastChildMol->clear != NS_STYLE_CLEAR_NONE) { ClearFloaters(aState, lastChildMol->clear); } - NS_RELEASE(lastChildSC); } // Now that we've handled force breaks (and maybe called AdvanceToNextLine() @@ -1096,7 +1097,6 @@ nsBlockFrame::PlaceAndReflowChild(nsIPresContext* aCX, // a line break before the next frame is placed. aState.breakAfterChild = PR_TRUE; } - NS_RELEASE(kidSC); aState.reflowStatus = status; return PLACE_FLOWED | PLACE_FIT; @@ -1132,12 +1132,11 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, nsIFrame* prevKidFrame = nsnull; for (kidFrame = mFirstChild; nsnull != kidFrame; ) { - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); - NS_RELEASE(kid); // Attempt to place and reflow the child @@ -1147,7 +1146,6 @@ nsBlockFrame::ReflowMappedChildren(nsIPresContext* aCX, PRIntn placeStatus = PlaceAndReflowChild(aCX, aState, kidFrame, kidMol); ReflowStatus status = aState.reflowStatus; - NS_RELEASE(kidSC); if (0 == (placeStatus & PLACE_FIT)) { // The child doesn't fit. Push it and any remaining children. PushKids(aState); @@ -1224,10 +1222,10 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) if (IsPseudoFrame()) { // Get the next content object that we would like to reflow PRInt32 kidIndex = NextChildOffset(); - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull != kid) { // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); switch (kidMol->display) { case NS_STYLE_DISPLAY_BLOCK: @@ -1239,8 +1237,6 @@ PRBool nsBlockFrame::MoreToReflow(nsIPresContext* aCX) rv = PR_TRUE; break; } - NS_RELEASE(kidSC); - NS_RELEASE(kid); } } else { if (NextChildOffset() < mContent->ChildCount()) { @@ -1288,14 +1284,14 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; } // Resolve style for the kid - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -1321,8 +1317,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); result = frComplete; goto done; } @@ -1379,8 +1373,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mLastContentIsComplete = PRBool(nsnull == kidNextInFlow); PushKids(aState); - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1403,8 +1395,7 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } #ifdef NS_DEBUG @@ -1414,8 +1405,6 @@ nsBlockFrame::ReflowAppendedChildren(nsIPresContext* aCX, NS_ASSERTION(nsnull == kidNextInFlow, "huh?"); #endif } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); // The child that we just reflowed is complete #ifdef NS_DEBUG @@ -1485,10 +1474,10 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } // Get style information for the pulled up kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC = aCX->ResolveStyleContextFor(kid, this); + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC = aCX->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); ReflowStatus status; @@ -1504,8 +1493,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, PushKids(aState); result = PR_FALSE; - NS_RELEASE(kid); - NS_RELEASE(kidSC); goto push_done; } @@ -1531,8 +1518,7 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, mChildCount++; // Switch to new kid style - NS_RELEASE(kidSC); - kidFrame->GetStyleContext(aCX, kidSC); + kidFrame->GetStyleContext(aCX, kidSC.AssignRef()); kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); } else { // The child has a next-in-flow, but it's not one of ours. @@ -1543,8 +1529,6 @@ nsBlockFrame::PullUpChildren(nsIPresContext* aCX, } } } while (frNotComplete == status); - NS_RELEASE(kid); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; } @@ -1950,11 +1934,10 @@ void nsBlockFrame::PlaceFloater(nsIPresContext* aCX, // todo list and we'll handle it when we flush out the line if (IsLeftMostChild(aPlaceholder)) { // Get the type of floater - nsIStyleContext* styleContext; + nsIStyleContextPtr styleContext; - aFloater->GetStyleContext(aCX, styleContext); + aFloater->GetStyleContext(aCX, styleContext.AssignRef()); nsStyleMolecule* mol = (nsStyleMolecule*)styleContext->GetData(kStyleMoleculeSID); - NS_RELEASE(styleContext); if (!mCurrentState->isInline) { // Get the current band for this line @@ -2008,13 +1991,13 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, flow->LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { break; } // Resolve style for the kid - nsIStyleContext* kidSC = aPresContext->ResolveStyleContextFor(kid, this); + nsIStyleContextPtr kidSC = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // Is it a floater? @@ -2039,9 +2022,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, // decided it needed a pseudo-frame when it shouldn't have. NS_ASSERTION(nsnull != mFirstChild, "bad body"); - NS_RELEASE(kidSC); - NS_RELEASE(kid); - return NS_OK; } // FALL THROUGH (and create frame) @@ -2058,8 +2038,6 @@ NS_METHOD nsBlockFrame::ContentAppended(nsIPresShell* aShell, } } kidFrame->SetStyleContext(kidSC); - NS_RELEASE(kidSC); - NS_RELEASE(kid); // Link child frame into the list of children if (nsnull != prevKidFrame) { diff --git a/mozilla/layout/html/base/src/nsColumnFrame.cpp b/mozilla/layout/html/base/src/nsColumnFrame.cpp index 2448f5d4b2d..22cfc0fc0d5 100644 --- a/mozilla/layout/html/base/src/nsColumnFrame.cpp +++ b/mozilla/layout/html/base/src/nsColumnFrame.cpp @@ -27,6 +27,7 @@ #include "nsIViewManager.h" #include "nsIDeviceContext.h" #include "nsISpaceManager.h" +#include "nsIPtr.h" #ifdef NS_DEBUG #undef NOISY @@ -39,6 +40,9 @@ static NS_DEFINE_IID(kIRunaroundIID, NS_IRUNAROUND_IID); static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct ColumnReflowState { // The space manager to use nsISpaceManager* spaceManager; @@ -240,14 +244,13 @@ PRBool ColumnFrame::ReflowMappedChildren(nsIPresContext* aPresContext, nsIFrame::ReflowStatus status; // Get top margin for this kid - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidFrame, kidMol); // XXX Style system should do this... nscoord bottomMargin = ChildIsPseudoFrame(kidFrame) ? 0 : kidMol->margin.bottom; - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -440,9 +443,9 @@ PRBool ColumnFrame::PullUpChildren(nsIPresContext* aPresContext, } // Get top margin for this kid - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidFrame, kidMol); // XXX Style system should do this... @@ -486,7 +489,6 @@ PRBool ColumnFrame::PullUpChildren(nsIPresContext* aPresContext, mLastContentIsComplete = prevLastContentIsComplete; mChildCount--; result = PR_FALSE; - NS_RELEASE(kidSC); goto push_done; } @@ -544,7 +546,6 @@ PRBool ColumnFrame::PullUpChildren(nsIPresContext* aPresContext, } } } while (frNotComplete == status); - NS_RELEASE(kidSC); prevKidFrame = kidFrame; prevLastContentIsComplete = mLastContentIsComplete; @@ -651,7 +652,7 @@ ColumnFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; @@ -660,12 +661,11 @@ ColumnFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, // Make sure we still have room left if (aState.availSize.height <= 0) { // Note: return status was set to frNotComplete above... - NS_RELEASE(kid); break; } // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidStyleContext->GetData(kStyleMoleculeSID); @@ -786,8 +786,6 @@ ColumnFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, f->GetNextSibling(f); } mChildCount -= overflowKids; - NS_RELEASE(kidStyleContext); - NS_RELEASE(kid); goto done; } @@ -833,8 +831,6 @@ ColumnFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, } } } while (frNotComplete == status); - NS_RELEASE(kidStyleContext); - NS_RELEASE(kid); prevKidFrame = kidFrame; kidPrevInFlow = nsnull; @@ -1032,14 +1028,13 @@ NS_METHOD ColumnFrame::IncrementalReflow(nsIPresContext* aPresContext, prevKidFrame->GetRect(startKidRect); // Get style info - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - prevKidFrame->GetStyleContext(aPresContext, kidSC); + prevKidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); // XXX Style system should do this... nscoord bottomMargin = ChildIsPseudoFrame(prevKidFrame) ? 0 : kidMol->margin.bottom; - NS_RELEASE(kidSC); state.y = startKidRect.YMost(); if (bottomMargin < 0) { @@ -1066,9 +1061,9 @@ NS_METHOD ColumnFrame::IncrementalReflow(nsIPresContext* aPresContext, // Now ResizeReflow the appended frames while (nsnull != kidFrame) { - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, state, kidFrame, kidMol); @@ -1113,7 +1108,6 @@ NS_METHOD ColumnFrame::IncrementalReflow(nsIPresContext* aPresContext, } else { state.prevMaxPosBottomMargin = bottomMargin; } - NS_RELEASE(kidSC); // Is the child complete? if (frNotComplete == aStatus) { @@ -1192,13 +1186,13 @@ NS_METHOD ColumnFrame::ContentAppended(nsIPresShell* aShell, // Create frames for each new child for (;;) { // Get the next content object - nsIContent* kid = content->ChildAt(kidIndex); + nsIContentPtr kid = content->ChildAt(kidIndex); if (nsnull == kid) { break; } // Get style context for the kid - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidStyleContext->GetData(kStyleMoleculeSID); @@ -1256,7 +1250,6 @@ NS_METHOD ColumnFrame::ContentAppended(nsIPresShell* aShell, nsBlockFrame::NewFrame(&kidFrame, mContent, mIndexInParent, this); // Resolve style for the pseudo-frame (kid's style won't do) - NS_RELEASE(kidStyleContext); kidStyleContext = aPresContext->ResolveStyleContextFor(mContent, this); kidFrame->SetStyleContext(kidStyleContext); @@ -1297,8 +1290,6 @@ NS_METHOD ColumnFrame::ContentAppended(nsIPresShell* aShell, kidIndex = NextChildOffset(); break; } - NS_RELEASE(kid); - NS_RELEASE(kidStyleContext); } SetLastContentOffset(prevKidFrame); // Note: Column frames *never* directly generate reflow commands diff --git a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp index c5026c6058a..4b4aad7cea5 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp @@ -31,6 +31,7 @@ #include "nsIURL.h" static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); nsHTMLContainerFrame::nsHTMLContainerFrame(nsIContent* aContent, @@ -53,12 +54,12 @@ NS_METHOD nsHTMLContainerFrame::Paint(nsIPresContext& aPresContext, PRIntn skipSides = GetSkipSides(); nsStyleColor* color = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* border = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *color); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *mol, skipSides); + aDirtyRect, mRect, *border, skipSides); } PaintChildren(aPresContext, aRenderingContext, aDirtyRect); diff --git a/mozilla/layout/html/base/src/nsLeafFrame.cpp b/mozilla/layout/html/base/src/nsLeafFrame.cpp index da502bfbe0c..912178cb2db 100644 --- a/mozilla/layout/html/base/src/nsLeafFrame.cpp +++ b/mozilla/layout/html/base/src/nsLeafFrame.cpp @@ -19,7 +19,8 @@ #include "nsIStyleContext.h" #include "nsCSSRendering.h" -static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLESPACING_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); nsLeafFrame::nsLeafFrame(nsIContent* aContent, @@ -39,12 +40,12 @@ NS_METHOD nsLeafFrame::Paint(nsIPresContext& aPresContext, { nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); return NS_OK; } @@ -91,10 +92,10 @@ NS_METHOD nsLeafFrame::IncrementalReflow(nsIPresContext* aPresContext, void nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext, nsReflowMetrics& aDesiredSize) { - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); - aDesiredSize.width += mol->borderPadding.left + mol->borderPadding.right; - aDesiredSize.height += mol->borderPadding.top + mol->borderPadding.bottom; + nsStyleSpacing* space = + (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + aDesiredSize.width += space->mBorderPadding.left + space->mBorderPadding.right; + aDesiredSize.height += space->mBorderPadding.top + space->mBorderPadding.bottom; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; } @@ -102,14 +103,14 @@ void nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext, void nsLeafFrame::GetInnerArea(nsIPresContext* aPresContext, nsRect& aInnerArea) const { - nsStyleMolecule* mol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); - aInnerArea.x = mol->borderPadding.left; - aInnerArea.y = mol->borderPadding.top; + nsStyleSpacing* space = + (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + aInnerArea.x = space->mBorderPadding.left; + aInnerArea.y = space->mBorderPadding.top; aInnerArea.width = mRect.width - - (mol->borderPadding.left + mol->borderPadding.right); + (space->mBorderPadding.left + space->mBorderPadding.right); aInnerArea.height = mRect.height - - (mol->borderPadding.top + mol->borderPadding.bottom); + (space->mBorderPadding.top + space->mBorderPadding.bottom); } NS_METHOD nsLeafFrame::CreateContinuingFrame(nsIPresContext* aPresContext, diff --git a/mozilla/layout/html/table/src/nsCellLayoutData.cpp b/mozilla/layout/html/table/src/nsCellLayoutData.cpp index 87e88f091f8..6be4c28eba5 100644 --- a/mozilla/layout/html/table/src/nsCellLayoutData.cpp +++ b/mozilla/layout/html/table/src/nsCellLayoutData.cpp @@ -21,11 +21,15 @@ #include "nsIFrame.h" #include "nsTableCell.h" #include "nsIStyleContext.h" +#include "nsIPtr.h" #include /* XXX */ // for printf -static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLESPACING_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); + +NS_DEF_PTR(nsIStyleContext); nsCellLayoutData::nsCellLayoutData(nsTableCellFrame *aCellFrame, nsReflowMetrics * aDesiredSize, nsSize * aMaxElementSize) @@ -77,16 +81,16 @@ void nsCellLayoutData::SetMaxElementSize(nsSize * aMaxElementSize) } /** - * Get the style molecue for this object (determined, by + * Get the style context for this object (determined, by * asking for the frame * **/ -nsStyleMolecule* nsCellLayoutData::GetStyleMolecule() +nsIStyleContext* nsCellLayoutData::GetStyleContext() { if (mCellFrame != nsnull) { - nsStyleMolecule* styleMol; - mCellFrame->GetStyleData(kStyleMoleculeSID, (nsStyleStruct*&)styleMol); - return styleMol; + nsIStyleContext* styleContext; + mCellFrame->GetStyleContext(nsnull, styleContext); + return styleContext; } return nsnull; } @@ -96,51 +100,52 @@ nsStyleMolecule* nsCellLayoutData::GetStyleMolecule() /** - * Given a list of nsCellLayoutData and a index, get the style molecule for + * Given a list of nsCellLayoutData and a index, get the style context for * that element in the list * **/ -nsStyleMolecule* nsCellLayoutData::GetStyleMoleculeAt(nsVoidArray* aList, PRInt32 aIndex) +nsIStyleContext* nsCellLayoutData::GetStyleContextAt(nsVoidArray* aList, PRInt32 aIndex) { - nsStyleMolecule* result = nsnull; + nsIStyleContext* result = nsnull; if (aList != nsnull) { nsCellLayoutData* data = (nsCellLayoutData*)aList->ElementAt(aIndex); if (data != nsnull) - result = data->GetStyleMolecule(); + result = data->GetStyleContext(); } return result; } /** - * Given a style molecule and an edge, find the margin + * Given a style context and an edge, find the margin * **/ -nscoord nsCellLayoutData::GetMargin(nsStyleMolecule* aStyle,PRUint8 aEdge) +nscoord nsCellLayoutData::GetMargin(nsIStyleContext* aStyle,PRUint8 aEdge) { nscoord result = 0; if (aStyle) { + nsStyleSpacing* spacing = (nsStyleSpacing*)aStyle->GetData(kStyleSpacingSID); switch (aEdge) { case NS_SIDE_TOP: - result = aStyle->margin.top; + result = spacing->mMargin.top; break; case NS_SIDE_RIGHT: - result = aStyle->margin.right; + result = spacing->mMargin.right; break; case NS_SIDE_BOTTOM: - result = aStyle->margin.bottom; + result = spacing->mMargin.bottom; break; case NS_SIDE_LEFT: - result = aStyle->margin.left; + result = spacing->mMargin.left; break; } @@ -150,32 +155,33 @@ nscoord nsCellLayoutData::GetMargin(nsStyleMolecule* aStyle,PRUint8 aEdge) /** - * Given a style molecule and an edge, find the border width + * Given a style context and an edge, find the border width * **/ -nscoord nsCellLayoutData::GetBorderWidth(nsStyleMolecule* aStyle,PRUint8 aEdge) +nscoord nsCellLayoutData::GetBorderWidth(nsIStyleContext* aStyle,PRUint8 aEdge) { nscoord result = 0; if (aStyle) { + nsStyleSpacing* spacing = (nsStyleSpacing*)aStyle->GetData(kStyleSpacingSID); switch (aEdge) { case NS_SIDE_TOP: - result = aStyle->border.top; + result = spacing->mBorder.top; break; case NS_SIDE_RIGHT: - result = aStyle->border.right; + result = spacing->mBorder.right; break; case NS_SIDE_BOTTOM: - result = aStyle->border.bottom; + result = spacing->mBorder.bottom; break; case NS_SIDE_LEFT: - result = aStyle->border.left; + result = spacing->mBorder.left; break; } @@ -185,31 +191,32 @@ nscoord nsCellLayoutData::GetBorderWidth(nsStyleMolecule* aStyle,PRUint8 aEdge) /** - * Given a style molecule and an edge, find the padding + * Given a style context and an edge, find the padding * **/ -nscoord nsCellLayoutData::GetPadding(nsStyleMolecule* aStyle,PRUint8 aEdge) +nscoord nsCellLayoutData::GetPadding(nsIStyleContext* aStyle,PRUint8 aEdge) { nscoord result = 0; if (aStyle) { + nsStyleSpacing* spacing = (nsStyleSpacing*)aStyle->GetData(kStyleSpacingSID); switch (aEdge) { case NS_SIDE_TOP: - result = aStyle->padding.top; + result = spacing->mPadding.top; break; case NS_SIDE_RIGHT: - result = aStyle->padding.right; + result = spacing->mPadding.right; break; case NS_SIDE_BOTTOM: - result = aStyle->padding.bottom; + result = spacing->mPadding.bottom; break; case NS_SIDE_LEFT: - result = aStyle->padding.left; + result = spacing->mPadding.left; break; } @@ -275,15 +282,15 @@ PRUint8 nsCellLayoutData::GetOpposingEdge(PRUint8 aEdge) */ -nsStyleMolecule* nsCellLayoutData::CompareCellBorders(nsStyleMolecule* aStyle1, - PRUint8 aEdge1, - nsStyleMolecule* aStyle2, - PRUint8 aEdge2) +nsIStyleContext* nsCellLayoutData::CompareCellBorders(nsIStyleContext* aStyle1, + PRUint8 aEdge1, + nsIStyleContext* aStyle2, + PRUint8 aEdge2) { PRInt32 width1 = GetBorderWidth(aStyle1,aEdge1); PRInt32 width2 = GetBorderWidth(aStyle2,aEdge2); - nsStyleMolecule* result = nsnull; + nsIStyleContext* result = nsnull; if (width1 > width2) result = aStyle1; @@ -291,7 +298,9 @@ nsStyleMolecule* nsCellLayoutData::CompareCellBorders(nsStyleMolecule* aStyle1, result = aStyle2; else // width1 == width2 { - if (aStyle1->borderStyle[aEdge1] >= aStyle2->borderStyle[aEdge2]) + nsStyleBorder* border1 = (nsStyleBorder*)aStyle1->GetData(kStyleBorderSID); + nsStyleBorder* border2 = (nsStyleBorder*)aStyle2->GetData(kStyleBorderSID); + if (border1->mStyle[aEdge1] >= border2->mStyle[aEdge2]) result = aStyle1; else result = aStyle2; @@ -306,10 +315,10 @@ nsStyleMolecule* nsCellLayoutData::CompareCellBorders(nsStyleMolecule* aStyle1, * **/ -nsStyleMolecule* nsCellLayoutData::FindHighestPrecedentBorder(nsVoidArray* aList, +nsIStyleContext* nsCellLayoutData::FindHighestPrecedentBorder(nsVoidArray* aList, PRUint8 aEdge) { - nsStyleMolecule* result = nsnull; + nsIStyleContext* result = nsnull; PRInt32 index = 0; PRInt32 count = 0; @@ -318,18 +327,19 @@ nsStyleMolecule* nsCellLayoutData::FindHighestPrecedentBorder(nsVoidArray* aList count = aList->Count(); if (count) { - nsStyleMolecule* style = nsnull; - nsStyleMolecule* style2 = nsnull; + nsIStyleContextPtr style; + nsIStyleContextPtr style2; - style = GetStyleMoleculeAt(aList,index++); + style = GetStyleContextAt(aList,index++); while (index < count) { - style2 = GetStyleMoleculeAt(aList,index++); - if (GetMargin(style2,aEdge) == 0) - style = CompareCellBorders(style,aEdge, style2,aEdge); + style2 = GetStyleContextAt(aList,index++); + if (GetMargin(style2,aEdge) == 0) { + style.SetAddRef(CompareCellBorders(style,aEdge, style2,aEdge)); + } } - if (style && GetMargin(style,aEdge) != 0) - result = style; + if (style && (GetMargin(style,aEdge) != 0)) + result = style.AddRef(); } return result; } @@ -337,22 +347,22 @@ nsStyleMolecule* nsCellLayoutData::FindHighestPrecedentBorder(nsVoidArray* aList -nsStyleMolecule* nsCellLayoutData::FindInnerBorder( nsStyleMolecule* aStyle, - nsVoidArray* aList, - PRUint8 aEdge) +nsStyleSpacing* nsCellLayoutData::FindInnerBorder( nsIStyleContext* aStyle, + nsVoidArray* aList, + PRUint8 aEdge) { - nsStyleMolecule* result = nsnull; - nsStyleMolecule* altStyle = nsnull; - PRUint8 opposite = GetOpposingEdge(aEdge); + nsStyleSpacing* result = nsnull; + PRUint8 opposite = GetOpposingEdge(aEdge); if (GetMargin(aStyle,aEdge) == 0) { - - nsStyleMolecule* altStyle = FindHighestPrecedentBorder(aList,opposite); + nsIStyleContextPtr style; + nsIStyleContextPtr altStyle = FindHighestPrecedentBorder(aList,opposite); if (altStyle != nsnull) - result = CompareCellBorders(aStyle,aEdge,altStyle,opposite); + style.SetAddRef(CompareCellBorders(aStyle,aEdge,altStyle,opposite)); else - result = aStyle; + style.SetAddRef(aStyle); + result = (nsStyleSpacing*)style->GetData(kStyleSpacingSID); } return result; @@ -379,16 +389,17 @@ nsStyleMolecule* nsCellLayoutData::FindInnerBorder( nsStyleMolecule* aStyle, * * */ -nsStyleMolecule* nsCellLayoutData::FindOuterBorder( nsTableFrame* aTableFrame, - nsIFrame* aFrame, - nsStyleMolecule* aStyle, - PRUint8 aEdge) +nsStyleSpacing* nsCellLayoutData::FindOuterBorder( nsTableFrame* aTableFrame, + nsIFrame* aFrame, + nsIStyleContext* aStyle, + PRUint8 aEdge) { - // By default, return the passed in style - nsStyleMolecule* style = aStyle; - nsIFrame* frame = aFrame; - PRBool done = PR_FALSE; + nsIStyleContextPtr style; + nsIFrame* frame = aFrame; + PRBool done = PR_FALSE; + // By default, return the passed in style + style.SetAddRef(aStyle); // The table frame is the outer most frame we test against while (done == PR_FALSE) { @@ -401,16 +412,16 @@ nsStyleMolecule* nsCellLayoutData::FindOuterBorder( nsTableFrame* aTableFrame, // for the parent frame is also zero if (margin == 0) { - nsIFrame* parentFrame; - nsStyleMolecule* parentStyle; + nsIFrame* parentFrame; + nsIStyleContextPtr parentStyle; aFrame->GetGeometricParent(parentFrame); - aFrame->GetStyleData(kStyleMoleculeSID, (nsStyleStruct*&)parentStyle); + aFrame->GetStyleContext(nsnull, parentStyle.AssignRef()); // if the padding for the parent style is zero just // recursively call this routine PRInt32 padding = GetPadding(parentStyle,aEdge); - if (parentStyle && padding == 0) + if (parentStyle && (padding == 0)) { style = parentStyle; frame = parentFrame; @@ -422,7 +433,8 @@ nsStyleMolecule* nsCellLayoutData::FindOuterBorder( nsTableFrame* aTableFrame, } } - return style; + nsStyleSpacing* result = (nsStyleSpacing*)style->GetData(kStyleSpacingSID); + return result; } @@ -456,27 +468,27 @@ nsStyleMolecule* nsCellLayoutData::FindOuterBorder( nsTableFrame* aTableFrame, * @param aIsBottom -- TRUE if this is the last cell in the column */ -nsStyleMolecule* nsCellLayoutData::FindBorderStyle(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, - nsVoidArray* aList, - PRUint8 aEdge) +nsStyleSpacing* nsCellLayoutData::FindBorderStyle(nsTableFrame* aTableFrame, + nsIStyleContext* aCellStyle, + nsVoidArray* aList, + PRUint8 aEdge) { - nsStyleMolecule* style = nsnull; + nsStyleSpacing* style = nsnull; if (aList && aList->Count() == 0) style = FindOuterBorder(aTableFrame,mCellFrame,aCellStyle,aEdge); else style = FindInnerBorder(aCellStyle,aList, aEdge); - if (!style) - style = aCellStyle; + if (!style) + style = (nsStyleSpacing*)aCellStyle->GetData(kStyleSpacingSID); return style; } void nsCellLayoutData::CalculateBorders(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, + nsIStyleContext* aCellStyle, nsVoidArray* aBoundaryCells[4]) { @@ -502,12 +514,12 @@ nscoord nsCellLayoutData::FindLargestMargin(nsVoidArray* aList,PRUint8 aEdge) count = aList->Count(); if (count) { - nsStyleMolecule* style = nsnull; + nsIStyleContextPtr style; nscoord value = 0; while (index < count) { - style = GetStyleMoleculeAt(aList,index++); + style = GetStyleContextAt(aList,index++); value = GetMargin(style,aEdge); if (value > result) result = value; @@ -520,12 +532,13 @@ nscoord nsCellLayoutData::FindLargestMargin(nsVoidArray* aList,PRUint8 aEdge) void nsCellLayoutData::CalculateMargins(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, + nsIStyleContext* aCellStyle, nsVoidArray* aBoundaryCells[4]) { // By default the margin is just the margin found in the // table cells style - mMargin = aCellStyle->margin; + nsStyleSpacing* spacing = (nsStyleSpacing*)aCellStyle->GetData(kStyleSpacingSID); + mMargin = spacing->mMargin; // Left and Top Margins are collapsed with their neightbors // Right and Bottom Margins are simple left as they are @@ -553,9 +566,9 @@ void nsCellLayoutData::RecalcLayoutData(nsTableFrame* aTableFrame, nsVoidArray* aBoundaryCells[4]) { - nsStyleMolecule* cellStyle; + nsIStyleContextPtr cellStyle; - mCellFrame->GetStyleData(kStyleMoleculeSID, (nsStyleStruct*&)cellStyle); + mCellFrame->GetStyleContext(nsnull, cellStyle.AssignRef()); CalculateBorders(aTableFrame,cellStyle,aBoundaryCells); CalculateMargins(aTableFrame,cellStyle,aBoundaryCells); @@ -586,10 +599,10 @@ void nsCellLayoutData::List(FILE* out, PRInt32 aIndent) const nscoord top,left,bottom,right; - top = (mBorderStyle[NS_SIDE_TOP] ? mBorderStyle[NS_SIDE_TOP]->border.top : 0); - left = (mBorderStyle[NS_SIDE_LEFT] ? mBorderStyle[NS_SIDE_LEFT]->border.left : 0); - bottom = (mBorderStyle[NS_SIDE_BOTTOM] ? mBorderStyle[NS_SIDE_BOTTOM]->border.bottom : 0); - right = (mBorderStyle[NS_SIDE_RIGHT] ? mBorderStyle[NS_SIDE_RIGHT]->border.right : 0); + top = (mBorderStyle[NS_SIDE_TOP] ? mBorderStyle[NS_SIDE_TOP]->mBorder.top : 0); + left = (mBorderStyle[NS_SIDE_LEFT] ? mBorderStyle[NS_SIDE_LEFT]->mBorder.left : 0); + bottom = (mBorderStyle[NS_SIDE_BOTTOM] ? mBorderStyle[NS_SIDE_BOTTOM]->mBorder.bottom : 0); + right = (mBorderStyle[NS_SIDE_RIGHT] ? mBorderStyle[NS_SIDE_RIGHT]->mBorder.right : 0); fprintf(out,"Border -- Top: %d Left: %d Bottom: %d Right: %d \n", diff --git a/mozilla/layout/html/table/src/nsCellLayoutData.h b/mozilla/layout/html/table/src/nsCellLayoutData.h index 2012996e6df..145dc05c270 100644 --- a/mozilla/layout/html/table/src/nsCellLayoutData.h +++ b/mozilla/layout/html/table/src/nsCellLayoutData.h @@ -25,7 +25,8 @@ class nsColLayoutData; class nsTableFrame; - +class nsIStyleContext; +struct nsStyleSpacing; /** Simple data class that represents in-process reflow information about a cell. @@ -76,56 +77,56 @@ public: /** debug method outputs data about this cell to FILE *out */ void List(FILE* out = stdout, PRInt32 aIndent = 0) const; - /** returns the style molecule associated with this cell */ - nsStyleMolecule* GetStyleMolecule(); + /** returns the style context associated with this cell */ + nsIStyleContext* GetStyleContext(); private: // All these methods are support methods for RecalcLayoutData - nsStyleMolecule* GetStyleMoleculeAt(nsVoidArray* aList, PRInt32 aIndex); + nsIStyleContext* GetStyleContextAt(nsVoidArray* aList, PRInt32 aIndex); - nscoord GetMargin(nsStyleMolecule* aStyle,PRUint8 aEdge); + nscoord GetMargin(nsIStyleContext* aStyle,PRUint8 aEdge); - nscoord GetBorderWidth(nsStyleMolecule* aStyle,PRUint8 aEdge); + nscoord GetBorderWidth(nsIStyleContext* aStyle,PRUint8 aEdge); - nscoord GetPadding(nsStyleMolecule* aStyle,PRUint8 aEdge); + nscoord GetPadding(nsIStyleContext* aStyle,PRUint8 aEdge); PRUint8 GetOpposingEdge(PRUint8 aEdge); - nsStyleMolecule* CompareCellBorders(nsStyleMolecule* aStyle1, + nsIStyleContext* CompareCellBorders(nsIStyleContext* aStyle1, PRUint8 aEdge1, - nsStyleMolecule* aStyle2, + nsIStyleContext* aStyle2, PRUint8 aEdge2); - nsStyleMolecule* FindHighestPrecedentBorder(nsVoidArray* aList, + nsIStyleContext* FindHighestPrecedentBorder(nsVoidArray* aList, PRUint8 aEdge); - nsStyleMolecule* FindInnerBorder( nsStyleMolecule* aStyle, - nsVoidArray* aList, - PRUint8 aEdge); + nsStyleSpacing* FindInnerBorder( nsIStyleContext* aStyle, + nsVoidArray* aList, + PRUint8 aEdge); - nsStyleMolecule* FindOuterBorder( nsTableFrame* aTableFrame, - nsIFrame* aFrame, - nsStyleMolecule* aStyle, - PRUint8 aEdge); + nsStyleSpacing* FindOuterBorder( nsTableFrame* aTableFrame, + nsIFrame* aFrame, + nsIStyleContext* aStyle, + PRUint8 aEdge); - nsStyleMolecule* FindBorderStyle(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, - nsVoidArray* aCellList, - PRUint8 aEdge); + nsStyleSpacing* FindBorderStyle(nsTableFrame* aTableFrame, + nsIStyleContext* aCellStyle, + nsVoidArray* aCellList, + PRUint8 aEdge); void CalculateBorders(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, + nsIStyleContext* aCellStyle, nsVoidArray* aBoundaryCells[4]); nscoord FindLargestMargin(nsVoidArray* aList,PRUint8 aEdge); void CalculateMargins(nsTableFrame* aTableFrame, - nsStyleMolecule* aCellStyle, + nsIStyleContext* aCellStyle, nsVoidArray* aBoundaryCells[4]); public: @@ -148,7 +149,7 @@ private: nsSize mMaxElementSize; nsMargin mMargin; - nsStyleMolecule* mBorderStyle[4]; + nsStyleSpacing* mBorderStyle[4]; }; #endif diff --git a/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp b/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp index edd68945b9c..fe44dd3420d 100644 --- a/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp @@ -34,6 +34,7 @@ static const PRBool gsDebug = PR_FALSE; #endif static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); /** @@ -98,18 +99,18 @@ NS_METHOD nsTableCaptionFrame::Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); NS_ASSERTION(nsnull!=myColor, "bad style color"); - NS_ASSERTION(nsnull!=myMol, "bad style molecule"); - if (nsnull==myMol) return NS_OK; + NS_ASSERTION(nsnull!=myBorder, "bad style border"); + if (nsnull==myBorder) return NS_OK; nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); // for debug... diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 2c0f2654401..ca74d55ba83 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -36,6 +36,7 @@ static const PRBool gsDebug = PR_FALSE; #endif static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); /** @@ -57,15 +58,15 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, { nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); NS_ASSERTION(nsnull!=myColor, "bad style color"); - NS_ASSERTION(nsnull!=myMol, "bad style molecule"); + NS_ASSERTION(nsnull!=myBorder, "bad style border"); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); // for debug... diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 535d859da01..e4de2748789 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -35,6 +35,7 @@ #include "nsCellLayoutData.h" #include "nsVoidArray.h" #include "prinrval.h" +#include "nsIPtr.h" #ifdef NS_DEBUG @@ -56,8 +57,15 @@ static const PRBool gsDebugMBP = PR_FALSE; #endif static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); +NS_DEF_PTR(nsTableContent); +NS_DEF_PTR(nsTableCol); +NS_DEF_PTR(nsTableCell); + /* ----------- InnerTableReflowState ---------- */ struct InnerTableReflowState { @@ -395,16 +403,16 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext& aPresContext, // table paint code is concerned primarily with borders and bg color nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); NS_ASSERTION(nsnull != myColor, "null style color"); - NS_ASSERTION(nsnull != myMol, "null style molecule"); - if (nsnull!=myMol) + NS_ASSERTION(nsnull != myBorder, "null style border"); + if (nsnull!=myBorder) { nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); } // for debug... @@ -568,7 +576,7 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont * TBody, in order */ for (;;) { - nsIContent* kid = c->ChildAt(kidIndex); // kid: REFCNT++ + nsIContentPtr kid = c->ChildAt(kidIndex); // kid: REFCNT++ if (nsnull == kid) { result = frComplete; break; @@ -576,11 +584,11 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont mLastContentIsComplete = PR_TRUE; - const PRInt32 contentType = ((nsTableContent *)kid)->GetType(); + const PRInt32 contentType = ((nsTableContent *)(nsIContent*)kid)->GetType(); if (contentType==nsITableContent::kTableRowGroupType) { // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); NS_ASSERTION(nsnull != kidStyleContext, "null style context for kid"); nsStyleMolecule* kidStyle = @@ -605,7 +613,6 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont NS_RELEASE(kidDel); kidFrame->SetStyleContext(kidStyleContext); } - NS_RELEASE(kidStyleContext); nsSize maxKidElementSize; result = ReflowChild(kidFrame, aPresContext, kidSize, availSize, pKidMaxSize); @@ -653,7 +660,6 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont // If the child didn't finish layout then it means that it used // up all of our available space (or needs us to split). mLastContentIsComplete = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- break; } } @@ -663,10 +669,8 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont // If the child didn't finish layout then it means that it used // up all of our available space (or needs us to split). mLastContentIsComplete = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- break; } - NS_RELEASE(kid); // kid: REFCNT-- } if (nsnull != prevKidFrame) { @@ -910,19 +914,17 @@ PRBool nsTableFrame::ReflowMappedChildren( nsIPresContext* aPresContext, nsIFrame::ReflowStatus status; // Get top margin for this kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - if (((nsTableContent *)kid)->GetType() == nsITableContent::kTableRowGroupType) + kidFrame->GetContent(kid.AssignRef()); + if (((nsTableContent *)(nsIContent*)kid)->GetType() == nsITableContent::kTableRowGroupType) { // skip children that are not row groups - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kid); - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -1315,7 +1317,7 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; @@ -1324,12 +1326,11 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, // Make sure we still have room left if (aState.availSize.height <= 0) { // Note: return status was set to frNotComplete above... - NS_RELEASE(kid); break; } // Resolve style for the child - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); // Figure out how we should treat the child @@ -1347,8 +1348,6 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } - NS_RELEASE(kid); - NS_RELEASE(kidStyleContext); // Try to reflow the child into the available space. It might not // fit or might need continuing. @@ -1551,7 +1550,7 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt nsVoidArray *columnLayoutData = GetColumnLayoutData(); nsColLayoutData * colData = (nsColLayoutData *)(columnLayoutData->ElementAt(colIndex)); NS_ASSERTION(nsnull != colData, "bad column data"); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ NS_ASSERTION(nsnull != col, "bad col"); nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); @@ -1580,8 +1579,8 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt // SEC: TODO -- when we have a style system, set the mol for the col nsCellLayoutData * data = (nsCellLayoutData *)(cells->ElementAt(0)); nsTableCellFrame *cellFrame = data->GetCellFrame(); - nsTableCell *cell; - cellFrame->GetContent((nsIContent*&)cell); // cell: REFCNT++ + nsTableCellPtr cell; + cellFrame->GetContent((nsIContent*&)(cell.AssignRef())); // cell: REFCNT++ nsStyleMolecule* cellStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); NS_ASSERTION(nsnull != cellStyle, "bad style for cell."); // SEC: this is the code to replace @@ -1590,7 +1589,6 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt if (-1!=cellStyle->proportionalWidth) colStyle->proportionalWidth = cellStyle->proportionalWidth; // SEC: end code to replace - NS_RELEASE(cell); // cell: REFCNT-- } if (-1!=colStyle->fixedWidth) { // this col has fixed width, so set the cell's width @@ -1641,7 +1639,6 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt if (gsDebug==PR_TRUE) printf (" after this col, minTableWidth = %d and maxTableWidth = %d\n", aMinTableWidth, aMaxTableWidth); - NS_IF_RELEASE(col); // col: ADDREF-- } // end Step 1 for fixed-width columns return PR_TRUE; } @@ -1722,7 +1719,7 @@ PRBool nsTableFrame::SetColumnsToMinWidth(nsIPresContext* aPresContext) for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1763,7 +1760,6 @@ PRBool nsTableFrame::SetColumnsToMinWidth(nsIPresContext* aPresContext) printf (" 2: col %d, set to width = %d\n", colIndex, mColumnWidths[colIndex]); } } - NS_IF_RELEASE(col); // col: ADDREF-- } return result; } @@ -1780,7 +1776,7 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1856,7 +1852,6 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, } } } - NS_IF_RELEASE(col); // col: ADDREF-- } return result; } @@ -1877,7 +1872,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1957,7 +1952,6 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext } } } - NS_IF_RELEASE(col); // col: ADDREF-- } // post-process if necessary @@ -2033,9 +2027,9 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, ChildAt(i, kidFrame); // frames are not ref counted NS_ASSERTION(nsnull != kidFrame, "bad kid frame"); - nsTableContent* kid; + nsTableContentPtr kid; - kidFrame->GetContent((nsIContent*&)kid); // kid: REFCNT++ + kidFrame->GetContent((nsIContent*&)(kid.AssignRef())); // kid: REFCNT++ NS_ASSERTION(nsnull != kid, "bad kid"); if (kid->GetType() == nsITableContent::kTableRowGroupType) { @@ -2209,7 +2203,6 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, rowGroupFrame->SizeTo(rowGroupFrameSize.width, rowGroupHeight); tableHeight += rowGroupHeight; } - NS_RELEASE(kid); // kid: REFCNT-- } if (0!=tableHeight) { @@ -2293,7 +2286,7 @@ PRBool nsTableFrame::SetCellLayoutData(nsCellLayoutData * aData, nsTableCell *aC PRInt32 tableKidCount = tablePart->ChildCount(); for (PRInt32 i=0; iChildAt(i); + nsTableContentPtr tableKid = (nsTableContent *)tablePart->ChildAt(i); NS_ASSERTION(nsnull != tableKid, "bad kid"); const int contentType = tableKid->GetType(); if (contentType == nsITableContent::kTableColGroupType) @@ -2301,20 +2294,17 @@ PRBool nsTableFrame::SetCellLayoutData(nsCellLayoutData * aData, nsTableCell *aC PRInt32 colsInGroup = tableKid->ChildCount(); for (PRInt32 j=0; jChildAt(j); + nsTableColPtr col = (nsTableCol *)tableKid->ChildAt(j); NS_ASSERTION(nsnull != col, "bad content"); nsColLayoutData *colData = new nsColLayoutData(col); mColumnLayoutData->AppendElement((void *)colData); - NS_RELEASE(col); // col: REFCNT-- } } // can't have col groups after row groups, so stop if you find a row group else if (contentType == nsITableContent::kTableRowGroupType) { - NS_RELEASE(tableKid); // tableKid: REFCNT-- break; } - NS_RELEASE(tableKid); // tableKid: REFCNT-- } } @@ -2388,16 +2378,14 @@ nsCellLayoutData * nsTableFrame::GetCellLayoutData(nsTableCell *aCell) for (PRInt32 i=0; iElementAt(i)); - nsTableCell *cell; + nsTableCellPtr cell; - data->GetCellFrame()->GetContent((nsIContent*&)cell); // cell: REFCNT++ + data->GetCellFrame()->GetContent((nsIContent*&)(cell.AssignRef())); // cell: REFCNT++ if (cell == aCell) { result = data; - NS_RELEASE(cell); // cell: REFCNT-- break; } - NS_RELEASE(cell); // cell: REFCNT-- } } } @@ -2542,7 +2530,7 @@ nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, for (colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); if (PR_TRUE==IsProportionalWidth(colStyle)) @@ -2552,7 +2540,6 @@ nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, mColumnWidths[colIndex] += additionalSpace; additionalSpaceAdded += additionalSpace; } - NS_IF_RELEASE(col); // col: ADDREF-- } if (spaceUsed+additionalSpaceAdded < aMaxTableWidth) mColumnWidths[numCols-1] += (aMaxTableWidth - (spaceUsed+additionalSpaceAdded)); diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index 385d46b6e1e..2439865157f 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -32,6 +32,7 @@ #include "nsCSSLayout.h" #include "nsVoidArray.h" #include "nsReflowCommand.h" +#include "nsIPtr.h" #ifdef NS_DEBUG static PRBool gsDebug = PR_FALSE; @@ -45,6 +46,9 @@ static const PRBool gsDebug = PR_FALSE; static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct OuterTableReflowState { // The presentation context @@ -231,13 +235,12 @@ NS_METHOD nsTableOuterFrame::ResizeReflow(nsIPresContext* aPresContext, &innerTableMaxElementSize, tableStyleMol); #ifdef NOISY_MARGINS - nsIContent* content = mInnerTableFrame->GetContent(); + nsIContentPtr content = mInnerTableFrame->GetContent(); nsTablePart *table = (nsTablePart*)content; if (table != nsnull) table->DumpCellMap(); mInnerTableFrame->ResetColumnLayoutData(); mInnerTableFrame->ListColumnLayoutData(stdout,1); - NS_IF_RELEASE(content); #endif } @@ -455,13 +458,12 @@ PRBool nsTableOuterFrame::ReflowMappedChildren( nsIPresContext* aPresContex kidFrame, aState.processingCaption?"caption":"inner"); // Get top margin for this kid - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -835,9 +837,9 @@ PRBool nsTableOuterFrame::PullUpChildren( nsIPresContext* aPresContext, */ void nsTableOuterFrame::SetReflowState(OuterTableReflowState& aState, nsIFrame* aKidFrame) { - nsIContent *kid; + nsIContentPtr kid; - aKidFrame->GetContent(kid); // kid: REFCNT++ + aKidFrame->GetContent(kid.AssignRef()); // kid: REFCNT++ nsITableContent *tableContentInterface = nsnull; kid->QueryInterface(kITableContentIID, (void**)&tableContentInterface);// tableContentInterface: REFCNT++ if (nsnull!=tableContentInterface) @@ -847,7 +849,6 @@ void nsTableOuterFrame::SetReflowState(OuterTableReflowState& aState, nsIFrame* } else aState.processingCaption = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- } /** @@ -870,9 +871,9 @@ nsTableOuterFrame::ReflowChild( nsIFrame* aKidFrame, if (PR_TRUE==aState.processingCaption) { // it's a caption, find out if it's top or bottom // Resolve style - nsIStyleContext* captionStyleContext; + nsIStyleContextPtr captionStyleContext; - aKidFrame->GetStyleContext(aPresContext, captionStyleContext); + aKidFrame->GetStyleContext(aPresContext, captionStyleContext.AssignRef()); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -915,7 +916,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_OK!=frameCreated) return; // SEC: an error!!!! // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(mContent, this); NS_ASSERTION(nsnull!=kidStyleContext, "bad style context for kid."); mInnerTableFrame->SetStyleContext(kidStyleContext); @@ -930,11 +931,11 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) // create caption frames as needed nsIFrame *lastTopCaption = nsnull; for (PRInt32 kidIndex=0; /* nada */ ;kidIndex++) { - nsIContent* caption = mContent->ChildAt(kidIndex); // caption: REFCNT++ + nsIContentPtr caption = mContent->ChildAt(kidIndex); // caption: REFCNT++ if (nsnull == caption) { break; } - const PRInt32 contentType = ((nsTableContent *)caption)->GetType(); + const PRInt32 contentType = ((nsTableContent *)(nsIContent*)caption)->GetType(); if (contentType==nsITableContent::kTableCaptionType) { nsIFrame *captionFrame=nsnull; @@ -942,7 +943,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_OK!=frameCreated) return; // SEC: an error!!!! // Resolve style - nsIStyleContext* captionStyleContext = + nsIStyleContextPtr captionStyleContext = aPresContext->ResolveStyleContextFor(caption, this); NS_ASSERTION(nsnull!=captionStyleContext, "bad style context for caption."); nsStyleMolecule* captionStyle = @@ -976,11 +977,9 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) lastTopCaption = captionFrame; } mCaptionFrames->AppendElement(captionFrame); - NS_RELEASE(caption); // caption: REFCNT-- } else { - NS_RELEASE(caption); // caption: REFCNT-- break; } } @@ -1030,9 +1029,9 @@ nsTableOuterFrame::ResizeReflowTopCaptionsPass2(nsIPresContext* aPresContext, nsTableCaptionFrame *captionFrame = (nsTableCaptionFrame *)mCaptionFrames->ElementAt(captionIndex); // Resolve style - nsIStyleContext* captionStyleContext; + nsIStyleContextPtr captionStyleContext; - captionFrame->GetStyleContext(aPresContext, captionStyleContext); + captionFrame->GetStyleContext(aPresContext, captionStyleContext.AssignRef()); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -1099,7 +1098,7 @@ nsTableOuterFrame::ResizeReflowBottomCaptionsPass2(nsIPresContext* aPresContext // Resolve style /* - nsIStyleContext* captionStyleContext = captionFrame->GetStyleContext(aPresContext); + nsIStyleContextPtr captionStyleContext = captionFrame->GetStyleContext(aPresContext); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -1216,10 +1215,9 @@ void nsTableOuterFrame::PrepareContinuingFrame(nsIPresContext* aPresContext, // Resolve style for the continuing frame and set its style context. // XXX presumptive - nsIStyleContext* styleContext = + nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, aParent); aContFrame->SetStyleContext(styleContext); - NS_RELEASE(styleContext); } NS_METHOD nsTableOuterFrame::VerifyTree() const @@ -1336,10 +1334,9 @@ void nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext) mChildCount++; // Resolve style and set the style context - nsIStyleContext* styleContext = + nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, this); mInnerTableFrame->SetStyleContext(styleContext); - NS_RELEASE(styleContext); } else { nsTableOuterFrame* prevOuterTable = (nsTableOuterFrame*)mPrevInFlow; diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp index 3bfe3881cea..06689af4349 100644 --- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -25,6 +25,7 @@ #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsIView.h" +#include "nsIPtr.h" #ifdef NS_DEBUG static PRBool gsDebug1 = PR_FALSE; @@ -38,6 +39,9 @@ static const PRBool gsDebug2 = PR_FALSE; static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + /* ----------- RowGroupReflowState ---------- */ struct RowGroupReflowState { @@ -264,17 +268,15 @@ PRBool nsTableRowGroupFrame::ReflowMappedChildren( nsIPresContext* aPresCon nsIFrame::ReflowStatus status; // Get top margin for this kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC; + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kid); - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -698,7 +700,7 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; @@ -707,12 +709,11 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, // Make sure we still have room left if (aState.availSize.height <= 0) { // Note: return status was set to frNotComplete above... - NS_RELEASE(kid); break; } // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidStyleContext->GetData(kStyleMoleculeSID); @@ -731,8 +732,6 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } - NS_RELEASE(kid); - NS_RELEASE(kidStyleContext); // Try to reflow the child into the available space. It might not // fit or might need continuing. diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 2c0f2654401..ca74d55ba83 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -36,6 +36,7 @@ static const PRBool gsDebug = PR_FALSE; #endif static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); /** @@ -57,15 +58,15 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, { nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); NS_ASSERTION(nsnull!=myColor, "bad style color"); - NS_ASSERTION(nsnull!=myMol, "bad style molecule"); + NS_ASSERTION(nsnull!=myBorder, "bad style border"); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); // for debug... diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 535d859da01..e4de2748789 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -35,6 +35,7 @@ #include "nsCellLayoutData.h" #include "nsVoidArray.h" #include "prinrval.h" +#include "nsIPtr.h" #ifdef NS_DEBUG @@ -56,8 +57,15 @@ static const PRBool gsDebugMBP = PR_FALSE; #endif static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +static NS_DEFINE_IID(kStyleBorderSID, NS_STYLEBORDER_SID); static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); +NS_DEF_PTR(nsTableContent); +NS_DEF_PTR(nsTableCol); +NS_DEF_PTR(nsTableCell); + /* ----------- InnerTableReflowState ---------- */ struct InnerTableReflowState { @@ -395,16 +403,16 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext& aPresContext, // table paint code is concerned primarily with borders and bg color nsStyleColor* myColor = (nsStyleColor*)mStyleContext->GetData(kStyleColorSID); - nsStyleMolecule* myMol = - (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); + nsStyleBorder* myBorder = + (nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); NS_ASSERTION(nsnull != myColor, "null style color"); - NS_ASSERTION(nsnull != myMol, "null style molecule"); - if (nsnull!=myMol) + NS_ASSERTION(nsnull != myBorder, "null style border"); + if (nsnull!=myBorder) { nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, mRect, *myColor); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, mRect, *myMol, 0); + aDirtyRect, mRect, *myBorder, 0); } // for debug... @@ -568,7 +576,7 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont * TBody, in order */ for (;;) { - nsIContent* kid = c->ChildAt(kidIndex); // kid: REFCNT++ + nsIContentPtr kid = c->ChildAt(kidIndex); // kid: REFCNT++ if (nsnull == kid) { result = frComplete; break; @@ -576,11 +584,11 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont mLastContentIsComplete = PR_TRUE; - const PRInt32 contentType = ((nsTableContent *)kid)->GetType(); + const PRInt32 contentType = ((nsTableContent *)(nsIContent*)kid)->GetType(); if (contentType==nsITableContent::kTableRowGroupType) { // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); NS_ASSERTION(nsnull != kidStyleContext, "null style context for kid"); nsStyleMolecule* kidStyle = @@ -605,7 +613,6 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont NS_RELEASE(kidDel); kidFrame->SetStyleContext(kidStyleContext); } - NS_RELEASE(kidStyleContext); nsSize maxKidElementSize; result = ReflowChild(kidFrame, aPresContext, kidSize, availSize, pKidMaxSize); @@ -653,7 +660,6 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont // If the child didn't finish layout then it means that it used // up all of our available space (or needs us to split). mLastContentIsComplete = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- break; } } @@ -663,10 +669,8 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont // If the child didn't finish layout then it means that it used // up all of our available space (or needs us to split). mLastContentIsComplete = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- break; } - NS_RELEASE(kid); // kid: REFCNT-- } if (nsnull != prevKidFrame) { @@ -910,19 +914,17 @@ PRBool nsTableFrame::ReflowMappedChildren( nsIPresContext* aPresContext, nsIFrame::ReflowStatus status; // Get top margin for this kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - if (((nsTableContent *)kid)->GetType() == nsITableContent::kTableRowGroupType) + kidFrame->GetContent(kid.AssignRef()); + if (((nsTableContent *)(nsIContent*)kid)->GetType() == nsITableContent::kTableRowGroupType) { // skip children that are not row groups - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kid); - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -1315,7 +1317,7 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, LastChild(prevKidFrame); for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; @@ -1324,12 +1326,11 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, // Make sure we still have room left if (aState.availSize.height <= 0) { // Note: return status was set to frNotComplete above... - NS_RELEASE(kid); break; } // Resolve style for the child - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); // Figure out how we should treat the child @@ -1347,8 +1348,6 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } - NS_RELEASE(kid); - NS_RELEASE(kidStyleContext); // Try to reflow the child into the available space. It might not // fit or might need continuing. @@ -1551,7 +1550,7 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt nsVoidArray *columnLayoutData = GetColumnLayoutData(); nsColLayoutData * colData = (nsColLayoutData *)(columnLayoutData->ElementAt(colIndex)); NS_ASSERTION(nsnull != colData, "bad column data"); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ NS_ASSERTION(nsnull != col, "bad col"); nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); @@ -1580,8 +1579,8 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt // SEC: TODO -- when we have a style system, set the mol for the col nsCellLayoutData * data = (nsCellLayoutData *)(cells->ElementAt(0)); nsTableCellFrame *cellFrame = data->GetCellFrame(); - nsTableCell *cell; - cellFrame->GetContent((nsIContent*&)cell); // cell: REFCNT++ + nsTableCellPtr cell; + cellFrame->GetContent((nsIContent*&)(cell.AssignRef())); // cell: REFCNT++ nsStyleMolecule* cellStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); NS_ASSERTION(nsnull != cellStyle, "bad style for cell."); // SEC: this is the code to replace @@ -1590,7 +1589,6 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt if (-1!=cellStyle->proportionalWidth) colStyle->proportionalWidth = cellStyle->proportionalWidth; // SEC: end code to replace - NS_RELEASE(cell); // cell: REFCNT-- } if (-1!=colStyle->fixedWidth) { // this col has fixed width, so set the cell's width @@ -1641,7 +1639,6 @@ PRBool nsTableFrame::AssignFixedColumnWidths(nsIPresContext* aPresContext, PRInt if (gsDebug==PR_TRUE) printf (" after this col, minTableWidth = %d and maxTableWidth = %d\n", aMinTableWidth, aMaxTableWidth); - NS_IF_RELEASE(col); // col: ADDREF-- } // end Step 1 for fixed-width columns return PR_TRUE; } @@ -1722,7 +1719,7 @@ PRBool nsTableFrame::SetColumnsToMinWidth(nsIPresContext* aPresContext) for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1763,7 +1760,6 @@ PRBool nsTableFrame::SetColumnsToMinWidth(nsIPresContext* aPresContext) printf (" 2: col %d, set to width = %d\n", colIndex, mColumnWidths[colIndex]); } } - NS_IF_RELEASE(col); // col: ADDREF-- } return result; } @@ -1780,7 +1776,7 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1856,7 +1852,6 @@ PRBool nsTableFrame::BalanceColumnsTableFits(nsIPresContext* aPresContext, } } } - NS_IF_RELEASE(col); // col: ADDREF-- } return result; } @@ -1877,7 +1872,7 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext for (PRInt32 colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); nsVoidArray *cells = colData->GetCells(); @@ -1957,7 +1952,6 @@ PRBool nsTableFrame::BalanceColumnsHTML4Constrained(nsIPresContext* aPresContext } } } - NS_IF_RELEASE(col); // col: ADDREF-- } // post-process if necessary @@ -2033,9 +2027,9 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, ChildAt(i, kidFrame); // frames are not ref counted NS_ASSERTION(nsnull != kidFrame, "bad kid frame"); - nsTableContent* kid; + nsTableContentPtr kid; - kidFrame->GetContent((nsIContent*&)kid); // kid: REFCNT++ + kidFrame->GetContent((nsIContent*&)(kid.AssignRef())); // kid: REFCNT++ NS_ASSERTION(nsnull != kid, "bad kid"); if (kid->GetType() == nsITableContent::kTableRowGroupType) { @@ -2209,7 +2203,6 @@ void nsTableFrame::ShrinkWrapChildren(nsIPresContext* aPresContext, rowGroupFrame->SizeTo(rowGroupFrameSize.width, rowGroupHeight); tableHeight += rowGroupHeight; } - NS_RELEASE(kid); // kid: REFCNT-- } if (0!=tableHeight) { @@ -2293,7 +2286,7 @@ PRBool nsTableFrame::SetCellLayoutData(nsCellLayoutData * aData, nsTableCell *aC PRInt32 tableKidCount = tablePart->ChildCount(); for (PRInt32 i=0; iChildAt(i); + nsTableContentPtr tableKid = (nsTableContent *)tablePart->ChildAt(i); NS_ASSERTION(nsnull != tableKid, "bad kid"); const int contentType = tableKid->GetType(); if (contentType == nsITableContent::kTableColGroupType) @@ -2301,20 +2294,17 @@ PRBool nsTableFrame::SetCellLayoutData(nsCellLayoutData * aData, nsTableCell *aC PRInt32 colsInGroup = tableKid->ChildCount(); for (PRInt32 j=0; jChildAt(j); + nsTableColPtr col = (nsTableCol *)tableKid->ChildAt(j); NS_ASSERTION(nsnull != col, "bad content"); nsColLayoutData *colData = new nsColLayoutData(col); mColumnLayoutData->AppendElement((void *)colData); - NS_RELEASE(col); // col: REFCNT-- } } // can't have col groups after row groups, so stop if you find a row group else if (contentType == nsITableContent::kTableRowGroupType) { - NS_RELEASE(tableKid); // tableKid: REFCNT-- break; } - NS_RELEASE(tableKid); // tableKid: REFCNT-- } } @@ -2388,16 +2378,14 @@ nsCellLayoutData * nsTableFrame::GetCellLayoutData(nsTableCell *aCell) for (PRInt32 i=0; iElementAt(i)); - nsTableCell *cell; + nsTableCellPtr cell; - data->GetCellFrame()->GetContent((nsIContent*&)cell); // cell: REFCNT++ + data->GetCellFrame()->GetContent((nsIContent*&)(cell.AssignRef())); // cell: REFCNT++ if (cell == aCell) { result = data; - NS_RELEASE(cell); // cell: REFCNT-- break; } - NS_RELEASE(cell); // cell: REFCNT-- } } } @@ -2542,7 +2530,7 @@ nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, for (colIndex = 0; colIndexElementAt(colIndex)); - nsTableCol *col = colData->GetCol(); // col: ADDREF++ + nsTableColPtr col = colData->GetCol(); // col: ADDREF++ nsStyleMolecule* colStyle = (nsStyleMolecule*)mStyleContext->GetData(kStyleMoleculeSID); if (PR_TRUE==IsProportionalWidth(colStyle)) @@ -2552,7 +2540,6 @@ nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, mColumnWidths[colIndex] += additionalSpace; additionalSpaceAdded += additionalSpace; } - NS_IF_RELEASE(col); // col: ADDREF-- } if (spaceUsed+additionalSpaceAdded < aMaxTableWidth) mColumnWidths[numCols-1] += (aMaxTableWidth - (spaceUsed+additionalSpaceAdded)); diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index 385d46b6e1e..2439865157f 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -32,6 +32,7 @@ #include "nsCSSLayout.h" #include "nsVoidArray.h" #include "nsReflowCommand.h" +#include "nsIPtr.h" #ifdef NS_DEBUG static PRBool gsDebug = PR_FALSE; @@ -45,6 +46,9 @@ static const PRBool gsDebug = PR_FALSE; static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + struct OuterTableReflowState { // The presentation context @@ -231,13 +235,12 @@ NS_METHOD nsTableOuterFrame::ResizeReflow(nsIPresContext* aPresContext, &innerTableMaxElementSize, tableStyleMol); #ifdef NOISY_MARGINS - nsIContent* content = mInnerTableFrame->GetContent(); + nsIContentPtr content = mInnerTableFrame->GetContent(); nsTablePart *table = (nsTablePart*)content; if (table != nsnull) table->DumpCellMap(); mInnerTableFrame->ResetColumnLayoutData(); mInnerTableFrame->ListColumnLayoutData(stdout,1); - NS_IF_RELEASE(content); #endif } @@ -455,13 +458,12 @@ PRBool nsTableOuterFrame::ReflowMappedChildren( nsIPresContext* aPresContex kidFrame, aState.processingCaption?"caption":"inner"); // Get top margin for this kid - nsIStyleContext* kidSC; + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -835,9 +837,9 @@ PRBool nsTableOuterFrame::PullUpChildren( nsIPresContext* aPresContext, */ void nsTableOuterFrame::SetReflowState(OuterTableReflowState& aState, nsIFrame* aKidFrame) { - nsIContent *kid; + nsIContentPtr kid; - aKidFrame->GetContent(kid); // kid: REFCNT++ + aKidFrame->GetContent(kid.AssignRef()); // kid: REFCNT++ nsITableContent *tableContentInterface = nsnull; kid->QueryInterface(kITableContentIID, (void**)&tableContentInterface);// tableContentInterface: REFCNT++ if (nsnull!=tableContentInterface) @@ -847,7 +849,6 @@ void nsTableOuterFrame::SetReflowState(OuterTableReflowState& aState, nsIFrame* } else aState.processingCaption = PR_FALSE; - NS_RELEASE(kid); // kid: REFCNT-- } /** @@ -870,9 +871,9 @@ nsTableOuterFrame::ReflowChild( nsIFrame* aKidFrame, if (PR_TRUE==aState.processingCaption) { // it's a caption, find out if it's top or bottom // Resolve style - nsIStyleContext* captionStyleContext; + nsIStyleContextPtr captionStyleContext; - aKidFrame->GetStyleContext(aPresContext, captionStyleContext); + aKidFrame->GetStyleContext(aPresContext, captionStyleContext.AssignRef()); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -915,7 +916,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_OK!=frameCreated) return; // SEC: an error!!!! // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(mContent, this); NS_ASSERTION(nsnull!=kidStyleContext, "bad style context for kid."); mInnerTableFrame->SetStyleContext(kidStyleContext); @@ -930,11 +931,11 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) // create caption frames as needed nsIFrame *lastTopCaption = nsnull; for (PRInt32 kidIndex=0; /* nada */ ;kidIndex++) { - nsIContent* caption = mContent->ChildAt(kidIndex); // caption: REFCNT++ + nsIContentPtr caption = mContent->ChildAt(kidIndex); // caption: REFCNT++ if (nsnull == caption) { break; } - const PRInt32 contentType = ((nsTableContent *)caption)->GetType(); + const PRInt32 contentType = ((nsTableContent *)(nsIContent*)caption)->GetType(); if (contentType==nsITableContent::kTableCaptionType) { nsIFrame *captionFrame=nsnull; @@ -942,7 +943,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_OK!=frameCreated) return; // SEC: an error!!!! // Resolve style - nsIStyleContext* captionStyleContext = + nsIStyleContextPtr captionStyleContext = aPresContext->ResolveStyleContextFor(caption, this); NS_ASSERTION(nsnull!=captionStyleContext, "bad style context for caption."); nsStyleMolecule* captionStyle = @@ -976,11 +977,9 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) lastTopCaption = captionFrame; } mCaptionFrames->AppendElement(captionFrame); - NS_RELEASE(caption); // caption: REFCNT-- } else { - NS_RELEASE(caption); // caption: REFCNT-- break; } } @@ -1030,9 +1029,9 @@ nsTableOuterFrame::ResizeReflowTopCaptionsPass2(nsIPresContext* aPresContext, nsTableCaptionFrame *captionFrame = (nsTableCaptionFrame *)mCaptionFrames->ElementAt(captionIndex); // Resolve style - nsIStyleContext* captionStyleContext; + nsIStyleContextPtr captionStyleContext; - captionFrame->GetStyleContext(aPresContext, captionStyleContext); + captionFrame->GetStyleContext(aPresContext, captionStyleContext.AssignRef()); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -1099,7 +1098,7 @@ nsTableOuterFrame::ResizeReflowBottomCaptionsPass2(nsIPresContext* aPresContext // Resolve style /* - nsIStyleContext* captionStyleContext = captionFrame->GetStyleContext(aPresContext); + nsIStyleContextPtr captionStyleContext = captionFrame->GetStyleContext(aPresContext); NS_ASSERTION(nsnull != captionStyleContext, "null style context for caption"); nsStyleMolecule* captionStyle = (nsStyleMolecule*)captionStyleContext->GetData(kStyleMoleculeSID); @@ -1216,10 +1215,9 @@ void nsTableOuterFrame::PrepareContinuingFrame(nsIPresContext* aPresContext, // Resolve style for the continuing frame and set its style context. // XXX presumptive - nsIStyleContext* styleContext = + nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, aParent); aContFrame->SetStyleContext(styleContext); - NS_RELEASE(styleContext); } NS_METHOD nsTableOuterFrame::VerifyTree() const @@ -1336,10 +1334,9 @@ void nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext) mChildCount++; // Resolve style and set the style context - nsIStyleContext* styleContext = + nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, this); mInnerTableFrame->SetStyleContext(styleContext); - NS_RELEASE(styleContext); } else { nsTableOuterFrame* prevOuterTable = (nsTableOuterFrame*)mPrevInFlow; diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index 3bfe3881cea..06689af4349 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -25,6 +25,7 @@ #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsIView.h" +#include "nsIPtr.h" #ifdef NS_DEBUG static PRBool gsDebug1 = PR_FALSE; @@ -38,6 +39,9 @@ static const PRBool gsDebug2 = PR_FALSE; static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID); +NS_DEF_PTR(nsIStyleContext); +NS_DEF_PTR(nsIContent); + /* ----------- RowGroupReflowState ---------- */ struct RowGroupReflowState { @@ -264,17 +268,15 @@ PRBool nsTableRowGroupFrame::ReflowMappedChildren( nsIPresContext* aPresCon nsIFrame::ReflowStatus status; // Get top margin for this kid - nsIContent* kid; + nsIContentPtr kid; - kidFrame->GetContent(kid); - nsIStyleContext* kidSC; + kidFrame->GetContent(kid.AssignRef()); + nsIStyleContextPtr kidSC; - kidFrame->GetStyleContext(aPresContext, kidSC); + kidFrame->GetStyleContext(aPresContext, kidSC.AssignRef()); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID); nscoord topMargin = GetTopMarginFor(aPresContext, aState, kidMol); nscoord bottomMargin = kidMol->margin.bottom; - NS_RELEASE(kid); - NS_RELEASE(kidSC); // Figure out the amount of available size for the child (subtract // off the top margin we are going to apply to it) @@ -698,7 +700,7 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, for (;;) { // Get the next content object - nsIContent* kid = mContent->ChildAt(kidIndex); + nsIContentPtr kid = mContent->ChildAt(kidIndex); if (nsnull == kid) { result = frComplete; break; @@ -707,12 +709,11 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, // Make sure we still have room left if (aState.availSize.height <= 0) { // Note: return status was set to frNotComplete above... - NS_RELEASE(kid); break; } // Resolve style - nsIStyleContext* kidStyleContext = + nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(kid, this); nsStyleMolecule* kidMol = (nsStyleMolecule*)kidStyleContext->GetData(kStyleMoleculeSID); @@ -731,8 +732,6 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } - NS_RELEASE(kid); - NS_RELEASE(kidStyleContext); // Try to reflow the child into the available space. It might not // fit or might need continuing.