375196, r+sr=roc
authorOlli.Pettay@helsinki.fi
Sun, 25 Mar 2007 22:38:22 -0700
changeset 95 404d9269e106dca81ba3908a15c44da382565383
parent 94 cb128bc30b60c4dbb4ae2c33ec765fb214853684
child 96 b18f0a86184149f45a3cc4bb4314cb4b779ee6bd
push idunknown
push userunknown
push dateunknown
bugs375196
milestone1.9a4pre
375196, r+sr=roc
content/base/src/nsGenericElement.cpp
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/xml/document/src/nsXMLContentSink.cpp
layout/base/nsIPresShell.h
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsListControlFrame.cpp
layout/forms/nsTextControlFrame.cpp
layout/xul/base/src/nsButtonBoxFrame.cpp
layout/xul/base/src/nsMenuFrame.cpp
layout/xul/base/src/nsPopupSetFrame.cpp
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -2435,17 +2435,17 @@ nsGenericElement::DispatchEvent(nsPresCo
   NS_PRECONDITION(aTarget, "Must have target");
   NS_PRECONDITION(aEvent, "Must have source event");
   NS_PRECONDITION(aStatus, "Null out param?");
 
   if (!aPresContext) {
     return NS_OK;
   }
 
-  nsIPresShell *shell = aPresContext->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
   if (!shell) {
     return NS_OK;
   }
 
   if (aFullDispatch) {
     return shell->HandleEventWithTarget(aEvent, nsnull, aTarget, aStatus);
   }
 
@@ -3877,17 +3877,17 @@ nsGenericElement::PostHandleEventForLink
     if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) {
       nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, aVisitor.mEvent);
       if (inputEvent->isControl || inputEvent->isMeta ||
           inputEvent->isAlt ||inputEvent->isShift) {
         break;
       }
 
       // The default action is simply to dispatch DOMActivate
-      nsIPresShell *shell = aVisitor.mPresContext->GetPresShell();
+      nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
       if (shell) {
         // single-click
         nsEventStatus status = nsEventStatus_eIgnore;
         nsUIEvent actEvent(NS_IS_TRUSTED_EVENT(aVisitor.mEvent),
                            NS_UI_ACTIVATE, 1);
 
         rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
       }
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -374,17 +374,18 @@ nsHTMLButtonElement::PostHandleEvent(nsE
                                         &status);
           }
         }
         break;// NS_KEY_PRESS
 
       case NS_MOUSE_CLICK:
         {
           if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) {
-            nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell();
+            nsCOMPtr<nsIPresShell> presShell =
+              aVisitor.mPresContext->GetPresShell();
             if (presShell) {
               // single-click
               nsUIEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent),
                               NS_UI_ACTIVATE, 1);
               nsEventStatus status = nsEventStatus_eIgnore;
   
               presShell->HandleDOMEventWithTarget(this, &event, &status);
               aVisitor.mEventStatus = status;
@@ -398,17 +399,18 @@ nsHTMLButtonElement::PostHandleEvent(nsE
           if (mForm && (mType == NS_FORM_BUTTON_SUBMIT ||
                         mType == NS_FORM_BUTTON_RESET)) {
             nsFormEvent event(PR_TRUE,
                               (mType == NS_FORM_BUTTON_RESET)
                               ? NS_FORM_RESET : NS_FORM_SUBMIT);
             event.originator      = this;
             nsEventStatus status  = nsEventStatus_eIgnore;
 
-            nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell();
+            nsCOMPtr<nsIPresShell> presShell =
+              aVisitor.mPresContext->GetPresShell();
             // If |nsIPresShell::Destroy| has been called due to
             // handling the event, the pres context will return
             // a null pres shell.  See bug 125624.
             //
             // Using presShell to dispatch the event. It makes sure that
             // event is not handled if the window is being destroyed.
             if (presShell) {
               nsCOMPtr<nsIContent> form(do_QueryInterface(mForm));
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -1040,17 +1040,17 @@ nsHTMLInputElement::GetRadioGroupContain
 nsresult
 nsHTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext)
 {
   if (!mForm) {
     // Nothing to do here.
     return NS_OK;
   }
   
-  nsIPresShell* shell = aPresContext->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
   if (!shell) {
     return NS_OK;
   }
 
   // Get the default submit element
   nsIFormControl* submitControl = mForm->GetDefaultSubmitElement();
   if (submitControl) {
     nsCOMPtr<nsIContent> submitContent(do_QueryInterface(submitControl));
@@ -1497,17 +1497,17 @@ nsHTMLInputElement::PostHandleEvent(nsEv
   // when space is pressed.  So, we just nest the firing of DOMActivate inside
   // the click event handling, and allow cancellation of DOMActivate to cancel
   // the click.
   if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault &&
       mType != NS_FORM_INPUT_TEXT &&
       NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) {
     nsUIEvent actEvent(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), NS_UI_ACTIVATE, 1);
 
-    nsIPresShell *shell = aVisitor.mPresContext->GetPresShell();
+    nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
     if (shell) {
       nsEventStatus status = nsEventStatus_eIgnore;
       SET_BOOLBIT(mBitField, BF_IN_INTERNAL_ACTIVATE, PR_TRUE);
       rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
       SET_BOOLBIT(mBitField, BF_IN_INTERNAL_ACTIVATE, PR_FALSE);
 
       // If activate is cancelled, we must do the same as when click is
       // cancelled (revert the checkbox to its original value).
@@ -1765,17 +1765,18 @@ nsHTMLInputElement::PostHandleEvent(nsEv
         case NS_FORM_INPUT_SUBMIT:
         case NS_FORM_INPUT_IMAGE:
           if (mForm) {
             nsFormEvent event(PR_TRUE, (mType == NS_FORM_INPUT_RESET) ?
                               NS_FORM_RESET : NS_FORM_SUBMIT);
             event.originator      = this;
             nsEventStatus status  = nsEventStatus_eIgnore;
 
-            nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell();
+            nsCOMPtr<nsIPresShell> presShell =
+              aVisitor.mPresContext->GetPresShell();
 
             // If |nsIPresShell::Destroy| has been called due to
             // handling the event the pres context will return a null
             // pres shell.  See bug 125624.
             if (presShell) {
               nsCOMPtr<nsIContent> form(do_QueryInterface(mForm));
               presShell->HandleDOMEventWithTarget(form, &event, &status);
             }
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -1006,17 +1006,17 @@ nsSVGSVGElement::SetCurrentScaleTranslat
   SetCurrentScale(s);  // clamps! don't call mCurrentScale->SetValue() directly
   mCurrentTranslate->SetX(x);
   mCurrentTranslate->SetY(y);
   mDispatchEvent = PR_TRUE;
 
   // now dispatch an SVGZoom event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
     NS_ASSERTION(presShell, "no presShell");
     if (presShell &&
         doc->GetRootContent() == NS_STATIC_CAST(nsIContent*, this)) {
       nsEventStatus status = nsEventStatus_eIgnore;
       nsGUIEvent event(PR_TRUE, NS_SVG_ZOOM, 0);
       event.eventStructType = NS_SVGZOOM_EVENT;
       presShell->HandleDOMEventWithTarget(this, &event, &status);
     }
@@ -1031,17 +1031,17 @@ nsSVGSVGElement::SetCurrentTranslate(flo
   mDispatchEvent = PR_FALSE;
   mCurrentTranslate->SetX(x);
   mCurrentTranslate->SetY(y);
   mDispatchEvent = PR_TRUE;
 
   // now dispatch an SVGScroll event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
     NS_ASSERTION(presShell, "no presShell");
     if (presShell &&
         doc->GetRootContent() == NS_STATIC_CAST(nsIContent*, this)) {
       nsEventStatus status = nsEventStatus_eIgnore;
       nsEvent event(PR_TRUE, NS_SVG_SCROLL);
       event.eventStructType = NS_SVG_EVENT;
       presShell->HandleDOMEventWithTarget(this, &event, &status);
     }
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -1109,17 +1109,17 @@ nsXMLContentSink::HandleEndElement(const
   DidAddContent();
 
 #ifdef MOZ_SVG
   if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
       content->HasAttr(kNameSpaceID_None, nsGkAtoms::onload)) {
     nsEventStatus status = nsEventStatus_eIgnore;
     nsEvent event(PR_TRUE, NS_SVG_LOAD);
     event.eventStructType = NS_SVG_EVENT;
-    nsIPresShell *presShell = mDocument->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = mDocument->GetShellAt(0);
     if (presShell) {
       FlushTags();
       presShell->HandleDOMEventWithTarget(content, &event, &status);
     }
   }
 #endif
 
   return NS_SUCCEEDED(result) ? DidProcessATokenImpl() : result;
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -509,24 +509,26 @@ public:
     *           else NS_OK
     */
   NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnabled) = 0;
   
   virtual nsISelection* GetCurrentSelection(SelectionType aType) = 0;
 
   /**
     * Interface to dispatch events via the presshell
+    * @note The caller must have a strong reference to the PresShell.
     */
   NS_IMETHOD HandleEventWithTarget(nsEvent* aEvent,
                                    nsIFrame* aFrame,
                                    nsIContent* aContent,
                                    nsEventStatus* aStatus) = 0;
 
   /**
    * Dispatch event to content only (NOT full processing)
+   * @note The caller must have a strong reference to the PresShell.
    */
   NS_IMETHOD HandleDOMEventWithTarget(nsIContent* aTargetContent,
                                       nsEvent* aEvent,
                                       nsEventStatus* aStatus) = 0;
 
   /**
     * Gets the current target event frame from the PresShell
     */
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -389,17 +389,17 @@ nsComboboxControlFrame::ShowPopup(PRBool
   }
 
   // fire a popup dom event
   nsEventStatus status = nsEventStatus_eIgnore;
   nsMouseEvent event(PR_TRUE, aShowPopup ?
                      NS_XUL_POPUP_SHOWING : NS_XUL_POPUP_HIDING, nsnull,
                      nsMouseEvent::eReal);
 
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) 
     shell->HandleDOMEventWithTarget(mContent, &event, &status);
 }
 
 // Show the dropdown list
 
 void 
 nsComboboxControlFrame::ShowList(nsPresContext* aPresContext, PRBool aShowList)
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1653,17 +1653,17 @@ nsListControlFrame::FireOnChange()
     if (index == GetSelectedIndex())
       return;
   }
 
   // Dispatch the NS_FORM_CHANGE event
   nsEventStatus status = nsEventStatus_eIgnore;
   nsEvent event(PR_TRUE, NS_FORM_CHANGE);
 
-  nsIPresShell *presShell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> presShell = GetPresContext()->GetPresShell();
   if (presShell) {
     presShell->HandleEventWithTarget(&event, this, nsnull, &status);
   }
 }
 
 //---------------------------------------------------------
 // Determine if the specified item in the listbox is selected.
 NS_IMETHODIMP
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -300,17 +300,17 @@ nsTextInputListener::NotifySelectionChan
                                 nsISelectionListener::SELECTALL_REASON)))
   {
     nsIContent* content = mFrame->GetContent();
     if (content) 
     {
       nsCOMPtr<nsIDocument> doc = content->GetDocument();
       if (doc) 
       {
-        nsIPresShell *presShell = doc->GetShellAt(0);
+        nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
         if (presShell) 
         {
           nsEventStatus status = nsEventStatus_eIgnore;
           nsEvent event(PR_TRUE, NS_FORM_SELECTED);
 
           presShell->HandleEventWithTarget(&event, mFrame, content, &status);
         }
       }
@@ -2462,18 +2462,18 @@ nsTextControlFrame::FireOnInput()
     return; // if notification is turned off, do nothing
   
   // Dispatch the "input" event
   nsEventStatus status = nsEventStatus_eIgnore;
   nsUIEvent event(PR_TRUE, NS_FORM_INPUT, 0);
 
   // Have the content handle the event, propagating it according to normal
   // DOM rules.
-  GetPresContext()->PresShell()->HandleEventWithTarget(&event, nsnull, mContent,
-                                                       &status); 
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->PresShell();
+  shell->HandleEventWithTarget(&event, nsnull, mContent, &status);
 }
 
 nsresult
 nsTextControlFrame::InitFocusedValue()
 {
   return GetText(&mFocusedValue);
 }
 
@@ -2483,19 +2483,18 @@ nsTextControlFrame::CheckFireOnChange()
   nsString value;
   GetText(&value);
   if (!mFocusedValue.Equals(value))
   {
     mFocusedValue = value;
     // Dispatch the change event
     nsEventStatus status = nsEventStatus_eIgnore;
     nsInputEvent event(PR_TRUE, NS_FORM_CHANGE, nsnull);
-
-    GetPresContext()->PresShell()->HandleEventWithTarget(&event, nsnull,
-                                                         mContent, &status);
+    nsCOMPtr<nsIPresShell> shell = GetPresContext()->PresShell();
+    shell->HandleEventWithTarget(&event, nsnull, mContent, &status);
   }
   return NS_OK;
 }
 
 //======
 //privates
 
 NS_IMETHODIMP
--- a/layout/xul/base/src/nsButtonBoxFrame.cpp
+++ b/layout/xul/base/src/nsButtonBoxFrame.cpp
@@ -150,14 +150,13 @@ nsButtonBoxFrame::DoMouseClick(nsGUIEven
   if(aEvent) {
     event.isShift = ((nsInputEvent*)(aEvent))->isShift;
     event.isControl = ((nsInputEvent*)(aEvent))->isControl;
     event.isAlt = ((nsInputEvent*)(aEvent))->isAlt;
     event.isMeta = ((nsInputEvent*)(aEvent))->isMeta;
   }
 
   // Have the content handle the event, propagating it according to normal DOM rules.
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) {
     shell->HandleDOMEventWithTarget(mContent, &event, &status);
-    // shell may no longer be alive, don't use it here unless you keep a ref
   }
 }
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -1721,25 +1721,24 @@ nsMenuFrame::OnCreate()
   nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull,
                      nsMouseEvent::eReal);
 
   nsCOMPtr<nsIContent> child;
   GetMenuChildrenElement(getter_AddRefs(child));
   
   nsresult rv = NS_OK;
 
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) {
     if (child) {
       rv = shell->HandleDOMEventWithTarget(child, &event, &status);
     }
     else {
       rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
     }
-    // shell may no longer be alive, don't use it here unless you keep a ref
   }
 
   if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
     return PR_FALSE;
 
   // The menu is going to show, and the create handler has executed.
   // We should now walk all of our menu item children, checking to see if any
   // of them has a command attribute.  If so, then several attributes must
@@ -1795,25 +1794,24 @@ nsMenuFrame::OnCreated()
   nsEventStatus status = nsEventStatus_eIgnore;
   nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull,
                      nsMouseEvent::eReal);
 
   nsCOMPtr<nsIContent> child;
   GetMenuChildrenElement(getter_AddRefs(child));
   
   nsresult rv = NS_OK;
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) {
     if (child) {
       rv = shell->HandleDOMEventWithTarget(child, &event, &status);
     }
     else {
       rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
     }
-    // shell may no longer be alive, don't use it here unless you keep a ref
   }
 
   if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
     return PR_FALSE;
   return PR_TRUE;
 }
 
 PRBool
@@ -1822,25 +1820,24 @@ nsMenuFrame::OnDestroy()
   nsEventStatus status = nsEventStatus_eIgnore;
   nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull,
                      nsMouseEvent::eReal);
 
   nsCOMPtr<nsIContent> child;
   GetMenuChildrenElement(getter_AddRefs(child));
   
   nsresult rv = NS_OK;
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) {
     if (child) {
       rv = shell->HandleDOMEventWithTarget(child, &event, &status);
     }
     else {
       rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
     }
-    // shell may no longer be alive, don't use it here unless you keep a ref
   }
 
   if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
     return PR_FALSE;
   return PR_TRUE;
 }
 
 PRBool
@@ -1849,25 +1846,24 @@ nsMenuFrame::OnDestroyed()
   nsEventStatus status = nsEventStatus_eIgnore;
   nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull,
                      nsMouseEvent::eReal);
 
   nsCOMPtr<nsIContent> child;
   GetMenuChildrenElement(getter_AddRefs(child));
   
   nsresult rv = NS_OK;
-  nsIPresShell *shell = GetPresContext()->GetPresShell();
+  nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
   if (shell) {
     if (child) {
       rv = shell->HandleDOMEventWithTarget(child, &event, &status);
     }
     else {
       rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
     }
-    // shell may no longer be alive, don't use it here unless you keep a ref
   }
 
   if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
     return PR_FALSE;
   return PR_TRUE;
 }
 
 NS_IMETHODIMP
--- a/layout/xul/base/src/nsPopupSetFrame.cpp
+++ b/layout/xul/base/src/nsPopupSetFrame.cpp
@@ -640,21 +640,20 @@ nsPopupSetFrame::OnCreate(PRInt32 aX, PR
   // XXX This is messed up: it needs to account for widgets.
   nsPoint dummy;
   event.widget = GetClosestView()->GetNearestWidget(&dummy);
   event.refPoint.x = aX;
   event.refPoint.y = aY;
 
   if (aPopupContent) {
     nsCOMPtr<nsIContent> kungFuDeathGrip(aPopupContent);
-    nsIPresShell *shell = GetPresContext()->GetPresShell();
+    nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
     if (shell) {
       nsresult rv = shell->HandleDOMEventWithTarget(aPopupContent, &event,
                                                     &status);
-      // shell may no longer be alive, don't use it here unless you keep a ref
       if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
         return PR_FALSE;
     }
 
     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aPopupContent->GetDocument()));
     if (!domDoc) return PR_FALSE;
 
     // The menu is going to show, and the create handler has executed.
@@ -709,21 +708,20 @@ nsPopupSetFrame::OnCreated(PRInt32 aX, P
   nsEventStatus status = nsEventStatus_eIgnore;
   nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull,
                      nsMouseEvent::eReal);
   // XXX See OnCreate above
   //event.point.x = aX;
   //event.point.y = aY;
 
   if (aPopupContent) {
-    nsIPresShell *shell = GetPresContext()->GetPresShell();
+    nsCOMPtr<nsIPresShell> shell = GetPresContext()->GetPresShell();
     if (shell) {
       nsresult rv = shell->HandleDOMEventWithTarget(aPopupContent, &event,
                                                     &status);
-      // shell may no longer be alive, don't use it here unless you keep a ref
       if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
         return PR_FALSE;
     }
   }
 
   return PR_TRUE;
 }