Bug 58250 -- this fixes a situation where getting a NS_GOTFOCUS before the

matching NS_DEACTIVATE would fire a blur on the wrong
content/window/document, leaving it in a fairly broken focus state.
r=saari, sr=hyatt, a=tor.
This commit is contained in:
bryner%uiuc.edu 2001-06-18 07:34:41 +00:00
parent 5825708ad5
commit b6c0c5ec57

View File

@ -371,8 +371,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
EnsureDocument(aPresContext);
if (gLastFocusedDocument == mDocument)
break;
break;
//fire focus
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent focusevent;
@ -402,7 +402,9 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
}
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
if (!mCurrentFocus && gLastFocusedContent) {// must send it to the element that is loosing focus. since SendFocusBlur wont be called
if (!mCurrentFocus && gLastFocusedContent) {
// must send it to the element that is losing focus,
// since SendFocusBlur wont be called
gLastFocusedContent->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
nsCOMPtr<nsIDocument> doc;
@ -620,22 +622,12 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
{
EnsureDocument(aPresContext);
// We can get a deactivate on an Ender widget. In this
// case, we would like to obtain the DOM Window to start
// with by looking at gLastFocusedContent.
if (gLastFocusedDocument != mDocument)
break;
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
if (gLastFocusedContent) {
nsCOMPtr<nsIDocument> doc;
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
if(doc)
doc->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
else {
mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
NS_RELEASE(gLastFocusedContent);
}
}
else mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
// Suppress the command dispatcher for the duration of the
// de-activation. This will cause it to remember the last
// focused sub-window and sub-element for this top-level
@ -654,29 +646,24 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
// Now fire blurs. We have to fire a blur on the focused window
// and on the focused element if there is one.
if (gLastFocusedDocument && gLastFocusedPresContext) {
// Blur the element.
if (gLastFocusedContent) {
// Retrieve this content node's pres context. it can be out of sync in
// the Ender widget case.
nsCOMPtr<nsIDocument> doc;
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(0));
if (shell) {
nsCOMPtr<nsIPresContext> oldPresContext;
shell->GetPresContext(getter_AddRefs(oldPresContext));
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_BLUR_CONTENT;
nsCOMPtr<nsIEventStateManager> esm;
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
esm->SetFocusedContent(gLastFocusedContent);
gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
esm->SetFocusedContent(nsnull);
NS_IF_RELEASE(gLastFocusedContent);
}
// Blur the element.
nsCOMPtr<nsIPresShell> shell =
getter_AddRefs(gLastFocusedDocument->GetShellAt(0));
if (shell) {
nsCOMPtr<nsIPresContext> oldPresContext;
shell->GetPresContext(getter_AddRefs(oldPresContext));
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_BLUR_CONTENT;
nsCOMPtr<nsIEventStateManager> esm;
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
esm->SetFocusedContent(gLastFocusedContent);
gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
esm->SetFocusedContent(nsnull);
NS_IF_RELEASE(gLastFocusedContent);
}
}
@ -686,13 +673,10 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
event.message = NS_BLUR_CONTENT;
// fire blur on document and window
nsCOMPtr<nsIScriptGlobalObject> globalObject;
if(gLastFocusedDocument) {
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
if(globalObject)
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
if (ourGlobal)
ourGlobal->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
// Now clear our our global variables
mCurrentTarget = nsnull;
NS_IF_RELEASE(gLastFocusedDocument);