diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 4ccf8bf6e4c..866102ddc6d 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -461,28 +461,29 @@ nsWebShell::FireUnloadEvent() { nsresult rv = NS_OK; - if (mScriptGlobal) { - nsIDocumentViewer* docViewer; - if (mContentViewer && NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer))) { - nsIPresContext *presContext; - if (NS_SUCCEEDED(docViewer->GetPresContext(presContext))) { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_UNLOAD; - rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + if (!mFiredUnloadEvent) { + mFiredUnloadEvent = PR_TRUE; - NS_RELEASE(presContext); + if (mScriptGlobal) { + nsIDocumentViewer* docViewer; + if (mContentViewer && NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer))) { + nsIPresContext *presContext; + if (NS_SUCCEEDED(docViewer->GetPresContext(presContext))) { + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_PAGE_UNLOAD; + rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + + NS_RELEASE(presContext); + } + NS_RELEASE(docViewer); } - NS_RELEASE(docViewer); } } - //Fire child unloads now while our data is intact. rv = FireUnloadForChildren(); - mFiredUnloadEvent = PR_TRUE; - return rv; } @@ -1075,25 +1076,13 @@ nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader, { nsresult rv = NS_ERROR_FAILURE; - if(mScriptGlobal && (loader == mDocLoader)) - { - if(mContentViewer) - { - nsCOMPtr presContext; - GetPresContext(getter_AddRefs(presContext)); - if(presContext) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_UNLOAD; - rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - } - } - if(loader == mDocLoader) { + //fire unload event to old doc + rv = FireUnloadEvent(); + //reset mFiredUnloadEvent for the new doc + mFiredUnloadEvent = PR_FALSE; + nsCOMPtr dlObserver; if(!mDocLoaderObserver && mParent) @@ -1588,10 +1577,8 @@ NS_IMETHODIMP nsWebShell::Destroy() { nsresult rv = NS_OK; - if (!mFiredUnloadEvent) { - //Fire unload event before we blow anything away. - rv = FireUnloadEvent(); - } + //Fire unload event before we blow anything away. + rv = FireUnloadEvent(); nsDocShell::Destroy(); diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 17d093cd753..34f0c7d5427 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3596,7 +3596,7 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, nsEventStatus* a nsresult rv; nsIEventStateManager *manager; - if (NS_OK == mPresContext->GetEventStateManager(&manager)) { + if (NS_OK == mPresContext->GetEventStateManager(&manager) && GetCurrentEventFrame()) { //1. Give event to event manager for pre event state changes and generation of synthetic events. rv = manager->PreHandleEvent(mPresContext, aEvent, mCurrentEventFrame, aStatus, aView); diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index e015c1183c2..456b875bd4a 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -322,22 +322,22 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) nsIContent *formContent = nsnull; mFormFrame->GetContent(&formContent); - if (IsReset(type) == PR_TRUE) { - event.message = NS_FORM_RESET; - if (nsnull != formContent) { - formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + if (presShell) { + if (IsReset(type) == PR_TRUE) { + event.message = NS_FORM_RESET; + presShell->HandleEventWithTarget(&event, nsnull, formContent, &status); + if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { + mFormFrame->OnReset(aPresContext); + } } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnReset(aPresContext); - } - } - else if (IsSubmit(type) == PR_TRUE) { - event.message = NS_FORM_SUBMIT; - if (nsnull != formContent) { - formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnSubmit(aPresContext, this); + else if (IsSubmit(type) == PR_TRUE) { + event.message = NS_FORM_SUBMIT; + presShell->HandleEventWithTarget(&event, nsnull, formContent, &status); + if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { + mFormFrame->OnSubmit(aPresContext, this); + } } } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 17d093cd753..34f0c7d5427 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -3596,7 +3596,7 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, nsEventStatus* a nsresult rv; nsIEventStateManager *manager; - if (NS_OK == mPresContext->GetEventStateManager(&manager)) { + if (NS_OK == mPresContext->GetEventStateManager(&manager) && GetCurrentEventFrame()) { //1. Give event to event manager for pre event state changes and generation of synthetic events. rv = manager->PreHandleEvent(mPresContext, aEvent, mCurrentEventFrame, aStatus, aView); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 1b7d032a99e..91a7224152d 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -4234,7 +4234,10 @@ nsEnderEventListener::DispatchMouseEvent(nsIDOMMouseEvent *aEvent, PRInt32 aEven nsCOMPtr esm; pc->GetEventStateManager(getter_AddRefs(esm)); esm->ConsumeFocusEvents(PR_TRUE); - mFrame->SetFocus(); + gfxFrame = mFrame.Reference(); // check for deletion + if (gfxFrame) { + gfxFrame->SetFocus(); + } } } NS_IF_RELEASE(event.widget); diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index e015c1183c2..456b875bd4a 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -322,22 +322,22 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) nsIContent *formContent = nsnull; mFormFrame->GetContent(&formContent); - if (IsReset(type) == PR_TRUE) { - event.message = NS_FORM_RESET; - if (nsnull != formContent) { - formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + if (presShell) { + if (IsReset(type) == PR_TRUE) { + event.message = NS_FORM_RESET; + presShell->HandleEventWithTarget(&event, nsnull, formContent, &status); + if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { + mFormFrame->OnReset(aPresContext); + } } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnReset(aPresContext); - } - } - else if (IsSubmit(type) == PR_TRUE) { - event.message = NS_FORM_SUBMIT; - if (nsnull != formContent) { - formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnSubmit(aPresContext, this); + else if (IsSubmit(type) == PR_TRUE) { + event.message = NS_FORM_SUBMIT; + presShell->HandleEventWithTarget(&event, nsnull, formContent, &status); + if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { + mFormFrame->OnSubmit(aPresContext, this); + } } } diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 4ccf8bf6e4c..866102ddc6d 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -461,28 +461,29 @@ nsWebShell::FireUnloadEvent() { nsresult rv = NS_OK; - if (mScriptGlobal) { - nsIDocumentViewer* docViewer; - if (mContentViewer && NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer))) { - nsIPresContext *presContext; - if (NS_SUCCEEDED(docViewer->GetPresContext(presContext))) { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_UNLOAD; - rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + if (!mFiredUnloadEvent) { + mFiredUnloadEvent = PR_TRUE; - NS_RELEASE(presContext); + if (mScriptGlobal) { + nsIDocumentViewer* docViewer; + if (mContentViewer && NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer))) { + nsIPresContext *presContext; + if (NS_SUCCEEDED(docViewer->GetPresContext(presContext))) { + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_PAGE_UNLOAD; + rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + + NS_RELEASE(presContext); + } + NS_RELEASE(docViewer); } - NS_RELEASE(docViewer); } } - //Fire child unloads now while our data is intact. rv = FireUnloadForChildren(); - mFiredUnloadEvent = PR_TRUE; - return rv; } @@ -1075,25 +1076,13 @@ nsWebShell::OnStartDocumentLoad(nsIDocumentLoader* loader, { nsresult rv = NS_ERROR_FAILURE; - if(mScriptGlobal && (loader == mDocLoader)) - { - if(mContentViewer) - { - nsCOMPtr presContext; - GetPresContext(getter_AddRefs(presContext)); - if(presContext) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_UNLOAD; - rv = mScriptGlobal->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - } - } - if(loader == mDocLoader) { + //fire unload event to old doc + rv = FireUnloadEvent(); + //reset mFiredUnloadEvent for the new doc + mFiredUnloadEvent = PR_FALSE; + nsCOMPtr dlObserver; if(!mDocLoaderObserver && mParent) @@ -1588,10 +1577,8 @@ NS_IMETHODIMP nsWebShell::Destroy() { nsresult rv = NS_OK; - if (!mFiredUnloadEvent) { - //Fire unload event before we blow anything away. - rv = FireUnloadEvent(); - } + //Fire unload event before we blow anything away. + rv = FireUnloadEvent(); nsDocShell::Destroy();