Bug 750846 - Move thumbnail size logic to Gecko. r=blassey
This commit is contained in:
@@ -2256,6 +2256,46 @@ Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *jenv, jclass,
|
||||
|
||||
nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt32 srcY, PRInt32 srcW, PRInt32 srcH, PRInt32 dstW, PRInt32 dstH, PRInt32 tabId, float scale, PRInt32 token)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// 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);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> docElement;
|
||||
rv = doc->GetDocumentElement(getter_AddRefs(docElement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRInt32 viewportWidth;
|
||||
PRInt32 viewportHeight;
|
||||
PRInt32 pageWidth;
|
||||
PRInt32 pageHeight;
|
||||
window->GetInnerWidth(&viewportWidth);
|
||||
window->GetInnerHeight(&viewportHeight);
|
||||
docElement->GetScrollWidth(&pageWidth);
|
||||
docElement->GetScrollHeight(&pageHeight);
|
||||
|
||||
// use the page or viewport dimensions, whichever is larger
|
||||
PRInt32 width;
|
||||
PRInt32 height;
|
||||
width = viewportWidth > pageWidth ? viewportWidth : pageWidth;
|
||||
height = viewportHeight > pageHeight ? viewportHeight : pageHeight;
|
||||
|
||||
if (!width || !height)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
float aspectRatio = ((float) dstW) / dstH;
|
||||
if (width / aspectRatio < height) {
|
||||
srcW = width;
|
||||
srcH = width / aspectRatio;
|
||||
} else {
|
||||
srcW = height * aspectRatio;
|
||||
srcH = height;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
|
||||
if (!win)
|
||||
return NS_ERROR_FAILURE;
|
||||
@@ -2291,7 +2331,7 @@ nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt
|
||||
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(static_cast<unsigned char*>(data), nsIntSize(dstW, dstH), stride, gfxASurface::ImageFormatRGB16_565);
|
||||
nsRefPtr<gfxContext> context = new gfxContext(surf);
|
||||
context->Scale(scale * dstW / srcW, scale * dstH / srcH);
|
||||
nsresult rv = presShell->RenderDocument(r, renderDocFlags, bgColor, context);
|
||||
rv = presShell->RenderDocument(r, renderDocFlags, bgColor, context);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
AndroidBridge::AutoLocalJNIFrame jniFrame(jenv, 1);
|
||||
jenv->CallStaticVoidMethod(AndroidBridge::Bridge()->mGeckoAppShellClass, AndroidBridge::Bridge()->jNotifyScreenShot, buffer, tabId, srcX * dstW / srcW , srcY * dstH / srcH, dstW, dstH, token);
|
||||
|
||||
Reference in New Issue
Block a user