content/canvas/src/DocumentRendererChild.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial