diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /image/AutoRestoreSVGState.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'image/AutoRestoreSVGState.h')
-rw-r--r-- | image/AutoRestoreSVGState.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/image/AutoRestoreSVGState.h b/image/AutoRestoreSVGState.h new file mode 100644 index 0000000000..c01c2f612b --- /dev/null +++ b/image/AutoRestoreSVGState.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_image_AutoRestoreSVGState_h +#define mozilla_image_AutoRestoreSVGState_h + +#include "mozilla/Attributes.h" +#include "mozilla/AutoRestore.h" +#include "mozilla/SVGContextPaint.h" +#include "mozilla/dom/SVGSVGElement.h" +#include "nsPresContext.h" +#include "SVGDrawingParameters.h" +#include "SVGDocumentWrapper.h" +#include "mozilla/dom/DocumentInlines.h" +#include "mozilla/dom/SVGDocument.h" +#include "mozilla/dom/BrowsingContextBinding.h" + +namespace mozilla::image { + +class MOZ_STACK_CLASS AutoRestoreSVGState final { + public: + AutoRestoreSVGState(const SVGDrawingParameters& aParams, + SVGDocumentWrapper* aSVGDocumentWrapper, + bool aContextPaint) + : AutoRestoreSVGState(aParams.svgContext, aParams.animationTime, + aSVGDocumentWrapper, aContextPaint) {} + + AutoRestoreSVGState(const SVGImageContext& aSVGContext, float aAnimationTime, + SVGDocumentWrapper* aSVGDocumentWrapper, + bool aContextPaint) + : mIsDrawing(aSVGDocumentWrapper->mIsDrawing), + // Apply any 'preserveAspectRatio' override (if specified) to the root + // element: + mPAR(aSVGContext, aSVGDocumentWrapper->GetRootSVGElem()), + // Set the animation time: + mTime(aSVGDocumentWrapper->GetRootSVGElem(), aAnimationTime) { + MOZ_ASSERT(!mIsDrawing.SavedValue()); + MOZ_ASSERT(aSVGDocumentWrapper->GetDocument()); + + if (auto* pc = aSVGDocumentWrapper->GetDocument()->GetPresContext()) { + pc->SetColorSchemeOverride([&] { + if (auto scheme = aSVGContext.GetColorScheme()) { + return *scheme == ColorScheme::Light + ? dom::PrefersColorSchemeOverride::Light + : dom::PrefersColorSchemeOverride::Dark; + } + return dom::PrefersColorSchemeOverride::None; + }()); + } + + aSVGDocumentWrapper->mIsDrawing = true; + + // Set context paint (if specified) on the document: + if (aContextPaint) { + MOZ_ASSERT(aSVGContext.GetContextPaint()); + mContextPaint.emplace(aSVGContext.GetContextPaint(), + aSVGDocumentWrapper->GetDocument()); + } + } + + private: + AutoRestore<bool> mIsDrawing; + AutoPreserveAspectRatioOverride mPAR; + AutoSVGTimeSetRestore mTime; + Maybe<AutoSetRestoreSVGContextPaint> mContextPaint; +}; + +} // namespace mozilla::image + +#endif // mozilla_image_AutoRestoreSVGState_h |