Add a flag to protect SetFocus() from recursive calls on the same element. b=401160 r+sr=peterv a=mtschrep

This commit is contained in:
mats.palmgren@bredband.net 2007-11-16 16:30:53 -08:00
Родитель 316c205d89
Коммит 885859c9d1
4 изменённых файлов: 45 добавлений и 6 удалений

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

@ -111,7 +111,8 @@ protected:
already_AddRefed<nsIContent> GetFirstFormControl(nsIContent *current);
// XXX It would be nice if we could use an event flag instead.
PRBool mHandlingEvent;
PRPackedBool mHandlingEvent;
PRPackedBool mInSetFocus;
};
// construction, destruction
@ -121,8 +122,9 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Label)
nsHTMLLabelElement::nsHTMLLabelElement(nsINodeInfo *aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo),
mHandlingEvent(PR_FALSE)
: nsGenericHTMLFormElement(aNodeInfo)
, mHandlingEvent(PR_FALSE)
, mInSetFocus(PR_FALSE)
{
}
@ -269,11 +271,13 @@ nsHTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
void
nsHTMLLabelElement::SetFocus(nsPresContext* aContext)
{
// Since we don't have '-moz-user-focus: normal', the only time
// |SetFocus| will be called is when the accesskey is activated.
if (mInSetFocus)
return;
mInSetFocus = PR_TRUE;
nsCOMPtr<nsIContent> content = GetForContent();
if (content)
content->SetFocus(aContext);
mInSetFocus = PR_FALSE;
}
nsresult

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

@ -103,6 +103,9 @@ public:
PRBool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
PRPackedBool mInSetFocus;
};
@ -111,6 +114,7 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
nsHTMLLegendElement::nsHTMLLegendElement(nsINodeInfo *aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo)
, mInSetFocus(PR_FALSE)
{
}
@ -252,10 +256,11 @@ void
nsHTMLLegendElement::SetFocus(nsPresContext* aPresContext)
{
nsIDocument *document = GetCurrentDoc();
if (!aPresContext || !document) {
if (!aPresContext || !document || mInSetFocus) {
return;
}
mInSetFocus = PR_TRUE;
if (IsFocusable()) {
nsGenericHTMLFormElement::SetFocus(aPresContext);
} else {
@ -272,6 +277,7 @@ nsHTMLLegendElement::SetFocus(nsPresContext* aPresContext)
}
}
}
mInSetFocus = PR_FALSE;
}
NS_IMETHODIMP

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

@ -101,6 +101,7 @@ _TEST_FILES = test_bug589.html \
test_bug391994.html \
test_bug392567.html \
test_bug394700.html \
test_bug401160.xhtml \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,28 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=401160
-->
<head>
<title>Test for Bug 401160</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=401160">Mozilla Bug 401160</a>
<label id="label" contenteditable="true"><legend></legend><div></div></label>
<pre id="test">
<script type="text/javascript">
function do_test() {
document.getElementById('label').focus();
ok(true, "This is crash test - the test succeeded if we reach this line")
}
do_test();
</script>
</pre>
</body>
</html>