Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/svg/SVGImageContext.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
8
// Main header first:
9
#include "SVGImageContext.h"
10
11
// Keep others in (case-insensitive) order:
12
#include "gfxUtils.h"
13
#include "mozilla/Preferences.h"
14
#include "nsIFrame.h"
15
#include "nsPresContext.h"
16
#include "nsStyleStruct.h"
17
18
namespace mozilla {
19
20
/* static */ void
21
SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
22
                                        nsIFrame* aFromFrame,
23
                                        imgIContainer* aImgContainer)
24
0
{
25
0
  return MaybeStoreContextPaint(aContext,
26
0
                                aFromFrame->Style(),
27
0
                                aImgContainer);
28
0
}
29
30
/* static */ void
31
SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
32
                                        ComputedStyle* aFromComputedStyle,
33
                                        imgIContainer* aImgContainer)
34
0
{
35
0
  const nsStyleSVG* style = aFromComputedStyle->StyleSVG();
36
0
37
0
  if (!style->ExposesContextProperties()) {
38
0
    // Content must have '-moz-context-properties' set to the names of the
39
0
    // properties it wants to expose to images it links to.
40
0
    return;
41
0
  }
42
0
43
0
  if (aImgContainer->GetType() != imgIContainer::TYPE_VECTOR) {
44
0
    // Avoid this overhead for raster images.
45
0
    return;
46
0
  }
47
0
48
0
  bool haveContextPaint = false;
49
0
50
0
  RefPtr<SVGEmbeddingContextPaint> contextPaint = new SVGEmbeddingContextPaint();
51
0
52
0
  if ((style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_FILL) &&
53
0
      style->mFill.Type() == eStyleSVGPaintType_Color) {
54
0
    haveContextPaint = true;
55
0
    contextPaint->SetFill(style->mFill.GetColor(aFromComputedStyle));
56
0
  }
57
0
  if ((style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_STROKE) &&
58
0
      style->mStroke.Type() == eStyleSVGPaintType_Color) {
59
0
    haveContextPaint = true;
60
0
    contextPaint->SetStroke(style->mStroke.GetColor(aFromComputedStyle));
61
0
  }
62
0
  if (style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY) {
63
0
    haveContextPaint = true;
64
0
    contextPaint->SetFillOpacity(style->mFillOpacity);
65
0
  }
66
0
  if (style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY) {
67
0
    haveContextPaint = true;
68
0
    contextPaint->SetStrokeOpacity(style->mStrokeOpacity);
69
0
  }
70
0
71
0
  if (haveContextPaint) {
72
0
    if (!aContext) {
73
0
      aContext.emplace();
74
0
    }
75
0
    aContext->mContextPaint = contextPaint.forget();
76
0
  }
77
0
}
78
79
} // namespace mozilla