diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 6f6439ea983..f3c4b606c80 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -877,11 +877,9 @@ PRBool nsAccessible::IsVisible(PRBool *aIsOffscreen) relFrameRect.y = frameOffset.y; } - float p2t; - p2t = presContext->PixelsToTwips(); nsRectVisibility rectVisibility; - viewManager->GetRectVisibility(containingView, relFrameRect, - NS_STATIC_CAST(PRUint16, (kMinPixels * p2t)), + viewManager->GetRectVisibility(containingView, relFrameRect, + nsPresContext::CSSPixelsToAppUnits(kMinPixels), &rectVisibility); if (rectVisibility == nsRectVisibility_kZeroAreaRect) { @@ -1173,9 +1171,6 @@ NS_IMETHODIMP nsAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PR return NS_ERROR_FAILURE; } - float t2p; - t2p = presContext->TwipsToPixels(); // Get pixels to twips conversion factor - nsRect unionRectTwips; nsIFrame* aBoundingFrame = nsnull; GetBoundsRect(unionRectTwips, &aBoundingFrame); // Unions up all primary frames for this node and all siblings after it @@ -1184,10 +1179,10 @@ NS_IMETHODIMP nsAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PR return NS_ERROR_FAILURE; } - *x = NSTwipsToIntPixels(unionRectTwips.x, t2p); - *y = NSTwipsToIntPixels(unionRectTwips.y, t2p); - *width = NSTwipsToIntPixels(unionRectTwips.width, t2p); - *height = NSTwipsToIntPixels(unionRectTwips.height, t2p); + *x = presContext->AppUnitsToDevPixels(unionRectTwips.x); + *y = presContext->AppUnitsToDevPixels(unionRectTwips.y); + *width = presContext->AppUnitsToDevPixels(unionRectTwips.width); + *height = presContext->AppUnitsToDevPixels(unionRectTwips.height); // We have the union of the rectangle, now we need to put it in absolute screen coords diff --git a/accessible/src/base/nsCaretAccessible.cpp b/accessible/src/base/nsCaretAccessible.cpp index 480972ceaea..23c86b7d3e8 100644 --- a/accessible/src/base/nsCaretAccessible.cpp +++ b/accessible/src/base/nsCaretAccessible.cpp @@ -163,14 +163,10 @@ NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument *aDoc, ns if (!widget) return NS_OK; - float t2p = presContext->TwipsToPixels(); - - // Convert to pixels using that scale - caretRect.x = NSTwipsToIntPixels(caretRect.x, t2p); - caretRect.y = NSTwipsToIntPixels(caretRect.y, t2p); - - caretRect.width = NSTwipsToIntPixels(caretRect.width, t2p); - caretRect.height = NSTwipsToIntPixels(caretRect.height, t2p); + caretRect.x = presContext->AppUnitsToDevPixels(caretRect.x); + caretRect.y = presContext->AppUnitsToDevPixels(caretRect.y); + caretRect.width = presContext->AppUnitsToDevPixels(caretRect.width); + caretRect.height = presContext->AppUnitsToDevPixels(caretRect.height); widget->WidgetToScreen(caretRect, mCaretRect); diff --git a/accessible/src/html/nsHTMLAreaAccessible.cpp b/accessible/src/html/nsHTMLAreaAccessible.cpp index b3f40fccfeb..b7a4b2a95f3 100644 --- a/accessible/src/html/nsHTMLAreaAccessible.cpp +++ b/accessible/src/html/nsHTMLAreaAccessible.cpp @@ -144,16 +144,13 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *w rv = map->GetBoundsForAreaContent(ourContent, presContext, rect); NS_ENSURE_SUCCESS(rv, rv); - // Convert from twips to pixels - float t2p; - t2p = presContext->TwipsToPixels(); // Get pixels conversion factor - *x = NSTwipsToIntPixels(rect.x, t2p); - *y = NSTwipsToIntPixels(rect.y, t2p); + *x = presContext->AppUnitsToDevPixels(rect.x); + *y = presContext->AppUnitsToDevPixels(rect.y); // XXX Areas are screwy; they return their rects as a pair of points, one pair // stored into the width and height. - *width = NSTwipsToIntPixels(rect.width, t2p) - *x; - *height = NSTwipsToIntPixels(rect.height, t2p) - *y; + *width = presContext->AppUnitsToDevPixels(rect.width - rect.x); + *height = presContext->AppUnitsToDevPixels(rect.height - rect.y); // Put coords in absolute screen coords orgRectPixels = frame->GetScreenRectExternal(); diff --git a/accessible/src/html/nsHyperTextAccessible.cpp b/accessible/src/html/nsHyperTextAccessible.cpp index 9a454278a94..fe077fe531c 100644 --- a/accessible/src/html/nsHyperTextAccessible.cpp +++ b/accessible/src/html/nsHyperTextAccessible.cpp @@ -257,7 +257,6 @@ nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRInt32 aS NS_ENSURE_SUCCESS(rv, screenRect); nsPresContext *context = shell->GetPresContext(); - float t2p = context->TwipsToPixels(); while (frame && aLength > 0) { // Start with this frame's screen rect, which we will @@ -276,13 +275,13 @@ nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRInt32 aS nsPoint frameTextStartPoint; rv = frame->GetPointFromOffset(context, rc, aStartOffset, &frameTextStartPoint); NS_ENSURE_SUCCESS(rv, nsRect()); - frameScreenRect.x += NSTwipsToIntPixels(frameTextStartPoint.x, t2p); + frameScreenRect.x += context->AppUnitsToDevPixels(frameTextStartPoint.x); // Use the point for the end offset to calculate the width nsPoint frameTextEndPoint; rv = frame->GetPointFromOffset(context, rc, aStartOffset + frameSubStringLength, &frameTextEndPoint); NS_ENSURE_SUCCESS(rv, nsRect()); - frameScreenRect.width = NSTwipsToIntPixels(frameTextEndPoint.x - frameTextStartPoint.x, t2p); + frameScreenRect.width = context->AppUnitsToDevPixels(frameTextEndPoint.x - frameTextStartPoint.x); screenRect.UnionRect(frameScreenRect, screenRect); @@ -925,10 +924,8 @@ NS_IMETHODIMP nsHyperTextAccessible::GetOffsetAtPoint(PRInt32 aX, PRInt32 aY, ns nsPoint pointInHyperText(aX - frameScreenRect.x, aY - frameScreenRect.y); nsPresContext *context = GetPresContext(); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - // Convert to twips - float p2t = context->PixelsToTwips(); - pointInHyperText.x = NSIntPixelsToTwips(pointInHyperText.x, p2t); - pointInHyperText.y = NSIntPixelsToTwips(pointInHyperText.y, p2t); + pointInHyperText.x = context->DevPixelsToAppUnits(pointInHyperText.x); + pointInHyperText.y = context->DevPixelsToAppUnits(pointInHyperText.y); // Go through the frames to check if each one has the point. // When one does, add up the character offsets until we have a match diff --git a/accessible/src/msaa/nsTextAccessibleWrap.cpp b/accessible/src/msaa/nsTextAccessibleWrap.cpp index 2ddc8e1c592..bcd2cebb64a 100755 --- a/accessible/src/msaa/nsTextAccessibleWrap.cpp +++ b/accessible/src/msaa/nsTextAccessibleWrap.cpp @@ -221,7 +221,6 @@ nsresult nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset, PRInt32 { nsPresContext *presContext = GetPresContext(); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - float t2p = presContext->TwipsToPixels(); nsIFrame *frame = GetFrame(); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); @@ -245,8 +244,8 @@ nsresult nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset, PRInt32 nsIFrame *stopLoopFrame = endFrame->GetNextContinuation(); for (; iter != stopLoopFrame; iter = iter->GetNextContinuation()) { nsRect rect = iter->GetScreenRectExternal(); - nscoord start = (iter == startFrame) ? NSTwipsToIntPixels(startPoint.x, t2p) : 0; - nscoord end = (iter == endFrame) ? NSTwipsToIntPixels(endPoint.x, t2p) : + nscoord start = (iter == startFrame) ? presContext->AppUnitsToDevPixels(startPoint.x) : 0; + nscoord end = (iter == endFrame) ? presContext->AppUnitsToDevPixels(endPoint.x) : rect.width; rect.x += start; rect.width = end - start; diff --git a/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp b/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp index 92123a0cb4d..da7e2e938ae 100644 --- a/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp +++ b/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp @@ -102,8 +102,8 @@ NS_IMETHODIMP nsXULTreeitemAccessibleWrap::GetBounds(PRInt32 *x, PRInt32 *y, PRI PRInt32 cellStartX, cellStartY; mTree->GetCoordsForCellItem(mRow, mColumn, EmptyCString(), &cellStartX, &cellStartY, width, height); // Use entire row width, not just key column's width - float t2p = GetPresContext()->TwipsToPixels(); - *width = NSTwipsToIntPixels(frame->GetRect().width, t2p) - cellStartX; + *width = GetPresContext()->AppUnitsToDevPixels(frame->GetRect().width) - + cellStartX; } return NS_OK; } diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 2aaa52ee88e..bbe25910265 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -2619,10 +2619,6 @@ nsCanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, PRInt32 aX, PRInt3 nsresult rv = mCSSParser->ParseColorString(PromiseFlatString(aBGColor), nsnull, 0, PR_TRUE, &bgColor); NS_ENSURE_SUCCESS(rv, rv); - - float p2t = presContext->PixelsToTwips(); - nsRect r(aX, aY, aW, aH); - r.ScaleRoundOut(p2t); #ifndef MOZILLA_1_8_BRANCH nsIPresShell* presShell = presContext->PresShell(); @@ -2652,8 +2648,10 @@ nsCanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, PRInt32 aX, PRInt3 nsIFrame* rootFrame = presShell->FrameManager()->GetRootFrame(); if (rootFrame) { // XXX This shadows the other |r|, above. - nsRect r(aX, aY, aW, aH); - r.ScaleRoundOut(presContext->PixelsToTwips()); + nsRect r(nsPresContext::CSSPixelsToAppUnits(aX), + nsPresContext::CSSPixelsToAppUnits(aY), + nsPresContext::CSSPixelsToAppUnits(aW), + nsPresContext::CSSPixelsToAppUnits(aH)); nsDisplayListBuilder builder(rootFrame, PR_FALSE, PR_FALSE); nsDisplayList list; @@ -2669,7 +2667,7 @@ nsCanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, PRInt32 aX, PRInt3 rv = rootFrame->BuildDisplayListForStackingContext(&builder, r, &list); if (NS_SUCCEEDED(rv)) { - float t2p = presContext->TwipsToPixels(); + float t2p = presContext->AppUnitsPerDevPixel(); // Ensure that r.x,r.y gets drawn at (0,0) mThebesContext->Save(); mThebesContext->Translate(gfxPoint(-r.x*t2p, -r.y*t2p)); diff --git a/content/events/src/nsDOMUIEvent.cpp b/content/events/src/nsDOMUIEvent.cpp index 90772904da8..143d7883440 100644 --- a/content/events/src/nsDOMUIEvent.cpp +++ b/content/events/src/nsDOMUIEvent.cpp @@ -129,7 +129,8 @@ nsPoint nsDOMUIEvent::GetScreenPoint() { nsRect bounds(mEvent->refPoint, nsSize(1, 1)); nsRect offset; ((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset ); - return offset.TopLeft(); + return nsPoint(nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(offset.x)), + nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(offset.y))); } nsPoint nsDOMUIEvent::GetClientPoint() { @@ -223,7 +224,8 @@ nsPoint nsDOMUIEvent::GetClientPoint() { } } - return pt; + return nsPoint(nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(pt.x)), + nsPresContext::AppUnitsToIntCSSPixels(mPresContext->DevPixelsToAppUnits(pt.y))); } NS_IMETHODIMP @@ -262,13 +264,12 @@ nsDOMUIEvent::GetPageX(PRInt32* aPageX) nsresult ret = NS_OK; PRInt32 scrollX = 0; nsIScrollableView* view = nsnull; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if(view) { nscoord xPos, yPos; ret = view->GetScrollPosition(xPos, yPos); - scrollX = NSTwipsToIntPixels(xPos, t2p); + scrollX = nsPresContext::AppUnitsToIntCSSPixels(xPos); } if (NS_SUCCEEDED(ret)) { @@ -285,13 +286,12 @@ nsDOMUIEvent::GetPageY(PRInt32* aPageY) nsresult ret = NS_OK; PRInt32 scrollY = 0; nsIScrollableView* view = nsnull; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if(view) { nscoord xPos, yPos; ret = view->GetScrollPosition(xPos, yPos); - scrollY = NSTwipsToIntPixels(yPos, t2p); + scrollY = nsPresContext::AppUnitsToIntCSSPixels(yPos); } if (NS_SUCCEEDED(ret)) { @@ -382,7 +382,6 @@ nsPoint nsDOMUIEvent::GetLayerPoint() { // XXX This is supposed to be relative to the nearest view? // Any element can have a view, not just positioned ones. - float t2p = mPresContext->TwipsToPixels(); nsIFrame* targetFrame; nsPoint pt; mPresContext->EventStateManager()->GetEventTarget(&targetFrame); @@ -391,8 +390,8 @@ nsPoint nsDOMUIEvent::GetLayerPoint() { } if (targetFrame) { pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, targetFrame); - pt.x = NSTwipsToIntPixels(pt.x, t2p); - pt.y = NSTwipsToIntPixels(pt.y, t2p); + pt.x = nsPresContext::AppUnitsToIntCSSPixels(pt.x); + pt.y = nsPresContext::AppUnitsToIntCSSPixels(pt.y); return pt; } else { return nsPoint(0,0); @@ -442,27 +441,18 @@ nsDOMUIEvent::GetPreventDefault(PRBool* aReturn) } nsresult -nsDOMUIEvent::GetScrollInfo(nsIScrollableView** aScrollableView, - float* aP2T, float* aT2P) +nsDOMUIEvent::GetScrollInfo(nsIScrollableView** aScrollableView) { NS_ENSURE_ARG_POINTER(aScrollableView); - NS_ENSURE_ARG_POINTER(aP2T); - NS_ENSURE_ARG_POINTER(aT2P); if (!mPresContext) { *aScrollableView = nsnull; return NS_ERROR_FAILURE; } - *aP2T = mPresContext->PixelsToTwips(); - *aT2P = mPresContext->TwipsToPixels(); + nsIViewManager *vm = mPresContext->GetViewManager(); + if (vm) + return vm->GetRootScrollableView(aScrollableView); - nsIPresShell *presShell = mPresContext->GetPresShell(); - if (presShell) { - nsIViewManager* vm = presShell->GetViewManager(); - if(vm) { - return vm->GetRootScrollableView(aScrollableView); - } - } return NS_OK; } diff --git a/content/events/src/nsDOMUIEvent.h b/content/events/src/nsDOMUIEvent.h index 6a8c7723a1d..9680f8727e9 100644 --- a/content/events/src/nsDOMUIEvent.h +++ b/content/events/src/nsDOMUIEvent.h @@ -72,8 +72,7 @@ public: protected: // Internal helper functions - nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, - float* aT2P); + nsresult GetScrollInfo(nsIScrollableView** aScrollableView); nsPoint GetClientPoint(); nsPoint GetScreenPoint(); nsPoint GetLayerPoint(); diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 2670a63406a..9d1d925f453 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -1675,13 +1675,14 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, // nsEventListenerManager::PrepareToUseCaretPosition // // This checks to see if we should use the caret position for popup context -// menus. Returns true if the caret position should be used, and the window -// coordinates of that position are placed into WindowX/Y. This function +// menus. Returns true if the caret position should be used, and the +// coordinates of that position is returned in aTargetPt. This function // will also scroll the window as needed to make the caret visible. // // The event widget should be the widget that generated the event, and // whose coordinate system the resulting event's refPoint should be -// relative to. +// relative to. The returned point is in device pixels realtive to the +// widget passed in. PRBool nsEventListenerManager::PrepareToUseCaretPosition(nsIWidget* aEventWidget, @@ -1779,14 +1780,14 @@ nsEventListenerManager::PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsPoint viewDelta = view->GetOffsetTo(widgetView) + viewToWidget; // caret coordinates are in twips, convert to pixels - float t2p = aShell->GetPresContext()->TwipsToPixels(); - aTargetPt.x = NSTwipsToIntPixels(viewDelta.x + caretCoords.x + caretCoords.width, t2p); - aTargetPt.y = NSTwipsToIntPixels(viewDelta.y + caretCoords.y + caretCoords.height, t2p); + nsPresContext* presContext = aShell->GetPresContext(); + aTargetPt.x = presContext->AppUnitsToDevPixels(viewDelta.x + caretCoords.x + caretCoords.width); + aTargetPt.y = presContext->AppUnitsToDevPixels(viewDelta.y + caretCoords.y + caretCoords.height); return PR_TRUE; } -// Get coordinates relative to root view for element, +// Get coordinates in device pixels relative to root view for element, // first ensuring the element is onscreen void nsEventListenerManager::GetCoordinatesFor(nsIDOMElement *aCurrentEl, @@ -1883,10 +1884,8 @@ nsEventListenerManager::GetCoordinatesFor(nsIDOMElement *aCurrentEl, } #endif - // Convert from twips to pixels - float t2p = aPresContext->TwipsToPixels(); - aTargetPt.x = NSTwipsToIntPixels(frameOrigin.x + extra, t2p); - aTargetPt.y = NSTwipsToIntPixels(frameOrigin.y + extra, t2p) + extraPixelsY; + aTargetPt.x = aPresContext->AppUnitsToDevPixels(frameOrigin.x + extra); + aTargetPt.y = aPresContext->AppUnitsToDevPixels(frameOrigin.y + extra) + extraPixelsY; } } diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index c2fcfffb933..c6d949efe50 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -717,16 +717,12 @@ nsGenericHTMLElement::GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent) // XXX We should really consider subtracting out padding for // content-box sizing, but we should see what IE does.... - - // Get the scale from that Presentation Context - float scale; - scale = context->TwipsToPixels(); // Convert to pixels using that scale - aRect.x = NSTwipsToIntPixels(origin.x, scale); - aRect.y = NSTwipsToIntPixels(origin.y, scale); - aRect.width = NSTwipsToIntPixels(rcFrame.width, scale); - aRect.height = NSTwipsToIntPixels(rcFrame.height, scale); + aRect.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x); + aRect.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y); + aRect.width = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.width); + aRect.height = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.height); } nsresult @@ -886,12 +882,9 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML) void nsGenericHTMLElement::GetScrollInfo(nsIScrollableView **aScrollableView, - float *aP2T, float *aT2P, nsIFrame **aFrame) { *aScrollableView = nsnull; - *aP2T = 0.0f; - *aT2P = 0.0f; nsIDocument *document = GetCurrentDoc(); if (!document) { @@ -909,12 +902,6 @@ nsGenericHTMLElement::GetScrollInfo(nsIScrollableView **aScrollableView, return; } - // Get the presentation context - nsPresContext *presContext = presShell->GetPresContext(); - if (!presContext) { - return; - } - // Get the primary frame for this element nsIFrame *frame = presShell->GetPrimaryFrameFor(this); if (!frame) { @@ -925,9 +912,6 @@ nsGenericHTMLElement::GetScrollInfo(nsIScrollableView **aScrollableView, *aFrame = frame; } - *aP2T = presContext->PixelsToTwips(); - *aT2P = presContext->TwipsToPixels(); - // Get the scrollable frame nsIScrollableFrame *scrollFrame = nsnull; CallQueryInterface(frame, &scrollFrame); @@ -983,15 +967,14 @@ nsGenericHTMLElement::GetScrollTop(PRInt32* aScrollTop) nsIScrollableView *view = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (view) { nscoord xPos, yPos; rv = view->GetScrollPosition(xPos, yPos); - *aScrollTop = NSTwipsToIntPixels(yPos, t2p); + *aScrollTop = nsPresContext::AppUnitsToIntCSSPixels(yPos); } return rv; @@ -1002,9 +985,8 @@ nsGenericHTMLElement::SetScrollTop(PRInt32 aScrollTop) { nsIScrollableView *view = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (view) { nscoord xPos, yPos; @@ -1012,7 +994,7 @@ nsGenericHTMLElement::SetScrollTop(PRInt32 aScrollTop) rv = view->GetScrollPosition(xPos, yPos); if (NS_SUCCEEDED(rv)) { - rv = view->ScrollTo(xPos, NSIntPixelsToTwips(aScrollTop, p2t), + rv = view->ScrollTo(xPos, nsPresContext::CSSPixelsToAppUnits(aScrollTop), NS_VMREFRESH_IMMEDIATE); } } @@ -1028,15 +1010,14 @@ nsGenericHTMLElement::GetScrollLeft(PRInt32* aScrollLeft) nsIScrollableView *view = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (view) { nscoord xPos, yPos; rv = view->GetScrollPosition(xPos, yPos); - *aScrollLeft = NSTwipsToIntPixels(xPos, t2p); + *aScrollLeft = nsPresContext::AppUnitsToIntCSSPixels(xPos); } return rv; @@ -1047,16 +1028,15 @@ nsGenericHTMLElement::SetScrollLeft(PRInt32 aScrollLeft) { nsIScrollableView *view = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (view) { nscoord xPos, yPos; rv = view->GetScrollPosition(xPos, yPos); if (NS_SUCCEEDED(rv)) { - rv = view->ScrollTo(NSIntPixelsToTwips(aScrollLeft, p2t), + rv = view->ScrollTo(nsPresContext::CSSPixelsToAppUnits(aScrollLeft), yPos, NS_VMREFRESH_IMMEDIATE); } } @@ -1072,9 +1052,8 @@ nsGenericHTMLElement::GetScrollHeight(PRInt32* aScrollHeight) nsIScrollableView *scrollView = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&scrollView, &p2t, &t2p); + GetScrollInfo(&scrollView); if (!scrollView) { return GetOffsetHeight(aScrollHeight); @@ -1084,7 +1063,7 @@ nsGenericHTMLElement::GetScrollHeight(PRInt32* aScrollHeight) nscoord xMax, yMax; rv = scrollView->GetContainerSize(&xMax, &yMax); - *aScrollHeight = NSTwipsToIntPixels(yMax, t2p); + *aScrollHeight = nsPresContext::AppUnitsToIntCSSPixels(yMax); return rv; } @@ -1097,9 +1076,8 @@ nsGenericHTMLElement::GetScrollWidth(PRInt32* aScrollWidth) nsIScrollableView *scrollView = nsnull; nsresult rv = NS_OK; - float p2t, t2p; - GetScrollInfo(&scrollView, &p2t, &t2p); + GetScrollInfo(&scrollView); if (!scrollView) { return GetOffsetWidth(aScrollWidth); @@ -1108,7 +1086,7 @@ nsGenericHTMLElement::GetScrollWidth(PRInt32* aScrollWidth) nscoord xMax, yMax; rv = scrollView->GetContainerSize(&xMax, &yMax); - *aScrollWidth = NSTwipsToIntPixels(xMax, t2p); + *aScrollWidth = nsPresContext::AppUnitsToIntCSSPixels(xMax); return rv; } @@ -1127,22 +1105,21 @@ nsGenericHTMLElement::GetClientHeight(PRInt32* aClientHeight) *aClientHeight = 0; nsIScrollableView *scrollView = nsnull; - float p2t, t2p; nsIFrame *frame = nsnull; - GetScrollInfo(&scrollView, &p2t, &t2p, &frame); + GetScrollInfo(&scrollView, &frame); if (scrollView) { nsRect r = scrollView->View()->GetBounds(); - *aClientHeight = NSTwipsToIntPixels(r.height, t2p); + *aClientHeight = nsPresContext::AppUnitsToIntCSSPixels(r.height); } else if (frame && (frame->GetStyleDisplay()->mDisplay != NS_STYLE_DISPLAY_INLINE || (frame->IsFrameOfType(nsIFrame::eReplaced)))) { // Special case code to make clientHeight work even when there isn't // a scroll view, see bug 180552 and bug 227567. - *aClientHeight = NSTwipsToIntPixels(GetClientAreaSize(frame).height, t2p); + *aClientHeight = nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaSize(frame).height); } return NS_OK; @@ -1155,22 +1132,21 @@ nsGenericHTMLElement::GetClientWidth(PRInt32* aClientWidth) *aClientWidth = 0; nsIScrollableView *scrollView = nsnull; - float p2t, t2p; nsIFrame *frame = nsnull; - GetScrollInfo(&scrollView, &p2t, &t2p, &frame); + GetScrollInfo(&scrollView, &frame); if (scrollView) { nsRect r = scrollView->View()->GetBounds(); - *aClientWidth = NSTwipsToIntPixels(r.width, t2p); + *aClientWidth = nsPresContext::AppUnitsToIntCSSPixels(r.width); } else if (frame && (frame->GetStyleDisplay()->mDisplay != NS_STYLE_DISPLAY_INLINE || (frame->IsFrameOfType(nsIFrame::eReplaced)))) { // Special case code to make clientWidth work even when there isn't // a scroll view, see bug 180552 and bug 227567. - *aClientWidth = NSTwipsToIntPixels(GetClientAreaSize(frame).width, t2p); + *aClientWidth = nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaSize(frame).width); } return NS_OK; diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index ab4d8578bb1..1e9dddbd67a 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -172,8 +172,8 @@ public: * [OUT] */ void GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent); - void GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T, - float *aT2P, nsIFrame **aFrame = nsnull); + void GetScrollInfo(nsIScrollableView **aScrollableView, + nsIFrame **aFrame = nsnull); /** * Get an element's client info if the element doesn't have a diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index e9fb50e4255..895baba81d8 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -52,12 +52,10 @@ #include "nsIScriptContext.h" #include "nsIURL.h" #include "nsIIOService.h" -#include "nsIURL.h" #include "nsIServiceManager.h" #include "nsNetUtil.h" #include "nsContentUtils.h" #include "nsIFrame.h" -#include "nsIImageFrame.h" #include "nsNodeInfoManager.h" #include "nsGUIEvent.h" #include "nsContentPolicyUtils.h" @@ -148,7 +146,6 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; protected: - void GetImageFrame(nsIImageFrame** aImageFrame); nsPoint GetXY(); nsSize GetWidthHeight(); }; @@ -218,21 +215,6 @@ NS_IMPL_URI_ATTR(nsHTMLImageElement, Src, src) NS_IMPL_STRING_ATTR(nsHTMLImageElement, UseMap, usemap) NS_IMPL_INT_ATTR(nsHTMLImageElement, Vspace, vspace) -void -nsHTMLImageElement::GetImageFrame(nsIImageFrame** aImageFrame) -{ - *aImageFrame = nsnull; - // If we have no parent, then we won't have a frame yet - if (!GetParent()) - return; - - nsIFrame* frame = GetPrimaryFrame(Flush_Frames); - - if (frame) { - CallQueryInterface(frame, aImageFrame); - } -} - NS_IMETHODIMP nsHTMLImageElement::GetComplete(PRBool* aComplete) { @@ -257,34 +239,13 @@ nsHTMLImageElement::GetXY() { nsPoint point(0, 0); - nsIDocument *document = GetCurrentDoc(); - - if (!document) { - return point; - } - - // Get Presentation shell 0 - nsIPresShell *presShell = document->GetShellAt(0); - if (!presShell) { - return point; - } - - // Get the Presentation Context from the Shell - nsPresContext *context = presShell->GetPresContext(); - if (!context) { - return point; - } - - // Flush all pending notifications so that our frames are laid out correctly - document->FlushPendingNotifications(Flush_Layout); - - // Get the Frame for this image - nsIFrame* frame = presShell->GetPrimaryFrameFor(this); + nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame) { return point; } + // XXX This should search for the nearest abs. pos. container nsPoint origin(0, 0); nsIView* parentView; nsresult rv = frame->GetOffsetFromView(origin, &parentView); @@ -292,13 +253,9 @@ nsHTMLImageElement::GetXY() return point; } - // Get the scale from that Presentation Context - float scale; - scale = context->TwipsToPixels(); - // Convert to pixels using that scale - point.x = NSTwipsToIntPixels(origin.x, scale); - point.y = NSTwipsToIntPixels(origin.y, scale); + point.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x); + point.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y); return point; } @@ -324,37 +281,13 @@ nsHTMLImageElement::GetWidthHeight() { nsSize size(0,0); - nsIDocument* doc = GetCurrentDoc(); - if (doc) { - // Flush all pending notifications so that our frames are up to date. - // If we're not in a document, we don't have a frame anyway, so we - // don't care. - doc->FlushPendingNotifications(Flush_Layout); - } - - nsIImageFrame* imageFrame; - GetImageFrame(&imageFrame); - - nsIFrame* frame = nsnull; - - if (imageFrame) { - CallQueryInterface(imageFrame, &frame); - NS_ASSERTION(frame,"Should not happen - image frame is not frame"); - } + nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (frame) { - // XXX we could put an accessor on nsIImageFrame to return its - // mComputedSize..... size = frame->GetContentRect().Size(); - nsPresContext *context = GetPresContext(); - if (context) { - float t2p; - t2p = context->TwipsToPixels(); - - size.width = NSTwipsToIntPixels(size.width, t2p); - size.height = NSTwipsToIntPixels(size.height, t2p); - } + size.width = nsPresContext::AppUnitsToIntCSSPixels(size.width); + size.height = nsPresContext::AppUnitsToIntCSSPixels(size.height); } else { const nsAttrValue* value; nsCOMPtr image; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index a67ae1df998..c22c99c2527 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2666,15 +2666,8 @@ nsHTMLDocument::GetPixelDimensions(nsIPresShell* aShell, size = frame->GetSize(); } - // Convert from twips to pixels - nsPresContext *context = aShell->GetPresContext(); - if (context) { - float scale; - scale = context->TwipsToPixels(); - - *aWidth = NSTwipsToIntPixels(size.width, scale); - *aHeight = NSTwipsToIntPixels(size.height, scale); - } + *aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width); + *aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height); } return NS_OK; diff --git a/content/html/document/src/nsImageDocument.cpp b/content/html/document/src/nsImageDocument.cpp index 3ef45585444..6a0e1991215 100644 --- a/content/html/document/src/nsImageDocument.cpp +++ b/content/html/document/src/nsImageDocument.cpp @@ -449,8 +449,8 @@ nsImageDocument::RestoreImageTo(PRInt32 aX, PRInt32 aY) return NS_OK; nsRect portRect = view->View()->GetBounds(); - view->ScrollTo(NSToCoordRound((aX/ratio)*context->PixelsToTwips() - portRect.width/2), - NSToCoordRound((aY/ratio)*context->PixelsToTwips() - portRect.height/2), + view->ScrollTo(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2, + nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2, NS_VMREFRESH_IMMEDIATE); return NS_OK; } @@ -624,10 +624,8 @@ nsImageDocument::CheckOverflowing(PRBool changeState) if (styleContext->GetStylePadding()->GetPadding(m)) visibleArea.Deflate(m); - float t2p; - t2p = context->TwipsToPixels(); - mVisibleWidth = NSTwipsToIntPixels(visibleArea.width, t2p); - mVisibleHeight = NSTwipsToIntPixels(visibleArea.height, t2p); + mVisibleWidth = nsPresContext::AppUnitsToIntCSSPixels(visibleArea.width); + mVisibleHeight = nsPresContext::AppUnitsToIntCSSPixels(visibleArea.height); PRBool imageWasOverflowing = mImageIsOverflowing; mImageIsOverflowing = diff --git a/content/svg/content/src/nsSVGSVGElement.cpp b/content/svg/content/src/nsSVGSVGElement.cpp index aa8dbe1dc07..ad0dc60cf7a 100644 --- a/content/svg/content/src/nsSVGSVGElement.cpp +++ b/content/svg/content/src/nsSVGSVGElement.cpp @@ -282,7 +282,7 @@ nsSVGSVGElement::GetPixelUnitToMillimeterX(float *aPixelUnitToMillimeterX) nsPresContext *context = presShell->GetPresContext(); if (!context) return NS_OK; - *aPixelUnitToMillimeterX = context->ScaledPixelsToTwips() / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); + *aPixelUnitToMillimeterX = 25.4f / nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch()); return NS_OK; } @@ -312,9 +312,7 @@ nsSVGSVGElement::GetScreenPixelToMillimeterX(float *aScreenPixelToMillimeterX) nsPresContext *context = presShell->GetPresContext(); if (!context) return NS_OK; - float TwipsPerPx; - TwipsPerPx = context->PixelsToTwips(); - *aScreenPixelToMillimeterX = TwipsPerPx / TWIPS_PER_POINT_FLOAT / (72.0f * 0.03937f); + *aScreenPixelToMillimeterX = 25.4f / context->AppUnitsToDevPixels(context->AppUnitsPerInch()); return NS_OK; } @@ -1296,8 +1294,8 @@ void nsSVGSVGElement::GetOffsetToAncestor(nsIContent* ancestor, if (frame && ancestorFrame) { nsPoint point = frame->GetOffsetTo(ancestorFrame); - x = point.x * context->TwipsToPixels(); - y = point.y * context->TwipsToPixels(); + x = nsPresContext::AppUnitsToFloatCSSPixels(point.x); + y = nsPresContext::AppUnitsToFloatCSSPixels(point.y); } } diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 098d6392f23..9e086781cbd 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1352,11 +1352,8 @@ nsXULDocument::GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth, size = frame->GetSize(); } - // Convert from twips to pixels - float scale = aShell->GetPresContext()->TwipsToPixels(); - - *aWidth = NSTwipsToIntPixels(size.width, scale); - *aHeight = NSTwipsToIntPixels(size.height, scale); + *aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width); + *aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height); } else { *aWidth = 0; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 1fdb7e5cc89..be48cd2849e 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4838,12 +4838,6 @@ nsDocShell::EnsureDeviceContext() NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); mDeviceContext->Init(widget->GetNativeData(NS_NATIVE_WIDGET)); - float dev2twip; - dev2twip = mDeviceContext->DevUnitsToTwips(); - mDeviceContext->SetDevUnitsToAppUnits(dev2twip); - float twip2dev; - twip2dev = mDeviceContext->TwipsToDevUnits(); - mDeviceContext->SetAppUnitsToDevUnits(twip2dev); return NS_OK; } diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 2d528047dd9..87a3ce8a763 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -3070,10 +3070,9 @@ nsGlobalWindow::GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY) nsresult rv; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; FlushPendingNotifications(Flush_Layout); - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (!view) return NS_OK; // bug 230965 changed from NS_ERROR_FAILURE @@ -3085,10 +3084,10 @@ nsGlobalWindow::GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY) if (aScrollMaxX) *aScrollMaxX = PR_MAX(0, - (PRInt32)floor(t2p*(scrolledSize.width - portRect.width))); + (PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrolledSize.width - portRect.width))); if (aScrollMaxY) *aScrollMaxY = PR_MAX(0, - (PRInt32)floor(t2p*(scrolledSize.height - portRect.height))); + (PRInt32)floor(nsPresContext::AppUnitsToFloatCSSPixels(scrolledSize.height - portRect.height))); return NS_OK; } @@ -3118,7 +3117,6 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY, nsresult rv; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; if (aDoFlush) { FlushPendingNotifications(Flush_Layout); @@ -3126,7 +3124,7 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY, EnsureSizeUpToDate(); } - GetScrollInfo(&view, &p2t, &t2p); + GetScrollInfo(&view); if (!view) return NS_OK; // bug 202206 changed from NS_ERROR_FAILURE @@ -3142,9 +3140,9 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY, } if (aScrollX) - *aScrollX = NSTwipsToIntPixels(xPos, t2p); + *aScrollX = nsPresContext::AppUnitsToIntCSSPixels(xPos); if (aScrollY) - *aScrollY = NSTwipsToIntPixels(yPos, t2p); + *aScrollY = nsPresContext::AppUnitsToIntCSSPixels(yPos); return NS_OK; } @@ -4051,10 +4049,9 @@ nsGlobalWindow::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll) { nsresult result; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; FlushPendingNotifications(Flush_Layout); - result = GetScrollInfo(&view, &p2t, &t2p); + result = GetScrollInfo(&view); if (view) { // Here we calculate what the max pixel value is that we can @@ -4062,7 +4059,7 @@ nsGlobalWindow::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll) // twips conversion factor, and substracting 4, the 4 comes from // experimenting with this value, anything less makes the view // code not scroll correctly, I have no idea why. -- jst - const PRInt32 maxpx = (PRInt32)((float)0x7fffffff / p2t) - 4; + const PRInt32 maxpx = nsPresContext::AppUnitsToIntCSSPixels(0x7fffffff) - 4; if (aXScroll > maxpx) { aXScroll = maxpx; @@ -4072,8 +4069,8 @@ nsGlobalWindow::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll) aYScroll = maxpx; } - result = view->ScrollTo(NSIntPixelsToTwips(aXScroll, p2t), - NSIntPixelsToTwips(aYScroll, p2t), + result = view->ScrollTo(nsPresContext::CSSPixelsToAppUnits(aXScroll), + nsPresContext::CSSPixelsToAppUnits(aYScroll), NS_VMREFRESH_IMMEDIATE); } @@ -4085,17 +4082,16 @@ nsGlobalWindow::ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif) { nsresult result; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; FlushPendingNotifications(Flush_Layout); - result = GetScrollInfo(&view, &p2t, &t2p); + result = GetScrollInfo(&view); if (view) { nscoord xPos, yPos; result = view->GetScrollPosition(xPos, yPos); if (NS_SUCCEEDED(result)) { - result = ScrollTo(NSTwipsToIntPixels(xPos, t2p) + aXScrollDif, - NSTwipsToIntPixels(yPos, t2p) + aYScrollDif); + result = ScrollTo(nsPresContext::AppUnitsToIntCSSPixels(xPos) + aXScrollDif, + nsPresContext::AppUnitsToIntCSSPixels(yPos) + aYScrollDif); } } @@ -4107,10 +4103,9 @@ nsGlobalWindow::ScrollByLines(PRInt32 numLines) { nsresult result; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; FlushPendingNotifications(Flush_Layout); - result = GetScrollInfo(&view, &p2t, &t2p); + result = GetScrollInfo(&view); if (view) { result = view->ScrollByLines(0, numLines); } @@ -4123,10 +4118,9 @@ nsGlobalWindow::ScrollByPages(PRInt32 numPages) { nsresult result; nsIScrollableView *view = nsnull; // no addref/release for views - float p2t, t2p; FlushPendingNotifications(Flush_Layout); - result = GetScrollInfo(&view, &p2t, &t2p); + result = GetScrollInfo(&view); if (view) { result = view->ScrollByPages(0, numPages); } @@ -7128,15 +7122,12 @@ nsGlobalWindow::GetWebBrowserChrome(nsIWebBrowserChrome **aBrowserChrome) } nsresult -nsGlobalWindow::GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T, - float *aT2P) +nsGlobalWindow::GetScrollInfo(nsIScrollableView **aScrollableView) { - FORWARD_TO_OUTER(GetScrollInfo, (aScrollableView, aP2T, aT2P), + FORWARD_TO_OUTER(GetScrollInfo, (aScrollableView), NS_ERROR_NOT_INITIALIZED); *aScrollableView = nsnull; - *aP2T = 0.0f; - *aT2P = 0.0f; if (!mDocShell) { return NS_OK; @@ -7145,9 +7136,6 @@ nsGlobalWindow::GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T, nsCOMPtr presContext; mDocShell->GetPresContext(getter_AddRefs(presContext)); if (presContext) { - *aP2T = presContext->PixelsToTwips(); - *aT2P = presContext->TwipsToPixels(); - nsIViewManager* vm = presContext->GetViewManager(); if (vm) return vm->GetRootScrollableView(aScrollableView); diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 66aa601a546..9fde02452b1 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -515,8 +515,7 @@ protected: nsresult GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome); // GetScrollInfo does not flush. Callers should do it themselves as needed, // depending on which info they actually want off the scrollable view. - nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, - float* aT2P); + nsresult GetScrollInfo(nsIScrollableView** aScrollableView); nsresult SecurityCheckURL(const char *aURL); nsresult BuildURIfromBase(const char *aURL, nsIURI **aBuiltURI, diff --git a/dom/src/base/nsScreen.cpp b/dom/src/base/nsScreen.cpp index 9bee23bb47f..bcb2db257d3 100644 --- a/dom/src/base/nsScreen.cpp +++ b/dom/src/base/nsScreen.cpp @@ -241,16 +241,10 @@ nsScreen::GetRect(nsRect& aRect) context->GetRect(aRect); - float devUnits; - devUnits = context->DevUnitsToAppUnits(); - - aRect.x = NSToIntRound(float(aRect.x) / devUnits); - aRect.y = NSToIntRound(float(aRect.y) / devUnits); - - context->GetDeviceSurfaceDimensions(aRect.width, aRect.height); - - aRect.height = NSToIntRound(float(aRect.height) / devUnits); - aRect.width = NSToIntRound(float(aRect.width) / devUnits); + aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x); + aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y); + aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height); + aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width); return NS_OK; } @@ -266,13 +260,10 @@ nsScreen::GetAvailRect(nsRect& aRect) context->GetClientRect(aRect); - float devUnits; - devUnits = context->DevUnitsToAppUnits(); - - aRect.x = NSToIntRound(float(aRect.x) / devUnits); - aRect.y = NSToIntRound(float(aRect.y) / devUnits); - aRect.height = NSToIntRound(float(aRect.height) / devUnits); - aRect.width = NSToIntRound(float(aRect.width) / devUnits); + aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x); + aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y); + aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height); + aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width); return NS_OK; } diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index bec4ab1ed18..c182ddbe63e 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -5711,8 +5711,6 @@ nsHTMLEditor::GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & nsCOMPtr content = do_QueryInterface(aElement); nsIFrame *frame = ps->GetPrimaryFrameFor(content); // not ref-counted - float t2p = ps->GetPresContext()->TwipsToPixels(); - if (nsHTMLEditUtils::IsHR(aElement) && frame) { frame = frame->GetNextSibling(); } @@ -5731,8 +5729,8 @@ nsHTMLEditor::GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & frame = frame->GetParent(); } - aX = NSTwipsToIntPixels(offsetX , t2p); - aY = NSTwipsToIntPixels(offsetY , t2p); + aX = nsPresContext::AppUnitsToIntCSSPixels(offsetX); + aY = nsPresContext::AppUnitsToIntCSSPixels(offsetY); return NS_OK; } diff --git a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp index 8e5064c9ac6..af85882d0ad 100644 --- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp +++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp @@ -471,10 +471,8 @@ nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, nsRect shellArea = presContext->GetVisibleArea(); - float pixelScale; - pixelScale = presContext->TwipsToPixels(); - PRInt32 browserCX = PRInt32((float)shellArea.width*pixelScale); - PRInt32 browserCY = PRInt32((float)shellArea.height*pixelScale); + PRInt32 browserCX = presContext->AppUnitsToDevPixels(shellArea.width); + PRInt32 browserCY = presContext->AppUnitsToDevPixels(shellArea.height); return webBrowserChrome->SizeBrowserTo(browserCX, browserCY); } diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 988773faaa6..994ee2d0c7c 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -2594,6 +2594,7 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell, // Set up the variables we need, return true if we can't get at them all const PRUint16 kMinPixels = 12; + PRUint16 minPixels = PRUint16(nsPresContext::CSSPixelsToAppUnits(kMinPixels)); nsIViewManager* viewManager = aPresShell->GetViewManager(); if (!viewManager) { @@ -2606,8 +2607,6 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell, // for only needs to be a rough indicator nsIView *containingView = nsnull; nsPoint frameOffset; - float p2t; - p2t = aPresContext->PixelsToTwips(); nsRectVisibility rectVisibility = nsRectVisibility_kAboveViewport; if (!aGetTopVisibleLeaf) { @@ -2623,7 +2622,7 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell, relFrameRect.y = frameOffset.y; viewManager->GetRectVisibility(containingView, relFrameRect, - NS_STATIC_CAST(PRUint16, (kMinPixels * p2t)), + minPixels, &rectVisibility); if (rectVisibility != nsRectVisibility_kAboveViewport && @@ -2667,9 +2666,7 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell, relFrameRect.x = frameOffset.x; relFrameRect.y = frameOffset.y; viewManager->GetRectVisibility(containingView, relFrameRect, - NS_STATIC_CAST(PRUint16, - (kMinPixels * p2t)), - &rectVisibility); + minPixels, &rectVisibility); } } diff --git a/gfx/public/nsDeviceContext.h b/gfx/public/nsDeviceContext.h index c0a68427194..eef220ccd3f 100644 --- a/gfx/public/nsDeviceContext.h +++ b/gfx/public/nsDeviceContext.h @@ -100,9 +100,6 @@ public: NS_IMETHOD CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext); NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext); - NS_IMETHOD GetCanonicalPixelScale(float &aScale) const; - NS_IMETHOD SetCanonicalPixelScale(float aScale); - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics*& aMetrics); NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); @@ -152,7 +149,6 @@ protected: nsFontCache *mFontCache; nsCOMPtr mLocaleLangGroup; // XXX temp fix for performance bug - erik nsHashtable* mFontAliasTable; - float mCPixelScale; #ifdef NS_PRINT_PREVIEW nsCOMPtr mAltDC; diff --git a/gfx/public/nsIDeviceContext.h b/gfx/public/nsIDeviceContext.h index a6098b2e3b9..74b3391ecd3 100644 --- a/gfx/public/nsIDeviceContext.h +++ b/gfx/public/nsIDeviceContext.h @@ -282,84 +282,22 @@ public: NS_IMETHOD PrepareNativeWidget(nsIWidget* aWidget, void** aOut) = 0; /** - * Obtain the size of a device unit relative to a Twip. A twip is 1/20 of - * a point (which is 1/72 of an inch). - * @return conversion value + * Gets the number of app units in one CSS pixel; this number is global, + * not unique to each device context. */ - float DevUnitsToTwips() const { return mPixelsToTwips; } + static PRInt32 AppUnitsPerCSSPixel() { return 60; } /** - * Obtain the size of a Twip relative to a device unit. - * @return conversion value + * Gets the number of app units in one device pixel; this number is usually + * a factor of AppUnitsPerCSSPixel(), although that is not guaranteed. */ - float TwipsToDevUnits() const { return mTwipsToPixels; } + PRInt32 AppUnitsPerDevPixel() const { return mAppUnitsPerDevPixel; } /** - * Set the scale factor to convert units used by the application - * to device units. Typically, an application will query the device - * for twips to device units scale and then set the scale - * to convert from whatever unit the application wants to use - * to device units. From that point on, all other parts of the - * app can use the Get* methods below to figure out how - * to convert device units <-> app units. - * @param aAppUnits scale value to convert from application defined - * units to device units. + * Gets the number of app units in one inch; this is the device's DPI + * times AppUnitsPerDevPixel(). */ - void SetAppUnitsToDevUnits(float aAppUnits) - { - mAppUnitsToDevUnits = aAppUnits; - } - - /** - * Set the scale factor to convert device units to units - * used by the application. This should generally be - * 1.0f / the value passed into SetAppUnitsToDevUnits(). - * @param aDevUnits scale value to convert from device units to - * application defined units - */ - void SetDevUnitsToAppUnits(float aDevUnits) - { - mDevUnitsToAppUnits = aDevUnits; - } - - /** - * Get the scale factor to convert from application defined - * units to device units. - * @param aAppUnits scale value - */ - float AppUnitsToDevUnits() const { return mAppUnitsToDevUnits; } - - /** - * Get the scale factor to convert from device units to - * application defined units. - * @param aDevUnits out paramater for scale value - * @return error status - */ - float DevUnitsToAppUnits() const { return mDevUnitsToAppUnits; } - - /** - * Get the value used to scale a "standard" pixel to a pixel - * of the same physical size for this device. a standard pixel - * is defined as a pixel on display 0. this is used to make - * sure that entities defined in pixel dimensions maintain a - * constant relative size when displayed from one output - * device to another. - * @param aScale out parameter for scale value - * @return error status - */ - NS_IMETHOD GetCanonicalPixelScale(float &aScale) const = 0; - - /** - * Get the value used to scale a "standard" pixel to a pixel - * of the same physical size for this device. a standard pixel - * is defined as a pixel on display 0. this is used to make - * sure that entities defined in pixel dimensions maintain a - * constant relative size when displayed from one output - * device to another. - * @param aScale in parameter for scale value - * @return error status - */ - NS_IMETHOD SetCanonicalPixelScale(float aScale) = 0; + PRInt32 AppUnitsPerInch() const { return mAppUnitsPerInch; } /** * Fill in an nsFont based on the ID of a system font. This function @@ -433,7 +371,7 @@ public: * @param aHeight out parameter for height * @return error status */ - NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) = 0; + NS_IMETHOD GetDeviceSurfaceDimensions(nscoord &aWidth, nscoord &aHeight) = 0; /** * Get the size of the content area of the output device in app units. @@ -560,10 +498,8 @@ public: NS_IMETHOD ClearCachedSystemFonts() = 0; protected: - float mTwipsToPixels; - float mPixelsToTwips; - float mAppUnitsToDevUnits; - float mDevUnitsToAppUnits; + PRInt32 mAppUnitsPerDevPixel; + PRInt32 mAppUnitsPerInch; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContext, NS_IDEVICE_CONTEXT_IID) diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index e4310e094ee..86f58dcf5b3 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -55,13 +55,9 @@ NS_IMPL_ISUPPORTS3(DeviceContextImpl, nsIDeviceContext, nsIObserver, nsISupports DeviceContextImpl::DeviceContextImpl() { - - mDevUnitsToAppUnits = 1.0f; - mAppUnitsToDevUnits = 1.0f; - mTwipsToPixels = 1.0f; - mPixelsToTwips = 1.0f; + mAppUnitsPerDevPixel = -1; + mAppUnitsPerInch = -1; mFontCache = nsnull; - mCPixelScale = 1.0f; mWidget = nsnull; mFontAliasTable = nsnull; @@ -130,18 +126,6 @@ void DeviceContextImpl::CommonInit(void) obs->AddObserver(this, "memory-pressure", PR_TRUE); } -NS_IMETHODIMP DeviceContextImpl::GetCanonicalPixelScale(float &aScale) const -{ - aScale = mCPixelScale; - return NS_OK; -} - -NS_IMETHODIMP DeviceContextImpl::SetCanonicalPixelScale(float aScale) -{ - mCPixelScale = aScale; - return NS_OK; -} - NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) { #ifdef NS_PRINT_PREVIEW diff --git a/gfx/src/nsRect.cpp b/gfx/src/nsRect.cpp index 4065451c657..7eef03bbe1b 100644 --- a/gfx/src/nsRect.cpp +++ b/gfx/src/nsRect.cpp @@ -38,6 +38,7 @@ #include "nsRect.h" #include "nsString.h" #include "nsUnitConversion.h" +#include "nsIDeviceContext.h" #ifdef MIN #undef MIN @@ -210,15 +211,19 @@ FILE* operator<<(FILE* out, const nsRect& rect) { nsAutoString tmp; - // Output the coordinates in fractional points so they're easier to read + // Output the coordinates in fractional pixels so they're easier to read tmp.AppendLiteral("{"); - tmp.AppendFloat(NSTwipsToFloatPoints(rect.x)); + tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.x, + nsIDeviceContext::AppUnitsPerCSSPixel())); tmp.AppendLiteral(", "); - tmp.AppendFloat(NSTwipsToFloatPoints(rect.y)); + tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.y, + nsIDeviceContext::AppUnitsPerCSSPixel())); tmp.AppendLiteral(", "); - tmp.AppendFloat(NSTwipsToFloatPoints(rect.width)); + tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.width, + nsIDeviceContext::AppUnitsPerCSSPixel())); tmp.AppendLiteral(", "); - tmp.AppendFloat(NSTwipsToFloatPoints(rect.height)); + tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.height, + nsIDeviceContext::AppUnitsPerCSSPixel())); tmp.AppendLiteral("}"); fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); return out; diff --git a/gfx/src/shared/nsRenderingContextImpl.cpp b/gfx/src/shared/nsRenderingContextImpl.cpp index d56f51b7215..04a3576c145 100644 --- a/gfx/src/shared/nsRenderingContextImpl.cpp +++ b/gfx/src/shared/nsRenderingContextImpl.cpp @@ -115,12 +115,10 @@ nsresult nsRenderingContextImpl::AllocateBackbuffer(const nsRect &aRequestedSize } else { SelectOffScreenDrawingSurface(gBackbuffer); - float p2t; nsCOMPtr dx; GetDeviceContext(*getter_AddRefs(dx)); - p2t = dx->DevUnitsToAppUnits(); nsRect bounds = aRequestedSize; - bounds *= p2t; + bounds *= dx->AppUnitsPerDevPixel(); SetClipRect(bounds, nsClipCombine_kReplace); } @@ -229,17 +227,16 @@ void nsRenderingContextImpl::GetDrawingSurfaceSize(const nsRect& aMaxBackbufferS void nsRenderingContextImpl::CalculateDiscreteSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSurfaceSize) { // Get the height and width of the screen - PRInt32 height; - PRInt32 width; + nscoord height; + nscoord width; nsCOMPtr dx; GetDeviceContext(*getter_AddRefs(dx)); dx->GetDeviceSurfaceDimensions(width, height); - float devUnits; - devUnits = dx->DevUnitsToAppUnits(); - PRInt32 screenHeight = NSToIntRound(float( height) / devUnits ); - PRInt32 screenWidth = NSToIntRound(float( width) / devUnits ); + PRInt32 p2a = dx->AppUnitsPerDevPixel(); + PRInt32 screenHeight = NSAppUnitsToIntPixels(height, p2a); + PRInt32 screenWidth = NSAppUnitsToIntPixels(width, p2a); // These tests must go from smallest rectangle to largest rectangle. diff --git a/gfx/src/thebes/nsThebesDeviceContext.cpp b/gfx/src/thebes/nsThebesDeviceContext.cpp index 90cd5718d10..bf9623cd8df 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -141,14 +141,11 @@ nsThebesDeviceContext::~nsThebesDeviceContext() nsresult nsThebesDeviceContext::SetDPI(PRInt32 aPrefDPI) { - PRInt32 OSVal; - PRBool do_round = PR_TRUE; // XXX bogus -- only caller for which it's false is a round number - PRInt32 dpi = 96; #if defined(MOZ_ENABLE_GTK2) float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f; - OSVal = NSToCoordRound(float(::gdk_screen_width()) / screenWidthIn); + PRInt32 OSVal = NSToCoordRound(float(::gdk_screen_width()) / screenWidthIn); if (aPrefDPI > 0) { // If there's a valid pref value for the logical resolution, @@ -169,16 +166,13 @@ nsThebesDeviceContext::SetDPI(PRInt32 aPrefDPI) // notion of DPI so we have to use 72... // XXX is this an issue? we force everything else to be 96+ dpi = 72; - do_round = PR_FALSE; } #elif defined(XP_WIN) // XXX we should really look at the widget for printing and such, but this widget is currently always null... HDC dc = GetHDC() ? GetHDC() : GetDC((HWND)nsnull); - OSVal = GetDeviceCaps(dc, LOGPIXELSY); - if (GetDeviceCaps(dc, TECHNOLOGY) != DT_RASDISPLAY) - do_round = PR_FALSE; + PRInt32 OSVal = GetDeviceCaps(dc, LOGPIXELSY); if (dc != GetHDC()) ReleaseDC((HWND)nsnull, dc); @@ -190,18 +184,15 @@ nsThebesDeviceContext::SetDPI(PRInt32 aPrefDPI) if (mPrinter) { dpi = 72; - do_round = PR_FALSE; } #endif - int in2pt = 72; + if (aPrefDPI > 0 && !mPrinter) + dpi = aPrefDPI; - // make p2t a nice round number - this prevents rounding problems - mPixelsToTwips = float(NSIntPointsToTwips(in2pt)) / float(dpi); - if (do_round) - mPixelsToTwips = float(NSToIntRound(mPixelsToTwips)); - mTwipsToPixels = 1.0f / mPixelsToTwips; + mAppUnitsPerDevPixel = AppUnitsPerCSSPixel() / PR_MAX(1, (dpi + 48) / 96); + mAppUnitsPerInch = NSIntPixelsToAppUnits(dpi, mAppUnitsPerDevPixel); return NS_OK; } @@ -391,7 +382,7 @@ nsThebesDeviceContext::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const aFont->familyNameQuirks = fontStyle.familyNameQuirks; aFont->weight = fontStyle.weight; aFont->decorations = fontStyle.decorations; - aFont->size = NSToCoordRound(fontStyle.size * mPixelsToTwips); + aFont->size = NSFloatPixelsToAppUnits(fontStyle.size, AppUnitsPerDevPixel()); //aFont->langGroup = fontStyle.langGroup; aFont->sizeAdjust = fontStyle.sizeAdjust; @@ -430,7 +421,7 @@ nsThebesDeviceContext::ConvertPixel(nscolor aColor, PRUint32 & aPixel) } NS_IMETHODIMP -nsThebesDeviceContext::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) +nsThebesDeviceContext::GetDeviceSurfaceDimensions(nscoord &aWidth, nscoord &aHeight) { if (mPrinter) { // we have a printer device @@ -512,17 +503,6 @@ nsThebesDeviceContext::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, newDevCon->Init(nsnull); - float newscale = newDevCon->TwipsToDevUnits(); - float origscale = this->TwipsToDevUnits(); - - newDevCon->SetCanonicalPixelScale(newscale / origscale); - - float t2d = this->TwipsToDevUnits(); - float a2d = this->AppUnitsToDevUnits(); - - newDevCon->SetAppUnitsToDevUnits((a2d / t2d) * newDevCon->mTwipsToPixels); - newDevCon->SetDevUnitsToAppUnits(1.0f / newDevCon->mAppUnitsToDevUnits); - newDevCon->CalcPrintingSize(); return NS_OK; @@ -668,10 +648,10 @@ nsThebesDeviceContext::ComputeClientRectUsingScreen(nsRect* outRect) screen->GetAvailRect(&x, &y, &width, &height); // convert to device units - outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); - outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); - outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); - outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); + outRect->y = NSIntPixelsToAppUnits(y, AppUnitsPerDevPixel()); + outRect->x = NSIntPixelsToAppUnits(x, AppUnitsPerDevPixel()); + outRect->width = NSIntPixelsToAppUnits(width, AppUnitsPerDevPixel()); + outRect->height = NSIntPixelsToAppUnits(height, AppUnitsPerDevPixel()); } } @@ -689,10 +669,10 @@ nsThebesDeviceContext::ComputeFullAreaUsingScreen(nsRect* outRect) screen->GetRect ( &x, &y, &width, &height ); // convert to device units - outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); - outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); - outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); - outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); + outRect->y = NSIntPixelsToAppUnits(y, AppUnitsPerDevPixel()); + outRect->x = NSIntPixelsToAppUnits(x, AppUnitsPerDevPixel()); + outRect->width = NSIntPixelsToAppUnits(width, AppUnitsPerDevPixel()); + outRect->height = NSIntPixelsToAppUnits(height, AppUnitsPerDevPixel()); mWidth = outRect->width; mHeight = outRect->height; @@ -753,8 +733,8 @@ nsThebesDeviceContext::CalcPrintingSize() { inPoints = PR_FALSE; HDC dc = GetHDC() ? GetHDC() : GetDC((HWND)mWidget); - size.width = NSToIntRound(::GetDeviceCaps(dc, HORZRES) * mDevUnitsToAppUnits); - size.height = NSToIntRound(::GetDeviceCaps(dc, VERTRES) * mDevUnitsToAppUnits); + size.width = NSIntPixelsToAppUnits(::GetDeviceCaps(dc, HORZRES), AppUnitsPerDevPixel()); + size.height = NSIntPixelsToAppUnits(::GetDeviceCaps(dc, VERTRES), AppUnitsPerDevPixel()); mDepth = (PRUint32)::GetDeviceCaps(dc, BITSPIXEL); if (dc != (HDC)GetHDC()) ReleaseDC((HWND)mWidget, dc); @@ -766,8 +746,8 @@ nsThebesDeviceContext::CalcPrintingSize() } if (inPoints) { - mWidth = NSFloatPointsToTwips(size.width); - mHeight = NSFloatPointsToTwips(size.height); + mWidth = float(size.width) * AppUnitsPerInch() / 72; + mHeight = float(size.height) * AppUnitsPerInch() / 72; printf("%f %f\n", size.width, size.height); printf("%d %d\n", (PRInt32)mWidth, (PRInt32)mHeight); } else { diff --git a/gfx/src/thebes/nsThebesFontMetrics.cpp b/gfx/src/thebes/nsThebesFontMetrics.cpp index 36cd3b21a92..0427045828a 100644 --- a/gfx/src/thebes/nsThebesFontMetrics.cpp +++ b/gfx/src/thebes/nsThebesFontMetrics.cpp @@ -77,12 +77,12 @@ nsThebesFontMetrics::Init(const nsFont& aFont, nsIAtom* aLangGroup, mFont = aFont; mLangGroup = aLangGroup; mDeviceContext = (nsThebesDeviceContext*)aContext; - mDev2App = aContext->DevUnitsToAppUnits(); + mP2A = mDeviceContext->AppUnitsPerDevPixel(); mIsRightToLeft = PR_FALSE; mTextRunRTL = PR_FALSE; // work around layout giving us 0 sized fonts... - double size = aFont.size * mDeviceContext->AppUnitsToDevUnits(); + double size = NSAppUnitsToFloatPixels(aFont.size, mP2A); if (size == 0.0) size = 1.0; @@ -119,7 +119,8 @@ nsThebesFontMetrics::Destroy() return NS_OK; } -#define ROUND_TO_TWIPS(x) (nscoord)floor(((x) * mDev2App) + 0.5) +// XXXTODO get rid of this macro +#define ROUND_TO_TWIPS(x) (nscoord)floor(((x) * mP2A) + 0.5) const gfxFont::Metrics& nsThebesFontMetrics::GetMetrics() const { diff --git a/gfx/src/thebes/nsThebesFontMetrics.h b/gfx/src/thebes/nsThebesFontMetrics.h index bb2ef39068f..b49607c1306 100644 --- a/gfx/src/thebes/nsThebesFontMetrics.h +++ b/gfx/src/thebes/nsThebesFontMetrics.h @@ -165,14 +165,14 @@ protected: const char* aString, PRInt32 aLength, PRBool aEnableSpacing) { mTextRun = gfxTextRunCache::GetCache()->GetOrMakeTextRun( NS_STATIC_CAST(gfxContext*, aRC->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT)), - aMetrics->mFontGroup, aString, aLength, aMetrics->mDev2App, + aMetrics->mFontGroup, aString, aLength, aMetrics->mP2A, aMetrics->GetRightToLeftTextRunMode(), aEnableSpacing, &mOwning); } AutoTextRun(nsThebesFontMetrics* aMetrics, nsIRenderingContext* aRC, const PRUnichar* aString, PRInt32 aLength, PRBool aEnableSpacing) { mTextRun = gfxTextRunCache::GetCache()->GetOrMakeTextRun( NS_STATIC_CAST(gfxContext*, aRC->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT)), - aMetrics->mFontGroup, aString, aLength, aMetrics->mDev2App, + aMetrics->mFontGroup, aString, aLength, aMetrics->mP2A, aMetrics->GetRightToLeftTextRunMode(), aEnableSpacing, &mOwning); } ~AutoTextRun() { @@ -194,7 +194,7 @@ protected: private: nsThebesDeviceContext *mDeviceContext; nsCOMPtr mLangGroup; - float mDev2App; + PRInt32 mP2A; PRPackedBool mIsRightToLeft; PRPackedBool mTextRunRTL; }; diff --git a/gfx/src/thebes/nsThebesImage.cpp b/gfx/src/thebes/nsThebesImage.cpp index 2699815550d..bf1ffeac37d 100644 --- a/gfx/src/thebes/nsThebesImage.cpp +++ b/gfx/src/thebes/nsThebesImage.cpp @@ -415,6 +415,7 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, nsresult nsThebesImage::ThebesDrawTile(gfxContext *thebesContext, + nsIDeviceContext* dx, const gfxPoint& offset, const gfxRect& targetRect, const PRInt32 xPadding, @@ -494,7 +495,12 @@ nsThebesImage::ThebesDrawTile(gfxContext *thebesContext, p0.x = - floor(offset.x + 0.5); p0.y = - floor(offset.y + 0.5); } - + // Scale factor to account for CSS pixels; note that the offset (and + // therefore p0) is in device pixels, while the width and height are in + // CSS pixels. + gfxFloat scale = gfxFloat(nsIDeviceContext::AppUnitsPerCSSPixel()) / + gfxFloat(dx->AppUnitsPerDevPixel()); + patMat.Scale(1.0 / scale, 1.0 / scale); patMat.Translate(p0); pat = new gfxPattern(surface); diff --git a/gfx/src/thebes/nsThebesImage.h b/gfx/src/thebes/nsThebesImage.h index 848fec1a1bc..2c1798a0bf2 100644 --- a/gfx/src/thebes/nsThebesImage.h +++ b/gfx/src/thebes/nsThebesImage.h @@ -88,6 +88,7 @@ public: PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); nsresult ThebesDrawTile(gfxContext *thebesContext, + nsIDeviceContext* dx, const gfxPoint& aOffset, const gfxRect& aTileRect, const PRInt32 aXPadding, diff --git a/gfx/src/thebes/nsThebesRenderingContext.cpp b/gfx/src/thebes/nsThebesRenderingContext.cpp index fc72ebb984e..e14e9865902 100644 --- a/gfx/src/thebes/nsThebesRenderingContext.cpp +++ b/gfx/src/thebes/nsThebesRenderingContext.cpp @@ -72,9 +72,10 @@ static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); ////////////////////////////////////////////////////////////////////// -#define FROM_TWIPS(_x) ((gfxFloat)((_x)/(mP2T))) -#define FROM_TWIPS_INT(_x) (NSToIntRound((gfxFloat)((_x)/(mP2T)))) -#define TO_TWIPS(_x) ((nscoord)((_x)*(mP2T))) +// XXXTodo: rename FORM_TWIPS to FROM_APPUNITS +#define FROM_TWIPS(_x) ((gfxFloat)((_x)/(mP2A))) +#define FROM_TWIPS_INT(_x) (NSToIntRound((gfxFloat)((_x)/(mP2A)))) +#define TO_TWIPS(_x) ((nscoord)((_x)*(mP2A))) #define GFX_RECT_FROM_TWIPS_RECT(_r) (gfxRect(FROM_TWIPS((_r).x), FROM_TWIPS((_r).y), FROM_TWIPS((_r).width), FROM_TWIPS((_r).height))) ////////////////////////////////////////////////////////////////////// @@ -173,8 +174,7 @@ nsThebesRenderingContext::CommonInit(void) mThebes->SetLineWidth(1.0); - mT2P = mDeviceContext->AppUnitsToDevUnits(); - mP2T = mDeviceContext->DevUnitsToAppUnits(); + mP2A = mDeviceContext->AppUnitsPerDevPixel(); return NS_OK; } @@ -673,7 +673,7 @@ nsThebesRenderingContext::FillRect(const nsRect& aRect) gfxRect r(GFX_RECT_FROM_TWIPS_RECT(aRect)); /* Clamp coordinates to work around a design bug in cairo */ - nscoord bigval = (nscoord)(CAIRO_COORD_MAX*mP2T); + nscoord bigval = (nscoord)(CAIRO_COORD_MAX*mP2A); if (aRect.width > bigval || aRect.height > bigval || aRect.x < -bigval || @@ -993,11 +993,11 @@ nsThebesRenderingContext::DrawImage(imgIContainer *aImage, // twSrcRect is always in appunits (twips), // and has nothing to do with the current transform (it's a region // of the image) - nsIntRect pxSr; - pxSr.x = NSToIntRound(FROM_TWIPS(twSrcRect.x)); - pxSr.y = NSToIntRound(FROM_TWIPS(twSrcRect.y)); - pxSr.width = NSToIntRound(FROM_TWIPS(twSrcRect.width)); - pxSr.height = NSToIntRound(FROM_TWIPS(twSrcRect.height)); + double p2a = nsIDeviceContext::AppUnitsPerCSSPixel(); + nsIntRect pxSr(NSAppUnitsToIntPixels(twSrcRect.x, p2a), + NSAppUnitsToIntPixels(twSrcRect.y, p2a), + NSAppUnitsToIntPixels(twSrcRect.width, p2a), + NSAppUnitsToIntPixels(twSrcRect.height, p2a)); // the dest rect is affected by the current transform; that'll be // handled by Image::Draw(), when we actually set up the rectangle. @@ -1112,7 +1112,7 @@ nsThebesRenderingContext::DrawTile(imgIContainer *aImage, phase.y -= imgFrameRect.y; } - return thebesImage->ThebesDrawTile (mThebes, phase, + return thebesImage->ThebesDrawTile (mThebes, mDeviceContext, phase, GFX_RECT_FROM_TWIPS_RECT(*twTargetRect), xPadding, yPadding); } diff --git a/gfx/src/thebes/nsThebesRenderingContext.h b/gfx/src/thebes/nsThebesRenderingContext.h index c249fd352ed..8d28ed2d659 100644 --- a/gfx/src/thebes/nsThebesRenderingContext.h +++ b/gfx/src/thebes/nsThebesRenderingContext.h @@ -274,7 +274,7 @@ public: protected: nsCOMPtr mDeviceContext; // cached pixels2twips, twips2pixels values - double mP2T, mT2P; + double mP2A; nsCOMPtr mWidget; diff --git a/gfx/thebes/public/gfxContext.h b/gfx/thebes/public/gfxContext.h index 28d461ed775..fc9b1a15c8d 100644 --- a/gfx/thebes/public/gfxContext.h +++ b/gfx/thebes/public/gfxContext.h @@ -60,6 +60,9 @@ typedef struct _cairo cairo_t; * The functions like Rectangle and Arc do not do any drawing themselves. * When a path is drawn (stroked or filled), it is filled/stroked with a * pattern set by SetPattern, SetColor or SetSource. + * + * Note that the gfxContext takes coordinates in device pixels, + * as opposed to app units. */ class THEBES_API gfxContext { THEBES_INLINE_DECL_REFCOUNTING(gfxContext) diff --git a/gfx/thebes/public/gfxFont.h b/gfx/thebes/public/gfxFont.h index fe82b65f009..68581fa5c2d 100644 --- a/gfx/thebes/public/gfxFont.h +++ b/gfx/thebes/public/gfxFont.h @@ -243,7 +243,7 @@ public: PRUint32 *mInitialBreaks; PRUint32 mInitialBreakCount; // The ratio to use to convert device pixels to application layout units - gfxFloat mPixelsToUnits; + PRUint32 mAppUnitsPerDevUnit; // Flags --- see above PRUint32 mFlags; }; @@ -703,11 +703,12 @@ public: void *GetUserData() const { return mUserData; } PRUint32 GetFlags() const { return mFlags; } const gfxSkipChars& GetSkipChars() const { return mSkipChars; } - gfxFloat GetPixelsToAppUnits() { return mPixelsToAppUnits; } + float GetAppUnitsPerDevUnit() { return mAppUnitsPerDevUnit; } protected: gfxTextRun(gfxTextRunFactory::Parameters *aParams, PRBool aIs8Bit) - : mUserData(aParams->mUserData), mPixelsToAppUnits(aParams->mPixelsToUnits), + : mUserData(aParams->mUserData), + mAppUnitsPerDevUnit(aParams->mAppUnitsPerDevUnit), mFlags(aParams->mFlags) { mSkipChars.TakeFrom(aParams->mSkipChars); @@ -718,7 +719,9 @@ protected: void * mUserData; gfxSkipChars mSkipChars; - gfxFloat mPixelsToAppUnits; + // This is actually an integer, but we keep it in float form to reduce + // the conversions required + float mAppUnitsPerDevUnit; PRUint32 mFlags; }; #endif diff --git a/gfx/thebes/public/gfxTextRunCache.h b/gfx/thebes/public/gfxTextRunCache.h index 055b9d1fad4..55e90b3addf 100644 --- a/gfx/thebes/public/gfxTextRunCache.h +++ b/gfx/thebes/public/gfxTextRunCache.h @@ -64,11 +64,13 @@ public: * the next GetOrMakeTextRun call and the caller must not delete it. */ gfxTextRun *GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGroup, - const char *aString, PRUint32 aLength, gfxFloat aDevToApp, - PRBool aIsRTL, PRBool aEnableSpacing, PRBool *aCallerOwns); + const char *aString, PRUint32 aLength, + PRUint32 aAppUnitsPerDevUnit, PRBool aIsRTL, + PRBool aEnableSpacing, PRBool *aCallerOwns); gfxTextRun *GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGroup, - const PRUnichar *aString, PRUint32 aLength, gfxFloat aDevToApp, - PRBool aIsRTL, PRBool aEnableSpacing, PRBool *aCallerOwns); + const PRUnichar *aString, PRUint32 aLength, + PRUint32 aAppUnitsPerDevUnit, PRBool aIsRTL, + PRBool aEnableSpacing, PRBool *aCallerOwns); protected: gfxTextRunCache(); diff --git a/gfx/thebes/src/gfxAtsuiFonts.cpp b/gfx/thebes/src/gfxAtsuiFonts.cpp index 53df702567c..cd86c466337 100644 --- a/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -444,11 +444,11 @@ gfxWrapperTextRun::SetupSpacingFromProvider(PropertyProvider* aProvider) nsTArray spaceArray; PRUint32 i; - gfxFloat offset = 0; + gfxFloat offset = 0; // in device pixels for (i = 0; i < mLength; ++i) { NS_ASSERTION(spacing.Elements()[i].mBefore == 0, "Can't handle before-spacing!"); - gfxFloat nextOffset = offset + spacing.Elements()[i].mAfter/mPixelsToAppUnits; + gfxFloat nextOffset = offset + spacing.Elements()[i].mAfter/mAppUnitsPerDevUnit; spaceArray.AppendElement(ROUND(nextOffset) - ROUND(offset)); offset = nextOffset; } @@ -464,7 +464,7 @@ gfxWrapperTextRun::Draw(gfxContext *aContext, gfxPoint aPt, { NS_ASSERTION(aStart == 0 && aLength == mLength, "Can't handle substrings"); SetupSpacingFromProvider(aBreakProvider); - gfxPoint pt(aPt.x/mPixelsToAppUnits, aPt.y/mPixelsToAppUnits); + gfxPoint pt(aPt.x/mAppUnitsPerDevUnit, aPt.y/mAppUnitsPerDevUnit); return mInner.Draw(mContext, pt); } @@ -474,7 +474,7 @@ gfxWrapperTextRun::GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength, { NS_ASSERTION(aStart == 0 && aLength == mLength, "Can't handle substrings"); SetupSpacingFromProvider(aBreakProvider); - return mInner.Measure(mContext)*mPixelsToAppUnits; + return mInner.Measure(mContext)*mAppUnitsPerDevUnit; } gfxTextRun * diff --git a/gfx/thebes/src/gfxPangoFonts.cpp b/gfx/thebes/src/gfxPangoFonts.cpp index cd06507571c..49f47c545f8 100644 --- a/gfx/thebes/src/gfxPangoFonts.cpp +++ b/gfx/thebes/src/gfxPangoFonts.cpp @@ -851,7 +851,7 @@ gfxPangoTextRun::ComputeLigatureData(PRUint32 aPartOffset, PropertyProvider *aPr } while (!charGlyphs[ligStart].IsClusterStart()); } result.mStartOffset = ligStart; - result.mLigatureWidth = ComputeClusterAdvance(ligStart)*mPixelsToAppUnits; + result.mLigatureWidth = ComputeClusterAdvance(ligStart)*mAppUnitsPerDevUnit; result.mPartClusterIndex = PR_UINT32_MAX; PRUint32 charIndex = ligStart; @@ -927,7 +927,7 @@ gfxPangoTextRun::GetAdjustedSpacing(PRUint32 aStart, PRUint32 aEnd, if (i > aStart) { aSpacing[i - 1 - aStart].mAfter -= clusterWidth; } - clusterWidth = glyphData->GetSimpleAdvance()*mPixelsToAppUnits; + clusterWidth = glyphData->GetSimpleAdvance()*mAppUnitsPerDevUnit; } else if (glyphData->IsComplexCluster()) { NS_ASSERTION(mDetailedGlyphs, "No details but we have a complex cluster..."); if (i > aStart) { @@ -941,7 +941,7 @@ gfxPangoTextRun::GetAdjustedSpacing(PRUint32 aStart, PRUint32 aEnd, break; ++details; } - clusterWidth *= mPixelsToAppUnits; + clusterWidth *= mAppUnitsPerDevUnit; } } aSpacing[aEnd - 1 - aStart].mAfter -= clusterWidth; @@ -969,7 +969,7 @@ gfxPangoTextRun::ProcessCairoGlyphsWithSpacing(CairoGlyphProcessorCallback aCB, if (aStart >= aEnd) return; - double appUnitsToPixels = 1/mPixelsToAppUnits; + double appUnitsToPixels = 1/mAppUnitsPerDevUnit; CompressedGlyph *charGlyphs = mCharacterGlyphs; double direction = GetDirection(); @@ -1127,7 +1127,7 @@ gfxPangoTextRun::DrawPartialLigature(gfxContext *aCtx, PRUint32 aOffset, if (!mCharacterGlyphs[aOffset].IsClusterStart() || !aDirtyRect) return; - gfxFloat appUnitsToPixels = 1.0/mPixelsToAppUnits; + gfxFloat appUnitsToPixels = 1.0/mAppUnitsPerDevUnit; // Draw partial ligature. We hack this by clipping the ligature. LigatureData data = ComputeLigatureData(aOffset, aProvider); @@ -1149,7 +1149,7 @@ gfxPangoTextRun::DrawPartialLigature(gfxContext *aCtx, PRUint32 aOffset, left = PR_MAX(left, aPt->x); } widthBeforeCluster = clusterWidth*data.mPartClusterIndex + - data.mBeforeSpacing/mPixelsToAppUnits; + data.mBeforeSpacing*appUnitsToPixels; } else { // We're drawing the start of the ligature, so our cluster includes any // before-spacing. @@ -1165,7 +1165,7 @@ gfxPangoTextRun::DrawPartialLigature(gfxContext *aCtx, PRUint32 aOffset, } afterSpace = 0; } else { - afterSpace = data.mAfterSpacing/mPixelsToAppUnits; + afterSpace = data.mAfterSpacing*appUnitsToPixels; } aCtx->Save(); @@ -1186,7 +1186,7 @@ gfxPangoTextRun::Draw(gfxContext *aContext, gfxPoint aPt, { NS_ASSERTION(aStart + aLength <= mCharacterCount, "Substring out of range"); - gfxFloat appUnitsToPixels = 1/mPixelsToAppUnits; + gfxFloat appUnitsToPixels = 1/mAppUnitsPerDevUnit; CompressedGlyph *charGlyphs = mCharacterGlyphs; gfxFloat direction = GetDirection(); @@ -1224,7 +1224,7 @@ gfxPangoTextRun::Draw(gfxContext *aContext, gfxPoint aPt, } if (aAdvanceWidth) { - *aAdvanceWidth = (pt.x - startX)*direction*mPixelsToAppUnits; + *aAdvanceWidth = (pt.x - startX)*direction*mAppUnitsPerDevUnit; } } @@ -1235,7 +1235,7 @@ gfxPangoTextRun::DrawToPath(gfxContext *aContext, gfxPoint aPt, { NS_ASSERTION(aStart + aLength <= mCharacterCount, "Substring out of range"); - gfxFloat appUnitsToPixels = 1/mPixelsToAppUnits; + gfxFloat appUnitsToPixels = 1/mAppUnitsPerDevUnit; CompressedGlyph *charGlyphs = mCharacterGlyphs; gfxFloat direction = GetDirection(); @@ -1263,7 +1263,7 @@ gfxPangoTextRun::DrawToPath(gfxContext *aContext, gfxPoint aPt, } if (aAdvanceWidth) { - *aAdvanceWidth = (pt.x - startX)*direction*mPixelsToAppUnits; + *aAdvanceWidth = (pt.x - startX)*direction*mAppUnitsPerDevUnit; } } @@ -1303,7 +1303,7 @@ gfxPangoTextRun::AccumulatePangoMetricsForRun(PangoFont *aPangoFont, PRUint32 aS nsAutoTArray spacingBuffer; PRBool haveSpacing = GetAdjustedSpacingArray(aStart, aEnd, aProvider, &spacingBuffer); - gfxFloat appUnitsToPango = gfxFloat(PANGO_SCALE)/mPixelsToAppUnits; + gfxFloat appUnitsToPango = gfxFloat(PANGO_SCALE)/mAppUnitsPerDevUnit; // We start by assuming every character is a cluster and subtract off // characters where that's not true @@ -1376,7 +1376,8 @@ gfxPangoTextRun::AccumulatePangoMetricsForRun(PangoFont *aPangoFont, PRUint32 aS glyphs.glyphs = glyphBuffer.Elements(); glyphs.log_clusters = nsnull; glyphs.space = glyphBuffer.Length(); - Metrics metrics = GetPangoMetrics(&glyphs, aPangoFont, mPixelsToAppUnits, clusterCount); + Metrics metrics = GetPangoMetrics(&glyphs, aPangoFont, mAppUnitsPerDevUnit, + clusterCount); if (IsRightToLeft()) { metrics.CombineWith(*aMetrics); @@ -1563,7 +1564,7 @@ gfxPangoTextRun::BreakAndMeasureText(PRUint32 aStart, PRUint32 aMaxLength, PRBool lineBreakHere = mCharacterGlyphs[i].CanBreakBefore() && (!aSuppressInitialBreak || i > aStart); if (lineBreakHere || (haveHyphenation && hyphenBuffer[i - bufferStart])) { - gfxFloat advance = gfxFloat(pixelAdvance)*mPixelsToAppUnits + floatAdvanceUnits; + gfxFloat advance = gfxFloat(pixelAdvance)*mAppUnitsPerDevUnit + floatAdvanceUnits; gfxFloat hyphenatedAdvance = advance; PRBool hyphenation = !lineBreakHere; if (hyphenation) { @@ -1594,7 +1595,7 @@ gfxPangoTextRun::BreakAndMeasureText(PRUint32 aStart, PRUint32 aMaxLength, NS_ASSERTION(mDetailedGlyphs, "No details but we have a complex cluster..."); DetailedGlyph *details = mDetailedGlyphs[i]; for (;;) { - floatAdvanceUnits += details->mAdvance*mPixelsToAppUnits; + floatAdvanceUnits += details->mAdvance*mAppUnitsPerDevUnit; if (details->mIsLastGlyph) break; ++details; @@ -1610,7 +1611,7 @@ gfxPangoTextRun::BreakAndMeasureText(PRUint32 aStart, PRUint32 aMaxLength, } if (!aborted) { - gfxFloat advance = gfxFloat(pixelAdvance)*mPixelsToAppUnits + floatAdvanceUnits; + gfxFloat advance = gfxFloat(pixelAdvance)*mAppUnitsPerDevUnit + floatAdvanceUnits; width += advance; } @@ -1691,7 +1692,7 @@ gfxPangoTextRun::GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength, NS_ASSERTION(mDetailedGlyphs, "No details but we have a complex cluster..."); DetailedGlyph *details = mDetailedGlyphs[i]; for (;;) { - result += details->mAdvance*mPixelsToAppUnits; + result += details->mAdvance*mAppUnitsPerDevUnit; if (details->mIsLastGlyph) break; ++details; @@ -1699,7 +1700,7 @@ gfxPangoTextRun::GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength, } } - return result + gfxFloat(pixelAdvance)*mPixelsToAppUnits; + return result + gfxFloat(pixelAdvance)*mAppUnitsPerDevUnit; } #define IS_MISSING_GLYPH(g) (((g) & 0x10000000) || (g) == 0x0FFFFFFF) @@ -1807,14 +1808,14 @@ gfxPangoTextRun::MeasureTextSpecialString(SpecialString aString, return Metrics(); PangoFont *pangoFont = mFontGroup->GetFontAt(0)->GetPangoFont(); - return GetPangoMetrics(data->mGlyphs, pangoFont, mPixelsToAppUnits, 1); + return GetPangoMetrics(data->mGlyphs, pangoFont, mAppUnitsPerDevUnit, 1); } void gfxPangoTextRun::DrawSpecialString(gfxContext *aContext, gfxPoint aPt, SpecialString aString) { - gfxFloat appUnitsToPixels = 1/mPixelsToAppUnits; + gfxFloat appUnitsToPixels = 1.0/mAppUnitsPerDevUnit; gfxPoint pt(NSToCoordRound(aPt.x*appUnitsToPixels), NSToCoordRound(aPt.y*appUnitsToPixels)); const gfxPangoFontGroup::SpecialStringData *data = GetSpecialStringData(aString, mFontGroup); @@ -1864,32 +1865,32 @@ gfxPangoTextRun::DrawSpecialString(gfxContext *aContext, gfxPoint aPt, gfxFloat gfxPangoTextRun::GetAdvanceWidthSpecialString(SpecialString aString) { - return GetSpecialStringData(aString, mFontGroup)->mAdvance*mPixelsToAppUnits; + return GetSpecialStringData(aString, mFontGroup)->mAdvance*mAppUnitsPerDevUnit; } gfxFont::Metrics gfxPangoTextRun::GetDecorationMetrics() { gfxFont::Metrics metrics = mFontGroup->GetFontAt(0)->GetMetrics(); - metrics.xHeight *= mPixelsToAppUnits; - metrics.superscriptOffset *= mPixelsToAppUnits; - metrics.subscriptOffset *= mPixelsToAppUnits; - metrics.strikeoutSize *= mPixelsToAppUnits; - metrics.strikeoutOffset *= mPixelsToAppUnits; - metrics.underlineSize *= mPixelsToAppUnits; - metrics.underlineOffset *= mPixelsToAppUnits; - metrics.height *= mPixelsToAppUnits; - metrics.internalLeading *= mPixelsToAppUnits; - metrics.externalLeading *= mPixelsToAppUnits; - metrics.emHeight *= mPixelsToAppUnits; - metrics.emAscent *= mPixelsToAppUnits; - metrics.emDescent *= mPixelsToAppUnits; - metrics.maxHeight *= mPixelsToAppUnits; - metrics.maxAscent *= mPixelsToAppUnits; - metrics.maxDescent *= mPixelsToAppUnits; - metrics.maxAdvance *= mPixelsToAppUnits; - metrics.aveCharWidth *= mPixelsToAppUnits; - metrics.spaceWidth *= mPixelsToAppUnits; + metrics.xHeight *= mAppUnitsPerDevUnit; + metrics.superscriptOffset *= mAppUnitsPerDevUnit; + metrics.subscriptOffset *= mAppUnitsPerDevUnit; + metrics.strikeoutSize *= mAppUnitsPerDevUnit; + metrics.strikeoutOffset *= mAppUnitsPerDevUnit; + metrics.underlineSize *= mAppUnitsPerDevUnit; + metrics.underlineOffset *= mAppUnitsPerDevUnit; + metrics.height *= mAppUnitsPerDevUnit; + metrics.internalLeading *= mAppUnitsPerDevUnit; + metrics.externalLeading *= mAppUnitsPerDevUnit; + metrics.emHeight *= mAppUnitsPerDevUnit; + metrics.emAscent *= mAppUnitsPerDevUnit; + metrics.emDescent *= mAppUnitsPerDevUnit; + metrics.maxHeight *= mAppUnitsPerDevUnit; + metrics.maxAscent *= mAppUnitsPerDevUnit; + metrics.maxDescent *= mAppUnitsPerDevUnit; + metrics.maxAdvance *= mAppUnitsPerDevUnit; + metrics.aveCharWidth *= mAppUnitsPerDevUnit; + metrics.spaceWidth *= mAppUnitsPerDevUnit; return metrics; } diff --git a/gfx/thebes/src/gfxTextRunCache.cpp b/gfx/thebes/src/gfxTextRunCache.cpp index 987ad786d6c..d390564b7ef 100644 --- a/gfx/thebes/src/gfxTextRunCache.cpp +++ b/gfx/thebes/src/gfxTextRunCache.cpp @@ -101,13 +101,14 @@ static PRUint32 ComputeFlags(PRBool aIsRTL, PRBool aEnableSpacing) gfxTextRun* gfxTextRunCache::GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGroup, - const PRUnichar *aString, PRUint32 aLength, gfxFloat aDevToApp, - PRBool aIsRTL, PRBool aEnableSpacing, PRBool *aCallerOwns) + const PRUnichar *aString, PRUint32 aLength, + PRUint32 aAppUnitsPerDevUnit, PRBool aIsRTL, + PRBool aEnableSpacing, PRBool *aCallerOwns) { gfxSkipChars skipChars; // Choose pessimistic flags since we don't want to bother analyzing the string gfxTextRunFactory::Parameters params = - { aContext, nsnull, nsnull, &skipChars, nsnull, 0, aDevToApp, + { aContext, nsnull, nsnull, &skipChars, nsnull, 0, aAppUnitsPerDevUnit, ComputeFlags(aIsRTL, aEnableSpacing) }; gfxTextRun* tr = nsnull; @@ -125,7 +126,7 @@ gfxTextRunCache::GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGrou // Check that this matches what we wanted. If it doesn't, we leave // this cache entry alone and return a fresh, caller-owned textrun // below. - if (cachedTR->GetPixelsToAppUnits() == aDevToApp && + if (cachedTR->GetAppUnitsPerDevUnit() == aAppUnitsPerDevUnit && cachedTR->IsRightToLeft() == aIsRTL) { entry->Used(); tr = cachedTR; @@ -156,13 +157,14 @@ gfxTextRunCache::GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGrou gfxTextRun* gfxTextRunCache::GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGroup, - const char *aString, PRUint32 aLength, gfxFloat aDevToApp, - PRBool aIsRTL, PRBool aEnableSpacing, PRBool *aCallerOwns) + const char *aString, PRUint32 aLength, + PRUint32 aAppUnitsPerDevUnit, PRBool aIsRTL, + PRBool aEnableSpacing, PRBool *aCallerOwns) { gfxSkipChars skipChars; // Choose pessimistic flags since we don't want to bother analyzing the string gfxTextRunFactory::Parameters params = - { aContext, nsnull, nsnull, &skipChars, nsnull, 0, aDevToApp, + { aContext, nsnull, nsnull, &skipChars, nsnull, 0, aAppUnitsPerDevUnit, ComputeFlags(aIsRTL, aEnableSpacing) }; const PRUint8* str = NS_REINTERPRET_CAST(const PRUint8*, aString); @@ -181,7 +183,7 @@ gfxTextRunCache::GetOrMakeTextRun (gfxContext* aContext, gfxFontGroup *aFontGrou // Check that this matches what we wanted. If it doesn't, we leave // this cache entry alone and return a fresh, caller-owned textrun // below. - if (cachedTR->GetPixelsToAppUnits() == aDevToApp && + if (cachedTR->GetAppUnitsPerDevUnit() == aAppUnitsPerDevUnit && cachedTR->IsRightToLeft() == aIsRTL) { entry->Used(); tr = cachedTR; diff --git a/gfx/thebes/src/gfxWindowsFonts.cpp b/gfx/thebes/src/gfxWindowsFonts.cpp index 8bd530faf73..264f257a46a 100644 --- a/gfx/thebes/src/gfxWindowsFonts.cpp +++ b/gfx/thebes/src/gfxWindowsFonts.cpp @@ -626,7 +626,7 @@ gfxWrapperTextRun::SetupSpacingFromProvider(PropertyProvider* aProvider) for (i = 0; i < mLength; ++i) { NS_ASSERTION(spacing.Elements()[i].mBefore == 0, "Can't handle before-spacing!"); - gfxFloat nextOffset = offset + spacing.Elements()[i].mAfter/mPixelsToAppUnits; + gfxFloat nextOffset = offset + spacing.Elements()[i].mAfter/mAppUnitsPerDevUnit; spaceArray.AppendElement(ROUND(nextOffset) - ROUND(offset)); offset = nextOffset; } @@ -642,7 +642,7 @@ gfxWrapperTextRun::Draw(gfxContext *aContext, gfxPoint aPt, { NS_ASSERTION(aStart == 0 && aLength == mLength, "Can't handle substrings"); SetupSpacingFromProvider(aBreakProvider); - gfxPoint pt(aPt.x/mPixelsToAppUnits, aPt.y/mPixelsToAppUnits); + gfxPoint pt(aPt.x/mAppUnitsPerDevUnit, aPt.y/mAppUnitsPerDevUnit); return mInner.Draw(mContext, pt); } @@ -652,7 +652,7 @@ gfxWrapperTextRun::GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength, { NS_ASSERTION(aStart == 0 && aLength == mLength, "Can't handle substrings"); SetupSpacingFromProvider(aBreakProvider); - return mInner.Measure(mContext)*mPixelsToAppUnits; + return mInner.Measure(mContext)*mAppUnitsPerDevUnit; } gfxTextRun * diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 33ae6b62b3c..408cdb394cc 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -6205,22 +6205,6 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState& aState, PRBool aIsRoot, nsIFrame*& aNewFrame) { - // Check to see the type of parent frame so we know whether we need to - // turn off/on scaling for the scrollbars - // - // If the parent is a viewportFrame then we are the scrollbars for the UI - // if not then we are scrollbars inside the document. - PRBool noScalingOfTwips = PR_FALSE; - PRBool isPrintPreview = - aState.mPresContext->Type() == nsPresContext::eContext_PrintPreview; - - if (isPrintPreview) { - noScalingOfTwips = aParentFrame->GetType() == nsGkAtoms::viewportFrame; - if (noScalingOfTwips) { - aState.mPresContext->SetScalingOfTwips(PR_FALSE); - } - } - nsIFrame* parentFrame = nsnull; nsIFrame* gfxScrollFrame = aNewFrame; @@ -6262,11 +6246,7 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState& aState, gfxScrollFrame->SetInitialChildList(nsnull, anonymousItems.childList); } - if (isPrintPreview && noScalingOfTwips) { - aState.mPresContext->SetScalingOfTwips(PR_TRUE); - } - - return aScrolledChildStyle;; + return aScrolledChildStyle; } void diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 1f28e1105af..82affc48de6 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -1711,7 +1711,7 @@ void nsCSSRendering::PaintBorder(nsPresContext* aPresContext, } } /* Get our conversion values */ - nscoord twipsPerPixel = NSIntPixelsToTwips(1, aPresContext->PixelsToTwips()); + nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1); static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT }; nscolor sideColor; @@ -2072,7 +2072,7 @@ nscoord width, offset; // Draw all the other sides - nscoord twipsPerPixel = NSIntPixelsToTwips(1, aPresContext->PixelsToTwips()); + PRInt32 appUnitsPerPixel = aPresContext->DevPixelsToAppUnits(1); // default to current color in case it is invert color // and the platform does not support that @@ -2095,25 +2095,25 @@ nscoord width, offset; outlineStyle, outlineColor, bgColor->mBackgroundColor, outside, inside, aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); DrawSide(aRenderingContext, NS_SIDE_LEFT, outlineStyle, outlineColor, bgColor->mBackgroundColor,outside, inside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); DrawSide(aRenderingContext, NS_SIDE_TOP, outlineStyle, outlineColor, bgColor->mBackgroundColor,outside, inside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); DrawSide(aRenderingContext, NS_SIDE_RIGHT, outlineStyle, outlineColor, bgColor->mBackgroundColor,outside, inside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); if(modeChanged ) { aRenderingContext.SetPenMode(nsPenMode_kNone); @@ -2161,10 +2161,7 @@ void nsCSSRendering::PaintBorderEdges(nsPresContext* aPresContext, DrawDashedSegments(aRenderingContext, aBorderArea, aBorderEdges, aSkipSides, aGap); // Draw all the other sides - nscoord twipsPerPixel; - float p2t; - p2t = aPresContext->PixelsToTwips(); - twipsPerPixel = (nscoord) p2t;/* XXX huh!*/ + nscoord appUnitsPerPixel = nsPresContext::AppUnitsPerCSSPixel(); if (0 == (aSkipSides & (1<mEdges[NS_SIDE_TOP].Count(); @@ -2187,7 +2184,7 @@ void nsCSSRendering::PaintBorderEdges(nsPresContext* aPresContext, borderEdge->mColor, bgColor->mBackgroundColor, inside, outside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, inside, outside, aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, inside, outside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, inside, outside,aSkipSides, - twipsPerPixel, aGap); + appUnitsPerPixel, aGap); } } } @@ -2848,10 +2845,8 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext, image->GetWidth(&imageSize.width); image->GetHeight(&imageSize.height); - float p2t; - p2t = aPresContext->ScaledPixelsToTwips(); - imageSize.width = NSIntPixelsToTwips(imageSize.width, p2t); - imageSize.height = NSIntPixelsToTwips(imageSize.height, p2t); + imageSize.width = nsPresContext::CSSPixelsToAppUnits(imageSize.width); + imageSize.height = nsPresContext::CSSPixelsToAppUnits(imageSize.height); req = nsnull; @@ -3170,6 +3165,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext, // Take the intersection again to paint only the required area. nsRect absTileRect = tileRect + aBorderArea.TopLeft(); + nsRect drawRect; if (drawRect.IntersectRect(absTileRect, dirtyRect)) { // Note that due to the way FindTileStart works we're guaranteed @@ -3299,12 +3295,9 @@ nsCSSRendering::PaintRoundedBackground(nsPresContext* aPresContext, nsFloatPoint thePath[MAXPATHSIZE]; static nsPoint polyPath[MAXPOLYPATHSIZE]; PRInt16 np; - nscoord twipsPerPixel; - float p2t; // needed for our border thickness - p2t = aPresContext->PixelsToTwips(); - twipsPerPixel = NSToCoordRound(p2t); + nscoord appUnitsPerPixel = nsPresContext::AppUnitsPerCSSPixel(); nscolor color = aColor.mBackgroundColor; if (!aCanPaintNonWhite) { @@ -3325,7 +3318,8 @@ nsCSSRendering::PaintRoundedBackground(nsPresContext* aPresContext, } // set the rounded rect up, and let'er rip - outerPath.Set(aBgClipArea.x,aBgClipArea.y,aBgClipArea.width,aBgClipArea.height,aTheRadius,twipsPerPixel); + outerPath.Set(aBgClipArea.x, aBgClipArea.y, aBgClipArea.width, + aBgClipArea.height, aTheRadius, appUnitsPerPixel); outerPath.GetRoundedBorders(UL,UR,LL,LR); // BUILD THE ENTIRE OUTSIDE PATH @@ -3407,8 +3401,6 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, nsFloatPoint thePath[MAXPATHSIZE]; PRInt16 np; nsMargin border; - nscoord twipsPerPixel,qtwips; - float p2t; NS_ASSERTION((aIsOutline && aOutlineStyle) || (!aIsOutline && aBorderStyle), "null params not allowed"); if (!aIsOutline) { @@ -3429,13 +3421,11 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, } // needed for our border thickness - twipsPerPixel = NSIntPixelsToTwips(1, aPresContext->PixelsToTwips()); + nscoord appUnitsPerPixel = aPresContext->DevPixelsToAppUnits(1); + nscoord quarterPixel = appUnitsPerPixel / 4; - // Base our thickness check on the segment being less than a pixel and 1/2 - qtwips = twipsPerPixel >> 2; - //qtwips = twipsPerPixel; - - outerPath.Set(aBorderArea.x,aBorderArea.y,aBorderArea.width,aBorderArea.height,aBorderRadius,twipsPerPixel); + outerPath.Set(aBorderArea.x, aBorderArea.y, aBorderArea.width, + aBorderArea.height, aBorderRadius, appUnitsPerPixel); outerPath.GetRoundedBorders(UL,UR,LL,LR); outerPath.CalcInsetCurves(IUL,IUR,ILL,ILR,border); @@ -3459,7 +3449,8 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, thePath[np++].MoveTo(Icr2.mAnc2.x, Icr2.mAnc2.y); thePath[np++].MoveTo(Icr2.mCon.x, Icr2.mCon.y); thePath[np++].MoveTo(Icr2.mAnc1.x, Icr2.mAnc1.y); - RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_TOP,border,qtwips, aIsOutline); + RenderSide(thePath, aRenderingContext, aBorderStyle, aOutlineStyle, + aStyleContext, NS_SIDE_TOP, border, quarterPixel, aIsOutline); } // RIGHT LINE ---------------------------------------------------------------- LR.MidPointDivide(&cr2,&cr3); @@ -3479,7 +3470,8 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, thePath[np++].MoveTo(Icr4.mAnc2.x,Icr4.mAnc2.y); thePath[np++].MoveTo(Icr4.mCon.x, Icr4.mCon.y); thePath[np++].MoveTo(Icr4.mAnc1.x,Icr4.mAnc1.y); - RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_RIGHT,border,qtwips, aIsOutline); + RenderSide(thePath, aRenderingContext, aBorderStyle, aOutlineStyle, + aStyleContext, NS_SIDE_RIGHT, border, quarterPixel, aIsOutline); } // bottom line ---------------------------------------------------------------- @@ -3500,7 +3492,8 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, thePath[np++].MoveTo(Icr3.mAnc2.x, Icr3.mAnc2.y); thePath[np++].MoveTo(Icr3.mCon.x, Icr3.mCon.y); thePath[np++].MoveTo(Icr3.mAnc1.x, Icr3.mAnc1.y); - RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_BOTTOM,border,qtwips, aIsOutline); + RenderSide(thePath, aRenderingContext, aBorderStyle, aOutlineStyle, + aStyleContext, NS_SIDE_BOTTOM, border, quarterPixel, aIsOutline); } // left line ---------------------------------------------------------------- if(0==border.left) @@ -3521,7 +3514,8 @@ nsCSSRendering::PaintRoundedBorder(nsPresContext* aPresContext, thePath[np++].MoveTo(Icr4.mCon.x, Icr4.mCon.y); thePath[np++].MoveTo(Icr4.mAnc1.x, Icr4.mAnc1.y); - RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_LEFT,border,qtwips, aIsOutline); + RenderSide(thePath, aRenderingContext, aBorderStyle, aOutlineStyle, + aStyleContext, NS_SIDE_LEFT, border, quarterPixel, aIsOutline); } @@ -4196,7 +4190,7 @@ nsCSSRendering::DrawTableBorderSegment(nsIRenderingContext& aContext, aContext.SetColor (aBorderColor); PRBool horizontal = ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide)); - nscoord twipsPerPixel = NSIntPixelsToTwips(1, aPixelsToTwips); + nscoord twipsPerPixel = NSIntPixelsToAppUnits(1, aPixelsToTwips); PRBool ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE; if ((twipsPerPixel >= aBorder.width) || (twipsPerPixel >= aBorder.height) || diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 48b7955c26f..d2be4ea09b0 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -125,12 +125,10 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) mShowDuringSelection = tempInt ? PR_TRUE : PR_FALSE; } - float tDevUnitsToTwips; - tDevUnitsToTwips = presContext->DeviceContext()->DevUnitsToTwips(); - mCaretTwipsWidth = (nscoord)(tDevUnitsToTwips * (float)caretPixelsWidth); - mBidiIndicatorTwipsSize = (nscoord)(tDevUnitsToTwips * (float)kMinBidiIndicatorPixels); - if (mBidiIndicatorTwipsSize < mCaretTwipsWidth) { - mBidiIndicatorTwipsSize = mCaretTwipsWidth; + mCaretWidth = presContext->DevPixelsToAppUnits(caretPixelsWidth); + mBidiIndicatorSize = presContext->DevPixelsToAppUnits(kMinBidiIndicatorPixels); + if (mBidiIndicatorSize < mCaretWidth) { + mBidiIndicatorSize = mCaretWidth; } // get the selection from the pres shell, and set ourselves up as a selection @@ -350,7 +348,7 @@ NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, outCoordinates->x = viewOffset.x; outCoordinates->y = viewOffset.y; outCoordinates->height = theFrame->GetSize().height; - outCoordinates->width = mCaretTwipsWidth; + outCoordinates->width = mCaretWidth; return NS_OK; } @@ -1049,7 +1047,7 @@ nsresult nsCaret::UpdateCaretRects(nsIFrame* aFrame, PRInt32 aFrameOffset) } mCaretRect += framePos; - mCaretRect.width = mCaretTwipsWidth; + mCaretRect.width = mCaretWidth; // on RTL frames the right edge of mCaretRect must be equal to framePos const nsStyleVisibility* vis = aFrame->GetStyleVisibility(); @@ -1106,10 +1104,10 @@ nsresult nsCaret::UpdateHookRect(nsPresContext* aPresContext) // The height of the hook rectangle is the same as the width of the caret // rectangle. mHookRect.SetRect(mCaretRect.x + ((isCaretRTL) ? - mBidiIndicatorTwipsSize * -1 : + mBidiIndicatorSize * -1 : mCaretRect.width), - mCaretRect.y + mBidiIndicatorTwipsSize, - mBidiIndicatorTwipsSize, + mCaretRect.y + mBidiIndicatorSize, + mBidiIndicatorSize, mCaretRect.width); } #endif //IBMBIDI diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index f1822f188e7..ee724a09a28 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -165,8 +165,8 @@ protected: PRUint32 mBlinkRate; // time for one cyle (off then on), in milliseconds - nscoord mCaretTwipsWidth; // caret width in twips. this gets calculated laziiy - nscoord mBidiIndicatorTwipsSize; // width and height of bidi indicator + nscoord mCaretWidth; // caret width. this gets calculated laziiy + nscoord mBidiIndicatorSize; // width and height of bidi indicator PRPackedBool mVisible; // is the caret blinking PRPackedBool mDrawn; // this should be mutable diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index ff4bc6c6e44..d733b0d4079 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -808,17 +808,17 @@ void nsDisplayOpacity::Paint(nsDisplayListBuilder* aBuilder, nsCOMPtr devCtx; aCtx->GetDeviceContext(*getter_AddRefs(devCtx)); - float t2p = devCtx->AppUnitsToDevUnits(); + float a2p = 1.0f / devCtx->AppUnitsPerDevPixel(); nsRefPtr ctx = (gfxContext*)aCtx->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); ctx->Save(); ctx->NewPath(); - ctx->Rectangle(gfxRect(bounds.x * t2p, - bounds.y * t2p, - bounds.width * t2p, - bounds.height * t2p), + ctx->Rectangle(gfxRect(bounds.x * a2p, + bounds.y * a2p, + bounds.width * a2p, + bounds.height * a2p), PR_TRUE); ctx->Clip(); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 78896ef1c6a..892ed4b42ed 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -686,12 +686,8 @@ DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow) nsRect bounds; mWindow->GetBounds(bounds); - float p2t; - - p2t = mPresContext->PixelsToTwips(); - - nscoord width = NSIntPixelsToTwips(bounds.width, p2t); - nscoord height = NSIntPixelsToTwips(bounds.height, p2t); + nscoord width = mPresContext->DevPixelsToAppUnits(bounds.width); + nscoord height = mPresContext->DevPixelsToAppUnits(bounds.height); mViewManager->DisableRefresh(); mViewManager->SetWindowDimensions(width, height); @@ -802,7 +798,6 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, // Clear PrintPreview Alternate Device if (mDeviceContext) { mDeviceContext->SetAltDevice(nsnull); - mDeviceContext->SetCanonicalPixelScale(1.0); } #endif @@ -924,9 +919,8 @@ DocumentViewerImpl::DumpContentToPPM(const char* aFileName) mViewManager->GetRootView(view); } nsRect r = view->GetBounds() - view->GetPosition(); - float p2t = mPresContext->PixelsToTwips(); // Limit the bitmap size to 5000x5000 - nscoord twipLimit = NSIntPixelsToTwips(5000, p2t); + nscoord twipLimit = mPresContext->DevPixelsToAppUnits(5000); if (r.height > twipLimit) r.height = twipLimit; if (r.width > twipLimit) @@ -950,9 +944,8 @@ DocumentViewerImpl::DumpContentToPPM(const char* aFileName) if (!surface) { status = "NOSURFACE"; } else { - float t2p = mPresContext->TwipsToPixels(); - PRUint32 width = NSTwipsToIntPixels(view->GetBounds().width, t2p); - PRUint32 height = NSTwipsToIntPixels(view->GetBounds().height, t2p); + PRUint32 width = mPresContext->AppUnitsToDevPixels(view->GetBounds().width); + PRUint32 height = mPresContext->AppUnitsToDevPixels(view->GetBounds().height); PRUint8* data; PRInt32 rowLen, rowSpan; @@ -2318,9 +2311,7 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, nsIDeviceContext *dx = mPresContext->DeviceContext(); nsRect tbounds = aBounds; - float p2t; - p2t = mPresContext->PixelsToTwips(); - tbounds *= p2t; + tbounds *= mPresContext->AppUnitsPerDevPixel(); // Initialize the view manager with an offset. This allows the viewmanager // to manage a coordinate space offset from (0,0) @@ -3150,7 +3141,6 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent() NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); PRInt32 width, height; - float pixelScale; // so how big is it? nsRect shellArea = presContext->GetVisibleArea(); @@ -3159,9 +3149,8 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent() // Protect against bogus returns here return NS_ERROR_FAILURE; } - pixelScale = presContext->TwipsToPixels(); - width = PRInt32((float)shellArea.width*pixelScale); - height = PRInt32((float)shellArea.height*pixelScale); + width = presContext->AppUnitsToDevPixels(shellArea.width); + height = presContext->AppUnitsToDevPixels(shellArea.height); nsCOMPtr treeOwner; docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner)); diff --git a/layout/base/nsImageLoader.cpp b/layout/base/nsImageLoader.cpp index 659e3631004..94594f7a237 100644 --- a/layout/base/nsImageLoader.cpp +++ b/layout/base/nsImageLoader.cpp @@ -196,12 +196,10 @@ NS_IMETHODIMP nsImageLoader::FrameChanged(imgIContainer *aContainer, nsRect r(*dirtyRect); - float p2t; - p2t = mPresContext->PixelsToTwips(); - r.x = NSIntPixelsToTwips(r.x, p2t); - r.y = NSIntPixelsToTwips(r.y, p2t); - r.width = NSIntPixelsToTwips(r.width, p2t); - r.height = NSIntPixelsToTwips(r.height, p2t); + r.x = nsPresContext::CSSPixelsToAppUnits(r.x); + r.y = nsPresContext::CSSPixelsToAppUnits(r.y); + r.width = nsPresContext::CSSPixelsToAppUnits(r.width); + r.height = nsPresContext::CSSPixelsToAppUnits(r.height); RedrawDirtyFrame(&r); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 034f5e5b622..96c3b9a6075 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -658,10 +658,9 @@ nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext, nsPoint viewToWidget; nsIWidget* wid = baseView->GetNearestWidget(&viewToWidget); NS_ASSERTION(aWidget == wid, "Clashing widgets"); - float pixelsToTwips = aPresContext->PixelsToTwips(); - nsPoint refPointTwips(NSIntPixelsToTwips(aPt.x, pixelsToTwips), - NSIntPixelsToTwips(aPt.y, pixelsToTwips)); - return refPointTwips - viewToWidget - aView->GetOffsetTo(baseView); + nsPoint refPointAppUnits(aPresContext->DevPixelsToAppUnits(aPt.x), + aPresContext->DevPixelsToAppUnits(aPt.y)); + return refPointAppUnits - viewToWidget - aView->GetOffsetTo(baseView); } // Combine aNewBreakType with aOrigBreakType, but limit the break types @@ -1397,9 +1396,7 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext, GetMinimumWidgetSize(aRenderingContext, aFrame, disp->mAppearance, &size, &canOverride); - // GMWS() returns size in pixels, we need to convert it back to twips - float p2t = presContext->ScaledPixelsToTwips(); - nscoord themeWidth = NSIntPixelsToTwips(size.width, p2t); + nscoord themeWidth = presContext->DevPixelsToAppUnits(size.width); // GMWS() returns a border-box width themeWidth += offsets.hMargin; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 20e30c7311f..ef6355048e5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -143,12 +143,11 @@ IsVisualCharset(const nsCString& aCharset) #endif // IBMBIDI -PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* closure) +PR_STATIC_CALLBACK(PLDHashOperator) +destroy_loads(const PRUint32& aKey, nsCOMPtr& aData, void* closure) { - nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); - nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); - loader->Destroy(); - return PR_TRUE; + aData->Destroy(); + return PL_DHASH_NEXT; } static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); @@ -163,20 +162,21 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType) mPageSize(-1, -1), mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO), mImageAnimationModePref(imgIContainer::kNormalAnimMode), + // Font sizes default to zero; they will be set in GetFontPreferences mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)), + NS_FONT_WEIGHT_NORMAL, 0, 0), mCanPaginatedScroll(PR_FALSE), mIsRootPaginatedDocument(PR_FALSE) { @@ -226,7 +226,7 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType) nsPresContext::~nsPresContext() { - mImageLoaders.Enumerate(destroy_loads); + mImageLoaders.Enumerate(destroy_loads, nsnull); NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer"); SetShell(nsnull); @@ -326,9 +326,8 @@ nsPresContext::GetFontPreferences() font.minimum-size.[langGroup] = integer - settable by the user */ - float p2t = ScaledPixelsToTwips(); - mDefaultVariableFont.size = NSFloatPixelsToTwips((float)16, p2t); - mDefaultFixedFont.size = NSFloatPixelsToTwips((float)13, p2t); + mDefaultVariableFont.size = CSSPixelsToAppUnits(16); + mDefaultFixedFont.size = CSSPixelsToAppUnits(13); const char *langGroup; mLangGroup->GetUTF8String(&langGroup); @@ -362,10 +361,10 @@ nsPresContext::GetFontPreferences() PRInt32 size = nsContentUtils::GetIntPref(pref.get()); if (unit == eUnit_px) { - mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); + mMinimumFontSize = CSSPixelsToAppUnits(size); } else if (unit == eUnit_pt) { - mMinimumFontSize = NSIntPointsToTwips(size); + mMinimumFontSize = this->PointsToAppUnits(size); } // get attributes specific to each generic font @@ -429,10 +428,10 @@ nsPresContext::GetFontPreferences() size = nsContentUtils::GetIntPref(pref.get()); if (size > 0) { if (unit == eUnit_px) { - font->size = NSFloatPixelsToTwips((float)size, p2t); + font->size = nsPresContext::CSSPixelsToAppUnits(size); } else if (unit == eUnit_pt) { - font->size = NSIntPointsToTwips(size); + font->size = this->PointsToAppUnits(size); } } @@ -698,6 +697,9 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = aDeviceContext; NS_ADDREF(mDeviceContext); + if (!mImageLoaders.Init()) + return NS_ERROR_OUT_OF_MEMORY; + // Get the look and feel service here; default colors will be initialized // from calling GetUserPreferences() when we get a presshell. nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel); @@ -750,10 +752,9 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mInitialized = PR_TRUE; #endif - float pixelsToTwips = ScaledPixelsToTwips(); - mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); - mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); - mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); + mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = CSSPixelsToAppUnits(1); + mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = CSSPixelsToAppUnits(3); + mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = CSSPixelsToAppUnits(5); return NS_OK; } @@ -913,13 +914,12 @@ static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode) } // Enumeration call back for HashTable -PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void* closure) +PR_STATIC_CALLBACK(PLDHashOperator) +set_animation_mode(const PRUint32& aKey, nsCOMPtr& aData, void* closure) { - nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); - nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); - imgIRequest* imgReq = loader->GetRequest(); + imgIRequest* imgReq = aData->GetRequest(); SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure)); - return PR_TRUE; + return PL_DHASH_NEXT; } // IMPORTANT: Assumption is that all images for a Presentation @@ -1035,47 +1035,6 @@ nsPresContext::GetDefaultFontExternal(PRUint8 aFontID) const return GetDefaultFontInternal(aFontID); } -float -nsPresContext::TwipsToPixelsForFonts() const -{ - 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 printer's - // scaling values for calculating the font heights - nsCOMPtr altDC; - mDeviceContext->GetAltDevice(getter_AddRefs(altDC)); - if (altDC) { - app2dev = altDC->AppUnitsToDevUnits(); - } else { - app2dev = mDeviceContext->AppUnitsToDevUnits(); - } -#else - app2dev = mDeviceContext->AppUnitsToDevUnits(); -#endif - return app2dev; -} - - - -float -nsPresContext::ScaledPixelsToTwips() const -{ - float scale; - float p2t; - - p2t = mDeviceContext->DevUnitsToAppUnits(); - if (mDoScaledTwips) { - mDeviceContext->GetCanonicalPixelScale(scale); - scale = p2t * scale; - } else { - scale = p2t; - } - - return scale; -} - void nsPresContext::SetTextZoomExternal(float aZoom) { @@ -1086,25 +1045,21 @@ imgIRequest* nsPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame) { // look and see if we have a loader for the target frame. - - nsVoidKey key(aTargetFrame); - nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs + nsCOMPtr loader; + mImageLoaders.Get(NS_PTR_TO_INT32(aTargetFrame), getter_AddRefs(loader)); if (!loader) { loader = new nsImageLoader(); if (!loader) return nsnull; - NS_ADDREF(loader); // new - loader->Init(aTargetFrame, this); - mImageLoaders.Put(&key, loader); + mImageLoaders.Put(NS_PTR_TO_INT32(aTargetFrame), loader); } loader->Load(aImage); imgIRequest *request = loader->GetRequest(); - NS_RELEASE(loader); return request; } @@ -1113,14 +1068,13 @@ nsPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame) void nsPresContext::StopImagesFor(nsIFrame* aTargetFrame) { - nsVoidKey key(aTargetFrame); - nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs + nsCOMPtr loader; + mImageLoaders.Get(NS_PTR_TO_INT32(aTargetFrame), getter_AddRefs(loader)); if (loader) { loader->Destroy(); - NS_RELEASE(loader); - mImageLoaders.Remove(&key); + mImageLoaders.Remove(NS_PTR_TO_INT32(aTargetFrame)); } } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 0f68f3c370c..0058cee65b1 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -48,7 +48,6 @@ #include "nsIPresShell.h" #include "nsRect.h" #include "nsIDeviceContext.h" -#include "nsHashtable.h" #include "nsFont.h" #include "nsIWeakReference.h" #include "nsITheme.h" @@ -60,6 +59,8 @@ #include "nsPropertyTable.h" #include "nsGkAtoms.h" #include "nsIDocument.h" +#include "nsInterfaceHashtable.h" +class nsImageLoader; #ifdef IBMBIDI class nsBidiPresUtils; #endif // IBMBIDI @@ -425,29 +426,15 @@ public: { mIsRootPaginatedDocument = aIsRootPaginatedDocument; } /** - * Conversion from device pixels to twips. - * WARNING: The misuse of this function to convert CSS pixels to twips - * will cause problems during printing - */ - float PixelsToTwips() const { return mDeviceContext->DevUnitsToAppUnits(); } + * Get/set the print scaling level; used by nsPageFrame to scale up + * pages. Set safe to call before reflow, get guaranteed to be set + * properly after reflow. + */ - float TwipsToPixels() const { return mDeviceContext->AppUnitsToDevUnits(); } + float GetPageScale() { return mPageScale; } + void SetPageScale(float aScale) { mPageScale = aScale; } - NS_HIDDEN_(float) TwipsToPixelsForFonts() const; - //XXX this is probably not an ideal name. MMP - /** - * Do CSS pixels to twips conversion taking into account - * differing size of a "pixel" from device to device. - */ - NS_HIDDEN_(float) ScaledPixelsToTwips() const; - - /* Convenience method for converting one pixel value to twips */ - nscoord IntScaledPixelsToTwips(nscoord aPixels) const - { return NSIntPixelsToTwips(aPixels, ScaledPixelsToTwips()); } - - /* Set whether twip scaling is used */ - void SetScalingOfTwips(PRBool aOn) { mDoScaledTwips = aOn; } nsIDeviceContext* DeviceContext() { return mDeviceContext; } nsIEventStateManager* EventStateManager() { return mEventManager; } @@ -465,7 +452,47 @@ public: void SetTextZoom(float aZoom) { SetTextZoomExternal(aZoom); } #endif + static PRInt32 AppUnitsPerCSSPixel() { return nsIDeviceContext::AppUnitsPerCSSPixel(); } + PRInt32 AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); } + PRInt32 AppUnitsPerInch() const { return mDeviceContext->AppUnitsPerInch(); } + static nscoord CSSPixelsToAppUnits(PRInt32 aPixels) + { return NSIntPixelsToAppUnits(aPixels, + nsIDeviceContext::AppUnitsPerCSSPixel()); } + + static nscoord CSSPixelsToAppUnits(float aPixels) + { return NSFloatPixelsToAppUnits(aPixels, + nsIDeviceContext::AppUnitsPerCSSPixel()); } + + static PRInt32 AppUnitsToIntCSSPixels(nscoord aAppUnits) + { return NSAppUnitsToIntPixels(aAppUnits, + nsIDeviceContext::AppUnitsPerCSSPixel()); } + + static float AppUnitsToFloatCSSPixels(nscoord aAppUnits) + { return NSAppUnitsToFloatPixels(aAppUnits, + nsIDeviceContext::AppUnitsPerCSSPixel()); } + + nscoord DevPixelsToAppUnits(PRInt32 aPixels) const + { return NSIntPixelsToAppUnits(aPixels, + mDeviceContext->AppUnitsPerDevPixel()); } + + PRInt32 AppUnitsToDevPixels(nscoord aAppUnits) const + { return NSAppUnitsToIntPixels(aAppUnits, + mDeviceContext->AppUnitsPerDevPixel()); } + + nscoord TwipsToAppUnits(PRInt32 aTwips) const + { return NSToCoordRound(NS_TWIPS_TO_INCHES(aTwips) * + mDeviceContext->AppUnitsPerInch()); } + + PRInt32 AppUnitsToTwips(nscoord aTwips) const + { return NS_INCHES_TO_TWIPS((float)aTwips / + mDeviceContext->AppUnitsPerInch()); } + + nscoord PointsToAppUnits(float aPoints) const + { return NSToCoordRound(aPoints * mDeviceContext->AppUnitsPerInch() / + 72.0f); } + float AppUnitsToPoints(nscoord aAppUnits) const + { return (float)aAppUnits / mDeviceContext->AppUnitsPerInch() * 72.0f; } /** * Get the language-specific transform type for the current document. @@ -720,7 +747,7 @@ protected: nsILinkHandler* mLinkHandler; // [WEAK] nsIAtom* mLangGroup; // [STRONG] - nsSupportsHashtable mImageLoaders; + nsInterfaceHashtable mImageLoaders; nsWeakPtr mContainer; // Only used in the root prescontext (this->RootPresContext() == this) @@ -747,6 +774,7 @@ protected: nsRect mVisibleArea; nsSize mPageSize; + float mPageScale; nscolor mDefaultColor; nscolor mBackgroundColor; diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 00b19456dd5..e39d9c4eab0 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -5023,7 +5023,7 @@ PresShell::RenderOffscreen(nsRect aRect, PRBool aUntrusted, return NS_ERROR_FAILURE; nsRect bounds(nsPoint(0, 0), aRect.Size()); - bounds.ScaleRoundOut(mPresContext->TwipsToPixels()); + bounds.ScaleRoundOut(1.0f / mPresContext->AppUnitsPerDevPixel()); nsIDrawingSurface* surface; nsresult rv @@ -7195,8 +7195,9 @@ void ReflowCountMgr::PaintCount(const char * aName, IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key); if (counter != nsnull && counter->mName.EqualsASCII(aName)) { aRenderingContext->PushState(); - nsFont font("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL, - NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(8)); + nsFont font("Times", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nsPresContext::CSSPixelsToAppUnits(11)); nsCOMPtr fm = aPresContext->GetMetricsFor(font); aRenderingContext->SetFont(fm); diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 15419346e93..361ee8715ad 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -524,9 +524,7 @@ nsComboboxControlFrame::PositionDropdown(nsPresContext* aPresContext, nscoord screenHeightInPixels = 0; if (NS_SUCCEEDED(nsFormControlFrame::GetScreenHeight(aPresContext, screenHeightInPixels))) { // Get the height of the dropdown list in pixels. - float t2p; - t2p = aPresContext->TwipsToPixels(); - nscoord absoluteDropDownHeight = NSTwipsToIntPixels(dropdownRect.height, t2p); + nscoord absoluteDropDownHeight = aPresContext->AppUnitsToDevPixels(dropdownRect.height); // Check to see if the drop-down list will go offscreen if (NS_SUCCEEDED(rv) && ((aAbsolutePixelRect.y + aAbsolutePixelRect.height + absoluteDropDownHeight) > screenHeightInPixels)) { @@ -638,7 +636,7 @@ nsComboboxControlFrame::Reflow(nsPresContext* aPresContext, // First reflow our dropdown so that we know how tall we should be. ReflowDropdown(aPresContext, aReflowState); - + // Get the width of the vertical scrollbar. That will be the width of the // dropdown button. nsIScrollableFrame* scrollable; @@ -1391,8 +1389,7 @@ void nsComboboxControlFrame::PaintFocus(nsIRenderingContext& aRenderingContext, aRenderingContext.SetLineStyle(nsLineStyle_kSolid); } //aRenderingContext.DrawRect(clipRect); - float p2t = GetPresContext()->PixelsToTwips(); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); clipRect.width -= onePixel; clipRect.height -= onePixel; aRenderingContext.DrawLine(clipRect.x, clipRect.y, diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp index 6d405777b64..001de9f0f5e 100644 --- a/layout/forms/nsFieldSetFrame.cpp +++ b/layout/forms/nsFieldSetFrame.cpp @@ -597,9 +597,8 @@ nsFieldSetFrame::Reflow(nsPresContext* aPresContext, mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left; break; case NS_STYLE_TEXT_ALIGN_CENTER: - float p2t; - p2t = aPresContext->PixelsToTwips(); - mLegendRect.x = NSIntPixelsToTwips((nscoord) NSToIntRound((float)(contentRect.width/2 - mLegendRect.width/2 + borderPadding.left) / p2t),p2t); + // Note: rounding removed; there doesn't seem to be any need + mLegendRect.x = contentRect.width / 2 - mLegendRect.width / 2 + borderPadding.left; break; } diff --git a/layout/forms/nsFormControlFrame.cpp b/layout/forms/nsFormControlFrame.cpp index d0ce55e96b2..8c5f3f080db 100644 --- a/layout/forms/nsFormControlFrame.cpp +++ b/layout/forms/nsFormControlFrame.cpp @@ -231,10 +231,8 @@ nsFormControlFrame::GetScreenHeight(nsPresContext* aPresContext, context->GetRect ( screen ); else context->GetClientRect(screen); - - float devUnits; - devUnits = context->DevUnitsToAppUnits(); - aHeight = NSToIntRound(float(screen.height) / devUnits ); + + aHeight = aPresContext->AppUnitsToDevPixels(screen.height); return NS_OK; } @@ -255,12 +253,6 @@ nsFormControlFrame::GetAbsoluteFramePosition(nsPresContext* aPresContext, aAbsoluteTwipsRect.x = 0; aAbsoluteTwipsRect.y = 0; - // Get conversions between twips and pixels - float t2p; - float p2t; - t2p = aPresContext->TwipsToPixels(); - p2t = aPresContext->PixelsToTwips(); - // Start with frame's offset from it it's containing view nsIView *view = nsnull; nsPoint frameOffset; @@ -290,8 +282,8 @@ nsFormControlFrame::GetAbsoluteFramePosition(nsPresContext* aPresContext, // XXX a twip version of this would be really nice here! widget->WidgetToScreen(zeroRect, absBounds); // Convert widget coordinates to twips - aAbsoluteTwipsRect.x += NSIntPixelsToTwips(absBounds.x, p2t); - aAbsoluteTwipsRect.y += NSIntPixelsToTwips(absBounds.y, p2t); + aAbsoluteTwipsRect.x += aPresContext->DevPixelsToAppUnits(absBounds.x); + aAbsoluteTwipsRect.y += aPresContext->DevPixelsToAppUnits(absBounds.y); break; } @@ -301,11 +293,10 @@ nsFormControlFrame::GetAbsoluteFramePosition(nsPresContext* aPresContext, // convert to pixel coordinates if (NS_SUCCEEDED(rv)) { - aAbsolutePixelRect.x = NSTwipsToIntPixels(aAbsoluteTwipsRect.x, t2p); - aAbsolutePixelRect.y = NSTwipsToIntPixels(aAbsoluteTwipsRect.y, t2p); - - aAbsolutePixelRect.width = NSTwipsToIntPixels(aAbsoluteTwipsRect.width, t2p); - aAbsolutePixelRect.height = NSTwipsToIntPixels(aAbsoluteTwipsRect.height, t2p); + aAbsolutePixelRect.x = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.x); + aAbsolutePixelRect.y = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.y); + aAbsolutePixelRect.width = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.width); + aAbsolutePixelRect.height = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.height); } return rv; diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index f46389bcc17..c861909ace4 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -365,7 +365,7 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsPoint aPt) nsILookAndFeel::eColor_WidgetSelectForeground : nsILookAndFeel::eColor_WidgetSelectBackground, color); - nscoord onePixelInTwips = presContext->IntScaledPixelsToTwips(1); + nscoord onePixelInTwips = nsPresContext::CSSPixelsToAppUnits(1); nsRect dirty; nscolor colors[] = {color, color, color, color}; @@ -714,9 +714,7 @@ nsListControlFrame::ReflowAsDropdown(nsPresContext* aPresContext, // We can fix these cases later if they actually happen. nscoord screenHeightInPixels = 0; if (NS_SUCCEEDED(nsFormControlFrame::GetScreenHeight(aPresContext, screenHeightInPixels))) { - float p2t; - p2t = aPresContext->PixelsToTwips(); - nscoord screenHeight = NSIntPixelsToTwips(screenHeightInPixels, p2t); + nscoord screenHeight = aPresContext->DevPixelsToAppUnits(screenHeightInPixels); nscoord availDropHgt = (screenHeight / 2) - (heightOfARow*2); // approx half screen minus combo size availDropHgt -= aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom; diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 74182521be2..af8b03eebf9 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -1317,11 +1317,10 @@ nsTextControlFrame::CalcIntrinsicSize(nsIRenderingContext* aRenderingContext, // this if charMaxAdvance != charWidth; if they are equal, this is almost // certainly a fixed-width font. if (charWidth != charMaxAdvance) { - float p2t; - p2t = presContext->PixelsToTwips(); - nscoord internalPadding = PR_MAX(charMaxAdvance - NSToCoordRound(4 * p2t), 0); - // round to a multiple of p2t - nscoord t = NSToCoordRound(p2t); + nscoord internalPadding = PR_MAX(0, charMaxAdvance - + nsPresContext::CSSPixelsToAppUnits(4)); + nscoord t = nsPresContext::CSSPixelsToAppUnits(1); + // Round to a multiple of t nscoord rest = internalPadding % t; if (rest < t - rest) { internalPadding -= rest; diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index e1f2d910d71..cea59f6eeb6 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -5214,7 +5214,7 @@ nsBlockFrame::ReflowFloat(nsBlockReflowState& aState, // needed when prev. float has procentage width // (maybe is a table flaw that makes table chose to round up // but I don't want to change that, too risky) - nscoord twp = aState.mPresContext->IntScaledPixelsToTwips(1); + nscoord twp = nsPresContext::CSSPixelsToAppUnits(1); availWidth -= availWidth % twp; } diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index d6ad5c5914a..80f02c2b02f 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -1462,8 +1462,6 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX, const nsStyleFont* myFont = GetStyleFont(); nsCOMPtr fm = aCX->GetMetricsFor(myFont->mFont); nscoord bulletSize; - float p2t; - float t2p; nsAutoString text; switch (myList->mListStyleType) { @@ -1475,16 +1473,10 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX, case NS_STYLE_LIST_STYLE_DISC: case NS_STYLE_LIST_STYLE_CIRCLE: case NS_STYLE_LIST_STYLE_SQUARE: - t2p = aCX->TwipsToPixels(); fm->GetMaxAscent(ascent); - bulletSize = NSTwipsToIntPixels( - (nscoord)NSToIntRound(0.8f * (float(ascent) / 2.0f)), t2p); - if (bulletSize < MIN_BULLET_SIZE) { - bulletSize = MIN_BULLET_SIZE; - } - p2t = aCX->PixelsToTwips(); - bulletSize = NSIntPixelsToTwips(bulletSize, p2t); - mPadding.bottom = NSIntPixelsToTwips((nscoord) NSToIntRound((float)ascent / (8.0f * p2t)),p2t); + bulletSize = PR_MAX(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE), + NSToCoordRound(0.8f * (float(ascent) / 2.0f))); + mPadding.bottom = NSToCoordRound(float(ascent) / 8.0f); aMetrics.width = mPadding.right + bulletSize; aMetrics.ascent = aMetrics.height = mPadding.bottom + bulletSize; break; @@ -1610,11 +1602,10 @@ NS_IMETHODIMP nsBulletFrame::OnStartContainer(imgIRequest *aRequest, aImage->GetWidth(&w); aImage->GetHeight(&h); - float p2t; nsPresContext* presContext = GetPresContext(); - p2t = presContext->PixelsToTwips(); - nsSize newsize(NSIntPixelsToTwips(w, p2t), NSIntPixelsToTwips(h, p2t)); + nsSize newsize(nsPresContext::CSSPixelsToAppUnits(w), + nsPresContext::CSSPixelsToAppUnits(h)); if (mIntrinsicSize != newsize) { mIntrinsicSize = newsize; diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index dc4ef994c28..df8260ac4eb 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -721,11 +721,10 @@ nsIFrame::GetUsedBorder() const presContext->GetTheme()->GetWidgetBorder(presContext->DeviceContext(), mutable_this, disp->mAppearance, &result); - float p2t = presContext->ScaledPixelsToTwips(); - result.top = NSIntPixelsToTwips(result.top, p2t); - result.right = NSIntPixelsToTwips(result.right, p2t); - result.bottom = NSIntPixelsToTwips(result.bottom, p2t); - result.left = NSIntPixelsToTwips(result.left, p2t); + result.top = presContext->DevPixelsToAppUnits(result.top); + result.right = presContext->DevPixelsToAppUnits(result.right); + result.bottom = presContext->DevPixelsToAppUnits(result.bottom); + result.left = presContext->DevPixelsToAppUnits(result.left); return result; } @@ -752,11 +751,10 @@ nsIFrame::GetUsedPadding() const mutable_this, disp->mAppearance, &padding)) { - float p2t = presContext->ScaledPixelsToTwips(); - padding.top = NSIntPixelsToTwips(padding.top, p2t); - padding.right = NSIntPixelsToTwips(padding.right, p2t); - padding.bottom = NSIntPixelsToTwips(padding.bottom, p2t); - padding.left = NSIntPixelsToTwips(padding.left, p2t); + padding.top = presContext->DevPixelsToAppUnits(padding.top); + padding.right = presContext->DevPixelsToAppUnits(padding.right); + padding.bottom = presContext->DevPixelsToAppUnits(padding.bottom); + padding.left = presContext->DevPixelsToAppUnits(padding.left); return padding; } } @@ -959,7 +957,7 @@ void nsDisplaySelectionOverlay::Paint(nsDisplayListBuilder* aBuilder, nsRect rect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize()); rect.IntersectRect(rect, aDirtyRect); - rect.ScaleRoundOut(mFrame->GetPresContext()->TwipsToPixels()); + rect.ScaleRoundOut(1.0f / mFrame->GetPresContext()->AppUnitsPerDevPixel()); ctx->Rectangle(gfxRect(rect.x, rect.y, rect.width, rect.height), PR_TRUE); ctx->Fill(); #endif @@ -3078,19 +3076,18 @@ nsFrame::IntrinsicWidthOffsets(nsIRenderingContext* aRenderingContext) const nsStyleDisplay *disp = GetStyleDisplay(); if (IsThemed(disp)) { nsPresContext *presContext = GetPresContext(); - float p2t = presContext->ScaledPixelsToTwips(); nsMargin border; presContext->GetTheme()->GetWidgetBorder(presContext->DeviceContext(), this, disp->mAppearance, &border); - result.hBorder = NSIntPixelsToTwips(border.LeftRight(), p2t); + result.hBorder = presContext->DevPixelsToAppUnits(border.LeftRight()); nsMargin padding; if (presContext->GetTheme()->GetWidgetPadding(presContext->DeviceContext(), this, disp->mAppearance, &padding)) { - result.hPadding = NSIntPixelsToTwips(padding.LeftRight(), p2t); + result.hPadding = presContext->DevPixelsToAppUnits(padding.LeftRight()); result.hPctPadding = 0; } } @@ -3190,10 +3187,8 @@ nsFrame::ComputeSize(nsIRenderingContext *aRenderingContext, GetMinimumWidgetSize(aRenderingContext, this, disp->mAppearance, &size, &canOverride); - // GMWS() returns size in pixels, we need to convert it back to twips - float p2t = presContext->ScaledPixelsToTwips(); - size.width = NSIntPixelsToTwips(size.width, p2t); - size.height = NSIntPixelsToTwips(size.height, p2t); + size.width = presContext->DevPixelsToAppUnits(size.width); + size.height = presContext->DevPixelsToAppUnits(size.height); // GMWS() returns border-box; we need content-box size.width -= aBorder.width + aPadding.width; @@ -3525,7 +3520,7 @@ nsIntRect nsIFrame::GetScreenRect() const if (widget) { nsRect ourRect = mRect; ourRect.MoveTo(toViewOffset + toWidgetOffset); - ourRect.ScaleRoundOut(GetPresContext()->TwipsToPixels()); + ourRect.ScaleRoundOut(1.0f / GetPresContext()->AppUnitsPerDevPixel()); // Is it safe to pass the same rect for both args of WidgetToScreen? // It's not clear, so let's not... nsIntRect ourPxRect(ourRect.x, ourRect.y, ourRect.width, ourRect.height); @@ -7129,10 +7124,10 @@ void DR_State::DeleteTreeNode(DR_FrameTreeNode& aNode) static void CheckPixelError(nscoord aSize, - float aPixelToTwips) + PRInt32 aPixelToTwips) { if (NS_UNCONSTRAINEDSIZE != aSize) { - if ((aSize % NSToCoordRound(aPixelToTwips)) > 0) { + if ((aSize % aPixelToTwips) > 0) { printf("VALUE %d is not a whole pixel \n", aSize); } } @@ -7186,7 +7181,7 @@ static void DisplayReflowEnterPrint(nsPresContext* aPresContext, else printf("cnt=%d \n", DR_state->mCount); if (DR_state->mDisplayPixelErrors) { - float p2t = aPresContext->ScaledPixelsToTwips(); + PRInt32 p2t = aPresContext->AppUnitsPerDevPixel(); CheckPixelError(aReflowState.availableWidth, p2t); CheckPixelError(aReflowState.availableHeight, p2t); CheckPixelError(aReflowState.ComputedWidth(), p2t); @@ -7303,7 +7298,7 @@ void nsFrame::DisplayReflowExit(nsPresContext* aPresContext, } printf("\n"); if (DR_state->mDisplayPixelErrors) { - float p2t = aPresContext->ScaledPixelsToTwips(); + PRInt32 p2t = aPresContext->AppUnitsPerDevPixel(); CheckPixelError(aMetrics.width, p2t); CheckPixelError(aMetrics.height, p2t); } diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index 88aa33a71f3..75d2ba7afa4 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -125,9 +125,6 @@ public: virtual void Destroy(); - virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext); - virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext); - NS_IMETHOD Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, @@ -322,13 +319,13 @@ nsSubDocumentFrame::GetIntrinsicWidth() return 0; // has no useful intrinsic width } - if (!mContent->IsNodeOfType(nsINode::eXUL)) { + if (mContent->IsNodeOfType(nsINode::eXUL)) { return 0; // also has no useful intrinsic width } // We must be an HTML