Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mozilla/ipc/DocumentRendererChild.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/basictypes.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "gfx2DGlue.h" |
michael@0 | 10 | #include "gfxPattern.h" |
michael@0 | 11 | #include "mozilla/gfx/2D.h" |
michael@0 | 12 | #include "mozilla/RefPtr.h" |
michael@0 | 13 | #include "nsPIDOMWindow.h" |
michael@0 | 14 | #include "nsIDOMWindow.h" |
michael@0 | 15 | #include "nsIDocShell.h" |
michael@0 | 16 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 17 | #include "nsComponentManagerUtils.h" |
michael@0 | 18 | #include "nsCSSParser.h" |
michael@0 | 19 | #include "nsPresContext.h" |
michael@0 | 20 | #include "nsCOMPtr.h" |
michael@0 | 21 | #include "nsColor.h" |
michael@0 | 22 | #include "gfxContext.h" |
michael@0 | 23 | #include "nsLayoutUtils.h" |
michael@0 | 24 | #include "nsContentUtils.h" |
michael@0 | 25 | #include "nsCSSValue.h" |
michael@0 | 26 | #include "nsRuleNode.h" |
michael@0 | 27 | #include "mozilla/gfx/Matrix.h" |
michael@0 | 28 | |
michael@0 | 29 | using namespace mozilla; |
michael@0 | 30 | using namespace mozilla::gfx; |
michael@0 | 31 | using namespace mozilla::ipc; |
michael@0 | 32 | |
michael@0 | 33 | DocumentRendererChild::DocumentRendererChild() |
michael@0 | 34 | {} |
michael@0 | 35 | |
michael@0 | 36 | DocumentRendererChild::~DocumentRendererChild() |
michael@0 | 37 | {} |
michael@0 | 38 | |
michael@0 | 39 | bool |
michael@0 | 40 | DocumentRendererChild::RenderDocument(nsIDOMWindow *window, |
michael@0 | 41 | const nsRect& documentRect, |
michael@0 | 42 | const mozilla::gfx::Matrix& transform, |
michael@0 | 43 | const nsString& aBGColor, |
michael@0 | 44 | uint32_t renderFlags, |
michael@0 | 45 | bool flushLayout, |
michael@0 | 46 | const nsIntSize& renderSize, |
michael@0 | 47 | nsCString& data) |
michael@0 | 48 | { |
michael@0 | 49 | if (flushLayout) |
michael@0 | 50 | nsContentUtils::FlushLayoutForTree(window); |
michael@0 | 51 | |
michael@0 | 52 | nsRefPtr<nsPresContext> presContext; |
michael@0 | 53 | nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window); |
michael@0 | 54 | if (win) { |
michael@0 | 55 | nsIDocShell* docshell = win->GetDocShell(); |
michael@0 | 56 | if (docshell) { |
michael@0 | 57 | docshell->GetPresContext(getter_AddRefs(presContext)); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | if (!presContext) |
michael@0 | 61 | return false; |
michael@0 | 62 | |
michael@0 | 63 | nsCSSParser parser; |
michael@0 | 64 | nsCSSValue bgColorValue; |
michael@0 | 65 | if (!parser.ParseColorString(aBGColor, nullptr, 0, bgColorValue)) { |
michael@0 | 66 | return false; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | nscolor bgColor; |
michael@0 | 70 | if (!nsRuleNode::ComputeColor(bgColorValue, presContext, nullptr, bgColor)) { |
michael@0 | 71 | return false; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | // Draw directly into the output array. |
michael@0 | 75 | data.SetLength(renderSize.width * renderSize.height * 4); |
michael@0 | 76 | |
michael@0 | 77 | RefPtr<DrawTarget> dt = |
michael@0 | 78 | Factory::CreateDrawTargetForData(BackendType::CAIRO, |
michael@0 | 79 | reinterpret_cast<uint8_t*>(data.BeginWriting()), |
michael@0 | 80 | IntSize(renderSize.width, renderSize.height), |
michael@0 | 81 | 4 * renderSize.width, |
michael@0 | 82 | SurfaceFormat::B8G8R8A8); |
michael@0 | 83 | nsRefPtr<gfxContext> ctx = new gfxContext(dt); |
michael@0 | 84 | ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform)); |
michael@0 | 85 | |
michael@0 | 86 | nsCOMPtr<nsIPresShell> shell = presContext->PresShell(); |
michael@0 | 87 | shell->RenderDocument(documentRect, renderFlags, bgColor, ctx); |
michael@0 | 88 | |
michael@0 | 89 | return true; |
michael@0 | 90 | } |