Bug 880854. Part 2: Support reflows/frame reconstruction in print/print-preview documents by promoting them to frame reconstruction of the whole document. r=mats

--HG--
extra : rebase_source : e81c5cd0f9da7bbcd876669c4b9de46dac825a5d
This commit is contained in:
Robert O'Callahan 2013-06-18 23:41:30 +12:00
parent 46c791393d
commit 3fc13110af
5 changed files with 51 additions and 2 deletions

View File

@ -94,6 +94,7 @@
#include "nsTransitionManager.h"
#include "nsSVGIntegrationUtils.h"
#include "nsViewportFrame.h"
#include "nsPageContentFrame.h"
#include <algorithm>
#ifdef MOZ_XUL
@ -1422,6 +1423,7 @@ nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument *aDocument,
, mHasRootAbsPosContainingBlock(false)
, mObservingRefreshDriver(false)
, mInStyleRefresh(false)
, mPromoteReflowsToReframeRoot(false)
, mHoverGeneration(0)
, mRebuildAllExtraHint(nsChangeHint(0))
, mAnimationGeneration(0)
@ -8060,6 +8062,17 @@ NeedToReframeForAddingOrRemovingTransform(nsIFrame* aFrame)
return false;
}
static nsIFrame*
FindReflowRootFor(nsIFrame* aFrame)
{
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
if (f->GetStateBits() & NS_FRAME_REFLOW_ROOT) {
return f;
}
}
return nullptr;
}
nsresult
nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList& aChangeList)
{
@ -8119,6 +8132,21 @@ nsCSSFrameConstructor::ProcessRestyledFrames(nsStyleChangeList& aChangeList)
}
}
if (mPromoteReflowsToReframeRoot &&
(hint & (nsChangeHint_ReconstructFrame | nsChangeHint_NeedReflow))) {
nsIFrame* reflowRoot = FindReflowRootFor(frame);
if (!reflowRoot) {
// Reflow root is the viewport. Better reframe the document.
// We don't do this for elements which are inside a reflow root --- they
// should be OK.
nsIContent* root = mDocument->GetRootElement();
if (root) {
NS_UpdateHint(hint, nsChangeHint_ReconstructFrame);
content = root;
}
}
}
if ((hint & nsChangeHint_AddOrRemoveTransform) && frame &&
!(hint & nsChangeHint_ReconstructFrame)) {
if (NeedToReframeForAddingOrRemovingTransform(frame)) {
@ -12115,6 +12143,7 @@ nsCSSFrameConstructor::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
mRebuildAllStyleData = true;
NS_UpdateHint(mRebuildAllExtraHint, aExtraHint);
// Get a restyle event posted if necessary
PostRestyleEventInternal(false);
}

View File

@ -19,7 +19,6 @@
#include "nsCounterManager.h"
#include "nsHashKeys.h"
#include "nsThreadUtils.h"
#include "nsPageContentFrame.h"
#include "nsCSSPseudoElements.h"
#include "RestyleTracker.h"
#include "nsIAnonymousContentCreator.h"
@ -383,6 +382,8 @@ public:
nsIFrame* GetDocElementContainingBlock()
{ return mDocElementContainingBlock; }
void SetPromoteReflowsToReframeRoot(bool aPromote) { mPromoteReflowsToReframeRoot = aPromote; }
private:
struct FrameConstructionItem;
class FrameConstructionItemList;
@ -1885,6 +1886,8 @@ private:
bool mObservingRefreshDriver : 1;
// True if we're in the middle of a nsRefreshDriver refresh
bool mInStyleRefresh : 1;
// True if reflows/frame reconstruction should be promoted to reframe the root element
bool mPromoteReflowsToReframeRoot : 1;
uint32_t mHoverGeneration;
nsChangeHint mRebuildAllExtraHint;

View File

@ -114,6 +114,7 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewerPrint.h"
#include "nsCSSFrameConstructor.h"
#include "nsFocusManager.h"
#include "nsRange.h"
@ -1778,13 +1779,14 @@ nsPrintEngine::SetupToPrintContent()
if (didReconstruction) {
FirePrintPreviewUpdateEvent();
}
DUMP_DOC_LIST(("\nAfter Reflow------------------------------------------"));
PR_PL(("\n"));
PR_PL(("-------------------------------------------------------\n"));
PR_PL(("\n"));
CalcNumPrintablePages(mPrt->mNumPrintablePages);
PromoteReflowsToReframeRoot();
PR_PL(("--- Printing %d pages\n", mPrt->mNumPrintablePages));
DUMP_DOC_TREELAYOUT;
@ -2349,6 +2351,19 @@ nsPrintEngine::CalcNumPrintablePages(int32_t& aNumPages)
}
}
}
void
nsPrintEngine::PromoteReflowsToReframeRoot()
{
for (uint32_t i=0; i<mPrt->mPrintDocList.Length(); i++) {
nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
NS_ASSERTION(po, "nsPrintObject can't be null!");
if (po->mPresContext) {
po->mPresContext->PresShell()->FrameConstructor()->SetPromoteReflowsToReframeRoot(true);
}
}
}
//-----------------------------------------------------------------
//-- Done: Reflow Methods
//-----------------------------------------------------------------

View File

@ -127,6 +127,7 @@ public:
void CheckForChildFrameSets(nsPrintObject* aPO);
void CalcNumPrintablePages(int32_t& aNumPages);
void PromoteReflowsToReframeRoot();
void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify);
nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting);
// If FinishPrintPreview() fails, caller may need to reset the state of the

View File

@ -12,6 +12,7 @@
#include "nsSMILKeySpline.h"
#include "nsEventDispatcher.h"
#include "nsCSSFrameConstructor.h"
#include "nsLayoutUtils.h"
#include <math.h>
using namespace mozilla;