Bug 323805, tab switching not working when for non-html and non-xul elements are focused, r=neil,sr=bz

This commit is contained in:
enndeakin@sympatico.ca 2007-07-12 15:57:17 -07:00
Родитель 1ecdaf63fa
Коммит d5d0ef3e21
3 изменённых файлов: 61 добавлений и 3 удалений

Просмотреть файл

@ -45,7 +45,9 @@
* getInterface on a DOMWindow.
*/
[scriptable, uuid(76cdfff8-6f13-43e8-9ed4-36066cd83742)]
interface nsIDOMElement;
[scriptable, uuid(1F313394-73AB-41BF-8307-9FC5DA8A481E)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -126,4 +128,13 @@ interface nsIDOMWindowUtils : nsISupports {
in long aKeyCode,
in long aCharCode,
in long aModifiers);
/**
* Focus the element aElement. The element should be in the same document
* that the window is displaying. Pass null to blur the element, if any,
* that currently has focus, and focus the document.
*
* @param aElement the element to focus
*/
void focus(in nsIDOMElement aElement);
};

Просмотреть файл

@ -45,6 +45,7 @@
#include "nsGlobalWindow.h"
#include "nsIDocument.h"
#include "nsIFocusController.h"
#include "nsIEventStateManager.h"
#include "nsContentUtils.h"
@ -270,3 +271,32 @@ nsDOMWindowUtils::GetWidget()
return nsnull;
}
NS_IMETHODIMP
nsDOMWindowUtils::Focus(nsIDOMElement* aElement)
{
if (mWindow) {
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (content) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
if (!doc || content->GetCurrentDoc() != doc)
return NS_ERROR_FAILURE;
}
nsIDocShell *docShell = mWindow->GetDocShell();
if (docShell) {
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
if (presShell) {
nsPresContext *pc = presShell->GetPresContext();
if (pc) {
pc->EventStateManager()->ChangeFocusWith(content,
nsIEventStateManager::eEventFocusedByApplication);
}
}
}
}
return NS_OK;
}

Просмотреть файл

@ -695,7 +695,15 @@
// Clear focus outline before we draw on top of it.
// Only blur the focused element if it isn't a tab,
// to avoid breaking keyboard tab navigation
this.mCurrentBrowser.focusedElement.blur();
var elem = this.mCurrentBrowser.focusedElement;
if (elem instanceof HTMLElement || elem instanceof XULElement) {
elem.blur();
}
else {
var content = elem.ownerDocument.defaultView;
if (content instanceof Components.interfaces.nsIInterfaceRequestor)
content.getInterface(Components.interfaces.nsIDOMWindowUtils).focus(null);
}
}
this.mCurrentBrowser.setAttribute("type", "content-targetable");
}
@ -801,7 +809,16 @@
.getService(Components.interfaces.nsIWindowWatcher);
if (ww.activeWindow == window) {
cmdDispatcher.suppressFocusScroll = true;
if (whatToFocus instanceof HTMLElement ||
whatToFocus instanceof XULElement ||
whatToFocus instanceof Window) {
whatToFocus.focus();
}
else if (whatToFocus instanceof Node) {
var content = window.content;
if (content instanceof Components.interfaces.nsIInterfaceRequestor)
content.getInterface(Components.interfaces.nsIDOMWindowUtils).focus(whatToFocus);
}
cmdDispatcher.suppressFocusScroll = false;
}
else {