michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ipc/DocumentRendererChild.h" michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: #include "gfx2DGlue.h" michael@0: #include "gfxPattern.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsPIDOMWindow.h" michael@0: #include "nsIDOMWindow.h" michael@0: #include "nsIDocShell.h" michael@0: #include "nsIInterfaceRequestorUtils.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsCSSParser.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsColor.h" michael@0: #include "gfxContext.h" michael@0: #include "nsLayoutUtils.h" michael@0: #include "nsContentUtils.h" michael@0: #include "nsCSSValue.h" michael@0: #include "nsRuleNode.h" michael@0: #include "mozilla/gfx/Matrix.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::gfx; michael@0: using namespace mozilla::ipc; michael@0: michael@0: DocumentRendererChild::DocumentRendererChild() michael@0: {} michael@0: michael@0: DocumentRendererChild::~DocumentRendererChild() michael@0: {} michael@0: michael@0: bool michael@0: DocumentRendererChild::RenderDocument(nsIDOMWindow *window, michael@0: const nsRect& documentRect, michael@0: const mozilla::gfx::Matrix& transform, michael@0: const nsString& aBGColor, michael@0: uint32_t renderFlags, michael@0: bool flushLayout, michael@0: const nsIntSize& renderSize, michael@0: nsCString& data) michael@0: { michael@0: if (flushLayout) michael@0: nsContentUtils::FlushLayoutForTree(window); michael@0: michael@0: nsRefPtr presContext; michael@0: nsCOMPtr win = do_QueryInterface(window); michael@0: if (win) { michael@0: nsIDocShell* docshell = win->GetDocShell(); michael@0: if (docshell) { michael@0: docshell->GetPresContext(getter_AddRefs(presContext)); michael@0: } michael@0: } michael@0: if (!presContext) michael@0: return false; michael@0: michael@0: nsCSSParser parser; michael@0: nsCSSValue bgColorValue; michael@0: if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) { michael@0: return false; michael@0: } michael@0: michael@0: nscolor bgColor; michael@0: if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) { michael@0: return false; michael@0: } michael@0: michael@0: // Draw directly into the output array. michael@0: data.SetLength(renderSize.width * renderSize.height * 4); michael@0: michael@0: RefPtr dt = michael@0: Factory::CreateDrawTargetForData(BackendType::CAIRO, michael@0: reinterpret_cast(data.BeginWriting()), michael@0: IntSize(renderSize.width, renderSize.height), michael@0: 4 * renderSize.width, michael@0: SurfaceFormat::B8G8R8A8); michael@0: nsRefPtr ctx = new gfxContext(dt); michael@0: ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform)); michael@0: michael@0: nsCOMPtr shell = presContext->PresShell(); michael@0: shell->RenderDocument(documentRect, renderFlags, bgColor, ctx); michael@0: michael@0: return true; michael@0: }