Bug 1748835 [wpt PR 32273] - Avoid reftest-wait timeout if ::target-text is unsupport...
[gecko.git] / layout / svg / SVGImageContext.cpp
blob32238550ecf4149e94118f71962b2e467fcb3133
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/Preferences.h"
13 #include "nsIFrame.h"
14 #include "nsPresContext.h"
15 #include "nsStyleStruct.h"
17 namespace mozilla {
19 /* static */
20 void SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
21 nsIFrame* aFromFrame,
22 imgIContainer* aImgContainer) {
23 return MaybeStoreContextPaint(aContext, aFromFrame->Style(), aImgContainer);
26 /* static */
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.
35 return;
38 if (aImgContainer->GetType() != imgIContainer::TYPE_VECTOR) {
39 // Avoid this overhead for raster images.
40 return;
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()
64 : 1.0f);
66 if (style->mMozContextProperties.bits &
67 StyleContextPropertyBits::STROKE_OPACITY) {
68 haveContextPaint = true;
69 contextPaint->SetStrokeOpacity(style->mStrokeOpacity.IsOpacity()
70 ? style->mStrokeOpacity.AsOpacity()
71 : 1.0f);
74 if (haveContextPaint) {
75 if (!aContext) {
76 aContext.emplace();
78 aContext->mContextPaint = std::move(contextPaint);
82 } // namespace mozilla