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