Bug 1249664 - Make stateful frames responsible for their own keys r=dbaron a=ritu
authorChris H-C <chutten@mozilla.com>
Thu, 10 Mar 2016 10:14:37 -0500
changeset 326103 0c124b78808e4f9984509175d0b087150b94eb04
parent 326102 87255dc87819998bf5ef561e855875ccd65a2ca4
child 326104 1276ba0df4ba37dab5e62ff968b8cac1f0d08e13
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron, ritu
bugs1249664
milestone47.0
Bug 1249664 - Make stateful frames responsible for their own keys r=dbaron a=ritu nsFrameManager::CaptureFrameStateFor generates keys for stateful frames that only take into account the document and element. This precluded saving pieces of information coming from different frames responsible for the same element. MozReview-Commit-ID: 29x3Gj66wAy
layout/base/nsFrameManager.cpp
layout/generic/nsIStatefulFrame.h
--- a/layout/base/nsFrameManager.cpp
+++ b/layout/base/nsFrameManager.cpp
@@ -548,17 +548,17 @@ nsFrameManager::CaptureFrameStateFor(nsI
     return;
   }
 
   // Generate the hash key to store the state under
   // Exit early if we get empty key
   nsAutoCString stateKey;
   nsIContent* content = aFrame->GetContent();
   nsIDocument* doc = content ? content->GetCurrentDoc() : nullptr;
-  rv = nsContentUtils::GenerateStateKey(content, doc, stateKey);
+  rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
   if(NS_FAILED(rv) || stateKey.IsEmpty()) {
     return;
   }
 
   // Store the state. aState owns frameState now.
   aState->AddState(stateKey, frameState.forget());
 }
 
@@ -611,17 +611,17 @@ nsFrameManager::RestoreFrameStateFor(nsI
   // If we don't have content, we can't generate a hash
   // key and there's probably no state information for us.
   if (!content) {
     return;
   }
 
   nsAutoCString stateKey;
   nsIDocument* doc = content->GetCurrentDoc();
-  nsresult rv = nsContentUtils::GenerateStateKey(content, doc, stateKey);
+  nsresult rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
   if (NS_FAILED(rv) || stateKey.IsEmpty()) {
     return;
   }
 
   // Get the state from the hash
   nsPresState* frameState = aState->GetState(stateKey);
   if (!frameState) {
     return;
--- a/layout/generic/nsIStatefulFrame.h
+++ b/layout/generic/nsIStatefulFrame.h
@@ -20,11 +20,19 @@ class nsIStatefulFrame
   NS_DECL_QUERYFRAME_TARGET(nsIStatefulFrame)
 
   // Save the state for this frame.  If this method succeeds, the caller is
   // responsible for deleting the resulting state when done with it.
   NS_IMETHOD SaveState(nsPresState** aState) = 0;
 
   // Restore the state for this frame from aState
   NS_IMETHOD RestoreState(nsPresState* aState) = 0;
+
+  // Generate a key for this stateful frame
+  NS_IMETHOD GenerateStateKey(nsIContent* aContent,
+                              nsIDocument* aDocument,
+                              nsACString& aKey)
+  {
+    return nsContentUtils::GenerateStateKey(aContent, aDocument, aKey);
+  };
 };
 
 #endif /* _nsIStatefulFrame_h */