diff --git a/mozilla/content/base/src/nsCopySupport.cpp b/mozilla/content/base/src/nsCopySupport.cpp index 2058933638f..2fc20db668b 100644 --- a/mozilla/content/base/src/nsCopySupport.cpp +++ b/mozilla/content/base/src/nsCopySupport.cpp @@ -352,21 +352,22 @@ nsresult nsCopySupport::IsPlainTextContext(nsISelection *aSel, nsIDocument *aDoc return NS_ERROR_NULL_POINTER; range->GetCommonAncestorContainer(getter_AddRefs(commonParent)); - nsCOMPtr tmp, selContent( do_QueryInterface(commonParent) ); - while (selContent) + for (nsCOMPtr selContent(do_QueryInterface(commonParent)); + selContent; + selContent = selContent->GetParent()) { // checking for selection inside a plaintext form widget nsCOMPtr atom; selContent->GetTag(getter_AddRefs(atom)); - if (atom.get() == nsHTMLAtoms::input || - atom.get() == nsHTMLAtoms::textarea) + if (atom == nsHTMLAtoms::input || + atom == nsHTMLAtoms::textarea) { *aIsPlainTextContext = PR_TRUE; break; } - if (atom.get() == nsHTMLAtoms::body) + if (atom == nsHTMLAtoms::body) { // check for moz prewrap style on body. If it's there we are // in a plaintext editor. This is pretty cheezy but I haven't @@ -380,8 +381,6 @@ nsresult nsCopySupport::IsPlainTextContext(nsISelection *aSel, nsIDocument *aDoc break; } } - selContent->GetParent(getter_AddRefs(tmp)); - selContent = tmp; } // also consider ourselves in a text widget if we can't find an html document diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index d0a85c49301..cbc141ea87c 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -7985,17 +7985,14 @@ ShouldIgnoreSelectChild(nsIContent* aContainer) if (containerTag == nsHTMLAtoms::optgroup || containerTag == nsHTMLAtoms::select) { - nsCOMPtr selectContent = aContainer; - nsCOMPtr tmpContent; + nsIContent* selectContent = aContainer; - while (selectContent) { - if (containerTag == nsHTMLAtoms::select) + while (containerTag != nsHTMLAtoms::select) { + selectContent = selectContent->GetParent(); + if (!selectContent) { break; - - tmpContent = selectContent; - tmpContent->GetParent(getter_AddRefs(selectContent)); - if (selectContent) - selectContent->GetTag(getter_AddRefs(containerTag)); + } + selectContent->GetTag(getter_AddRefs(containerTag)); } nsCOMPtr selectElement = do_QueryInterface(selectContent); @@ -8097,11 +8094,11 @@ nsCSSFrameConstructor::ContentAppended(nsIPresContext* aPresContext, PRBool hasInsertion = PR_FALSE; if (!multiple) { nsCOMPtr bindingManager; - nsCOMPtr document; + nsIDocument* document = nsnull; nsCOMPtr firstAppendedChild; aContainer->ChildAt(aNewIndexInContainer, getter_AddRefs(firstAppendedChild)); if (firstAppendedChild) { - firstAppendedChild->GetDocument(getter_AddRefs(document)); + document = firstAppendedChild->GetDocument(); } if (document) document->GetBindingManager(getter_AddRefs(bindingManager)); @@ -8969,8 +8966,7 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, // Check again to see if the frame we are manipulating is part // of a block-in-inline hierarchy. if (IsFrameSpecial(parentFrame)) { - nsCOMPtr parentContainer; - blockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = blockContent->GetParent(); #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentInserted: parentFrame="); @@ -9944,8 +9940,7 @@ nsCSSFrameConstructor::ContentChanged(nsIPresContext* aPresContext, if (haveFirstLetterStyle) { // The block has first-letter style. Use content-replaced to // repair the blocks frame structure properly. - nsCOMPtr container; - aContent->GetParent(getter_AddRefs(container)); + nsCOMPtr container = aContent->GetParent(); if (container) { PRInt32 ix; container->IndexOf(aContent, ix); @@ -10055,18 +10050,10 @@ nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList& aChangeList, return NS_OK; } -inline already_AddRefed -parent_of(nsIContent *aContent) -{ - nsIContent *parent = nsnull; - aContent->GetParent(&parent); - return parent; -} - static PRBool IsAncestorOf(nsIContent *aAncestor, nsIContent *aDescendant) { - for (nsCOMPtr n = aDescendant; n; n = parent_of(n)) + for (nsIContent* n = aDescendant; n; n = n->GetParent()) if (n == aAncestor) return PR_TRUE; return PR_FALSE; @@ -11272,10 +11259,8 @@ nsCSSFrameConstructor::FindFrameWithContent(nsIPresContext* aPresContext, // child frames, too. // We also need to search if the child content is anonymous and scoped // to the parent content. - nsCOMPtr parentScope; - kidContent->GetBindingParent(getter_AddRefs(parentScope)); if (aParentContent == kidContent || - (aParentContent && (aParentContent == parentScope))) + (aParentContent && (aParentContent == kidContent->GetBindingParent()))) { #ifdef NOISY_FINDFRAME FFWC_recursions++; @@ -11358,14 +11343,13 @@ nsCSSFrameConstructor::FindPrimaryFrameFor(nsIPresContext* aPresContext, // - internal table frames (row-group, row, cell, col-group, col) // // That means we need to need to search for the frame - nsCOMPtr parentContent; // we get this one time nsIFrame* parentFrame; // this pointer is used to iterate across all frames that map to parentContent // Get the frame that corresponds to the parent content object. // Note that this may recurse indirectly, because the pres shell will // call us back if there is no mapping in the hash table - aContent->GetParent(getter_AddRefs(parentContent)); - if (parentContent.get()) { + nsCOMPtr parentContent = aContent->GetParent(); // Get this once + if (parentContent) { aFrameManager->GetPrimaryFrameFor(parentContent, &parentFrame); while (parentFrame) { // Search the child frames for a match @@ -11455,8 +11439,7 @@ nsCSSFrameConstructor::GetInsertionPoint(nsIPresShell* aPresShell, if (!container) return NS_OK; - nsCOMPtr document; - container->GetDocument(getter_AddRefs(document)); + nsIDocument* document = container->GetDocument(); if (!document) return NS_OK; @@ -11469,9 +11452,7 @@ nsCSSFrameConstructor::GetInsertionPoint(nsIPresShell* aPresShell, if (aChildContent) { // We've got an explicit insertion child. Check to see if it's // anonymous. - nsCOMPtr bindingParent; - aChildContent->GetBindingParent(getter_AddRefs(bindingParent)); - if (bindingParent == container) { + if (aChildContent->GetBindingParent() == container) { // This child content is anonymous. Don't use the insertion // point, since that's only for the explicit kids. return NS_OK; @@ -11585,8 +11566,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, // If there is no document, we don't want to recreate frames for it. (You // shouldn't generally be giving this method content without a document // anyway). - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = aContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); // Is the frame `special'? If so, we need to reframe the containing @@ -11630,8 +11610,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, } nsresult rv = NS_OK; - nsCOMPtr container; - aContent->GetParent(getter_AddRefs(container)); + nsCOMPtr container = aContent->GetParent(); if (container) { PRInt32 indexInContainer; rv = container->IndexOf(aContent, indexInContainer); @@ -11667,8 +11646,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, // However, double check that it's really part of the document, // since rebuilding the frame tree can have bad effects, especially // if it's the frame tree for chrome (see bug 157322). - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = aContent->GetDocument(); NS_ASSERTION(doc, "received style change for content not in document"); if (doc) ReconstructDocElementHierarchy(aPresContext); @@ -13336,8 +13314,7 @@ nsCSSFrameConstructor::WipeContainingBlock(nsIPresContext* aPresContext, // Tell parent of the containing block to reformulate the // entire block. This is painful and definitely not optimal // but it will *always* get the right answer. - nsCOMPtr parentContainer; - aBlockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = aBlockContent->GetParent(); #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::WipeContainingBlock: aBlockContent=%p parentContainer=%p\n", @@ -13662,11 +13639,10 @@ nsCSSFrameConstructor::ReframeContainingBlock(nsIPresContext* aPresContext, nsIF // so GetFloaterContainingBlock(aPresContext, aFrame) has been removed // And get the containingBlock's content - nsIContent* blockContent = containingBlock->GetContent(); + nsCOMPtr blockContent = containingBlock->GetContent(); if (blockContent) { // Now find the containingBlock's content's parent - nsCOMPtr parentContainer; - blockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = blockContent->GetParent(); if (parentContainer) { #ifdef DEBUG if (gNoisyContentUpdates) { diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 28a9cb1b79d..d14c99eb1aa 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2797,22 +2797,16 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, // a root, other wise keep going in order to let the theme stuff // draw the background. The canvas really should be drawing the // bg, but there's no way to hook that up via css. - const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay(); - if (displayData->mAppearance) { - nsIContent* content = aForFrame->GetContent(); - if (content) { - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - if (parent) - return; - else - color = aForFrame->GetStyleBackground(); - } - else - return; - } - else + if (!aForFrame->GetStyleDisplay()->mAppearance) { return; + } + + nsIContent* content = aForFrame->GetContent(); + if (!content || content->GetParent()) { + return; + } + + color = aForFrame->GetStyleBackground(); } if (!isCanvas) { PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame, diff --git a/mozilla/layout/base/nsChildIterator.cpp b/mozilla/layout/base/nsChildIterator.cpp index 949d39db7d6..9ce19a67e87 100644 --- a/mozilla/layout/base/nsChildIterator.cpp +++ b/mozilla/layout/base/nsChildIterator.cpp @@ -53,9 +53,8 @@ ChildIterator::Init(nsIContent* aContent, if (! aContent) return NS_ERROR_NULL_POINTER; - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc != nsnull, "element not in the document"); + nsCOMPtr doc = aContent->GetDocument(); + NS_ASSERTION(doc, "element not in the document"); if (! doc) return NS_ERROR_FAILURE; diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index 82cd70fc775..3174f32ac0e 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -617,14 +617,14 @@ FrameManager::GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aResult) // if any methods in here fail, don't report that failure // we're just trying to enhance performance here, not test for correctness nsFindFrameHint hint; - nsCOMPtr prevSibling, parent; - rv = aContent->GetParent(getter_AddRefs(parent)); - if (NS_SUCCEEDED(rv) && parent) + nsIContent* parent = aContent->GetParent(); + if (parent) { PRInt32 index; rv = parent->IndexOf(aContent, index); - if (NS_SUCCEEDED(rv) && index>0) // no use looking if it's the first child + if (NS_SUCCEEDED(rv) && index > 0) // no use looking if it's the first child { + nsCOMPtr prevSibling; nsCOMPtr tag; do { parent->ChildAt(--index, getter_AddRefs(prevSibling)); @@ -809,8 +809,7 @@ FrameManager::GetUndisplayedContent(nsIContent* aContent) if (!aContent || !mUndisplayedMap) return nsnull; - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); if (!parent) return nsnull; @@ -839,8 +838,7 @@ FrameManager::SetUndisplayedContent(nsIContent* aContent, mUndisplayedMap = new UndisplayedMap; } if (mUndisplayedMap) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); NS_ASSERTION(parent, "undisplayed content must have a parent"); if (parent) { mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext); @@ -861,9 +859,7 @@ FrameManager::ChangeUndisplayedContent(nsIContent* aContent, printf("ChangeUndisplayedContent(%d): p=%p \n", i++, (void *)aContent); #endif - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); - for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(parent); + for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(aContent->GetParent()); node; node = node->mNext) { if (node->mContent == aContent) { node->mStyle = aStyleContext; diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index 4b17f010eb4..7602bc53499 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -1393,8 +1393,7 @@ nsPresContext::LoadImage(const nsString& aURL, nsCOMPtr element(do_QueryInterface(content)); if (content && element) { - nsCOMPtr document; - rv = content->GetDocument(getter_AddRefs(document)); + nsCOMPtr document = content->GetDocument(); // If there is no document, skip the policy check // XXXldb This really means the document is being destroyed, so diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 36137f82adc..322a107b48f 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -4343,9 +4343,8 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, // XXX: The dependency on the command dispatcher needs to be fixed. nsIContent* content = aFrame->GetContent(); if (content) { - nsCOMPtr document; - content->GetDocument(getter_AddRefs(document)); - if(document){ + nsIDocument* document = content->GetDocument(); + if (document){ nsCOMPtr focusController; nsCOMPtr ourGlobal; document->GetScriptGlobalObject(getter_AddRefs(ourGlobal)); @@ -5769,9 +5768,7 @@ PresShell::GetCurrentEventFrame() // then we assume it is no longer in the content tree and the // frame shouldn't get an event, nor should we even assume its // safe to try and find the frame. - nsCOMPtr doc; - nsresult result = mCurrentEventContent->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(result) && doc) { + if (mCurrentEventContent->GetDocument()) { GetPrimaryFrameFor(mCurrentEventContent, &mCurrentEventFrame); } } @@ -5836,9 +5833,9 @@ PRBool PresShell::InZombieDocument(nsIContent *aContent) // Such documents cannot handle DOM events. // It might actually be in a node not attached to any document, // in which case there is not parent presshell to retarget it to. - nsCOMPtr doc; - mCurrentEventContent->GetDocument(getter_AddRefs(doc)); - return !doc; + // XXXbz shouldn't this use aContent->GetDocument? Good thing we + // only call it on mCurrentEventContent.... + return !mCurrentEventContent->GetDocument(); } nsresult PresShell::RetargetEventToParent(nsIView *aView, @@ -6088,8 +6085,7 @@ PresShell::HandleEvent(nsIView *aView, // will *not* go away. And this happens on every mousemove. while (targetElement && !targetElement->IsContentOfType(nsIContent::eELEMENT)) { - nsIContent* temp = targetElement; - temp->GetParent(getter_AddRefs(targetElement)); + targetElement = targetElement->GetParent(); } // If we found an element, target it. Otherwise, target *nothing*. diff --git a/mozilla/layout/base/src/nsCopySupport.cpp b/mozilla/layout/base/src/nsCopySupport.cpp index 2058933638f..2fc20db668b 100644 --- a/mozilla/layout/base/src/nsCopySupport.cpp +++ b/mozilla/layout/base/src/nsCopySupport.cpp @@ -352,21 +352,22 @@ nsresult nsCopySupport::IsPlainTextContext(nsISelection *aSel, nsIDocument *aDoc return NS_ERROR_NULL_POINTER; range->GetCommonAncestorContainer(getter_AddRefs(commonParent)); - nsCOMPtr tmp, selContent( do_QueryInterface(commonParent) ); - while (selContent) + for (nsCOMPtr selContent(do_QueryInterface(commonParent)); + selContent; + selContent = selContent->GetParent()) { // checking for selection inside a plaintext form widget nsCOMPtr atom; selContent->GetTag(getter_AddRefs(atom)); - if (atom.get() == nsHTMLAtoms::input || - atom.get() == nsHTMLAtoms::textarea) + if (atom == nsHTMLAtoms::input || + atom == nsHTMLAtoms::textarea) { *aIsPlainTextContext = PR_TRUE; break; } - if (atom.get() == nsHTMLAtoms::body) + if (atom == nsHTMLAtoms::body) { // check for moz prewrap style on body. If it's there we are // in a plaintext editor. This is pretty cheezy but I haven't @@ -380,8 +381,6 @@ nsresult nsCopySupport::IsPlainTextContext(nsISelection *aSel, nsIDocument *aDoc break; } } - selContent->GetParent(getter_AddRefs(tmp)); - selContent = tmp; } // also consider ourselves in a text widget if we can't find an html document diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index 4b17f010eb4..7602bc53499 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -1393,8 +1393,7 @@ nsPresContext::LoadImage(const nsString& aURL, nsCOMPtr element(do_QueryInterface(content)); if (content && element) { - nsCOMPtr document; - rv = content->GetDocument(getter_AddRefs(document)); + nsCOMPtr document = content->GetDocument(); // If there is no document, skip the policy check // XXXldb This really means the document is being destroyed, so diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 1405e1f2c2e..8d5994de43c 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -388,9 +388,8 @@ nsComboboxControlFrame::Init(nsIPresContext* aPresContext, // Start - Temporary fix for Bug 36558 //------------------------------- mGoodToGo = PR_FALSE; - nsCOMPtr document; - nsresult rv = aContent->GetDocument(getter_AddRefs(document)); - if (NS_SUCCEEDED(rv) && document) { + nsIDocument* document = aContent->GetDocument(); + if (document) { #ifdef MOZ_XUL nsCOMPtr xulDoc(do_QueryInterface(document)); mGoodToGo = xulDoc?PR_FALSE:PR_TRUE; @@ -2124,8 +2123,7 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, mDisplayContent = do_QueryInterface(labelContent); mDisplayContent->SetText(NS_LITERAL_STRING("X"), PR_TRUE); - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); // mContent->AppendChildTo(labelContent, PR_FALSE, PR_FALSE); nsCOMPtr nimgr; diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 24d8578486c..e7a3225504a 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -139,8 +139,7 @@ nsFileControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aChildList) { // Get the NodeInfoManager and tag necessary to create input elements - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); nsCOMPtr nimgr; nsresult rv = doc->GetNodeInfoManager(getter_AddRefs(nimgr)); NS_ENSURE_SUCCESS(rv, rv); @@ -269,10 +268,9 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) if (!content) return NS_ERROR_FAILURE; - nsCOMPtr doc; - result = content->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = content->GetDocument(); if (!doc) - return NS_FAILED(result) ? result : NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; nsCOMPtr scriptGlobalObject; result = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 7ef1cb9f3a1..9b6403728a9 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -110,13 +110,12 @@ nsGfxButtonControlFrame::IsFileBrowseButton(PRInt32 type) // Check to see if parent is a file input nsresult result; - nsCOMPtr parentContent; - result = mContent->GetParent(getter_AddRefs(parentContent)); - if (NS_SUCCEEDED(result) && parentContent) { + nsCOMPtr parentContent = mContent->GetParent(); + if (parentContent) { nsCOMPtr atom; result = parentContent->GetTag(getter_AddRefs(atom)); if (NS_SUCCEEDED(result) && atom) { - if (atom.get() == nsHTMLAtoms::input) { + if (atom == nsHTMLAtoms::input) { // It's an input, is it a file input? nsAutoString value; diff --git a/mozilla/layout/forms/nsIsIndexFrame.cpp b/mozilla/layout/forms/nsIsIndexFrame.cpp index 1890468d492..94999e33439 100644 --- a/mozilla/layout/forms/nsIsIndexFrame.cpp +++ b/mozilla/layout/forms/nsIsIndexFrame.cpp @@ -227,8 +227,7 @@ nsIsIndexFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsresult result; // Get the node info manager (used to create hr's and input's) - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); nsCOMPtr nimgr; result = doc->GetNodeInfoManager(getter_AddRefs(nimgr)); NS_ENSURE_SUCCESS(result, result); @@ -417,8 +416,7 @@ nsIsIndexFrame::OnSubmit(nsIPresContext* aPresContext) // Get the document. // We'll need it now to form the URL we're submitting to. // We'll also need it later to get the DOM window when notifying form submit observers (bug 33203) - nsCOMPtr document; - mContent->GetDocument(getter_AddRefs(document)); + nsCOMPtr document = mContent->GetDocument(); if (!document) return NS_OK; // No doc means don't submit, see Bug 28988 // Resolve url to an absolute url @@ -506,8 +504,7 @@ void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset) // see 17.3 The FORM element in HTML 4 for details // Get the charset from document - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (doc) { doc->GetDocumentCharacterSet(oCharset); } diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 6fdb77d2476..7dbd48da623 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -1455,17 +1455,10 @@ nsListControlFrame::IsOptionElement(nsIContent* aContent) nsIContent * nsListControlFrame::GetOptionFromContent(nsIContent *aContent) { - nsCOMPtr content = aContent; - while (content) { + for (nsIContent* content = aContent; content; content = content->GetParent()) { if (IsOptionElement(content)) { - nsIContent *out = content; - NS_ADDREF(out); - return out; + return content; } - - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - parent.swap(content); } return nsnull; @@ -2899,7 +2892,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, nsCOMPtr content; stateManager->GetEventTargetContent(nsnull, getter_AddRefs(content)); - nsCOMPtr optionContent = getter_AddRefs(GetOptionFromContent(content)); + nsCOMPtr optionContent = GetOptionFromContent(content); if (optionContent) { aCurIndex = GetIndexFromContent(optionContent); rv = NS_OK; @@ -3109,8 +3102,7 @@ nsListControlFrame::ScrollToFrame(nsIContent* aOptElement) // and then adds in the parent's y coord // XXX this assume only one level of nesting of optgroups // which is all the spec specifies at the moment. - nsCOMPtr parentContent; - aOptElement->GetParent(getter_AddRefs(parentContent)); + nsCOMPtr parentContent = aOptElement->GetParent(); nsCOMPtr optGroup(do_QueryInterface(parentContent)); nsRect optRect(0,0,0,0); if (optGroup) { diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 99cd95141d1..ae7e00eb7b7 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -262,22 +262,19 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsISelection* mFrame->GetFormContent(*getter_AddRefs(content)); if (content) { - nsCOMPtr doc; - if (NS_SUCCEEDED(content->GetDocument(getter_AddRefs(doc)))) + nsCOMPtr doc = content->GetDocument(); + if (doc) { - if (doc) + nsCOMPtr presShell; + doc->GetShellAt(0, getter_AddRefs(presShell)); + if (presShell) { - nsCOMPtr presShell; - doc->GetShellAt(0, getter_AddRefs(presShell)); - if (presShell) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SELECTED; + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_FORM_SELECTED; - presShell->HandleEventWithTarget(&event,mFrame,content,NS_EVENT_FLAG_INIT,&status); - } + presShell->HandleEventWithTarget(&event,mFrame,content,NS_EVENT_FLAG_INIT,&status); } } } @@ -384,12 +381,11 @@ nsTextInputListener::UpdateTextInputCommands(const nsAString& commandsToUpdate) nsIContent* content = mFrame->GetContent(); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - nsCOMPtr doc; - nsresult rv = content->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = content->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); nsCOMPtr scriptGlobalObject; - rv = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); + nsresult rv = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE); nsCOMPtr domWindow = do_QueryInterface(scriptGlobalObject); diff --git a/mozilla/layout/generic/nsBRFrame.cpp b/mozilla/layout/generic/nsBRFrame.cpp index 6fc58821c77..607753464a3 100644 --- a/mozilla/layout/generic/nsBRFrame.cpp +++ b/mozilla/layout/generic/nsBRFrame.cpp @@ -228,8 +228,10 @@ NS_IMETHODIMP BRFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, { if (!mContent) return NS_ERROR_NULL_POINTER; - nsresult result = mContent->GetParent(aContent); - if (NS_SUCCEEDED(result) && *aContent) + NS_IF_ADDREF(*aContent = mContent->GetParent()); + + nsresult result = NS_OK; + if (*aContent) result = (*aContent)->IndexOf(mContent, aOffsetBegin); aOffsetEnd = aOffsetBegin; aBeginFrameContent = PR_TRUE; @@ -241,14 +243,11 @@ NS_IMETHODIMP BRFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStru if (!aPos) return NS_ERROR_NULL_POINTER; - nsCOMPtr parentContent; PRInt32 offsetBegin; //offset of this content in its parents child list. base 0 - nsresult result = mContent->GetParent(getter_AddRefs(parentContent)); - - - if (NS_SUCCEEDED(result) && parentContent) - result = parentContent->IndexOf(mContent, offsetBegin); + nsCOMPtr parentContent = mContent->GetParent(); + if (parentContent) + parentContent->IndexOf(mContent, offsetBegin); if (aPos->mAmount != eSelectLine && aPos->mAmount != eSelectBeginLine && aPos->mAmount != eSelectEndLine) //then we must do the adjustment to make sure we leave this frame diff --git a/mozilla/layout/generic/nsBulletFrame.cpp b/mozilla/layout/generic/nsBulletFrame.cpp index f5d9ceb071c..3ebfeba9671 100644 --- a/mozilla/layout/generic/nsBulletFrame.cpp +++ b/mozilla/layout/generic/nsBulletFrame.cpp @@ -144,7 +144,7 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsCOMPtr documentURI; nsCOMPtr doc; if (mContent) { - (void) mContent->GetDocument(getter_AddRefs(doc)); + doc = mContent->GetDocument(); if (doc) { doc->GetDocumentURL(getter_AddRefs(documentURI)); } @@ -1648,7 +1648,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, nsCOMPtr documentURI; nsCOMPtr doc; if (mContent) { - (void) mContent->GetDocument(getter_AddRefs(doc)); + doc = mContent->GetDocument(); if (doc) { doc->GetDocumentURL(getter_AddRefs(documentURI)); } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 08d0a1816ae..19bafd8ab55 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -857,12 +857,12 @@ nsFrame::Paint(nsIPresContext* aPresContext, return NS_OK; //if frame does not allow selection. do nothing - nsCOMPtr newContent; - result = mContent->GetParent(getter_AddRefs(newContent)); + nsCOMPtr newContent = mContent->GetParent(); -//check to see if we are anonymouse content + //check to see if we are anonymous content PRInt32 offset; - if (NS_SUCCEEDED(result) && newContent){ + if (newContent) { + // XXXbz there has GOT to be a better way of determining this! result = newContent->IndexOf(mContent, offset); if (NS_FAILED(result)) return result; @@ -1098,9 +1098,7 @@ nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, nsIContent* tableOrCellContent = frame->GetContent(); if (!tableOrCellContent) return NS_ERROR_FAILURE; - nsCOMPtr parentContent; - result = tableOrCellContent->GetParent(getter_AddRefs(parentContent)); - if (NS_FAILED(result)) return result; + nsCOMPtr parentContent = tableOrCellContent->GetParent(); if (!parentContent) return NS_ERROR_FAILURE; PRInt32 offset; @@ -1331,11 +1329,10 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; if (!isEditor && !keyEvent->isAlt) { - nsCOMPtr content; - GetContent (getter_AddRefs(content)); static NS_NAMED_LITERAL_STRING(simple, "simple"); - while (content) { + for (nsIContent* content = mContent; content; + content = content->GetParent()) { // are we a link with an href? If so, bail out now! nsAutoString href; // a? @@ -1379,12 +1376,6 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, frameRect.y <= aEvent->point.y && (frameRect.y + frameRect.height >= aEvent->point.y)) return NS_OK; } - - // now try the parent - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content.swap(parent); - } // if browser, not editor } @@ -2007,11 +1998,9 @@ nsresult nsFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, nsIContent* kidContent = GetContent(); if (kidContent) { - nsCOMPtr content; + nsCOMPtr content = kidContent->GetParent(); - result = kidContent->GetParent(getter_AddRefs(content)); - - if (NS_SUCCEEDED(result) && content) { + if (content) { PRInt32 kidCount = 0; result = content->ChildCount(kidCount); @@ -2120,7 +2109,7 @@ nsresult nsFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, thisRect.x = offsetPoint.x; thisRect.y = offsetPoint.y; - result = mContent->GetParent(aNewContent); + NS_IF_ADDREF(*aNewContent = mContent->GetParent()); if (*aNewContent){ PRInt32 contentOffset(aContentOffset); //temp to hold old value in case of failure @@ -2660,9 +2649,7 @@ PRInt32 nsFrame::ContentIndexInContainer(const nsIFrame* aFrame) nsIContent* content = aFrame->GetContent(); if (content) { - nsCOMPtr parentContent; - - content->GetParent(getter_AddRefs(parentContent)); + nsIContent* parentContent = content->GetParent(); if (parentContent) { parentContent->IndexOf(content, result); } @@ -3109,11 +3096,10 @@ nsFrame::GetPointFromOffset(nsIPresContext* inPresContext, nsIRenderingContext* nsPoint bottomLeft(0, 0); if (mContent) { - nsCOMPtr newContent; - PRInt32 newOffset; - nsresult result = mContent->GetParent(getter_AddRefs(newContent)); + nsIContent* newContent = mContent->GetParent(); if (newContent){ - result = newContent->IndexOf(mContent, newOffset); + PRInt32 newOffset; + nsresult result = newContent->IndexOf(mContent, newOffset); if (NS_FAILED(result)) { return result; @@ -3305,8 +3291,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsIPresContext* aPresContext, nsIContent* content = resultFrame->GetContent(); if (content) { - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); + nsIContent* parent = content->GetParent(); if (parent) { aPos->mResultContent = parent; @@ -3665,10 +3650,9 @@ nsFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) { if (mContent) { - nsCOMPtr newContent; - PRInt32 newOffset; - result = mContent->GetParent(getter_AddRefs(newContent)); + nsIContent* newContent = mContent->GetParent(); if (newContent){ + PRInt32 newOffset; aPos->mResultContent = newContent; result = newContent->IndexOf(mContent, newOffset); if (aPos->mStartOffset < 0)//start at "end" diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index a763da8b210..84b54c47f07 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -623,11 +623,8 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, } // If the noResize attribute changes, dis/allow frame to be resized else if (aAttribute == nsHTMLAtoms::noresize) { - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); - nsCOMPtr parentTag; - parentContent->GetTag(getter_AddRefs(parentTag)); + mContent->GetParent()->GetTag(getter_AddRefs(parentTag)); if (parentTag == nsHTMLAtoms::frameset) { nsIFrame* parentFrame = GetParent(); diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 487ba192cd0..83e4ef60a1c 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -283,8 +283,7 @@ nsHTMLFramesetFrame::Observe(nsISupports* aObject, const char* aAction, { nsAutoString prefName(aPrefName); if (prefName.Equals(NS_LITERAL_STRING(kFrameResizePref))) { - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); if (doc) { doc->BeginUpdate(); doc->AttributeWillChange(mContent, @@ -707,15 +706,11 @@ nsHTMLFramesetFrame* nsHTMLFramesetFrame::GetFramesetParent(nsIFrame* aChild) nsIContent* content = aChild->GetContent(); if (content) { - nsCOMPtr contentParent; - content->GetParent(getter_AddRefs(contentParent)); + nsCOMPtr contentParent = content->GetParent(); - nsCOMPtr contentParent2 = - do_QueryInterface(contentParent); - - if (contentParent2) { + if (contentParent && contentParent->IsContentOfType(nsIContent::eHTML)) { nsCOMPtr tag; - contentParent2->GetTag(getter_AddRefs(tag)); + contentParent->GetTag(getter_AddRefs(tag)); if (tag == nsHTMLAtoms::frameset) { nsIFrame* fptr = aChild->GetParent(); diff --git a/mozilla/layout/generic/nsHTMLReflowState.cpp b/mozilla/layout/generic/nsHTMLReflowState.cpp index 2bbc42614c4..d372ad48d14 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.cpp +++ b/mozilla/layout/generic/nsHTMLReflowState.cpp @@ -1325,15 +1325,10 @@ IsInitialContainingBlock(nsIFrame* aFrame) { nsIContent* content = aFrame->GetContent(); - if (content) { - nsCOMPtr parentContent; - - content->GetParent(getter_AddRefs(parentContent)); - if (!parentContent) { - // The containing block corresponds to the document element so it's - // the initial containing block - return PR_TRUE; - } + if (content && !content->GetParent()) { + // The containing block corresponds to the document element so it's + // the initial containing block + return PR_TRUE; } return PR_FALSE; } @@ -2780,13 +2775,10 @@ nsHTMLReflowState::IsBidiFormControl(nsIPresContext* aPresContext) // find out if the reflow root is a descendant of a form control. // Otherwise, just test this content node if (mReflowDepth == 0) { - while (content) { + for ( ; content; content = content->GetParent()) { if (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) { return PR_TRUE; } - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content = parent; } } else { return (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)); diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 7cb85c87c1c..20b17987207 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -1428,8 +1428,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, selection->GetRangeCount(&rangeCount); if (rangeCount == 1) //if not one then let code drop to nsFrame::Paint { - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); + nsCOMPtr parentContent = mContent->GetParent(); if (parentContent) { PRInt32 thisOffset; @@ -1473,8 +1472,7 @@ nsImageMap* nsImageFrame::GetImageMap(nsIPresContext* aPresContext) { if (!mImageMap) { - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (!doc) { return nsnull; } @@ -1598,9 +1596,8 @@ nsImageFrame::GetAnchorHREFAndTarget(nsString& aHref, nsString& aTarget) aTarget.Truncate(); // Walk up the content tree, looking for an nsIDOMAnchorElement - nsCOMPtr content; - mContent->GetParent(getter_AddRefs(content)); - while (content) { + for (nsIContent* content = mContent->GetParent(); + content; content = content->GetParent()) { nsCOMPtr anchor(do_QueryInterface(content)); if (anchor) { anchor->GetHref(aHref); @@ -1610,9 +1607,6 @@ nsImageFrame::GetAnchorHREFAndTarget(nsString& aHref, nsString& aTarget) anchor->GetTarget(aTarget); break; } - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content = parent; } return status; } @@ -1891,13 +1885,10 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, void nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const { - nsresult rv; - nsCOMPtr htmlContent(do_QueryInterface(mContent, &rv)); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr doc; - rv = htmlContent->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(rv)) - (void) doc->GetDocumentCharacterSet(aCharset); + if (mContent) { + NS_ASSERTION(mContent->GetDocument(), + "Frame still alive after content removed from document!"); + mContent->GetDocument()->GetDocumentCharacterSet(aCharset); } } diff --git a/mozilla/layout/generic/nsImageMap.cpp b/mozilla/layout/generic/nsImageMap.cpp index 97d47e4aacb..7a2b8cc62a3 100644 --- a/mozilla/layout/generic/nsImageMap.cpp +++ b/mozilla/layout/generic/nsImageMap.cpp @@ -448,6 +448,7 @@ void RectArea::ParseCoords(const nsAString& aSpec) if (NS_FAILED(rv)) return; + // XXX GetOwnerDocument nsCOMPtr nodeInfo; mArea->GetNodeInfo(getter_AddRefs(nodeInfo)); NS_ASSERTION(nodeInfo, "Element with no nodeinfo"); @@ -736,10 +737,12 @@ void CircleArea::GetRect(nsIPresContext* aCX, nsRect& aRect) //---------------------------------------------------------------------- -nsImageMap::nsImageMap() +nsImageMap::nsImageMap() : + mPresShell(nsnull), + mImageFrame(nsnull), + mDocument(nsnull), + mContainsBlockContents(PR_FALSE) { - mDocument = nsnull; - mContainsBlockContents = PR_FALSE; } nsImageMap::~nsImageMap() @@ -759,8 +762,8 @@ nsImageMap::~nsImageMap() } FreeAreas(); - if (nsnull != mDocument) { - mDocument->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); + if (mDocument) { + mDocument->RemoveObserver(this); } } @@ -815,12 +818,9 @@ nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapE nsresult rv; mMap = do_QueryInterface(aMap, &rv); NS_ASSERTION(mMap, "aMap is not an nsIHTMLContent!"); - rv = mMap->GetDocument(&mDocument); - if (NS_SUCCEEDED(rv) && mDocument) { - mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); - // mDocument is a weak reference, so release the reference we got - nsIDocument *temp = mDocument; - NS_RELEASE(temp); + mDocument = mMap->GetDocument(); + if (mDocument) { + mDocument->AddObserver(this); } // "Compile" the areas in the map into faster access versions @@ -1026,8 +1026,7 @@ PRBool nsImageMap::IsAncestorOf(nsIContent* aContent, nsIContent* aAncestorContent) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContent->GetParent(); if (parent) { return parent == aAncestorContent || IsAncestorOf(parent, aAncestorContent); @@ -1043,9 +1042,8 @@ nsImageMap::ContentChanged(nsIDocument *aDocument, { // If the parent of the changing content node is our map then update // the map. - nsCOMPtr parent; - nsresult rv = aContent->GetParent(getter_AddRefs(parent)); - if (NS_SUCCEEDED(rv) && (nsnull != parent)) { + nsIContent* parent = aContent->GetParent(); + if (parent) { if ((parent == mMap) || (mContainsBlockContents && IsAncestorOf(parent, mMap))) { UpdateAreas(); @@ -1063,8 +1061,7 @@ nsImageMap::AttributeChanged(nsIDocument *aDocument, { // If the parent of the changing content node is our map then update // the map. - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); if ((parent == mMap) || (mContainsBlockContents && IsAncestorOf(parent, mMap))) { UpdateAreas(); @@ -1153,9 +1150,9 @@ nsImageMap::ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus) { //Set or Remove internal focus area->HasFocus(aFocus); //Now invalidate the rect - nsCOMPtr doc; + nsCOMPtr doc = targetContent->GetDocument(); //This check is necessary to see if we're still attached to the doc - if (NS_SUCCEEDED(targetContent->GetDocument(getter_AddRefs(doc))) && doc) { + if (doc) { nsCOMPtr presShell; doc->GetShellAt(0, getter_AddRefs(presShell)); if (presShell) { diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 28b5128e534..7d48c2a1050 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -1591,8 +1591,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // for THIS content node in order to call ->Print() on the right plugin // first, we need to get the document - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER); // now we need to get the shell for the screen @@ -1964,9 +1963,7 @@ nsresult nsObjectFrame::GetPluginInstance(nsIPluginInstance*& aPluginInstance) nsresult nsObjectFrame::NotifyContentObjectWrapper() { - nsCOMPtr doc; - - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); nsCOMPtr sgo; diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 4feece69644..c6a900586bd 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -658,7 +658,7 @@ public: {} }; - nsIDocument* GetDocument(nsIPresContext* aPresContext); + already_AddRefed GetDocument(nsIPresContext* aPresContext); PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, nsAutoIndexBuffer* aIndexBuffer, @@ -1024,10 +1024,8 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, mSelectionPseudoBGIsTransparent = PR_FALSE; if (aContent) { - nsCOMPtr parentContent; - aContent->GetParent(getter_AddRefs(parentContent)); nsRefPtr sc; - sc = aPresContext->ProbePseudoStyleContextFor(parentContent, + sc = aPresContext->ProbePseudoStyleContextFor(aContent->GetParent(), nsCSSPseudoElements::mozSelection, aStyleContext); if (sc) { @@ -1347,20 +1345,15 @@ nsTextFrame::~nsTextFrame() } } -nsIDocument* +already_AddRefed nsTextFrame::GetDocument(nsIPresContext* aPresContext) { nsIDocument* result = nsnull; if (mContent) { - mContent->GetDocument(&result); + NS_IF_ADDREF(result = mContent->GetDocument()); } if (!result && aPresContext) { - nsIPresShell* shell; - aPresContext->GetShell(&shell); - if (shell) { - shell->GetDocument(&result); - NS_RELEASE(shell); - } + aPresContext->GetPresShell()->GetDocument(&result); } return result; } @@ -2519,7 +2512,7 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, *aNewContent = mContent; aOffset =0; } - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr doc(GetDocument(aPresContext)); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -3429,7 +3422,7 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, SetFontFromStyle(acx, mStyleContext); // Get the renderable form of the text - nsCOMPtr doc(getter_AddRefs(GetDocument(aCX))); + nsCOMPtr doc(GetDocument(aCX)); nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull, aCX); @@ -3767,7 +3760,7 @@ nsTextFrame::GetPointFromOffset(nsIPresContext* aPresContext, } // Transform text from content into renderable form - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr doc(GetDocument(aPresContext)); nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull, aPresContext); @@ -3975,14 +3968,12 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectNoAmount: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { - return result; + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { + return NS_OK; } nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, nsnull, aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -4007,14 +3998,12 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectCharacter: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { - return result; + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { + return NS_OK; } nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, nsnull, aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -4153,9 +4142,8 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectWord: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { return result; } @@ -4163,7 +4151,6 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) doc->GetLineBreaker(getter_AddRefs(lb)); nsCOMPtr wb; doc->GetWordBreaker(getter_AddRefs(wb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, wb, aPresContext); @@ -5345,8 +5332,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, nscoord maxWidth = aReflowState.availableWidth; // Setup text transformer to transform this frames text content - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (!doc) { NS_WARNING("Content has no document."); return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/base/src/nsBRFrame.cpp b/mozilla/layout/html/base/src/nsBRFrame.cpp index 6fc58821c77..607753464a3 100644 --- a/mozilla/layout/html/base/src/nsBRFrame.cpp +++ b/mozilla/layout/html/base/src/nsBRFrame.cpp @@ -228,8 +228,10 @@ NS_IMETHODIMP BRFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, { if (!mContent) return NS_ERROR_NULL_POINTER; - nsresult result = mContent->GetParent(aContent); - if (NS_SUCCEEDED(result) && *aContent) + NS_IF_ADDREF(*aContent = mContent->GetParent()); + + nsresult result = NS_OK; + if (*aContent) result = (*aContent)->IndexOf(mContent, aOffsetBegin); aOffsetEnd = aOffsetBegin; aBeginFrameContent = PR_TRUE; @@ -241,14 +243,11 @@ NS_IMETHODIMP BRFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStru if (!aPos) return NS_ERROR_NULL_POINTER; - nsCOMPtr parentContent; PRInt32 offsetBegin; //offset of this content in its parents child list. base 0 - nsresult result = mContent->GetParent(getter_AddRefs(parentContent)); - - - if (NS_SUCCEEDED(result) && parentContent) - result = parentContent->IndexOf(mContent, offsetBegin); + nsCOMPtr parentContent = mContent->GetParent(); + if (parentContent) + parentContent->IndexOf(mContent, offsetBegin); if (aPos->mAmount != eSelectLine && aPos->mAmount != eSelectBeginLine && aPos->mAmount != eSelectEndLine) //then we must do the adjustment to make sure we leave this frame diff --git a/mozilla/layout/html/base/src/nsBulletFrame.cpp b/mozilla/layout/html/base/src/nsBulletFrame.cpp index f5d9ceb071c..3ebfeba9671 100644 --- a/mozilla/layout/html/base/src/nsBulletFrame.cpp +++ b/mozilla/layout/html/base/src/nsBulletFrame.cpp @@ -144,7 +144,7 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsCOMPtr documentURI; nsCOMPtr doc; if (mContent) { - (void) mContent->GetDocument(getter_AddRefs(doc)); + doc = mContent->GetDocument(); if (doc) { doc->GetDocumentURL(getter_AddRefs(documentURI)); } @@ -1648,7 +1648,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, nsCOMPtr documentURI; nsCOMPtr doc; if (mContent) { - (void) mContent->GetDocument(getter_AddRefs(doc)); + doc = mContent->GetDocument(); if (doc) { doc->GetDocumentURL(getter_AddRefs(documentURI)); } diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 08d0a1816ae..19bafd8ab55 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -857,12 +857,12 @@ nsFrame::Paint(nsIPresContext* aPresContext, return NS_OK; //if frame does not allow selection. do nothing - nsCOMPtr newContent; - result = mContent->GetParent(getter_AddRefs(newContent)); + nsCOMPtr newContent = mContent->GetParent(); -//check to see if we are anonymouse content + //check to see if we are anonymous content PRInt32 offset; - if (NS_SUCCEEDED(result) && newContent){ + if (newContent) { + // XXXbz there has GOT to be a better way of determining this! result = newContent->IndexOf(mContent, offset); if (NS_FAILED(result)) return result; @@ -1098,9 +1098,7 @@ nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, nsIContent* tableOrCellContent = frame->GetContent(); if (!tableOrCellContent) return NS_ERROR_FAILURE; - nsCOMPtr parentContent; - result = tableOrCellContent->GetParent(getter_AddRefs(parentContent)); - if (NS_FAILED(result)) return result; + nsCOMPtr parentContent = tableOrCellContent->GetParent(); if (!parentContent) return NS_ERROR_FAILURE; PRInt32 offset; @@ -1331,11 +1329,10 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; if (!isEditor && !keyEvent->isAlt) { - nsCOMPtr content; - GetContent (getter_AddRefs(content)); static NS_NAMED_LITERAL_STRING(simple, "simple"); - while (content) { + for (nsIContent* content = mContent; content; + content = content->GetParent()) { // are we a link with an href? If so, bail out now! nsAutoString href; // a? @@ -1379,12 +1376,6 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, frameRect.y <= aEvent->point.y && (frameRect.y + frameRect.height >= aEvent->point.y)) return NS_OK; } - - // now try the parent - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content.swap(parent); - } // if browser, not editor } @@ -2007,11 +1998,9 @@ nsresult nsFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, nsIContent* kidContent = GetContent(); if (kidContent) { - nsCOMPtr content; + nsCOMPtr content = kidContent->GetParent(); - result = kidContent->GetParent(getter_AddRefs(content)); - - if (NS_SUCCEEDED(result) && content) { + if (content) { PRInt32 kidCount = 0; result = content->ChildCount(kidCount); @@ -2120,7 +2109,7 @@ nsresult nsFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aCX, thisRect.x = offsetPoint.x; thisRect.y = offsetPoint.y; - result = mContent->GetParent(aNewContent); + NS_IF_ADDREF(*aNewContent = mContent->GetParent()); if (*aNewContent){ PRInt32 contentOffset(aContentOffset); //temp to hold old value in case of failure @@ -2660,9 +2649,7 @@ PRInt32 nsFrame::ContentIndexInContainer(const nsIFrame* aFrame) nsIContent* content = aFrame->GetContent(); if (content) { - nsCOMPtr parentContent; - - content->GetParent(getter_AddRefs(parentContent)); + nsIContent* parentContent = content->GetParent(); if (parentContent) { parentContent->IndexOf(content, result); } @@ -3109,11 +3096,10 @@ nsFrame::GetPointFromOffset(nsIPresContext* inPresContext, nsIRenderingContext* nsPoint bottomLeft(0, 0); if (mContent) { - nsCOMPtr newContent; - PRInt32 newOffset; - nsresult result = mContent->GetParent(getter_AddRefs(newContent)); + nsIContent* newContent = mContent->GetParent(); if (newContent){ - result = newContent->IndexOf(mContent, newOffset); + PRInt32 newOffset; + nsresult result = newContent->IndexOf(mContent, newOffset); if (NS_FAILED(result)) { return result; @@ -3305,8 +3291,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsIPresContext* aPresContext, nsIContent* content = resultFrame->GetContent(); if (content) { - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); + nsIContent* parent = content->GetParent(); if (parent) { aPos->mResultContent = parent; @@ -3665,10 +3650,9 @@ nsFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) { if (mContent) { - nsCOMPtr newContent; - PRInt32 newOffset; - result = mContent->GetParent(getter_AddRefs(newContent)); + nsIContent* newContent = mContent->GetParent(); if (newContent){ + PRInt32 newOffset; aPos->mResultContent = newContent; result = newContent->IndexOf(mContent, newOffset); if (aPos->mStartOffset < 0)//start at "end" diff --git a/mozilla/layout/html/base/src/nsFrameManager.cpp b/mozilla/layout/html/base/src/nsFrameManager.cpp index 82cd70fc775..3174f32ac0e 100644 --- a/mozilla/layout/html/base/src/nsFrameManager.cpp +++ b/mozilla/layout/html/base/src/nsFrameManager.cpp @@ -617,14 +617,14 @@ FrameManager::GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aResult) // if any methods in here fail, don't report that failure // we're just trying to enhance performance here, not test for correctness nsFindFrameHint hint; - nsCOMPtr prevSibling, parent; - rv = aContent->GetParent(getter_AddRefs(parent)); - if (NS_SUCCEEDED(rv) && parent) + nsIContent* parent = aContent->GetParent(); + if (parent) { PRInt32 index; rv = parent->IndexOf(aContent, index); - if (NS_SUCCEEDED(rv) && index>0) // no use looking if it's the first child + if (NS_SUCCEEDED(rv) && index > 0) // no use looking if it's the first child { + nsCOMPtr prevSibling; nsCOMPtr tag; do { parent->ChildAt(--index, getter_AddRefs(prevSibling)); @@ -809,8 +809,7 @@ FrameManager::GetUndisplayedContent(nsIContent* aContent) if (!aContent || !mUndisplayedMap) return nsnull; - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); if (!parent) return nsnull; @@ -839,8 +838,7 @@ FrameManager::SetUndisplayedContent(nsIContent* aContent, mUndisplayedMap = new UndisplayedMap; } if (mUndisplayedMap) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); NS_ASSERTION(parent, "undisplayed content must have a parent"); if (parent) { mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext); @@ -861,9 +859,7 @@ FrameManager::ChangeUndisplayedContent(nsIContent* aContent, printf("ChangeUndisplayedContent(%d): p=%p \n", i++, (void *)aContent); #endif - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); - for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(parent); + for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(aContent->GetParent()); node; node = node->mNext) { if (node->mContent == aContent) { node->mStyle = aStyleContext; diff --git a/mozilla/layout/html/base/src/nsHRFrame.cpp b/mozilla/layout/html/base/src/nsHRFrame.cpp index 937c4663c72..bd67a9c107c 100644 --- a/mozilla/layout/html/base/src/nsHRFrame.cpp +++ b/mozilla/layout/html/base/src/nsHRFrame.cpp @@ -380,8 +380,8 @@ HRuleFrame::GetContentAndOffsetsFromPoint(nsIPresContext* aPresContext, thisRect.x = offsetPoint.x; thisRect.y = offsetPoint.y; - rv = mContent->GetParent(aNewContent); - if (!*aNewContent) return rv; + NS_IF_ADDREF(*aNewContent = mContent->GetParent()); + if (!*aNewContent) return NS_OK; rv = (*aNewContent)->IndexOf(mContent, aContentOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp index 2bbc42614c4..d372ad48d14 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp @@ -1325,15 +1325,10 @@ IsInitialContainingBlock(nsIFrame* aFrame) { nsIContent* content = aFrame->GetContent(); - if (content) { - nsCOMPtr parentContent; - - content->GetParent(getter_AddRefs(parentContent)); - if (!parentContent) { - // The containing block corresponds to the document element so it's - // the initial containing block - return PR_TRUE; - } + if (content && !content->GetParent()) { + // The containing block corresponds to the document element so it's + // the initial containing block + return PR_TRUE; } return PR_FALSE; } @@ -2780,13 +2775,10 @@ nsHTMLReflowState::IsBidiFormControl(nsIPresContext* aPresContext) // find out if the reflow root is a descendant of a form control. // Otherwise, just test this content node if (mReflowDepth == 0) { - while (content) { + for ( ; content; content = content->GetParent()) { if (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) { return PR_TRUE; } - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content = parent; } } else { return (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)); diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 7cb85c87c1c..20b17987207 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -1428,8 +1428,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, selection->GetRangeCount(&rangeCount); if (rangeCount == 1) //if not one then let code drop to nsFrame::Paint { - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); + nsCOMPtr parentContent = mContent->GetParent(); if (parentContent) { PRInt32 thisOffset; @@ -1473,8 +1472,7 @@ nsImageMap* nsImageFrame::GetImageMap(nsIPresContext* aPresContext) { if (!mImageMap) { - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (!doc) { return nsnull; } @@ -1598,9 +1596,8 @@ nsImageFrame::GetAnchorHREFAndTarget(nsString& aHref, nsString& aTarget) aTarget.Truncate(); // Walk up the content tree, looking for an nsIDOMAnchorElement - nsCOMPtr content; - mContent->GetParent(getter_AddRefs(content)); - while (content) { + for (nsIContent* content = mContent->GetParent(); + content; content = content->GetParent()) { nsCOMPtr anchor(do_QueryInterface(content)); if (anchor) { anchor->GetHref(aHref); @@ -1610,9 +1607,6 @@ nsImageFrame::GetAnchorHREFAndTarget(nsString& aHref, nsString& aTarget) anchor->GetTarget(aTarget); break; } - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - content = parent; } return status; } @@ -1891,13 +1885,10 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, void nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const { - nsresult rv; - nsCOMPtr htmlContent(do_QueryInterface(mContent, &rv)); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr doc; - rv = htmlContent->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(rv)) - (void) doc->GetDocumentCharacterSet(aCharset); + if (mContent) { + NS_ASSERTION(mContent->GetDocument(), + "Frame still alive after content removed from document!"); + mContent->GetDocument()->GetDocumentCharacterSet(aCharset); } } diff --git a/mozilla/layout/html/base/src/nsImageMap.cpp b/mozilla/layout/html/base/src/nsImageMap.cpp index 97d47e4aacb..7a2b8cc62a3 100644 --- a/mozilla/layout/html/base/src/nsImageMap.cpp +++ b/mozilla/layout/html/base/src/nsImageMap.cpp @@ -448,6 +448,7 @@ void RectArea::ParseCoords(const nsAString& aSpec) if (NS_FAILED(rv)) return; + // XXX GetOwnerDocument nsCOMPtr nodeInfo; mArea->GetNodeInfo(getter_AddRefs(nodeInfo)); NS_ASSERTION(nodeInfo, "Element with no nodeinfo"); @@ -736,10 +737,12 @@ void CircleArea::GetRect(nsIPresContext* aCX, nsRect& aRect) //---------------------------------------------------------------------- -nsImageMap::nsImageMap() +nsImageMap::nsImageMap() : + mPresShell(nsnull), + mImageFrame(nsnull), + mDocument(nsnull), + mContainsBlockContents(PR_FALSE) { - mDocument = nsnull; - mContainsBlockContents = PR_FALSE; } nsImageMap::~nsImageMap() @@ -759,8 +762,8 @@ nsImageMap::~nsImageMap() } FreeAreas(); - if (nsnull != mDocument) { - mDocument->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); + if (mDocument) { + mDocument->RemoveObserver(this); } } @@ -815,12 +818,9 @@ nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapE nsresult rv; mMap = do_QueryInterface(aMap, &rv); NS_ASSERTION(mMap, "aMap is not an nsIHTMLContent!"); - rv = mMap->GetDocument(&mDocument); - if (NS_SUCCEEDED(rv) && mDocument) { - mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); - // mDocument is a weak reference, so release the reference we got - nsIDocument *temp = mDocument; - NS_RELEASE(temp); + mDocument = mMap->GetDocument(); + if (mDocument) { + mDocument->AddObserver(this); } // "Compile" the areas in the map into faster access versions @@ -1026,8 +1026,7 @@ PRBool nsImageMap::IsAncestorOf(nsIContent* aContent, nsIContent* aAncestorContent) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContent->GetParent(); if (parent) { return parent == aAncestorContent || IsAncestorOf(parent, aAncestorContent); @@ -1043,9 +1042,8 @@ nsImageMap::ContentChanged(nsIDocument *aDocument, { // If the parent of the changing content node is our map then update // the map. - nsCOMPtr parent; - nsresult rv = aContent->GetParent(getter_AddRefs(parent)); - if (NS_SUCCEEDED(rv) && (nsnull != parent)) { + nsIContent* parent = aContent->GetParent(); + if (parent) { if ((parent == mMap) || (mContainsBlockContents && IsAncestorOf(parent, mMap))) { UpdateAreas(); @@ -1063,8 +1061,7 @@ nsImageMap::AttributeChanged(nsIDocument *aDocument, { // If the parent of the changing content node is our map then update // the map. - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); if ((parent == mMap) || (mContainsBlockContents && IsAncestorOf(parent, mMap))) { UpdateAreas(); @@ -1153,9 +1150,9 @@ nsImageMap::ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus) { //Set or Remove internal focus area->HasFocus(aFocus); //Now invalidate the rect - nsCOMPtr doc; + nsCOMPtr doc = targetContent->GetDocument(); //This check is necessary to see if we're still attached to the doc - if (NS_SUCCEEDED(targetContent->GetDocument(getter_AddRefs(doc))) && doc) { + if (doc) { nsCOMPtr presShell; doc->GetShellAt(0, getter_AddRefs(presShell)); if (presShell) { diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 28b5128e534..7d48c2a1050 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -1591,8 +1591,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // for THIS content node in order to call ->Print() on the right plugin // first, we need to get the document - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER); // now we need to get the shell for the screen @@ -1964,9 +1963,7 @@ nsresult nsObjectFrame::GetPluginInstance(nsIPluginInstance*& aPluginInstance) nsresult nsObjectFrame::NotifyContentObjectWrapper() { - nsCOMPtr doc; - - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); nsCOMPtr sgo; diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 36137f82adc..322a107b48f 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -4343,9 +4343,8 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, // XXX: The dependency on the command dispatcher needs to be fixed. nsIContent* content = aFrame->GetContent(); if (content) { - nsCOMPtr document; - content->GetDocument(getter_AddRefs(document)); - if(document){ + nsIDocument* document = content->GetDocument(); + if (document){ nsCOMPtr focusController; nsCOMPtr ourGlobal; document->GetScriptGlobalObject(getter_AddRefs(ourGlobal)); @@ -5769,9 +5768,7 @@ PresShell::GetCurrentEventFrame() // then we assume it is no longer in the content tree and the // frame shouldn't get an event, nor should we even assume its // safe to try and find the frame. - nsCOMPtr doc; - nsresult result = mCurrentEventContent->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(result) && doc) { + if (mCurrentEventContent->GetDocument()) { GetPrimaryFrameFor(mCurrentEventContent, &mCurrentEventFrame); } } @@ -5836,9 +5833,9 @@ PRBool PresShell::InZombieDocument(nsIContent *aContent) // Such documents cannot handle DOM events. // It might actually be in a node not attached to any document, // in which case there is not parent presshell to retarget it to. - nsCOMPtr doc; - mCurrentEventContent->GetDocument(getter_AddRefs(doc)); - return !doc; + // XXXbz shouldn't this use aContent->GetDocument? Good thing we + // only call it on mCurrentEventContent.... + return !mCurrentEventContent->GetDocument(); } nsresult PresShell::RetargetEventToParent(nsIView *aView, @@ -6088,8 +6085,7 @@ PresShell::HandleEvent(nsIView *aView, // will *not* go away. And this happens on every mousemove. while (targetElement && !targetElement->IsContentOfType(nsIContent::eELEMENT)) { - nsIContent* temp = targetElement; - temp->GetParent(getter_AddRefs(targetElement)); + targetElement = targetElement->GetParent(); } // If we found an element, target it. Otherwise, target *nothing*. diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 4feece69644..c6a900586bd 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -658,7 +658,7 @@ public: {} }; - nsIDocument* GetDocument(nsIPresContext* aPresContext); + already_AddRefed GetDocument(nsIPresContext* aPresContext); PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, nsAutoIndexBuffer* aIndexBuffer, @@ -1024,10 +1024,8 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, mSelectionPseudoBGIsTransparent = PR_FALSE; if (aContent) { - nsCOMPtr parentContent; - aContent->GetParent(getter_AddRefs(parentContent)); nsRefPtr sc; - sc = aPresContext->ProbePseudoStyleContextFor(parentContent, + sc = aPresContext->ProbePseudoStyleContextFor(aContent->GetParent(), nsCSSPseudoElements::mozSelection, aStyleContext); if (sc) { @@ -1347,20 +1345,15 @@ nsTextFrame::~nsTextFrame() } } -nsIDocument* +already_AddRefed nsTextFrame::GetDocument(nsIPresContext* aPresContext) { nsIDocument* result = nsnull; if (mContent) { - mContent->GetDocument(&result); + NS_IF_ADDREF(result = mContent->GetDocument()); } if (!result && aPresContext) { - nsIPresShell* shell; - aPresContext->GetShell(&shell); - if (shell) { - shell->GetDocument(&result); - NS_RELEASE(shell); - } + aPresContext->GetPresShell()->GetDocument(&result); } return result; } @@ -2519,7 +2512,7 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, *aNewContent = mContent; aOffset =0; } - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr doc(GetDocument(aPresContext)); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -3429,7 +3422,7 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, SetFontFromStyle(acx, mStyleContext); // Get the renderable form of the text - nsCOMPtr doc(getter_AddRefs(GetDocument(aCX))); + nsCOMPtr doc(GetDocument(aCX)); nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull, aCX); @@ -3767,7 +3760,7 @@ nsTextFrame::GetPointFromOffset(nsIPresContext* aPresContext, } // Transform text from content into renderable form - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr doc(GetDocument(aPresContext)); nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull, aPresContext); @@ -3975,14 +3968,12 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectNoAmount: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { - return result; + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { + return NS_OK; } nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, nsnull, aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -4007,14 +3998,12 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectCharacter: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { - return result; + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { + return NS_OK; } nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, nsnull, aPresContext); PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength); @@ -4153,9 +4142,8 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) case eSelectWord: { // Transform text from content into renderable form - nsIDocument* doc; - result = mContent->GetDocument(&doc); - if (NS_FAILED(result) || !doc) { + nsIDocument* doc = mContent->GetDocument(); + if (!doc) { return result; } @@ -4163,7 +4151,6 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos) doc->GetLineBreaker(getter_AddRefs(lb)); nsCOMPtr wb; doc->GetWordBreaker(getter_AddRefs(wb)); - NS_RELEASE(doc); nsTextTransformer tx(lb, wb, aPresContext); @@ -5345,8 +5332,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, nscoord maxWidth = aReflowState.availableWidth; // Setup text transformer to transform this frames text content - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (!doc) { NS_WARNING("Content has no document."); return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index a763da8b210..84b54c47f07 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -623,11 +623,8 @@ nsHTMLFrameOuterFrame::AttributeChanged(nsIPresContext* aPresContext, } // If the noResize attribute changes, dis/allow frame to be resized else if (aAttribute == nsHTMLAtoms::noresize) { - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); - nsCOMPtr parentTag; - parentContent->GetTag(getter_AddRefs(parentTag)); + mContent->GetParent()->GetTag(getter_AddRefs(parentTag)); if (parentTag == nsHTMLAtoms::frameset) { nsIFrame* parentFrame = GetParent(); diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp index 487ba192cd0..83e4ef60a1c 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp @@ -283,8 +283,7 @@ nsHTMLFramesetFrame::Observe(nsISupports* aObject, const char* aAction, { nsAutoString prefName(aPrefName); if (prefName.Equals(NS_LITERAL_STRING(kFrameResizePref))) { - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); if (doc) { doc->BeginUpdate(); doc->AttributeWillChange(mContent, @@ -707,15 +706,11 @@ nsHTMLFramesetFrame* nsHTMLFramesetFrame::GetFramesetParent(nsIFrame* aChild) nsIContent* content = aChild->GetContent(); if (content) { - nsCOMPtr contentParent; - content->GetParent(getter_AddRefs(contentParent)); + nsCOMPtr contentParent = content->GetParent(); - nsCOMPtr contentParent2 = - do_QueryInterface(contentParent); - - if (contentParent2) { + if (contentParent && contentParent->IsContentOfType(nsIContent::eHTML)) { nsCOMPtr tag; - contentParent2->GetTag(getter_AddRefs(tag)); + contentParent->GetTag(getter_AddRefs(tag)); if (tag == nsHTMLAtoms::frameset) { nsIFrame* fptr = aChild->GetParent(); diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 1405e1f2c2e..8d5994de43c 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -388,9 +388,8 @@ nsComboboxControlFrame::Init(nsIPresContext* aPresContext, // Start - Temporary fix for Bug 36558 //------------------------------- mGoodToGo = PR_FALSE; - nsCOMPtr document; - nsresult rv = aContent->GetDocument(getter_AddRefs(document)); - if (NS_SUCCEEDED(rv) && document) { + nsIDocument* document = aContent->GetDocument(); + if (document) { #ifdef MOZ_XUL nsCOMPtr xulDoc(do_QueryInterface(document)); mGoodToGo = xulDoc?PR_FALSE:PR_TRUE; @@ -2124,8 +2123,7 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, mDisplayContent = do_QueryInterface(labelContent); mDisplayContent->SetText(NS_LITERAL_STRING("X"), PR_TRUE); - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); // mContent->AppendChildTo(labelContent, PR_FALSE, PR_FALSE); nsCOMPtr nimgr; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 24d8578486c..e7a3225504a 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -139,8 +139,7 @@ nsFileControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aChildList) { // Get the NodeInfoManager and tag necessary to create input elements - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); nsCOMPtr nimgr; nsresult rv = doc->GetNodeInfoManager(getter_AddRefs(nimgr)); NS_ENSURE_SUCCESS(rv, rv); @@ -269,10 +268,9 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) if (!content) return NS_ERROR_FAILURE; - nsCOMPtr doc; - result = content->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = content->GetDocument(); if (!doc) - return NS_FAILED(result) ? result : NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; nsCOMPtr scriptGlobalObject; result = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 7ef1cb9f3a1..9b6403728a9 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -110,13 +110,12 @@ nsGfxButtonControlFrame::IsFileBrowseButton(PRInt32 type) // Check to see if parent is a file input nsresult result; - nsCOMPtr parentContent; - result = mContent->GetParent(getter_AddRefs(parentContent)); - if (NS_SUCCEEDED(result) && parentContent) { + nsCOMPtr parentContent = mContent->GetParent(); + if (parentContent) { nsCOMPtr atom; result = parentContent->GetTag(getter_AddRefs(atom)); if (NS_SUCCEEDED(result) && atom) { - if (atom.get() == nsHTMLAtoms::input) { + if (atom == nsHTMLAtoms::input) { // It's an input, is it a file input? nsAutoString value; diff --git a/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp b/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp index 1890468d492..94999e33439 100644 --- a/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp +++ b/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp @@ -227,8 +227,7 @@ nsIsIndexFrame::CreateAnonymousContent(nsIPresContext* aPresContext, nsresult result; // Get the node info manager (used to create hr's and input's) - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); nsCOMPtr nimgr; result = doc->GetNodeInfoManager(getter_AddRefs(nimgr)); NS_ENSURE_SUCCESS(result, result); @@ -417,8 +416,7 @@ nsIsIndexFrame::OnSubmit(nsIPresContext* aPresContext) // Get the document. // We'll need it now to form the URL we're submitting to. // We'll also need it later to get the DOM window when notifying form submit observers (bug 33203) - nsCOMPtr document; - mContent->GetDocument(getter_AddRefs(document)); + nsCOMPtr document = mContent->GetDocument(); if (!document) return NS_OK; // No doc means don't submit, see Bug 28988 // Resolve url to an absolute url @@ -506,8 +504,7 @@ void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset) // see 17.3 The FORM element in HTML 4 for details // Get the charset from document - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (doc) { doc->GetDocumentCharacterSet(oCharset); } diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 6fdb77d2476..7dbd48da623 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -1455,17 +1455,10 @@ nsListControlFrame::IsOptionElement(nsIContent* aContent) nsIContent * nsListControlFrame::GetOptionFromContent(nsIContent *aContent) { - nsCOMPtr content = aContent; - while (content) { + for (nsIContent* content = aContent; content; content = content->GetParent()) { if (IsOptionElement(content)) { - nsIContent *out = content; - NS_ADDREF(out); - return out; + return content; } - - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - parent.swap(content); } return nsnull; @@ -2899,7 +2892,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, nsCOMPtr content; stateManager->GetEventTargetContent(nsnull, getter_AddRefs(content)); - nsCOMPtr optionContent = getter_AddRefs(GetOptionFromContent(content)); + nsCOMPtr optionContent = GetOptionFromContent(content); if (optionContent) { aCurIndex = GetIndexFromContent(optionContent); rv = NS_OK; @@ -3109,8 +3102,7 @@ nsListControlFrame::ScrollToFrame(nsIContent* aOptElement) // and then adds in the parent's y coord // XXX this assume only one level of nesting of optgroups // which is all the spec specifies at the moment. - nsCOMPtr parentContent; - aOptElement->GetParent(getter_AddRefs(parentContent)); + nsCOMPtr parentContent = aOptElement->GetParent(); nsCOMPtr optGroup(do_QueryInterface(parentContent)); nsRect optRect(0,0,0,0); if (optGroup) { diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index 99cd95141d1..ae7e00eb7b7 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -262,22 +262,19 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsISelection* mFrame->GetFormContent(*getter_AddRefs(content)); if (content) { - nsCOMPtr doc; - if (NS_SUCCEEDED(content->GetDocument(getter_AddRefs(doc)))) + nsCOMPtr doc = content->GetDocument(); + if (doc) { - if (doc) + nsCOMPtr presShell; + doc->GetShellAt(0, getter_AddRefs(presShell)); + if (presShell) { - nsCOMPtr presShell; - doc->GetShellAt(0, getter_AddRefs(presShell)); - if (presShell) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SELECTED; + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_FORM_SELECTED; - presShell->HandleEventWithTarget(&event,mFrame,content,NS_EVENT_FLAG_INIT,&status); - } + presShell->HandleEventWithTarget(&event,mFrame,content,NS_EVENT_FLAG_INIT,&status); } } } @@ -384,12 +381,11 @@ nsTextInputListener::UpdateTextInputCommands(const nsAString& commandsToUpdate) nsIContent* content = mFrame->GetContent(); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - nsCOMPtr doc; - nsresult rv = content->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = content->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); nsCOMPtr scriptGlobalObject; - rv = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); + nsresult rv = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE); nsCOMPtr domWindow = do_QueryInterface(scriptGlobalObject); diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index d0a85c49301..cbc141ea87c 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -7985,17 +7985,14 @@ ShouldIgnoreSelectChild(nsIContent* aContainer) if (containerTag == nsHTMLAtoms::optgroup || containerTag == nsHTMLAtoms::select) { - nsCOMPtr selectContent = aContainer; - nsCOMPtr tmpContent; + nsIContent* selectContent = aContainer; - while (selectContent) { - if (containerTag == nsHTMLAtoms::select) + while (containerTag != nsHTMLAtoms::select) { + selectContent = selectContent->GetParent(); + if (!selectContent) { break; - - tmpContent = selectContent; - tmpContent->GetParent(getter_AddRefs(selectContent)); - if (selectContent) - selectContent->GetTag(getter_AddRefs(containerTag)); + } + selectContent->GetTag(getter_AddRefs(containerTag)); } nsCOMPtr selectElement = do_QueryInterface(selectContent); @@ -8097,11 +8094,11 @@ nsCSSFrameConstructor::ContentAppended(nsIPresContext* aPresContext, PRBool hasInsertion = PR_FALSE; if (!multiple) { nsCOMPtr bindingManager; - nsCOMPtr document; + nsIDocument* document = nsnull; nsCOMPtr firstAppendedChild; aContainer->ChildAt(aNewIndexInContainer, getter_AddRefs(firstAppendedChild)); if (firstAppendedChild) { - firstAppendedChild->GetDocument(getter_AddRefs(document)); + document = firstAppendedChild->GetDocument(); } if (document) document->GetBindingManager(getter_AddRefs(bindingManager)); @@ -8969,8 +8966,7 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, // Check again to see if the frame we are manipulating is part // of a block-in-inline hierarchy. if (IsFrameSpecial(parentFrame)) { - nsCOMPtr parentContainer; - blockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = blockContent->GetParent(); #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentInserted: parentFrame="); @@ -9944,8 +9940,7 @@ nsCSSFrameConstructor::ContentChanged(nsIPresContext* aPresContext, if (haveFirstLetterStyle) { // The block has first-letter style. Use content-replaced to // repair the blocks frame structure properly. - nsCOMPtr container; - aContent->GetParent(getter_AddRefs(container)); + nsCOMPtr container = aContent->GetParent(); if (container) { PRInt32 ix; container->IndexOf(aContent, ix); @@ -10055,18 +10050,10 @@ nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList& aChangeList, return NS_OK; } -inline already_AddRefed -parent_of(nsIContent *aContent) -{ - nsIContent *parent = nsnull; - aContent->GetParent(&parent); - return parent; -} - static PRBool IsAncestorOf(nsIContent *aAncestor, nsIContent *aDescendant) { - for (nsCOMPtr n = aDescendant; n; n = parent_of(n)) + for (nsIContent* n = aDescendant; n; n = n->GetParent()) if (n == aAncestor) return PR_TRUE; return PR_FALSE; @@ -11272,10 +11259,8 @@ nsCSSFrameConstructor::FindFrameWithContent(nsIPresContext* aPresContext, // child frames, too. // We also need to search if the child content is anonymous and scoped // to the parent content. - nsCOMPtr parentScope; - kidContent->GetBindingParent(getter_AddRefs(parentScope)); if (aParentContent == kidContent || - (aParentContent && (aParentContent == parentScope))) + (aParentContent && (aParentContent == kidContent->GetBindingParent()))) { #ifdef NOISY_FINDFRAME FFWC_recursions++; @@ -11358,14 +11343,13 @@ nsCSSFrameConstructor::FindPrimaryFrameFor(nsIPresContext* aPresContext, // - internal table frames (row-group, row, cell, col-group, col) // // That means we need to need to search for the frame - nsCOMPtr parentContent; // we get this one time nsIFrame* parentFrame; // this pointer is used to iterate across all frames that map to parentContent // Get the frame that corresponds to the parent content object. // Note that this may recurse indirectly, because the pres shell will // call us back if there is no mapping in the hash table - aContent->GetParent(getter_AddRefs(parentContent)); - if (parentContent.get()) { + nsCOMPtr parentContent = aContent->GetParent(); // Get this once + if (parentContent) { aFrameManager->GetPrimaryFrameFor(parentContent, &parentFrame); while (parentFrame) { // Search the child frames for a match @@ -11455,8 +11439,7 @@ nsCSSFrameConstructor::GetInsertionPoint(nsIPresShell* aPresShell, if (!container) return NS_OK; - nsCOMPtr document; - container->GetDocument(getter_AddRefs(document)); + nsIDocument* document = container->GetDocument(); if (!document) return NS_OK; @@ -11469,9 +11452,7 @@ nsCSSFrameConstructor::GetInsertionPoint(nsIPresShell* aPresShell, if (aChildContent) { // We've got an explicit insertion child. Check to see if it's // anonymous. - nsCOMPtr bindingParent; - aChildContent->GetBindingParent(getter_AddRefs(bindingParent)); - if (bindingParent == container) { + if (aChildContent->GetBindingParent() == container) { // This child content is anonymous. Don't use the insertion // point, since that's only for the explicit kids. return NS_OK; @@ -11585,8 +11566,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, // If there is no document, we don't want to recreate frames for it. (You // shouldn't generally be giving this method content without a document // anyway). - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = aContent->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); // Is the frame `special'? If so, we need to reframe the containing @@ -11630,8 +11610,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, } nsresult rv = NS_OK; - nsCOMPtr container; - aContent->GetParent(getter_AddRefs(container)); + nsCOMPtr container = aContent->GetParent(); if (container) { PRInt32 indexInContainer; rv = container->IndexOf(aContent, indexInContainer); @@ -11667,8 +11646,7 @@ nsCSSFrameConstructor::RecreateFramesForContent(nsIPresContext* aPresContext, // However, double check that it's really part of the document, // since rebuilding the frame tree can have bad effects, especially // if it's the frame tree for chrome (see bug 157322). - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = aContent->GetDocument(); NS_ASSERTION(doc, "received style change for content not in document"); if (doc) ReconstructDocElementHierarchy(aPresContext); @@ -13336,8 +13314,7 @@ nsCSSFrameConstructor::WipeContainingBlock(nsIPresContext* aPresContext, // Tell parent of the containing block to reformulate the // entire block. This is painful and definitely not optimal // but it will *always* get the right answer. - nsCOMPtr parentContainer; - aBlockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = aBlockContent->GetParent(); #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::WipeContainingBlock: aBlockContent=%p parentContainer=%p\n", @@ -13662,11 +13639,10 @@ nsCSSFrameConstructor::ReframeContainingBlock(nsIPresContext* aPresContext, nsIF // so GetFloaterContainingBlock(aPresContext, aFrame) has been removed // And get the containingBlock's content - nsIContent* blockContent = containingBlock->GetContent(); + nsCOMPtr blockContent = containingBlock->GetContent(); if (blockContent) { // Now find the containingBlock's content's parent - nsCOMPtr parentContainer; - blockContent->GetParent(getter_AddRefs(parentContainer)); + nsCOMPtr parentContainer = blockContent->GetParent(); if (parentContainer) { #ifdef DEBUG if (gNoisyContentUpdates) { diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index 28a9cb1b79d..d14c99eb1aa 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -2797,22 +2797,16 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, // a root, other wise keep going in order to let the theme stuff // draw the background. The canvas really should be drawing the // bg, but there's no way to hook that up via css. - const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay(); - if (displayData->mAppearance) { - nsIContent* content = aForFrame->GetContent(); - if (content) { - nsCOMPtr parent; - content->GetParent(getter_AddRefs(parent)); - if (parent) - return; - else - color = aForFrame->GetStyleBackground(); - } - else - return; - } - else + if (!aForFrame->GetStyleDisplay()->mAppearance) { return; + } + + nsIContent* content = aForFrame->GetContent(); + if (!content || content->GetParent()) { + return; + } + + color = aForFrame->GetStyleBackground(); } if (!isCanvas) { PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame, diff --git a/mozilla/layout/html/style/src/nsChildIterator.cpp b/mozilla/layout/html/style/src/nsChildIterator.cpp index 949d39db7d6..9ce19a67e87 100644 --- a/mozilla/layout/html/style/src/nsChildIterator.cpp +++ b/mozilla/layout/html/style/src/nsChildIterator.cpp @@ -53,9 +53,8 @@ ChildIterator::Init(nsIContent* aContent, if (! aContent) return NS_ERROR_NULL_POINTER; - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc != nsnull, "element not in the document"); + nsCOMPtr doc = aContent->GetDocument(); + NS_ASSERTION(doc, "element not in the document"); if (! doc) return NS_ERROR_FAILURE; diff --git a/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp index 84567999617..16e3e8ae00d 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp @@ -630,7 +630,7 @@ nsMathMLFrame::MapAttributesIntoCSS(nsIPresContext* aPresContext, if (!sheet) { // first time... we do this to defer the lookup up to the // point where we encounter attributes that actually matter - aContent->GetDocument(getter_AddRefs(doc)); + doc = aContent->GetDocument(); if (!doc) return 0; GetMathMLAttributeStyleSheet(aPresContext, getter_AddRefs(sheet)); diff --git a/mozilla/layout/xul/base/src/nsBox.cpp b/mozilla/layout/xul/base/src/nsBox.cpp index 6d624e4f7fb..c72c9256762 100644 --- a/mozilla/layout/xul/base/src/nsBox.cpp +++ b/mozilla/layout/xul/base/src/nsBox.cpp @@ -672,8 +672,7 @@ nsBox::GetBorder(nsMargin& aMargin) nsCOMPtr content; frame->GetContent(getter_AddRefs(content)); if (content) { - nsCOMPtr doc; - content->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = content->GetDocument(); if (doc) { nsCOMPtr shell; doc->GetShellAt(0, getter_AddRefs(shell)); diff --git a/mozilla/layout/xul/base/src/nsBoxObject.cpp b/mozilla/layout/xul/base/src/nsBoxObject.cpp index a3991ca894b..25bf40de845 100644 --- a/mozilla/layout/xul/base/src/nsBoxObject.cpp +++ b/mozilla/layout/xul/base/src/nsBoxObject.cpp @@ -179,8 +179,7 @@ nsBoxObject::GetOffsetRect(nsRect& aRect) aRect.x = aRect.y = 0; aRect.Empty(); - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); if (doc) { // Get Presentation shell 0 @@ -284,8 +283,7 @@ nsBoxObject::GetScreenRect(nsRect& aRect) aRect.x = aRect.y = 0; aRect.Empty(); - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); if (doc) { // Get Presentation shell 0 diff --git a/mozilla/layout/xul/base/src/nsDocElementBoxFrame.cpp b/mozilla/layout/xul/base/src/nsDocElementBoxFrame.cpp index 75ea1bdde84..341dc9f41ab 100644 --- a/mozilla/layout/xul/base/src/nsDocElementBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsDocElementBoxFrame.cpp @@ -124,8 +124,7 @@ nsDocElementBoxFrame::CreateAnonymousContent(nsIPresContext* aPresContext, return NS_ERROR_FAILURE; nsCOMPtr nodeInfoManager; - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mContent->GetDocument(); if (!doc) // The page is currently being torn down. Why bother. return NS_ERROR_FAILURE; diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index 72888280a52..efac5a9326b 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -476,7 +476,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) nsCOMPtr documentURI; nsCOMPtr doc; if (mContent) { - (void) mContent->GetDocument(getter_AddRefs(doc)); + doc = mContent->GetDocument(); if (doc) { doc->GetDocumentURL(getter_AddRefs(documentURI)); } diff --git a/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp b/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp index c7b06581087..8022381ef57 100644 --- a/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp @@ -579,8 +579,7 @@ nsListBoxBodyFrame::GetIndexOfItem(nsIDOMElement* aItem, PRInt32* _retval) *_retval = 0; nsCOMPtr itemContent(do_QueryInterface(aItem)); - nsCOMPtr listbox; - mContent->GetBindingParent(getter_AddRefs(listbox)); + nsIContent* listbox = mContent->GetBindingParent(); PRInt32 childCount = 0; listbox->ChildCount(childCount); @@ -612,8 +611,7 @@ nsListBoxBodyFrame::GetItemAtIndex(PRInt32 aIndex, nsIDOMElement** _retval) if (aIndex < 0) return NS_ERROR_ILLEGAL_VALUE; - nsCOMPtr listbox; - mContent->GetBindingParent(getter_AddRefs(listbox)); + nsIContent* listbox = mContent->GetBindingParent(); PRInt32 childCount = 0; listbox->ChildCount(childCount); @@ -750,8 +748,7 @@ nsListBoxBodyFrame::ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState) styleContext->GetStyleMargin()->GetMargin(margin); width += (margin.left + margin.right); - nsCOMPtr listbox; - mContent->GetBindingParent(getter_AddRefs(listbox)); + nsIContent* listbox = mContent->GetBindingParent(); PRInt32 childCount; listbox->ChildCount(childCount); @@ -803,8 +800,7 @@ nsListBoxBodyFrame::ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState) void nsListBoxBodyFrame::ComputeTotalRowCount() { - nsCOMPtr listbox; - mContent->GetBindingParent(getter_AddRefs(listbox)); + nsIContent* listbox = mContent->GetBindingParent(); PRInt32 childCount; listbox->ChildCount(childCount); @@ -856,9 +852,7 @@ nsListBoxBodyFrame::DoScrollToIndex(PRInt32 aRowIndex, PRBool aForceDestruct) // This change has to happen immediately. // Flush any pending reflow commands. - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); - doc->FlushPendingNotifications(); + mContent->GetDocument()->FlushPendingNotifications(); return NS_OK; } @@ -1147,8 +1141,7 @@ nsListBoxBodyFrame::GetFirstItemBox(PRInt32 aOffset, PRBool* aCreated) // We need to insert rows before the top frame nsCOMPtr topContent; mTopFrame->GetContent(getter_AddRefs(topContent)); - nsCOMPtr topParent; - topContent->GetParent(getter_AddRefs(topParent)); + nsIContent* topParent = topContent->GetParent(); PRInt32 contentIndex; topParent->IndexOf(topContent, contentIndex); contentIndex -= aOffset; @@ -1206,8 +1199,7 @@ nsListBoxBodyFrame::GetNextItemBox(nsIBox* aBox, PRInt32 aOffset, PRBool* aCreat PRInt32 i, childCount; nsCOMPtr prevContent; frame->GetContent(getter_AddRefs(prevContent)); - nsCOMPtr parentContent; - prevContent->GetParent(getter_AddRefs(parentContent)); + nsIContent* parentContent = prevContent->GetParent(); parentContent->IndexOf(prevContent, i); parentContent->ChildCount(childCount); if (i+aOffset+1 < childCount) { @@ -1356,10 +1348,9 @@ nsListBoxBodyFrame::OnContentRemoved(nsIPresContext* aPresContext, nsIFrame* aCh if (!aChildFrame) { // The row we are removing is out of view, so we need to try to // determine the index of its next sibling. - nsCOMPtr listboxContent; - mContent->GetBindingParent(getter_AddRefs(listboxContent)); nsCOMPtr oldNextSiblingContent; - listboxContent->ChildAt(aIndex, getter_AddRefs(oldNextSiblingContent)); + mContent->GetBindingParent()->ChildAt(aIndex, + getter_AddRefs(oldNextSiblingContent)); PRInt32 siblingIndex = -1; if (oldNextSiblingContent) { nsCOMPtr nextSiblingContent; @@ -1382,8 +1373,7 @@ nsListBoxBodyFrame::OnContentRemoved(nsIPresContext* aPresContext, nsIFrame* aCh // down by one, and we will have to insert a new frame at the top. // if the last content node has a frame, we are scrolled to the bottom - nsCOMPtr listBoxContent; - mContent->GetBindingParent(getter_AddRefs(listBoxContent)); + nsIContent* listBoxContent = mContent->GetBindingParent(); PRInt32 childCount; listBoxContent->ChildCount(childCount); if (childCount > 0) { @@ -1426,8 +1416,7 @@ nsListBoxBodyFrame::OnContentRemoved(nsIPresContext* aPresContext, nsIFrame* aCh void nsListBoxBodyFrame::GetListItemContentAt(PRInt32 aIndex, nsIContent** aContent) { - nsCOMPtr listboxContent; - mContent->GetBindingParent(getter_AddRefs(listboxContent)); + nsIContent* listboxContent = mContent->GetBindingParent(); PRInt32 childCount; listboxContent->ChildCount(childCount); @@ -1452,8 +1441,7 @@ nsListBoxBodyFrame::GetListItemContentAt(PRInt32 aIndex, nsIContent** aContent) void nsListBoxBodyFrame::GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, PRInt32& aSiblingIndex) { - nsCOMPtr listboxContent; - mContent->GetBindingParent(getter_AddRefs(listboxContent)); + nsIContent* listboxContent = mContent->GetBindingParent(); aSiblingIndex = -1; diff --git a/mozilla/layout/xul/base/src/nsListBoxObject.cpp b/mozilla/layout/xul/base/src/nsListBoxObject.cpp index de35fdc4bbb..f860c6548b4 100644 --- a/mozilla/layout/xul/base/src/nsListBoxObject.cpp +++ b/mozilla/layout/xul/base/src/nsListBoxObject.cpp @@ -186,8 +186,7 @@ FindBodyContent(nsIContent* aParent, nsIContent** aResult) NS_IF_ADDREF(*aResult); } else { - nsCOMPtr doc; - aParent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = aParent->GetDocument(); nsCOMPtr bindingManager; doc->GetBindingManager(getter_AddRefs(bindingManager)); nsCOMPtr kids; diff --git a/mozilla/layout/xul/base/src/nsMenuBarFrame.cpp b/mozilla/layout/xul/base/src/nsMenuBarFrame.cpp index 031125a491e..6510591466a 100644 --- a/mozilla/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuBarFrame.cpp @@ -153,9 +153,7 @@ nsMenuBarFrame::Init(nsIPresContext* aPresContext, // Hook up the menu bar as a key listener on the whole document. It will see every // key press that occurs, but after everyone else does. - nsCOMPtr doc; - aContent->GetDocument(getter_AddRefs(doc)); - nsCOMPtr target = do_QueryInterface(doc); + nsCOMPtr target = do_QueryInterface(aContent->GetDocument()); mTarget = target; diff --git a/mozilla/layout/xul/base/src/nsMenuFrame.cpp b/mozilla/layout/xul/base/src/nsMenuFrame.cpp index ecf5824fb09..070cd101431 100644 --- a/mozilla/layout/xul/base/src/nsMenuFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuFrame.cpp @@ -1512,11 +1512,8 @@ nsMenuFrame::BuildAcceleratorText() if (keyValue.IsEmpty()) return; - nsCOMPtr document; - mContent->GetDocument(getter_AddRefs(document)); - // Turn the document into a DOM document so we can use getElementById - nsCOMPtr domDocument(do_QueryInterface(document)); + nsCOMPtr domDocument(do_QueryInterface(mContent->GetDocument())); if (!domDocument) return; @@ -1710,14 +1707,12 @@ nsMenuFrame::Execute(nsGUIEvent *aEvent) // XXX HACK. Just gracefully exit if the node has been removed, e.g., window.close() // was executed. - nsCOMPtr doc; - content->GetDocument(getter_AddRefs(doc)); - nsIFrame* primary = nsnull; if (shell) shell->GetPrimaryFrameFor(content, &primary); // Now properly close them all up. - if (doc && (primary == me) && mMenuParent) // <-- HACK IS HERE. ICK. + if (content->GetDocument() && // <-- HACK IS HERE. ICK. + (primary == me) && mMenuParent) mMenuParent->DismissChain(); // END HACK @@ -1764,9 +1759,7 @@ nsMenuFrame::OnCreate() // of them has a command attribute. If so, then several attributes must // potentially be updated. if (child) { - nsCOMPtr doc; - child->GetDocument(getter_AddRefs(doc)); - nsCOMPtr domDoc(do_QueryInterface(doc)); + nsCOMPtr domDoc(do_QueryInterface(child->GetDocument())); PRInt32 count; child->ChildCount(count); diff --git a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp index 8d2bc9dc4a8..34b01416fbb 100644 --- a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -223,8 +223,7 @@ nsMenuPopupFrame::Init(nsIPresContext* aPresContext, widgetData.mBorderStyle = eBorderStyle_default; widgetData.clipSiblings = PR_TRUE; - nsCOMPtr parentContent; - aContent->GetParent(getter_AddRefs(parentContent)); + nsIContent* parentContent = aContent->GetParent(); nsCOMPtr tag; if (parentContent) parentContent->GetTag(getter_AddRefs(tag)); @@ -632,8 +631,7 @@ nsMenuPopupFrame::AdjustClientXYForNestedDocuments ( nsIDOMXULDocument* inPopupD nsCOMPtr targetAsContent ( do_QueryInterface(targetNode) ); nsCOMPtr targetDocumentWidget; if ( targetAsContent ) { - nsCOMPtr targetDocument; - targetAsContent->GetDocument(getter_AddRefs(targetDocument)); + nsCOMPtr targetDocument = targetAsContent->GetDocument(); if (targetDocument) { nsCOMPtr shell; targetDocument->GetShellAt(0, getter_AddRefs(shell)); @@ -1456,8 +1454,7 @@ NS_IMETHODIMP nsMenuPopupFrame::ConsumeOutsideClicks(PRBool& aConsumeOutsideClic aConsumeOutsideClicks = PR_TRUE; - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); + nsCOMPtr parentContent = mContent->GetParent(); if (parentContent) { nsCOMPtr parentTag; @@ -1702,8 +1699,7 @@ nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, PRBool& doActi nsIMenuFrame* frameAfter = nsnull; nsIMenuFrame* frameShortcut = nsnull; - nsCOMPtr parentContent; - mContent->GetParent(getter_AddRefs(parentContent)); + nsIContent* parentContent = mContent->GetParent(); if (parentContent) { nsCOMPtr tag; parentContent->GetTag(getter_AddRefs(tag)); @@ -2090,9 +2086,7 @@ nsMenuPopupFrame::InstallKeyboardNavigator() if (mKeyboardNavigator) return NS_OK; - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); - nsCOMPtr target = do_QueryInterface(doc); + nsCOMPtr target = do_QueryInterface(mContent->GetDocument()); mTarget = target; mKeyboardNavigator = new nsMenuListener(this); diff --git a/mozilla/layout/xul/base/src/nsPopupSetFrame.cpp b/mozilla/layout/xul/base/src/nsPopupSetFrame.cpp index 9c37dee6dc7..80f24a21ede 100644 --- a/mozilla/layout/xul/base/src/nsPopupSetFrame.cpp +++ b/mozilla/layout/xul/base/src/nsPopupSetFrame.cpp @@ -558,8 +558,7 @@ nsPopupSetFrame::ActivatePopup(nsPopupFrameList* aEntry, PRBool aActivateFlag) // can get into trouble if a dialog with a modal event loop comes along and // processes the reflows before we get to call DestroyChain(). Processing the // reflow will cause the popup to show itself again. (bug 71219) - nsCOMPtr doc; - aEntry->mPopupContent->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = aEntry->mPopupContent->GetDocument(); if (doc) doc->FlushPendingNotifications(); @@ -613,9 +612,7 @@ nsPopupSetFrame::OnCreate(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent) // of them has a command attribute. If so, then several attributes must // potentially be updated. - nsCOMPtr doc; - aPopupContent->GetDocument(getter_AddRefs(doc)); - nsCOMPtr domDoc(do_QueryInterface(doc)); + nsCOMPtr domDoc(do_QueryInterface(aPopupContent->GetDocument())); PRInt32 count; aPopupContent->ChildCount(count); diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp index 4724e8714bf..521a87c91bd 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp @@ -139,10 +139,8 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent) nsCOMPtr targetNode(do_QueryInterface(eventTarget)); // which node is our tooltip on? - nsCOMPtr doc; - mCurrentTooltip->GetDocument(getter_AddRefs(doc)); - nsCOMPtr xulDoc(do_QueryInterface(doc)); - if (!doc) // remotely possible someone could have + nsCOMPtr xulDoc(do_QueryInterface(mCurrentTooltip->GetDocument())); + if (!xulDoc) // remotely possible someone could have return NS_OK; // removed tooltip from dom while it was open nsCOMPtr tooltipNode; xulDoc->GetTooltipNode (getter_AddRefs(tooltipNode)); @@ -387,15 +385,11 @@ nsXULTooltipListener::ShowTooltip() return NS_ERROR_FAILURE; // the target node doesn't need a tooltip // set the node in the document that triggered the tooltip and show it - nsCOMPtr doc; - mCurrentTooltip->GetDocument(getter_AddRefs(doc)); - nsCOMPtr xulDoc(do_QueryInterface(doc)); + nsCOMPtr xulDoc(do_QueryInterface(mCurrentTooltip->GetDocument())); if (xulDoc) { // Make sure the target node is still attached to some document. // It might have been deleted. - nsCOMPtr targetDoc; - mSourceNode->GetDocument(getter_AddRefs(targetDoc)); - if (targetDoc) { + if (mSourceNode->GetDocument()) { #ifdef MOZ_XUL if (!mIsSourceTree) { mLastTreeRow = -1; @@ -426,8 +420,7 @@ nsXULTooltipListener::ShowTooltip() (nsIDOMMouseListener*)this, PR_FALSE); // listen for mousedown,keydown, and DOMMouseScroll events at document level - nsCOMPtr doc; - mSourceNode->GetDocument(getter_AddRefs(doc)); + nsIDocument* doc = mSourceNode->GetDocument(); if (doc) { evtTarget = do_QueryInterface(doc); evtTarget->AddEventListener(NS_LITERAL_STRING("DOMMouseScroll"), @@ -567,8 +560,8 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip) return NS_ERROR_FAILURE; // could be a text node or something // before we go on, make sure that target node still has a window - nsCOMPtr document; - if (NS_FAILED(aTarget->GetDocument(getter_AddRefs(document))) || !document) { + nsCOMPtr document = aTarget->GetDocument(); + if (!document) { NS_ERROR("Unable to retrieve the tooltip node document."); return NS_ERROR_FAILURE; } @@ -645,8 +638,7 @@ nsXULTooltipListener::DestroyTooltip() { if (mCurrentTooltip) { // clear out the tooltip node on the document - nsCOMPtr doc; - mCurrentTooltip->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mCurrentTooltip->GetDocument(); if (doc) { nsCOMPtr xulDoc(do_QueryInterface(doc)); if (xulDoc) @@ -726,9 +718,7 @@ nsXULTooltipListener::GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject) *aBoxObject = nsnull; if (mIsSourceTree && mSourceNode) { - nsCOMPtr treeParent; - mSourceNode->GetParent(getter_AddRefs(treeParent)); - nsCOMPtr xulEl(do_QueryInterface(treeParent)); + nsCOMPtr xulEl(do_QueryInterface(mSourceNode->GetParent())); if (xulEl) { nsCOMPtr bx; xulEl->GetBoxObject(getter_AddRefs(bx)); diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 7e8a31ba801..ee7cc3c050c 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -265,8 +265,7 @@ nsTreeColumn::nsTreeColumn(nsIContent* aColElement, nsIFrame* aFrame) // Cache our index. mColIndex = -1; - nsCOMPtr parent; - mColElement->GetParent(getter_AddRefs(parent)); + nsIContent* parent = mColElement->GetParent(); PRInt32 count; parent->ChildCount(count); PRInt32 j = 0; @@ -559,12 +558,9 @@ nsTreeBodyFrame::EnsureBoxObject() GetBaseElement(getter_AddRefs(parent)); if (parent) { - nsCOMPtr parentDoc; - parent->GetDocument(getter_AddRefs(parentDoc)); - if (!parentDoc) // there may be no document, if we're called from Destroy() + nsCOMPtr nsDoc = do_QueryInterface(parent->GetDocument()); + if (!nsDoc) // there may be no document, if we're called from Destroy() return; - - nsCOMPtr nsDoc = do_QueryInterface(parentDoc); nsCOMPtr box; nsCOMPtr domElem = do_QueryInterface(parent); nsDoc->GetBoxObjectFor(domElem, getter_AddRefs(box)); @@ -612,9 +608,7 @@ nsTreeBodyFrame::EnsureView() // If we don't have a box object yet, or no view was set on it, // look for a XULTreeBuilder or create a content view. - nsCOMPtr parent; - mContent->GetParent(getter_AddRefs(parent)); - nsCOMPtr xulele = do_QueryInterface(parent); + nsCOMPtr xulele = do_QueryInterface(mContent->GetParent()); if (xulele) { nsCOMPtr view; @@ -1117,9 +1111,7 @@ nsTreeBodyFrame::AdjustEventCoordsToBoxCoordSpace (PRInt32 aX, PRInt32 aY, PRInt aY = NSToIntRound(aY * pixelsToTwips); // Get our box object. - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); - nsCOMPtr nsDoc(do_QueryInterface(doc)); + nsCOMPtr nsDoc(do_QueryInterface(mContent->GetDocument())); nsCOMPtr elt(do_QueryInterface(mContent)); nsCOMPtr boxObject; @@ -1952,8 +1944,7 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs nsCOMPtr imgDecoderObserver = listener; nsCOMPtr baseURI; - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = mContent->GetDocument(); if (!doc) // The page is currently being torn down. Why bother. return NS_ERROR_FAILURE; @@ -3522,18 +3513,16 @@ nsTreeBodyFrame::EnsureColumns() nsresult nsTreeBodyFrame::GetBaseElement(nsIContent** aContent) { - nsCOMPtr parent = mContent; nsCOMPtr tag; - nsCOMPtr temp; - - while (parent && NS_SUCCEEDED(parent->GetTag(getter_AddRefs(tag))) - && tag != nsXULAtoms::tree && tag != nsHTMLAtoms::select) { - temp = parent; - temp->GetParent(getter_AddRefs(parent)); + nsIContent* parent; + for (parent = mContent; + parent && NS_SUCCEEDED(parent->GetTag(getter_AddRefs(tag))) + && tag != nsXULAtoms::tree && tag != nsHTMLAtoms::select; + parent = parent->GetParent()) { + // Do nothing; we just go up till we hit the right tag or run off the tree } - *aContent = parent; - NS_IF_ADDREF(*aContent); + NS_IF_ADDREF(*aContent = parent); return NS_OK; } diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeColFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeColFrame.cpp index 21b97ec5a74..3ffe4cb40ea 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeColFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeColFrame.cpp @@ -201,14 +201,10 @@ nsTreeColFrame::EnsureTree() { if (!mTree && mContent) { // Get our parent node. - nsCOMPtr parent; - mContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = mContent->GetParent(); if (parent) { - nsCOMPtr grandParent; - parent->GetParent(getter_AddRefs(grandParent)); - nsCOMPtr doc; - mContent->GetDocument(getter_AddRefs(doc)); - nsCOMPtr nsDoc(do_QueryInterface(doc)); + nsIContent* grandParent = parent->GetParent(); + nsCOMPtr nsDoc(do_QueryInterface(mContent->GetDocument())); nsCOMPtr elt(do_QueryInterface(grandParent)); nsCOMPtr boxObject; diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeContentView.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeContentView.cpp index e8a9a84d888..baafe0be613 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeContentView.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeContentView.cpp @@ -551,8 +551,7 @@ nsTreeContentView::SetTree(nsITreeBoxObject* aTree) mRoot = do_QueryInterface(element); // Add ourselves to document's observers. - nsCOMPtr document; - mRoot->GetDocument(getter_AddRefs(document)); + nsIDocument* document = mRoot->GetDocument(); if (document) { document->AddObserver(this); mDocument = document; @@ -757,8 +756,7 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument, nsCOMPtr parent = aContent; nsCOMPtr parentTag; do { - nsCOMPtr temp = parent; - temp->GetParent(getter_AddRefs(parent)); + parent = parent->GetParent(); if (parent) parent->GetTag(getter_AddRefs(parentTag)); } while (parent && parentTag != nsXULAtoms::tree); @@ -783,11 +781,9 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument, } else if (!hidden && index < 0) { // Show this row along with its children. - nsCOMPtr container; - aContent->GetParent(getter_AddRefs(container)); + nsCOMPtr container = aContent->GetParent(); if (container) { - nsCOMPtr parent; - container->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = container->GetParent(); if (parent) InsertRowFor(parent, container, aContent); } @@ -843,8 +839,7 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument, } else if (tag == nsXULAtoms::treerow) { if (aAttribute == nsXULAtoms::properties) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContent->GetParent(); if (parent) { PRInt32 index = FindContent(parent); if (index >= 0) { @@ -859,11 +854,9 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument, aAttribute == nsXULAtoms::mode || aAttribute == nsHTMLAtoms::value || aAttribute == nsHTMLAtoms::label) { - nsCOMPtr parent; - aContent->GetParent(getter_AddRefs(parent)); + nsIContent* parent = aContent->GetParent(); if (parent) { - nsCOMPtr grandParent; - parent->GetParent(getter_AddRefs(grandParent)); + nsCOMPtr grandParent = parent->GetParent(); if (grandParent) { PRInt32 index = FindContent(grandParent); if (index >= 0) { @@ -922,7 +915,7 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument, nsCOMPtr element = aContainer; nsCOMPtr parentTag; - while (element) { + for (nsIContent* element = aContainer; element; element = element->GetParent()) { element->GetTag(getter_AddRefs(parentTag)); if ((element->IsContentOfType(nsIContent::eXUL) && parentTag == nsXULAtoms::tree) || (element->IsContentOfType(nsIContent::eHTML) && parentTag == nsHTMLAtoms::select)) @@ -930,14 +923,11 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument, break; else // this is not for us, we can bail out return NS_OK; - nsCOMPtr temp = element; - temp->GetParent(getter_AddRefs(element)); } if (childTag == nsXULAtoms::treeitem || childTag == nsXULAtoms::treeseparator) { - nsCOMPtr parent; - aContainer->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContainer->GetParent(); if (parent) InsertRowFor(parent, aContainer, aChild); } @@ -969,8 +959,7 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument, mBoxObject->InvalidateRow(index); } else if (childTag == nsXULAtoms::treecell) { - nsCOMPtr parent; - aContainer->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContainer->GetParent(); if (parent) { PRInt32 index = FindContent(parent); if (index >= 0) @@ -1023,10 +1012,9 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument, // If we have a legal tag, go up to the tree/select and make sure // that it's ours. - nsCOMPtr element = aContainer; nsCOMPtr parentTag; - while (element) { + for (nsIContent* element = aContainer; element; element = element->GetParent()) { element->GetTag(getter_AddRefs(parentTag)); if ((element->IsContentOfType(nsIContent::eXUL) && parentTag == nsXULAtoms::tree) || (element->IsContentOfType(nsIContent::eHTML) && parentTag == nsHTMLAtoms::select)) @@ -1034,8 +1022,6 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument, break; else // this is not for us, we can bail out return NS_OK; - nsCOMPtr temp = element; - temp->GetParent(getter_AddRefs(element)); } if (tag == nsXULAtoms::treeitem || @@ -1074,8 +1060,7 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument, mBoxObject->InvalidateRow(index); } else if (tag == nsXULAtoms::treecell) { - nsCOMPtr parent; - aContainer->GetParent(getter_AddRefs(parent)); + nsCOMPtr parent = aContainer->GetParent(); if (parent) { PRInt32 index = FindContent(parent); if (index >= 0) diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeSelection.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeSelection.cpp index 80dd3bad437..df8cd82f512 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeSelection.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeSelection.cpp @@ -736,8 +736,7 @@ nsTreeSelection::FireOnSelectHandler() boxObject->GetElement(getter_AddRefs(elt)); nsCOMPtr content(do_QueryInterface(elt)); - nsCOMPtr document; - content->GetDocument(getter_AddRefs(document)); + nsCOMPtr document = content->GetDocument(); // we might be firing on a delay, so it's possible in rare cases that // the document may have been destroyed by the time it fires