From 88f80381e30611d980719009739823f36701d9fe Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Thu, 29 Jul 2004 19:41:39 +0000 Subject: [PATCH] Consolidate PresContext classes into a single nsIPresContext implementation, and finish deCOMtaminating it. Bug 253470, r+sr=roc. --- content/base/src/nsDocument.cpp | 6 +- content/base/src/nsDocumentViewer.cpp | 26 +- content/base/src/nsPrintEngine.cpp | 44 +-- content/base/src/nsRuleNode.cpp | 11 +- content/html/content/src/nsFormSubmission.cpp | 3 +- content/html/document/src/nsHTMLDocument.cpp | 4 +- content/html/style/src/nsHTMLStyleSheet.cpp | 5 +- content/html/style/src/nsStyleUtil.cpp | 5 +- content/shared/src/nsStyleStruct.cpp | 3 +- content/svg/content/src/nsSVGSVGElement.cpp | 4 +- content/xml/content/src/Makefile.in | 1 + editor/composer/src/Makefile.in | 1 + .../browser/activex/src/control/Makefile.in | 1 + .../typeaheadfind/src/nsTypeAheadFind.cpp | 4 +- gfx/public/nsITheme.h | 5 + layout/base/nsBidiPresUtils.cpp | 3 +- layout/base/nsCSSFrameConstructor.cpp | 45 +-- layout/base/nsCSSRendering.cpp | 18 +- layout/base/nsDocumentViewer.cpp | 26 +- layout/base/nsPresContext.cpp | 356 +++++++++++------- layout/base/nsPresContext.h | 205 ++++++++-- layout/base/nsPresShell.cpp | 33 +- layout/base/public/Makefile.in | 2 - layout/base/public/nsIPresContext.h | 205 ++++++++-- layout/base/public/nsIPrintContext.h | 0 layout/base/public/nsIPrintPreviewContext.h | 0 layout/base/public/nsPresContext.h | 205 ++++++++-- layout/base/src/Makefile.in | 106 ------ layout/base/src/nsBidiPresUtils.cpp | 3 +- layout/base/src/nsGalleyContext.cpp | 0 layout/base/src/nsPresContext.cpp | 356 +++++++++++------- layout/base/src/nsPresContext.h | 0 layout/base/src/nsPrintContext.cpp | 0 layout/base/src/nsPrintPreviewContext.cpp | 0 layout/build/nsLayoutCID.h | 12 - layout/build/nsLayoutModule.cpp | 19 - layout/forms/nsGfxCheckboxControlFrame.cpp | 19 +- layout/forms/nsGfxRadioControlFrame.cpp | 3 +- layout/forms/nsListControlFrame.cpp | 7 +- layout/generic/nsBlockFrame.cpp | 11 +- layout/generic/nsBulletFrame.cpp | 10 +- layout/generic/nsFrame.cpp | 6 +- layout/generic/nsFrameFrame.cpp | 32 +- layout/generic/nsFrameSetFrame.cpp | 6 +- layout/generic/nsGfxScrollFrame.cpp | 8 +- layout/generic/nsHTMLReflowState.cpp | 3 +- layout/generic/nsImageFrame.cpp | 17 +- layout/generic/nsObjectFrame.cpp | 18 +- layout/generic/nsPageContentFrame.cpp | 1 - layout/generic/nsPageFrame.cpp | 25 +- layout/generic/nsSimplePageSequence.cpp | 33 +- layout/generic/nsTextFrame.cpp | 12 +- layout/generic/nsTextTransformer.cpp | 3 +- layout/html/base/src/nsBlockFrame.cpp | 11 +- layout/html/base/src/nsBulletFrame.cpp | 10 +- layout/html/base/src/nsFrame.cpp | 6 +- layout/html/base/src/nsGfxScrollFrame.cpp | 8 +- layout/html/base/src/nsHTMLReflowState.cpp | 3 +- layout/html/base/src/nsImageFrame.cpp | 17 +- layout/html/base/src/nsObjectFrame.cpp | 18 +- layout/html/base/src/nsPageContentFrame.cpp | 1 - layout/html/base/src/nsPageFrame.cpp | 25 +- layout/html/base/src/nsPresShell.cpp | 33 +- layout/html/base/src/nsSimplePageSequence.cpp | 33 +- layout/html/base/src/nsTextFrame.cpp | 12 +- layout/html/base/src/nsTextTransformer.cpp | 3 +- layout/html/document/src/nsFrameFrame.cpp | 32 +- layout/html/document/src/nsFrameSetFrame.cpp | 6 +- .../forms/src/nsGfxCheckboxControlFrame.cpp | 19 +- .../html/forms/src/nsGfxRadioControlFrame.cpp | 3 +- layout/html/forms/src/nsListControlFrame.cpp | 7 +- .../html/style/src/nsCSSFrameConstructor.cpp | 45 +-- layout/html/style/src/nsCSSRendering.cpp | 18 +- .../table/src/BasicTableLayoutStrategy.cpp | 9 +- .../table/src/FixedTableLayoutStrategy.cpp | 300 --------------- layout/html/table/src/nsTableCellFrame.cpp | 9 +- layout/html/table/src/nsTableFrame.h | 6 +- layout/html/table/src/nsTableOuterFrame.cpp | 19 +- layout/html/table/src/nsTablePainter.cpp | 2 +- layout/mathml/base/src/nsMathMLChar.cpp | 8 +- layout/mathml/base/src/nsMathMLFrame.cpp | 8 +- layout/mathml/base/src/nsMathMLFrame.h | 6 +- layout/mathml/base/src/nsMathMLTokenFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmfracFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmoFrame.cpp | 8 +- layout/mathml/base/src/nsMathMLmoverFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmrootFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmsqrtFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmsubFrame.cpp | 9 +- .../mathml/base/src/nsMathMLmsubsupFrame.cpp | 4 +- layout/mathml/base/src/nsMathMLmsupFrame.cpp | 9 +- .../mathml/base/src/nsMathMLmunderFrame.cpp | 4 +- .../base/src/nsMathMLmunderoverFrame.cpp | 4 +- layout/printing/nsPrintEngine.cpp | 44 +-- layout/style/nsHTMLStyleSheet.cpp | 5 +- layout/style/nsRuleNode.cpp | 11 +- layout/style/nsStyleStruct.cpp | 3 +- layout/style/nsStyleUtil.cpp | 5 +- .../svg/base/src/nsSVGForeignObjectFrame.cpp | 5 +- layout/svg/base/src/nsSVGOuterSVGFrame.cpp | 18 +- layout/svg/renderer/src/cairo/Makefile.in | 1 + layout/svg/renderer/src/gdiplus/Makefile.in | 1 + layout/svg/renderer/src/libart/Makefile.in | 1 + layout/tables/BasicTableLayoutStrategy.cpp | 9 +- layout/tables/FixedTableLayoutStrategy.cpp | 3 +- layout/tables/nsTableCellFrame.cpp | 9 +- layout/tables/nsTableFrame.h | 6 +- layout/tables/nsTableOuterFrame.cpp | 19 +- layout/tables/nsTablePainter.cpp | 2 +- layout/xul/base/src/nsBox.cpp | 44 +-- layout/xul/base/src/nsBoxFrame.cpp | 24 +- layout/xul/base/src/nsImageBoxFrame.cpp | 5 +- layout/xul/base/src/nsListBoxBodyFrame.cpp | 4 +- layout/xul/base/src/nsMenuPopupFrame.cpp | 5 +- layout/xul/base/src/nsSliderFrame.cpp | 21 +- layout/xul/base/src/nsSplitterFrame.cpp | 8 +- layout/xul/base/src/nsSprocketLayout.cpp | 4 +- layout/xul/base/src/nsStackLayout.cpp | 10 +- layout/xul/base/src/nsTextBoxFrame.cpp | 3 +- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 18 +- modules/oji/src/Makefile.in | 1 + modules/plugin/base/src/Makefile.in | 1 + uriloader/base/Makefile.in | 1 + 123 files changed, 1350 insertions(+), 1607 deletions(-) delete mode 100644 layout/base/public/nsIPrintContext.h delete mode 100644 layout/base/public/nsIPrintPreviewContext.h delete mode 100644 layout/base/src/nsGalleyContext.cpp delete mode 100644 layout/base/src/nsPresContext.h delete mode 100644 layout/base/src/nsPrintContext.cpp delete mode 100644 layout/base/src/nsPrintPreviewContext.cpp diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 683f1172580..b499b6ed9b7 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -2989,8 +2989,7 @@ nsDocument::GetDir(nsAString& aDirection) nsCOMPtr context; shell->GetPresContext(getter_AddRefs(context)); if (context) { - PRUint32 options; - context->GetBidi(&options); + PRUint32 options = context->GetBidi(); for (const DirTable* elt = dirAttributes; elt->mName; elt++) { if (GET_BIDI_OPTION_DIRECTION(options) == elt->mValue) { CopyASCIItoUTF16(elt->mName, aDirection); @@ -3022,8 +3021,7 @@ nsDocument::SetDir(const nsAString& aDirection) shell->GetPresContext(getter_AddRefs(context)); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); - PRUint32 options; - context->GetBidi(&options); + PRUint32 options = context->GetBidi(); for (const DirTable* elt = dirAttributes; elt->mName; elt++) { if (aDirection == NS_ConvertASCIItoUCS2(elt->mName)) { diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 8405d6b5770..31dcfe734fe 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -99,7 +99,6 @@ #include "nsILayoutHistoryState.h" #include "nsLayoutAtoms.h" #include "nsIParser.h" -#include "nsIPrintContext.h" #include "nsGUIEvent.h" #include "nsHTMLReflowState.h" #include "nsIDOMHTMLAnchorElement.h" @@ -160,7 +159,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsIPluginDocument.h" // Print Preview -#include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants // Print Progress @@ -195,8 +193,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "prenv.h" #include -static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); - static const char kDOMStringBundleURL[] = "chrome://communicator/locale/dom/dom.properties"; @@ -230,9 +226,6 @@ static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing"); class DocumentViewerImpl; -// New PrintPreview -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); - // a small delegate class used to avoid circular references #ifdef XP_MAC @@ -797,15 +790,12 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, if (aDoCreation) { if (aParentWidget && !mPresContext) { // Create presentation context - if (GetIsCreatingPrintPreview()) { - mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv); - } else { - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - } - if (NS_FAILED(rv)) - return rv; + mPresContext = new nsIPresContext(GetIsCreatingPrintPreview() ? + nsIPresContext::eContext_PrintPreview : + nsIPresContext::eContext_Galley); + NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY); - rv = mPresContext->Init(aDeviceContext); + nsresult rv = mPresContext->Init(aDeviceContext); if (NS_FAILED(rv)) { mPresContext = nsnull; return rv; @@ -1500,8 +1490,8 @@ DocumentViewerImpl::Show(void) } NS_ASSERTION(!mPresContext, "Shouldn't have a prescontext if we have no shell!"); - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + mPresContext = new nsIPresContext(nsIPresContext::eContext_Galley); + NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY); rv = mPresContext->Init(mDeviceContext); if (NS_FAILED(rv)) { @@ -2644,7 +2634,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetBidiOptions(PRUint32* aBidiOptions) { if (aBidiOptions) { if (mPresContext) { - mPresContext->GetBidi(aBidiOptions); + *aBidiOptions = mPresContext->GetBidi(); } else *aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS; diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp index 76dba175305..d87a84bde3e 100644 --- a/content/base/src/nsPrintEngine.cpp +++ b/content/base/src/nsPrintEngine.cpp @@ -77,7 +77,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsIDOMHTMLObjectElement.h" // Print Preview -#include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants #include "nsIScrollableView.h" #include "nsIScrollable.h" @@ -157,7 +156,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsLayoutAtoms.h" #include "nsFrameManager.h" #include "nsIParser.h" -#include "nsIPrintContext.h" #include "nsGUIEvent.h" #include "nsHTMLReflowState.h" #include "nsIDOMHTMLAnchorElement.h" @@ -173,10 +171,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsPIDOMWindow.h" #include "nsIFocusController.h" -// New PrintPreview -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); -static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); - //----------------------------------------------------- // PR LOGGING #ifdef MOZ_LOGGING @@ -2567,23 +2561,11 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // create the PresContext PRBool containerIsSet = PR_FALSE; - nsresult rv; - if (mIsCreatingPrintPreview) { - nsCOMPtr printPreviewCon(do_CreateInstance(kPrintPreviewContextCID, &rv)); - if (NS_FAILED(rv)) { - return rv; - } - aPO->mPresContext = do_QueryInterface(printPreviewCon); - printPreviewCon->SetPrintSettings(mPrt->mPrintSettings); - } else { - nsCOMPtr printcon(do_CreateInstance(kPrintContextCID, &rv)); - if (NS_FAILED(rv)) { - return rv; - } - aPO->mPresContext = do_QueryInterface(printcon); - printcon->SetPrintSettings(mPrt->mPrintSettings); - } - + aPO->mPresContext = new nsIPresContext(mIsCreatingPrintPreview ? + nsIPresContext::eContext_PrintPreview: + nsIPresContext::eContext_Print); + NS_ENSURE_TRUE(aPO->mPresContext, NS_ERROR_OUT_OF_MEMORY); + aPO->mPresContext->SetPrintSettings(mPrt->mPrintSettings); // set the presentation context to the value in the print settings PRBool printBGColors; @@ -2594,7 +2576,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // init it with the DC - rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); + nsresult rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); if (NS_FAILED(rv)) { aPO->mPresContext = nsnull; return rv; @@ -2779,7 +2761,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return NS_OK; } - aPO->mPresContext->SetPageDim(&adjRect); + aPO->mPresContext->SetPageDim(adjRect); rv = aPO->mPresShell->InitialReflow(width, height); if (NS_SUCCEEDED(rv)) { // Transfer Selection Ranges to the new Print PresShell @@ -3322,9 +3304,7 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon return NS_ERROR_FAILURE; } - nsCOMPtr ppContext = do_QueryInterface(poPresContext); - if (!ppContext) { - + if (poPresContext->Type() != nsIPresContext::eContext_PrintPreview) { nscoord sheight = seqFrame->GetSize().height; nsRect r = poRootView->GetBounds(); @@ -4491,9 +4471,8 @@ nsPrintEngine::FinishPrintPreview() // Turning off the scaling of twips so any of the UI scrollbars // will not get scaled - nsCOMPtr printPreviewContext(do_QueryInterface(mPresContext)); - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + if (mPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + mPresContext->SetScalingOfTwips(PR_FALSE); mDeviceContext->SetCanonicalPixelScale(mPrtPreview->mOrigDCScale); } @@ -4798,8 +4777,7 @@ void DumpLayoutData(char* aTitleStr, } #ifdef NS_PRINT_PREVIEW - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { return; } #endif diff --git a/content/base/src/nsRuleNode.cpp b/content/base/src/nsRuleNode.cpp index 2c788f813f3..ba4d0181f1b 100644 --- a/content/base/src/nsRuleNode.cpp +++ b/content/base/src/nsRuleNode.cpp @@ -198,9 +198,8 @@ nscoord CalcLength(const nsCSSValue& aValue, } nsCSSUnit unit = aValue.GetUnit(); if (unit == eCSSUnit_Pixel) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - return NSFloatPixelsToTwips(aValue.GetFloatValue(), p2t); + return NSFloatPixelsToTwips(aValue.GetFloatValue(), + aPresContext->ScaledPixelsToTwips()); } // Common code for all units other than pixels: aInherited = PR_TRUE; @@ -220,8 +219,7 @@ nscoord CalcLength(const nsCSSValue& aValue, return NSToCoordRound((aValue.GetFloatValue() * (float)font->size) / 2.0f); } case eCSSUnit_XHeight: { - nsCOMPtr fm; - aPresContext->GetMetricsFor(*font, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(*font); nscoord xHeight; fm->GetXHeight(xHeight); return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight); @@ -4340,8 +4338,7 @@ SetSVGLength(const nsCSSValue& aValue, float parentLength, float& length, } else { length = (float) coord.GetCoordValue(); - float twipsPerPix; - aPresContext->GetScaledPixelsToTwips(&twipsPerPix); + float twipsPerPix = aPresContext->ScaledPixelsToTwips(); if (twipsPerPix == 0.0f) twipsPerPix = 1e-20f; length /= twipsPerPix; diff --git a/content/html/content/src/nsFormSubmission.cpp b/content/html/content/src/nsFormSubmission.cpp index 684a1d0f505..4d7ad4eb019 100644 --- a/content/html/content/src/nsFormSubmission.cpp +++ b/content/html/content/src/nsFormSubmission.cpp @@ -1161,9 +1161,8 @@ GetSubmissionFromForm(nsIHTMLContent* aForm, // // Get BIDI options - PRUint32 bidiOptions = 0; PRUint8 ctrlsModAtSubmit = 0; - aPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = aPresContext->GetBidi(); ctrlsModAtSubmit = GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions); // Get encoding type (default: urlencoded) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 261748c4687..39041b97617 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -756,9 +756,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCOMPtr cx; docShell->GetPresContext(getter_AddRefs(cx)); if(cx){ - PRUint32 mBidiOption; - cx->GetBidi(&mBidiOption); - mTexttype = GET_BIDI_OPTION_TEXTTYPE(mBidiOption); + mTexttype = GET_BIDI_OPTION_TEXTTYPE(cx->GetBidi()); } // // The following logic is mirrored in nsWebShell::Embed! diff --git a/content/html/style/src/nsHTMLStyleSheet.cpp b/content/html/style/src/nsHTMLStyleSheet.cpp index c1327330380..adf110eef83 100644 --- a/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/content/html/style/src/nsHTMLStyleSheet.cpp @@ -232,9 +232,8 @@ ProcessTableRulesAttribute(nsStyleStruct* aStyleStruct, borderData->SetBorderColor(aSide, borderColor); } // set the border width to be 1 pixel - float p2t; - aRuleData->mPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSToCoordRound(p2t); + nscoord onePixel = + NSToCoordRound(aRuleData->mPresContext->ScaledPixelsToTwips()); nsStyleCoord coord(onePixel); switch(aSide) { case NS_SIDE_TOP: diff --git a/content/html/style/src/nsStyleUtil.cpp b/content/html/style/src/nsStyleUtil.cpp index 241efe497e9..670d60fca8e 100644 --- a/content/html/style/src/nsStyleUtil.cpp +++ b/content/html/style/src/nsStyleUtil.cpp @@ -218,9 +218,8 @@ nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, } // Make special call specifically for fonts (needed PrintPreview) - float t2p; - aPresContext->GetTwipsToPixelsForFonts(&t2p); - PRInt32 fontSize = NSTwipsToIntPixels(aBasePointSize, t2p); + PRInt32 fontSize = NSTwipsToIntPixels(aBasePointSize, + aPresContext->TwipsToPixelsForFonts()); if ((fontSize >= sFontSizeTableMin) && (fontSize <= sFontSizeTableMax)) { diff --git a/content/shared/src/nsStyleStruct.cpp b/content/shared/src/nsStyleStruct.cpp index d20158fff77..9ff48068335 100644 --- a/content/shared/src/nsStyleStruct.cpp +++ b/content/shared/src/nsStyleStruct.cpp @@ -1164,8 +1164,7 @@ nsChangeHint nsStyleDisplay::CalcDifference(const nsStyleDisplay& aOther) const nsStyleVisibility::nsStyleVisibility(nsIPresContext* aPresContext) { - PRUint32 bidiOptions; - aPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = aPresContext->GetBidi(); if (GET_BIDI_OPTION_DIRECTION(bidiOptions) == IBMBIDI_TEXTDIRECTION_RTL) mDirection = NS_STYLE_DIRECTION_RTL; else diff --git a/content/svg/content/src/nsSVGSVGElement.cpp b/content/svg/content/src/nsSVGSVGElement.cpp index 0f231a40f09..3de4f6c9c45 100644 --- a/content/svg/content/src/nsSVGSVGElement.cpp +++ b/content/svg/content/src/nsSVGSVGElement.cpp @@ -436,9 +436,7 @@ nsSVGSVGElement::GetPixelUnitToMillimeterX(float *aPixelUnitToMillimeterX) presShell->GetPresContext(getter_AddRefs(context)); if (!context) return NS_OK; - float TwipsPerPx; - context->GetScaledPixelsToTwips(&TwipsPerPx); - *aPixelUnitToMillimeterX = TwipsPerPx / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); + *aPixelUnitToMillimeterX = context->ScaledPixelsToTwips() / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); return NS_OK; } diff --git a/content/xml/content/src/Makefile.in b/content/xml/content/src/Makefile.in index d553497a9f6..2424be43a11 100644 --- a/content/xml/content/src/Makefile.in +++ b/content/xml/content/src/Makefile.in @@ -59,6 +59,7 @@ REQUIRES = xpcom \ xpconnect \ unicharutil \ pref \ + locale \ $(NULL) CPPSRCS = \ diff --git a/editor/composer/src/Makefile.in b/editor/composer/src/Makefile.in index b6d7c405870..0d41266b483 100644 --- a/editor/composer/src/Makefile.in +++ b/editor/composer/src/Makefile.in @@ -71,6 +71,7 @@ REQUIRES = xpcom \ commandhandler \ composer \ appshell \ + locale \ $(NULL) CPPSRCS = \ diff --git a/embedding/browser/activex/src/control/Makefile.in b/embedding/browser/activex/src/control/Makefile.in index 9c24d960bb1..88d54ff45f5 100644 --- a/embedding/browser/activex/src/control/Makefile.in +++ b/embedding/browser/activex/src/control/Makefile.in @@ -78,6 +78,7 @@ REQUIRES = \ composer \ commandhandler \ ax_common \ + locale \ $(NULL) CPPSRCS = \ diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 9ca62652f4c..5945d100573 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -100,7 +100,6 @@ #include "nsIWindowWatcher.h" #include "nsIObserverService.h" #include "nsLayoutAtoms.h" -#include "nsIPrintPreviewContext.h" #include "nsIPrivateTextEvent.h" #include "nsIPrivateCompositionEvent.h" @@ -2495,8 +2494,7 @@ nsTypeAheadFind::GetTargetIfTypeAheadOkay(nsIDOMEvent *aEvent, nsCOMPtr presContext; presShell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr printPreview(do_QueryInterface(presContext)); - if (printPreview) { + if (presContext->Type() == nsIPresContext::eContext_PrintPreview) { // Typeaheadfind is not designed to work in print preview. // You can't navigate through the links there. if (lastShell != presShell) { diff --git a/gfx/public/nsITheme.h b/gfx/public/nsITheme.h index 928151bc328..4edc440a7b4 100644 --- a/gfx/public/nsITheme.h +++ b/gfx/public/nsITheme.h @@ -36,6 +36,9 @@ * * ***** END LICENSE BLOCK ***** */ +#ifndef nsITheme_h_ +#define nsITheme_h_ + #include "nsISupports.h" #include "nsCOMPtr.h" #include "nsColor.h" @@ -94,3 +97,5 @@ public: // Creator function extern NS_METHOD NS_NewNativeTheme(nsISupports *aOuter, REFNSIID aIID, void **aResult); + +#endif diff --git a/layout/base/nsBidiPresUtils.cpp b/layout/base/nsBidiPresUtils.cpp index ffc12d7f206..8389177962f 100644 --- a/layout/base/nsBidiPresUtils.cpp +++ b/layout/base/nsBidiPresUtils.cpp @@ -819,8 +819,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, nsresult rv = NS_OK; // ahmed //adjusted for correct numeral shaping - PRUint32 bidiOptions; - aPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = aPresContext->GetBidi(); switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { case IBMBIDI_NUMERAL_HINDI: diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 691eb68a2d6..e1e69f7a776 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -103,7 +103,6 @@ #include "nsFormControlHelper.h" #include "nsObjectFrame.h" #include "nsRuleNode.h" -#include "nsIPrintPreviewContext.h" #include "nsIDOMMutationEvent.h" #include "nsChildIterator.h" #include "nsCSSRendering.h" @@ -3709,7 +3708,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // the entire canvas as specified by the CSS2 spec PRBool isPaginated = aPresContext->IsPaginated(); - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; nsIFrame* rootFrame = nsnull; nsIAtom* rootPseudo; @@ -3789,7 +3789,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, } if (isPaginated) { - if (printPreviewContext) { // print preview + if (isPrintPreview) { isScrollable = aPresContext->HasPaginatedScrolling(); } else { isScrollable = PR_FALSE; // we are printing @@ -3814,7 +3814,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, nsIFrame* parentFrame = viewportFrame; // If paginated, make sure we don't put scrollbars in - if (isPaginated && !printPreviewContext) + if (isPaginated && !isPrintPreview) rootPseudoStyle = styleSet->ResolvePseudoStyleFor(nsnull, rootPseudo, viewportPseudoStyle); @@ -3911,7 +3911,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, rootFrame->Init(aPresContext, aDocElement, parentFrame, rootPseudoStyle, nsnull); - if (!isPaginated || printPreviewContext) { + if (!isPaginated || isPrintPreview) { if (isScrollable) { FinishBuildingScrollFrame(aPresContext, state, @@ -5809,11 +5809,13 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh // If the parent is a viewportFrame then we are the scrollbars for the UI // if not then we are scrollbars inside the document. PRBool noScalingOfTwips = PR_FALSE; - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; + + if (isPrintPreview) { noScalingOfTwips = aParentFrame->GetType() == nsLayoutAtoms::viewportFrame; if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + aPresContext->SetScalingOfTwips(PR_FALSE); } } @@ -5877,8 +5879,8 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh } - if (printPreviewContext && noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + if (isPrintPreview && noScalingOfTwips) { + aPresContext->SetScalingOfTwips(PR_TRUE); } return aScrolledChildStyle;; @@ -5976,11 +5978,10 @@ nsCSSFrameConstructor::BuildScrollFrame(nsIPresShell* aPresShell, // If the parent is a viewportFrame then we are the scrollbars for the UI // if not then we are scrollbars inside the document. PRBool noScalingOfTwips = PR_FALSE; - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { noScalingOfTwips = aParentFrame->GetType() == nsLayoutAtoms::viewportFrame; if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + aPresContext->SetScalingOfTwips(PR_FALSE); } } @@ -6018,7 +6019,7 @@ nsCSSFrameConstructor::BuildScrollFrame(nsIPresShell* aPresShell, aState.mFrameManager->SetPrimaryFrameFor( aContent, aNewFrame ); if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + aPresContext->SetScalingOfTwips(PR_TRUE); } return NS_OK; @@ -9950,13 +9951,14 @@ nsCSSFrameConstructor::DoContentStateChanged(nsIPresContext* aPresContext, if (primaryFrame) { PRUint8 app = primaryFrame->GetStyleDisplay()->mAppearance; if (app) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); - PRBool repaint = PR_FALSE; - if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, app)) + nsITheme *theme = aPresContext->GetTheme(); + if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, app)) { + PRBool repaint = PR_FALSE; theme->WidgetStateChanged(primaryFrame, app, nsnull, &repaint); - if (repaint) - ApplyRenderingChangeToTree(aPresContext, primaryFrame, nsnull, nsChangeHint_RepaintFrame); + if (repaint) { + ApplyRenderingChangeToTree(aPresContext, primaryFrame, nsnull, nsChangeHint_RepaintFrame); + } + } } } @@ -10042,8 +10044,7 @@ nsCSSFrameConstructor::AttributeChanged(nsIPresContext* aPresContext, if (primaryFrame) { const nsStyleDisplay* disp = primaryFrame->GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, disp->mAppearance)) { PRBool repaint = PR_FALSE; theme->WidgetStateChanged(primaryFrame, disp->mAppearance, aAttribute, &repaint); diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 571960edd3d..95add6658e1 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -58,7 +58,6 @@ #include "gfxIImageFrame.h" #include "nsCSSRendering.h" #include "nsCSSColorUtils.h" -#include "nsIPrintContext.h" #include "nsITheme.h" #include "nsThemeConstants.h" #include "nsIServiceManager.h" @@ -1634,8 +1633,7 @@ void nsCSSRendering::PaintBorder(nsIPresContext* aPresContext, // may be different! Always use |aStyleContext|! const nsStyleDisplay* displayData = aStyleContext->GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) return; // Let the theme handle it. } @@ -1795,10 +1793,7 @@ void nsCSSRendering::PaintBorder(nsIPresContext* aPresContext, } } /* Get our conversion values */ - nscoord twipsPerPixel; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - twipsPerPixel = NSIntPixelsToTwips(1,p2t); + nscoord twipsPerPixel = aPresContext->IntScaledPixelsToTwips(1); static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT }; nscolor sideColor; @@ -2791,8 +2786,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, // renderer draw the background and bail out. const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) { theme->DrawWidgetBackground(&aRenderingContext, aForFrame, displayData->mAppearance, aBorderArea, aDirtyRect); @@ -2834,14 +2828,14 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, // We have a background image // Lookup the image - nsCOMPtr req; - nsresult rv = aPresContext->LoadImage(aColor.mBackgroundImage, aForFrame, getter_AddRefs(req)); + imgIRequest *req = aPresContext->LoadImage(aColor.mBackgroundImage, + aForFrame); PRUint32 status = imgIRequest::STATUS_ERROR; if (req) req->GetImageStatus(&status); - if (NS_FAILED(rv) || !req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) { + if (!req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) { PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea, aColor, aBorder, aPadding, canDrawBackgroundColor); return; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 8405d6b5770..31dcfe734fe 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -99,7 +99,6 @@ #include "nsILayoutHistoryState.h" #include "nsLayoutAtoms.h" #include "nsIParser.h" -#include "nsIPrintContext.h" #include "nsGUIEvent.h" #include "nsHTMLReflowState.h" #include "nsIDOMHTMLAnchorElement.h" @@ -160,7 +159,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsIPluginDocument.h" // Print Preview -#include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants // Print Progress @@ -195,8 +193,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "prenv.h" #include -static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); - static const char kDOMStringBundleURL[] = "chrome://communicator/locale/dom/dom.properties"; @@ -230,9 +226,6 @@ static PRLogModuleInfo * kPrintingLogMod = PR_NewLogModule("printing"); class DocumentViewerImpl; -// New PrintPreview -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); - // a small delegate class used to avoid circular references #ifdef XP_MAC @@ -797,15 +790,12 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, if (aDoCreation) { if (aParentWidget && !mPresContext) { // Create presentation context - if (GetIsCreatingPrintPreview()) { - mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv); - } else { - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - } - if (NS_FAILED(rv)) - return rv; + mPresContext = new nsIPresContext(GetIsCreatingPrintPreview() ? + nsIPresContext::eContext_PrintPreview : + nsIPresContext::eContext_Galley); + NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY); - rv = mPresContext->Init(aDeviceContext); + nsresult rv = mPresContext->Init(aDeviceContext); if (NS_FAILED(rv)) { mPresContext = nsnull; return rv; @@ -1500,8 +1490,8 @@ DocumentViewerImpl::Show(void) } NS_ASSERTION(!mPresContext, "Shouldn't have a prescontext if we have no shell!"); - mPresContext = do_CreateInstance(kGalleyContextCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + mPresContext = new nsIPresContext(nsIPresContext::eContext_Galley); + NS_ENSURE_TRUE(mPresContext, NS_ERROR_OUT_OF_MEMORY); rv = mPresContext->Init(mDeviceContext); if (NS_FAILED(rv)) { @@ -2644,7 +2634,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetBidiOptions(PRUint32* aBidiOptions) { if (aBidiOptions) { if (mPresContext) { - mPresContext->GetBidi(aBidiOptions); + *aBidiOptions = mPresContext->GetBidi(); } else *aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 6e7b129c885..806ef80d932 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -35,7 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" -#include "nsPresContext.h" +#include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" @@ -96,9 +96,9 @@ MakeColorPref(const char *colstr) } int PR_CALLBACK -nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) +nsIPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) { - nsPresContext* presContext = (nsPresContext*)instance_data; + nsIPresContext* presContext = (nsIPresContext*)instance_data; NS_ASSERTION(nsnull != presContext, "bad instance data"); if (nsnull != presContext) { @@ -109,7 +109,7 @@ nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) #ifdef IBMBIDI static PRBool -IsVisualCharset(const nsCAutoString& aCharset) +IsVisualCharset(const nsCString& aCharset) { if (aCharset.LowerCaseEqualsLiteral("ibm864") // Arabic//ahmed || aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew @@ -135,32 +135,32 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); - // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // NOTE! nsIPresContext::operator new() zeroes out all members, so don't // bother initializing members to 0. -nsPresContext::nsPresContext() - : mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), +nsIPresContext::nsIPresContext(nsPresContextType aType) + : mType(aType), + mCompatibilityMode(eCompatibility_FullStandards), + mImageAnimationModePref(imgIContainer::kNormalAnimMode), + mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), - mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), - mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) { - - // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // NOTE! nsIPresContext::operator new() zeroes out all members, so don't // bother initializing members to 0. - mCompatibilityMode = eCompatibility_FullStandards; - mImageAnimationMode = imgIContainer::kNormalAnimMode; - mImageAnimationModePref = imgIContainer::kNormalAnimMode; + mDoScaledTwips = PR_TRUE; SetBackgroundImageDraw(PR_TRUE); // always draw the background SetBackgroundColorDraw(PR_TRUE); @@ -184,9 +184,26 @@ nsPresContext::nsPresContext() mFocusRingWidth = 1; mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown; + if (aType == eContext_Galley) { + mMedium = nsLayoutAtoms::screen; + mImageAnimationMode = imgIContainer::kNormalAnimMode; + } else { + SetBackgroundImageDraw(PR_FALSE); + SetBackgroundColorDraw(PR_FALSE); + mImageAnimationMode = imgIContainer::kDontAnimMode; + mNeverAnimate = PR_TRUE; + mMedium = nsLayoutAtoms::print; + mPaginated = PR_TRUE; + if (aType == eContext_PrintPreview) { + mCanPaginatedScroll = PR_TRUE; + mPageDim.SetRect(-1, -1, -1, -1); + } else { + mPageDim.SetRect(0, 0, 0, 0); + } + } } -nsPresContext::~nsPresContext() +nsIPresContext::~nsIPresContext() { mImageLoaders.Enumerate(destroy_loads); @@ -200,28 +217,28 @@ nsPresContext::~nsPresContext() // Unregister preference callbacks nsContentUtils::UnregisterPrefCallback("font.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.display.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.underline_anchors", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.anchor_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.active_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.visited_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("network.image.imageBehavior", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("image.animation_mode", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); #ifdef IBMBIDI nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this); @@ -234,7 +251,7 @@ nsPresContext::~nsPresContext() NS_IF_RELEASE(mLangGroup); } -NS_IMPL_ISUPPORTS2(nsPresContext, nsIPresContext, nsIObserver) +NS_IMPL_ISUPPORTS2(nsIPresContext, nsIPresContext, nsIObserver) #define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \ _pref.Assign(_s0); \ @@ -251,7 +268,7 @@ static const char* const kGenericFont[] = { }; void -nsPresContext::GetFontPreferences() +nsIPresContext::GetFontPreferences() { if (!mLangGroup) return; @@ -272,8 +289,7 @@ nsPresContext::GetFontPreferences() font.minimum-size.[langGroup] = integer - settable by the user */ - float p2t; - GetScaledPixelsToTwips(&p2t); + float p2t = ScaledPixelsToTwips(); mDefaultVariableFont.size = NSFloatPixelsToTwips((float)16, p2t); mDefaultFixedFont.size = NSFloatPixelsToTwips((float)13, p2t); @@ -403,7 +419,7 @@ nsPresContext::GetFontPreferences() } void -nsPresContext::GetDocumentColorPreferences() +nsIPresContext::GetDocumentColorPreferences() { PRInt32 useAccessibilityTheme = 0; PRBool usePrefColors = PR_TRUE; @@ -456,7 +472,7 @@ nsPresContext::GetDocumentColorPreferences() } void -nsPresContext::GetUserPreferences() +nsIPresContext::GetUserPreferences() { mFontScaler = nsContentUtils::GetIntPref("browser.display.base_font_scaler", @@ -571,7 +587,7 @@ nsPresContext::GetUserPreferences() } void -nsPresContext::ClearStyleDataAndReflow() +nsIPresContext::ClearStyleDataAndReflow() { if (mShell) { // Clear out all our style data. @@ -586,7 +602,7 @@ nsPresContext::ClearStyleDataAndReflow() } void -nsPresContext::PreferenceChanged(const char* aPrefName) +nsIPresContext::PreferenceChanged(const char* aPrefName) { nsCOMPtr docShell(do_QueryReferent(mContainer)); if (docShell) { @@ -605,11 +621,11 @@ nsPresContext::PreferenceChanged(const char* aPrefName) } mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); } -NS_IMETHODIMP -nsPresContext::Init(nsIDeviceContext* aDeviceContext) +nsresult +nsIPresContext::Init(nsIDeviceContext* aDeviceContext) { NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context"); NS_ENSURE_ARG(aDeviceContext); @@ -635,28 +651,28 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) // Register callbacks so we're notified when the preferences change nsContentUtils::RegisterPrefCallback("font.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.display.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.underline_anchors", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.anchor_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.active_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.visited_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("network.image.imageBehavior", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("image.animation_mode", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); #ifdef IBMBIDI nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback, @@ -680,8 +696,8 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) // Note: We don't hold a reference on the shell; it has a reference to // us -NS_IMETHODIMP -nsPresContext::SetShell(nsIPresShell* aShell) +void +nsIPresContext::SetShell(nsIPresShell* aShell) { if (mShell) { // Remove ourselves as the charset observer from the shell's doc, because @@ -702,7 +718,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) if (doc) { nsIURI *baseURI = doc->GetBaseURI(); - if (!mNeverAnimate && baseURI) { + if (mMedium != nsLayoutAtoms::print && baseURI) { PRBool isChrome = PR_FALSE; PRBool isRes = PR_FALSE; baseURI->SchemeIs("chrome", &isChrome); @@ -721,11 +737,10 @@ nsPresContext::SetShell(nsIPresShell* aShell) } } } - return NS_OK; } void -nsPresContext::UpdateCharSet(const char* aCharSet) +nsIPresContext::UpdateCharSet(const char* aCharSet) { if (mLangService) { NS_IF_RELEASE(mLangGroup); @@ -757,24 +772,24 @@ nsPresContext::UpdateCharSet(const char* aCharSet) } NS_IMETHODIMP -nsPresContext::Observe(nsISupports* aSubject, - const char* aTopic, - const PRUnichar* aData) +nsIPresContext::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) { if (!nsCRT::strcmp(aTopic, "charset")) { UpdateCharSet(NS_LossyConvertUCS2toASCII(aData).get()); mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); return NS_OK; } - NS_WARNING("unrecognized topic in nsPresContext::Observe"); + NS_WARNING("unrecognized topic in nsIPresContext::Observe"); return NS_ERROR_FAILURE; } void -nsPresContext::SetCompatibilityMode(nsCompatibility aMode) +nsIPresContext::SetCompatibilityMode(nsCompatibility aMode) { mCompatibilityMode = aMode; @@ -813,7 +828,7 @@ PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void // // Walks content and set the animation mode // this is a way to turn on/off image animations -void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) +void nsIPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) { nsCOMPtr imgContent(do_QueryInterface(aParent)); if (imgContent) { @@ -830,12 +845,16 @@ void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) } void -nsPresContext::SetImageAnimationMode(PRUint16 aMode) +nsIPresContext::SetImageAnimationModeInternal(PRUint16 aMode) { NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode || aMode == imgIContainer::kDontAnimMode || aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!"); + // Image animation mode cannot be changed when rendering to a printer. + if (mMedium == nsLayoutAtoms::print) + return; + // This hash table contains a list of background images // so iterate over it and set the mode mImageLoaders.Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode)); @@ -856,19 +875,28 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode) mImageAnimationMode = aMode; } -NS_IMETHODIMP -nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) +void +nsIPresContext::SetImageAnimationModeExternal(PRUint16 aMode) { - NS_PRECONDITION(aResult, "null out param"); + SetImageAnimationModeInternal(aMode); +} +already_AddRefed +nsIPresContext::GetMetricsForInternal(const nsFont& aFont) +{ nsIFontMetrics* metrics = nsnull; mDeviceContext->GetMetricsFor(aFont, mLangGroup, metrics); - *aResult = metrics; - return NS_OK; + return metrics; +} + +already_AddRefed +nsIPresContext::GetMetricsForExternal(const nsFont& aFont) +{ + return GetMetricsForInternal(aFont); } const nsFont* -nsPresContext::GetDefaultFont(PRUint8 aFontID) const +nsIPresContext::GetDefaultFontInternal(PRUint8 aFontID) const { const nsFont *font; switch (aFontID) { @@ -903,14 +931,15 @@ nsPresContext::GetDefaultFont(PRUint8 aFontID) const return font; } -NS_IMETHODIMP -nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const +const nsFont* +nsIPresContext::GetDefaultFontExternal(PRUint8 aFontID) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + return GetDefaultFontInternal(aFontID); +} +float +nsIPresContext::TwipsToPixelsForFonts() const +{ float app2dev; #ifdef NS_PRINT_PREVIEW // If an alternative DC is available we want to use @@ -927,32 +956,30 @@ nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const #else app2dev = mDeviceContext->AppUnitsToDevUnits(); #endif - *aResult = app2dev; - return NS_OK; + return app2dev; } -NS_IMETHODIMP -nsPresContext::GetScaledPixelsToTwips(float* aResult) const +float +nsIPresContext::ScaledPixelsToTwips() const { - NS_PRECONDITION(aResult, "null out param"); - float scale; float p2t; p2t = mDeviceContext->DevUnitsToAppUnits(); - mDeviceContext->GetCanonicalPixelScale(scale); - scale = p2t * scale; + if (mDoScaledTwips) { + mDeviceContext->GetCanonicalPixelScale(scale); + scale = p2t * scale; + } else { + scale = p2t; + } - *aResult = scale; - return NS_OK; + return scale; } -nsresult -nsPresContext::LoadImage(imgIRequest* aImage, - nsIFrame* aTargetFrame,//may be null (precached image) - imgIRequest **aRequest) +imgIRequest* +nsIPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame) { // look and see if we have a loader for the target frame. @@ -962,7 +989,7 @@ nsPresContext::LoadImage(imgIRequest* aImage, if (!loader) { loader = new nsImageLoader(); if (!loader) - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; NS_ADDREF(loader); // new @@ -972,16 +999,15 @@ nsPresContext::LoadImage(imgIRequest* aImage, loader->Load(aImage); - NS_IF_ADDREF(*aRequest = loader->GetRequest()); - + imgIRequest *request = loader->GetRequest(); NS_RELEASE(loader); - return NS_OK; + return request; } void -nsPresContext::StopImagesFor(nsIFrame* aTargetFrame) +nsIPresContext::StopImagesFor(nsIFrame* aTargetFrame) { nsVoidKey key(aTargetFrame); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs @@ -996,7 +1022,7 @@ nsPresContext::StopImagesFor(nsIFrame* aTargetFrame) void -nsPresContext::SetContainer(nsISupports* aHandler) +nsIPresContext::SetContainer(nsISupports* aHandler) { mContainer = do_GetWeakReference(aHandler); if (mContainer) { @@ -1005,7 +1031,7 @@ nsPresContext::SetContainer(nsISupports* aHandler) } already_AddRefed -nsPresContext::GetContainer() +nsIPresContext::GetContainerInternal() { nsISupports *result; if (mContainer) @@ -1016,16 +1042,22 @@ nsPresContext::GetContainer() return result; } +already_AddRefed +nsIPresContext::GetContainerExternal() +{ + return GetContainerInternal(); +} + #ifdef IBMBIDI PRBool -nsPresContext::BidiEnabled() const +nsIPresContext::BidiEnabledInternal() const { PRBool bidiEnabled = PR_FALSE; - NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled"); + NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsIPresContext::GetBidiEnabled"); if (mShell) { nsCOMPtr doc; mShell->GetDocument(getter_AddRefs(doc) ); - NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled"); + NS_ASSERTION(doc, "PresShell has no document in nsIPresContext::GetBidiEnabled"); if (doc) { bidiEnabled = doc->GetBidiEnabled(); } @@ -1033,8 +1065,14 @@ nsPresContext::BidiEnabled() const return bidiEnabled; } +PRBool +nsIPresContext::BidiEnabledExternal() const +{ + return BidiEnabledInternal(); +} + void -nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const +nsIPresContext::SetBidiEnabled(PRBool aBidiEnabled) const { if (mShell) { nsCOMPtr doc; @@ -1045,23 +1083,17 @@ nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const } } -NS_IMETHODIMP -nsPresContext::GetBidiUtils(nsBidiPresUtils** aBidiUtils) +nsBidiPresUtils* +nsIPresContext::GetBidiUtils() { - nsresult rv = NS_OK; - - if (!mBidiUtils) { + if (!mBidiUtils) mBidiUtils = new nsBidiPresUtils; - if (!mBidiUtils) { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } - *aBidiUtils = mBidiUtils; - return rv; + + return mBidiUtils; } -NS_IMETHODIMP -nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) +void +nsIPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) { mBidi = aSource; if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(mBidi) @@ -1078,22 +1110,13 @@ nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) SetVisualMode(IsVisualCharset(mCharset) ); } if (mShell && aForceReflow) { - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); } - return NS_OK; -} - -NS_IMETHODIMP -nsPresContext::GetBidi(PRUint32* aDest) const -{ - if (aDest) - *aDest = mBidi; - return NS_OK; } #endif //IBMBIDI -NS_IMETHODIMP -nsPresContext::GetTheme(nsITheme** aResult) +nsITheme* +nsIPresContext::GetTheme() { if (!mNoTheme && !mTheme) { mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1"); @@ -1101,13 +1124,11 @@ nsPresContext::GetTheme(nsITheme** aResult) mNoTheme = PR_TRUE; } - *aResult = mTheme; - NS_IF_ADDREF(*aResult); - return mTheme ? NS_OK : NS_ERROR_FAILURE; + return mTheme; } -NS_IMETHODIMP -nsPresContext::ThemeChanged() +void +nsIPresContext::ThemeChanged() { // Tell the theme that it changed, so it can flush any handles to stale theme // data. @@ -1118,14 +1139,12 @@ nsPresContext::ThemeChanged() if (mLookAndFeel) mLookAndFeel->LookAndFeelChanged(); - if (!mShell) - return NS_OK; - - return mShell->ReconstructStyleData(); + if (mShell) + mShell->ReconstructStyleData(); } -NS_IMETHODIMP -nsPresContext::SysColorChanged() +void +nsIPresContext::SysColorChanged() { if (mLookAndFeel) { // Don't use the cached values for the system colors @@ -1150,26 +1169,79 @@ nsPresContext::SysColorChanged() // data without reflowing/updating views will lead to incorrect change hints // later, because when generating change hints, any style structs which have // been cleared and not reread are assumed to not be used at all. - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); +} + +void +nsIPresContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) +{ + if (mMedium == nsLayoutAtoms::print) { + if (aActualRect) { + PRInt32 width, height; + nsresult rv = mDeviceContext->GetDeviceSurfaceDimensions(width, height); + if (NS_SUCCEEDED(rv)) + aActualRect->SetRect(0, 0, width, height); + } + if (aAdjRect) + *aAdjRect = mPageDim; + } else { + if (aActualRect) + aActualRect->SetRect(0, 0, 0, 0); + if (aAdjRect) + aAdjRect->SetRect(0, 0, 0, 0); + } +} + +void +nsIPresContext::SetPageDim(const nsRect& aPageDim) +{ + if (mMedium == nsLayoutAtoms::print) + mPageDim = aPageDim; +} + +void +nsIPresContext::SetPaginatedScrolling(PRBool aPaginated) +{ + if (mType == eContext_PrintPreview) + mCanPaginatedScroll = aPaginated; +} + +void +nsIPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings) +{ + if (mMedium == nsLayoutAtoms::print) + mPrintSettings = aPrintSettings; +} + +nsresult +NS_NewPresContext(nsIPresContext::nsPresContextType aType, + nsIPresContext** aInstancePtrResult) +{ + nsIPresContext *context = new nsIPresContext(aType); + if (!context) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aInstancePtrResult = context); return NS_OK; } #ifdef MOZ_REFLOW_PERF -NS_IMETHODIMP -nsPresContext::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) +void +nsIPresContext::CountReflows(const char * aName, + PRUint32 aType, nsIFrame * aFrame) { if (mShell) { mShell->CountReflows(aName, aType, aFrame); } - return NS_OK; } -NS_IMETHODIMP -nsPresContext::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor) +void +nsIPresContext::PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIFrame * aFrame, PRUint32 aColor) { if (mShell) { mShell->PaintCount(aName, aRenderingContext, this, aFrame, aColor); } - return NS_OK; } #endif diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index f33b591aea8..ea7e89d4e63 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -46,11 +46,18 @@ #include "nsIPresShell.h" #include "nsRect.h" #include "nsIDeviceContext.h" +#include "nsHashtable.h" +#include "nsFont.h" +#include "nsIWeakReference.h" +#include "nsITheme.h" +#include "nsILanguageAtomService.h" +#include "nsIObserver.h" +#include "nsCRT.h" +#include "nsIPrintSettings.h" #ifdef IBMBIDI class nsBidiPresUtils; #endif // IBMBIDI -struct nsFont; struct nsRect; class imgIRequest; @@ -69,7 +76,6 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; class nsIAtom; -class nsITheme; struct nsStyleStruct; struct nsStyleBackground; @@ -78,8 +84,8 @@ class nsIRenderingContext; #endif #define NS_IPRESCONTEXT_IID \ -{ 0xa394329f, 0x3b10, 0x49ac, \ - {0x8f, 0xf2, 0xeb, 0x0b, 0x66, 0x93, 0x82, 0x38} } +{ 0x96e4bc06, 0x8e72, 0x4941, \ + {0xa6, 0x6c, 0x70, 0xee, 0x7d, 0x1b, 0x58, 0x21} } enum nsWidgetType { eWidgetType_Button = 1, @@ -109,20 +115,35 @@ const PRUint8 kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fi // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. -class nsIPresContext : public nsISupports { +class nsIPresContext : public nsIObserver { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESCONTEXT_IID) + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + enum nsPresContextType { + eContext_Galley, // unpaginated screen presentation + eContext_PrintPreview, // paginated screen presentation + eContext_Print // paginated printer presentation + }; + + nsIPresContext(nsPresContextType aType) NS_HIDDEN; + /** * Initialize the presentation context from a particular device. */ - NS_IMETHOD Init(nsIDeviceContext* aDeviceContext) = 0; + NS_HIDDEN_(nsresult) Init(nsIDeviceContext* aDeviceContext); /** * Set the presentation shell that this context is bound to. * A presentation context may only be bound to a single shell. */ - NS_IMETHOD SetShell(nsIPresShell* aShell) = 0; + NS_HIDDEN_(void) SetShell(nsIPresShell* aShell); + + + NS_HIDDEN_(nsPresContextType) Type() const { return mType; } /** * Get the PresentationShell that this context is bound to. @@ -151,13 +172,21 @@ public: * relying on a default. */ nsCompatibility CompatibilityMode() const { return mCompatibilityMode; } - virtual void SetCompatibilityMode(nsCompatibility aMode) = 0; + NS_HIDDEN_(void) SetCompatibilityMode(nsCompatibility aMode); /** * Access the image animation mode for this context */ PRUint16 ImageAnimationMode() const { return mImageAnimationMode; } - virtual void SetImageAnimationMode(PRUint16 aMode) = 0; + virtual void SetImageAnimationModeExternal(PRUint16 aMode); + NS_HIDDEN_(void) SetImageAnimationModeInternal(PRUint16 aMode); +#ifdef _IMPL_NS_LAYOUT + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeInternal(aMode); } +#else + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeExternal(aMode); } +#endif /** * Get cached look and feel service. This is faster than obtaining it @@ -173,7 +202,7 @@ public: /** * Clear style data from the root frame downwards, and reflow. */ - virtual void ClearStyleDataAndReflow() = 0; + NS_HIDDEN_(void) ClearStyleDataAndReflow(); void* AllocateFromShell(size_t aSize) { @@ -191,13 +220,31 @@ public: /** * Get the font metrics for a given font. */ - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0; + virtual already_AddRefed + GetMetricsForExternal(const nsFont& aFont); + NS_HIDDEN_(already_AddRefed) + GetMetricsForInternal(const nsFont& aFont); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForInternal(aFont); } +#else + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForExternal(aFont); } +#endif /** * Get the default font correponding to the given ID. This object is * read-only, you must copy the font to modify it. */ - virtual const nsFont* GetDefaultFont(PRUint8 aFontID) const = 0; + virtual const nsFont* GetDefaultFontExternal(PRUint8 aFontID) const; + NS_HIDDEN_(const nsFont*) GetDefaultFontInternal(PRUint8 aFontID) const; +#ifdef _IMPL_NS_LAYOUT + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontInternal(aFontID); } +#else + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontExternal(aFontID); } +#endif /** Get a cached boolean pref, by its type */ // * - initially created for bugs 31816, 20760, 22963 @@ -263,19 +310,26 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - virtual nsresult LoadImage(imgIRequest* aImage, - nsIFrame* aTargetFrame, - imgIRequest **aRequest) = 0; + NS_HIDDEN_(imgIRequest*) LoadImage(imgIRequest* aImage, + nsIFrame* aTargetFrame); /** * This method is called when a frame is being destroyed to * ensure that the image load gets disassociated from the prescontext */ - virtual void StopImagesFor(nsIFrame* aTargetFrame) = 0; + NS_HIDDEN_(void) StopImagesFor(nsIFrame* aTargetFrame); - virtual void SetContainer(nsISupports* aContainer) = 0; + NS_HIDDEN_(void) SetContainer(nsISupports* aContainer); - virtual already_AddRefed GetContainer() = 0; + virtual already_AddRefed GetContainerExternal(); + NS_HIDDEN_(already_AddRefed) GetContainerInternal(); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetContainer() + { return GetContainerInternal(); } +#else + already_AddRefed GetContainer() + { return GetContainerExternal(); } +#endif // XXX this are going to be replaced with set/get container void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } @@ -305,7 +359,7 @@ public: * Sets whether the presentation context can scroll for a paginated * context. */ - virtual void SetPaginatedScrolling(PRBool aResult) = 0; + NS_HIDDEN_(void) SetPaginatedScrolling(PRBool aResult); /** * Return true if this presentation context can scroll for paginated @@ -322,7 +376,7 @@ public: * @param aActualRect returns the size of the actual device/surface * @param aRect returns the adjusted size */ - virtual void GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0; + NS_HIDDEN_(void) GetPageDim(nsRect* aActualRect, nsRect* aAdjRect); /** * Sets the "adjusted" rect for the page Dimimensions, @@ -331,20 +385,27 @@ public: * * @param aRect returns the adjusted size */ - virtual void SetPageDim(nsRect* aRect) = 0; + NS_HIDDEN_(void) SetPageDim(const nsRect& aRect); float PixelsToTwips() const { return mDeviceContext->DevUnitsToAppUnits(); } float TwipsToPixels() const { return mDeviceContext->AppUnitsToDevUnits(); } - NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0; + NS_HIDDEN_(float) TwipsToPixelsForFonts() const; //XXX this is probably not an ideal name. MMP /** * Do pixels to twips conversion taking into account * differing size of a "pixel" from device to device. */ - NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; + NS_HIDDEN_(float) ScaledPixelsToTwips() const; + + /* Convenience method for converting one pixel value to twips */ + nscoord IntScaledPixelsToTwips(nscoord aPixels) const + { return NSIntPixelsToTwips(aPixels, ScaledPixelsToTwips()); } + + /* Set whether twip scaling is used */ + void SetScalingOfTwips(PRBool aOn) { mDoScaledTwips = aOn; } nsIDeviceContext* DeviceContext() { return mDeviceContext; } nsIEventStateManager* EventStateManager() { return mEventManager; } @@ -394,14 +455,20 @@ public: * * @lina 07/12/2000 */ - virtual PRBool BidiEnabled() const = 0; + virtual PRBool BidiEnabledExternal() const; + NS_HIDDEN_(PRBool) BidiEnabledInternal() const; +#ifdef _IMPL_NS_LAYOUT + PRBool BidiEnabled() const { return BidiEnabledInternal(); } +#else + PRBool BidiEnabled() const { return BidiEnabledExternal(); } +#endif /** * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm * * @lina 07/12/2000 */ - virtual void SetBidiEnabled(PRBool aBidiEnabled) const = 0; + NS_HIDDEN_(void) SetBidiEnabled(PRBool aBidiEnabled) const; /** * Set visual or implicit mode into the pres context. @@ -435,17 +502,18 @@ public: /** * Get a Bidi presentation utilities object */ - NS_IMETHOD GetBidiUtils(nsBidiPresUtils** aBidiUtils) = 0; + NS_HIDDEN_(nsBidiPresUtils*) GetBidiUtils(); /** * Set the Bidi options for the presentation context */ - NS_IMETHOD SetBidi(PRUint32 aBidiOptions, PRBool aForceReflow = PR_FALSE) = 0; + NS_HIDDEN_(void) SetBidi(PRUint32 aBidiOptions, + PRBool aForceReflow = PR_FALSE); /** * Get the Bidi options for the presentation context */ - NS_IMETHOD GetBidi(PRUint32* aBidiOptions) const = 0; + NS_HIDDEN_(PRUint32) GetBidi() const { return mBidi; } /** * Set the Bidi capabilities of the system @@ -478,7 +546,7 @@ public: /* * Obtain a native them for rendering our widgets (both form controls and html) */ - NS_IMETHOD GetTheme(nsITheme** aResult) = 0; + NS_HIDDEN_(nsITheme*) GetTheme(); /* * Notify the pres context that the theme has changed. An internal switch @@ -486,23 +554,42 @@ public: * Otherwise, the OS is telling us that the native theme for the platform * has changed. */ - NS_IMETHOD ThemeChanged() = 0; + NS_HIDDEN_(void) ThemeChanged(); /* * Notify the pres context that a system color has changed */ - NS_IMETHOD SysColorChanged() = 0; + NS_HIDDEN_(void) SysColorChanged(); + + /** Printing methods below should only be used for Medium() == print **/ + NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings); + + nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } #ifdef MOZ_REFLOW_PERF - NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; - NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; + NS_HIDDEN_(void) CountReflows(const char * aName, + PRUint32 aType, nsIFrame * aFrame); + NS_HIDDEN_(void) PaintCount(const char * aName, + nsIRenderingContext* aRendingContext, + nsIFrame * aFrame, PRUint32 aColor); #endif protected: + NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, PRUint16 aMode); + NS_HIDDEN_(void) GetDocumentColorPreferences(); + NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName); + static NS_HIDDEN_(int) PR_CALLBACK PrefChangedCallback(const char*, void*); + + NS_HIDDEN_(void) GetUserPreferences(); + NS_HIDDEN_(void) GetFontPreferences(); + + NS_HIDDEN_(void) UpdateCharSet(const char* aCharSet); + // IMPORTANT: The ownership implicit in the following member variables // has been explicitly checked. If you add any members to this class, // please make the ownership explicit (pinkerton, scc). + nsPresContextType mType; nsIPresShell* mShell; // [WEAK] nsIDeviceContext* mDeviceContext; // [STRONG] could be weak, but // better safe than sorry. @@ -517,11 +604,24 @@ protected: nsILinkHandler* mLinkHandler; // [WEAK] nsIAtom* mLangGroup; // [STRONG] + nsSupportsHashtable mImageLoaders; + nsWeakPtr mContainer; + +#ifdef IBMBIDI + nsBidiPresUtils* mBidiUtils; + nsCString mCharset; // the charset we are using +#endif + + nsCOMPtr mTheme; + nsCOMPtr mLangService; + nsCOMPtr mPrintSettings; + nsLanguageSpecificTransformType mLanguageSpecificTransformType; PRInt32 mFontScaler; nscoord mMinimumFontSize; nsRect mVisibleArea; + nsRect mPageDim; nscolor mDefaultColor; nscolor mBackgroundColor; @@ -538,6 +638,15 @@ protected: nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; + PRUint16 mImageAnimationModePref; + + nsFont mDefaultVariableFont; + nsFont mDefaultFixedFont; + nsFont mDefaultSerifFont; + nsFont mDefaultSansSerifFont; + nsFont mDefaultMonospaceFont; + nsFont mDefaultCursiveFont; + nsFont mDefaultFantasyFont; unsigned mUseDocumentFonts : 1; unsigned mUseDocumentColors : 1; @@ -551,10 +660,35 @@ protected: unsigned mNoTheme : 1; unsigned mPaginated : 1; unsigned mCanPaginatedScroll : 1; + unsigned mDoScaledTwips : 1; + unsigned mEnableJapaneseTransform : 1; #ifdef IBMBIDI unsigned mIsVisual : 1; unsigned mIsBidiSystem : 1; + + PRUint32 mBidi; #endif +#ifdef DEBUG + PRBool mInitialized; +#endif + + +private: + + ~nsIPresContext() NS_HIDDEN; + + // these are private, use the list in nsFont.h if you want a public list + enum { + eDefaultFont_Variable, + eDefaultFont_Fixed, + eDefaultFont_Serif, + eDefaultFont_SansSerif, + eDefaultFont_Monospace, + eDefaultFont_Cursive, + eDefaultFont_Fantasy, + eDefaultFont_COUNT + }; + }; // Bit values for StartLoadImage's aImageStatus @@ -562,11 +696,6 @@ protected: #define NS_LOAD_IMAGE_STATUS_SIZE 0x2 #define NS_LOAD_IMAGE_STATUS_BITS 0x4 -// Factory method to create a "galley" presentation context (galley is -// a kind of view that has no limit to the size of a page) -nsresult -NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index f278777829b..73bc6f099cd 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -146,7 +146,6 @@ #include "nsIDOMWindowInternal.h" #include "nsPIDOMWindow.h" #include "nsIFocusController.h" -#include "nsIPrintPreviewContext.h" // Drag & Drop, Clipboard #include "nsWidgetsCID.h" @@ -196,7 +195,6 @@ #include "nsContentCID.h" static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID); static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); // convert a color value to a string, in the CSS format #RRGGBB // * - initially created for bugs 31816, 20760, 22963 @@ -3541,8 +3539,7 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const // if it is then get the scrolled frame scrollable->GetScrolledFrame(nsnull, child); } else { - nsCOMPtr ppContext = do_QueryInterface(mPresContext); - if (ppContext) { + if (mPresContext->Type() == nsIPresContext::eContext_PrintPreview) { child = child->GetFirstChild(nsnull); } } @@ -5700,7 +5697,8 @@ PresShell::HandleEvent(nsIView *aView, // Check for a theme change up front, since the frame type is irrelevant if (aEvent->message == NS_THEMECHANGED && mPresContext) { - return mPresContext->ThemeChanged(); + mPresContext->ThemeChanged(); + return NS_OK; } // Check for a system color change up front, since the frame type is @@ -5717,7 +5715,8 @@ PresShell::HandleEvent(nsIView *aView, if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; - return mPresContext->SysColorChanged(); + mPresContext->SysColorChanged(); + return NS_OK; } } return NS_OK; @@ -7027,16 +7026,12 @@ PresShell::VerifyIncrementalReflow() nsIPresShell* sh; // Create a presentation context to view the new frame tree - nsresult rv; - if (mPresContext->IsPaginated()) { - nsCOMPtr ppx = do_CreateInstance(kPrintPreviewContextCID, &rv); - if (NS_SUCCEEDED(rv)) { - ppx->QueryInterface(NS_GET_IID(nsIPresContext),(void**)&cx); - } - } - else { - rv = NS_NewGalleyContext(&cx); - } + NS_IF_ADDREF(cx = new nsIPresContext(mPresContext->IsPaginated() ? + nsIPresContext::eContext_PrintPreview : + nsIPresContext::eContext_Galley)); + + if (!cx) + return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr container = mPresContext->GetContainer(); if (container) { @@ -7047,9 +7042,8 @@ PresShell::VerifyIncrementalReflow() } } - NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); nsIDeviceContext *dc = mPresContext->DeviceContext(); - rv = cx->Init(dc); + nsresult rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); // Get our scrolling preference @@ -7548,8 +7542,7 @@ void ReflowCountMgr::PaintCount(const char * aName, nsFont font("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(8)); - nsCOMPtr fm; - aPresContext->GetMetricsFor(font, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(font); aRenderingContext->SetFont(fm); char buf[16]; sprintf(buf, "%d", counter->mCount); diff --git a/layout/base/public/Makefile.in b/layout/base/public/Makefile.in index 0a49caa766a..4d37908f13c 100644 --- a/layout/base/public/Makefile.in +++ b/layout/base/public/Makefile.in @@ -74,8 +74,6 @@ nsIPercentHeightObserver.h \ nsIPresContext.h \ nsIPresShell.h \ nsIPresState.h \ -nsIPrintContext.h \ -nsIPrintPreviewContext.h \ nsIReflowCallback.h \ nsIScrollableFrame.h \ nsIScrollableViewProvider.h \ diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index f33b591aea8..ea7e89d4e63 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -46,11 +46,18 @@ #include "nsIPresShell.h" #include "nsRect.h" #include "nsIDeviceContext.h" +#include "nsHashtable.h" +#include "nsFont.h" +#include "nsIWeakReference.h" +#include "nsITheme.h" +#include "nsILanguageAtomService.h" +#include "nsIObserver.h" +#include "nsCRT.h" +#include "nsIPrintSettings.h" #ifdef IBMBIDI class nsBidiPresUtils; #endif // IBMBIDI -struct nsFont; struct nsRect; class imgIRequest; @@ -69,7 +76,6 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; class nsIAtom; -class nsITheme; struct nsStyleStruct; struct nsStyleBackground; @@ -78,8 +84,8 @@ class nsIRenderingContext; #endif #define NS_IPRESCONTEXT_IID \ -{ 0xa394329f, 0x3b10, 0x49ac, \ - {0x8f, 0xf2, 0xeb, 0x0b, 0x66, 0x93, 0x82, 0x38} } +{ 0x96e4bc06, 0x8e72, 0x4941, \ + {0xa6, 0x6c, 0x70, 0xee, 0x7d, 0x1b, 0x58, 0x21} } enum nsWidgetType { eWidgetType_Button = 1, @@ -109,20 +115,35 @@ const PRUint8 kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fi // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. -class nsIPresContext : public nsISupports { +class nsIPresContext : public nsIObserver { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESCONTEXT_IID) + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + enum nsPresContextType { + eContext_Galley, // unpaginated screen presentation + eContext_PrintPreview, // paginated screen presentation + eContext_Print // paginated printer presentation + }; + + nsIPresContext(nsPresContextType aType) NS_HIDDEN; + /** * Initialize the presentation context from a particular device. */ - NS_IMETHOD Init(nsIDeviceContext* aDeviceContext) = 0; + NS_HIDDEN_(nsresult) Init(nsIDeviceContext* aDeviceContext); /** * Set the presentation shell that this context is bound to. * A presentation context may only be bound to a single shell. */ - NS_IMETHOD SetShell(nsIPresShell* aShell) = 0; + NS_HIDDEN_(void) SetShell(nsIPresShell* aShell); + + + NS_HIDDEN_(nsPresContextType) Type() const { return mType; } /** * Get the PresentationShell that this context is bound to. @@ -151,13 +172,21 @@ public: * relying on a default. */ nsCompatibility CompatibilityMode() const { return mCompatibilityMode; } - virtual void SetCompatibilityMode(nsCompatibility aMode) = 0; + NS_HIDDEN_(void) SetCompatibilityMode(nsCompatibility aMode); /** * Access the image animation mode for this context */ PRUint16 ImageAnimationMode() const { return mImageAnimationMode; } - virtual void SetImageAnimationMode(PRUint16 aMode) = 0; + virtual void SetImageAnimationModeExternal(PRUint16 aMode); + NS_HIDDEN_(void) SetImageAnimationModeInternal(PRUint16 aMode); +#ifdef _IMPL_NS_LAYOUT + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeInternal(aMode); } +#else + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeExternal(aMode); } +#endif /** * Get cached look and feel service. This is faster than obtaining it @@ -173,7 +202,7 @@ public: /** * Clear style data from the root frame downwards, and reflow. */ - virtual void ClearStyleDataAndReflow() = 0; + NS_HIDDEN_(void) ClearStyleDataAndReflow(); void* AllocateFromShell(size_t aSize) { @@ -191,13 +220,31 @@ public: /** * Get the font metrics for a given font. */ - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0; + virtual already_AddRefed + GetMetricsForExternal(const nsFont& aFont); + NS_HIDDEN_(already_AddRefed) + GetMetricsForInternal(const nsFont& aFont); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForInternal(aFont); } +#else + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForExternal(aFont); } +#endif /** * Get the default font correponding to the given ID. This object is * read-only, you must copy the font to modify it. */ - virtual const nsFont* GetDefaultFont(PRUint8 aFontID) const = 0; + virtual const nsFont* GetDefaultFontExternal(PRUint8 aFontID) const; + NS_HIDDEN_(const nsFont*) GetDefaultFontInternal(PRUint8 aFontID) const; +#ifdef _IMPL_NS_LAYOUT + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontInternal(aFontID); } +#else + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontExternal(aFontID); } +#endif /** Get a cached boolean pref, by its type */ // * - initially created for bugs 31816, 20760, 22963 @@ -263,19 +310,26 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - virtual nsresult LoadImage(imgIRequest* aImage, - nsIFrame* aTargetFrame, - imgIRequest **aRequest) = 0; + NS_HIDDEN_(imgIRequest*) LoadImage(imgIRequest* aImage, + nsIFrame* aTargetFrame); /** * This method is called when a frame is being destroyed to * ensure that the image load gets disassociated from the prescontext */ - virtual void StopImagesFor(nsIFrame* aTargetFrame) = 0; + NS_HIDDEN_(void) StopImagesFor(nsIFrame* aTargetFrame); - virtual void SetContainer(nsISupports* aContainer) = 0; + NS_HIDDEN_(void) SetContainer(nsISupports* aContainer); - virtual already_AddRefed GetContainer() = 0; + virtual already_AddRefed GetContainerExternal(); + NS_HIDDEN_(already_AddRefed) GetContainerInternal(); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetContainer() + { return GetContainerInternal(); } +#else + already_AddRefed GetContainer() + { return GetContainerExternal(); } +#endif // XXX this are going to be replaced with set/get container void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } @@ -305,7 +359,7 @@ public: * Sets whether the presentation context can scroll for a paginated * context. */ - virtual void SetPaginatedScrolling(PRBool aResult) = 0; + NS_HIDDEN_(void) SetPaginatedScrolling(PRBool aResult); /** * Return true if this presentation context can scroll for paginated @@ -322,7 +376,7 @@ public: * @param aActualRect returns the size of the actual device/surface * @param aRect returns the adjusted size */ - virtual void GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0; + NS_HIDDEN_(void) GetPageDim(nsRect* aActualRect, nsRect* aAdjRect); /** * Sets the "adjusted" rect for the page Dimimensions, @@ -331,20 +385,27 @@ public: * * @param aRect returns the adjusted size */ - virtual void SetPageDim(nsRect* aRect) = 0; + NS_HIDDEN_(void) SetPageDim(const nsRect& aRect); float PixelsToTwips() const { return mDeviceContext->DevUnitsToAppUnits(); } float TwipsToPixels() const { return mDeviceContext->AppUnitsToDevUnits(); } - NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0; + NS_HIDDEN_(float) TwipsToPixelsForFonts() const; //XXX this is probably not an ideal name. MMP /** * Do pixels to twips conversion taking into account * differing size of a "pixel" from device to device. */ - NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; + NS_HIDDEN_(float) ScaledPixelsToTwips() const; + + /* Convenience method for converting one pixel value to twips */ + nscoord IntScaledPixelsToTwips(nscoord aPixels) const + { return NSIntPixelsToTwips(aPixels, ScaledPixelsToTwips()); } + + /* Set whether twip scaling is used */ + void SetScalingOfTwips(PRBool aOn) { mDoScaledTwips = aOn; } nsIDeviceContext* DeviceContext() { return mDeviceContext; } nsIEventStateManager* EventStateManager() { return mEventManager; } @@ -394,14 +455,20 @@ public: * * @lina 07/12/2000 */ - virtual PRBool BidiEnabled() const = 0; + virtual PRBool BidiEnabledExternal() const; + NS_HIDDEN_(PRBool) BidiEnabledInternal() const; +#ifdef _IMPL_NS_LAYOUT + PRBool BidiEnabled() const { return BidiEnabledInternal(); } +#else + PRBool BidiEnabled() const { return BidiEnabledExternal(); } +#endif /** * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm * * @lina 07/12/2000 */ - virtual void SetBidiEnabled(PRBool aBidiEnabled) const = 0; + NS_HIDDEN_(void) SetBidiEnabled(PRBool aBidiEnabled) const; /** * Set visual or implicit mode into the pres context. @@ -435,17 +502,18 @@ public: /** * Get a Bidi presentation utilities object */ - NS_IMETHOD GetBidiUtils(nsBidiPresUtils** aBidiUtils) = 0; + NS_HIDDEN_(nsBidiPresUtils*) GetBidiUtils(); /** * Set the Bidi options for the presentation context */ - NS_IMETHOD SetBidi(PRUint32 aBidiOptions, PRBool aForceReflow = PR_FALSE) = 0; + NS_HIDDEN_(void) SetBidi(PRUint32 aBidiOptions, + PRBool aForceReflow = PR_FALSE); /** * Get the Bidi options for the presentation context */ - NS_IMETHOD GetBidi(PRUint32* aBidiOptions) const = 0; + NS_HIDDEN_(PRUint32) GetBidi() const { return mBidi; } /** * Set the Bidi capabilities of the system @@ -478,7 +546,7 @@ public: /* * Obtain a native them for rendering our widgets (both form controls and html) */ - NS_IMETHOD GetTheme(nsITheme** aResult) = 0; + NS_HIDDEN_(nsITheme*) GetTheme(); /* * Notify the pres context that the theme has changed. An internal switch @@ -486,23 +554,42 @@ public: * Otherwise, the OS is telling us that the native theme for the platform * has changed. */ - NS_IMETHOD ThemeChanged() = 0; + NS_HIDDEN_(void) ThemeChanged(); /* * Notify the pres context that a system color has changed */ - NS_IMETHOD SysColorChanged() = 0; + NS_HIDDEN_(void) SysColorChanged(); + + /** Printing methods below should only be used for Medium() == print **/ + NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings); + + nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } #ifdef MOZ_REFLOW_PERF - NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; - NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; + NS_HIDDEN_(void) CountReflows(const char * aName, + PRUint32 aType, nsIFrame * aFrame); + NS_HIDDEN_(void) PaintCount(const char * aName, + nsIRenderingContext* aRendingContext, + nsIFrame * aFrame, PRUint32 aColor); #endif protected: + NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, PRUint16 aMode); + NS_HIDDEN_(void) GetDocumentColorPreferences(); + NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName); + static NS_HIDDEN_(int) PR_CALLBACK PrefChangedCallback(const char*, void*); + + NS_HIDDEN_(void) GetUserPreferences(); + NS_HIDDEN_(void) GetFontPreferences(); + + NS_HIDDEN_(void) UpdateCharSet(const char* aCharSet); + // IMPORTANT: The ownership implicit in the following member variables // has been explicitly checked. If you add any members to this class, // please make the ownership explicit (pinkerton, scc). + nsPresContextType mType; nsIPresShell* mShell; // [WEAK] nsIDeviceContext* mDeviceContext; // [STRONG] could be weak, but // better safe than sorry. @@ -517,11 +604,24 @@ protected: nsILinkHandler* mLinkHandler; // [WEAK] nsIAtom* mLangGroup; // [STRONG] + nsSupportsHashtable mImageLoaders; + nsWeakPtr mContainer; + +#ifdef IBMBIDI + nsBidiPresUtils* mBidiUtils; + nsCString mCharset; // the charset we are using +#endif + + nsCOMPtr mTheme; + nsCOMPtr mLangService; + nsCOMPtr mPrintSettings; + nsLanguageSpecificTransformType mLanguageSpecificTransformType; PRInt32 mFontScaler; nscoord mMinimumFontSize; nsRect mVisibleArea; + nsRect mPageDim; nscolor mDefaultColor; nscolor mBackgroundColor; @@ -538,6 +638,15 @@ protected: nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; + PRUint16 mImageAnimationModePref; + + nsFont mDefaultVariableFont; + nsFont mDefaultFixedFont; + nsFont mDefaultSerifFont; + nsFont mDefaultSansSerifFont; + nsFont mDefaultMonospaceFont; + nsFont mDefaultCursiveFont; + nsFont mDefaultFantasyFont; unsigned mUseDocumentFonts : 1; unsigned mUseDocumentColors : 1; @@ -551,10 +660,35 @@ protected: unsigned mNoTheme : 1; unsigned mPaginated : 1; unsigned mCanPaginatedScroll : 1; + unsigned mDoScaledTwips : 1; + unsigned mEnableJapaneseTransform : 1; #ifdef IBMBIDI unsigned mIsVisual : 1; unsigned mIsBidiSystem : 1; + + PRUint32 mBidi; #endif +#ifdef DEBUG + PRBool mInitialized; +#endif + + +private: + + ~nsIPresContext() NS_HIDDEN; + + // these are private, use the list in nsFont.h if you want a public list + enum { + eDefaultFont_Variable, + eDefaultFont_Fixed, + eDefaultFont_Serif, + eDefaultFont_SansSerif, + eDefaultFont_Monospace, + eDefaultFont_Cursive, + eDefaultFont_Fantasy, + eDefaultFont_COUNT + }; + }; // Bit values for StartLoadImage's aImageStatus @@ -562,11 +696,6 @@ protected: #define NS_LOAD_IMAGE_STATUS_SIZE 0x2 #define NS_LOAD_IMAGE_STATUS_BITS 0x4 -// Factory method to create a "galley" presentation context (galley is -// a kind of view that has no limit to the size of a page) -nsresult -NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/layout/base/public/nsIPrintContext.h b/layout/base/public/nsIPrintContext.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/base/public/nsIPrintPreviewContext.h b/layout/base/public/nsIPrintPreviewContext.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index f33b591aea8..ea7e89d4e63 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -46,11 +46,18 @@ #include "nsIPresShell.h" #include "nsRect.h" #include "nsIDeviceContext.h" +#include "nsHashtable.h" +#include "nsFont.h" +#include "nsIWeakReference.h" +#include "nsITheme.h" +#include "nsILanguageAtomService.h" +#include "nsIObserver.h" +#include "nsCRT.h" +#include "nsIPrintSettings.h" #ifdef IBMBIDI class nsBidiPresUtils; #endif // IBMBIDI -struct nsFont; struct nsRect; class imgIRequest; @@ -69,7 +76,6 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; class nsIAtom; -class nsITheme; struct nsStyleStruct; struct nsStyleBackground; @@ -78,8 +84,8 @@ class nsIRenderingContext; #endif #define NS_IPRESCONTEXT_IID \ -{ 0xa394329f, 0x3b10, 0x49ac, \ - {0x8f, 0xf2, 0xeb, 0x0b, 0x66, 0x93, 0x82, 0x38} } +{ 0x96e4bc06, 0x8e72, 0x4941, \ + {0xa6, 0x6c, 0x70, 0xee, 0x7d, 0x1b, 0x58, 0x21} } enum nsWidgetType { eWidgetType_Button = 1, @@ -109,20 +115,35 @@ const PRUint8 kPresContext_DefaultFixedFont_ID = 0x01; // kGenericFont_moz_fi // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. -class nsIPresContext : public nsISupports { +class nsIPresContext : public nsIObserver { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRESCONTEXT_IID) + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + enum nsPresContextType { + eContext_Galley, // unpaginated screen presentation + eContext_PrintPreview, // paginated screen presentation + eContext_Print // paginated printer presentation + }; + + nsIPresContext(nsPresContextType aType) NS_HIDDEN; + /** * Initialize the presentation context from a particular device. */ - NS_IMETHOD Init(nsIDeviceContext* aDeviceContext) = 0; + NS_HIDDEN_(nsresult) Init(nsIDeviceContext* aDeviceContext); /** * Set the presentation shell that this context is bound to. * A presentation context may only be bound to a single shell. */ - NS_IMETHOD SetShell(nsIPresShell* aShell) = 0; + NS_HIDDEN_(void) SetShell(nsIPresShell* aShell); + + + NS_HIDDEN_(nsPresContextType) Type() const { return mType; } /** * Get the PresentationShell that this context is bound to. @@ -151,13 +172,21 @@ public: * relying on a default. */ nsCompatibility CompatibilityMode() const { return mCompatibilityMode; } - virtual void SetCompatibilityMode(nsCompatibility aMode) = 0; + NS_HIDDEN_(void) SetCompatibilityMode(nsCompatibility aMode); /** * Access the image animation mode for this context */ PRUint16 ImageAnimationMode() const { return mImageAnimationMode; } - virtual void SetImageAnimationMode(PRUint16 aMode) = 0; + virtual void SetImageAnimationModeExternal(PRUint16 aMode); + NS_HIDDEN_(void) SetImageAnimationModeInternal(PRUint16 aMode); +#ifdef _IMPL_NS_LAYOUT + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeInternal(aMode); } +#else + void SetImageAnimationMode(PRUint16 aMode) + { SetImageAnimationModeExternal(aMode); } +#endif /** * Get cached look and feel service. This is faster than obtaining it @@ -173,7 +202,7 @@ public: /** * Clear style data from the root frame downwards, and reflow. */ - virtual void ClearStyleDataAndReflow() = 0; + NS_HIDDEN_(void) ClearStyleDataAndReflow(); void* AllocateFromShell(size_t aSize) { @@ -191,13 +220,31 @@ public: /** * Get the font metrics for a given font. */ - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0; + virtual already_AddRefed + GetMetricsForExternal(const nsFont& aFont); + NS_HIDDEN_(already_AddRefed) + GetMetricsForInternal(const nsFont& aFont); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForInternal(aFont); } +#else + already_AddRefed GetMetricsFor(const nsFont& aFont) + { return GetMetricsForExternal(aFont); } +#endif /** * Get the default font correponding to the given ID. This object is * read-only, you must copy the font to modify it. */ - virtual const nsFont* GetDefaultFont(PRUint8 aFontID) const = 0; + virtual const nsFont* GetDefaultFontExternal(PRUint8 aFontID) const; + NS_HIDDEN_(const nsFont*) GetDefaultFontInternal(PRUint8 aFontID) const; +#ifdef _IMPL_NS_LAYOUT + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontInternal(aFontID); } +#else + const nsFont* GetDefaultFont(PRUint8 aFontID) const + { return GetDefaultFontExternal(aFontID); } +#endif /** Get a cached boolean pref, by its type */ // * - initially created for bugs 31816, 20760, 22963 @@ -263,19 +310,26 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - virtual nsresult LoadImage(imgIRequest* aImage, - nsIFrame* aTargetFrame, - imgIRequest **aRequest) = 0; + NS_HIDDEN_(imgIRequest*) LoadImage(imgIRequest* aImage, + nsIFrame* aTargetFrame); /** * This method is called when a frame is being destroyed to * ensure that the image load gets disassociated from the prescontext */ - virtual void StopImagesFor(nsIFrame* aTargetFrame) = 0; + NS_HIDDEN_(void) StopImagesFor(nsIFrame* aTargetFrame); - virtual void SetContainer(nsISupports* aContainer) = 0; + NS_HIDDEN_(void) SetContainer(nsISupports* aContainer); - virtual already_AddRefed GetContainer() = 0; + virtual already_AddRefed GetContainerExternal(); + NS_HIDDEN_(already_AddRefed) GetContainerInternal(); +#ifdef _IMPL_NS_LAYOUT + already_AddRefed GetContainer() + { return GetContainerInternal(); } +#else + already_AddRefed GetContainer() + { return GetContainerExternal(); } +#endif // XXX this are going to be replaced with set/get container void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; } @@ -305,7 +359,7 @@ public: * Sets whether the presentation context can scroll for a paginated * context. */ - virtual void SetPaginatedScrolling(PRBool aResult) = 0; + NS_HIDDEN_(void) SetPaginatedScrolling(PRBool aResult); /** * Return true if this presentation context can scroll for paginated @@ -322,7 +376,7 @@ public: * @param aActualRect returns the size of the actual device/surface * @param aRect returns the adjusted size */ - virtual void GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0; + NS_HIDDEN_(void) GetPageDim(nsRect* aActualRect, nsRect* aAdjRect); /** * Sets the "adjusted" rect for the page Dimimensions, @@ -331,20 +385,27 @@ public: * * @param aRect returns the adjusted size */ - virtual void SetPageDim(nsRect* aRect) = 0; + NS_HIDDEN_(void) SetPageDim(const nsRect& aRect); float PixelsToTwips() const { return mDeviceContext->DevUnitsToAppUnits(); } float TwipsToPixels() const { return mDeviceContext->AppUnitsToDevUnits(); } - NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0; + NS_HIDDEN_(float) TwipsToPixelsForFonts() const; //XXX this is probably not an ideal name. MMP /** * Do pixels to twips conversion taking into account * differing size of a "pixel" from device to device. */ - NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; + NS_HIDDEN_(float) ScaledPixelsToTwips() const; + + /* Convenience method for converting one pixel value to twips */ + nscoord IntScaledPixelsToTwips(nscoord aPixels) const + { return NSIntPixelsToTwips(aPixels, ScaledPixelsToTwips()); } + + /* Set whether twip scaling is used */ + void SetScalingOfTwips(PRBool aOn) { mDoScaledTwips = aOn; } nsIDeviceContext* DeviceContext() { return mDeviceContext; } nsIEventStateManager* EventStateManager() { return mEventManager; } @@ -394,14 +455,20 @@ public: * * @lina 07/12/2000 */ - virtual PRBool BidiEnabled() const = 0; + virtual PRBool BidiEnabledExternal() const; + NS_HIDDEN_(PRBool) BidiEnabledInternal() const; +#ifdef _IMPL_NS_LAYOUT + PRBool BidiEnabled() const { return BidiEnabledInternal(); } +#else + PRBool BidiEnabled() const { return BidiEnabledExternal(); } +#endif /** * Set bidi enabled. This means we should apply the Unicode Bidi Algorithm * * @lina 07/12/2000 */ - virtual void SetBidiEnabled(PRBool aBidiEnabled) const = 0; + NS_HIDDEN_(void) SetBidiEnabled(PRBool aBidiEnabled) const; /** * Set visual or implicit mode into the pres context. @@ -435,17 +502,18 @@ public: /** * Get a Bidi presentation utilities object */ - NS_IMETHOD GetBidiUtils(nsBidiPresUtils** aBidiUtils) = 0; + NS_HIDDEN_(nsBidiPresUtils*) GetBidiUtils(); /** * Set the Bidi options for the presentation context */ - NS_IMETHOD SetBidi(PRUint32 aBidiOptions, PRBool aForceReflow = PR_FALSE) = 0; + NS_HIDDEN_(void) SetBidi(PRUint32 aBidiOptions, + PRBool aForceReflow = PR_FALSE); /** * Get the Bidi options for the presentation context */ - NS_IMETHOD GetBidi(PRUint32* aBidiOptions) const = 0; + NS_HIDDEN_(PRUint32) GetBidi() const { return mBidi; } /** * Set the Bidi capabilities of the system @@ -478,7 +546,7 @@ public: /* * Obtain a native them for rendering our widgets (both form controls and html) */ - NS_IMETHOD GetTheme(nsITheme** aResult) = 0; + NS_HIDDEN_(nsITheme*) GetTheme(); /* * Notify the pres context that the theme has changed. An internal switch @@ -486,23 +554,42 @@ public: * Otherwise, the OS is telling us that the native theme for the platform * has changed. */ - NS_IMETHOD ThemeChanged() = 0; + NS_HIDDEN_(void) ThemeChanged(); /* * Notify the pres context that a system color has changed */ - NS_IMETHOD SysColorChanged() = 0; + NS_HIDDEN_(void) SysColorChanged(); + + /** Printing methods below should only be used for Medium() == print **/ + NS_HIDDEN_(void) SetPrintSettings(nsIPrintSettings *aPrintSettings); + + nsIPrintSettings* GetPrintSettings() { return mPrintSettings; } #ifdef MOZ_REFLOW_PERF - NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; - NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; + NS_HIDDEN_(void) CountReflows(const char * aName, + PRUint32 aType, nsIFrame * aFrame); + NS_HIDDEN_(void) PaintCount(const char * aName, + nsIRenderingContext* aRendingContext, + nsIFrame * aFrame, PRUint32 aColor); #endif protected: + NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, PRUint16 aMode); + NS_HIDDEN_(void) GetDocumentColorPreferences(); + NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName); + static NS_HIDDEN_(int) PR_CALLBACK PrefChangedCallback(const char*, void*); + + NS_HIDDEN_(void) GetUserPreferences(); + NS_HIDDEN_(void) GetFontPreferences(); + + NS_HIDDEN_(void) UpdateCharSet(const char* aCharSet); + // IMPORTANT: The ownership implicit in the following member variables // has been explicitly checked. If you add any members to this class, // please make the ownership explicit (pinkerton, scc). + nsPresContextType mType; nsIPresShell* mShell; // [WEAK] nsIDeviceContext* mDeviceContext; // [STRONG] could be weak, but // better safe than sorry. @@ -517,11 +604,24 @@ protected: nsILinkHandler* mLinkHandler; // [WEAK] nsIAtom* mLangGroup; // [STRONG] + nsSupportsHashtable mImageLoaders; + nsWeakPtr mContainer; + +#ifdef IBMBIDI + nsBidiPresUtils* mBidiUtils; + nsCString mCharset; // the charset we are using +#endif + + nsCOMPtr mTheme; + nsCOMPtr mLangService; + nsCOMPtr mPrintSettings; + nsLanguageSpecificTransformType mLanguageSpecificTransformType; PRInt32 mFontScaler; nscoord mMinimumFontSize; nsRect mVisibleArea; + nsRect mPageDim; nscolor mDefaultColor; nscolor mBackgroundColor; @@ -538,6 +638,15 @@ protected: nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; + PRUint16 mImageAnimationModePref; + + nsFont mDefaultVariableFont; + nsFont mDefaultFixedFont; + nsFont mDefaultSerifFont; + nsFont mDefaultSansSerifFont; + nsFont mDefaultMonospaceFont; + nsFont mDefaultCursiveFont; + nsFont mDefaultFantasyFont; unsigned mUseDocumentFonts : 1; unsigned mUseDocumentColors : 1; @@ -551,10 +660,35 @@ protected: unsigned mNoTheme : 1; unsigned mPaginated : 1; unsigned mCanPaginatedScroll : 1; + unsigned mDoScaledTwips : 1; + unsigned mEnableJapaneseTransform : 1; #ifdef IBMBIDI unsigned mIsVisual : 1; unsigned mIsBidiSystem : 1; + + PRUint32 mBidi; #endif +#ifdef DEBUG + PRBool mInitialized; +#endif + + +private: + + ~nsIPresContext() NS_HIDDEN; + + // these are private, use the list in nsFont.h if you want a public list + enum { + eDefaultFont_Variable, + eDefaultFont_Fixed, + eDefaultFont_Serif, + eDefaultFont_SansSerif, + eDefaultFont_Monospace, + eDefaultFont_Cursive, + eDefaultFont_Fantasy, + eDefaultFont_COUNT + }; + }; // Bit values for StartLoadImage's aImageStatus @@ -562,11 +696,6 @@ protected: #define NS_LOAD_IMAGE_STATUS_SIZE 0x2 #define NS_LOAD_IMAGE_STATUS_BITS 0x4 -// Factory method to create a "galley" presentation context (galley is -// a kind of view that has no limit to the size of a page) -nsresult -NS_NewGalleyContext(nsIPresContext** aInstancePtrResult); - #ifdef MOZ_REFLOW_PERF #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ diff --git a/layout/base/src/Makefile.in b/layout/base/src/Makefile.in index 177648ed5d3..e69de29bb2d 100644 --- a/layout/base/src/Makefile.in +++ b/layout/base/src/Makefile.in @@ -1,106 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = layout -LIBRARY_NAME = gkbase_s -REQUIRES = xpcom \ - string \ - dom \ - content \ - gfx \ - widget \ - view \ - locale \ - webshell \ - necko \ - uconv \ - pref \ - uriloader \ - docshell \ - imglib2 \ - js \ - xpconnect \ - $(NULL) - -CPPSRCS = \ - nsAutoCopy.cpp \ - nsCaret.cpp \ - nsFrameList.cpp \ - nsFrameTraversal.cpp \ - nsFrameUtil.cpp \ - nsGalleyContext.cpp \ - nsImageLoader.cpp \ - nsIntervalSet.cpp \ - nsLayoutDebugger.cpp \ - nsLayoutHistoryState.cpp \ - nsLayoutUtils.cpp \ - nsPresContext.cpp \ - nsPresState.cpp \ - nsPrintContext.cpp \ - nsPrintPreviewContext.cpp \ - nsSpaceManager.cpp \ - nsStyleChangeList.cpp \ - $(NULL) - -ifdef IBMBIDI -CPPSRCS += \ - nsBidiPresUtils.cpp \ - nsBidi.cpp \ - $(NULL) -endif - -# we don't want the shared lib, but we want to force the creation of a static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -LOCAL_INCLUDES = \ - -I$(topsrcdir)/content/events/src \ - -I$(srcdir)/../../html/base/src \ - -I$(srcdir)/../../html/style/src \ - -I$(srcdir)/../../xul/base/src \ - -I$(srcdir)/../../xul/content/src \ - $(NULL) - -DEFINES += -D_IMPL_NS_LAYOUT diff --git a/layout/base/src/nsBidiPresUtils.cpp b/layout/base/src/nsBidiPresUtils.cpp index ffc12d7f206..8389177962f 100644 --- a/layout/base/src/nsBidiPresUtils.cpp +++ b/layout/base/src/nsBidiPresUtils.cpp @@ -819,8 +819,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, nsresult rv = NS_OK; // ahmed //adjusted for correct numeral shaping - PRUint32 bidiOptions; - aPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = aPresContext->GetBidi(); switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { case IBMBIDI_NUMERAL_HINDI: diff --git a/layout/base/src/nsGalleyContext.cpp b/layout/base/src/nsGalleyContext.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 6e7b129c885..806ef80d932 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -35,7 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" -#include "nsPresContext.h" +#include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" @@ -96,9 +96,9 @@ MakeColorPref(const char *colstr) } int PR_CALLBACK -nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) +nsIPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) { - nsPresContext* presContext = (nsPresContext*)instance_data; + nsIPresContext* presContext = (nsIPresContext*)instance_data; NS_ASSERTION(nsnull != presContext, "bad instance data"); if (nsnull != presContext) { @@ -109,7 +109,7 @@ nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) #ifdef IBMBIDI static PRBool -IsVisualCharset(const nsCAutoString& aCharset) +IsVisualCharset(const nsCString& aCharset) { if (aCharset.LowerCaseEqualsLiteral("ibm864") // Arabic//ahmed || aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew @@ -135,32 +135,32 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); - // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // NOTE! nsIPresContext::operator new() zeroes out all members, so don't // bother initializing members to 0. -nsPresContext::nsPresContext() - : mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), +nsIPresContext::nsIPresContext(nsPresContextType aType) + : mType(aType), + mCompatibilityMode(eCompatibility_FullStandards), + mImageAnimationModePref(imgIContainer::kNormalAnimMode), + mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), - mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), - mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) { - - // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // NOTE! nsIPresContext::operator new() zeroes out all members, so don't // bother initializing members to 0. - mCompatibilityMode = eCompatibility_FullStandards; - mImageAnimationMode = imgIContainer::kNormalAnimMode; - mImageAnimationModePref = imgIContainer::kNormalAnimMode; + mDoScaledTwips = PR_TRUE; SetBackgroundImageDraw(PR_TRUE); // always draw the background SetBackgroundColorDraw(PR_TRUE); @@ -184,9 +184,26 @@ nsPresContext::nsPresContext() mFocusRingWidth = 1; mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown; + if (aType == eContext_Galley) { + mMedium = nsLayoutAtoms::screen; + mImageAnimationMode = imgIContainer::kNormalAnimMode; + } else { + SetBackgroundImageDraw(PR_FALSE); + SetBackgroundColorDraw(PR_FALSE); + mImageAnimationMode = imgIContainer::kDontAnimMode; + mNeverAnimate = PR_TRUE; + mMedium = nsLayoutAtoms::print; + mPaginated = PR_TRUE; + if (aType == eContext_PrintPreview) { + mCanPaginatedScroll = PR_TRUE; + mPageDim.SetRect(-1, -1, -1, -1); + } else { + mPageDim.SetRect(0, 0, 0, 0); + } + } } -nsPresContext::~nsPresContext() +nsIPresContext::~nsIPresContext() { mImageLoaders.Enumerate(destroy_loads); @@ -200,28 +217,28 @@ nsPresContext::~nsPresContext() // Unregister preference callbacks nsContentUtils::UnregisterPrefCallback("font.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.display.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.underline_anchors", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.anchor_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.active_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("browser.visited_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("network.image.imageBehavior", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::UnregisterPrefCallback("image.animation_mode", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); #ifdef IBMBIDI nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this); @@ -234,7 +251,7 @@ nsPresContext::~nsPresContext() NS_IF_RELEASE(mLangGroup); } -NS_IMPL_ISUPPORTS2(nsPresContext, nsIPresContext, nsIObserver) +NS_IMPL_ISUPPORTS2(nsIPresContext, nsIPresContext, nsIObserver) #define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \ _pref.Assign(_s0); \ @@ -251,7 +268,7 @@ static const char* const kGenericFont[] = { }; void -nsPresContext::GetFontPreferences() +nsIPresContext::GetFontPreferences() { if (!mLangGroup) return; @@ -272,8 +289,7 @@ nsPresContext::GetFontPreferences() font.minimum-size.[langGroup] = integer - settable by the user */ - float p2t; - GetScaledPixelsToTwips(&p2t); + float p2t = ScaledPixelsToTwips(); mDefaultVariableFont.size = NSFloatPixelsToTwips((float)16, p2t); mDefaultFixedFont.size = NSFloatPixelsToTwips((float)13, p2t); @@ -403,7 +419,7 @@ nsPresContext::GetFontPreferences() } void -nsPresContext::GetDocumentColorPreferences() +nsIPresContext::GetDocumentColorPreferences() { PRInt32 useAccessibilityTheme = 0; PRBool usePrefColors = PR_TRUE; @@ -456,7 +472,7 @@ nsPresContext::GetDocumentColorPreferences() } void -nsPresContext::GetUserPreferences() +nsIPresContext::GetUserPreferences() { mFontScaler = nsContentUtils::GetIntPref("browser.display.base_font_scaler", @@ -571,7 +587,7 @@ nsPresContext::GetUserPreferences() } void -nsPresContext::ClearStyleDataAndReflow() +nsIPresContext::ClearStyleDataAndReflow() { if (mShell) { // Clear out all our style data. @@ -586,7 +602,7 @@ nsPresContext::ClearStyleDataAndReflow() } void -nsPresContext::PreferenceChanged(const char* aPrefName) +nsIPresContext::PreferenceChanged(const char* aPrefName) { nsCOMPtr docShell(do_QueryReferent(mContainer)); if (docShell) { @@ -605,11 +621,11 @@ nsPresContext::PreferenceChanged(const char* aPrefName) } mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); } -NS_IMETHODIMP -nsPresContext::Init(nsIDeviceContext* aDeviceContext) +nsresult +nsIPresContext::Init(nsIDeviceContext* aDeviceContext) { NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context"); NS_ENSURE_ARG(aDeviceContext); @@ -635,28 +651,28 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) // Register callbacks so we're notified when the preferences change nsContentUtils::RegisterPrefCallback("font.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.display.", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.underline_anchors", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.anchor_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.active_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("browser.visited_color", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("network.image.imageBehavior", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); nsContentUtils::RegisterPrefCallback("image.animation_mode", - nsPresContext::PrefChangedCallback, + nsIPresContext::PrefChangedCallback, this); #ifdef IBMBIDI nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback, @@ -680,8 +696,8 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) // Note: We don't hold a reference on the shell; it has a reference to // us -NS_IMETHODIMP -nsPresContext::SetShell(nsIPresShell* aShell) +void +nsIPresContext::SetShell(nsIPresShell* aShell) { if (mShell) { // Remove ourselves as the charset observer from the shell's doc, because @@ -702,7 +718,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) if (doc) { nsIURI *baseURI = doc->GetBaseURI(); - if (!mNeverAnimate && baseURI) { + if (mMedium != nsLayoutAtoms::print && baseURI) { PRBool isChrome = PR_FALSE; PRBool isRes = PR_FALSE; baseURI->SchemeIs("chrome", &isChrome); @@ -721,11 +737,10 @@ nsPresContext::SetShell(nsIPresShell* aShell) } } } - return NS_OK; } void -nsPresContext::UpdateCharSet(const char* aCharSet) +nsIPresContext::UpdateCharSet(const char* aCharSet) { if (mLangService) { NS_IF_RELEASE(mLangGroup); @@ -757,24 +772,24 @@ nsPresContext::UpdateCharSet(const char* aCharSet) } NS_IMETHODIMP -nsPresContext::Observe(nsISupports* aSubject, - const char* aTopic, - const PRUnichar* aData) +nsIPresContext::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) { if (!nsCRT::strcmp(aTopic, "charset")) { UpdateCharSet(NS_LossyConvertUCS2toASCII(aData).get()); mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); return NS_OK; } - NS_WARNING("unrecognized topic in nsPresContext::Observe"); + NS_WARNING("unrecognized topic in nsIPresContext::Observe"); return NS_ERROR_FAILURE; } void -nsPresContext::SetCompatibilityMode(nsCompatibility aMode) +nsIPresContext::SetCompatibilityMode(nsCompatibility aMode) { mCompatibilityMode = aMode; @@ -813,7 +828,7 @@ PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void // // Walks content and set the animation mode // this is a way to turn on/off image animations -void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) +void nsIPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) { nsCOMPtr imgContent(do_QueryInterface(aParent)); if (imgContent) { @@ -830,12 +845,16 @@ void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode) } void -nsPresContext::SetImageAnimationMode(PRUint16 aMode) +nsIPresContext::SetImageAnimationModeInternal(PRUint16 aMode) { NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode || aMode == imgIContainer::kDontAnimMode || aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!"); + // Image animation mode cannot be changed when rendering to a printer. + if (mMedium == nsLayoutAtoms::print) + return; + // This hash table contains a list of background images // so iterate over it and set the mode mImageLoaders.Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode)); @@ -856,19 +875,28 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode) mImageAnimationMode = aMode; } -NS_IMETHODIMP -nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) +void +nsIPresContext::SetImageAnimationModeExternal(PRUint16 aMode) { - NS_PRECONDITION(aResult, "null out param"); + SetImageAnimationModeInternal(aMode); +} +already_AddRefed +nsIPresContext::GetMetricsForInternal(const nsFont& aFont) +{ nsIFontMetrics* metrics = nsnull; mDeviceContext->GetMetricsFor(aFont, mLangGroup, metrics); - *aResult = metrics; - return NS_OK; + return metrics; +} + +already_AddRefed +nsIPresContext::GetMetricsForExternal(const nsFont& aFont) +{ + return GetMetricsForInternal(aFont); } const nsFont* -nsPresContext::GetDefaultFont(PRUint8 aFontID) const +nsIPresContext::GetDefaultFontInternal(PRUint8 aFontID) const { const nsFont *font; switch (aFontID) { @@ -903,14 +931,15 @@ nsPresContext::GetDefaultFont(PRUint8 aFontID) const return font; } -NS_IMETHODIMP -nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const +const nsFont* +nsIPresContext::GetDefaultFontExternal(PRUint8 aFontID) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + return GetDefaultFontInternal(aFontID); +} +float +nsIPresContext::TwipsToPixelsForFonts() const +{ float app2dev; #ifdef NS_PRINT_PREVIEW // If an alternative DC is available we want to use @@ -927,32 +956,30 @@ nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const #else app2dev = mDeviceContext->AppUnitsToDevUnits(); #endif - *aResult = app2dev; - return NS_OK; + return app2dev; } -NS_IMETHODIMP -nsPresContext::GetScaledPixelsToTwips(float* aResult) const +float +nsIPresContext::ScaledPixelsToTwips() const { - NS_PRECONDITION(aResult, "null out param"); - float scale; float p2t; p2t = mDeviceContext->DevUnitsToAppUnits(); - mDeviceContext->GetCanonicalPixelScale(scale); - scale = p2t * scale; + if (mDoScaledTwips) { + mDeviceContext->GetCanonicalPixelScale(scale); + scale = p2t * scale; + } else { + scale = p2t; + } - *aResult = scale; - return NS_OK; + return scale; } -nsresult -nsPresContext::LoadImage(imgIRequest* aImage, - nsIFrame* aTargetFrame,//may be null (precached image) - imgIRequest **aRequest) +imgIRequest* +nsIPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame) { // look and see if we have a loader for the target frame. @@ -962,7 +989,7 @@ nsPresContext::LoadImage(imgIRequest* aImage, if (!loader) { loader = new nsImageLoader(); if (!loader) - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; NS_ADDREF(loader); // new @@ -972,16 +999,15 @@ nsPresContext::LoadImage(imgIRequest* aImage, loader->Load(aImage); - NS_IF_ADDREF(*aRequest = loader->GetRequest()); - + imgIRequest *request = loader->GetRequest(); NS_RELEASE(loader); - return NS_OK; + return request; } void -nsPresContext::StopImagesFor(nsIFrame* aTargetFrame) +nsIPresContext::StopImagesFor(nsIFrame* aTargetFrame) { nsVoidKey key(aTargetFrame); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs @@ -996,7 +1022,7 @@ nsPresContext::StopImagesFor(nsIFrame* aTargetFrame) void -nsPresContext::SetContainer(nsISupports* aHandler) +nsIPresContext::SetContainer(nsISupports* aHandler) { mContainer = do_GetWeakReference(aHandler); if (mContainer) { @@ -1005,7 +1031,7 @@ nsPresContext::SetContainer(nsISupports* aHandler) } already_AddRefed -nsPresContext::GetContainer() +nsIPresContext::GetContainerInternal() { nsISupports *result; if (mContainer) @@ -1016,16 +1042,22 @@ nsPresContext::GetContainer() return result; } +already_AddRefed +nsIPresContext::GetContainerExternal() +{ + return GetContainerInternal(); +} + #ifdef IBMBIDI PRBool -nsPresContext::BidiEnabled() const +nsIPresContext::BidiEnabledInternal() const { PRBool bidiEnabled = PR_FALSE; - NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled"); + NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsIPresContext::GetBidiEnabled"); if (mShell) { nsCOMPtr doc; mShell->GetDocument(getter_AddRefs(doc) ); - NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled"); + NS_ASSERTION(doc, "PresShell has no document in nsIPresContext::GetBidiEnabled"); if (doc) { bidiEnabled = doc->GetBidiEnabled(); } @@ -1033,8 +1065,14 @@ nsPresContext::BidiEnabled() const return bidiEnabled; } +PRBool +nsIPresContext::BidiEnabledExternal() const +{ + return BidiEnabledInternal(); +} + void -nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const +nsIPresContext::SetBidiEnabled(PRBool aBidiEnabled) const { if (mShell) { nsCOMPtr doc; @@ -1045,23 +1083,17 @@ nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const } } -NS_IMETHODIMP -nsPresContext::GetBidiUtils(nsBidiPresUtils** aBidiUtils) +nsBidiPresUtils* +nsIPresContext::GetBidiUtils() { - nsresult rv = NS_OK; - - if (!mBidiUtils) { + if (!mBidiUtils) mBidiUtils = new nsBidiPresUtils; - if (!mBidiUtils) { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } - *aBidiUtils = mBidiUtils; - return rv; + + return mBidiUtils; } -NS_IMETHODIMP -nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) +void +nsIPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) { mBidi = aSource; if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(mBidi) @@ -1078,22 +1110,13 @@ nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) SetVisualMode(IsVisualCharset(mCharset) ); } if (mShell && aForceReflow) { - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); } - return NS_OK; -} - -NS_IMETHODIMP -nsPresContext::GetBidi(PRUint32* aDest) const -{ - if (aDest) - *aDest = mBidi; - return NS_OK; } #endif //IBMBIDI -NS_IMETHODIMP -nsPresContext::GetTheme(nsITheme** aResult) +nsITheme* +nsIPresContext::GetTheme() { if (!mNoTheme && !mTheme) { mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1"); @@ -1101,13 +1124,11 @@ nsPresContext::GetTheme(nsITheme** aResult) mNoTheme = PR_TRUE; } - *aResult = mTheme; - NS_IF_ADDREF(*aResult); - return mTheme ? NS_OK : NS_ERROR_FAILURE; + return mTheme; } -NS_IMETHODIMP -nsPresContext::ThemeChanged() +void +nsIPresContext::ThemeChanged() { // Tell the theme that it changed, so it can flush any handles to stale theme // data. @@ -1118,14 +1139,12 @@ nsPresContext::ThemeChanged() if (mLookAndFeel) mLookAndFeel->LookAndFeelChanged(); - if (!mShell) - return NS_OK; - - return mShell->ReconstructStyleData(); + if (mShell) + mShell->ReconstructStyleData(); } -NS_IMETHODIMP -nsPresContext::SysColorChanged() +void +nsIPresContext::SysColorChanged() { if (mLookAndFeel) { // Don't use the cached values for the system colors @@ -1150,26 +1169,79 @@ nsPresContext::SysColorChanged() // data without reflowing/updating views will lead to incorrect change hints // later, because when generating change hints, any style structs which have // been cleared and not reread are assumed to not be used at all. - nsPresContext::ClearStyleDataAndReflow(); + ClearStyleDataAndReflow(); +} + +void +nsIPresContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) +{ + if (mMedium == nsLayoutAtoms::print) { + if (aActualRect) { + PRInt32 width, height; + nsresult rv = mDeviceContext->GetDeviceSurfaceDimensions(width, height); + if (NS_SUCCEEDED(rv)) + aActualRect->SetRect(0, 0, width, height); + } + if (aAdjRect) + *aAdjRect = mPageDim; + } else { + if (aActualRect) + aActualRect->SetRect(0, 0, 0, 0); + if (aAdjRect) + aAdjRect->SetRect(0, 0, 0, 0); + } +} + +void +nsIPresContext::SetPageDim(const nsRect& aPageDim) +{ + if (mMedium == nsLayoutAtoms::print) + mPageDim = aPageDim; +} + +void +nsIPresContext::SetPaginatedScrolling(PRBool aPaginated) +{ + if (mType == eContext_PrintPreview) + mCanPaginatedScroll = aPaginated; +} + +void +nsIPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings) +{ + if (mMedium == nsLayoutAtoms::print) + mPrintSettings = aPrintSettings; +} + +nsresult +NS_NewPresContext(nsIPresContext::nsPresContextType aType, + nsIPresContext** aInstancePtrResult) +{ + nsIPresContext *context = new nsIPresContext(aType); + if (!context) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aInstancePtrResult = context); return NS_OK; } #ifdef MOZ_REFLOW_PERF -NS_IMETHODIMP -nsPresContext::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) +void +nsIPresContext::CountReflows(const char * aName, + PRUint32 aType, nsIFrame * aFrame) { if (mShell) { mShell->CountReflows(aName, aType, aFrame); } - return NS_OK; } -NS_IMETHODIMP -nsPresContext::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor) +void +nsIPresContext::PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIFrame * aFrame, PRUint32 aColor) { if (mShell) { mShell->PaintCount(aName, aRenderingContext, this, aFrame, aColor); } - return NS_OK; } #endif diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/base/src/nsPrintContext.cpp b/layout/base/src/nsPrintContext.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/base/src/nsPrintPreviewContext.cpp b/layout/base/src/nsPrintPreviewContext.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/layout/build/nsLayoutCID.h b/layout/build/nsLayoutCID.h index f3a829e02c5..f73567476dc 100644 --- a/layout/build/nsLayoutCID.h +++ b/layout/build/nsLayoutCID.h @@ -105,14 +105,6 @@ #define NS_PRESSTATE_CID \ { 0xa1fde861, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } } -// {A1FDE85E-E802-11d4-9885-00C04FA0CF4B} -#define NS_GALLEYCONTEXT_CID \ -{ 0xa1fde85e, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } } - -// {A1FDE85F-E802-11d4-9885-00C04FA0CF4B} -#define NS_PRINTCONTEXT_CID \ -{ 0xa1fde85f, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } } - // {95F46161-D177-11d2-BF86-00105A1B0627} #define NS_HTML_CSS_STYLESHEET_CID \ { 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } @@ -157,10 +149,6 @@ {/* {a6cf90e5-15b3-11d2-932e-00805f8add32}*/ \ 0xa6cf90e5, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } -/* a6cf90f7-15b3-11d2-932e-00805f8add32 */ -#define NS_PRINT_PREVIEW_CONTEXT_CID \ - { 0xa6cf90f7, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - // {64F300A1-C88C-11d3-97FB-00400553EEF0} #define NS_XBLSERVICE_CID \ { 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } } diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index e6097d1c981..0929ac185e9 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -121,9 +121,7 @@ #include "nsTextTransformer.h" #include "nsIFrameTraversal.h" #include "nsISelectionImageService.h" -#include "nsIPrintContext.h" #include "nsIAutoCopy.h" -#include "nsIPrintPreviewContext.h" #include "nsCSSLoader.h" #include "nsXULAtoms.h" #include "nsLayoutCID.h" @@ -500,9 +498,6 @@ MAKE_CTOR(CreateNewFrameTraversal, nsIFrameTraversal, NS_CreateFrameTr MAKE_CTOR(CreateNewLayoutHistoryState, nsILayoutHistoryState, NS_NewLayoutHistoryState) MAKE_CTOR(CreateNewPresShell, nsIPresShell, NS_NewPresShell) MAKE_CTOR(CreateNewPresState, nsIPresState, NS_NewPresState) -MAKE_CTOR(CreateNewGalleyContext, nsIPresContext, NS_NewGalleyContext) -MAKE_CTOR(CreateNewPrintContext, nsIPrintContext, NS_NewPrintContext) -MAKE_CTOR(CreateNewPrintPreviewContext, nsIPrintPreviewContext, NS_NewPrintPreviewContext) #ifdef MOZ_XUL MAKE_CTOR(CreateNewBoxObject, nsIBoxObject, NS_NewBoxObject) MAKE_CTOR(CreateNewListBoxObject, nsIBoxObject, NS_NewListBoxObject) @@ -831,20 +826,6 @@ static const nsModuleComponentInfo gComponents[] = { nsnull, CreateNewPresState }, - { "Galley context", - NS_GALLEYCONTEXT_CID, - nsnull, - CreateNewGalleyContext }, - - { "Print context", - NS_PRINTCONTEXT_CID, - nsnull, - CreateNewPrintContext }, - - { "Print Preview context", - NS_PRINT_PREVIEW_CONTEXT_CID, - nsnull, - CreateNewPrintPreviewContext }, // XXX end ick #ifdef MOZ_XUL diff --git a/layout/forms/nsGfxCheckboxControlFrame.cpp b/layout/forms/nsGfxCheckboxControlFrame.cpp index 99b27f8e786..5d002b23bfa 100644 --- a/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -181,16 +181,16 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIPresContext* aPresContext, { const nsStyleDisplay* disp = GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, this, disp->mAppearance)) return; // No need to paint the checkbox. The theme will do it. } - aRenderingContext.PushState(); + // Get current checked state through content model. + if (!GetCheckboxState()) + return; // we're not checked, nothing to paint. - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + aRenderingContext.PushState(); nsMargin borderPadding(0,0,0,0); CalcBorderPadding(borderPadding); @@ -201,11 +201,10 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIPresContext* aPresContext, const nsStyleColor* color = GetStyleColor(); aRenderingContext.SetColor(color->mColor); - // Get current checked state through content model. - if ( GetCheckboxState() ) { - nsFormControlHelper::PaintCheckMark(aRenderingContext, p2t, checkRect); - } - + nsFormControlHelper::PaintCheckMark(aRenderingContext, + aPresContext->ScaledPixelsToTwips(), + checkRect); + aRenderingContext.PopState(); } diff --git a/layout/forms/nsGfxRadioControlFrame.cpp b/layout/forms/nsGfxRadioControlFrame.cpp index 4ff2331ef6a..9d8c4a87519 100644 --- a/layout/forms/nsGfxRadioControlFrame.cpp +++ b/layout/forms/nsGfxRadioControlFrame.cpp @@ -171,8 +171,7 @@ nsGfxRadioControlFrame::PaintRadioButton(nsIPresContext* aPresContext, { const nsStyleDisplay* disp = GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, this, disp->mAppearance)) return; // No need to paint the radio button. The theme will do it. } diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 0b3d8e9d9dc..6c6b76ee56e 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -550,8 +550,7 @@ nsListControlFrame::Paint(nsIPresContext* aPresContext, if (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND) { const nsStyleDisplay* displayData = GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); nsRect rect(0, 0, mRect.width, mRect.height); if (theme && theme->ThemeSupportsWidget(aPresContext, this, displayData->mAppearance)) theme->DrawWidgetBackground(&aRenderingContext, this, @@ -687,9 +686,7 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsFramePaintLayer nsILookAndFeel::eColor_WidgetSelectForeground : nsILookAndFeel::eColor_WidgetSelectBackground, color); - float p2t; - mPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixelInTwips = NSToCoordRound(p2t); + nscoord onePixelInTwips = mPresContext->IntScaledPixelsToTwips(1); nsRect dirty; nscolor colors[] = {color, color, color, color}; diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index ef2f9be864a..8167591d21b 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -695,8 +695,7 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, #ifdef IBMBIDI if (! mLines.empty()) { if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { PRBool forceReflow; nsresult rc = bidiUtils->Resolve(aPresContext, this, @@ -3946,8 +3945,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, else { if (aState.mPresContext->BidiEnabled()) { if (!aState.mPresContext->IsVisualMode()) { - nsBidiPresUtils* bidiUtils; - aState.mPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aState.mPresContext->GetBidiUtils(); if (bidiUtils && bidiUtils->IsSuccessful() ) { nsIFrame* nextInFlow = (aLine.next() != end_lines()) @@ -4959,10 +4957,7 @@ nsBlockFrame::ReflowFloat(nsBlockReflowState& aState, // needed when prev. float has procentage width // (maybe is a table flaw that makes table chose to round up // but i don't want to change that, too risky) - nscoord twp; - float p2t; - aState.mPresContext->GetScaledPixelsToTwips(&p2t); - twp = NSIntPixelsToTwips(1,p2t); + nscoord twp = aState.mPresContext->IntScaledPixelsToTwips(1); availWidth -= availWidth % twp; } } diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index d408708a088..58ff078b6ce 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -336,7 +336,7 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_AM: case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ER: case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ET: - aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + fm = aPresContext->GetMetricsFor(myFont->mFont); #ifdef IBMBIDI // If we can't render our numeral using the chars in the numbering // system, we'll be using "decimal"... @@ -355,13 +355,12 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, } #ifdef IBMBIDI if (charType != eCharType_LeftToRight) { - aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + fm = aPresContext->GetMetricsFor(myFont->mFont); aRenderingContext.SetFont(fm); nscoord ascent; fm->GetMaxAscent(ascent); - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { const PRUnichar* buffer = text.get(); PRInt32 textLength = text.Length(); @@ -1467,8 +1466,7 @@ nsBulletFrame::GetDesiredSize(nsIPresContext* aCX, } const nsStyleFont* myFont = GetStyleFont(); - nsCOMPtr fm; - aCX->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = aCX->GetMetricsFor(myFont->mFont); nscoord bulletSize; float p2t; float t2p; diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 6b5375de49c..7a7c01ed65c 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -5343,8 +5343,7 @@ static void DisplayReflowEnterPrint(nsIPresContext* aPresContext, else printf("cnt=%d \n", DR_state->mCount); if (DR_state->mDisplayPixelErrors) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); CheckPixelError(aReflowState.availableWidth, p2t); CheckPixelError(aReflowState.availableHeight, p2t); CheckPixelError(aReflowState.mComputedWidth, p2t); @@ -5422,8 +5421,7 @@ void nsFrame::DisplayReflowExit(nsIPresContext* aPresContext, } printf("\n"); if (DR_state->mDisplayPixelErrors) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); CheckPixelError(aMetrics.width, p2t); CheckPixelError(aMetrics.height, p2t); if (aMetrics.mComputeMEW) diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index ae44a3eed2e..f5dc36a91ce 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -75,8 +75,6 @@ #include "nsXPIDLString.h" #include "nsIScrollable.h" #include "nsINameSpaceManager.h" -#include "nsIPrintContext.h" -#include "nsIPrintPreviewContext.h" #include "nsIWidget.h" #include "nsIWebBrowserPrint.h" #include "nsWeakReference.h" @@ -261,25 +259,19 @@ nsSubDocumentFrame::Init(nsIPresContext* aPresContext, } // determine if we are a printcontext - PRBool shouldCreateDoc = PR_TRUE; - nsCOMPtr thePrinterContext(do_QueryInterface(aPresContext)); + PRBool shouldCreateDoc; + + if (aPresContext->Medium() == nsLayoutAtoms::print) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + // for print preview we want to create the view and widget but + // we do not want to load the document, it is already loaded. + rv = CreateViewAndWidget(eContentTypeContent); + NS_ENSURE_SUCCESS(rv,rv); + } - if (thePrinterContext) { - // we are printing - shouldCreateDoc = PR_FALSE; - } - - // for print preview we want to create the view and widget but - // we do not want to load the document, it is alerady loaded. - nsCOMPtr thePrintPreviewContext = - do_QueryInterface(aPresContext); - - if (thePrintPreviewContext) { - rv = CreateViewAndWidget(eContentTypeContent); - NS_ENSURE_SUCCESS(rv,rv); - - // we are in PrintPreview shouldCreateDoc = PR_FALSE; + } else { + shouldCreateDoc = PR_TRUE; } if (shouldCreateDoc) { @@ -306,7 +298,7 @@ nsSubDocumentFrame::GetDesiredSize(nsIPresContext* aPresContext, if (!mContent->IsContentOfType(nsIContent::eXUL)) // If no width/height was specified, use 300/150. // This is for compatability with IE. - aPresContext->GetScaledPixelsToTwips(&p2t); + p2t = aPresContext->ScaledPixelsToTwips(); if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) { aDesiredSize.width = aReflowState.mComputedWidth; diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index ab2c3e810cb..4ebf7dbd175 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -525,8 +525,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext, PRInt32 numRelative = 0; PRInt32* relative= new PRInt32[aNumSpecs]; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); PRInt32 i, j; // initialize the fixed, percent, relative indices, allocate the fixed sizes and zero the others @@ -637,8 +636,7 @@ PRInt32 nsHTMLFramesetFrame::GetBorderWidth(nsIPresContext* aPresContext, return 0; } } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); nsHTMLValue htmlVal; nsCOMPtr content(do_QueryInterface(mContent)); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 2eea2043dc2..15afc0d8cf6 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -66,7 +66,6 @@ #include "nsITextControlFrame.h" #include "nsIDOMHTMLTextAreaElement.h" #include "nsNodeInfoManager.h" -#include "nsIPrintPreviewContext.h" #include "nsIURI.h" #include "nsGUIEvent.h" #include "nsContentCreatorFunctions.h" @@ -1934,13 +1933,10 @@ nsGfxScrollFrameInner::Layout(nsBoxLayoutState& aState) GetScrolledSize(aState.PresContext(),&scrolledContentSize.width, &scrolledContentSize.height); nsIPresContext* presContext = aState.PresContext(); - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - mOnePixel = NSIntPixelsToTwips(1, p2t); + mOnePixel = presContext->IntScaledPixelsToTwips(1); const nsStyleFont* font = mOuter->GetStyleFont(); const nsFont& f = font->mFont; - nsCOMPtr fm; - presContext->GetMetricsFor(f, getter_AddRefs(fm)); + nsCOMPtr fm = presContext->GetMetricsFor(f); nscoord fontHeight = 1; NS_ASSERTION(fm,"FontMetrics is null assuming fontHeight == 1"); if (fm) diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index 22e61832e49..9dccbca4b05 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -2500,8 +2500,7 @@ nsHTMLReflowState::IsBidiFormControl(nsIPresContext* aPresContext) return PR_FALSE; } - PRUint32 options; - aPresContext->GetBidi(&options); + PRUint32 options = aPresContext->GetBidi(); if (IBMBIDI_CONTROLSTEXTMODE_LOGICAL != GET_BIDI_OPTION_CONTROLSTEXTMODE(options)) { return PR_FALSE; } diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 2dc50bf5dd6..0ba8e166f06 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -747,12 +747,9 @@ nsImageFrame::GetDesiredSize(nsIPresContext* aPresContext, // a * (b / c) because of its reduced accuracy relative to a * b / c // or (a * b) / c (which are equivalent). - float t2p, sp2t; - t2p = aPresContext->TwipsToPixels(); - aPresContext->GetScaledPixelsToTwips(&sp2t); - // convert from normal twips to scaled twips (printing...) - float t2st = t2p * sp2t; // twips to scaled twips + float t2st = aPresContext->TwipsToPixels() * + aPresContext->ScaledPixelsToTwips(); // twips to scaled twips nscoord intrinsicWidth = NSToCoordRound(float(mIntrinsicSize.width) * t2st); nscoord intrinsicHeight = @@ -990,10 +987,8 @@ nsImageFrame::Reflow(nsIPresContext* aPresContext, aMetrics.height > aReflowState.availableHeight) { // split an image frame but not an image control frame if (nsLayoutAtoms::imageFrame == GetType()) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); // our desired height was greater than 0, so to avoid infinite splitting, use 1 pixel as the min - aMetrics.height = PR_MAX(NSToCoordRound(p2t), aReflowState.availableHeight); + aMetrics.height = PR_MAX(NSToCoordRound(aPresContext->ScaledPixelsToTwips()), aReflowState.availableHeight); aStatus = NS_FRAME_NOT_COMPLETE; } } @@ -1164,9 +1159,8 @@ nsImageFrame::DisplayAltFeedback(nsIPresContext* aPresContext, GetInnerArea(aPresContext, inner); // Display a recessed one pixel border - float p2t; nscoord borderEdgeWidth; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); borderEdgeWidth = NSIntPixelsToTwips(ALT_BORDER_WIDTH, p2t); // if inner area is empty, then make it big enough for at least the icon @@ -1987,8 +1981,7 @@ void nsImageFrame::InvalidateIcon() // invalidate the inner area, where the icon lives nsIPresContext *presContext = GetPresContext(); - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); + float p2t = presContext->ScaledPixelsToTwips(); nsRect inner; GetInnerArea(presContext, inner); diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index f491fa199a6..7ab3339cff3 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -95,8 +95,6 @@ #include "nsIDocumentEncoder.h" #include "nsXPIDLString.h" #include "nsIDOMRange.h" -#include "nsIPrintContext.h" -#include "nsIPrintPreviewContext.h" #include "nsIPluginWidget.h" #include "nsGUIEvent.h" #include "nsIRenderingContext.h" @@ -879,8 +877,7 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext, // for EMBED and APPLET, default to 240x200 for compatibility nsIAtom *atom = mContent->Tag(); if (atom == nsHTMLAtoms::applet || atom == nsHTMLAtoms::embed) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); if (aMetrics.width == NS_UNCONSTRAINEDSIZE) { aMetrics.width = PR_MIN(PR_MAX(NSIntPixelsToTwips(EMBED_DEF_WIDTH, p2t), aReflowState.mComputedMinWidth), @@ -982,9 +979,7 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, } // if we are printing or print previewing, bail for now - nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); - nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); - if (thePrinterContext || thePrintPreviewContext) { + if (aPresContext->Medium() == nsLayoutAtoms::print) { aStatus = NS_FRAME_COMPLETE; return rv; } @@ -1515,14 +1510,12 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } // If we are painting in Print Preview do nothing.... - nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); - if (thePrintPreviewContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { return NS_OK; } // determine if we are printing - nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); - if (thePrinterContext) { + if (aPresContext->Type() == nsIPresContext::eContext_Print) { // UNIX Plugins can't PP at this time, so draw an empty box // we only want to print on the content layer pass if (eFramePaintLayer_Content != aWhichLayer) @@ -3914,7 +3907,6 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) nsIView *view; nsresult rv = NS_ERROR_FAILURE; - float p2t; if (mOwner) { @@ -3929,7 +3921,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) mInstance->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless); // always create widgets in Twips, not pixels - mContext->GetScaledPixelsToTwips(&p2t); + float p2t = mContext->ScaledPixelsToTwips(); rv = mOwner->CreateWidget(mContext, NSIntPixelsToTwips(mPluginWindow->width, p2t), NSIntPixelsToTwips(mPluginWindow->height, p2t), diff --git a/layout/generic/nsPageContentFrame.cpp b/layout/generic/nsPageContentFrame.cpp index 0091eb4bd05..fe97d3e9a2e 100644 --- a/layout/generic/nsPageContentFrame.cpp +++ b/layout/generic/nsPageContentFrame.cpp @@ -44,7 +44,6 @@ #include "nsIPresShell.h" #include "nsIDeviceContext.h" #include "nsReadableUtils.h" -#include "nsIPrintPreviewContext.h" #include "nsSimplePageSequence.h" #include "nsIView.h" diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index 58ab506df1b..b815f5d29a7 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -46,8 +46,6 @@ #include "nsCSSFrameConstructor.h" #include "nsIDeviceContext.h" #include "nsReadableUtils.h" -#include "nsIPrintPreviewContext.h" -#include "nsIPrintContext.h" #include "nsPageContentFrame.h" #include "nsTextFrame.h" // for function BinarySearchForPosition @@ -127,8 +125,8 @@ nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext, { nsIView* view = aChildList->GetView(); if (view && mDoCreateWidget) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext && view->GetNearestWidget(nsnull)) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview && + view->GetNearestWidget(nsnull)) { view->CreateWidget(kCChildCID); } } @@ -187,9 +185,7 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext, nsSize maxSize(mPD->mReflowRect.width - mPD->mReflowMargin.right - mPD->mReflowMargin.left, avHeight); // Get the number of Twips per pixel from the PresContext - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixelInTwips = NSToCoordRound(p2t); + nscoord onePixelInTwips = aPresContext->IntScaledPixelsToTwips(1); NS_ASSERTION(maxSize.width >= onePixelInTwips, "maxSize.width must be >= 1 pixel"); NS_ASSERTION(maxSize.height >= onePixelInTwips, "maxSize.height must be >= 1 pixel"); // insurance against infinite reflow, when reflowing less than a pixel @@ -536,8 +532,7 @@ nsPageFrame::DrawHeaderFooter(nsIPresContext* aPresContext, nsresult rv = NS_ERROR_FAILURE; if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { PRUnichar* buffer = str.BeginWriting(); @@ -598,8 +593,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { // fill page with White aRenderingContext.SetColor(NS_RGB(255,255,255)); rect.x = 0; @@ -648,9 +642,8 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) { // For PrintPreview the if (!mPD->mPrintSettings) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { - ppContext->GetPrintSettings(getter_AddRefs(mPD->mPrintSettings)); + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + mPD->mPrintSettings = aPresContext->GetPrintSettings(); } } NS_ASSERTION(mPD->mPrintSettings, "Must have a good PrintSettings here!"); @@ -776,9 +769,7 @@ nsPageBreakFrame::GetDesiredSize(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize) { NS_PRECONDITION(aPresContext, "null pres context"); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSToCoordRound(p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aDesiredSize.width = onePixel; if (mHaveReflowed) { diff --git a/layout/generic/nsSimplePageSequence.cpp b/layout/generic/nsSimplePageSequence.cpp index 425a7d56b81..f0ec32755a0 100644 --- a/layout/generic/nsSimplePageSequence.cpp +++ b/layout/generic/nsSimplePageSequence.cpp @@ -46,8 +46,6 @@ #include "nsIFontMetrics.h" #include "nsIPrintSettings.h" #include "nsPageFrame.h" -#include "nsIPrintPreviewContext.h" -#include "nsIPrintContext.h" #include "nsStyleConsts.h" #include "nsRegion.h" #include "nsLayoutAtoms.h" @@ -253,23 +251,16 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // Turn on the scaling of twips so any of the scrollbars // in the UI no longer get scaled - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; + if (isPrintPreview) { + aPresContext->SetScalingOfTwips(PR_TRUE); } - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - // See if we can get a Print Settings from the Context - if (!mPageData->mPrintSettings) { - if (ppContext) { - ppContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings)); - } else { - nsCOMPtr prtContext = do_QueryInterface(aPresContext); - if (prtContext) { - prtContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings)); - } - } + if (!mPageData->mPrintSettings && + aPresContext->Medium() == nsLayoutAtoms::print) { + mPageData->mPrintSettings = aPresContext->GetPrintSettings(); } // now get out margins @@ -310,13 +301,11 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, nsMargin deadSpaceMargin(0,0,0,0); nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); - if (ppContext) { + if (isPrintPreview) { if (adjSize.width == width && adjSize.height == height) { deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap); extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord fourPixels = NSIntPixelsToTwips(4, p2t); + nscoord fourPixels = aPresContext->IntScaledPixelsToTwips(4); shadowSize.SizeTo(fourPixels, fourPixels); } } @@ -509,8 +498,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // Turn off the scaling of twips so any of the scrollbars // in the document get scaled - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + if (isPrintPreview) { + aPresContext->SetScalingOfTwips(PR_FALSE); } NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus); diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index a5747c09262..87ee9557d3c 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -544,7 +544,7 @@ public: if (mSmallCaps) { nscoord originalSize = plainFont->size; plainFont->size = nscoord(0.8 * plainFont->size); - aPresContext->GetMetricsFor(*plainFont, &mSmallFont); + mSmallFont = aPresContext->GetMetricsFor(*plainFont).get(); // addrefs // Reset to the size value saved earlier. plainFont->size = originalSize; } @@ -2267,8 +2267,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, // base direction aRenderingContext.SetRightToLeftText(PR_TRUE); } - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { #ifdef DEBUG PRInt32 rememberTextLength = textLength; @@ -2948,8 +2947,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, nsCharType charType = eCharType_LeftToRight; if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { isOddLevel = NS_GET_EMBEDDING_LEVEL(this) & 1; @@ -5444,9 +5442,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, // For now we add 1 pixel to the width of the invalidated rect. // This fixes cases where the twips to pixel roundoff causes the invalidated // rect's width to be one pixel short. - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); maxFrameWidth = PR_MAX(maxFrameWidth, mRect.width) + onePixel; maxFrameHeight = PR_MAX(maxFrameHeight, mRect.height); diff --git a/layout/generic/nsTextTransformer.cpp b/layout/generic/nsTextTransformer.cpp index 43f709e9d59..15957ae193c 100644 --- a/layout/generic/nsTextTransformer.cpp +++ b/layout/generic/nsTextTransformer.cpp @@ -1503,8 +1503,7 @@ nsTextTransformer::DoNumericShaping(PRUnichar* aText, if (aTextLength <= 0) return; - PRUint32 bidiOptions; - mPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = mPresContext->GetBidi(); switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { diff --git a/layout/html/base/src/nsBlockFrame.cpp b/layout/html/base/src/nsBlockFrame.cpp index ef2f9be864a..8167591d21b 100644 --- a/layout/html/base/src/nsBlockFrame.cpp +++ b/layout/html/base/src/nsBlockFrame.cpp @@ -695,8 +695,7 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, #ifdef IBMBIDI if (! mLines.empty()) { if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { PRBool forceReflow; nsresult rc = bidiUtils->Resolve(aPresContext, this, @@ -3946,8 +3945,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, else { if (aState.mPresContext->BidiEnabled()) { if (!aState.mPresContext->IsVisualMode()) { - nsBidiPresUtils* bidiUtils; - aState.mPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aState.mPresContext->GetBidiUtils(); if (bidiUtils && bidiUtils->IsSuccessful() ) { nsIFrame* nextInFlow = (aLine.next() != end_lines()) @@ -4959,10 +4957,7 @@ nsBlockFrame::ReflowFloat(nsBlockReflowState& aState, // needed when prev. float has procentage width // (maybe is a table flaw that makes table chose to round up // but i don't want to change that, too risky) - nscoord twp; - float p2t; - aState.mPresContext->GetScaledPixelsToTwips(&p2t); - twp = NSIntPixelsToTwips(1,p2t); + nscoord twp = aState.mPresContext->IntScaledPixelsToTwips(1); availWidth -= availWidth % twp; } } diff --git a/layout/html/base/src/nsBulletFrame.cpp b/layout/html/base/src/nsBulletFrame.cpp index d408708a088..58ff078b6ce 100644 --- a/layout/html/base/src/nsBulletFrame.cpp +++ b/layout/html/base/src/nsBulletFrame.cpp @@ -336,7 +336,7 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_AM: case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ER: case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ET: - aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + fm = aPresContext->GetMetricsFor(myFont->mFont); #ifdef IBMBIDI // If we can't render our numeral using the chars in the numbering // system, we'll be using "decimal"... @@ -355,13 +355,12 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, } #ifdef IBMBIDI if (charType != eCharType_LeftToRight) { - aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + fm = aPresContext->GetMetricsFor(myFont->mFont); aRenderingContext.SetFont(fm); nscoord ascent; fm->GetMaxAscent(ascent); - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { const PRUnichar* buffer = text.get(); PRInt32 textLength = text.Length(); @@ -1467,8 +1466,7 @@ nsBulletFrame::GetDesiredSize(nsIPresContext* aCX, } const nsStyleFont* myFont = GetStyleFont(); - nsCOMPtr fm; - aCX->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = aCX->GetMetricsFor(myFont->mFont); nscoord bulletSize; float p2t; float t2p; diff --git a/layout/html/base/src/nsFrame.cpp b/layout/html/base/src/nsFrame.cpp index 6b5375de49c..7a7c01ed65c 100644 --- a/layout/html/base/src/nsFrame.cpp +++ b/layout/html/base/src/nsFrame.cpp @@ -5343,8 +5343,7 @@ static void DisplayReflowEnterPrint(nsIPresContext* aPresContext, else printf("cnt=%d \n", DR_state->mCount); if (DR_state->mDisplayPixelErrors) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); CheckPixelError(aReflowState.availableWidth, p2t); CheckPixelError(aReflowState.availableHeight, p2t); CheckPixelError(aReflowState.mComputedWidth, p2t); @@ -5422,8 +5421,7 @@ void nsFrame::DisplayReflowExit(nsIPresContext* aPresContext, } printf("\n"); if (DR_state->mDisplayPixelErrors) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); CheckPixelError(aMetrics.width, p2t); CheckPixelError(aMetrics.height, p2t); if (aMetrics.mComputeMEW) diff --git a/layout/html/base/src/nsGfxScrollFrame.cpp b/layout/html/base/src/nsGfxScrollFrame.cpp index 2eea2043dc2..15afc0d8cf6 100644 --- a/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/layout/html/base/src/nsGfxScrollFrame.cpp @@ -66,7 +66,6 @@ #include "nsITextControlFrame.h" #include "nsIDOMHTMLTextAreaElement.h" #include "nsNodeInfoManager.h" -#include "nsIPrintPreviewContext.h" #include "nsIURI.h" #include "nsGUIEvent.h" #include "nsContentCreatorFunctions.h" @@ -1934,13 +1933,10 @@ nsGfxScrollFrameInner::Layout(nsBoxLayoutState& aState) GetScrolledSize(aState.PresContext(),&scrolledContentSize.width, &scrolledContentSize.height); nsIPresContext* presContext = aState.PresContext(); - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - mOnePixel = NSIntPixelsToTwips(1, p2t); + mOnePixel = presContext->IntScaledPixelsToTwips(1); const nsStyleFont* font = mOuter->GetStyleFont(); const nsFont& f = font->mFont; - nsCOMPtr fm; - presContext->GetMetricsFor(f, getter_AddRefs(fm)); + nsCOMPtr fm = presContext->GetMetricsFor(f); nscoord fontHeight = 1; NS_ASSERTION(fm,"FontMetrics is null assuming fontHeight == 1"); if (fm) diff --git a/layout/html/base/src/nsHTMLReflowState.cpp b/layout/html/base/src/nsHTMLReflowState.cpp index 22e61832e49..9dccbca4b05 100644 --- a/layout/html/base/src/nsHTMLReflowState.cpp +++ b/layout/html/base/src/nsHTMLReflowState.cpp @@ -2500,8 +2500,7 @@ nsHTMLReflowState::IsBidiFormControl(nsIPresContext* aPresContext) return PR_FALSE; } - PRUint32 options; - aPresContext->GetBidi(&options); + PRUint32 options = aPresContext->GetBidi(); if (IBMBIDI_CONTROLSTEXTMODE_LOGICAL != GET_BIDI_OPTION_CONTROLSTEXTMODE(options)) { return PR_FALSE; } diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index 2dc50bf5dd6..0ba8e166f06 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -747,12 +747,9 @@ nsImageFrame::GetDesiredSize(nsIPresContext* aPresContext, // a * (b / c) because of its reduced accuracy relative to a * b / c // or (a * b) / c (which are equivalent). - float t2p, sp2t; - t2p = aPresContext->TwipsToPixels(); - aPresContext->GetScaledPixelsToTwips(&sp2t); - // convert from normal twips to scaled twips (printing...) - float t2st = t2p * sp2t; // twips to scaled twips + float t2st = aPresContext->TwipsToPixels() * + aPresContext->ScaledPixelsToTwips(); // twips to scaled twips nscoord intrinsicWidth = NSToCoordRound(float(mIntrinsicSize.width) * t2st); nscoord intrinsicHeight = @@ -990,10 +987,8 @@ nsImageFrame::Reflow(nsIPresContext* aPresContext, aMetrics.height > aReflowState.availableHeight) { // split an image frame but not an image control frame if (nsLayoutAtoms::imageFrame == GetType()) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); // our desired height was greater than 0, so to avoid infinite splitting, use 1 pixel as the min - aMetrics.height = PR_MAX(NSToCoordRound(p2t), aReflowState.availableHeight); + aMetrics.height = PR_MAX(NSToCoordRound(aPresContext->ScaledPixelsToTwips()), aReflowState.availableHeight); aStatus = NS_FRAME_NOT_COMPLETE; } } @@ -1164,9 +1159,8 @@ nsImageFrame::DisplayAltFeedback(nsIPresContext* aPresContext, GetInnerArea(aPresContext, inner); // Display a recessed one pixel border - float p2t; nscoord borderEdgeWidth; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); borderEdgeWidth = NSIntPixelsToTwips(ALT_BORDER_WIDTH, p2t); // if inner area is empty, then make it big enough for at least the icon @@ -1987,8 +1981,7 @@ void nsImageFrame::InvalidateIcon() // invalidate the inner area, where the icon lives nsIPresContext *presContext = GetPresContext(); - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); + float p2t = presContext->ScaledPixelsToTwips(); nsRect inner; GetInnerArea(presContext, inner); diff --git a/layout/html/base/src/nsObjectFrame.cpp b/layout/html/base/src/nsObjectFrame.cpp index f491fa199a6..7ab3339cff3 100644 --- a/layout/html/base/src/nsObjectFrame.cpp +++ b/layout/html/base/src/nsObjectFrame.cpp @@ -95,8 +95,6 @@ #include "nsIDocumentEncoder.h" #include "nsXPIDLString.h" #include "nsIDOMRange.h" -#include "nsIPrintContext.h" -#include "nsIPrintPreviewContext.h" #include "nsIPluginWidget.h" #include "nsGUIEvent.h" #include "nsIRenderingContext.h" @@ -879,8 +877,7 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext, // for EMBED and APPLET, default to 240x200 for compatibility nsIAtom *atom = mContent->Tag(); if (atom == nsHTMLAtoms::applet || atom == nsHTMLAtoms::embed) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); if (aMetrics.width == NS_UNCONSTRAINEDSIZE) { aMetrics.width = PR_MIN(PR_MAX(NSIntPixelsToTwips(EMBED_DEF_WIDTH, p2t), aReflowState.mComputedMinWidth), @@ -982,9 +979,7 @@ nsObjectFrame::Reflow(nsIPresContext* aPresContext, } // if we are printing or print previewing, bail for now - nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); - nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); - if (thePrinterContext || thePrintPreviewContext) { + if (aPresContext->Medium() == nsLayoutAtoms::print) { aStatus = NS_FRAME_COMPLETE; return rv; } @@ -1515,14 +1510,12 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } // If we are painting in Print Preview do nothing.... - nsCOMPtr thePrintPreviewContext = do_QueryInterface(aPresContext); - if (thePrintPreviewContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { return NS_OK; } // determine if we are printing - nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); - if (thePrinterContext) { + if (aPresContext->Type() == nsIPresContext::eContext_Print) { // UNIX Plugins can't PP at this time, so draw an empty box // we only want to print on the content layer pass if (eFramePaintLayer_Content != aWhichLayer) @@ -3914,7 +3907,6 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) nsIView *view; nsresult rv = NS_ERROR_FAILURE; - float p2t; if (mOwner) { @@ -3929,7 +3921,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) mInstance->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless); // always create widgets in Twips, not pixels - mContext->GetScaledPixelsToTwips(&p2t); + float p2t = mContext->ScaledPixelsToTwips(); rv = mOwner->CreateWidget(mContext, NSIntPixelsToTwips(mPluginWindow->width, p2t), NSIntPixelsToTwips(mPluginWindow->height, p2t), diff --git a/layout/html/base/src/nsPageContentFrame.cpp b/layout/html/base/src/nsPageContentFrame.cpp index 0091eb4bd05..fe97d3e9a2e 100644 --- a/layout/html/base/src/nsPageContentFrame.cpp +++ b/layout/html/base/src/nsPageContentFrame.cpp @@ -44,7 +44,6 @@ #include "nsIPresShell.h" #include "nsIDeviceContext.h" #include "nsReadableUtils.h" -#include "nsIPrintPreviewContext.h" #include "nsSimplePageSequence.h" #include "nsIView.h" diff --git a/layout/html/base/src/nsPageFrame.cpp b/layout/html/base/src/nsPageFrame.cpp index 58ab506df1b..b815f5d29a7 100644 --- a/layout/html/base/src/nsPageFrame.cpp +++ b/layout/html/base/src/nsPageFrame.cpp @@ -46,8 +46,6 @@ #include "nsCSSFrameConstructor.h" #include "nsIDeviceContext.h" #include "nsReadableUtils.h" -#include "nsIPrintPreviewContext.h" -#include "nsIPrintContext.h" #include "nsPageContentFrame.h" #include "nsTextFrame.h" // for function BinarySearchForPosition @@ -127,8 +125,8 @@ nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext, { nsIView* view = aChildList->GetView(); if (view && mDoCreateWidget) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext && view->GetNearestWidget(nsnull)) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview && + view->GetNearestWidget(nsnull)) { view->CreateWidget(kCChildCID); } } @@ -187,9 +185,7 @@ NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext, nsSize maxSize(mPD->mReflowRect.width - mPD->mReflowMargin.right - mPD->mReflowMargin.left, avHeight); // Get the number of Twips per pixel from the PresContext - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixelInTwips = NSToCoordRound(p2t); + nscoord onePixelInTwips = aPresContext->IntScaledPixelsToTwips(1); NS_ASSERTION(maxSize.width >= onePixelInTwips, "maxSize.width must be >= 1 pixel"); NS_ASSERTION(maxSize.height >= onePixelInTwips, "maxSize.height must be >= 1 pixel"); // insurance against infinite reflow, when reflowing less than a pixel @@ -536,8 +532,7 @@ nsPageFrame::DrawHeaderFooter(nsIPresContext* aPresContext, nsresult rv = NS_ERROR_FAILURE; if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { PRUnichar* buffer = str.BeginWriting(); @@ -598,8 +593,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { // fill page with White aRenderingContext.SetColor(NS_RGB(255,255,255)); rect.x = 0; @@ -648,9 +642,8 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) { // For PrintPreview the if (!mPD->mPrintSettings) { - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { - ppContext->GetPrintSettings(getter_AddRefs(mPD->mPrintSettings)); + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + mPD->mPrintSettings = aPresContext->GetPrintSettings(); } } NS_ASSERTION(mPD->mPrintSettings, "Must have a good PrintSettings here!"); @@ -776,9 +769,7 @@ nsPageBreakFrame::GetDesiredSize(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize) { NS_PRECONDITION(aPresContext, "null pres context"); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSToCoordRound(p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aDesiredSize.width = onePixel; if (mHaveReflowed) { diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index f278777829b..73bc6f099cd 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -146,7 +146,6 @@ #include "nsIDOMWindowInternal.h" #include "nsPIDOMWindow.h" #include "nsIFocusController.h" -#include "nsIPrintPreviewContext.h" // Drag & Drop, Clipboard #include "nsWidgetsCID.h" @@ -196,7 +195,6 @@ #include "nsContentCID.h" static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID); static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); // convert a color value to a string, in the CSS format #RRGGBB // * - initially created for bugs 31816, 20760, 22963 @@ -3541,8 +3539,7 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const // if it is then get the scrolled frame scrollable->GetScrolledFrame(nsnull, child); } else { - nsCOMPtr ppContext = do_QueryInterface(mPresContext); - if (ppContext) { + if (mPresContext->Type() == nsIPresContext::eContext_PrintPreview) { child = child->GetFirstChild(nsnull); } } @@ -5700,7 +5697,8 @@ PresShell::HandleEvent(nsIView *aView, // Check for a theme change up front, since the frame type is irrelevant if (aEvent->message == NS_THEMECHANGED && mPresContext) { - return mPresContext->ThemeChanged(); + mPresContext->ThemeChanged(); + return NS_OK; } // Check for a system color change up front, since the frame type is @@ -5717,7 +5715,8 @@ PresShell::HandleEvent(nsIView *aView, if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; - return mPresContext->SysColorChanged(); + mPresContext->SysColorChanged(); + return NS_OK; } } return NS_OK; @@ -7027,16 +7026,12 @@ PresShell::VerifyIncrementalReflow() nsIPresShell* sh; // Create a presentation context to view the new frame tree - nsresult rv; - if (mPresContext->IsPaginated()) { - nsCOMPtr ppx = do_CreateInstance(kPrintPreviewContextCID, &rv); - if (NS_SUCCEEDED(rv)) { - ppx->QueryInterface(NS_GET_IID(nsIPresContext),(void**)&cx); - } - } - else { - rv = NS_NewGalleyContext(&cx); - } + NS_IF_ADDREF(cx = new nsIPresContext(mPresContext->IsPaginated() ? + nsIPresContext::eContext_PrintPreview : + nsIPresContext::eContext_Galley)); + + if (!cx) + return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr container = mPresContext->GetContainer(); if (container) { @@ -7047,9 +7042,8 @@ PresShell::VerifyIncrementalReflow() } } - NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); nsIDeviceContext *dc = mPresContext->DeviceContext(); - rv = cx->Init(dc); + nsresult rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); // Get our scrolling preference @@ -7548,8 +7542,7 @@ void ReflowCountMgr::PaintCount(const char * aName, nsFont font("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(8)); - nsCOMPtr fm; - aPresContext->GetMetricsFor(font, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(font); aRenderingContext->SetFont(fm); char buf[16]; sprintf(buf, "%d", counter->mCount); diff --git a/layout/html/base/src/nsSimplePageSequence.cpp b/layout/html/base/src/nsSimplePageSequence.cpp index 425a7d56b81..f0ec32755a0 100644 --- a/layout/html/base/src/nsSimplePageSequence.cpp +++ b/layout/html/base/src/nsSimplePageSequence.cpp @@ -46,8 +46,6 @@ #include "nsIFontMetrics.h" #include "nsIPrintSettings.h" #include "nsPageFrame.h" -#include "nsIPrintPreviewContext.h" -#include "nsIPrintContext.h" #include "nsStyleConsts.h" #include "nsRegion.h" #include "nsLayoutAtoms.h" @@ -253,23 +251,16 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // Turn on the scaling of twips so any of the scrollbars // in the UI no longer get scaled - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; + if (isPrintPreview) { + aPresContext->SetScalingOfTwips(PR_TRUE); } - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - // See if we can get a Print Settings from the Context - if (!mPageData->mPrintSettings) { - if (ppContext) { - ppContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings)); - } else { - nsCOMPtr prtContext = do_QueryInterface(aPresContext); - if (prtContext) { - prtContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings)); - } - } + if (!mPageData->mPrintSettings && + aPresContext->Medium() == nsLayoutAtoms::print) { + mPageData->mPrintSettings = aPresContext->GetPrintSettings(); } // now get out margins @@ -310,13 +301,11 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, nsMargin deadSpaceMargin(0,0,0,0); nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); - if (ppContext) { + if (isPrintPreview) { if (adjSize.width == width && adjSize.height == height) { deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap); extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord fourPixels = NSIntPixelsToTwips(4, p2t); + nscoord fourPixels = aPresContext->IntScaledPixelsToTwips(4); shadowSize.SizeTo(fourPixels, fourPixels); } } @@ -509,8 +498,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // Turn off the scaling of twips so any of the scrollbars // in the document get scaled - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + if (isPrintPreview) { + aPresContext->SetScalingOfTwips(PR_FALSE); } NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus); diff --git a/layout/html/base/src/nsTextFrame.cpp b/layout/html/base/src/nsTextFrame.cpp index a5747c09262..87ee9557d3c 100644 --- a/layout/html/base/src/nsTextFrame.cpp +++ b/layout/html/base/src/nsTextFrame.cpp @@ -544,7 +544,7 @@ public: if (mSmallCaps) { nscoord originalSize = plainFont->size; plainFont->size = nscoord(0.8 * plainFont->size); - aPresContext->GetMetricsFor(*plainFont, &mSmallFont); + mSmallFont = aPresContext->GetMetricsFor(*plainFont).get(); // addrefs // Reset to the size value saved earlier. plainFont->size = originalSize; } @@ -2267,8 +2267,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, // base direction aRenderingContext.SetRightToLeftText(PR_TRUE); } - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { #ifdef DEBUG PRInt32 rememberTextLength = textLength; @@ -2948,8 +2947,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, nsCharType charType = eCharType_LeftToRight; if (aPresContext->BidiEnabled()) { - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { isOddLevel = NS_GET_EMBEDDING_LEVEL(this) & 1; @@ -5444,9 +5442,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, // For now we add 1 pixel to the width of the invalidated rect. // This fixes cases where the twips to pixel roundoff causes the invalidated // rect's width to be one pixel short. - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); maxFrameWidth = PR_MAX(maxFrameWidth, mRect.width) + onePixel; maxFrameHeight = PR_MAX(maxFrameHeight, mRect.height); diff --git a/layout/html/base/src/nsTextTransformer.cpp b/layout/html/base/src/nsTextTransformer.cpp index 43f709e9d59..15957ae193c 100644 --- a/layout/html/base/src/nsTextTransformer.cpp +++ b/layout/html/base/src/nsTextTransformer.cpp @@ -1503,8 +1503,7 @@ nsTextTransformer::DoNumericShaping(PRUnichar* aText, if (aTextLength <= 0) return; - PRUint32 bidiOptions; - mPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = mPresContext->GetBidi(); switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { diff --git a/layout/html/document/src/nsFrameFrame.cpp b/layout/html/document/src/nsFrameFrame.cpp index ae44a3eed2e..f5dc36a91ce 100644 --- a/layout/html/document/src/nsFrameFrame.cpp +++ b/layout/html/document/src/nsFrameFrame.cpp @@ -75,8 +75,6 @@ #include "nsXPIDLString.h" #include "nsIScrollable.h" #include "nsINameSpaceManager.h" -#include "nsIPrintContext.h" -#include "nsIPrintPreviewContext.h" #include "nsIWidget.h" #include "nsIWebBrowserPrint.h" #include "nsWeakReference.h" @@ -261,25 +259,19 @@ nsSubDocumentFrame::Init(nsIPresContext* aPresContext, } // determine if we are a printcontext - PRBool shouldCreateDoc = PR_TRUE; - nsCOMPtr thePrinterContext(do_QueryInterface(aPresContext)); + PRBool shouldCreateDoc; + + if (aPresContext->Medium() == nsLayoutAtoms::print) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + // for print preview we want to create the view and widget but + // we do not want to load the document, it is already loaded. + rv = CreateViewAndWidget(eContentTypeContent); + NS_ENSURE_SUCCESS(rv,rv); + } - if (thePrinterContext) { - // we are printing - shouldCreateDoc = PR_FALSE; - } - - // for print preview we want to create the view and widget but - // we do not want to load the document, it is alerady loaded. - nsCOMPtr thePrintPreviewContext = - do_QueryInterface(aPresContext); - - if (thePrintPreviewContext) { - rv = CreateViewAndWidget(eContentTypeContent); - NS_ENSURE_SUCCESS(rv,rv); - - // we are in PrintPreview shouldCreateDoc = PR_FALSE; + } else { + shouldCreateDoc = PR_TRUE; } if (shouldCreateDoc) { @@ -306,7 +298,7 @@ nsSubDocumentFrame::GetDesiredSize(nsIPresContext* aPresContext, if (!mContent->IsContentOfType(nsIContent::eXUL)) // If no width/height was specified, use 300/150. // This is for compatability with IE. - aPresContext->GetScaledPixelsToTwips(&p2t); + p2t = aPresContext->ScaledPixelsToTwips(); if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) { aDesiredSize.width = aReflowState.mComputedWidth; diff --git a/layout/html/document/src/nsFrameSetFrame.cpp b/layout/html/document/src/nsFrameSetFrame.cpp index ab2c3e810cb..4ebf7dbd175 100644 --- a/layout/html/document/src/nsFrameSetFrame.cpp +++ b/layout/html/document/src/nsFrameSetFrame.cpp @@ -525,8 +525,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext, PRInt32 numRelative = 0; PRInt32* relative= new PRInt32[aNumSpecs]; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); PRInt32 i, j; // initialize the fixed, percent, relative indices, allocate the fixed sizes and zero the others @@ -637,8 +636,7 @@ PRInt32 nsHTMLFramesetFrame::GetBorderWidth(nsIPresContext* aPresContext, return 0; } } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); nsHTMLValue htmlVal; nsCOMPtr content(do_QueryInterface(mContent)); diff --git a/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index 99b27f8e786..5d002b23bfa 100644 --- a/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -181,16 +181,16 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIPresContext* aPresContext, { const nsStyleDisplay* disp = GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, this, disp->mAppearance)) return; // No need to paint the checkbox. The theme will do it. } - aRenderingContext.PushState(); + // Get current checked state through content model. + if (!GetCheckboxState()) + return; // we're not checked, nothing to paint. - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + aRenderingContext.PushState(); nsMargin borderPadding(0,0,0,0); CalcBorderPadding(borderPadding); @@ -201,11 +201,10 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIPresContext* aPresContext, const nsStyleColor* color = GetStyleColor(); aRenderingContext.SetColor(color->mColor); - // Get current checked state through content model. - if ( GetCheckboxState() ) { - nsFormControlHelper::PaintCheckMark(aRenderingContext, p2t, checkRect); - } - + nsFormControlHelper::PaintCheckMark(aRenderingContext, + aPresContext->ScaledPixelsToTwips(), + checkRect); + aRenderingContext.PopState(); } diff --git a/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 4ff2331ef6a..9d8c4a87519 100644 --- a/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -171,8 +171,7 @@ nsGfxRadioControlFrame::PaintRadioButton(nsIPresContext* aPresContext, { const nsStyleDisplay* disp = GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, this, disp->mAppearance)) return; // No need to paint the radio button. The theme will do it. } diff --git a/layout/html/forms/src/nsListControlFrame.cpp b/layout/html/forms/src/nsListControlFrame.cpp index 0b3d8e9d9dc..6c6b76ee56e 100644 --- a/layout/html/forms/src/nsListControlFrame.cpp +++ b/layout/html/forms/src/nsListControlFrame.cpp @@ -550,8 +550,7 @@ nsListControlFrame::Paint(nsIPresContext* aPresContext, if (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND) { const nsStyleDisplay* displayData = GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); nsRect rect(0, 0, mRect.width, mRect.height); if (theme && theme->ThemeSupportsWidget(aPresContext, this, displayData->mAppearance)) theme->DrawWidgetBackground(&aRenderingContext, this, @@ -687,9 +686,7 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsFramePaintLayer nsILookAndFeel::eColor_WidgetSelectForeground : nsILookAndFeel::eColor_WidgetSelectBackground, color); - float p2t; - mPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixelInTwips = NSToCoordRound(p2t); + nscoord onePixelInTwips = mPresContext->IntScaledPixelsToTwips(1); nsRect dirty; nscolor colors[] = {color, color, color, color}; diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index 691eb68a2d6..e1e69f7a776 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -103,7 +103,6 @@ #include "nsFormControlHelper.h" #include "nsObjectFrame.h" #include "nsRuleNode.h" -#include "nsIPrintPreviewContext.h" #include "nsIDOMMutationEvent.h" #include "nsChildIterator.h" #include "nsCSSRendering.h" @@ -3709,7 +3708,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // the entire canvas as specified by the CSS2 spec PRBool isPaginated = aPresContext->IsPaginated(); - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; nsIFrame* rootFrame = nsnull; nsIAtom* rootPseudo; @@ -3789,7 +3789,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, } if (isPaginated) { - if (printPreviewContext) { // print preview + if (isPrintPreview) { isScrollable = aPresContext->HasPaginatedScrolling(); } else { isScrollable = PR_FALSE; // we are printing @@ -3814,7 +3814,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, nsIFrame* parentFrame = viewportFrame; // If paginated, make sure we don't put scrollbars in - if (isPaginated && !printPreviewContext) + if (isPaginated && !isPrintPreview) rootPseudoStyle = styleSet->ResolvePseudoStyleFor(nsnull, rootPseudo, viewportPseudoStyle); @@ -3911,7 +3911,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, rootFrame->Init(aPresContext, aDocElement, parentFrame, rootPseudoStyle, nsnull); - if (!isPaginated || printPreviewContext) { + if (!isPaginated || isPrintPreview) { if (isScrollable) { FinishBuildingScrollFrame(aPresContext, state, @@ -5809,11 +5809,13 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh // If the parent is a viewportFrame then we are the scrollbars for the UI // if not then we are scrollbars inside the document. PRBool noScalingOfTwips = PR_FALSE; - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { + PRBool isPrintPreview = + aPresContext->Type() == nsIPresContext::eContext_PrintPreview; + + if (isPrintPreview) { noScalingOfTwips = aParentFrame->GetType() == nsLayoutAtoms::viewportFrame; if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + aPresContext->SetScalingOfTwips(PR_FALSE); } } @@ -5877,8 +5879,8 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh } - if (printPreviewContext && noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + if (isPrintPreview && noScalingOfTwips) { + aPresContext->SetScalingOfTwips(PR_TRUE); } return aScrolledChildStyle;; @@ -5976,11 +5978,10 @@ nsCSSFrameConstructor::BuildScrollFrame(nsIPresShell* aPresShell, // If the parent is a viewportFrame then we are the scrollbars for the UI // if not then we are scrollbars inside the document. PRBool noScalingOfTwips = PR_FALSE; - nsCOMPtr printPreviewContext(do_QueryInterface(aPresContext)); - if (printPreviewContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { noScalingOfTwips = aParentFrame->GetType() == nsLayoutAtoms::viewportFrame; if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + aPresContext->SetScalingOfTwips(PR_FALSE); } } @@ -6018,7 +6019,7 @@ nsCSSFrameConstructor::BuildScrollFrame(nsIPresShell* aPresShell, aState.mFrameManager->SetPrimaryFrameFor( aContent, aNewFrame ); if (noScalingOfTwips) { - printPreviewContext->SetScalingOfTwips(PR_TRUE); + aPresContext->SetScalingOfTwips(PR_TRUE); } return NS_OK; @@ -9950,13 +9951,14 @@ nsCSSFrameConstructor::DoContentStateChanged(nsIPresContext* aPresContext, if (primaryFrame) { PRUint8 app = primaryFrame->GetStyleDisplay()->mAppearance; if (app) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); - PRBool repaint = PR_FALSE; - if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, app)) + nsITheme *theme = aPresContext->GetTheme(); + if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, app)) { + PRBool repaint = PR_FALSE; theme->WidgetStateChanged(primaryFrame, app, nsnull, &repaint); - if (repaint) - ApplyRenderingChangeToTree(aPresContext, primaryFrame, nsnull, nsChangeHint_RepaintFrame); + if (repaint) { + ApplyRenderingChangeToTree(aPresContext, primaryFrame, nsnull, nsChangeHint_RepaintFrame); + } + } } } @@ -10042,8 +10044,7 @@ nsCSSFrameConstructor::AttributeChanged(nsIPresContext* aPresContext, if (primaryFrame) { const nsStyleDisplay* disp = primaryFrame->GetStyleDisplay(); if (disp->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, primaryFrame, disp->mAppearance)) { PRBool repaint = PR_FALSE; theme->WidgetStateChanged(primaryFrame, disp->mAppearance, aAttribute, &repaint); diff --git a/layout/html/style/src/nsCSSRendering.cpp b/layout/html/style/src/nsCSSRendering.cpp index 571960edd3d..95add6658e1 100644 --- a/layout/html/style/src/nsCSSRendering.cpp +++ b/layout/html/style/src/nsCSSRendering.cpp @@ -58,7 +58,6 @@ #include "gfxIImageFrame.h" #include "nsCSSRendering.h" #include "nsCSSColorUtils.h" -#include "nsIPrintContext.h" #include "nsITheme.h" #include "nsThemeConstants.h" #include "nsIServiceManager.h" @@ -1634,8 +1633,7 @@ void nsCSSRendering::PaintBorder(nsIPresContext* aPresContext, // may be different! Always use |aStyleContext|! const nsStyleDisplay* displayData = aStyleContext->GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) return; // Let the theme handle it. } @@ -1795,10 +1793,7 @@ void nsCSSRendering::PaintBorder(nsIPresContext* aPresContext, } } /* Get our conversion values */ - nscoord twipsPerPixel; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - twipsPerPixel = NSIntPixelsToTwips(1,p2t); + nscoord twipsPerPixel = aPresContext->IntScaledPixelsToTwips(1); static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT }; nscolor sideColor; @@ -2791,8 +2786,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, // renderer draw the background and bail out. const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay(); if (displayData->mAppearance) { - nsCOMPtr theme; - aPresContext->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) { theme->DrawWidgetBackground(&aRenderingContext, aForFrame, displayData->mAppearance, aBorderArea, aDirtyRect); @@ -2834,14 +2828,14 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, // We have a background image // Lookup the image - nsCOMPtr req; - nsresult rv = aPresContext->LoadImage(aColor.mBackgroundImage, aForFrame, getter_AddRefs(req)); + imgIRequest *req = aPresContext->LoadImage(aColor.mBackgroundImage, + aForFrame); PRUint32 status = imgIRequest::STATUS_ERROR; if (req) req->GetImageStatus(&status); - if (NS_FAILED(rv) || !req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) { + if (!req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) { PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea, aColor, aBorder, aPadding, canDrawBackgroundColor); return; diff --git a/layout/html/table/src/BasicTableLayoutStrategy.cpp b/layout/html/table/src/BasicTableLayoutStrategy.cpp index 27e0e25f596..90cab82ab0e 100644 --- a/layout/html/table/src/BasicTableLayoutStrategy.cpp +++ b/layout/html/table/src/BasicTableLayoutStrategy.cpp @@ -217,8 +217,7 @@ BasicTableLayoutStrategy::BalanceColumnWidths(const nsHTMLReflowState& aReflowSt #ifdef DEBUG_TABLE_REFLOW_TIMING nsTableFrame::DebugTimeMethod(nsTableFrame::eBalanceCols, *mTableFrame, (nsHTMLReflowState&)aReflowState, PR_TRUE); #endif - float p2t; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&p2t); + float p2t = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); ContinuingFrameCheck(); @@ -1003,8 +1002,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aMax PRInt32 colX, rowX; mCellSpacingTotal = 0; PRBool hasPctCol = PR_FALSE; // return value - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); + float pixelToTwips = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); PRInt32 rawPropTotal = -1; // total of numbers of the type 1*, 2*, etc PRInt32 numColsForColsAttr = 0; // Nav Quirks cols attribute for equal width cols @@ -1242,8 +1240,7 @@ BasicTableLayoutStrategy::CalcPctAdjTableWidth(const nsHTMLReflowState& aReflowS PRInt32 numRows = mTableFrame->GetRowCount(); PRInt32 numCols = mTableFrame->GetColCount(); // consider cols at end without orig cells PRInt32 colX, rowX; - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); + float pixelToTwips = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); // For an auto table, determine the potentially new percent adjusted width based // on percent cells/cols. This probably should only be a NavQuirks thing, since diff --git a/layout/html/table/src/FixedTableLayoutStrategy.cpp b/layout/html/table/src/FixedTableLayoutStrategy.cpp index 52d3850337f..e69de29bb2d 100644 --- a/layout/html/table/src/FixedTableLayoutStrategy.cpp +++ b/layout/html/table/src/FixedTableLayoutStrategy.cpp @@ -1,300 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "FixedTableLayoutStrategy.h" -#include "nsTableFrame.h" -#include "nsTableCellFrame.h" -#include "nsStyleConsts.h" -#include "nsVoidArray.h" - -FixedTableLayoutStrategy::FixedTableLayoutStrategy(nsTableFrame *aFrame) - : BasicTableLayoutStrategy(aFrame) -{ -} - -FixedTableLayoutStrategy::~FixedTableLayoutStrategy() -{ -} - -PRBool FixedTableLayoutStrategy::BalanceColumnWidths(const nsHTMLReflowState& aReflowState) -{ - return PR_TRUE; -} - -/* - * assign the width of all columns - * if there is a colframe with a width attribute, use it as the column width - * otherwise if there is a cell in the first row and it has a width attribute, use it - * if this cell includes a colspan, width is divided equally among spanned columns - * otherwise the cell get a proportion of the remaining space - * as determined by the table width attribute. If no table width attribute, it gets 0 width - */ -PRBool -FixedTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aComputedWidth, - const nsHTMLReflowState& aReflowState) -{ - // NS_ASSERTION(aComputedWidth != NS_UNCONSTRAINEDSIZE, "bad computed width"); - const nsStylePosition* tablePosition = mTableFrame->GetStylePosition(); - PRBool tableIsFixedWidth = eStyleUnit_Coord == tablePosition->mWidth.GetUnit() || - eStyleUnit_Percent == tablePosition->mWidth.GetUnit(); - - PRInt32 numCols = mTableFrame->GetColCount(); - PRInt32 colX; - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); - // availWidth is used as the basis for percentage width columns. It is aComputedWidth - // minus table border, padding, & cellspacing - nscoord spacingX = mTableFrame->GetCellSpacingX(); - mCellSpacingTotal = spacingX; - for (colX = 0; colX < numCols; colX++){ - if (mTableFrame->GetNumCellsOriginatingInCol(colX) > 0) { - mCellSpacingTotal += spacingX; - } - } - nscoord availWidth = (NS_UNCONSTRAINEDSIZE == aComputedWidth) - ? NS_UNCONSTRAINEDSIZE - : aComputedWidth - aReflowState.mComputedBorderPadding.left - - aReflowState.mComputedBorderPadding.right - - mCellSpacingTotal; - - PRInt32 specifiedCols = 0; // the number of columns whose width is given - nscoord totalColWidth = 0; // the sum of the widths of the columns - - nscoord* colWidths = new nscoord[numCols]; - if (!colWidths) return PR_FALSE; - memset(colWidths, WIDTH_NOT_SET, numCols*sizeof(nscoord)); - - nscoord* propInfo = new nscoord[numCols]; - if (!propInfo) { - delete [] colWidths; - return PR_FALSE; - } - - memset(propInfo, 0, numCols*sizeof(nscoord)); - nscoord propTotal = 0; - nscoord percTotal = 0; - // for every column, determine its specified width - for (colX = 0; colX < numCols; colX++) { - // Get column information - nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX); - if (!colFrame) { - NS_ASSERTION(PR_FALSE, "bad col frame"); - return PR_FALSE; - } - - // Get the columns's style - const nsStylePosition* colPosition = colFrame->GetStylePosition(); - - // get the fixed width if available - if (eStyleUnit_Coord == colPosition->mWidth.GetUnit()) { - colWidths[colX] = colPosition->mWidth.GetCoordValue(); - colFrame->SetWidth(MIN_CON, colWidths[colX]); - } // get the percentage width - else if ((eStyleUnit_Percent == colPosition->mWidth.GetUnit()) && - (aComputedWidth != NS_UNCONSTRAINEDSIZE)) { - // Only apply percentages if we're constrained. - float percent = colPosition->mWidth.GetPercentValue(); - colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(percent * (float)availWidth), pixelToTwips); - colFrame->SetWidth(PCT, colWidths[colX]); - percTotal+=colWidths[colX]; - } - else if (eStyleUnit_Proportional == colPosition->mWidth.GetUnit() && - colPosition->mWidth.GetIntValue() > 0) { - propInfo[colX] = colPosition->mWidth.GetIntValue(); - propTotal += propInfo[colX]; - } - else { // get width from the cell - - nsTableCellFrame* cellFrame = mTableFrame->GetCellFrameAt(0, colX); - if (nsnull != cellFrame) { - // Get the cell's style - const nsStylePosition* cellPosition = cellFrame->GetStylePosition(); - - nscoord cellWidth = 0; - PRInt32 colSpan = mTableFrame->GetEffectiveColSpan(*cellFrame); - // Get fixed cell width if available - if (eStyleUnit_Coord == cellPosition->mWidth.GetUnit()) { - // need to add border and padding into fixed width - nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - pixelToTwips, cellFrame); - cellWidth = cellPosition->mWidth.GetCoordValue() + borderPadding.left + borderPadding.right; - colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - pixelToTwips); - colFrame->SetWidth(MIN_CON, colWidths[colX]); - } - else if ((eStyleUnit_Percent == cellPosition->mWidth.GetUnit()) && - (aComputedWidth != NS_UNCONSTRAINEDSIZE)) { - float percent = cellPosition->mWidth.GetPercentValue(); - // need to add border and padding into percent width - nsMargin borderPadding = nsTableFrame::GetBorderPadding(nsSize(aReflowState.mComputedWidth, 0), - pixelToTwips, cellFrame); - cellWidth = NSToCoordRound(percent * (float) availWidth) + borderPadding.left + borderPadding.right; - colWidths[colX] = nsTableFrame::RoundToPixel(NSToCoordRound(((float) cellWidth) / ((float) colSpan)), - pixelToTwips); - colFrame->SetWidth(PCT, colWidths[colX]); - percTotal += colWidths[colX]; - } - } - } - if (colWidths[colX] >= 0) { - totalColWidth += colWidths[colX]; - specifiedCols++; - } - } - - nscoord lastColAllocated = -1; - nscoord remainingWidth = availWidth - totalColWidth; - if(availWidth == NS_UNCONSTRAINEDSIZE) - remainingWidth = 0; - if (remainingWidth >= 500000) { - // let's put a cap on the width so that it doesn't become insane. - remainingWidth = 100; - } - - if (0 < remainingWidth) { - if (propTotal > 0) { - nscoord amountToAllocate = 0; - for (colX = 0; colX < numCols; colX++) { - if (propInfo[colX] > 0) { - // We're proportional - float percent = ((float)propInfo[colX])/((float)propTotal); - amountToAllocate += NSToCoordRound(percent * (float)remainingWidth); - colWidths[colX] = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, - eRoundUpIfHalfOrMore) : 0; - totalColWidth += colWidths[colX]; - amountToAllocate -= colWidths[colX]; - lastColAllocated = colX; - } - } - } - else if (tableIsFixedWidth) { - if (numCols > specifiedCols) { - // allocate the extra space to the columns which have no width specified - nscoord colAlloc = - NSToCoordRound(((float)remainingWidth) / - (((float)numCols) - ((float)specifiedCols))); - nscoord amountToAllocate = 0; - for (colX = 0; colX < numCols; colX++) { - if (-1 == colWidths[colX]) { - amountToAllocate += colAlloc; - colWidths[colX] = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, - pixelToTwips, - eRoundUpIfHalfOrMore) : 0; - totalColWidth += colWidths[colX]; - amountToAllocate -= colWidths[colX]; - lastColAllocated = colX; - } - } - } - else { // allocate the extra space to the columns which have width specified - float divisor = (float)totalColWidth; - nscoord amountToAllocate = 0; - for (colX = 0; colX < numCols; colX++) { - if (colWidths[colX] > 0) { - amountToAllocate += NSToCoordRound(remainingWidth * colWidths[colX] / divisor); - nscoord colAlloc = (amountToAllocate > 0) ? - nsTableFrame::RoundToPixel(amountToAllocate, pixelToTwips, - eRoundUpIfHalfOrMore) : 0; - colWidths[colX] += colAlloc; - totalColWidth += colAlloc; - amountToAllocate -= colAlloc; - lastColAllocated = colX; - } - } - } - } - } - - nscoord overAllocation = ((availWidth >= 0) && (availWidth != NS_UNCONSTRAINEDSIZE)) - ? totalColWidth - availWidth : 0; - // set the column widths - for (colX = 0; colX < numCols; colX++) { - if (colWidths[colX] < 0) - colWidths[colX] = 0; - // if there was too much allocated due to rounding, remove it from the last col - if ((colX == lastColAllocated) && (overAllocation != 0)) { - nscoord thisRemoval = nsTableFrame::RoundToPixel(overAllocation, pixelToTwips); - colWidths[colX] -= thisRemoval; - totalColWidth -= thisRemoval; - - totalColWidth -= colWidths[colX] - PR_MAX(0, colWidths[colX]); - colWidths[colX] = PR_MAX(0, colWidths[colX]); - } - } - overAllocation = ((availWidth >= 0) && (availWidth != NS_UNCONSTRAINEDSIZE)) - ? totalColWidth - availWidth : 0; - if(overAllocation > 0){ - // reduce over specified percent col - nscoord amountToRemove = 0; - for (colX = 0; colX < numCols; colX++) { - nsTableColFrame* colFrame = mTableFrame->GetColFrame(colX); - if(( colFrame->GetWidth(PCT) > 0) && ( percTotal > 0)){ - amountToRemove += NSToCoordRound(overAllocation* colWidths[colX] / (float) percTotal); - nscoord thisRemoval = (amountToRemove > 0) ? - nsTableFrame::RoundToPixel(amountToRemove, pixelToTwips, - eRoundUpIfHalfOrMore) : 0; - colWidths[colX] -= thisRemoval; - amountToRemove -= thisRemoval; - totalColWidth -= thisRemoval; - - totalColWidth -= colWidths[colX] - PR_MAX(0, colWidths[colX]); - colWidths[colX] = PR_MAX(0, colWidths[colX]); - colFrame->SetWidth(PCT, colWidths[colX]); - } - } - } - for (colX = 0; colX < numCols; colX++) { - mTableFrame->SetColumnWidth(colX, colWidths[colX]); - } - - // clean up - if (nsnull != colWidths) { - delete [] colWidths; - } - - if (nsnull != propInfo) { - delete [] propInfo; - } - - return PR_TRUE; -} - - - - diff --git a/layout/html/table/src/nsTableCellFrame.cpp b/layout/html/table/src/nsTableCellFrame.cpp index 9694940be8a..c6e35ec1f85 100644 --- a/layout/html/table/src/nsTableCellFrame.cpp +++ b/layout/html/table/src/nsTableCellFrame.cpp @@ -588,9 +588,9 @@ void nsTableCellFrame::VerticallyAlignChild(nsIPresContext* aPresContex case NS_STYLE_VERTICAL_ALIGN_MIDDLE: // Align the middle of the child frame with the middle of the content area, kidYTop = (height - childHeight - bottomInset + topInset) / 2; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - kidYTop = nsTableFrame::RoundToPixel(kidYTop, p2t, eAlwaysRoundDown); + kidYTop = nsTableFrame::RoundToPixel(kidYTop, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } firstKid->SetPosition(nsPoint(kidRect.x, kidYTop)); nsHTMLReflowMetrics desiredSize(PR_FALSE); @@ -726,8 +726,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext* aPresContext, #if defined DEBUG_TABLE_REFLOW_TIMING nsTableFrame::DebugReflow(this, (nsHTMLReflowState&)aReflowState); #endif - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); // work around pixel rounding errors, round down to ensure we don't exceed the avail height in nscoord availHeight = aReflowState.availableHeight; diff --git a/layout/html/table/src/nsTableFrame.h b/layout/html/table/src/nsTableFrame.h index 37081404ad6..cb2f3548062 100644 --- a/layout/html/table/src/nsTableFrame.h +++ b/layout/html/table/src/nsTableFrame.h @@ -1153,12 +1153,10 @@ return;} return aReturn;} #define GET_PIXELS_TO_TWIPS(presContext,var) \ - float var; \ - (presContext)->GetScaledPixelsToTwips(&var); + float var = (presContext)->ScaledPixelsToTwips(); #define GET_TWIPS_TO_PIXELS(presContext,var) \ - float var; \ - (presContext)->GetScaledPixelsToTwips(&var); \ + float var = (presContext)->ScaledPixelsToTwips(); \ var = 1.0f / var; #endif diff --git a/layout/html/table/src/nsTableOuterFrame.cpp b/layout/html/table/src/nsTableOuterFrame.cpp index 32514a2f57d..f817c4e16ca 100644 --- a/layout/html/table/src/nsTableOuterFrame.cpp +++ b/layout/html/table/src/nsTableOuterFrame.cpp @@ -54,7 +54,6 @@ #endif #include "nsIServiceManager.h" #include "nsIDOMNode.h" -#include "nsIPrintContext.h" /* ----------- nsTableCaptionFrame ---------- */ @@ -941,9 +940,9 @@ nsTableOuterFrame::BalanceLeftRightCaption(nsIPresContext* aPresContext, else { aCaptionWidth = (nscoord) ((capPercent / innerPercent) * aInnerWidth); } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - aCaptionWidth = nsTableFrame::RoundToPixel(aCaptionWidth, p2t, eAlwaysRoundDown); + aCaptionWidth = nsTableFrame::RoundToPixel(aCaptionWidth, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } nsresult @@ -963,8 +962,7 @@ nsTableOuterFrame::GetCaptionOrigin(nsIPresContext* aPresContext, } if (!mCaptionFrame) return NS_OK; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); switch(aCaptionSide) { case NS_SIDE_BOTTOM: { @@ -1075,8 +1073,7 @@ nsTableOuterFrame::GetInnerOrigin(nsIPresContext* aPresContext, return NS_OK; } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); nscoord minCapWidth = aCaptionSize.width; if (NS_AUTOMARGIN != aCaptionMargin.left) @@ -1261,11 +1258,11 @@ nsTableOuterFrame::OuterReflowChild(nsIPresContext* aPresContext, aMargin = aPadding = nsMargin(0,0,0,0); // work around pixel rounding errors, round down to ensure we don't exceed the avail height in - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); nscoord availHeight = aOuterRS.availableHeight; if (NS_UNCONSTRAINEDSIZE != availHeight) { - availHeight = nsTableFrame::RoundToPixel(availHeight, p2t, eAlwaysRoundDown); + availHeight = nsTableFrame::RoundToPixel(availHeight, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } nsSize availSize(aAvailWidth, availHeight); if (mCaptionFrame == aChildFrame) { diff --git a/layout/html/table/src/nsTablePainter.cpp b/layout/html/table/src/nsTablePainter.cpp index 8f2bfb0aa50..cdf5278ed12 100644 --- a/layout/html/table/src/nsTablePainter.cpp +++ b/layout/html/table/src/nsTablePainter.cpp @@ -246,7 +246,7 @@ TableBackgroundPainter::TableBackgroundPainter(nsTableFrame* aTableFrame, mZeroPadding.RecalcData(); - mPresContext->GetScaledPixelsToTwips(&mP2t); + mP2t = mPresContext->ScaledPixelsToTwips(); mIsBorderCollapse = aTableFrame->IsBorderCollapse(); #ifdef DEBUG mCompatMode = mPresContext->CompatibilityMode(); diff --git a/layout/mathml/base/src/nsMathMLChar.cpp b/layout/mathml/base/src/nsMathMLChar.cpp index 638386f0da4..6e46f3f2c1d 100644 --- a/layout/mathml/base/src/nsMathMLChar.cpp +++ b/layout/mathml/base/src/nsMathMLChar.cpp @@ -2078,9 +2078,7 @@ nsMathMLChar::PaintVertically(nsIPresContext* aPresContext, nsRect clipRect; nscoord dx, dy; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); // get metrics data to be re-used later PRInt32 i; @@ -2255,9 +2253,7 @@ nsMathMLChar::PaintHorizontally(nsIPresContext* aPresContext, nsRect clipRect; nscoord dx, dy; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); // get metrics data to be re-used later PRInt32 i; diff --git a/layout/mathml/base/src/nsMathMLFrame.cpp b/layout/mathml/base/src/nsMathMLFrame.cpp index 3ca40e48737..0a7e9d8d1bd 100644 --- a/layout/mathml/base/src/nsMathMLFrame.cpp +++ b/layout/mathml/base/src/nsMathMLFrame.cpp @@ -418,9 +418,8 @@ nsMathMLFrame::CalcLength(nsIPresContext* aPresContext, nsCSSUnit unit = aCSSValue.GetUnit(); if (eCSSUnit_Pixel == unit) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - return NSFloatPixelsToTwips(aCSSValue.GetFloatValue(), p2t); + return NSFloatPixelsToTwips(aCSSValue.GetFloatValue(), + aPresContext->ScaledPixelsToTwips()); } else if (eCSSUnit_EM == unit) { const nsStyleFont* font = aStyleContext->GetStyleFont(); @@ -429,8 +428,7 @@ nsMathMLFrame::CalcLength(nsIPresContext* aPresContext, else if (eCSSUnit_XHeight == unit) { nscoord xHeight; const nsStyleFont* font = aStyleContext->GetStyleFont(); - nsCOMPtr fm; - aPresContext->GetMetricsFor(font->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(font->mFont); fm->GetXHeight(xHeight); return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight); } diff --git a/layout/mathml/base/src/nsMathMLFrame.h b/layout/mathml/base/src/nsMathMLFrame.h index 443ec6b8e62..479f3f16c0a 100644 --- a/layout/mathml/base/src/nsMathMLFrame.h +++ b/layout/mathml/base/src/nsMathMLFrame.h @@ -268,8 +268,7 @@ public: nscoord& aSubDrop) { const nsStyleFont* font = aChild->GetStyleFont(); - nsCOMPtr fm; - aPresContext->GetMetricsFor(font->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(font->mFont); GetSubDrop(fm, aSubDrop); } @@ -279,8 +278,7 @@ public: nscoord& aSupDrop) { const nsStyleFont* font = aChild->GetStyleFont(); - nsCOMPtr fm; - aPresContext->GetMetricsFor(font->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(font->mFont); GetSupDrop(fm, aSupDrop); } diff --git a/layout/mathml/base/src/nsMathMLTokenFrame.cpp b/layout/mathml/base/src/nsMathMLTokenFrame.cpp index 83378f9c9f8..1d050c1be8e 100644 --- a/layout/mathml/base/src/nsMathMLTokenFrame.cpp +++ b/layout/mathml/base/src/nsMathMLTokenFrame.cpp @@ -205,8 +205,8 @@ nsMathMLTokenFrame::Place(nsIPresContext* aPresContext, PRBool aPlaceOrigin, nsHTMLReflowMetrics& aDesiredSize) { - nsCOMPtr fm; - aPresContext->GetMetricsFor(GetStyleFont()->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = + aPresContext->GetMetricsFor(GetStyleFont()->mFont); nscoord ascent, descent; fm->GetMaxAscent(ascent); fm->GetMaxDescent(descent); diff --git a/layout/mathml/base/src/nsMathMLmfracFrame.cpp b/layout/mathml/base/src/nsMathMLmfracFrame.cpp index fb1cee8cb16..5f5f8a4a9b3 100644 --- a/layout/mathml/base/src/nsMathMLmfracFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmfracFrame.cpp @@ -292,9 +292,7 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext, ////////////////// // Get shifts - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aRenderingContext.SetFont(GetStyleFont()->mFont, nsnull); nsCOMPtr fm; diff --git a/layout/mathml/base/src/nsMathMLmoFrame.cpp b/layout/mathml/base/src/nsMathMLmoFrame.cpp index 56308ff9112..6b87bd765a6 100644 --- a/layout/mathml/base/src/nsMathMLmoFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmoFrame.cpp @@ -431,8 +431,8 @@ nsMathMLmoFrame::ProcessOperatorData(nsIPresContext* aPresContext) // cache the default values of lspace & rspace that we get from the dictionary. // since these values are relative to the 'em' unit, convert to twips now nscoord em; - nsCOMPtr fm; - aPresContext->GetMetricsFor(GetStyleFont()->mFont, getter_AddRefs(fm)); + nsCOMPtr fm = + aPresContext->GetMetricsFor(GetStyleFont()->mFont); GetEmHeight(fm, em); mEmbellishData.leftSpace = NSToCoordRound(lspace * em); @@ -493,9 +493,7 @@ nsMathMLmoFrame::ProcessOperatorData(nsIPresContext* aPresContext) // little extra tuning to round lspace & rspace to at least a pixel so that // operators don't look as if they are colliding with their operands if (leftSpace || rightSpace) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); if (leftSpace && leftSpace < onePixel) leftSpace = onePixel; if (rightSpace && rightSpace < onePixel) diff --git a/layout/mathml/base/src/nsMathMLmoverFrame.cpp b/layout/mathml/base/src/nsMathMLmoverFrame.cpp index 732b6c17104..0b5826734c7 100644 --- a/layout/mathml/base/src/nsMathMLmoverFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmoverFrame.cpp @@ -306,9 +306,7 @@ nsMathMLmoverFrame::Place(nsIPresContext* aPresContext, GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase); GetReflowAndBoundingMetricsFor(overFrame, overSize, bmOver); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); //////////////////// // Place Children diff --git a/layout/mathml/base/src/nsMathMLmrootFrame.cpp b/layout/mathml/base/src/nsMathMLmrootFrame.cpp index b6aa353503d..d11876643cf 100644 --- a/layout/mathml/base/src/nsMathMLmrootFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmrootFrame.cpp @@ -284,9 +284,7 @@ nsMathMLmrootFrame::Reflow(nsIPresContext* aPresContext, // the thickness of the overline ruleThickness = bmSqr.ascent; // make sure that the rule appears on on screen - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); if (ruleThickness < onePixel) { ruleThickness = onePixel; } diff --git a/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp b/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp index 54e51712d69..a6b22134aef 100644 --- a/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp @@ -253,9 +253,7 @@ nsMathMLmsqrtFrame::Reflow(nsIPresContext* aPresContext, // the thickness of the overline ruleThickness = bmSqr.ascent; // make sure that the rule appears on the screen - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); if (ruleThickness < onePixel) { ruleThickness = onePixel; } diff --git a/layout/mathml/base/src/nsMathMLmsubFrame.cpp b/layout/mathml/base/src/nsMathMLmsubFrame.cpp index 669c39af06b..848916bcb56 100644 --- a/layout/mathml/base/src/nsMathMLmsubFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmsubFrame.cpp @@ -142,9 +142,7 @@ nsMathMLmsubFrame::PlaceSubScript (nsIPresContext* aPresContext, if (!mathMLFrame) return NS_ERROR_INVALID_ARG; // force the scriptSpace to be atleast 1 pixel - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - aScriptSpace = PR_MAX(NSIntPixelsToTwips(1, p2t), aScriptSpace); + aScriptSpace = PR_MAX(aPresContext->IntScaledPixelsToTwips(1), aScriptSpace); //////////////////////////////////// // Get the children's desired sizes @@ -179,10 +177,9 @@ nsMathMLmsubFrame::PlaceSubScript (nsIPresContext* aPresContext, // get min subscript shift limit from x-height // = h(x) - 4/5 * sigma_5, Rule 18b, App. G, TeXbook nscoord xHeight = 0; - nsCOMPtr fm; + nsCOMPtr fm = + aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); - aPresContext->GetMetricsFor (baseFrame->GetStyleFont()->mFont, - getter_AddRefs(fm)); fm->GetXHeight (xHeight); nscoord minShiftFromXHeight = (nscoord) (bmSubScript.ascent - (4.0f/5.0f) * xHeight); diff --git a/layout/mathml/base/src/nsMathMLmsubsupFrame.cpp b/layout/mathml/base/src/nsMathMLmsubsupFrame.cpp index 936a6a564f5..ff3a974a8db 100644 --- a/layout/mathml/base/src/nsMathMLmsubsupFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmsubsupFrame.cpp @@ -158,9 +158,7 @@ nsMathMLmsubsupFrame::PlaceSubSupScript(nsIPresContext* aPresContext, if (!mathMLFrame) return NS_ERROR_INVALID_ARG; // force the scriptSpace to be atleast 1 pixel - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aScriptSpace = PR_MAX(onePixel, aScriptSpace); //////////////////////////////////// diff --git a/layout/mathml/base/src/nsMathMLmsupFrame.cpp b/layout/mathml/base/src/nsMathMLmsupFrame.cpp index 950fef0f79f..82cfce0ccf8 100644 --- a/layout/mathml/base/src/nsMathMLmsupFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmsupFrame.cpp @@ -142,9 +142,7 @@ nsMathMLmsupFrame::PlaceSuperScript(nsIPresContext* aPresContext, if (!mathMLFrame) return NS_ERROR_INVALID_ARG; // force the scriptSpace to be at least 1 pixel - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aScriptSpace = PR_MAX(onePixel, aScriptSpace); //////////////////////////////////// @@ -180,10 +178,9 @@ nsMathMLmsupFrame::PlaceSuperScript(nsIPresContext* aPresContext, // get min supscript shift limit from x-height // = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook nscoord xHeight = 0; - nsCOMPtr fm; + nsCOMPtr fm = + aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); - aPresContext->GetMetricsFor (baseFrame->GetStyleFont()->mFont, - getter_AddRefs(fm)); fm->GetXHeight (xHeight); nscoord minShiftFromXHeight = (nscoord) (bmSupScript.descent + (1.0f/4.0f) * xHeight); diff --git a/layout/mathml/base/src/nsMathMLmunderFrame.cpp b/layout/mathml/base/src/nsMathMLmunderFrame.cpp index 16e39c5e8e9..feab44485d3 100644 --- a/layout/mathml/base/src/nsMathMLmunderFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmunderFrame.cpp @@ -303,9 +303,7 @@ nsMathMLmunderFrame::Place(nsIPresContext* aPresContext, GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase); GetReflowAndBoundingMetricsFor(underFrame, underSize, bmUnder); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); //////////////////// // Place Children diff --git a/layout/mathml/base/src/nsMathMLmunderoverFrame.cpp b/layout/mathml/base/src/nsMathMLmunderoverFrame.cpp index b7ae59dfb47..c9e1cca7832 100644 --- a/layout/mathml/base/src/nsMathMLmunderoverFrame.cpp +++ b/layout/mathml/base/src/nsMathMLmunderoverFrame.cpp @@ -346,9 +346,7 @@ nsMathMLmunderoverFrame::Place(nsIPresContext* aPresContext, GetReflowAndBoundingMetricsFor(underFrame, underSize, bmUnder); GetReflowAndBoundingMetricsFor(overFrame, overSize, bmOver); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); //////////////////// // Place Children diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 76dba175305..d87a84bde3e 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -77,7 +77,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsIDOMHTMLObjectElement.h" // Print Preview -#include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants #include "nsIScrollableView.h" #include "nsIScrollable.h" @@ -157,7 +156,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsLayoutAtoms.h" #include "nsFrameManager.h" #include "nsIParser.h" -#include "nsIPrintContext.h" #include "nsGUIEvent.h" #include "nsHTMLReflowState.h" #include "nsIDOMHTMLAnchorElement.h" @@ -173,10 +171,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsPIDOMWindow.h" #include "nsIFocusController.h" -// New PrintPreview -static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); -static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); - //----------------------------------------------------- // PR LOGGING #ifdef MOZ_LOGGING @@ -2567,23 +2561,11 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // create the PresContext PRBool containerIsSet = PR_FALSE; - nsresult rv; - if (mIsCreatingPrintPreview) { - nsCOMPtr printPreviewCon(do_CreateInstance(kPrintPreviewContextCID, &rv)); - if (NS_FAILED(rv)) { - return rv; - } - aPO->mPresContext = do_QueryInterface(printPreviewCon); - printPreviewCon->SetPrintSettings(mPrt->mPrintSettings); - } else { - nsCOMPtr printcon(do_CreateInstance(kPrintContextCID, &rv)); - if (NS_FAILED(rv)) { - return rv; - } - aPO->mPresContext = do_QueryInterface(printcon); - printcon->SetPrintSettings(mPrt->mPrintSettings); - } - + aPO->mPresContext = new nsIPresContext(mIsCreatingPrintPreview ? + nsIPresContext::eContext_PrintPreview: + nsIPresContext::eContext_Print); + NS_ENSURE_TRUE(aPO->mPresContext, NS_ERROR_OUT_OF_MEMORY); + aPO->mPresContext->SetPrintSettings(mPrt->mPrintSettings); // set the presentation context to the value in the print settings PRBool printBGColors; @@ -2594,7 +2576,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // init it with the DC - rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); + nsresult rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); if (NS_FAILED(rv)) { aPO->mPresContext = nsnull; return rv; @@ -2779,7 +2761,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return NS_OK; } - aPO->mPresContext->SetPageDim(&adjRect); + aPO->mPresContext->SetPageDim(adjRect); rv = aPO->mPresShell->InitialReflow(width, height); if (NS_SUCCEEDED(rv)) { // Transfer Selection Ranges to the new Print PresShell @@ -3322,9 +3304,7 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon return NS_ERROR_FAILURE; } - nsCOMPtr ppContext = do_QueryInterface(poPresContext); - if (!ppContext) { - + if (poPresContext->Type() != nsIPresContext::eContext_PrintPreview) { nscoord sheight = seqFrame->GetSize().height; nsRect r = poRootView->GetBounds(); @@ -4491,9 +4471,8 @@ nsPrintEngine::FinishPrintPreview() // Turning off the scaling of twips so any of the UI scrollbars // will not get scaled - nsCOMPtr printPreviewContext(do_QueryInterface(mPresContext)); - if (printPreviewContext) { - printPreviewContext->SetScalingOfTwips(PR_FALSE); + if (mPresContext->Type() == nsIPresContext::eContext_PrintPreview) { + mPresContext->SetScalingOfTwips(PR_FALSE); mDeviceContext->SetCanonicalPixelScale(mPrtPreview->mOrigDCScale); } @@ -4798,8 +4777,7 @@ void DumpLayoutData(char* aTitleStr, } #ifdef NS_PRINT_PREVIEW - nsCOMPtr ppContext = do_QueryInterface(aPresContext); - if (ppContext) { + if (aPresContext->Type() == nsIPresContext::eContext_PrintPreview) { return; } #endif diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index c1327330380..adf110eef83 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -232,9 +232,8 @@ ProcessTableRulesAttribute(nsStyleStruct* aStyleStruct, borderData->SetBorderColor(aSide, borderColor); } // set the border width to be 1 pixel - float p2t; - aRuleData->mPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSToCoordRound(p2t); + nscoord onePixel = + NSToCoordRound(aRuleData->mPresContext->ScaledPixelsToTwips()); nsStyleCoord coord(onePixel); switch(aSide) { case NS_SIDE_TOP: diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 2c788f813f3..ba4d0181f1b 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -198,9 +198,8 @@ nscoord CalcLength(const nsCSSValue& aValue, } nsCSSUnit unit = aValue.GetUnit(); if (unit == eCSSUnit_Pixel) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - return NSFloatPixelsToTwips(aValue.GetFloatValue(), p2t); + return NSFloatPixelsToTwips(aValue.GetFloatValue(), + aPresContext->ScaledPixelsToTwips()); } // Common code for all units other than pixels: aInherited = PR_TRUE; @@ -220,8 +219,7 @@ nscoord CalcLength(const nsCSSValue& aValue, return NSToCoordRound((aValue.GetFloatValue() * (float)font->size) / 2.0f); } case eCSSUnit_XHeight: { - nsCOMPtr fm; - aPresContext->GetMetricsFor(*font, getter_AddRefs(fm)); + nsCOMPtr fm = aPresContext->GetMetricsFor(*font); nscoord xHeight; fm->GetXHeight(xHeight); return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight); @@ -4340,8 +4338,7 @@ SetSVGLength(const nsCSSValue& aValue, float parentLength, float& length, } else { length = (float) coord.GetCoordValue(); - float twipsPerPix; - aPresContext->GetScaledPixelsToTwips(&twipsPerPix); + float twipsPerPix = aPresContext->ScaledPixelsToTwips(); if (twipsPerPix == 0.0f) twipsPerPix = 1e-20f; length /= twipsPerPix; diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index d20158fff77..9ff48068335 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1164,8 +1164,7 @@ nsChangeHint nsStyleDisplay::CalcDifference(const nsStyleDisplay& aOther) const nsStyleVisibility::nsStyleVisibility(nsIPresContext* aPresContext) { - PRUint32 bidiOptions; - aPresContext->GetBidi(&bidiOptions); + PRUint32 bidiOptions = aPresContext->GetBidi(); if (GET_BIDI_OPTION_DIRECTION(bidiOptions) == IBMBIDI_TEXTDIRECTION_RTL) mDirection = NS_STYLE_DIRECTION_RTL; else diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index 241efe497e9..670d60fca8e 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -218,9 +218,8 @@ nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, } // Make special call specifically for fonts (needed PrintPreview) - float t2p; - aPresContext->GetTwipsToPixelsForFonts(&t2p); - PRInt32 fontSize = NSTwipsToIntPixels(aBasePointSize, t2p); + PRInt32 fontSize = NSTwipsToIntPixels(aBasePointSize, + aPresContext->TwipsToPixelsForFonts()); if ((fontSize >= sFontSizeTableMin) && (fontSize <= sFontSizeTableMax)) { diff --git a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp index c1f64148ab1..8af79aea24d 100644 --- a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp +++ b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp @@ -709,10 +709,7 @@ float nsSVGForeignObjectFrame::GetPxPerTwips() float nsSVGForeignObjectFrame::GetTwipsPerPx() { - float twipsPerPx=16.0f; - - GetPresContext()->GetScaledPixelsToTwips(&twipsPerPx); - return twipsPerPx; + return GetPresContext()->ScaledPixelsToTwips(); } void nsSVGForeignObjectFrame::TransformPoint(float& x, float& y) diff --git a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp index 23a2cc75e84..1ed6c452f79 100644 --- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp @@ -367,9 +367,8 @@ nsSVGOuterSVGFrame::Reflow(nsIPresContext* aPresContext, #if defined(DEBUG) && defined(SVG_DEBUG_PRINTING) { printf("nsSVGOuterSVGFrame(%p)::Reflow()[\n",this); - float twipsPerScPx,twipsPerPx; - aPresContext->GetScaledPixelsToTwips(&twipsPerScPx); - twipsPerPx = aPresContext->PixelsToTwips(); + float twipsPerScPx = aPresContext->ScaledPixelsToTwips(); + float twipsPerPx = aPresContext->PixelsToTwips(); printf("tw/sc(px)=%f tw/px=%f\n", twipsPerScPx, twipsPerPx); printf("]\n"); } @@ -789,9 +788,8 @@ nsSVGOuterSVGFrame::Paint(nsIPresContext* aPresContext, float sx=1.0f,sy=1.0f; xform->TransformNoXLate(&sx,&sy); printf("scale=(%f,%f)\n", sx, sy); - float twipsPerScPx,twipsPerPx; - aPresContext->GetScaledPixelsToTwips(&twipsPerScPx); - twipsPerPx = aPresContext->PixelsToTwips(); + float twipsPerScPx = aPresContext->ScaledPixelsToTwips(); + float twipsPerPx = aPresContext->PixelsToTwips(); printf("tw/sc(px)=%f tw/px=%f\n", twipsPerScPx, twipsPerPx); int fontsc; aPresContext->GetFontScaler(&fontsc); @@ -1042,9 +1040,7 @@ float nsSVGOuterSVGFrame::GetPxPerTwips() float nsSVGOuterSVGFrame::GetTwipsPerPx() { - float twipsPerPx; - GetPresContext()->GetScaledPixelsToTwips(&twipsPerPx); - return twipsPerPx; + return GetPresContext()->ScaledPixelsToTwips(); } void nsSVGOuterSVGFrame::InitiateReflow() @@ -1177,9 +1173,7 @@ nsSVGOuterSVGFrame::SetViewportDimensions(nsISVGViewportRect* vp, nsresult nsSVGOuterSVGFrame::SetViewportScale(nsISVGViewportRect* vp, nsIPresContext *context) { - float TwipsPerPx; - context->GetScaledPixelsToTwips(&TwipsPerPx); - float mmPerPx = TwipsPerPx / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); + float mmPerPx = context->ScaledPixelsToTwips() / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); nsCOMPtr scaleX; { diff --git a/layout/svg/renderer/src/cairo/Makefile.in b/layout/svg/renderer/src/cairo/Makefile.in index 2c150bc5882..fe4c5d233a0 100644 --- a/layout/svg/renderer/src/cairo/Makefile.in +++ b/layout/svg/renderer/src/cairo/Makefile.in @@ -60,6 +60,7 @@ REQUIRES = \ util \ uconv \ windowwatcher \ + locale \ $(NULL) CPPSRCS = \ diff --git a/layout/svg/renderer/src/gdiplus/Makefile.in b/layout/svg/renderer/src/gdiplus/Makefile.in index 1e440b6fcc1..f1b5a08f450 100644 --- a/layout/svg/renderer/src/gdiplus/Makefile.in +++ b/layout/svg/renderer/src/gdiplus/Makefile.in @@ -51,6 +51,7 @@ REQUIRES = xpcom \ necko \ content \ unicharutil \ + locale \ $(NULL) CPPSRCS = \ diff --git a/layout/svg/renderer/src/libart/Makefile.in b/layout/svg/renderer/src/libart/Makefile.in index b68da11251a..9ce88146340 100644 --- a/layout/svg/renderer/src/libart/Makefile.in +++ b/layout/svg/renderer/src/libart/Makefile.in @@ -57,6 +57,7 @@ REQUIRES = \ util \ uconv \ windowwatcher \ + locale \ $(NULL) CPPSRCS = \ diff --git a/layout/tables/BasicTableLayoutStrategy.cpp b/layout/tables/BasicTableLayoutStrategy.cpp index 27e0e25f596..90cab82ab0e 100644 --- a/layout/tables/BasicTableLayoutStrategy.cpp +++ b/layout/tables/BasicTableLayoutStrategy.cpp @@ -217,8 +217,7 @@ BasicTableLayoutStrategy::BalanceColumnWidths(const nsHTMLReflowState& aReflowSt #ifdef DEBUG_TABLE_REFLOW_TIMING nsTableFrame::DebugTimeMethod(nsTableFrame::eBalanceCols, *mTableFrame, (nsHTMLReflowState&)aReflowState, PR_TRUE); #endif - float p2t; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&p2t); + float p2t = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); ContinuingFrameCheck(); @@ -1003,8 +1002,7 @@ BasicTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aMax PRInt32 colX, rowX; mCellSpacingTotal = 0; PRBool hasPctCol = PR_FALSE; // return value - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); + float pixelToTwips = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); PRInt32 rawPropTotal = -1; // total of numbers of the type 1*, 2*, etc PRInt32 numColsForColsAttr = 0; // Nav Quirks cols attribute for equal width cols @@ -1242,8 +1240,7 @@ BasicTableLayoutStrategy::CalcPctAdjTableWidth(const nsHTMLReflowState& aReflowS PRInt32 numRows = mTableFrame->GetRowCount(); PRInt32 numCols = mTableFrame->GetColCount(); // consider cols at end without orig cells PRInt32 colX, rowX; - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); + float pixelToTwips = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); // For an auto table, determine the potentially new percent adjusted width based // on percent cells/cols. This probably should only be a NavQuirks thing, since diff --git a/layout/tables/FixedTableLayoutStrategy.cpp b/layout/tables/FixedTableLayoutStrategy.cpp index 52d3850337f..d1818e021c1 100644 --- a/layout/tables/FixedTableLayoutStrategy.cpp +++ b/layout/tables/FixedTableLayoutStrategy.cpp @@ -74,8 +74,7 @@ FixedTableLayoutStrategy::AssignNonPctColumnWidths(nscoord aCom PRInt32 numCols = mTableFrame->GetColCount(); PRInt32 colX; - float pixelToTwips; - mTableFrame->GetPresContext()->GetScaledPixelsToTwips(&pixelToTwips); + float pixelToTwips = mTableFrame->GetPresContext()->ScaledPixelsToTwips(); // availWidth is used as the basis for percentage width columns. It is aComputedWidth // minus table border, padding, & cellspacing nscoord spacingX = mTableFrame->GetCellSpacingX(); diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp index 9694940be8a..c6e35ec1f85 100644 --- a/layout/tables/nsTableCellFrame.cpp +++ b/layout/tables/nsTableCellFrame.cpp @@ -588,9 +588,9 @@ void nsTableCellFrame::VerticallyAlignChild(nsIPresContext* aPresContex case NS_STYLE_VERTICAL_ALIGN_MIDDLE: // Align the middle of the child frame with the middle of the content area, kidYTop = (height - childHeight - bottomInset + topInset) / 2; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - kidYTop = nsTableFrame::RoundToPixel(kidYTop, p2t, eAlwaysRoundDown); + kidYTop = nsTableFrame::RoundToPixel(kidYTop, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } firstKid->SetPosition(nsPoint(kidRect.x, kidYTop)); nsHTMLReflowMetrics desiredSize(PR_FALSE); @@ -726,8 +726,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsIPresContext* aPresContext, #if defined DEBUG_TABLE_REFLOW_TIMING nsTableFrame::DebugReflow(this, (nsHTMLReflowState&)aReflowState); #endif - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); // work around pixel rounding errors, round down to ensure we don't exceed the avail height in nscoord availHeight = aReflowState.availableHeight; diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index 37081404ad6..cb2f3548062 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -1153,12 +1153,10 @@ return;} return aReturn;} #define GET_PIXELS_TO_TWIPS(presContext,var) \ - float var; \ - (presContext)->GetScaledPixelsToTwips(&var); + float var = (presContext)->ScaledPixelsToTwips(); #define GET_TWIPS_TO_PIXELS(presContext,var) \ - float var; \ - (presContext)->GetScaledPixelsToTwips(&var); \ + float var = (presContext)->ScaledPixelsToTwips(); \ var = 1.0f / var; #endif diff --git a/layout/tables/nsTableOuterFrame.cpp b/layout/tables/nsTableOuterFrame.cpp index 32514a2f57d..f817c4e16ca 100644 --- a/layout/tables/nsTableOuterFrame.cpp +++ b/layout/tables/nsTableOuterFrame.cpp @@ -54,7 +54,6 @@ #endif #include "nsIServiceManager.h" #include "nsIDOMNode.h" -#include "nsIPrintContext.h" /* ----------- nsTableCaptionFrame ---------- */ @@ -941,9 +940,9 @@ nsTableOuterFrame::BalanceLeftRightCaption(nsIPresContext* aPresContext, else { aCaptionWidth = (nscoord) ((capPercent / innerPercent) * aInnerWidth); } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - aCaptionWidth = nsTableFrame::RoundToPixel(aCaptionWidth, p2t, eAlwaysRoundDown); + aCaptionWidth = nsTableFrame::RoundToPixel(aCaptionWidth, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } nsresult @@ -963,8 +962,7 @@ nsTableOuterFrame::GetCaptionOrigin(nsIPresContext* aPresContext, } if (!mCaptionFrame) return NS_OK; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); switch(aCaptionSide) { case NS_SIDE_BOTTOM: { @@ -1075,8 +1073,7 @@ nsTableOuterFrame::GetInnerOrigin(nsIPresContext* aPresContext, return NS_OK; } - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); nscoord minCapWidth = aCaptionSize.width; if (NS_AUTOMARGIN != aCaptionMargin.left) @@ -1261,11 +1258,11 @@ nsTableOuterFrame::OuterReflowChild(nsIPresContext* aPresContext, aMargin = aPadding = nsMargin(0,0,0,0); // work around pixel rounding errors, round down to ensure we don't exceed the avail height in - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); nscoord availHeight = aOuterRS.availableHeight; if (NS_UNCONSTRAINEDSIZE != availHeight) { - availHeight = nsTableFrame::RoundToPixel(availHeight, p2t, eAlwaysRoundDown); + availHeight = nsTableFrame::RoundToPixel(availHeight, + aPresContext->ScaledPixelsToTwips(), + eAlwaysRoundDown); } nsSize availSize(aAvailWidth, availHeight); if (mCaptionFrame == aChildFrame) { diff --git a/layout/tables/nsTablePainter.cpp b/layout/tables/nsTablePainter.cpp index 8f2bfb0aa50..cdf5278ed12 100644 --- a/layout/tables/nsTablePainter.cpp +++ b/layout/tables/nsTablePainter.cpp @@ -246,7 +246,7 @@ TableBackgroundPainter::TableBackgroundPainter(nsTableFrame* aTableFrame, mZeroPadding.RecalcData(); - mPresContext->GetScaledPixelsToTwips(&mP2t); + mP2t = mPresContext->ScaledPixelsToTwips(); mIsBorderCollapse = aTableFrame->IsBorderCollapse(); #ifdef DEBUG mCompatMode = mPresContext->CompatibilityMode(); diff --git a/layout/xul/base/src/nsBox.cpp b/layout/xul/base/src/nsBox.cpp index 51b7b3af14a..13f5ef37180 100644 --- a/layout/xul/base/src/nsBox.cpp +++ b/layout/xul/base/src/nsBox.cpp @@ -648,8 +648,7 @@ nsBox::GetBorder(nsMargin& aMargin) nsMargin margin(0,0,0,0); gTheme->GetWidgetBorder(context->DeviceContext(), frame, disp->mAppearance, &margin); - float p2t; - context->GetScaledPixelsToTwips(&p2t); + float p2t = context->ScaledPixelsToTwips(); aMargin.top = NSIntPixelsToTwips(margin.top, p2t); aMargin.right = NSIntPixelsToTwips(margin.right, p2t); aMargin.bottom = NSIntPixelsToTwips(margin.bottom, p2t); @@ -1162,23 +1161,18 @@ nsIBox::AddCSSPrefSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::width, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - aSize.width = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + aSize.width = + presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); widthSet = PR_TRUE; } if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::height, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - aSize.height = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + aSize.height = presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); heightSet = PR_TRUE; } } @@ -1201,16 +1195,14 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) // See if a native theme wants to supply a minimum size. const nsStyleDisplay* display = frame->GetStyleDisplay(); if (display->mAppearance) { - nsCOMPtr theme; - aState.PresContext()->GetTheme(getter_AddRefs(theme)); + nsITheme *theme = aState.PresContext()->GetTheme(); if (theme && theme->ThemeSupportsWidget(aState.PresContext(), frame, display->mAppearance)) { nsSize size; const nsHTMLReflowState* reflowState = aState.GetReflowState(); if (reflowState) { theme->GetMinimumWidgetSize(reflowState->rendContext, frame, display->mAppearance, &size, &canOverride); - float p2t; - aState.PresContext()->GetScaledPixelsToTwips(&p2t); + float p2t = aState.PresContext()->ScaledPixelsToTwips(); if (size.width) { aSize.width = NSIntPixelsToTwips(size.width, p2t); widthSet = PR_TRUE; @@ -1253,12 +1245,10 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::minwidth, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - nscoord val = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + nscoord val = + presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); if (val > aSize.width) aSize.width = val; widthSet = PR_TRUE; @@ -1266,12 +1256,10 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::minheight, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - nscoord val = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + nscoord val = + presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); if (val > aSize.height) aSize.height = val; @@ -1317,24 +1305,20 @@ nsIBox::AddCSSMaxSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::maxwidth, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - nscoord val = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + nscoord val = + presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); aSize.width = val; widthSet = PR_TRUE; } if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::maxheight, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - value.Trim("%"); - nscoord val = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + nscoord val = + presContext->IntScaledPixelsToTwips(value.ToInteger(&error)); aSize.height = val; heightSet = PR_TRUE; diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index b4d1df3592c..8d74604e1c7 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -106,7 +106,6 @@ // Needed for Print Preview #include "nsIDocument.h" -#include "nsIPrintPreviewContext.h" #include "nsIURI.h" @@ -752,8 +751,7 @@ nsBoxFrame::IsInitialReflowForPrintPreview(nsBoxLayoutState& aState, const nsHTMLReflowState* reflowState = aState.GetReflowState(); if (reflowState->reason == eReflowReason_Initial) { // See if we are doing Print Preview - nsCOMPtr ppContent(do_QueryInterface(aState.PresContext())); - if (ppContent) { + if (aState.PresContext()->Type() == nsIPresContext::eContext_PrintPreview) { // Now, get the current URI to see if we doing chrome nsIPresShell *presShell = aState.PresShell(); if (!presShell) return PR_FALSE; @@ -1674,10 +1672,7 @@ nsBoxFrame::PaintChildren(nsIPresContext* aPresContext, #ifdef DEBUG_LAYOUT if (mState & NS_STATE_CURRENTLY_IN_DEBUG) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); GetContentRect(r); if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) { @@ -2076,9 +2071,7 @@ nsBoxFrame::PaintDebug(nsIBox* aBox, PRBool isHorizontal = IsHorizontal(); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); nsMargin debugBorder(0,0,0,0); nsMargin debugMargin(0,0,0,0); @@ -2213,9 +2206,7 @@ nsBoxFrame::FillRect(nsIRenderingContext& aRenderingContext, PRBool aHorizontal, void nsBoxFrame::DrawSpacer(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, PRBool aHorizontal, PRInt32 flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); // if we do draw the coils int distance = 0; @@ -2278,9 +2269,7 @@ nsBoxFrame::GetDebugPadding(nsMargin& aPadding) void nsBoxFrame::PixelMarginToTwips(nsIPresContext* aPresContext, nsMargin& aMarginPixels) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); aMarginPixels.left *= onePixel; aMarginPixels.right *= onePixel; aMarginPixels.top *= onePixel; @@ -2292,8 +2281,7 @@ nsBoxFrame::PixelMarginToTwips(nsIPresContext* aPresContext, nsMargin& aMarginPi void nsBoxFrame::GetValue(nsIPresContext* aPresContext, const nsSize& a, const nsSize& b, char* ch) { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); char width[100]; char height[100]; diff --git a/layout/xul/base/src/nsImageBoxFrame.cpp b/layout/xul/base/src/nsImageBoxFrame.cpp index 4d0cea1ef37..3ce5ca1dd46 100644 --- a/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/layout/xul/base/src/nsImageBoxFrame.cpp @@ -565,10 +565,9 @@ nsImageBoxFrame::GetImageSize() { nsHTMLReflowMetrics desiredSize(PR_TRUE); const PRInt32 kDefaultSize = 0; - float p2t; - GetPresContext()->GetScaledPixelsToTwips(&p2t); // XXX constant zero? - const PRInt32 kDefaultSizeInTwips = NSIntPixelsToTwips(kDefaultSize, p2t); + const PRInt32 kDefaultSizeInTwips = + GetPresContext()->IntScaledPixelsToTwips(kDefaultSize); // not calculated? Get the intrinsic size if (mHasImage) { diff --git a/layout/xul/base/src/nsListBoxBodyFrame.cpp b/layout/xul/base/src/nsListBoxBodyFrame.cpp index f0ec896df25..e901f85f424 100644 --- a/layout/xul/base/src/nsListBoxBodyFrame.cpp +++ b/layout/xul/base/src/nsListBoxBodyFrame.cpp @@ -234,9 +234,7 @@ nsListBoxBodyFrame::Init(nsIPresContext* aPresContext, nsIContent* aContent, { nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - mOnePixel = NSIntPixelsToTwips(1, p2t); + mOnePixel = aPresContext->IntScaledPixelsToTwips(1); nsIFrame* box = aParent->GetParent(); if (!box) diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index cc25f8e7f74..31b9ae83215 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -884,14 +884,13 @@ nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext, // The dimensions of the frame invoking the popup. nsRect parentRect = aFrame->GetRect(); - float p2t, t2p; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); nsIViewManager* viewManager = containingView->GetViewManager(); nsCOMPtr dx; viewManager->GetDeviceContext(*getter_AddRefs(dx)); - t2p = dx->AppUnitsToDevUnits(); + float t2p = dx->AppUnitsToDevUnits(); // get the document and the global script object nsIPresShell *presShell = aPresContext->PresShell(); diff --git a/layout/xul/base/src/nsSliderFrame.cpp b/layout/xul/base/src/nsSliderFrame.cpp index 2779558e5a3..81c8f83947b 100644 --- a/layout/xul/base/src/nsSliderFrame.cpp +++ b/layout/xul/base/src/nsSliderFrame.cpp @@ -373,9 +373,7 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) else if (curpospx > maxpospx) curpospx = maxpospx; - float p2t; - aState.PresContext()->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aState.PresContext()->IntScaledPixelsToTwips(1); // get max pos in twips nscoord maxpos = maxpospx*onePixel; @@ -469,9 +467,7 @@ nsSliderFrame::HandleEvent(nsIPresContext* aPresContext, // convert start to twips nscoord startpx = mDragStartPx; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); nscoord start = startpx*onePixel; nsIFrame* thumbFrame = mFrames.FirstChild(); @@ -623,9 +619,7 @@ nsSliderFrame::HandleEvent(nsIPresContext* aPresContext, || (gMiddlePref && aEvent->message == NS_MOUSE_MIDDLE_BUTTON_DOWN)) { // convert coord from twips to pixels nscoord pos = isHorizontal ? aEvent->point.x : aEvent->point.y; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); nscoord pospx = pos/onePixel; // adjust so that the middle of the thumb is placed under the click @@ -758,10 +752,7 @@ nsSliderFrame::CurrentPositionChanged(nsIPresContext* aPresContext) curpos = maxpos; // convert to pixels - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); nscoord curpospx = curpos*onePixel; // get the thumb's rect @@ -938,9 +929,7 @@ nsSliderFrame::MouseDown(nsIDOMEvent* aMouseEvent) // mouseEvent has click coordinates in pixels, convert to twips first isHorizontal ? mouseEvent->GetClientX(&pospx) : mouseEvent->GetClientY(&pospx); - float p2t; - GetPresContext()->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = GetPresContext()->IntScaledPixelsToTwips(1); pos = pospx * onePixel; // then get it into our coordinate system by subtracting our parents offsets. diff --git a/layout/xul/base/src/nsSplitterFrame.cpp b/layout/xul/base/src/nsSplitterFrame.cpp index 717b9280239..74c64c76e55 100644 --- a/layout/xul/base/src/nsSplitterFrame.cpp +++ b/layout/xul/base/src/nsSplitterFrame.cpp @@ -534,9 +534,7 @@ nsSplitterFrameInner::MouseDrag(nsIPresContext* aPresContext, nsGUIEvent* aEvent // convert start to twips nscoord startpx = mDragStartPx; - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); nscoord start = startpx*onePixel; // get it into our coordintate system by subtracting our parents offsets. @@ -1062,9 +1060,7 @@ nsSplitterFrameInner::AdjustChildren(nsIPresContext* aPresContext, nsSplitterInf nsBoxLayoutState state(aPresContext); - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1); // first set all the widths. nsIBox* child = nsnull; diff --git a/layout/xul/base/src/nsSprocketLayout.cpp b/layout/xul/base/src/nsSprocketLayout.cpp index 10109278142..e1b1fcb2789 100644 --- a/layout/xul/base/src/nsSprocketLayout.cpp +++ b/layout/xul/base/src/nsSprocketLayout.cpp @@ -1116,9 +1116,7 @@ nsSprocketLayout::ComputeChildSizes(nsIBox* aBox, nsComputedBoxSize*& aComputedBoxSizes) { - // float p2t; - // aState.PresContext()->GetScaledPixelsToTwips(&p2t); - //nscoord onePixel = NSIntPixelsToTwips(1, p2t); + //nscoord onePixel = aState.PresContext()->IntScaledPixelsToTwips(1); PRInt32 sizeRemaining = aGivenSize; PRInt32 spacerConstantsRemaining = 0; diff --git a/layout/xul/base/src/nsStackLayout.cpp b/layout/xul/base/src/nsStackLayout.cpp index d9702b60348..2c92e87d5ef 100644 --- a/layout/xul/base/src/nsStackLayout.cpp +++ b/layout/xul/base/src/nsStackLayout.cpp @@ -223,18 +223,16 @@ nsStackLayout::AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize PRInt32 error; if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::left, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); value.Trim("%"); - offset.width = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + offset.width = NSIntPixelsToTwips(value.ToInteger(&error), + presContext->ScaledPixelsToTwips()); offsetSpecified = PR_TRUE; } if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::top, value)) { - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); value.Trim("%"); - offset.height = NSIntPixelsToTwips(value.ToInteger(&error), p2t); + offset.height = NSIntPixelsToTwips(value.ToInteger(&error), + presContext->ScaledPixelsToTwips()); offsetSpecified = PR_TRUE; } } diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index ccbe43e39d1..4e6b96cc04e 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -407,9 +407,8 @@ nsTextBoxFrame::PaintTitle(nsIPresContext* aPresContext, nsresult rv = NS_ERROR_FAILURE; if (mState & NS_FRAME_IS_BIDI) { - nsBidiPresUtils* bidiUtils; aPresContext->SetBidiEnabled(PR_TRUE); - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { PRUnichar* buffer = ToNewUnicode(mCroppedTitle); diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 77b58a100db..1a01b265bbd 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -2219,10 +2219,10 @@ nsTreeBodyFrame::PaintRow(PRInt32 aRowIndex, // If a -moz-appearance is provided, use theme drawing only if the current row // is not selected (since we draw the selection as part of drawing the background). PRBool useTheme = PR_FALSE; - nsCOMPtr theme; + nsITheme *theme = nsnull; const nsStyleDisplay* displayData = rowContext->GetStyleDisplay(); if (displayData->mAppearance) { - aPresContext->GetTheme(getter_AddRefs(theme)); + theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, displayData->mAppearance)) useTheme = PR_TRUE; } @@ -2314,10 +2314,10 @@ nsTreeBodyFrame::PaintSeparator(PRInt32 aRowIndex, // Resolve style for the separator. nsStyleContext* separatorContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeseparator); PRBool useTheme = PR_FALSE; - nsCOMPtr theme; + nsITheme *theme = nsnull; const nsStyleDisplay* displayData = separatorContext->GetStyleDisplay(); if ( displayData->mAppearance ) { - aPresContext->GetTheme(getter_AddRefs(theme)); + theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, displayData->mAppearance)) useTheme = PR_TRUE; } @@ -2551,10 +2551,10 @@ nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, nsStyleContext* twistyContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreetwisty); PRBool useTheme = PR_FALSE; - nsCOMPtr theme; + nsITheme *theme = nsnull; const nsStyleDisplay* twistyDisplayData = twistyContext->GetStyleDisplay(); if ( twistyDisplayData->mAppearance ) { - aPresContext->GetTheme(getter_AddRefs(theme)); + theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, twistyDisplayData->mAppearance)) useTheme = PR_TRUE; } @@ -2585,8 +2585,7 @@ nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, theme->GetMinimumWidgetSize(&aRenderingContext, this, twistyDisplayData->mAppearance, &minTwistySize, &canOverride); // GMWS() returns size in pixels, we need to convert it back to twips - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + float p2t = aPresContext->ScaledPixelsToTwips(); minTwistySize.width = NSIntPixelsToTwips(minTwistySize.width, p2t); minTwistySize.height = NSIntPixelsToTwips(minTwistySize.height, p2t); @@ -2904,8 +2903,7 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, #endif #ifdef IBMBIDI nsresult rv = NS_ERROR_FAILURE; - nsBidiPresUtils* bidiUtils; - aPresContext->GetBidiUtils(&bidiUtils); + nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils(); if (bidiUtils) { const nsStyleVisibility* vis = GetStyleVisibility(); diff --git a/modules/oji/src/Makefile.in b/modules/oji/src/Makefile.in index fd032d69873..8e5ef595ffa 100644 --- a/modules/oji/src/Makefile.in +++ b/modules/oji/src/Makefile.in @@ -69,6 +69,7 @@ REQUIRES = xpcom \ docshell \ webbrwsr \ intl \ + locale \ $(NULL) LIBRARY_NAME = oji diff --git a/modules/plugin/base/src/Makefile.in b/modules/plugin/base/src/Makefile.in index 591d9509075..f9ae66f74fc 100644 --- a/modules/plugin/base/src/Makefile.in +++ b/modules/plugin/base/src/Makefile.in @@ -75,6 +75,7 @@ REQUIRES = xpcom \ imglib2 \ layout \ js \ + locale \ $(NULL) ifneq (,$(filter gtk gtk2,$(MOZ_WIDGET_TOOLKIT))) diff --git a/uriloader/base/Makefile.in b/uriloader/base/Makefile.in index e77878b20d0..1e1169fc87a 100644 --- a/uriloader/base/Makefile.in +++ b/uriloader/base/Makefile.in @@ -62,6 +62,7 @@ REQUIRES = xpcom \ webshell \ xpconnect \ mimetype \ + locale \ $(NULL) CPPSRCS = \