Bug 401361 - Draw correctly when drawWindow is called on a window using fullZoom [p=roc r+sr=vlad a=blocking1.9+]
authorreed@reedloden.com
Wed, 07 Nov 2007 20:43:36 -0800
changeset 7683 fd373e6a5ca57fb22af3dc3032f07b0a056d5b35
parent 7682 2a79b0420001d7beee0fa68133b1b8c8619e5da6
child 7684 d4caa41a45de98fbeb7da059d497ca4709f4fb78
push idunknown
push userunknown
push dateunknown
reviewersblocking1.9
bugs401361
milestone1.9b2pre
Bug 401361 - Draw correctly when drawWindow is called on a window using fullZoom [p=roc r+sr=vlad a=blocking1.9+]
layout/base/nsIPresShell.h
layout/base/nsPresShell.cpp
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -689,25 +689,27 @@ public:
   /**
    * Render the document into an arbitrary gfxContext
    * Designed for getting a picture of a document or a piece of a document
    * Note that callers will generally want to call FlushPendingNotifications
    * to get an up-to-date view of the document
    * @param aRect is the region to capture into the offscreen buffer, in the
    * root frame's coordinate system (if aIgnoreViewportScrolling is false)
    * or in the root scrolled frame's coordinate system
-   * (if aIgnoreViewportScrolling is true)
+   * (if aIgnoreViewportScrolling is true). The coordinates are in appunits.
    * @param aUntrusted set to PR_TRUE if the contents may be passed to malicious
    * agents. E.g. we might choose not to paint the contents of sensitive widgets
    * such as the file name in a file upload widget, and we might choose not
    * to paint themes.
    * @param aIgnoreViewportScrolling ignore clipping/scrolling/scrollbar painting
    * due to scrolling in the viewport
    * @param aBackgroundColor a background color to render onto
-   * @param aRenderedContext the gfxContext to render to
+   * @param aRenderedContext the gfxContext to render to. We render so that
+   * one CSS pixel in the source document is rendered to one unit in the current
+   * transform.
    */
   NS_IMETHOD RenderDocument(const nsRect& aRect, PRBool aUntrusted,
                             PRBool aIgnoreViewportScrolling,
                             nscolor aBackgroundColor,
                             gfxContext* aRenderedContext) = 0;
 
   /**
    * Renders a node aNode to a surface and returns it. The aRegion may be used
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -4794,16 +4794,22 @@ PresShell::ComputeRepaintRegionForCopy(n
 NS_IMETHODIMP
 PresShell::RenderDocument(const nsRect& aRect, PRBool aUntrusted,
                           PRBool aIgnoreViewportScrolling,
                           nscolor aBackgroundColor,
                           gfxContext* aThebesContext)
 {
   NS_ENSURE_TRUE(!aUntrusted, NS_ERROR_NOT_IMPLEMENTED);
 
+  gfxRect r(0, 0,
+            nsPresContext::AppUnitsToFloatCSSPixels(aRect.width),
+            nsPresContext::AppUnitsToFloatCSSPixels(aRect.height));
+  aThebesContext->Save();
+  aThebesContext->Clip(r);
+
   aThebesContext->PushGroup(NS_GET_A(aBackgroundColor) == 0xff ?
                             gfxASurface::CONTENT_COLOR :
                             gfxASurface::CONTENT_COLOR_ALPHA);
 
   aThebesContext->Save();
 
   // draw background color
   if (NS_GET_A(aBackgroundColor) > 0) {
@@ -4834,20 +4840,23 @@ PresShell::RenderDocument(const nsRect& 
 
     nsresult rv = rootFrame->BuildDisplayListForStackingContext(&builder, rect, &list);   
 
     builder.LeavePresShell(rootFrame, rect);
 
     if (NS_SUCCEEDED(rv)) {
       // Ensure that r.x,r.y gets drawn at (0,0)
       aThebesContext->Save();
-      aThebesContext->Translate(gfxPoint(-mPresContext->AppUnitsToGfxUnits(rect.x),
-                                         -mPresContext->AppUnitsToGfxUnits(rect.y)));
+      aThebesContext->Translate(gfxPoint(-nsPresContext::AppUnitsToFloatCSSPixels(rect.x),
+                                         -nsPresContext::AppUnitsToFloatCSSPixels(rect.y)));
 
       nsIDeviceContext* devCtx = mPresContext->DeviceContext();
+      gfxFloat scale = gfxFloat(devCtx->AppUnitsPerDevPixel())/nsPresContext::AppUnitsPerCSSPixel();
+      aThebesContext->Scale(scale, scale);
+      
       nsCOMPtr<nsIRenderingContext> rc;
       devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc));
       rc->Init(devCtx, aThebesContext);
 
       nsRegion region(rect);
       list.OptimizeVisibility(&builder, &region);
       list.Paint(&builder, rc, rect);
       // Flush the list so we don't trigger the IsEmpty-on-destruction assertion
@@ -4856,16 +4865,18 @@ PresShell::RenderDocument(const nsRect& 
       aThebesContext->Restore();
     }
   }
 
   aThebesContext->Restore();
   aThebesContext->PopGroupToSource();
   aThebesContext->Paint();
 
+  aThebesContext->Restore();
+
   return NS_OK;
 }
 
 /*
  * Clip the display list aList to a range. Returns the clipped
  * rectangle surrounding the range.
  */
 nsRect