Bug 389619 - Duplicate frames for content in nested fixed-position divs, when on second page in print-preview, patch by dholbert, r+sr=roc, a=dbaron
authorfantasai.cvs@inkedblade.net
Tue, 07 Aug 2007 16:53:56 -0700
changeset 4366 d98e61bcd3a128d3b51cf4f2b4f9aea0cc04a17c
parent 4365 bd481ad563599e76f9ba3bdd58e32ebf0639b740
child 4367 45c61f5bc283e2492bbf1206e9216cbbf3083093
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs389619
milestone1.9a8pre
Bug 389619 - Duplicate frames for content in nested fixed-position divs, when on second page in print-preview, patch by dholbert, r+sr=roc, a=dbaron
layout/base/nsCSSFrameConstructor.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -10621,37 +10621,46 @@ nsCSSFrameConstructor::ReplicateFixedFra
   // the placeholders must be kids of a block, so we want to move over the
   // placeholders when processing the child of the pageContentFrame.
 
   nsIFrame* prevPageContentFrame = aParentFrame->GetPrevInFlow();
   if (!prevPageContentFrame) {
     return NS_OK;
   }
   nsIFrame* docRootFrame = aParentFrame->GetFirstChild(nsnull);
-  if (!docRootFrame) {
-    // document's root element's frame: don't need a page if there's no content
+  nsIFrame* prevDocRootFrame = prevPageContentFrame->GetFirstChild(nsnull);
+  if (!docRootFrame || !prevDocRootFrame) {
+    // document's root element frame missing
     return NS_ERROR_UNEXPECTED;
   }
 
   nsFrameItems fixedPlaceholders;
   nsIFrame* firstFixed = prevPageContentFrame->GetFirstChild(nsGkAtoms::fixedList);
   if (!firstFixed) {
     return NS_OK;
   }
 
   //XXXbz Should mInitialContainingBlock be docRootFrame? It probably doesn't matter.
   nsFrameConstructorState state(mPresShell, aParentFrame,
                                 mInitialContainingBlock,
                                 mInitialContainingBlock);
-  
-  // Iterate the fixed frames and replicate each
+
+  // Iterate across fixed frames and replicate each whose placeholder is a
+  // descendant of aFrame. (We don't want to explicitly copy placeholders that
+  // are within fixed frames, because that would cause duplicates on the new
+  // page - bug 389619)
   for (nsIFrame* fixed = firstFixed; fixed; fixed = fixed->GetNextSibling()) {
-    nsresult rv = ConstructFrame(state, fixed->GetContent(),
-                                 docRootFrame, fixedPlaceholders);
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsIFrame* prevPlaceholder = nsnull;
+    mPresShell->GetPlaceholderFrameFor(fixed, &prevPlaceholder);
+    if (prevPlaceholder &&
+        nsLayoutUtils::IsProperAncestorFrame(prevDocRootFrame, prevPlaceholder)) {
+      nsresult rv = ConstructFrame(state, fixed->GetContent(),
+                                   docRootFrame, fixedPlaceholders);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
   }
 
   // Add the placeholders to our primary child list.
   // XXXbz this is a little screwed up, since the fixed frames will have the
   // wrong parent block and hence auto-positioning will be broken.  Oh, well.
   NS_ASSERTION(!docRootFrame->GetFirstChild(nsnull),
                "leaking frames; doc root continuation must be empty");
   docRootFrame->SetInitialChildList(nsnull, fixedPlaceholders.childList);