From 5b5cd321a4c8ede5b7d8993f4e5057fef752d5fa Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Mon, 2 Feb 2004 22:17:21 +0000 Subject: [PATCH] Guarantee that the pres context's device context will be non-null by returning failure from Init() if it's null. Rename inline getter GetDeviceContext() to DeviceContext(), convert all callers to use the inline getter, and remove the virtual/refcounting getter. Bug 229371, r+sr=dbaron. git-svn-id: svn://10.0.0.236/trunk@152182 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 3 +- mozilla/content/base/src/nsPrintEngine.cpp | 308 +++++++++--------- mozilla/content/base/src/nsRuleNode.cpp | 18 +- mozilla/content/base/src/nsSelection.cpp | 13 +- .../events/src/nsEventStateManager.cpp | 14 +- mozilla/content/shared/src/nsStyleStruct.cpp | 4 +- mozilla/dom/src/base/nsScreen.cpp | 10 +- mozilla/dom/src/base/nsScreen.h | 2 +- mozilla/layout/base/nsCaret.cpp | 27 +- mozilla/layout/base/nsDocumentViewer.cpp | 3 +- mozilla/layout/base/nsPresContext.cpp | 90 ++--- mozilla/layout/base/nsPresContext.h | 3 +- mozilla/layout/base/nsPresShell.cpp | 19 +- mozilla/layout/base/public/nsIPresContext.h | 3 +- mozilla/layout/base/public/nsPresContext.h | 3 +- mozilla/layout/base/src/nsCaret.cpp | 27 +- mozilla/layout/base/src/nsPresContext.cpp | 90 ++--- mozilla/layout/base/src/nsPresContext.h | 1 - .../layout/forms/nsComboboxControlFrame.cpp | 18 +- mozilla/layout/forms/nsFormControlFrame.cpp | 37 +-- mozilla/layout/forms/nsFormControlHelper.cpp | 7 +- mozilla/layout/forms/nsListControlFrame.cpp | 6 +- mozilla/layout/forms/nsTextControlFrame.cpp | 27 +- mozilla/layout/generic/nsPageFrame.cpp | 6 +- mozilla/layout/generic/nsSelection.cpp | 13 +- .../layout/generic/nsSimplePageSequence.cpp | 22 +- mozilla/layout/html/base/src/nsPageFrame.cpp | 6 +- mozilla/layout/html/base/src/nsPresShell.cpp | 19 +- .../html/base/src/nsSimplePageSequence.cpp | 22 +- .../html/forms/src/nsComboboxControlFrame.cpp | 18 +- .../html/forms/src/nsFormControlFrame.cpp | 37 +-- .../html/forms/src/nsFormControlHelper.cpp | 7 +- .../html/forms/src/nsListControlFrame.cpp | 6 +- .../html/forms/src/nsTextControlFrame.cpp | 27 +- .../layout/mathml/base/src/nsMathMLChar.cpp | 3 +- mozilla/layout/printing/nsPrintEngine.cpp | 308 +++++++++--------- mozilla/layout/style/nsRuleNode.cpp | 18 +- mozilla/layout/style/nsStyleStruct.cpp | 4 +- mozilla/layout/xul/base/src/nsBox.cpp | 4 +- .../xul/base/src/nsListBoxBodyFrame.cpp | 11 +- .../layout/xul/base/src/nsTextBoxFrame.cpp | 17 +- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 13 +- 42 files changed, 544 insertions(+), 750 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index fba50729b19..1b7ff58898d 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -1697,8 +1697,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - nsCOMPtr dx; - mPresContext->GetDeviceContext(getter_AddRefs(dx)); + nsIDeviceContext *dx = mPresContext->DeviceContext(); nsRect tbounds = aBounds; float p2t; diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index c53d7e3eda2..b048558449e 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -726,7 +726,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, #endif nsCOMPtr devspec; - nsCOMPtr dx; mPrt->mPrintDC = nsnull; // XXX why? #ifdef NS_DEBUG @@ -806,183 +805,182 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE); if (NS_SUCCEEDED(rv)) { - rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); + rv = mPresContext->DeviceContext()-> + GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); if (NS_SUCCEEDED(rv)) { - rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); - if (NS_SUCCEEDED(rv)) { - // Get the Original PixelScale incase we need to start changing it - mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); - // Shrink to Fit over rides and scaling values - if (!mPrt->mShrinkToFit) { - double scaling; - mPrt->mPrintSettings->GetScaling(&scaling); - mPrt->mPrintDC->SetCanonicalPixelScale(float(scaling)*mPrt->mOrigDCScale); - } + // Get the Original PixelScale incase we need to start changing it + mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); + // Shrink to Fit over rides and scaling values + if (!mPrt->mShrinkToFit) { + double scaling; + mPrt->mPrintSettings->GetScaling(&scaling); + mPrt->mPrintDC->SetCanonicalPixelScale(float(scaling)*mPrt->mOrigDCScale); + } - if(webContainer) { + if(webContainer) { #ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; + float a1,a2; + PRInt32 i1,i2; - printf("CRITICAL PRINTING INFORMATION\n"); + printf("CRITICAL PRINTING INFORMATION\n"); - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); + // DEVICE CONTEXT INFORMATION from PresContext + nsIDeviceContext *dx = mPresContext->DeviceContext(); + printf("DeviceContext of Presentation Context(%x)\n", dx); + dx->GetDevUnitsToTwips(a1); + dx->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + dx->GetAppUnitsToDevUnits(a1); + dx->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + dx->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + dx->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + dx->GetZoom(a1); + printf(" Zoom = %f\n",a1); + dx->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + dx->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC); - mPrt->mPrintDC->GetDevUnitsToTwips(a1); - mPrt->mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrt->mPrintDC->GetAppUnitsToDevUnits(a1); - mPrt->mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrt->mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrt->mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrt->mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrt->mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); + // DEVICE CONTEXT INFORMATION + printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC); + mPrt->mPrintDC->GetDevUnitsToTwips(a1); + mPrt->mPrintDC->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + mPrt->mPrintDC->GetAppUnitsToDevUnits(a1); + mPrt->mPrintDC->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + mPrt->mPrintDC->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + mPrt->mPrintDC->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + mPrt->mPrintDC->GetZoom(a1); + printf(" Zoom = %f\n",a1); + mPrt->mPrintDC->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); #endif /* DEBUG_dcone */ - // Always check and set the print settings first and then fall back - // onto the PrintService if there isn't a PrintSettings - // - // Posiible Usage values: - // nsIPrintSettings::kUseInternalDefault - // nsIPrintSettings::kUseSettingWhenPossible - // - // NOTE: The consts are the same for PrintSettings and PrintSettings - PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; - mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); + // Always check and set the print settings first and then fall back + // onto the PrintService if there isn't a PrintSettings + // + // Posiible Usage values: + // nsIPrintSettings::kUseInternalDefault + // nsIPrintSettings::kUseSettingWhenPossible + // + // NOTE: The consts are the same for PrintSettings and PrintSettings + PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; + mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); - // Ok, see if we are going to use our value and override the default - if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { - // Get the Print Options/Settings PrintFrameType to see what is preferred - PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; - mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); + // Ok, see if we are going to use our value and override the default + if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { + // Get the Print Options/Settings PrintFrameType to see what is preferred + PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); - // Don't let anybody do something stupid like try to set it to - // kNoFrames when we are printing a FrameSet - if (printFrameType == nsIPrintSettings::kNoFrames) { - mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + // Don't let anybody do something stupid like try to set it to + // kNoFrames when we are printing a FrameSet + if (printFrameType == nsIPrintSettings::kNoFrames) { + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } else { + // First find out from the PrinService what options are available + // to us for Printing FrameSets + PRInt16 howToEnableFrameUI; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + switch (howToEnableFrameUI) { + case nsIPrintSettings::kFrameEnableAll: + mPrt->mPrintFrameType = printFrameType; + break; + + case nsIPrintSettings::kFrameEnableAsIsAndEach: + if (printFrameType != nsIPrintSettings::kSelectedFrame) { + mPrt->mPrintFrameType = printFrameType; + } else { // revert back to a good value + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + } + break; + } // switch mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); - } else { - // First find out from the PrinService what options are available - // to us for Printing FrameSets + } + } + } else { + mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); + } + +#ifdef MOZ_LAYOUTDEBUG + { + // This is a special debugging regression tool section + PRUnichar* tempFileName = nsnull; + if (nsPrintEngine::IsDoingRuntimeTesting()) { + // Here we check for a special filename (the destination for the print job) + // and sets into the print settings if there is a name then we want to + // print to a file. if not, let it print normally. + if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) { + if (*tempFileName) { + mPrt->mPrintSettings->SetPrintToFile(PR_TRUE); + mPrt->mPrintSettings->SetToFileName(tempFileName); + } + nsMemory::Free(tempFileName); + } + + // Here we check to see how we should print a frameset (if there is one) + PRBool asIs = PR_FALSE; + if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) { PRInt16 howToEnableFrameUI; mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { - switch (howToEnableFrameUI) { - case nsIPrintSettings::kFrameEnableAll: - mPrt->mPrintFrameType = printFrameType; - break; - - case nsIPrintSettings::kFrameEnableAsIsAndEach: - if (printFrameType != nsIPrintSettings::kSelectedFrame) { - mPrt->mPrintFrameType = printFrameType; - } else { // revert back to a good value - mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; - } - break; - } // switch + mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } } - } else { - mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - } - -#ifdef MOZ_LAYOUTDEBUG - { - // This is a special debugging regression tool section - PRUnichar* tempFileName = nsnull; - if (nsPrintEngine::IsDoingRuntimeTesting()) { - // Here we check for a special filename (the destination for the print job) - // and sets into the print settings if there is a name then we want to - // print to a file. if not, let it print normally. - if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) { - if (*tempFileName) { - mPrt->mPrintSettings->SetPrintToFile(PR_TRUE); - mPrt->mPrintSettings->SetToFileName(tempFileName); - } - nsMemory::Free(tempFileName); - } - - // Here we check to see how we should print a frameset (if there is one) - PRBool asIs = PR_FALSE; - if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) { - PRInt16 howToEnableFrameUI; - mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); - if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { - mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep; - mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); - } - } - } } + } #endif - // Get the Needed info for Calling PrepareDocument - PRUnichar* fileName = nsnull; - // check to see if we are printing to a file - PRBool isPrintToFile = PR_FALSE; - mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); - if (isPrintToFile) { - // On some platforms The PrepareDocument needs to know the name of the file - // and it uses the PrintService to get it, so we need to set it into the PrintService here - mPrt->mPrintSettings->GetToFileName(&fileName); - } - - PRUnichar * docTitleStr; - PRUnichar * docURLStr; - - GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); - PR_PL(("Title: %s\n", docTitleStr?NS_LossyConvertUCS2toASCII(docTitleStr).get():"")); - PR_PL(("URL: %s\n", docURLStr?NS_LossyConvertUCS2toASCII(docURLStr).get():"")); - - rv = mPrt->mPrintDC->PrepareDocument(docTitleStr, fileName); - - if (docTitleStr) nsMemory::Free(docTitleStr); - if (docURLStr) nsMemory::Free(docURLStr); - - CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE); - if (NS_FAILED(rv)) { - return CleanupOnFailure(rv, PR_TRUE); - } - - PRBool doNotify; - ShowPrintProgress(PR_TRUE, doNotify); - - if (!doNotify) { - // Print listener setup... - if (mPrt != nsnull) { - mPrt->OnStartPrinting(); - } - rv = DocumentReadyForPrinting(); + // Get the Needed info for Calling PrepareDocument + PRUnichar* fileName = nsnull; + // check to see if we are printing to a file + PRBool isPrintToFile = PR_FALSE; + mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); + if (isPrintToFile) { + // On some platforms The PrepareDocument needs to know the name of the file + // and it uses the PrintService to get it, so we need to set it into the PrintService here + mPrt->mPrintSettings->GetToFileName(&fileName); + } + + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + + GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); + PR_PL(("Title: %s\n", docTitleStr?NS_LossyConvertUCS2toASCII(docTitleStr).get():"")); + PR_PL(("URL: %s\n", docURLStr?NS_LossyConvertUCS2toASCII(docURLStr).get():"")); + + rv = mPrt->mPrintDC->PrepareDocument(docTitleStr, fileName); + + if (docTitleStr) nsMemory::Free(docTitleStr); + if (docURLStr) nsMemory::Free(docURLStr); + + CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE); + if (NS_FAILED(rv)) { + return CleanupOnFailure(rv, PR_TRUE); + } + + PRBool doNotify; + ShowPrintProgress(PR_TRUE, doNotify); + + if (!doNotify) { + // Print listener setup... + if (mPrt != nsnull) { + mPrt->OnStartPrinting(); } + rv = DocumentReadyForPrinting(); } } } diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index 99286ec6351..d475807bb8c 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -1560,18 +1560,16 @@ nsRuleNode::SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext, case NS_STYLE_FONT_FIELD: sysID = eSystemFont_Field; break; } - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - if (dc) { - // GetSystemFont sets the font face but not necessarily the size - aFont->mFont.size = defaultVariableFont->size; - if (NS_FAILED(dc->GetSystemFont(sysID, &aFont->mFont))) { + // GetSystemFont sets the font face but not necessarily the size + aFont->mFont.size = defaultVariableFont->size; + + if (NS_FAILED(aPresContext->DeviceContext()->GetSystemFont(sysID, + &aFont->mFont))) { aFont->mFont.name = defaultVariableFont->name; - } - // this becomes our cascading size - aFont->mSize = aFont->mFont.size - = nsStyleFont::ZoomText(aPresContext, aFont->mFont.size); } + // this becomes our cascading size + aFont->mSize = aFont->mFont.size = + nsStyleFont::ZoomText(aPresContext, aFont->mFont.size); aFont->mFont.familyNameQuirks = PR_FALSE; diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index e671cbf13d6..138fa9f7067 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -6957,16 +6957,6 @@ nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, n if (!presContext) return NS_ERROR_NULL_POINTER; - nsCOMPtr deviceContext; - - rv = presContext->GetDeviceContext(getter_AddRefs(deviceContext)); - - if (NS_FAILED(rv)) - return rv; - - if (!deviceContext) - return NS_ERROR_NULL_POINTER; - // // Now get the closest view with a widget so we can create // a rendering context. @@ -6999,7 +6989,8 @@ nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, n nsCOMPtr rendContext; - rv = deviceContext->CreateRenderingContext(closestView, *getter_AddRefs(rendContext)); + rv = presContext->DeviceContext()-> + CreateRenderingContext(closestView, *getter_AddRefs(rendContext)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index de6694a5888..70e445e5b10 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -1371,15 +1371,11 @@ nsEventStateManager::GenerateDragGesture(nsIPresContext* aPresContext, // figure out the delta in twips, since that is how it is in the event. // Do we need to do this conversion every time? // Will the pres context really change on us or can we cache it? - nsCOMPtr devContext; - aPresContext->GetDeviceContext (getter_AddRefs(devContext)); - nscoord thresholdX = 0, thresholdY = 0; - if (devContext) { - float pixelsToTwips = 0.0; - devContext->GetDevUnitsToTwips(pixelsToTwips); - thresholdX = NSIntPixelsToTwips(pixelThresholdX, pixelsToTwips); - thresholdY = NSIntPixelsToTwips(pixelThresholdY, pixelsToTwips); - } + float pixelsToTwips; + aPresContext->DeviceContext()->GetDevUnitsToTwips(pixelsToTwips); + + nscoord thresholdX = NSIntPixelsToTwips(pixelThresholdX, pixelsToTwips); + nscoord thresholdY = NSIntPixelsToTwips(pixelThresholdY, pixelsToTwips); // fire drag gesture if mouse has moved enough if (abs(aEvent->point.x - mGestureDownPoint.x) > thresholdX || diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index 8155f7aea2e..94645d7cafe 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -223,10 +223,8 @@ nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aOther) const inline float TextZoomFor(nsIPresContext* aPresContext) { - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); float textZoom; - dc->GetTextZoom(textZoom); + aPresContext->DeviceContext()->GetTextZoom(textZoom); return textZoom; } diff --git a/mozilla/dom/src/base/nsScreen.cpp b/mozilla/dom/src/base/nsScreen.cpp index 495151bd877..38d0dc9f7e9 100644 --- a/mozilla/dom/src/base/nsScreen.cpp +++ b/mozilla/dom/src/base/nsScreen.cpp @@ -130,7 +130,7 @@ ScreenImpl::GetHeight(PRInt32* aHeight) NS_IMETHODIMP ScreenImpl::GetPixelDepth(PRInt32* aPixelDepth) { - nsCOMPtr context(GetDeviceContext()); + nsIDeviceContext* context = GetDeviceContext(); if (!context) { *aPixelDepth = -1; @@ -196,7 +196,7 @@ ScreenImpl::GetAvailTop(PRInt32* aAvailTop) return rv; } -already_AddRefed +nsIDeviceContext* ScreenImpl::GetDeviceContext() { if(!mDocShell) @@ -214,7 +214,7 @@ ScreenImpl::GetDeviceContext() nsIDeviceContext* context = nsnull; if(presContext) - presContext->GetDeviceContext(&context); + context = presContext->DeviceContext(); return context; } @@ -222,7 +222,7 @@ ScreenImpl::GetDeviceContext() nsresult ScreenImpl::GetRect(nsRect& aRect) { - nsCOMPtr context(GetDeviceContext()); + nsIDeviceContext *context = GetDeviceContext(); if (!context) { return NS_ERROR_FAILURE; @@ -247,7 +247,7 @@ ScreenImpl::GetRect(nsRect& aRect) nsresult ScreenImpl::GetAvailRect(nsRect& aRect) { - nsCOMPtr context(GetDeviceContext()); + nsIDeviceContext *context = GetDeviceContext(); if (!context) { return NS_ERROR_FAILURE; diff --git a/mozilla/dom/src/base/nsScreen.h b/mozilla/dom/src/base/nsScreen.h index 99e058f08eb..1ca348cb46f 100644 --- a/mozilla/dom/src/base/nsScreen.h +++ b/mozilla/dom/src/base/nsScreen.h @@ -71,7 +71,7 @@ public: protected: - already_AddRefed GetDeviceContext(); + nsIDeviceContext* GetDeviceContext(); nsresult GetRect(nsRect& aRect); nsresult GetAvailRect(nsRect& aRect); diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index 52e9481579a..b887b583829 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -343,17 +343,10 @@ NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, nsI if (NS_FAILED(err)) return err; - // ... then get a device context - nsCOMPtr dx; - err = presContext->GetDeviceContext(getter_AddRefs(dx)); - if (NS_FAILED(err)) - return err; - if (!dx) - return NS_ERROR_UNEXPECTED; - // ... then tell it to make a rendering context nsCOMPtr rendContext; - err = dx->CreateRenderingContext(drawingView, *getter_AddRefs(rendContext)); + err = presContext->DeviceContext()-> + CreateRenderingContext(drawingView, *getter_AddRefs(rendContext)); if (NS_FAILED(err)) return err; if (!rendContext) @@ -984,11 +977,10 @@ void nsCaret::GetCaretRectAndInvert() { mRendContext = nsnull; // free existing one if we have one - nsCOMPtr dx; - if (NS_FAILED(presContext->GetDeviceContext(getter_AddRefs(dx))) || !dx) - return; - - if (NS_FAILED(dx->CreateRenderingContext(drawingView, *getter_AddRefs(mRendContext))) || !mRendContext) + nsresult rv = presContext->DeviceContext()-> + CreateRenderingContext(drawingView, *getter_AddRefs(mRendContext)); + + if (NS_FAILED(rv) || !mRendContext) return; } @@ -1037,11 +1029,8 @@ void nsCaret::GetCaretRectAndInvert() if (mCaretTwipsWidth < 0) // need to re-compute the pixel width { - float tDevUnitsToTwips = 15; - nsCOMPtr dx; - presContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) - dx->GetDevUnitsToTwips(tDevUnitsToTwips); + float tDevUnitsToTwips; + presContext->DeviceContext()->GetDevUnitsToTwips(tDevUnitsToTwips); mCaretTwipsWidth = (nscoord)(tDevUnitsToTwips * (float)mCaretPixelsWidth); } caretRect.width = mCaretTwipsWidth; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index fba50729b19..1b7ff58898d 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -1697,8 +1697,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - nsCOMPtr dx; - mPresContext->GetDeviceContext(getter_AddRefs(dx)); + nsIDeviceContext *dx = mPresContext->DeviceContext(); nsRect tbounds = aBounds; float p2t; diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index b13a8a68f34..011d06c3325 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -608,19 +608,18 @@ nsPresContext::PreferenceChanged(const char* aPrefName) mShell->SetPreferenceStyleRules(PR_TRUE); } - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); - } + mDeviceContext->FlushFontCache(); + nsPresContext::ClearStyleDataAndReflow(); } NS_IMETHODIMP nsPresContext::Init(nsIDeviceContext* aDeviceContext) { NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context"); + NS_ENSURE_ARG(aDeviceContext); mDeviceContext = aDeviceContext; - NS_IF_ADDREF(mDeviceContext); + NS_ADDREF(mDeviceContext); // Get the look and feel service here; default colors will be initialized // from calling GetUserPreferences() below. @@ -743,10 +742,9 @@ nsPresContext::Observe(nsISupports* aSubject, { if (!nsCRT::strcmp(aTopic, "charset")) { UpdateCharSet(NS_LossyConvertUCS2toASCII(aData).get()); - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); - } + mDeviceContext->FlushFontCache(); + nsPresContext::ClearStyleDataAndReflow(); + return NS_OK; } @@ -872,13 +870,11 @@ nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) NS_PRECONDITION(aResult, "null out param"); nsIFontMetrics* metrics = nsnull; - if (mDeviceContext) { - nsCOMPtr langGroup; - if (mLanguage) { - mLanguage->GetLanguageGroup(getter_AddRefs(langGroup)); - } - mDeviceContext->GetMetricsFor(aFont, langGroup, metrics); + nsCOMPtr langGroup; + if (mLanguage) { + mLanguage->GetLanguageGroup(getter_AddRefs(langGroup)); } + mDeviceContext->GetMetricsFor(aFont, langGroup, metrics); *aResult = metrics; return NS_OK; } @@ -940,10 +936,8 @@ nsPresContext::GetPixelsToTwips(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float p2t = 1.0f; - if (mDeviceContext) { - mDeviceContext->GetDevUnitsToAppUnits(p2t); - } + float p2t; + mDeviceContext->GetDevUnitsToAppUnits(p2t); *aResult = p2t; return NS_OK; } @@ -953,11 +947,7 @@ nsPresContext::GetTwipsToPixels(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float app2dev = 1.0f; - if (mDeviceContext) { - mDeviceContext->GetAppUnitsToDevUnits(app2dev); - } - *aResult = app2dev; + mDeviceContext->GetAppUnitsToDevUnits(*aResult); return NS_OK; } @@ -969,24 +959,22 @@ nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const return NS_ERROR_NULL_POINTER; } - float app2dev = 1.0f; - if (mDeviceContext) { + float app2dev; #ifdef NS_PRINT_PREVIEW - // If an alternative DC is available we want to use - // it to get the scaling factor for fonts. Usually, the AltDC - // is a printing DC so therefore we need to get the printers - // scaling values for calculating the font heights - nsCOMPtr altDC; - mDeviceContext->GetAltDevice(getter_AddRefs(altDC)); - if (altDC) { - altDC->GetAppUnitsToDevUnits(app2dev); - } else { - mDeviceContext->GetAppUnitsToDevUnits(app2dev); - } -#else + // If an alternative DC is available we want to use + // it to get the scaling factor for fonts. Usually, the AltDC + // is a printing DC so therefore we need to get the printers + // scaling values for calculating the font heights + nsCOMPtr altDC; + mDeviceContext->GetAltDevice(getter_AddRefs(altDC)); + if (altDC) { + altDC->GetAppUnitsToDevUnits(app2dev); + } else { mDeviceContext->GetAppUnitsToDevUnits(app2dev); -#endif } +#else + mDeviceContext->GetAppUnitsToDevUnits(app2dev); +#endif *aResult = app2dev; return NS_OK; } @@ -998,24 +986,14 @@ nsPresContext::GetScaledPixelsToTwips(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float scale = 1.0f; - if (mDeviceContext) - { - float p2t; - mDeviceContext->GetDevUnitsToAppUnits(p2t); - mDeviceContext->GetCanonicalPixelScale(scale); - scale = p2t * scale; - } - *aResult = scale; - return NS_OK; -} + float scale; + float p2t; -NS_IMETHODIMP -nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const -{ - NS_PRECONDITION(aResult, "null out param"); - *aResult = mDeviceContext; - NS_IF_ADDREF(*aResult); + mDeviceContext->GetDevUnitsToAppUnits(p2t); + mDeviceContext->GetCanonicalPixelScale(scale); + scale = p2t * scale; + + *aResult = scale; return NS_OK; } diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index ea0ffe75d7f..fd6bfa36a62 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -325,8 +325,7 @@ public: */ NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; - NS_IMETHOD GetDeviceContext(nsIDeviceContext** aResult) const = 0; - nsIDeviceContext* GetDeviceContext() { return mDeviceContext; } + nsIDeviceContext* DeviceContext() { return mDeviceContext; } NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; nsIEventStateManager* GetEventStateManager(); diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 7420ea3635e..924205489c6 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3909,17 +3909,13 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame, view->GetViewManager()->GetWidgetForView(view, getter_AddRefs(widget)); } - nsCOMPtr dx; - nsIRenderingContext* result = nsnull; - rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (NS_SUCCEEDED(rv) && dx) { - if (nsnull != widget) { - rv = dx->CreateRenderingContext(widget.get(), result); - } - else { - rv = dx->CreateRenderingContext(result); - } + nsIDeviceContext *deviceContext = mPresContext->DeviceContext(); + if (widget) { + rv = deviceContext->CreateRenderingContext(widget.get(), result); + } + else { + rv = deviceContext->CreateRenderingContext(result); } *aResult = result; @@ -7032,8 +7028,7 @@ PresShell::VerifyIncrementalReflow() } NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); - nsCOMPtr dc; - mPresContext->GetDeviceContext(getter_AddRefs(dc)); + nsIDeviceContext *dc = mPresContext->DeviceContext(); rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index ea0ffe75d7f..fd6bfa36a62 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -325,8 +325,7 @@ public: */ NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; - NS_IMETHOD GetDeviceContext(nsIDeviceContext** aResult) const = 0; - nsIDeviceContext* GetDeviceContext() { return mDeviceContext; } + nsIDeviceContext* DeviceContext() { return mDeviceContext; } NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; nsIEventStateManager* GetEventStateManager(); diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index ea0ffe75d7f..fd6bfa36a62 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -325,8 +325,7 @@ public: */ NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const = 0; - NS_IMETHOD GetDeviceContext(nsIDeviceContext** aResult) const = 0; - nsIDeviceContext* GetDeviceContext() { return mDeviceContext; } + nsIDeviceContext* DeviceContext() { return mDeviceContext; } NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; nsIEventStateManager* GetEventStateManager(); diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index 52e9481579a..b887b583829 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -343,17 +343,10 @@ NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, nsI if (NS_FAILED(err)) return err; - // ... then get a device context - nsCOMPtr dx; - err = presContext->GetDeviceContext(getter_AddRefs(dx)); - if (NS_FAILED(err)) - return err; - if (!dx) - return NS_ERROR_UNEXPECTED; - // ... then tell it to make a rendering context nsCOMPtr rendContext; - err = dx->CreateRenderingContext(drawingView, *getter_AddRefs(rendContext)); + err = presContext->DeviceContext()-> + CreateRenderingContext(drawingView, *getter_AddRefs(rendContext)); if (NS_FAILED(err)) return err; if (!rendContext) @@ -984,11 +977,10 @@ void nsCaret::GetCaretRectAndInvert() { mRendContext = nsnull; // free existing one if we have one - nsCOMPtr dx; - if (NS_FAILED(presContext->GetDeviceContext(getter_AddRefs(dx))) || !dx) - return; - - if (NS_FAILED(dx->CreateRenderingContext(drawingView, *getter_AddRefs(mRendContext))) || !mRendContext) + nsresult rv = presContext->DeviceContext()-> + CreateRenderingContext(drawingView, *getter_AddRefs(mRendContext)); + + if (NS_FAILED(rv) || !mRendContext) return; } @@ -1037,11 +1029,8 @@ void nsCaret::GetCaretRectAndInvert() if (mCaretTwipsWidth < 0) // need to re-compute the pixel width { - float tDevUnitsToTwips = 15; - nsCOMPtr dx; - presContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) - dx->GetDevUnitsToTwips(tDevUnitsToTwips); + float tDevUnitsToTwips; + presContext->DeviceContext()->GetDevUnitsToTwips(tDevUnitsToTwips); mCaretTwipsWidth = (nscoord)(tDevUnitsToTwips * (float)mCaretPixelsWidth); } caretRect.width = mCaretTwipsWidth; diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index b13a8a68f34..011d06c3325 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -608,19 +608,18 @@ nsPresContext::PreferenceChanged(const char* aPrefName) mShell->SetPreferenceStyleRules(PR_TRUE); } - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); - } + mDeviceContext->FlushFontCache(); + nsPresContext::ClearStyleDataAndReflow(); } NS_IMETHODIMP nsPresContext::Init(nsIDeviceContext* aDeviceContext) { NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context"); + NS_ENSURE_ARG(aDeviceContext); mDeviceContext = aDeviceContext; - NS_IF_ADDREF(mDeviceContext); + NS_ADDREF(mDeviceContext); // Get the look and feel service here; default colors will be initialized // from calling GetUserPreferences() below. @@ -743,10 +742,9 @@ nsPresContext::Observe(nsISupports* aSubject, { if (!nsCRT::strcmp(aTopic, "charset")) { UpdateCharSet(NS_LossyConvertUCS2toASCII(aData).get()); - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - nsPresContext::ClearStyleDataAndReflow(); - } + mDeviceContext->FlushFontCache(); + nsPresContext::ClearStyleDataAndReflow(); + return NS_OK; } @@ -872,13 +870,11 @@ nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) NS_PRECONDITION(aResult, "null out param"); nsIFontMetrics* metrics = nsnull; - if (mDeviceContext) { - nsCOMPtr langGroup; - if (mLanguage) { - mLanguage->GetLanguageGroup(getter_AddRefs(langGroup)); - } - mDeviceContext->GetMetricsFor(aFont, langGroup, metrics); + nsCOMPtr langGroup; + if (mLanguage) { + mLanguage->GetLanguageGroup(getter_AddRefs(langGroup)); } + mDeviceContext->GetMetricsFor(aFont, langGroup, metrics); *aResult = metrics; return NS_OK; } @@ -940,10 +936,8 @@ nsPresContext::GetPixelsToTwips(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float p2t = 1.0f; - if (mDeviceContext) { - mDeviceContext->GetDevUnitsToAppUnits(p2t); - } + float p2t; + mDeviceContext->GetDevUnitsToAppUnits(p2t); *aResult = p2t; return NS_OK; } @@ -953,11 +947,7 @@ nsPresContext::GetTwipsToPixels(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float app2dev = 1.0f; - if (mDeviceContext) { - mDeviceContext->GetAppUnitsToDevUnits(app2dev); - } - *aResult = app2dev; + mDeviceContext->GetAppUnitsToDevUnits(*aResult); return NS_OK; } @@ -969,24 +959,22 @@ nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const return NS_ERROR_NULL_POINTER; } - float app2dev = 1.0f; - if (mDeviceContext) { + float app2dev; #ifdef NS_PRINT_PREVIEW - // If an alternative DC is available we want to use - // it to get the scaling factor for fonts. Usually, the AltDC - // is a printing DC so therefore we need to get the printers - // scaling values for calculating the font heights - nsCOMPtr altDC; - mDeviceContext->GetAltDevice(getter_AddRefs(altDC)); - if (altDC) { - altDC->GetAppUnitsToDevUnits(app2dev); - } else { - mDeviceContext->GetAppUnitsToDevUnits(app2dev); - } -#else + // If an alternative DC is available we want to use + // it to get the scaling factor for fonts. Usually, the AltDC + // is a printing DC so therefore we need to get the printers + // scaling values for calculating the font heights + nsCOMPtr altDC; + mDeviceContext->GetAltDevice(getter_AddRefs(altDC)); + if (altDC) { + altDC->GetAppUnitsToDevUnits(app2dev); + } else { mDeviceContext->GetAppUnitsToDevUnits(app2dev); -#endif } +#else + mDeviceContext->GetAppUnitsToDevUnits(app2dev); +#endif *aResult = app2dev; return NS_OK; } @@ -998,24 +986,14 @@ nsPresContext::GetScaledPixelsToTwips(float* aResult) const { NS_PRECONDITION(aResult, "null out param"); - float scale = 1.0f; - if (mDeviceContext) - { - float p2t; - mDeviceContext->GetDevUnitsToAppUnits(p2t); - mDeviceContext->GetCanonicalPixelScale(scale); - scale = p2t * scale; - } - *aResult = scale; - return NS_OK; -} + float scale; + float p2t; -NS_IMETHODIMP -nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const -{ - NS_PRECONDITION(aResult, "null out param"); - *aResult = mDeviceContext; - NS_IF_ADDREF(*aResult); + mDeviceContext->GetDevUnitsToAppUnits(p2t); + mDeviceContext->GetCanonicalPixelScale(scale); + scale = p2t * scale; + + *aResult = scale; return NS_OK; } diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index daee7c26605..2fb007c7b83 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -100,7 +100,6 @@ public: NS_IMETHOD GetTwipsToPixels(float* aResult) const; NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const; NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const; - NS_IMETHOD GetDeviceContext(nsIDeviceContext** aResult) const; NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager); nsIEventStateManager* GetEventStateManager() { return nsIPresContext::GetEventStateManager(); diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 7408300dba6..25db795bc0e 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -805,11 +805,8 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext, { //printf("*****************\n"); const nsStyleFont* dspFont = mDisplayFrame->GetStyleFont(); - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsIFontMetrics * fontMet; - deviceContext->GetMetricsFor(dspFont->mFont, fontMet); + aPresContext->DeviceContext()->GetMetricsFor(dspFont->mFont, fontMet); nscoord visibleHeight; //nsCOMPtr fontMet; @@ -1242,15 +1239,10 @@ nsComboboxControlFrame::Reflow(nsIPresContext* aPresContext, // the default size of the of scrollbar // that will be the default width of the dropdown button // the height will be the height of the text - nscoord scrollbarWidth = 0; - nsCOMPtr dx; - aPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) { - float w, h; - // Get the width in Device pixels times p2t - dx->GetScrollBarDimensions(w, h); - scrollbarWidth = NSToCoordRound(w); - } + float w, h; + // Get the width in Device pixels times p2t + aPresContext->DeviceContext()->GetScrollBarDimensions(w, h); + nscoord scrollbarWidth = NSToCoordRound(w); // set up a new reflow state for use throughout nsHTMLReflowState firstPassState(aReflowState); diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 563c39dcd9a..9d544a2b240 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -862,30 +862,25 @@ nsFormControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight) } nsresult -nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, nscoord& aHeight) +nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, + nscoord& aHeight) { - aHeight = 0; - nsCOMPtr context; - aPresContext->GetDeviceContext( getter_AddRefs(context) ); - if ( context ) { - nsRect screen; + nsRect screen; - PRBool dropdownCanOverlapOSBar = PR_FALSE; - nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, - dropdownCanOverlapOSBar); - if ( dropdownCanOverlapOSBar ) - context->GetRect ( screen ); - else - context->GetClientRect(screen); + nsIDeviceContext *context = aPresContext->DeviceContext(); + PRBool dropdownCanOverlapOSBar = PR_FALSE; + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, + dropdownCanOverlapOSBar); + if ( dropdownCanOverlapOSBar ) + context->GetRect ( screen ); + else + context->GetClientRect(screen); - float devUnits; - context->GetDevUnitsToAppUnits(devUnits); - aHeight = NSToIntRound(float(screen.height) / devUnits ); - return NS_OK; - } - - return NS_ERROR_FAILURE; + float devUnits; + context->GetDevUnitsToAppUnits(devUnits); + aHeight = NSToIntRound(float(screen.height) / devUnits ); + return NS_OK; } // Calculate a frame's position in screen coordinates diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index d3e6c794136..da3eec3134b 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -146,11 +146,8 @@ nsresult nsFormControlHelper::GetFrameFontFM(nsIPresContext* aPresContext, const nsFont * font = nsnull; // Get frame font if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) { - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); - if (font != nsnull) { // Get font metrics - return deviceContext->GetMetricsFor(*font, *aFontMet); + if (font) { // Get font metrics + return aPresContext->DeviceContext()->GetMetricsFor(*font, *aFontMet); } } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 742e158716b..8f2b403016a 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -1184,11 +1184,9 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext, nsStyleContext* optStyle = optFrame->GetStyleContext(); if (optStyle) { const nsStyleFont* styleFont = optStyle->GetStyleFont(); - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsIFontMetrics * fontMet; - result = deviceContext->GetMetricsFor(styleFont->mFont, fontMet); + result = aPresContext->DeviceContext()-> + GetMetricsFor(styleFont->mFont, fontMet); if (NS_SUCCEEDED(result) && fontMet != nsnull) { if (fontMet) { fontMet->GetHeight(heightOfARow); diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index f2f530b23c7..ac569eb46ba 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -1410,24 +1410,17 @@ nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext, float p2t; aPresContext->GetPixelsToTwips(&p2t); - nscoord scrollbarWidth = 0; - nscoord scrollbarHeight = 0; - nsCOMPtr dx; - aPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) { - float scale; - dx->GetCanonicalPixelScale(scale); + nsIDeviceContext *dx = aPresContext->DeviceContext(); - float sbWidth; - float sbHeight; - dx->GetScrollBarDimensions(sbWidth, sbHeight); - scrollbarWidth = PRInt32(sbWidth * scale); - scrollbarHeight = PRInt32(sbHeight * scale); - } else { - NS_WARNING("Dude! No DeviceContext! Not cool!"); - scrollbarWidth = nsFormControlFrame::GetScrollbarWidth(p2t); - scrollbarHeight = scrollbarWidth; - } + float scale; + dx->GetCanonicalPixelScale(scale); + + float sbWidth; + float sbHeight; + dx->GetScrollBarDimensions(sbWidth, sbHeight); + + nscoord scrollbarWidth = PRInt32(sbWidth * scale); + nscoord scrollbarHeight = PRInt32(sbHeight * scale); aDesiredSize.height += scrollbarHeight; minSize.height += scrollbarHeight; diff --git a/mozilla/layout/generic/nsPageFrame.cpp b/mozilla/layout/generic/nsPageFrame.cpp index 1ea5f47da91..5d4c9277629 100644 --- a/mozilla/layout/generic/nsPageFrame.cpp +++ b/mozilla/layout/generic/nsPageFrame.cpp @@ -669,11 +669,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.SetColor(NS_RGB(0,0,0)); // Get the FontMetrics to determine width.height of strings - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsCOMPtr fontMet; - deviceContext->GetMetricsFor(*mPD->mHeadFootFont, nsnull, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont, nsnull, + *getter_AddRefs(fontMet)); nscoord ascent = 0; nscoord visibleHeight = 0; if (fontMet) { diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index e671cbf13d6..138fa9f7067 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -6957,16 +6957,6 @@ nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, n if (!presContext) return NS_ERROR_NULL_POINTER; - nsCOMPtr deviceContext; - - rv = presContext->GetDeviceContext(getter_AddRefs(deviceContext)); - - if (NS_FAILED(rv)) - return rv; - - if (!deviceContext) - return NS_ERROR_NULL_POINTER; - // // Now get the closest view with a widget so we can create // a rendering context. @@ -6999,7 +6989,8 @@ nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, n nsCOMPtr rendContext; - rv = deviceContext->CreateRenderingContext(closestView, *getter_AddRefs(rendContext)); + rv = presContext->DeviceContext()-> + CreateRenderingContext(closestView, *getter_AddRefs(rendContext)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index 15c1f2a080f..f5818708eef 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -295,11 +295,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // and if this Document is in the upper left hand corner // we need to suppress the top margin or it will reflow too small // Start by getting the actual printer page dimensions to see if we are not a whole page - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); nscoord width, height; - dc->GetDeviceSurfaceDimensions(width, height); + aPresContext->DeviceContext()->GetDeviceSurfaceDimensions(width, height); // Compute the size of each page and the x coordinate that each page will // be placed at @@ -657,10 +654,6 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } // Begin printing of the document - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); - nsresult rv = NS_OK; #if defined(DEBUG_rods) || defined(DEBUG_dcone) @@ -699,8 +692,8 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, if (mDoingPageRange) { // XXX because of the hack for making the selection all print on one page // we must make sure that the page is sized correctly before printing. - PRInt32 width,height; - dc->GetDeviceSurfaceDimensions(width,height); + PRInt32 width, height; + aPresContext->DeviceContext()->GetDeviceSurfaceDimensions(width, height); PRInt32 pageNum = 1; nscoord y = 0;//mMargin.top; @@ -811,8 +804,7 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext) mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages); // Begin printing of the document - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); + nsIDeviceContext *dc = aPresContext->DeviceContext(); NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); nsIViewManager* vm = aPresContext->GetViewManager(); @@ -965,13 +957,9 @@ nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext) nsresult rv = NS_OK; if (mPrintThisPage) { - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); - if(mSkipPageEnd){ PR_PL(("***************** End Page (DoPageEnd) *****************\n")); - nsresult rv = dc->EndPage(); + nsresult rv = aPresContext->DeviceContext()->EndPage(); if (NS_FAILED(rv)) { return rv; } diff --git a/mozilla/layout/html/base/src/nsPageFrame.cpp b/mozilla/layout/html/base/src/nsPageFrame.cpp index 1ea5f47da91..5d4c9277629 100644 --- a/mozilla/layout/html/base/src/nsPageFrame.cpp +++ b/mozilla/layout/html/base/src/nsPageFrame.cpp @@ -669,11 +669,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.SetColor(NS_RGB(0,0,0)); // Get the FontMetrics to determine width.height of strings - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsCOMPtr fontMet; - deviceContext->GetMetricsFor(*mPD->mHeadFootFont, nsnull, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont, nsnull, + *getter_AddRefs(fontMet)); nscoord ascent = 0; nscoord visibleHeight = 0; if (fontMet) { diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 7420ea3635e..924205489c6 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -3909,17 +3909,13 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame, view->GetViewManager()->GetWidgetForView(view, getter_AddRefs(widget)); } - nsCOMPtr dx; - nsIRenderingContext* result = nsnull; - rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (NS_SUCCEEDED(rv) && dx) { - if (nsnull != widget) { - rv = dx->CreateRenderingContext(widget.get(), result); - } - else { - rv = dx->CreateRenderingContext(result); - } + nsIDeviceContext *deviceContext = mPresContext->DeviceContext(); + if (widget) { + rv = deviceContext->CreateRenderingContext(widget.get(), result); + } + else { + rv = deviceContext->CreateRenderingContext(result); } *aResult = result; @@ -7032,8 +7028,7 @@ PresShell::VerifyIncrementalReflow() } NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); - nsCOMPtr dc; - mPresContext->GetDeviceContext(getter_AddRefs(dc)); + nsIDeviceContext *dc = mPresContext->DeviceContext(); rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp index 15c1f2a080f..f5818708eef 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -295,11 +295,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, // and if this Document is in the upper left hand corner // we need to suppress the top margin or it will reflow too small // Start by getting the actual printer page dimensions to see if we are not a whole page - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); nscoord width, height; - dc->GetDeviceSurfaceDimensions(width, height); + aPresContext->DeviceContext()->GetDeviceSurfaceDimensions(width, height); // Compute the size of each page and the x coordinate that each page will // be placed at @@ -657,10 +654,6 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, } // Begin printing of the document - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); - nsresult rv = NS_OK; #if defined(DEBUG_rods) || defined(DEBUG_dcone) @@ -699,8 +692,8 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext, if (mDoingPageRange) { // XXX because of the hack for making the selection all print on one page // we must make sure that the page is sized correctly before printing. - PRInt32 width,height; - dc->GetDeviceSurfaceDimensions(width,height); + PRInt32 width, height; + aPresContext->DeviceContext()->GetDeviceSurfaceDimensions(width, height); PRInt32 pageNum = 1; nscoord y = 0;//mMargin.top; @@ -811,8 +804,7 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext) mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages); // Begin printing of the document - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); + nsIDeviceContext *dc = aPresContext->DeviceContext(); NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); nsIViewManager* vm = aPresContext->GetViewManager(); @@ -965,13 +957,9 @@ nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext) nsresult rv = NS_OK; if (mPrintThisPage) { - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!"); - if(mSkipPageEnd){ PR_PL(("***************** End Page (DoPageEnd) *****************\n")); - nsresult rv = dc->EndPage(); + nsresult rv = aPresContext->DeviceContext()->EndPage(); if (NS_FAILED(rv)) { return rv; } diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 7408300dba6..25db795bc0e 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -805,11 +805,8 @@ nsComboboxControlFrame::ReflowItems(nsIPresContext* aPresContext, { //printf("*****************\n"); const nsStyleFont* dspFont = mDisplayFrame->GetStyleFont(); - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsIFontMetrics * fontMet; - deviceContext->GetMetricsFor(dspFont->mFont, fontMet); + aPresContext->DeviceContext()->GetMetricsFor(dspFont->mFont, fontMet); nscoord visibleHeight; //nsCOMPtr fontMet; @@ -1242,15 +1239,10 @@ nsComboboxControlFrame::Reflow(nsIPresContext* aPresContext, // the default size of the of scrollbar // that will be the default width of the dropdown button // the height will be the height of the text - nscoord scrollbarWidth = 0; - nsCOMPtr dx; - aPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) { - float w, h; - // Get the width in Device pixels times p2t - dx->GetScrollBarDimensions(w, h); - scrollbarWidth = NSToCoordRound(w); - } + float w, h; + // Get the width in Device pixels times p2t + aPresContext->DeviceContext()->GetScrollBarDimensions(w, h); + nscoord scrollbarWidth = NSToCoordRound(w); // set up a new reflow state for use throughout nsHTMLReflowState firstPassState(aReflowState); diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 563c39dcd9a..9d544a2b240 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -862,30 +862,25 @@ nsFormControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight) } nsresult -nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, nscoord& aHeight) +nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, + nscoord& aHeight) { - aHeight = 0; - nsCOMPtr context; - aPresContext->GetDeviceContext( getter_AddRefs(context) ); - if ( context ) { - nsRect screen; + nsRect screen; - PRBool dropdownCanOverlapOSBar = PR_FALSE; - nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, - dropdownCanOverlapOSBar); - if ( dropdownCanOverlapOSBar ) - context->GetRect ( screen ); - else - context->GetClientRect(screen); + nsIDeviceContext *context = aPresContext->DeviceContext(); + PRBool dropdownCanOverlapOSBar = PR_FALSE; + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, + dropdownCanOverlapOSBar); + if ( dropdownCanOverlapOSBar ) + context->GetRect ( screen ); + else + context->GetClientRect(screen); - float devUnits; - context->GetDevUnitsToAppUnits(devUnits); - aHeight = NSToIntRound(float(screen.height) / devUnits ); - return NS_OK; - } - - return NS_ERROR_FAILURE; + float devUnits; + context->GetDevUnitsToAppUnits(devUnits); + aHeight = NSToIntRound(float(screen.height) / devUnits ); + return NS_OK; } // Calculate a frame's position in screen coordinates diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index d3e6c794136..da3eec3134b 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -146,11 +146,8 @@ nsresult nsFormControlHelper::GetFrameFontFM(nsIPresContext* aPresContext, const nsFont * font = nsnull; // Get frame font if (NS_SUCCEEDED(aFrame->GetFont(aPresContext, font))) { - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); - if (font != nsnull) { // Get font metrics - return deviceContext->GetMetricsFor(*font, *aFontMet); + if (font) { // Get font metrics + return aPresContext->DeviceContext()->GetMetricsFor(*font, *aFontMet); } } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 742e158716b..8f2b403016a 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -1184,11 +1184,9 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext, nsStyleContext* optStyle = optFrame->GetStyleContext(); if (optStyle) { const nsStyleFont* styleFont = optStyle->GetStyleFont(); - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - NS_ASSERTION(deviceContext, "Couldn't get the device context"); nsIFontMetrics * fontMet; - result = deviceContext->GetMetricsFor(styleFont->mFont, fontMet); + result = aPresContext->DeviceContext()-> + GetMetricsFor(styleFont->mFont, fontMet); if (NS_SUCCEEDED(result) && fontMet != nsnull) { if (fontMet) { fontMet->GetHeight(heightOfARow); diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index f2f530b23c7..ac569eb46ba 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -1410,24 +1410,17 @@ nsTextControlFrame::ReflowStandard(nsIPresContext* aPresContext, float p2t; aPresContext->GetPixelsToTwips(&p2t); - nscoord scrollbarWidth = 0; - nscoord scrollbarHeight = 0; - nsCOMPtr dx; - aPresContext->GetDeviceContext(getter_AddRefs(dx)); - if (dx) { - float scale; - dx->GetCanonicalPixelScale(scale); + nsIDeviceContext *dx = aPresContext->DeviceContext(); - float sbWidth; - float sbHeight; - dx->GetScrollBarDimensions(sbWidth, sbHeight); - scrollbarWidth = PRInt32(sbWidth * scale); - scrollbarHeight = PRInt32(sbHeight * scale); - } else { - NS_WARNING("Dude! No DeviceContext! Not cool!"); - scrollbarWidth = nsFormControlFrame::GetScrollbarWidth(p2t); - scrollbarHeight = scrollbarWidth; - } + float scale; + dx->GetCanonicalPixelScale(scale); + + float sbWidth; + float sbHeight; + dx->GetScrollBarDimensions(sbWidth, sbHeight); + + nscoord scrollbarWidth = PRInt32(sbWidth * scale); + nscoord scrollbarHeight = PRInt32(sbHeight * scale); aDesiredSize.height += scrollbarHeight; minSize.height += scrollbarHeight; diff --git a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp index d7b5f378fd9..6d8a1227259 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp @@ -121,8 +121,7 @@ CheckFontExistence(nsIPresContext* aPresContext, const nsString& aFontName) { PRBool aliased; nsAutoString localName; - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); + nsIDeviceContext *deviceContext = aPresContext->DeviceContext(); deviceContext->GetLocalFontName(aFontName, localName, aliased); PRBool rv = (aliased || (NS_OK == deviceContext->CheckFontExistence(localName))); // (see bug 35824 for comments about the aliased localName) diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index c53d7e3eda2..b048558449e 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -726,7 +726,6 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, #endif nsCOMPtr devspec; - nsCOMPtr dx; mPrt->mPrintDC = nsnull; // XXX why? #ifdef NS_DEBUG @@ -806,183 +805,182 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE); if (NS_SUCCEEDED(rv)) { - rv = mPresContext->GetDeviceContext(getter_AddRefs(dx)); + rv = mPresContext->DeviceContext()-> + GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); if (NS_SUCCEEDED(rv)) { - rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC)); - if (NS_SUCCEEDED(rv)) { - // Get the Original PixelScale incase we need to start changing it - mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); - // Shrink to Fit over rides and scaling values - if (!mPrt->mShrinkToFit) { - double scaling; - mPrt->mPrintSettings->GetScaling(&scaling); - mPrt->mPrintDC->SetCanonicalPixelScale(float(scaling)*mPrt->mOrigDCScale); - } + // Get the Original PixelScale incase we need to start changing it + mPrt->mPrintDC->GetCanonicalPixelScale(mPrt->mOrigDCScale); + // Shrink to Fit over rides and scaling values + if (!mPrt->mShrinkToFit) { + double scaling; + mPrt->mPrintSettings->GetScaling(&scaling); + mPrt->mPrintDC->SetCanonicalPixelScale(float(scaling)*mPrt->mOrigDCScale); + } - if(webContainer) { + if(webContainer) { #ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; + float a1,a2; + PRInt32 i1,i2; - printf("CRITICAL PRINTING INFORMATION\n"); + printf("CRITICAL PRINTING INFORMATION\n"); - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); + // DEVICE CONTEXT INFORMATION from PresContext + nsIDeviceContext *dx = mPresContext->DeviceContext(); + printf("DeviceContext of Presentation Context(%x)\n", dx); + dx->GetDevUnitsToTwips(a1); + dx->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + dx->GetAppUnitsToDevUnits(a1); + dx->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + dx->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + dx->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + dx->GetZoom(a1); + printf(" Zoom = %f\n",a1); + dx->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + dx->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC); - mPrt->mPrintDC->GetDevUnitsToTwips(a1); - mPrt->mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrt->mPrintDC->GetAppUnitsToDevUnits(a1); - mPrt->mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrt->mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrt->mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrt->mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrt->mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); + // DEVICE CONTEXT INFORMATION + printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC); + mPrt->mPrintDC->GetDevUnitsToTwips(a1); + mPrt->mPrintDC->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + mPrt->mPrintDC->GetAppUnitsToDevUnits(a1); + mPrt->mPrintDC->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + mPrt->mPrintDC->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + mPrt->mPrintDC->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + mPrt->mPrintDC->GetZoom(a1); + printf(" Zoom = %f\n",a1); + mPrt->mPrintDC->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); #endif /* DEBUG_dcone */ - // Always check and set the print settings first and then fall back - // onto the PrintService if there isn't a PrintSettings - // - // Posiible Usage values: - // nsIPrintSettings::kUseInternalDefault - // nsIPrintSettings::kUseSettingWhenPossible - // - // NOTE: The consts are the same for PrintSettings and PrintSettings - PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; - mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); + // Always check and set the print settings first and then fall back + // onto the PrintService if there isn't a PrintSettings + // + // Posiible Usage values: + // nsIPrintSettings::kUseInternalDefault + // nsIPrintSettings::kUseSettingWhenPossible + // + // NOTE: The consts are the same for PrintSettings and PrintSettings + PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; + mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage); - // Ok, see if we are going to use our value and override the default - if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { - // Get the Print Options/Settings PrintFrameType to see what is preferred - PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; - mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); + // Ok, see if we are going to use our value and override the default + if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) { + // Get the Print Options/Settings PrintFrameType to see what is preferred + PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->GetPrintFrameType(&printFrameType); - // Don't let anybody do something stupid like try to set it to - // kNoFrames when we are printing a FrameSet - if (printFrameType == nsIPrintSettings::kNoFrames) { - mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + // Don't let anybody do something stupid like try to set it to + // kNoFrames when we are printing a FrameSet + if (printFrameType == nsIPrintSettings::kNoFrames) { + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); + } else { + // First find out from the PrinService what options are available + // to us for Printing FrameSets + PRInt16 howToEnableFrameUI; + mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + switch (howToEnableFrameUI) { + case nsIPrintSettings::kFrameEnableAll: + mPrt->mPrintFrameType = printFrameType; + break; + + case nsIPrintSettings::kFrameEnableAsIsAndEach: + if (printFrameType != nsIPrintSettings::kSelectedFrame) { + mPrt->mPrintFrameType = printFrameType; + } else { // revert back to a good value + mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; + } + break; + } // switch mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); - } else { - // First find out from the PrinService what options are available - // to us for Printing FrameSets + } + } + } else { + mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); + } + +#ifdef MOZ_LAYOUTDEBUG + { + // This is a special debugging regression tool section + PRUnichar* tempFileName = nsnull; + if (nsPrintEngine::IsDoingRuntimeTesting()) { + // Here we check for a special filename (the destination for the print job) + // and sets into the print settings if there is a name then we want to + // print to a file. if not, let it print normally. + if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) { + if (*tempFileName) { + mPrt->mPrintSettings->SetPrintToFile(PR_TRUE); + mPrt->mPrintSettings->SetToFileName(tempFileName); + } + nsMemory::Free(tempFileName); + } + + // Here we check to see how we should print a frameset (if there is one) + PRBool asIs = PR_FALSE; + if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) { PRInt16 howToEnableFrameUI; mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { - switch (howToEnableFrameUI) { - case nsIPrintSettings::kFrameEnableAll: - mPrt->mPrintFrameType = printFrameType; - break; - - case nsIPrintSettings::kFrameEnableAsIsAndEach: - if (printFrameType != nsIPrintSettings::kSelectedFrame) { - mPrt->mPrintFrameType = printFrameType; - } else { // revert back to a good value - mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; - } - break; - } // switch + mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } } - } else { - mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType); - } - -#ifdef MOZ_LAYOUTDEBUG - { - // This is a special debugging regression tool section - PRUnichar* tempFileName = nsnull; - if (nsPrintEngine::IsDoingRuntimeTesting()) { - // Here we check for a special filename (the destination for the print job) - // and sets into the print settings if there is a name then we want to - // print to a file. if not, let it print normally. - if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) { - if (*tempFileName) { - mPrt->mPrintSettings->SetPrintToFile(PR_TRUE); - mPrt->mPrintSettings->SetToFileName(tempFileName); - } - nsMemory::Free(tempFileName); - } - - // Here we check to see how we should print a frameset (if there is one) - PRBool asIs = PR_FALSE; - if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) { - PRInt16 howToEnableFrameUI; - mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); - if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { - mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep; - mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); - } - } - } } + } #endif - // Get the Needed info for Calling PrepareDocument - PRUnichar* fileName = nsnull; - // check to see if we are printing to a file - PRBool isPrintToFile = PR_FALSE; - mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); - if (isPrintToFile) { - // On some platforms The PrepareDocument needs to know the name of the file - // and it uses the PrintService to get it, so we need to set it into the PrintService here - mPrt->mPrintSettings->GetToFileName(&fileName); - } - - PRUnichar * docTitleStr; - PRUnichar * docURLStr; - - GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); - PR_PL(("Title: %s\n", docTitleStr?NS_LossyConvertUCS2toASCII(docTitleStr).get():"")); - PR_PL(("URL: %s\n", docURLStr?NS_LossyConvertUCS2toASCII(docURLStr).get():"")); - - rv = mPrt->mPrintDC->PrepareDocument(docTitleStr, fileName); - - if (docTitleStr) nsMemory::Free(docTitleStr); - if (docURLStr) nsMemory::Free(docURLStr); - - CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE); - if (NS_FAILED(rv)) { - return CleanupOnFailure(rv, PR_TRUE); - } - - PRBool doNotify; - ShowPrintProgress(PR_TRUE, doNotify); - - if (!doNotify) { - // Print listener setup... - if (mPrt != nsnull) { - mPrt->OnStartPrinting(); - } - rv = DocumentReadyForPrinting(); + // Get the Needed info for Calling PrepareDocument + PRUnichar* fileName = nsnull; + // check to see if we are printing to a file + PRBool isPrintToFile = PR_FALSE; + mPrt->mPrintSettings->GetPrintToFile(&isPrintToFile); + if (isPrintToFile) { + // On some platforms The PrepareDocument needs to know the name of the file + // and it uses the PrintService to get it, so we need to set it into the PrintService here + mPrt->mPrintSettings->GetToFileName(&fileName); + } + + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + + GetDisplayTitleAndURL(mPrt->mPrintObject, mPrt->mPrintSettings, mPrt->mBrandName, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); + PR_PL(("Title: %s\n", docTitleStr?NS_LossyConvertUCS2toASCII(docTitleStr).get():"")); + PR_PL(("URL: %s\n", docURLStr?NS_LossyConvertUCS2toASCII(docURLStr).get():"")); + + rv = mPrt->mPrintDC->PrepareDocument(docTitleStr, fileName); + + if (docTitleStr) nsMemory::Free(docTitleStr); + if (docURLStr) nsMemory::Free(docURLStr); + + CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE); + if (NS_FAILED(rv)) { + return CleanupOnFailure(rv, PR_TRUE); + } + + PRBool doNotify; + ShowPrintProgress(PR_TRUE, doNotify); + + if (!doNotify) { + // Print listener setup... + if (mPrt != nsnull) { + mPrt->OnStartPrinting(); } + rv = DocumentReadyForPrinting(); } } } diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 99286ec6351..d475807bb8c 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -1560,18 +1560,16 @@ nsRuleNode::SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext, case NS_STYLE_FONT_FIELD: sysID = eSystemFont_Field; break; } - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); - if (dc) { - // GetSystemFont sets the font face but not necessarily the size - aFont->mFont.size = defaultVariableFont->size; - if (NS_FAILED(dc->GetSystemFont(sysID, &aFont->mFont))) { + // GetSystemFont sets the font face but not necessarily the size + aFont->mFont.size = defaultVariableFont->size; + + if (NS_FAILED(aPresContext->DeviceContext()->GetSystemFont(sysID, + &aFont->mFont))) { aFont->mFont.name = defaultVariableFont->name; - } - // this becomes our cascading size - aFont->mSize = aFont->mFont.size - = nsStyleFont::ZoomText(aPresContext, aFont->mFont.size); } + // this becomes our cascading size + aFont->mSize = aFont->mFont.size = + nsStyleFont::ZoomText(aPresContext, aFont->mFont.size); aFont->mFont.familyNameQuirks = PR_FALSE; diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index 8155f7aea2e..94645d7cafe 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -223,10 +223,8 @@ nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aOther) const inline float TextZoomFor(nsIPresContext* aPresContext) { - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); float textZoom; - dc->GetTextZoom(textZoom); + aPresContext->DeviceContext()->GetTextZoom(textZoom); return textZoom; } diff --git a/mozilla/layout/xul/base/src/nsBox.cpp b/mozilla/layout/xul/base/src/nsBox.cpp index bc389645f75..c8122022dd4 100644 --- a/mozilla/layout/xul/base/src/nsBox.cpp +++ b/mozilla/layout/xul/base/src/nsBox.cpp @@ -648,10 +648,8 @@ nsBox::GetBorder(nsMargin& aMargin) nsCOMPtr context; shell->GetPresContext(getter_AddRefs(context)); if (gTheme->ThemeSupportsWidget(context, frame, disp->mAppearance)) { - nsCOMPtr dc; - context->GetDeviceContext(getter_AddRefs(dc)); nsMargin margin(0,0,0,0); - gTheme->GetWidgetBorder(dc, frame, + gTheme->GetWidgetBorder(context->DeviceContext(), frame, disp->mAppearance, &margin); float p2t; context->GetScaledPixelsToTwips(&p2t); diff --git a/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp b/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp index 4d3ed70fb07..4fc7acb941e 100644 --- a/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/nsListBoxBodyFrame.cpp @@ -259,10 +259,9 @@ nsListBoxBodyFrame::Init(nsIPresContext* aPresContext, nsIContent* aContent, nsBoxLayoutState boxLayoutState(aPresContext); - nsCOMPtr dc; - aPresContext->GetDeviceContext(getter_AddRefs(dc)); nsCOMPtr fm; - dc->GetMetricsFor(aContext->GetStyleFont()->mFont, *getter_AddRefs(fm)); + aPresContext->DeviceContext()->GetMetricsFor(aContext->GetStyleFont()->mFont, + *getter_AddRefs(fm)); fm->GetHeight(mRowHeight); return rv; @@ -748,10 +747,10 @@ nsListBoxBodyFrame::ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState) text->AppendTextTo(value); } } - nsCOMPtr dc; - presContext->GetDeviceContext(getter_AddRefs(dc)); nsCOMPtr fm; - dc->GetMetricsFor(styleContext->GetStyleFont()->mFont, *getter_AddRefs(fm)); + presContext->DeviceContext()-> + GetMetricsFor(styleContext->GetStyleFont()->mFont, + *getter_AddRefs(fm)); rendContext->SetFont(fm); nscoord textWidth; diff --git a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp index f4647b5cb7f..ecf1d9fcc96 100644 --- a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp @@ -392,10 +392,9 @@ nsTextBoxFrame::PaintTitle(nsIPresContext* aPresContext, nscoord offset; nscoord size; nscoord baseline; - nsCOMPtr deviceContext; nsCOMPtr fontMet; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - deviceContext->GetMetricsFor(fontStyle->mFont, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()->GetMetricsFor(fontStyle->mFont, + *getter_AddRefs(fontMet)); fontMet->GetMaxAscent(baseline); if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) { @@ -512,11 +511,9 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, if (mTitle.IsEmpty()) return; - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - nsCOMPtr fontMet; - deviceContext->GetMetricsFor(GetStyleFont()->mFont, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()->GetMetricsFor(GetStyleFont()->mFont, + *getter_AddRefs(fontMet)); aRenderingContext.SetFont(fontMet); // see if the text will completely fit in the width given @@ -789,11 +786,9 @@ void nsTextBoxFrame::GetTextSize(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsString& aString, nsSize& aSize, nscoord& aAscent) { - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - nsCOMPtr fontMet; - deviceContext->GetMetricsFor(GetStyleFont()->mFont, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()->GetMetricsFor(GetStyleFont()->mFont, + *getter_AddRefs(fontMet)); fontMet->GetHeight(aSize.height); aRenderingContext.SetFont(fontMet); aRenderingContext.GetWidth(aString, aSize.width); diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index ef80e276c53..21e706d19f5 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -1383,11 +1383,9 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // we add in borders and padding to the text dimension and give that back. nsStyleContext* textContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecelltext); - nsCOMPtr dc; - - mPresContext->GetDeviceContext(getter_AddRefs(dc)); nsCOMPtr fm; - dc->GetMetricsFor(textContext->GetStyleFont()->mFont, *getter_AddRefs(fm)); + mPresContext->DeviceContext()-> + GetMetricsFor(textContext->GetStyleFont()->mFont, *getter_AddRefs(fm)); nscoord height; fm->GetHeight(height); @@ -2828,11 +2826,10 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, textRect.Deflate(bp); // Compute our text size. - nsCOMPtr deviceContext; - aPresContext->GetDeviceContext(getter_AddRefs(deviceContext)); - nsCOMPtr fontMet; - deviceContext->GetMetricsFor(textContext->GetStyleFont()->mFont, *getter_AddRefs(fontMet)); + aPresContext->DeviceContext()-> + GetMetricsFor(textContext->GetStyleFont()->mFont, + *getter_AddRefs(fontMet)); nscoord height, baseline; fontMet->GetHeight(height);