Skip to content

Commit

Permalink
Bug 852428 part 2. Make nsIFrame::Init infallible. r=dholbert
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky committed Mar 20, 2013
1 parent 757aad8 commit f144b44
Show file tree
Hide file tree
Showing 121 changed files with 372 additions and 540 deletions.
6 changes: 2 additions & 4 deletions layout/base/nsCSSFrameConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4549,14 +4549,12 @@ nsCSSFrameConstructor::InitAndRestoreFrame(const nsFrameConstructorState& aState
NS_PRECONDITION(mUpdateCount != 0,
"Should be in an update while creating frames");

nsresult rv = NS_OK;

NS_ASSERTION(aNewFrame, "Null frame cannot be initialized");
if (!aNewFrame)
return NS_ERROR_NULL_POINTER;

// Initialize the frame
rv = aNewFrame->Init(aContent, aParentFrame, aPrevInFlow);
aNewFrame->Init(aContent, aParentFrame, aPrevInFlow);
aNewFrame->AddStateBits(aState.mAdditionalStateBits);

if (aState.mFrameState) {
Expand All @@ -4569,7 +4567,7 @@ nsCSSFrameConstructor::InitAndRestoreFrame(const nsFrameConstructorState& aState
CountersDirty();
}

return rv;
return NS_OK;
}

already_AddRefed<nsStyleContext>
Expand Down
16 changes: 2 additions & 14 deletions layout/forms/nsComboboxControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,12 +1371,7 @@ nsComboboxControlFrame::CreateFrameFor(nsIContent* aContent)
return nullptr;
}

nsresult rv = mDisplayFrame->Init(mContent, this, nullptr);
if (NS_FAILED(rv)) {
mDisplayFrame->Destroy();
mDisplayFrame = nullptr;
return nullptr;
}
mDisplayFrame->Init(mContent, this, nullptr);

// Create a text frame and put it inside the block frame
nsIFrame* textFrame = NS_NewTextFrame(shell, textStyleContext);
Expand All @@ -1385,14 +1380,7 @@ nsComboboxControlFrame::CreateFrameFor(nsIContent* aContent)
}

// initialize the text frame
rv = textFrame->Init(aContent, mDisplayFrame, nullptr);
if (NS_FAILED(rv)) {
mDisplayFrame->Destroy();
mDisplayFrame = nullptr;
textFrame->Destroy();
textFrame = nullptr;
return nullptr;
}
textFrame->Init(aContent, mDisplayFrame, nullptr);
mDisplayContent->SetPrimaryFrame(textFrame);

nsFrameList textList(textFrame, textFrame);
Expand Down
9 changes: 2 additions & 7 deletions layout/forms/nsFileControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,15 @@ nsFileControlFrame::nsFileControlFrame(nsStyleContext* aContext):
}


NS_IMETHODIMP
void
nsFileControlFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
NS_ENSURE_SUCCESS(rv, rv);
nsBlockFrame::Init(aContent, aParent, aPrevInFlow);

mMouseListener = new BrowseMouseListener(this);
NS_ENSURE_TRUE(mMouseListener, NS_ERROR_OUT_OF_MEMORY);
mCaptureMouseListener = new CaptureMouseListener(this);
NS_ENSURE_TRUE(mCaptureMouseListener, NS_ERROR_OUT_OF_MEMORY);

return rv;
}

void
Expand Down
6 changes: 3 additions & 3 deletions layout/forms/nsFileControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class nsFileControlFrame : public nsBlockFrame,
public:
nsFileControlFrame(nsStyleContext* aContext);

NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;

virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
Expand Down
9 changes: 3 additions & 6 deletions layout/forms/nsHTMLButtonControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ nsHTMLButtonControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
nsContainerFrame::DestroyFrom(aDestructRoot);
}

NS_IMETHODIMP
void
nsHTMLButtonControlFrame::Init(
nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
if (NS_SUCCEEDED(rv)) {
mRenderer.SetFrame(this, PresContext());
}
return rv;
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
mRenderer.SetFrame(this, PresContext());
}

NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame)
Expand Down
6 changes: 3 additions & 3 deletions layout/forms/nsHTMLButtonControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class nsHTMLButtonControlFrame : public nsContainerFrame,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus) MOZ_OVERRIDE;

NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* asPrevInFlow) MOZ_OVERRIDE;
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* asPrevInFlow) MOZ_OVERRIDE;

virtual nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const;
virtual void SetAdditionalStyleContext(int32_t aIndex,
Expand Down
21 changes: 9 additions & 12 deletions layout/forms/nsImageControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class nsImageControlFrame : public nsImageControlFrameSuper,
~nsImageControlFrame();

virtual void DestroyFrom(nsIFrame* aDestructRoot);
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;

NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
Expand Down Expand Up @@ -104,23 +104,20 @@ NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)

NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)

NS_IMETHODIMP
void
nsImageControlFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsImageControlFrameSuper::Init(aContent, aParent, aPrevInFlow);
NS_ENSURE_SUCCESS(rv, rv);
nsImageControlFrameSuper::Init(aContent, aParent, aPrevInFlow);

// nsIntPoint allocation can fail, in which case we just set the property
// to null, which is safe
if (aPrevInFlow) {
return NS_OK;
return;
}

return mContent->SetProperty(nsGkAtoms::imageClickedPoint,
new nsIntPoint(0, 0),
IntPointDtorFunc);
mContent->SetProperty(nsGkAtoms::imageClickedPoint,
new nsIntPoint(0, 0),
IntPointDtorFunc);
}

NS_QUERYFRAME_HEAD(nsImageControlFrame)
Expand Down
11 changes: 2 additions & 9 deletions layout/forms/nsListControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,23 +984,18 @@ nsListControlFrame::GetSizeAttribute(uint32_t *aSize) {


//---------------------------------------------------------
NS_IMETHODIMP
void
nsListControlFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult result = nsHTMLScrollFrame::Init(aContent, aParent, aPrevInFlow);

// get the receiver interface from the browser button's content node
NS_ENSURE_STATE(mContent);
nsHTMLScrollFrame::Init(aContent, aParent, aPrevInFlow);

// we shouldn't have to unregister this listener because when
// our frame goes away all these content node go away as well
// because our frame is the only one who references them.
// we need to hook up our listeners before the editor is initialized
mEventListener = new nsListEventListener(this);
if (!mEventListener)
return NS_ERROR_OUT_OF_MEMORY;

mContent->AddEventListener(NS_LITERAL_STRING("keypress"), mEventListener,
false, false);
Expand All @@ -1019,8 +1014,6 @@ nsListControlFrame::Init(nsIContent* aContent,
if (IsInDropDownMode()) {
AddStateBits(NS_FRAME_IN_POPUP);
}

return result;
}

already_AddRefed<nsIContent>
Expand Down
6 changes: 3 additions & 3 deletions layout/forms/nsListControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class nsListControlFrame : public nsHTMLScrollFrame,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus) MOZ_OVERRIDE;

NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;

NS_IMETHOD DidReflow(nsPresContext* aPresContext,
const nsHTMLReflowState* aReflowState,
Expand Down
6 changes: 2 additions & 4 deletions layout/generic/nsBlockFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6455,7 +6455,7 @@ nsBlockFrame::ChildIsDirty(nsIFrame* aChild)
nsBlockFrameSuper::ChildIsDirty(aChild);
}

NS_IMETHODIMP
void
nsBlockFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
Expand All @@ -6466,7 +6466,7 @@ nsBlockFrame::Init(nsIContent* aContent,
(NS_BLOCK_FLAGS_MASK & ~NS_BLOCK_FLAGS_NON_INHERITED_MASK));
}

nsresult rv = nsBlockFrameSuper::Init(aContent, aParent, aPrevInFlow);
nsBlockFrameSuper::Init(aContent, aParent, aPrevInFlow);

if (!aPrevInFlow ||
aPrevInFlow->GetStateBits() & NS_BLOCK_NEEDS_BIDI_RESOLUTION)
Expand All @@ -6477,8 +6477,6 @@ nsBlockFrame::Init(nsIContent* aContent,
(NS_FRAME_FONT_INFLATION_CONTAINER | NS_BLOCK_FLOAT_MGR)) {
AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
}

return rv;
}

NS_IMETHODIMP
Expand Down
6 changes: 3 additions & 3 deletions layout/generic/nsBlockFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class nsBlockFrame : public nsBlockFrameSuper
NS_DECL_QUERYFRAME

// nsIFrame
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList);
NS_IMETHOD AppendFrames(ChildListID aListID,
Expand Down
5 changes: 2 additions & 3 deletions layout/generic/nsContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,19 @@ NS_QUERYFRAME_HEAD(nsContainerFrame)
NS_QUERYFRAME_ENTRY(nsContainerFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsSplittableFrame)

NS_IMETHODIMP
void
nsContainerFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
if (aPrevInFlow) {
// Make sure we copy bits from our prev-in-flow that will affect
// us. A continuation for a container frame needs to know if it
// has a child with a view so that we'll properly reposition it.
if (aPrevInFlow->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)
AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
}
return rv;
}

NS_IMETHODIMP
Expand Down
6 changes: 3 additions & 3 deletions layout/generic/nsContainerFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class nsContainerFrame : public nsSplittableFrame
NS_DECL_QUERYFRAME

// nsIFrame overrides
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList) MOZ_OVERRIDE;
NS_IMETHOD AppendFrames(ChildListID aListID,
Expand Down
4 changes: 2 additions & 2 deletions layout/generic/nsFirstLetterFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ nsFirstLetterFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
BuildDisplayListForInline(aBuilder, aDirtyRect, aLists);
}

NS_IMETHODIMP
void
nsFirstLetterFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
Expand All @@ -73,7 +73,7 @@ nsFirstLetterFrame::Init(nsIContent* aContent,
}
}

return nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
}

NS_IMETHODIMP
Expand Down
6 changes: 3 additions & 3 deletions layout/generic/nsFirstLetterFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class nsFirstLetterFrame : public nsContainerFrame {
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) MOZ_OVERRIDE;

NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList) MOZ_OVERRIDE;
#ifdef DEBUG
Expand Down
4 changes: 1 addition & 3 deletions layout/generic/nsFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ IsFontSizeInflationContainer(nsIFrame* aFrame,
return !isInline;
}

NS_IMETHODIMP
void
nsFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
Expand Down Expand Up @@ -560,8 +560,6 @@ nsFrame::Init(nsIContent* aContent,

if (IsBoxWrapped())
InitBoxMetrics(false);

return NS_OK;
}

NS_IMETHODIMP nsFrame::SetInitialChildList(ChildListID aListID,
Expand Down
6 changes: 3 additions & 3 deletions layout/generic/nsFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ class nsFrame : public nsBox
NS_DECL_FRAMEARENA_HELPERS

// nsIFrame
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* asPrevInFlow);
virtual void Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* asPrevInFlow) MOZ_OVERRIDE;
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList);
NS_IMETHOD AppendFrames(ChildListID aListID,
Expand Down
Loading

0 comments on commit f144b44

Please sign in to comment.