From 4d09fabceecbf164a18a783ea7ccbdec18f6d55d Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Thu, 21 Oct 2010 19:58:11 -0500 Subject: [PATCH] Bug 605741. Only send state change notifications when we actually change state for textareas and inputs. f=volkmar r=jst a=dbaron --- .../html/content/src/nsHTMLInputElement.cpp | 3 ++- .../content/src/nsHTMLTextAreaElement.cpp | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index b626f8109f8..aee46bd28b4 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -3868,12 +3868,13 @@ nsHTMLInputElement::UpdatePatternMismatchValidityState() void nsHTMLInputElement::UpdateAllValidityStates(PRBool aNotify) { + PRBool validBefore = IsValid(); UpdateTooLongValidityState(); UpdateValueMissingValidityState(); UpdateTypeMismatchValidityState(); UpdatePatternMismatchValidityState(); - if (aNotify) { + if (validBefore != IsValid() && aNotify) { nsIDocument* doc = GetCurrentDoc(); if (doc) { MOZ_AUTO_DOC_UPDATE(doc, UPDATE_CONTENT_STATE, PR_TRUE); diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index 6f5c5d08fe9..4058c592e78 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -1386,20 +1386,27 @@ NS_IMETHODIMP_(void) nsHTMLTextAreaElement::OnValueChanged(PRBool aNotify) { // Update the validity state + PRBool validBefore = IsValid(); UpdateTooLongValidityState(); UpdateValueMissingValidityState(); if (aNotify) { - nsIDocument* doc = GetCurrentDoc(); - if (doc) { - MOZ_AUTO_DOC_UPDATE(doc, UPDATE_CONTENT_STATE, PR_TRUE); - doc->ContentStatesChanged(this, nsnull, NS_EVENT_STATE_VALID | - NS_EVENT_STATE_INVALID | - // We could check if that is - // really needed but considering - // we are already updating the - // state for valid/invalid... - NS_EVENT_STATE_MOZ_PLACEHOLDER); + nsEventStates states; + if (validBefore != IsValid()) { + states |= (NS_EVENT_STATE_VALID | NS_EVENT_STATE_INVALID); + } + + if (HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) + && !nsContentUtils::IsFocusedContent((nsIContent*)(this))) { + states |= NS_EVENT_STATE_MOZ_PLACEHOLDER; + } + + if (!states.IsEmpty()) { + nsIDocument* doc = GetCurrentDoc(); + if (doc) { + MOZ_AUTO_DOC_UPDATE(doc, UPDATE_CONTENT_STATE, PR_TRUE); + doc->ContentStatesChanged(this, nsnull, states); + } } } }