Landing workaround for bug 124750. Don't let DOM calls focus elements in hidden tabs. r+sr=bryner@brianryner.com

This commit is contained in:
jst%mozilla.jstenback.com 2004-11-04 01:24:05 +00:00
parent 8070d35e33
commit 6784b07eea
8 changed files with 52 additions and 5 deletions

View File

@ -96,6 +96,9 @@
#include "nsIServiceManager.h"
#include "nsIDOMEventListener.h"
#include "nsIWebNavigation.h"
#include "nsIBaseWindow.h"
#include "jsapi.h"
#include "nsIDOMXPathEvaluator.h"
@ -2422,6 +2425,34 @@ nsGenericElement::SetFocus(nsPresContext* aPresContext)
}
}
// static
PRBool
nsGenericElement::ShouldFocus(nsIContent *aContent)
{
PRBool visible = PR_TRUE;
// Figure out if we're focusing an element in an inactive (hidden)
// tab (whose docshell is not visible), if so, drop this focus
// request on the floor
nsIDocument *document = aContent->GetDocument();
if (document) {
nsIScriptGlobalObject *sgo = document->GetScriptGlobalObject();
if (sgo) {
nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(sgo));
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(webNav));
if (baseWin) {
baseWin->GetVisibility(&visible);
}
}
}
return visible;
}
nsIContent*
nsGenericElement::GetBindingParent() const
{

View File

@ -641,6 +641,8 @@ public:
static PRBool HasMutationListeners(nsIContent* aContent,
PRUint32 aType);
static PRBool ShouldFocus(nsIContent *aContent);
static nsresult InitHashes();
static PLDHashTable sEventListenerManagersHash;

View File

@ -200,7 +200,9 @@ nsHTMLAnchorElement::Blur()
NS_IMETHODIMP
nsHTMLAnchorElement::Focus()
{
SetElementFocus(PR_TRUE);
if (ShouldFocus(this)) {
SetElementFocus(PR_TRUE);
}
return NS_OK;
}

View File

@ -184,7 +184,9 @@ nsHTMLButtonElement::Blur()
NS_IMETHODIMP
nsHTMLButtonElement::Focus()
{
SetElementFocus(PR_TRUE);
if (ShouldFocus(this)) {
SetElementFocus(PR_TRUE);
}
return NS_OK;
}

View File

@ -1037,7 +1037,9 @@ nsHTMLInputElement::Blur()
NS_IMETHODIMP
nsHTMLInputElement::Focus()
{
SetElementFocus(PR_TRUE);
if (ShouldFocus(this)) {
SetElementFocus(PR_TRUE);
}
return NS_OK;
}

View File

@ -1568,7 +1568,9 @@ nsHTMLSelectElement::Blur()
NS_IMETHODIMP
nsHTMLSelectElement::Focus()
{
SetElementFocus(PR_TRUE);
if (ShouldFocus(this)) {
SetElementFocus(PR_TRUE);
}
return NS_OK;
}

View File

@ -225,7 +225,9 @@ nsHTMLTextAreaElement::Blur()
NS_IMETHODIMP
nsHTMLTextAreaElement::Focus()
{
SetElementFocus(PR_TRUE);
if (ShouldFocus(this)) {
SetElementFocus(PR_TRUE);
}
return NS_OK;
}

View File

@ -3749,6 +3749,10 @@ nsXULElement::IsAncestor(nsIDOMNode* aParentNode, nsIDOMNode* aChildNode)
NS_IMETHODIMP
nsXULElement::Focus()
{
if (!nsGenericElement::ShouldFocus(this)) {
return NS_OK;
}
// What kind of crazy tries to focus an element without a doc?
if (!mDocument)
return NS_OK;