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/. */
8 #include "SVGImageContext.h"
10 // Keep others in (case-insensitive) order:
12 #include "mozilla/Preferences.h"
14 #include "nsPresContext.h"
15 #include "nsStyleStruct.h"
20 void SVGImageContext::MaybeStoreContextPaint(Maybe
<SVGImageContext
>& aContext
,
22 imgIContainer
* aImgContainer
) {
23 return MaybeStoreContextPaint(aContext
, aFromFrame
->Style(), aImgContainer
);
27 void SVGImageContext::MaybeStoreContextPaint(
28 Maybe
<SVGImageContext
>& aContext
, const ComputedStyle
* aFromComputedStyle
,
29 imgIContainer
* aImgContainer
) {
30 const nsStyleSVG
* style
= aFromComputedStyle
->StyleSVG();
32 if (!style
->ExposesContextProperties()) {
33 // Content must have '-moz-context-properties' set to the names of the
34 // properties it wants to expose to images it links to.
38 if (aImgContainer
->GetType() != imgIContainer::TYPE_VECTOR
) {
39 // Avoid this overhead for raster images.
43 bool haveContextPaint
= false;
45 auto contextPaint
= MakeRefPtr
<SVGEmbeddingContextPaint
>();
47 if ((style
->mMozContextProperties
.bits
& StyleContextPropertyBits::FILL
) &&
48 style
->mFill
.kind
.IsColor()) {
49 haveContextPaint
= true;
50 contextPaint
->SetFill(
51 style
->mFill
.kind
.AsColor().CalcColor(*aFromComputedStyle
));
53 if ((style
->mMozContextProperties
.bits
& StyleContextPropertyBits::STROKE
) &&
54 style
->mStroke
.kind
.IsColor()) {
55 haveContextPaint
= true;
56 contextPaint
->SetStroke(
57 style
->mStroke
.kind
.AsColor().CalcColor(*aFromComputedStyle
));
59 if (style
->mMozContextProperties
.bits
&
60 StyleContextPropertyBits::FILL_OPACITY
) {
61 haveContextPaint
= true;
62 contextPaint
->SetFillOpacity(style
->mFillOpacity
.IsOpacity()
63 ? style
->mFillOpacity
.AsOpacity()
66 if (style
->mMozContextProperties
.bits
&
67 StyleContextPropertyBits::STROKE_OPACITY
) {
68 haveContextPaint
= true;
69 contextPaint
->SetStrokeOpacity(style
->mStrokeOpacity
.IsOpacity()
70 ? style
->mStrokeOpacity
.AsOpacity()
74 if (haveContextPaint
) {
78 aContext
->mContextPaint
= std::move(contextPaint
);
82 } // namespace mozilla