diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 39cd59874482..7365eb54abe8 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 29d1b091ea11..725b8b1075f2 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 01e4f6dacb75..90537b812513 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 59da213f9e49..468befa4fdf0 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 b2b33d46b029..ef558f19d3a7 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 357d514a4a6d..c7ea4d0e3e0b 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 046679b01f85..327b2689082a 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 11cef3b1f1ed..d54635f1aa05 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 9c92d1130bb5..7674ee328946 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 f02bcf8b3455..03ec0402fe2e 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 35a9a52877f7..aa4c3ca0e4f7 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 40d6df0504f7..e8ad6a53b422 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 752992c60a36..a1cea01163c7 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 e5a91adbdbb7..42fe42d72253 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 673bcdcb1000..207099475f52 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 533f597aa1f6..e56a0d88eba6 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 509a724c602e..e61f51346c1a 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 533f597aa1f6..e56a0d88eba6 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 533f597aa1f6..e56a0d88eba6 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 67920373d2da..0f2af9654b0a 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 673bcdcb1000..207099475f52 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 992be3964065..00754a094d76 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 355398f3695b..e3b9ae1df003 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 ec9bb3bd88a5..179300091075 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 71b5f8823809..4a8b715c7e16 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 074b11fc625d..5a2d3b8987a8 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