if(!mDOMDocument) { executingKeyBind = PR_FALSE; return ret; }   nsCOMPtr<nsIDOMNode> target = nsnull; aKeyEvent->GetTarget(getter_AddRefs(target));
executingKeyBind = PR_TRUE;  if (!aKeyEvent) { executingKeyBind = PR_FALSE; return ret; }  if (!mDOMDocument) { executingKeyBind = PR_FALSE; return ret; }   nsCOMPtr<nsIDOMNode> target = nsnull; aKeyEvent->GetTarget(getter_AddRefs(target));
nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventType){	static PRBool executingKeyBind = PR_FALSE;	nsresult ret = NS_OK;		if(executingKeyBind)		return NS_OK;	else 		executingKeyBind = PR_TRUE;	if(!aKeyEvent) {		executingKeyBind = PR_FALSE;		return ret;	}	if(!mDOMDocument) {		executingKeyBind = PR_FALSE;		return ret;	}  	// Get DOMEvent target	nsCOMPtr<nsIDOMNode> target = nsnull;	aKeyEvent->GetTarget(getter_AddRefs(target));  nsCOMPtr<nsPIDOMWindow> piWindow;	nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);	// Find a keyset node  // Get the current focused object from the command dispatcher  nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;  mDOMDocument->GetCommandDispatcher(getter_AddRefs(commandDispatcher));  nsCOMPtr<nsIDOMElement> focusedElement;  commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement));  nsCOMPtr<nsIDOMWindow> domWindow;  commandDispatcher->GetFocusedWindow(getter_AddRefs(domWindow));  piWindow = do_QueryInterface(domWindow);  nsCAutoString keyFile, platformKeyFile;  if (focusedElement) {    // See if it's a textarea or input field.    // XXX Check to see if the "key-bindings" CSS property points us to a file.    // Hopefully we can get Pierre to add this. ;)        nsAutoString tagName;    focusedElement->GetTagName(tagName);    if (tagName.EqualsIgnoreCase("input")) {      nsAutoString type;      focusedElement->GetAttribute(nsAutoString("type"), type);      if (type == "" || type.EqualsIgnoreCase("text") ||          type.EqualsIgnoreCase("password")) {        keyFile = "chrome://global/content/inputBindings.xul";        platformKeyFile = "chrome://global/content/platformInputBindings.xul";      }    }    else if (tagName.EqualsIgnoreCase("textarea")) {      keyFile = "chrome://global/content/textAreaBindings.xul";      platformKeyFile = "chrome://global/content/platformTextAreaBindings.xul";    }  }     nsCOMPtr<nsIDOMXULDocument> document;  GetKeyBindingDocument(platformKeyFile, getter_AddRefs(document));    // Locate the key node and execute the JS on a match.  PRBool handled = PR_FALSE;  if (document) // Local focused ELEMENT handling stage.    LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled);	  if (!handled) {    GetKeyBindingDocument(keyFile, getter_AddRefs(document));    if (document) // Local focused ELEMENT handling stage.    LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled);  }    nsCAutoString browserFile = "chrome://global/content/browserBindings.xul";  nsCAutoString editorFile = "chrome://global/content/editorBindings.xul";  nsCAutoString browserPlatformFile = "chrome://global/content/platformBrowserBindings.xul";  nsCAutoString editorPlatformFile = "chrome://global/content/platformEditorBindings.xul";  nsresult result;  if (!handled) {    while (piWindow && !handled) {      // See if we have a XUL document. Give it a crack.      nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(piWindow);      nsCOMPtr<nsIDOMDocument> windowDoc;      domWindow->GetDocument(getter_AddRefs(windowDoc));      nsCOMPtr<nsIDOMXULDocument> xulWindowDoc = do_QueryInterface(windowDoc);      if (xulWindowDoc) {        // Give the local key bindings in this XUL file a shot.        LocateAndExecuteKeyBinding(keyEvent, aEventType, xulWindowDoc, handled);      }      if (!handled) {        // Give the DOM window's associated key binding doc a shot.        // XXX Check to see if we're in edit mode (how??!)        nsCOMPtr<nsIWebShell> webShell;        nsCOMPtr<nsIPresShell> presShell;        result = piWindow->GetWebShell(getter_AddRefs(webShell));        nsCOMPtr<nsIContentViewer> cv;        webShell->GetContentViewer(getter_AddRefs(cv));        if (nsnull != cv)         {          nsCOMPtr<nsIDocumentViewer> docv;          cv->QueryInterface(nsIDocumentViewer::GetIID(), getter_AddRefs(docv));          if (nsnull != docv)           {            nsCOMPtr<nsIPresContext> cx;            docv->GetPresContext(*getter_AddRefs(cx));	          if (nsnull != cx)             {	            result = cx->GetShell(getter_AddRefs(presShell));	          }          }        }        PRBool editorHasBindings = PR_FALSE;        nsCOMPtr<nsIDOMXULDocument> platformDoc;        if (presShell)        {          PRBool isEditor;          if (NS_SUCCEEDED(presShell->GetDisplayNonTextSelection(&isEditor)) && isEditor)          {            editorHasBindings = PR_TRUE;            GetKeyBindingDocument(editorPlatformFile, getter_AddRefs(platformDoc));            GetKeyBindingDocument(editorFile, getter_AddRefs(document));          }        }        if (!editorHasBindings) {          GetKeyBindingDocument(browserPlatformFile, getter_AddRefs(platformDoc));          GetKeyBindingDocument(browserFile, getter_AddRefs(document));        }        if (platformDoc)          LocateAndExecuteKeyBinding(keyEvent, aEventType, platformDoc, handled);        if (!handled && document)          LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled);      }      // Move up to the parent DOM window. Need to use the private API      // to cross sandboxes      nsCOMPtr<nsPIDOMWindow> piParent;      piWindow->GetPrivateParent(getter_AddRefs(piParent));      piWindow = piParent;    }  }  executingKeyBind = PR_FALSE;	return ret;}