Bug 612128 - Part 2: Set the editable flag on the entire subtree rooted at the anonymous content for those nodes which need it; r=roc a=bz
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 22 Nov 2010 03:13:37 -0500
changeset 58926 3aaa0ec60f8fda0bd9671d3f5e8fbaeb7f1f08ee
parent 58925 7cd873b260dafe8797fc094dc4cfa9ae4e74988a
child 58927 2d6180a57f657e9217f70ffe95cd5b19d6cdbbf4
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersroc, bz
bugs612128
milestone2.0b8pre
Bug 612128 - Part 2: Set the editable flag on the entire subtree rooted at the anonymous content for those nodes which need it; r=roc a=bz
layout/base/nsCSSFrameConstructor.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -3922,16 +3922,31 @@ nsCSSFrameConstructor::CreateAnonymousFr
       // create the frame and attach it to our frame
       ConstructFrame(aState, content, aParentFrame, aChildItems);
     }
   }
 
   return NS_OK;
 }
 
+static void
+SetFlagsOnSubtree(nsIContent *aNode, PtrBits aFlagsToSet)
+{
+  // Set the flag on the node itself
+  aNode->SetFlags(aFlagsToSet);
+
+  // Set the flag on all of its children recursively
+  PRUint32 count;
+  nsIContent * const *children = aNode->GetChildArray(&count);
+
+  for (PRUint32 index = 0; index < count; ++index) {
+    SetFlagsOnSubtree(children[index], aFlagsToSet);
+  }
+}
+
 nsresult
 nsCSSFrameConstructor::GetAnonymousContent(nsIContent* aParent,
                                            nsIFrame* aParentFrame,
                                            nsTArray<nsIContent*>& aContent)
 {
   nsIAnonymousContentCreator* creator = do_QueryFrame(aParentFrame);
   if (!creator)
     return NS_OK;
@@ -3956,18 +3971,20 @@ nsCSSFrameConstructor::GetAnonymousConte
     {
       content->SetNativeAnonymous();
     }
 
     PRBool anonContentIsEditable = content->HasFlag(NODE_IS_EDITABLE);
     rv = content->BindToTree(mDocument, aParent, aParent, PR_TRUE);
     // If the anonymous content creator requested that the content should be
     // editable, honor its request.
+    // We need to set the flag on the whole subtree, because existing
+    // children's flags have already been set as part of the BindToTree operation.
     if (anonContentIsEditable) {
-      content->SetFlags(NODE_IS_EDITABLE);
+      SetFlagsOnSubtree(content, NODE_IS_EDITABLE);
     }
     if (NS_FAILED(rv)) {
       content->UnbindFromTree();
       return rv;
     }
   }
 
   return NS_OK;