Bug 639733 - Include the tag name in the frame state key. r=bzbarsky
authorMats Palmgren <matspal@gmail.com>
Wed, 06 Apr 2011 13:32:31 +0200
changeset 67570 1652e3d8dc1cb5661678028b70457745016f2657
parent 67569 80dc22b6c3f66118de8e16ed6e65cc8302a2c10b
child 67571 77ce8faa1906878b676a1a018feeceaf45f0b497
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs639733
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 639733 - Include the tag name in the frame state key. r=bzbarsky
content/base/src/nsContentUtils.cpp
layout/forms/nsIsIndexFrame.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -2133,21 +2133,27 @@ nsContentUtils::GenerateStateKey(nsICont
       nsAutoString name;
       aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
       KeyAppendString(name, aKey);
     }
   }
 
   if (!generatedUniqueKey) {
     // Either we didn't have a form control or we aren't in an HTML document so
-    // we can't figure out form info.  First append a character that is not "d"
-    // or "f" to disambiguate from the case when we were a form control in an
-    // HTML document.
-    KeyAppendString(NS_LITERAL_CSTRING("o"), aKey);
-    
+    // we can't figure out form info.  Append the tag name if it's an element
+    // to avoid restoring state for one type of element on another type.
+    if (aContent->IsElement()) {
+      KeyAppendString(nsDependentAtomString(aContent->Tag()), aKey);
+    }
+    else {
+      // Append a character that is not "d" or "f" to disambiguate from
+      // the case when we were a form control in an HTML document.
+      KeyAppendString(NS_LITERAL_CSTRING("o"), aKey);
+    }
+
     // Now start at aContent and append the indices of it and all its ancestors
     // in their containers.  That should at least pin down its position in the
     // DOM...
     nsINode* parent = aContent->GetNodeParent();
     nsINode* content = aContent;
     while (parent) {
       KeyAppendInt(parent->IndexOf(content), aKey);
       content = parent;
--- a/layout/forms/nsIsIndexFrame.cpp
+++ b/layout/forms/nsIsIndexFrame.cpp
@@ -522,21 +522,22 @@ nsIsIndexFrame::URLEncode(const nsString
 //----------------------------------------------------------------------
 // nsIStatefulFrame
 //----------------------------------------------------------------------
 NS_IMETHODIMP
 nsIsIndexFrame::SaveState(SpecialStateID aStateID, nsPresState** aState)
 {
   NS_ENSURE_ARG_POINTER(aState);
 
+  *aState = nsnull;
+
   // Get the value string
   nsAutoString stateString;
   GetInputValue(stateString);
 
-  nsresult res = NS_OK;
   if (! stateString.IsEmpty()) {
 
     // Construct a pres state and store value in it.
     *aState = new nsPresState();
     if (!*aState)
       return NS_ERROR_OUT_OF_MEMORY;
 
     nsCOMPtr<nsISupportsString> state
@@ -544,26 +545,31 @@ nsIsIndexFrame::SaveState(SpecialStateID
 
     if (!state)
       return NS_ERROR_OUT_OF_MEMORY;
 
     state->SetData(stateString);
     (*aState)->SetStateProperty(state);
   }
 
-  return res;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsIsIndexFrame::RestoreState(nsPresState* aState)
 {
   NS_ENSURE_ARG_POINTER(aState);
 
   // Set the value to the stored state.
   nsCOMPtr<nsISupportsString> stateString
     (do_QueryInterface(aState->GetStateProperty()));
-  
+
+  if (!stateString) {
+    NS_ERROR("Not a <isindex> state!");
+    return NS_ERROR_FAILURE;
+  }
+
   nsAutoString data;
   stateString->GetData(data);
   SetInputValue(data);
 
   return NS_OK;
 }