Bug 760458 - When taking thumbnail screenshots account for RTL pages as well. r=bnicholson

This commit is contained in:
Kartikaya Gupta 2012-06-01 20:30:46 -04:00
parent 69dd3f4e84
commit 14d8057fd8

View File

@ -29,6 +29,8 @@
#include "nsIDocShell.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/ScreenOrientation.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDOMClientRect.h"
#ifdef DEBUG
#define ALOG_BRIDGE(args...) ALOG(args)
@ -2358,30 +2360,23 @@ nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt
// take a screenshot, as wide as possible, proportional to the destination size
if (!srcW && !srcH) {
nsCOMPtr<nsIDOMDocument> doc;
rv = window->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
if (!doc)
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
if (!utils)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMElement> docElement;
rv = doc->GetDocumentElement(getter_AddRefs(docElement));
nsCOMPtr<nsIDOMClientRect> rect;
rv = utils->GetRootBounds(getter_AddRefs(rect));
NS_ENSURE_SUCCESS(rv, rv);
if (!docElement)
if (!rect)
return NS_ERROR_FAILURE;
PRInt32 viewportHeight;
PRInt32 pageWidth;
PRInt32 pageHeight;
window->GetInnerHeight(&viewportHeight);
docElement->GetScrollWidth(&pageWidth);
docElement->GetScrollHeight(&pageHeight);
float left, top, width, height;
rect->GetLeft(&left);
rect->GetTop(&top);
rect->GetWidth(&width);
rect->GetHeight(&height);
// use the page or viewport dimensions, whichever is larger
PRInt32 width = pageWidth;
PRInt32 height = viewportHeight > pageHeight ? viewportHeight : pageHeight;
if (!width || !height)
if (width == 0 || height == 0)
return NS_ERROR_FAILURE;
float aspectRatio = ((float) dstW) / dstH;
@ -2392,6 +2387,9 @@ nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt
srcW = height * aspectRatio;
srcH = height;
}
srcX = left;
srcY = top;
}
JNIEnv* env = GetJNIEnv();