2012-05-21 11:12:37 +00: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 17:58:31 +00:00
|
|
|
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "mozilla/ipc/DocumentRendererChild.h"
|
|
|
|
|
2009-11-05 05:11:33 +00:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-12-26 18:06:53 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "gfxPattern.h"
|
2014-03-31 11:52:33 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2012-06-06 07:42:47 +00:00
|
|
|
#include "nsIDocShell.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-03-08 20:16:41 +00:00
|
|
|
#include "nsCSSParser.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-30 21:26:04 +00:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsRuleNode.h"
|
2013-12-26 18:06:53 +00:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2009-11-05 05:11:33 +00:00
|
|
|
|
2013-12-26 18:06:53 +00:00
|
|
|
using namespace mozilla;
|
2014-03-31 11:52:33 +00:00
|
|
|
using namespace mozilla::gfx;
|
2009-10-29 17:58:31 +00:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
DocumentRendererChild::DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DocumentRendererChild::~DocumentRendererChild()
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool
|
2010-10-26 22:20:53 +00:00
|
|
|
DocumentRendererChild::RenderDocument(nsIDOMWindow *window,
|
|
|
|
const nsRect& documentRect,
|
2013-12-26 18:06:53 +00:00
|
|
|
const mozilla::gfx::Matrix& transform,
|
2012-06-06 07:36:38 +00:00
|
|
|
const nsString& aBGColor,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t renderFlags,
|
2013-12-26 18:06:53 +00:00
|
|
|
bool flushLayout,
|
2010-10-26 22:20:53 +00:00
|
|
|
const nsIntSize& renderSize,
|
|
|
|
nsCString& data)
|
2009-10-29 17:58:31 +00:00
|
|
|
{
|
2010-10-26 22:20:53 +00:00
|
|
|
if (flushLayout)
|
2010-11-03 12:57:15 +00:00
|
|
|
nsContentUtils::FlushLayoutForTree(window);
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2014-03-18 00:23:03 +00:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2009-10-29 17:58:31 +00: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 20:16:41 +00:00
|
|
|
nsCSSParser parser;
|
2012-06-06 07:36:38 +00:00
|
|
|
nsCSSValue bgColorValue;
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) {
|
2009-10-29 17:58:31 +00:00
|
|
|
return false;
|
2012-06-06 07:36:38 +00:00
|
|
|
}
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2012-06-06 07:36:38 +00:00
|
|
|
nscolor bgColor;
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) {
|
2012-06-06 07:36:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-29 17:58:31 +00:00
|
|
|
|
|
|
|
// Draw directly into the output array.
|
2010-10-26 22:20:53 +00:00
|
|
|
data.SetLength(renderSize.width * renderSize.height * 4);
|
|
|
|
|
2014-03-31 11:52:33 +00: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 18:06:53 +00:00
|
|
|
ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform));
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2012-10-27 01:02:57 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
|
|
|
|
shell->RenderDocument(documentRect, renderFlags, bgColor, ctx);
|
2009-10-29 17:58:31 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|