From f186598ef5a5379d4b0a0249c00d971a4ff8b215 Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Sat, 14 Nov 1998 01:52:27 +0000 Subject: [PATCH] changes for pixel scaling/printing. --- .../html/content/src/nsGenericHTMLElement.cpp | 9 ++++++--- content/html/content/src/nsHTMLBodyElement.cpp | 2 +- content/html/content/src/nsHTMLHRElement.cpp | 3 ++- .../html/content/src/nsHTMLIFrameElement.cpp | 3 ++- content/html/content/src/nsHTMLImageElement.cpp | 3 ++- content/html/content/src/nsHTMLInputElement.cpp | 3 ++- .../html/content/src/nsHTMLTableCellElement.cpp | 3 ++- .../html/content/src/nsHTMLTableColElement.cpp | 4 ++-- .../content/src/nsHTMLTableColGroupElement.cpp | 4 ++-- content/html/content/src/nsHTMLTableElement.cpp | 6 ++++-- .../html/content/src/nsHTMLTableRowElement.cpp | 3 ++- .../content/src/nsHTMLTableSectionElement.cpp | 3 ++- content/html/style/src/nsCSSStyleRule.cpp | 4 +++- layout/base/nsCSSRendering.cpp | 5 +++-- layout/base/nsPresContext.cpp | 15 +++++++++++++++ layout/base/nsPresContext.h | 7 +++++++ layout/base/nsPresShell.cpp | 17 +++++++---------- layout/base/public/nsIPresContext.h | 7 +++++++ layout/base/public/nsPresContext.h | 7 +++++++ layout/base/src/nsFrameImageLoader.cpp | 6 +++++- layout/base/src/nsPresContext.cpp | 15 +++++++++++++++ layout/base/src/nsPresContext.h | 1 + layout/forms/nsFieldSetFrame.cpp | 3 ++- layout/forms/nsFormControlFrame.cpp | 3 ++- layout/forms/nsHTMLButtonControlFrame.cpp | 6 ++++-- layout/generic/nsFrameFrame.cpp | 9 ++++++--- layout/generic/nsFrameSetFrame.cpp | 6 ++++-- layout/generic/nsImageFrame.cpp | 12 ++++++++---- layout/generic/nsObjectFrame.cpp | 6 ++++-- layout/generic/nsSpacerFrame.cpp | 3 ++- layout/html/base/src/nsBodyFrame.cpp | 3 ++- layout/html/base/src/nsHRFrame.cpp | 14 ++++++++++---- layout/html/base/src/nsHTMLImage.cpp | 12 ++++++++---- layout/html/base/src/nsImageFrame.cpp | 12 ++++++++---- layout/html/base/src/nsObjectFrame.cpp | 6 ++++-- layout/html/base/src/nsPresShell.cpp | 17 +++++++---------- layout/html/base/src/nsSpacerFrame.cpp | 3 ++- .../html/content/src/nsGenericHTMLElement.cpp | 9 ++++++--- layout/html/content/src/nsHTMLBodyElement.cpp | 2 +- layout/html/content/src/nsHTMLHRElement.cpp | 3 ++- layout/html/content/src/nsHTMLIFrameElement.cpp | 3 ++- layout/html/content/src/nsHTMLImageElement.cpp | 3 ++- layout/html/content/src/nsHTMLInputElement.cpp | 3 ++- layout/html/content/src/nsHTMLLayerElement.cpp | 3 ++- .../html/content/src/nsHTMLTableCellElement.cpp | 3 ++- .../html/content/src/nsHTMLTableColElement.cpp | 4 ++-- .../content/src/nsHTMLTableColGroupElement.cpp | 4 ++-- layout/html/content/src/nsHTMLTableElement.cpp | 6 ++++-- .../html/content/src/nsHTMLTableRowElement.cpp | 3 ++- .../content/src/nsHTMLTableSectionElement.cpp | 3 ++- layout/html/document/src/nsFrameFrame.cpp | 9 ++++++--- layout/html/document/src/nsFrameSetFrame.cpp | 6 ++++-- .../html/forms/src/nsCheckboxControlFrame.cpp | 3 ++- layout/html/forms/src/nsFieldSetFrame.cpp | 3 ++- layout/html/forms/src/nsFormControlFrame.cpp | 3 ++- .../html/forms/src/nsHTMLButtonControlFrame.cpp | 6 ++++-- layout/html/forms/src/nsRadioControlFrame.cpp | 3 ++- layout/html/style/src/nsCSSRendering.cpp | 5 +++-- layout/html/style/src/nsCSSStyleRule.cpp | 4 +++- layout/html/table/src/nsTableCellFrame.cpp | 8 ++++++-- layout/html/table/src/nsTableFrame.cpp | 2 +- layout/style/nsCSSStyleRule.cpp | 4 +++- layout/tables/nsTableCellFrame.cpp | 8 ++++++-- layout/tables/nsTableFrame.cpp | 2 +- 64 files changed, 248 insertions(+), 112 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 39cd5987448..7365eb54abe 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1462,7 +1462,8 @@ nsGenericHTMLElement::MapImageAttributesInto(nsIHTMLAttributes* aAttributes, if (nsnull != aAttributes) { nsHTMLValue value; - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); nsStyleSpacing* spacing = (nsStyleSpacing*) @@ -1534,7 +1535,8 @@ nsGenericHTMLElement::MapImageAlignAttributeInto(nsIHTMLAttributes* aAttributes, aContext->GetMutableStyleData(eStyleStruct_Text); nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetMutableStyleData(eStyleStruct_Spacing); - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStyleCoord three(NSIntPixelsToTwips(3, p2t)); switch (align) { case NS_STYLE_TEXT_ALIGN_LEFT: @@ -1575,7 +1577,8 @@ nsGenericHTMLElement::MapImageBorderAttributesInto(nsIHTMLAttributes* aAttribute value.SetPixelValue(2); } - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); // Fixup border-padding sums: subtract out the old size and then diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index 29d1b091ea1..725b8b1075f 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -405,7 +405,7 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, // marginwidth/marginheight // XXX: see ua.css for related code in the BODY rule float p2t; - p2t = aPresContext->GetPixelsToTwips(); + aPresContext->GetScaledPixelsToTwips(p2t); nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetMutableStyleData(eStyleStruct_Spacing); aAttributes->GetAttribute(nsHTMLAtoms::marginwidth, value); diff --git a/content/html/content/src/nsHTMLHRElement.cpp b/content/html/content/src/nsHTMLHRElement.cpp index 01e4f6dacb7..90537b81251 100644 --- a/content/html/content/src/nsHTMLHRElement.cpp +++ b/content/html/content/src/nsHTMLHRElement.cpp @@ -222,7 +222,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, } // width: pixel, percent - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); aAttributes->GetAttribute(nsHTMLAtoms::width, value); diff --git a/content/html/content/src/nsHTMLIFrameElement.cpp b/content/html/content/src/nsHTMLIFrameElement.cpp index 59da213f9e4..468befa4fdf 100644 --- a/content/html/content/src/nsHTMLIFrameElement.cpp +++ b/content/html/content/src/nsHTMLIFrameElement.cpp @@ -232,7 +232,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsHTMLValue value; - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); nsStyleSpacing* spacing = (nsStyleSpacing*) diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index b2b33d46b02..ef558f19d3a 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -245,7 +245,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetMutableStyleData(eStyleStruct_Spacing); - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStyleCoord three(NSIntPixelsToTwips(3, p2t)); switch (align) { case NS_STYLE_TEXT_ALIGN_LEFT: diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 357d514a4a6..c7ea4d0e3e0 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -567,7 +567,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_RADIO: { - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nscoord pad = NSIntPixelsToTwips(3, p2t); // add left and right padding around the radio button via css diff --git a/content/html/content/src/nsHTMLTableCellElement.cpp b/content/html/content/src/nsHTMLTableCellElement.cpp index 046679b01f8..327b2689082 100644 --- a/content/html/content/src/nsHTMLTableCellElement.cpp +++ b/content/html/content/src/nsHTMLTableCellElement.cpp @@ -350,7 +350,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, } // width: pixel - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); aAttributes->GetAttribute(nsHTMLAtoms::width, widthValue); diff --git a/content/html/content/src/nsHTMLTableColElement.cpp b/content/html/content/src/nsHTMLTableColElement.cpp index 11cef3b1f1e..d54635f1aa0 100644 --- a/content/html/content/src/nsHTMLTableColElement.cpp +++ b/content/html/content/src/nsHTMLTableColElement.cpp @@ -223,7 +223,6 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); if (nsnull != aAttributes) { - float p2t; nsHTMLValue value; nsStyleText* textStyle = nsnull; @@ -238,7 +237,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, break; case eHTMLUnit_Pixel: - p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); break; } diff --git a/content/html/content/src/nsHTMLTableColGroupElement.cpp b/content/html/content/src/nsHTMLTableColGroupElement.cpp index 9c92d1130bb..7674ee32894 100644 --- a/content/html/content/src/nsHTMLTableColGroupElement.cpp +++ b/content/html/content/src/nsHTMLTableColGroupElement.cpp @@ -212,7 +212,6 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); if (nsnull != aAttributes) { - float p2t; nsHTMLValue value; nsStyleText* textStyle = nsnull; @@ -227,7 +226,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, break; case eHTMLUnit_Pixel: - p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); break; } diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index f02bcf8b345..03ec0402fe2 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -526,7 +526,8 @@ MapTableBorderInto(nsIHTMLAttributes* aAttributes, aContext->GetMutableStyleData(eStyleStruct_Spacing); nsStyleTable *tableStyle = (nsStyleTable*) aContext->GetMutableStyleData(eStyleStruct_Table); - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStyleCoord twips; if (borderValue.GetUnit() == eHTMLUnit_Empty) { tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // non-0 values of border imply default rules=all @@ -561,7 +562,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, if (nsnull!=aAttributes) { - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsHTMLValue value; // width diff --git a/content/html/content/src/nsHTMLTableRowElement.cpp b/content/html/content/src/nsHTMLTableRowElement.cpp index 35a9a52877f..aa4c3ca0e4f 100644 --- a/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/content/html/content/src/nsHTMLTableRowElement.cpp @@ -314,7 +314,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, // height: pixel aAttributes->GetAttribute(nsHTMLAtoms::height, value); if (value.GetUnit() == eHTMLUnit_Pixel) { - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); diff --git a/content/html/content/src/nsHTMLTableSectionElement.cpp b/content/html/content/src/nsHTMLTableSectionElement.cpp index 40d6df0504f..e8ad6a53b42 100644 --- a/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -265,7 +265,8 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, // height: pixel aAttributes->GetAttribute(nsHTMLAtoms::height, value); if (value.GetUnit() == eHTMLUnit_Pixel) { - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); nsStylePosition* pos = (nsStylePosition*) aContext->GetMutableStyleData(eStyleStruct_Position); nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index 752992c60a3..a1cea01163c 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -717,7 +717,9 @@ nscoord CalcLength(const nsCSSValue& aValue, return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight); } case eCSSUnit_Pixel: - return NSFloatPixelsToTwips(aValue.GetFloatValue(), aPresContext->GetPixelsToTwips()); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); + return NSFloatPixelsToTwips(aValue.GetFloatValue(), p2t); } return 0; } diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index e5a91adbdbb..42fe42d7225 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -873,7 +873,8 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, #endif // Convert image dimensions into nscoord's - float p2t = aPresContext.GetPixelsToTwips(); + float p2t; + aPresContext.GetScaledPixelsToTwips(p2t); nscoord tileWidth = NSIntPixelsToTwips(imageSize.width, p2t); nscoord tileHeight = NSIntPixelsToTwips(imageSize.height, p2t); if ((tileWidth == 0) || (tileHeight == 0)) { @@ -937,7 +938,7 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, PRIntn x = xstart; nscoord xpos = xpostart; for (; x <= xCount; ++x, xpos += tileWidth) { - aRenderingContext.DrawImage(image, xpos, ypos); + aRenderingContext.DrawImage(image, xpos, ypos, tileWidth, tileHeight); } } aRenderingContext.PopState(clipState); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 673bcdcb100..207099475f5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -447,6 +447,21 @@ nsPresContext::GetTwipsToPixels() const return 1.0f; } +NS_IMETHODIMP nsPresContext :: GetScaledPixelsToTwips(float &aScale) const +{ + if (nsnull != mDeviceContext) + { + float p2t, scale; + mDeviceContext->GetDevUnitsToAppUnits(p2t); + mDeviceContext->GetCanonicalPixelScale(scale); + aScale = p2t * scale; + } + else + aScale = 1.0f; + + return NS_OK; +} + nsIDeviceContext* nsPresContext::GetDeviceContext() const { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 533f597aa1f..e56a0d88eba 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -214,6 +214,13 @@ public: virtual float GetPixelsToTwips() const = 0; virtual float GetTwipsToPixels() const = 0; + //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; + //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 509a724c602..e61f51346c1 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -755,19 +755,16 @@ NS_IMETHODIMP PresShell :: CreateRenderingContext(nsIFrame *aFrame, view->GetParent(view); } - if (nsnull != view) - { - nsIDeviceContext *dx; + nsIDeviceContext *dx; - dx = mPresContext->GetDeviceContext(); + dx = mPresContext->GetDeviceContext(); + + if (nsnull != view) rv = dx->CreateRenderingContext(view, aContext); - NS_RELEASE(dx); - } else - { - rv = NS_ERROR_FAILURE; - aContext = nsnull; - } + rv = dx->CreateRenderingContext(aContext); + + NS_RELEASE(dx); return rv; } diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index 533f597aa1f..e56a0d88eba 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -214,6 +214,13 @@ public: virtual float GetPixelsToTwips() const = 0; virtual float GetTwipsToPixels() const = 0; + //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; + //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index 533f597aa1f..e56a0d88eba 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -214,6 +214,13 @@ public: virtual float GetPixelsToTwips() const = 0; virtual float GetTwipsToPixels() const = 0; + //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; + //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; diff --git a/layout/base/src/nsFrameImageLoader.cpp b/layout/base/src/nsFrameImageLoader.cpp index 67920373d2d..0f2af9654b0 100644 --- a/layout/base/src/nsFrameImageLoader.cpp +++ b/layout/base/src/nsFrameImageLoader.cpp @@ -29,6 +29,7 @@ #include "prlog.h" #include "nsISizeOfHandler.h" #include "nsIStyleContext.h" +#include "nsIDeviceContext.h" static NS_DEFINE_IID(kIFrameImageLoaderIID, NS_IFRAME_IMAGE_LOADER_IID); static NS_DEFINE_IID(kIImageRequestObserverIID, NS_IIMAGEREQUESTOBSERVER_IID); @@ -206,7 +207,7 @@ nsFrameImageLoader::Notify(nsIImageRequest *aImageRequest, mImageLoadStatus |= NS_IMAGE_LOAD_STATUS_IMAGE_READY; // Convert the rect from pixels to twips - p2t = mPresContext->GetPixelsToTwips(); + mPresContext->GetScaledPixelsToTwips(p2t); changeRect = (const nsRect*)aParam3; damageRect.x = NSIntPixelsToTwips(changeRect->x, p2t); damageRect.y = NSIntPixelsToTwips(changeRect->y, p2t); @@ -283,6 +284,8 @@ nsFrameImageLoader::DamageRepairFrame(const nsRect* aDamageRect) ("nsFrameImageLoader::DamageRepairFrame frame=%p status=%x", mTargetFrame, mImageLoadStatus)); +#if 0 + // XXX I #if 0'd this per troy's instruction... MMP // XXX this should be done somewhere else, like when the window // is created or something??? // XXX maybe there should be a seperate notification service for @@ -297,6 +300,7 @@ nsFrameImageLoader::DamageRepairFrame(const nsRect* aDamageRect) gXXXInstalledColorMap = PR_TRUE; } NS_RELEASE(window); +#endif // Determine damaged area and tell view manager to redraw it nsPoint offset; diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 673bcdcb100..207099475f5 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -447,6 +447,21 @@ nsPresContext::GetTwipsToPixels() const return 1.0f; } +NS_IMETHODIMP nsPresContext :: GetScaledPixelsToTwips(float &aScale) const +{ + if (nsnull != mDeviceContext) + { + float p2t, scale; + mDeviceContext->GetDevUnitsToAppUnits(p2t); + mDeviceContext->GetCanonicalPixelScale(scale); + aScale = p2t * scale; + } + else + aScale = 1.0f; + + return NS_OK; +} + nsIDeviceContext* nsPresContext::GetDeviceContext() const { diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h index 992be396406..00754a094d7 100644 --- a/layout/base/src/nsPresContext.h +++ b/layout/base/src/nsPresContext.h @@ -74,6 +74,7 @@ public: virtual void SetVisibleArea(const nsRect& r); virtual float GetPixelsToTwips() const; virtual float GetTwipsToPixels() const; + NS_IMETHOD GetScaledPixelsToTwips(float &aScale) const; virtual nsIDeviceContext* GetDeviceContext() const; NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager); diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp index 355398f3695..e3b9ae1df00 100644 --- a/layout/forms/nsFieldSetFrame.cpp +++ b/layout/forms/nsFieldSetFrame.cpp @@ -241,7 +241,8 @@ nsFieldSetFrame::Reflow(nsIPresContext& aPresContext, nsReflowStatus& aStatus) { nsSize availSize(aReflowState.maxSize); - float p2t = aPresContext.GetPixelsToTwips(); + float p2t; + aPresContext.GetScaledPixelsToTwips(p2t); const PRInt32 minTopBorder = NSIntPixelsToTwips(MIN_TOP_BORDER, p2t); const nsStyleSpacing* spacing = diff --git a/layout/forms/nsFormControlFrame.cpp b/layout/forms/nsFormControlFrame.cpp index ec9bb3bd88a..17930009107 100644 --- a/layout/forms/nsFormControlFrame.cpp +++ b/layout/forms/nsFormControlFrame.cpp @@ -798,7 +798,8 @@ nsFormControlFrame::CalculateSize (nsIPresContext* aPresContext, nsFormControlFr if (nsnull != aSpec.mColSizeAttr) { colStatus = hContent->GetAttribute(aSpec.mColSizeAttr, colAttr); } - float p2t = aPresContext->GetPixelsToTwips(); + float p2t; + aPresContext->GetScaledPixelsToTwips(p2t); // determine the width nscoord adjSize; diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index 71b5f882380..4a8b715c7e1 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -387,7 +387,8 @@ nsHTMLButtonControlFrame::ShiftContents(nsIPresContext& aPresContext, PRBool aDo nsStyleSpacing* spacing = (nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); // cast deliberate - float p2t = aPresContext.GetPixelsToTwips(); + float p2t; + aPresContext.GetScaledPixelsToTwips(p2t); nscoord shift = (aDown) ? NSIntPixelsToTwips(1, p2t) : -NSIntPixelsToTwips(1, p2t); nsStyleCoord styleCoord; @@ -573,7 +574,8 @@ nsHTMLButtonControlFrame::Paint(nsIPresContext& aPresContext, nsMargin border; spacing->CalcBorderFor(this, border); - float p2t = aPresContext.GetPixelsToTwips(); + float p2t; + aPresContext.GetScaledPixelsToTwips(p2t); nscoord onePixel = NSIntPixelsToTwips(1, p2t); nsRect outside(0, 0, mRect.width, mRect.height); diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index 074b11fc625..5a2d3b8987a 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -237,7 +237,8 @@ nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize) { // processing does not use this routine, only