diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 4c03f78a03c..887f98b87cf 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -109,6 +109,7 @@ #include "mozAutoDocUpdate.h" #include "nsHTMLFormElement.h" +#include "nsContentCreatorFunctions.h" #include "nsTextEditRules.h" @@ -133,6 +134,7 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #define BF_IN_INTERNAL_ACTIVATE 8 #define BF_CHECKED_IS_TOGGLED 9 #define BF_INDETERMINATE 10 +#define BF_INHIBIT_RESTORATION 11 #define GET_BOOLBIT(bitfield, field) (((bitfield) & (0x01 << (field))) \ ? PR_TRUE : PR_FALSE) @@ -554,6 +556,8 @@ nsHTMLInputElement::nsHTMLInputElement(nsINodeInfo *aNodeInfo, mBitField(0) { SET_BOOLBIT(mBitField, BF_PARSER_CREATING, aFromParser); + SET_BOOLBIT(mBitField, BF_INHIBIT_RESTORATION, + aFromParser & NS_FROM_PARSER_FRAGMENT); mInputData.mState = new nsTextEditorState(this); NS_ADDREF(mInputData.mState); } @@ -2965,7 +2969,10 @@ nsHTMLInputElement::DoneCreatingElement() // Restore state as needed. Note that disabled state applies to all control // types. // - PRBool restoredCheckedState = RestoreFormControlState(this, this); + PRBool restoredCheckedState = + GET_BOOLBIT(mBitField, BF_INHIBIT_RESTORATION) ? + PR_FALSE : + RestoreFormControlState(this, this); // // If restore does not occur, we initialize .checked using the CHECKED diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 00fb98da1ae..0136a915912 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -47,6 +47,7 @@ #include "nsIForm.h" #include "nsFormSubmission.h" #include "nsIFormProcessor.h" +#include "nsContentCreatorFunctions.h" #include "nsIDOMHTMLOptGroupElement.h" #include "nsIOptionElement.h" @@ -140,6 +141,7 @@ nsHTMLSelectElement::nsHTMLSelectElement(nsINodeInfo *aNodeInfo, mIsDoneAddingChildren(!aFromParser), mDisabledChanged(PR_FALSE), mMutating(PR_FALSE), + mInhibitStateRestoration(!!(aFromParser & NS_FROM_PARSER_FRAGMENT)), mNonOptionChildren(0), mOptGroupCount(0), mSelectedIndex(-1) @@ -1353,7 +1355,9 @@ nsHTMLSelectElement::DoneAddingChildren(PRBool aHaveNotified) } // Restore state - RestoreFormControlState(this, this); + if (!mInhibitStateRestoration) { + RestoreFormControlState(this, this); + } // Now that we're done, select something (if it's a single select something // must be selected) diff --git a/content/html/content/src/nsHTMLSelectElement.h b/content/html/content/src/nsHTMLSelectElement.h index 886e999b45e..bb93a3173d7 100644 --- a/content/html/content/src/nsHTMLSelectElement.h +++ b/content/html/content/src/nsHTMLSelectElement.h @@ -491,6 +491,10 @@ protected: * Used by nsSafeOptionListMutation. */ PRPackedBool mMutating; + /** + * True if DoneAddingChildren will get called but shouldn't restore state. + */ + PRPackedBool mInhibitStateRestoration; /** The number of non-options as children of the select */ PRUint32 mNonOptionChildren; /** The number of optgroups anywhere under the select */ diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index 8e105b22a20..ce9eea9de28 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -76,6 +76,7 @@ #include "nsDOMError.h" #include "mozAutoDocUpdate.h" #include "nsISupportsPrimitives.h" +#include "nsContentCreatorFunctions.h" #include "nsTextEditorState.h" @@ -204,6 +205,8 @@ protected: /** Whether or not we are done adding children (always PR_TRUE if not created by a parser */ PRPackedBool mDoneAddingChildren; + /** Whether state restoration should be inhibited in DoneAddingChildren. */ + PRPackedBool mInhibitStateRestoration; /** Whether our disabled state has changed from the default **/ PRPackedBool mDisabledChanged; /** The state of the text editor (selection controller and the editor) **/ @@ -249,6 +252,7 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement(nsINodeInfo *aNodeInfo, mValueChanged(PR_FALSE), mHandlingSelect(PR_FALSE), mDoneAddingChildren(!aFromParser), + mInhibitStateRestoration(!!(aFromParser & NS_FROM_PARSER_FRAGMENT)), mDisabledChanged(PR_FALSE), mState(new nsTextEditorState(this)) { @@ -676,8 +680,9 @@ nsHTMLTextAreaElement::DoneAddingChildren(PRBool aHaveNotified) // sneak some text in without calling AppendChildTo. Reset(); } - - RestoreFormControlState(this, this); + if (!mInhibitStateRestoration) { + RestoreFormControlState(this, this); + } } mDoneAddingChildren = PR_TRUE; diff --git a/parser/htmlparser/tests/mochitest/Makefile.in b/parser/htmlparser/tests/mochitest/Makefile.in index 806e38fb1f1..9bc8270947b 100644 --- a/parser/htmlparser/tests/mochitest/Makefile.in +++ b/parser/htmlparser/tests/mochitest/Makefile.in @@ -59,6 +59,7 @@ _TEST_FILES = parser_datreader.js \ test_bug460437.xhtml \ test_bug502091.html \ bug_502091_iframe.html \ + test_bug566879.html \ test_compatmode.html \ invalidchar.xml \ $(NULL) diff --git a/parser/htmlparser/tests/mochitest/test_bug566879.html b/parser/htmlparser/tests/mochitest/test_bug566879.html new file mode 100644 index 00000000000..dc8d2b1155a --- /dev/null +++ b/parser/htmlparser/tests/mochitest/test_bug566879.html @@ -0,0 +1,60 @@ + + + + + Test for Bug 566879 + + + + + + +Mozilla Bug 566879 +

+ +
+
+
+ + +