From 77e33872891bee71cd4087ee98fe513c967bad07 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Tue, 14 Sep 2010 20:35:37 +0200 Subject: [PATCH] Bug 592802 - Send change event when is changed even with display:none. r=sicking a2.0=blocking --- .../html/content/src/nsHTMLInputElement.cpp | 40 ++-- content/html/content/test/Makefile.in | 1 + content/html/content/test/test_bug592802.html | 221 ++++++++++++++++++ 3 files changed, 237 insertions(+), 25 deletions(-) create mode 100644 content/html/content/test/test_bug592802.html diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index b2f9d77b9ea..66e83c4b5b8 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -307,10 +307,8 @@ AsyncClickHandler::Run() if (!filePicker) return NS_ERROR_FAILURE; - nsFileControlFrame* frame = static_cast(mInput->GetPrimaryFrame()); - nsTextControlFrame* textFrame = nsnull; - if (frame) - textFrame = static_cast(frame->GetTextFrame()); + nsFileControlFrame* frame = + static_cast(mInput->GetPrimaryFrame()); PRBool multi; rv = mInput->GetMultiple(&multi); @@ -384,17 +382,14 @@ AsyncClickHandler::Run() filePicker->SetDisplayDirectory(localFile); } - // Tell our textframe to remember the currently focused value - if (textFrame) - textFrame->InitFocusedValue(); - // Open dialog PRInt16 mode; rv = filePicker->Show(&mode); NS_ENSURE_SUCCESS(rv, rv); - if (mode == nsIFilePicker::returnCancel) + if (mode == nsIFilePicker::returnCancel) { return NS_OK; - + } + // Collect new selected filenames nsCOMArray newFiles; if (multi) { @@ -404,7 +399,9 @@ AsyncClickHandler::Run() nsCOMPtr tmp; PRBool prefSaved = PR_FALSE; - while (NS_SUCCEEDED(iter->GetNext(getter_AddRefs(tmp)))) { + PRBool loop = PR_TRUE; + while (NS_SUCCEEDED(iter->HasMoreElements(&loop)) && loop) { + iter->GetNext(getter_AddRefs(tmp)); nsCOMPtr localFile = do_QueryInterface(tmp); if (localFile) { nsString unicodePath; @@ -444,21 +441,14 @@ AsyncClickHandler::Run() // Set new selected files if (newFiles.Count()) { - // Tell mTextFrame that this update of the value is a user initiated - // change. Otherwise it'll think that the value is being set by a script - // and not fire onchange when it should. - PRBool oldState; - if (textFrame) { - oldState = textFrame->GetFireChangeEventState(); - textFrame->SetFireChangeEventState(PR_TRUE); - } - + // The text control frame (if there is one) isn't going to send a change + // event because it will think this is done by a script. + // So, we can safely send one by ourself. mInput->SetFiles(newFiles); - if (textFrame) { - textFrame->SetFireChangeEventState(oldState); - // May need to fire an onchange here - textFrame->CheckFireOnChange(); - } + nsContentUtils::DispatchTrustedEvent(mInput->GetOwnerDoc(), + static_cast(mInput.get()), + NS_LITERAL_STRING("change"), PR_FALSE, + PR_FALSE); } return NS_OK; diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 33054a39454..25bf642f15f 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -223,6 +223,7 @@ _TEST_FILES = \ test_bug590363.html \ test_bug557628-1.html \ test_bug557628-2.html \ + test_bug592802.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/html/content/test/test_bug592802.html b/content/html/content/test/test_bug592802.html new file mode 100644 index 00000000000..e9812ab429d --- /dev/null +++ b/content/html/content/test/test_bug592802.html @@ -0,0 +1,221 @@ + + + + + Test for Bug 592802 + + + + + + +Mozilla Bug 592802 +

+
+ + +
+ + +
+
+
+ +