mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
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:
parent
8070d35e33
commit
6784b07eea
@ -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
|
||||
{
|
||||
|
@ -641,6 +641,8 @@ public:
|
||||
static PRBool HasMutationListeners(nsIContent* aContent,
|
||||
PRUint32 aType);
|
||||
|
||||
static PRBool ShouldFocus(nsIContent *aContent);
|
||||
|
||||
static nsresult InitHashes();
|
||||
|
||||
static PLDHashTable sEventListenerManagersHash;
|
||||
|
@ -200,7 +200,9 @@ nsHTMLAnchorElement::Blur()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLAnchorElement::Focus()
|
||||
{
|
||||
SetElementFocus(PR_TRUE);
|
||||
if (ShouldFocus(this)) {
|
||||
SetElementFocus(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -184,7 +184,9 @@ nsHTMLButtonElement::Blur()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonElement::Focus()
|
||||
{
|
||||
SetElementFocus(PR_TRUE);
|
||||
if (ShouldFocus(this)) {
|
||||
SetElementFocus(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1037,7 +1037,9 @@ nsHTMLInputElement::Blur()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::Focus()
|
||||
{
|
||||
SetElementFocus(PR_TRUE);
|
||||
if (ShouldFocus(this)) {
|
||||
SetElementFocus(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1568,7 +1568,9 @@ nsHTMLSelectElement::Blur()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSelectElement::Focus()
|
||||
{
|
||||
SetElementFocus(PR_TRUE);
|
||||
if (ShouldFocus(this)) {
|
||||
SetElementFocus(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -225,7 +225,9 @@ nsHTMLTextAreaElement::Blur()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTextAreaElement::Focus()
|
||||
{
|
||||
SetElementFocus(PR_TRUE);
|
||||
if (ShouldFocus(this)) {
|
||||
SetElementFocus(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user