From 885859c9d192ba4e802e0fa7a163a8d1090f4ead Mon Sep 17 00:00:00 2001 From: "mats.palmgren@bredband.net" Date: Fri, 16 Nov 2007 16:30:53 -0800 Subject: [PATCH] Add a flag to protect SetFocus() from recursive calls on the same element. b=401160 r+sr=peterv a=mtschrep --- .../html/content/src/nsHTMLLabelElement.cpp | 14 ++++++---- .../html/content/src/nsHTMLLegendElement.cpp | 8 +++++- content/html/content/test/Makefile.in | 1 + .../html/content/test/test_bug401160.xhtml | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 content/html/content/test/test_bug401160.xhtml diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp index ba4c0e6241e3..654a95860ce9 100644 --- a/content/html/content/src/nsHTMLLabelElement.cpp +++ b/content/html/content/src/nsHTMLLabelElement.cpp @@ -111,7 +111,8 @@ protected: already_AddRefed 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 content = GetForContent(); if (content) content->SetFocus(aContext); + mInSetFocus = PR_FALSE; } nsresult diff --git a/content/html/content/src/nsHTMLLegendElement.cpp b/content/html/content/src/nsHTMLLegendElement.cpp index 99f94ad72e10..252f5493e850 100644 --- a/content/html/content/src/nsHTMLLegendElement.cpp +++ b/content/html/content/src/nsHTMLLegendElement.cpp @@ -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 diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 8bd976d5b950..377bb3a1ec78 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -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) diff --git a/content/html/content/test/test_bug401160.xhtml b/content/html/content/test/test_bug401160.xhtml new file mode 100644 index 000000000000..d4a15a49a33c --- /dev/null +++ b/content/html/content/test/test_bug401160.xhtml @@ -0,0 +1,28 @@ + + + + Test for Bug 401160 + + + + + +Mozilla Bug 401160 + + +
+
+
+ +