no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / layout / svg / SVGImageContext.cpp
blobb256d3cf292ea1ac1a3d273c6ad77ff082472589
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/. */
7 // Main header first:
8 #include "SVGImageContext.h"
10 // Keep others in (case-insensitive) order:
11 #include "gfxUtils.h"
12 #include "mozilla/LookAndFeel.h"
13 #include "mozilla/StaticPrefs_svg.h"
14 #include "mozilla/dom/Document.h"
15 #include "nsIFrame.h"
16 #include "nsPresContext.h"
17 #include "nsStyleStruct.h"
19 namespace mozilla {
21 /* static */
22 void SVGImageContext::MaybeStoreContextPaint(SVGImageContext& aContext,
23 nsIFrame* aFromFrame,
24 imgIContainer* aImgContainer) {
25 return MaybeStoreContextPaint(aContext, *aFromFrame->PresContext(),
26 *aFromFrame->Style(), aImgContainer);
29 /* static */
30 void SVGImageContext::MaybeStoreContextPaint(SVGImageContext& aContext,
31 const nsPresContext& aPresContext,
32 const ComputedStyle& aStyle,
33 imgIContainer* aImgContainer) {
34 if (aImgContainer->GetType() != imgIContainer::TYPE_VECTOR) {
35 // Avoid this overhead for raster images.
36 return;
39 if (StaticPrefs::svg_embedder_prefers_color_scheme_content_enabled() ||
40 aPresContext.Document()->ChromeRulesEnabled()) {
41 auto scheme = LookAndFeel::ColorSchemeForStyle(
42 *aPresContext.Document(), aStyle.StyleUI()->mColorScheme.bits,
43 ColorSchemeMode::Preferred);
44 aContext.SetColorScheme(Some(scheme));
47 const nsStyleSVG* style = aStyle.StyleSVG();
48 if (!style->ExposesContextProperties()) {
49 // Content must have '-moz-context-properties' set to the names of the
50 // properties it wants to expose to images it links to.
51 return;
54 bool haveContextPaint = false;
56 auto contextPaint = MakeRefPtr<SVGEmbeddingContextPaint>();
58 if ((style->mMozContextProperties.bits & StyleContextPropertyBits::FILL) &&
59 style->mFill.kind.IsColor()) {
60 haveContextPaint = true;
61 contextPaint->SetFill(style->mFill.kind.AsColor().CalcColor(aStyle));
63 if ((style->mMozContextProperties.bits & StyleContextPropertyBits::STROKE) &&
64 style->mStroke.kind.IsColor()) {
65 haveContextPaint = true;
66 contextPaint->SetStroke(style->mStroke.kind.AsColor().CalcColor(aStyle));
68 if (style->mMozContextProperties.bits &
69 StyleContextPropertyBits::FILL_OPACITY) {
70 haveContextPaint = true;
71 contextPaint->SetFillOpacity(style->mFillOpacity.IsOpacity()
72 ? style->mFillOpacity.AsOpacity()
73 : 1.0f);
75 if (style->mMozContextProperties.bits &
76 StyleContextPropertyBits::STROKE_OPACITY) {
77 haveContextPaint = true;
78 contextPaint->SetStrokeOpacity(style->mStrokeOpacity.IsOpacity()
79 ? style->mStrokeOpacity.AsOpacity()
80 : 1.0f);
83 if (haveContextPaint) {
84 aContext.mContextPaint = std::move(contextPaint);
88 } // namespace mozilla