зеркало из https://github.com/mozilla/gecko-dev.git
Landing focus memory. If you pull before saari completes this checkin (we
still have to land nsWebShellWindow and nsGlobalWindow), you will not like the result. r=saari
This commit is contained in:
Родитель
8558ec21de
Коммит
34cd127797
|
@ -50,6 +50,7 @@
|
||||||
#include "nsISelfScrollingFrame.h"
|
#include "nsISelfScrollingFrame.h"
|
||||||
#include "nsIPrivateDOMEvent.h"
|
#include "nsIPrivateDOMEvent.h"
|
||||||
#include "nsIGfxTextControlFrame.h"
|
#include "nsIGfxTextControlFrame.h"
|
||||||
|
#include "nsIDOMWindow.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
|
@ -58,6 +59,8 @@
|
||||||
#include "nsISessionHistory.h"
|
#include "nsISessionHistory.h"
|
||||||
|
|
||||||
#include "nsXULAtoms.h"
|
#include "nsXULAtoms.h"
|
||||||
|
#include "nsIDOMXULDocument.h"
|
||||||
|
#include "nsIDOMXULCommandDispatcher.h"
|
||||||
|
|
||||||
#undef DEBUG_scroll // define to see ugly mousewheel messages
|
#undef DEBUG_scroll // define to see ugly mousewheel messages
|
||||||
#undef GFXSCROLL_IS_PRIMARY // define this when the code is enabled to make
|
#undef GFXSCROLL_IS_PRIMARY // define this when the code is enabled to make
|
||||||
|
@ -425,6 +428,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
break;
|
break;
|
||||||
case NS_GOTFOCUS:
|
case NS_GOTFOCUS:
|
||||||
{
|
{
|
||||||
|
printf("Got focus.\n");
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
|
|
||||||
|
@ -466,6 +471,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
|
|
||||||
case NS_LOSTFOCUS:
|
case NS_LOSTFOCUS:
|
||||||
{
|
{
|
||||||
|
printf("Lost focus.\n");
|
||||||
|
|
||||||
// Hold the blur, wait for the focus so we can query the style of the focus
|
// Hold the blur, wait for the focus so we can query the style of the focus
|
||||||
// target as to what to do with the event. If appropriate we fire the blur
|
// target as to what to do with the event. If appropriate we fire the blur
|
||||||
// at that time.
|
// at that time.
|
||||||
|
@ -474,25 +481,9 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
|
|
||||||
case NS_ACTIVATE:
|
case NS_ACTIVATE:
|
||||||
{
|
{
|
||||||
nsIContent* newFocus;
|
// If we have a command dispatcher, and if it has a focused window and a
|
||||||
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, &newFocus);
|
// focused element in its focus memory, then restore the focus to those
|
||||||
if (newFocus) {
|
// objects.
|
||||||
nsIFocusableContent *focusChange;
|
|
||||||
if (NS_SUCCEEDED(newFocus->QueryInterface(NS_GET_IID(nsIFocusableContent),
|
|
||||||
(void **)&focusChange))) {
|
|
||||||
NS_RELEASE(focusChange);
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
}
|
|
||||||
|
|
||||||
//fire focus
|
|
||||||
nsEventStatus status = nsEventStatus_eIgnore;
|
|
||||||
nsEvent focusevent;
|
|
||||||
focusevent.eventStructType = NS_EVENT;
|
|
||||||
focusevent.message = NS_FOCUS_CONTENT;
|
|
||||||
|
|
||||||
if (!mDocument) {
|
if (!mDocument) {
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
|
@ -501,65 +492,139 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDocument) {
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
||||||
// NS_IF_RELEASE(gLastFocusedContent);
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||||
// mCurrentTarget->GetContent(&gLastFocusedContent);
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
||||||
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(mDocument);
|
||||||
mCurrentTarget = nsnull;
|
if (xulDoc) {
|
||||||
|
// See if we have a command dispatcher attached.
|
||||||
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
||||||
|
if (commandDispatcher) {
|
||||||
|
// Obtain focus info from the command dispatcher.
|
||||||
|
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
||||||
|
commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fire focus on window, not document
|
if (!focusedWindow) {
|
||||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||||
mDocument->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
focusedWindow = do_QueryInterface(globalObject);
|
||||||
if(!globalObject) break;
|
|
||||||
|
|
||||||
globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Focus the DOM window.
|
||||||
|
focusedWindow->Focus();
|
||||||
|
|
||||||
|
if (focusedElement) {
|
||||||
|
// Focus the content node.
|
||||||
|
nsCOMPtr<nsIFocusableContent> focusContent = do_QueryInterface(focusedElement);
|
||||||
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||||
|
nsCOMPtr<nsIDocument> document;
|
||||||
|
focusedWindow->GetDocument(getter_AddRefs(domDoc));
|
||||||
|
document = do_QueryInterface(domDoc);
|
||||||
|
nsCOMPtr<nsIPresShell> shell;
|
||||||
|
nsCOMPtr<nsIPresContext> context;
|
||||||
|
shell = getter_AddRefs(document->GetShellAt(0));
|
||||||
|
shell->GetPresContext(getter_AddRefs(context));
|
||||||
|
focusContent->SetFocus(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandDispatcher)
|
||||||
|
commandDispatcher->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again.
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NS_DEACTIVATE:
|
case NS_DEACTIVATE:
|
||||||
{
|
{
|
||||||
nsIContent* newFocus;
|
if (!mDocument) {
|
||||||
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, &newFocus);
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
if (newFocus) {
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
nsIFocusableContent *focusChange;
|
if (presShell) {
|
||||||
if (NS_SUCCEEDED(newFocus->QueryInterface(NS_GET_IID(nsIFocusableContent),
|
presShell->GetDocument(&mDocument);
|
||||||
(void **)&focusChange))) {
|
|
||||||
NS_RELEASE(focusChange);
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fire blur
|
|
||||||
nsEventStatus status = nsEventStatus_eIgnore;
|
|
||||||
nsEvent event;
|
|
||||||
event.eventStructType = NS_EVENT;
|
|
||||||
event.message = NS_BLUR_CONTENT;
|
|
||||||
|
|
||||||
if (!mDocument) {
|
// We can get a deactivate on an Ender widget. In this
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
// case, we would like to obtain the DOM Window to start
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
// with by looking at gLastFocusedContent.
|
||||||
if (presShell) {
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
||||||
presShell->GetDocument(&mDocument);
|
if (gLastFocusedContent) {
|
||||||
}
|
nsCOMPtr<nsIDocument> doc;
|
||||||
}
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
||||||
|
doc->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
||||||
if (mDocument) {
|
}
|
||||||
mCurrentTarget = nsnull;
|
else 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
|
||||||
|
// window.
|
||||||
|
nsCOMPtr<nsIDOMWindow> rootWindow;
|
||||||
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
||||||
|
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
|
||||||
|
nsCOMPtr<nsIDOMDocument> rootDocument;
|
||||||
|
rootWindow->GetDocument(getter_AddRefs(rootDocument));
|
||||||
|
|
||||||
// fire focus on window, not document
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
||||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(rootDocument);
|
||||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
if (xulDoc) {
|
||||||
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
// See if we have a command dispatcher attached.
|
||||||
if(!globalObject) break;
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
||||||
|
if (commandDispatcher) {
|
||||||
globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
// Suppress the command dispatcher.
|
||||||
}
|
commandDispatcher->SetSuppressFocus(PR_TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
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_RELEASE(gLastFocusedContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
|
nsEvent event;
|
||||||
|
event.eventStructType = NS_EVENT;
|
||||||
|
event.message = NS_BLUR_CONTENT;
|
||||||
|
|
||||||
|
// fire blur on document and window
|
||||||
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||||
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||||
|
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
|
if(!globalObject) break;
|
||||||
|
|
||||||
|
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
|
mCurrentTarget = nsnull;
|
||||||
|
|
||||||
|
// Now clear our our global variables
|
||||||
|
NS_RELEASE(gLastFocusedDocument);
|
||||||
|
gLastFocusedPresContext = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandDispatcher)
|
||||||
|
commandDispatcher->SetSuppressFocus(PR_FALSE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "nsISelfScrollingFrame.h"
|
#include "nsISelfScrollingFrame.h"
|
||||||
#include "nsIPrivateDOMEvent.h"
|
#include "nsIPrivateDOMEvent.h"
|
||||||
#include "nsIGfxTextControlFrame.h"
|
#include "nsIGfxTextControlFrame.h"
|
||||||
|
#include "nsIDOMWindow.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
|
@ -58,6 +59,8 @@
|
||||||
#include "nsISessionHistory.h"
|
#include "nsISessionHistory.h"
|
||||||
|
|
||||||
#include "nsXULAtoms.h"
|
#include "nsXULAtoms.h"
|
||||||
|
#include "nsIDOMXULDocument.h"
|
||||||
|
#include "nsIDOMXULCommandDispatcher.h"
|
||||||
|
|
||||||
#undef DEBUG_scroll // define to see ugly mousewheel messages
|
#undef DEBUG_scroll // define to see ugly mousewheel messages
|
||||||
#undef GFXSCROLL_IS_PRIMARY // define this when the code is enabled to make
|
#undef GFXSCROLL_IS_PRIMARY // define this when the code is enabled to make
|
||||||
|
@ -425,6 +428,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
break;
|
break;
|
||||||
case NS_GOTFOCUS:
|
case NS_GOTFOCUS:
|
||||||
{
|
{
|
||||||
|
printf("Got focus.\n");
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
|
|
||||||
|
@ -466,6 +471,8 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
|
|
||||||
case NS_LOSTFOCUS:
|
case NS_LOSTFOCUS:
|
||||||
{
|
{
|
||||||
|
printf("Lost focus.\n");
|
||||||
|
|
||||||
// Hold the blur, wait for the focus so we can query the style of the focus
|
// Hold the blur, wait for the focus so we can query the style of the focus
|
||||||
// target as to what to do with the event. If appropriate we fire the blur
|
// target as to what to do with the event. If appropriate we fire the blur
|
||||||
// at that time.
|
// at that time.
|
||||||
|
@ -474,25 +481,9 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
|
|
||||||
case NS_ACTIVATE:
|
case NS_ACTIVATE:
|
||||||
{
|
{
|
||||||
nsIContent* newFocus;
|
// If we have a command dispatcher, and if it has a focused window and a
|
||||||
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, &newFocus);
|
// focused element in its focus memory, then restore the focus to those
|
||||||
if (newFocus) {
|
// objects.
|
||||||
nsIFocusableContent *focusChange;
|
|
||||||
if (NS_SUCCEEDED(newFocus->QueryInterface(NS_GET_IID(nsIFocusableContent),
|
|
||||||
(void **)&focusChange))) {
|
|
||||||
NS_RELEASE(focusChange);
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
}
|
|
||||||
|
|
||||||
//fire focus
|
|
||||||
nsEventStatus status = nsEventStatus_eIgnore;
|
|
||||||
nsEvent focusevent;
|
|
||||||
focusevent.eventStructType = NS_EVENT;
|
|
||||||
focusevent.message = NS_FOCUS_CONTENT;
|
|
||||||
|
|
||||||
if (!mDocument) {
|
if (!mDocument) {
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
|
@ -501,65 +492,139 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDocument) {
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
||||||
// NS_IF_RELEASE(gLastFocusedContent);
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||||
// mCurrentTarget->GetContent(&gLastFocusedContent);
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
||||||
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(mDocument);
|
||||||
mCurrentTarget = nsnull;
|
if (xulDoc) {
|
||||||
|
// See if we have a command dispatcher attached.
|
||||||
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
||||||
|
if (commandDispatcher) {
|
||||||
|
// Obtain focus info from the command dispatcher.
|
||||||
|
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
||||||
|
commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fire focus on window, not document
|
if (!focusedWindow) {
|
||||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||||
mDocument->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
focusedWindow = do_QueryInterface(globalObject);
|
||||||
if(!globalObject) break;
|
|
||||||
|
|
||||||
globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Focus the DOM window.
|
||||||
|
focusedWindow->Focus();
|
||||||
|
|
||||||
|
if (focusedElement) {
|
||||||
|
// Focus the content node.
|
||||||
|
nsCOMPtr<nsIFocusableContent> focusContent = do_QueryInterface(focusedElement);
|
||||||
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||||
|
nsCOMPtr<nsIDocument> document;
|
||||||
|
focusedWindow->GetDocument(getter_AddRefs(domDoc));
|
||||||
|
document = do_QueryInterface(domDoc);
|
||||||
|
nsCOMPtr<nsIPresShell> shell;
|
||||||
|
nsCOMPtr<nsIPresContext> context;
|
||||||
|
shell = getter_AddRefs(document->GetShellAt(0));
|
||||||
|
shell->GetPresContext(getter_AddRefs(context));
|
||||||
|
focusContent->SetFocus(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandDispatcher)
|
||||||
|
commandDispatcher->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again.
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NS_DEACTIVATE:
|
case NS_DEACTIVATE:
|
||||||
{
|
{
|
||||||
nsIContent* newFocus;
|
if (!mDocument) {
|
||||||
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, &newFocus);
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
if (newFocus) {
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||||
nsIFocusableContent *focusChange;
|
if (presShell) {
|
||||||
if (NS_SUCCEEDED(newFocus->QueryInterface(NS_GET_IID(nsIFocusableContent),
|
presShell->GetDocument(&mDocument);
|
||||||
(void **)&focusChange))) {
|
|
||||||
NS_RELEASE(focusChange);
|
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
NS_RELEASE(newFocus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fire blur
|
|
||||||
nsEventStatus status = nsEventStatus_eIgnore;
|
|
||||||
nsEvent event;
|
|
||||||
event.eventStructType = NS_EVENT;
|
|
||||||
event.message = NS_BLUR_CONTENT;
|
|
||||||
|
|
||||||
if (!mDocument) {
|
// We can get a deactivate on an Ender widget. In this
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
// case, we would like to obtain the DOM Window to start
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
// with by looking at gLastFocusedContent.
|
||||||
if (presShell) {
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
||||||
presShell->GetDocument(&mDocument);
|
if (gLastFocusedContent) {
|
||||||
}
|
nsCOMPtr<nsIDocument> doc;
|
||||||
}
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
||||||
|
doc->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
||||||
if (mDocument) {
|
}
|
||||||
mCurrentTarget = nsnull;
|
else 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
|
||||||
|
// window.
|
||||||
|
nsCOMPtr<nsIDOMWindow> rootWindow;
|
||||||
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
||||||
|
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
|
||||||
|
nsCOMPtr<nsIDOMDocument> rootDocument;
|
||||||
|
rootWindow->GetDocument(getter_AddRefs(rootDocument));
|
||||||
|
|
||||||
// fire focus on window, not document
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
||||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(rootDocument);
|
||||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
if (xulDoc) {
|
||||||
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
// See if we have a command dispatcher attached.
|
||||||
if(!globalObject) break;
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
||||||
|
if (commandDispatcher) {
|
||||||
globalObject->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
// Suppress the command dispatcher.
|
||||||
}
|
commandDispatcher->SetSuppressFocus(PR_TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
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_RELEASE(gLastFocusedContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
|
nsEvent event;
|
||||||
|
event.eventStructType = NS_EVENT;
|
||||||
|
event.message = NS_BLUR_CONTENT;
|
||||||
|
|
||||||
|
// fire blur on document and window
|
||||||
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||||
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||||
|
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
|
if(!globalObject) break;
|
||||||
|
|
||||||
|
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
|
mCurrentTarget = nsnull;
|
||||||
|
|
||||||
|
// Now clear our our global variables
|
||||||
|
NS_RELEASE(gLastFocusedDocument);
|
||||||
|
gLastFocusedPresContext = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandDispatcher)
|
||||||
|
commandDispatcher->SetSuppressFocus(PR_FALSE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче