2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "mozilla/ipc/DocumentRendererChild.h"
|
|
|
|
|
2009-11-04 21:11:33 -08:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-12-26 10:06:53 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "gfxPattern.h"
|
2014-03-31 04:52:33 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2012-06-06 00:42:47 -07:00
|
|
|
#include "nsIDocShell.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-03-08 12:16:41 -08:00
|
|
|
#include "nsCSSParser.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-30 14:26:04 -07:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsRuleNode.h"
|
2013-12-26 10:06:53 -08:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2009-11-04 21:11:33 -08:00
|
|
|
|
2013-12-26 10:06:53 -08:00
|
|
|
using namespace mozilla;
|
2014-03-31 04:52:33 -07:00
|
|
|
using namespace mozilla::gfx;
|
2009-10-29 10:58:31 -07:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
DocumentRendererChild::DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DocumentRendererChild::~DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool
|
2010-10-26 15:20:53 -07:00
|
|
|
DocumentRendererChild::RenderDocument(nsIDOMWindow *window,
|
|
|
|
const nsRect& documentRect,
|
2013-12-26 10:06:53 -08:00
|
|
|
const mozilla::gfx::Matrix& transform,
|
2012-06-06 00:36:38 -07:00
|
|
|
const nsString& aBGColor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t renderFlags,
|
2013-12-26 10:06:53 -08:00
|
|
|
bool flushLayout,
|
2010-10-26 15:20:53 -07:00
|
|
|
const nsIntSize& renderSize,
|
|
|
|
nsCString& data)
|
2009-10-29 10:58:31 -07:00
|
|
|
{
|
2010-10-26 15:20:53 -07:00
|
|
|
if (flushLayout)
|
2010-11-03 05:57:15 -07:00
|
|
|
nsContentUtils::FlushLayoutForTree(window);
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2009-10-29 10:58:31 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
|
|
|
|
if (win) {
|
|
|
|
nsIDocShell* docshell = win->GetDocShell();
|
|
|
|
if (docshell) {
|
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!presContext)
|
|
|
|
return false;
|
|
|
|
|
2010-03-08 12:16:41 -08:00
|
|
|
nsCSSParser parser;
|
2012-06-06 00:36:38 -07:00
|
|
|
nsCSSValue bgColorValue;
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) {
|
2009-10-29 10:58:31 -07:00
|
|
|
return false;
|
2012-06-06 00:36:38 -07:00
|
|
|
}
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2012-06-06 00:36:38 -07:00
|
|
|
nscolor bgColor;
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
|
2012-06-06 00:36:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-29 10:58:31 -07:00
|
|
|
|
|
|
|
// Draw directly into the output array.
|
2010-10-26 15:20:53 -07:00
|
|
|
data.SetLength(renderSize.width * renderSize.height * 4);
|
|
|
|
|
2014-03-31 04:52:33 -07:00
|
|
|
RefPtr<DrawTarget> dt =
|
|
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
|
|
reinterpret_cast<uint8_t*>(data.BeginWriting()),
|
|
|
|
IntSize(renderSize.width, renderSize.height),
|
|
|
|
4 * renderSize.width,
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(dt);
|
2013-12-26 10:06:53 -08:00
|
|
|
ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform));
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2012-10-26 18:02:57 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
|
|
|
|
shell->RenderDocument(documentRect, renderFlags, bgColor, ctx);
|
2009-10-29 10:58:31 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|