Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / image / AutoRestoreSVGState.h
blob9bb4ff6b97b4d65d79844e9bdc4471705dbc1ef0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_image_AutoRestoreSVGState_h
7 #define mozilla_image_AutoRestoreSVGState_h
9 #include "mozilla/Attributes.h"
10 #include "mozilla/AutoRestore.h"
11 #include "mozilla/SVGContextPaint.h"
12 #include "mozilla/dom/SVGSVGElement.h"
13 #include "SVGDrawingParameters.h"
14 #include "SVGDocumentWrapper.h"
16 namespace mozilla {
17 namespace image {
19 class MOZ_STACK_CLASS AutoRestoreSVGState final {
20 public:
21 AutoRestoreSVGState(const SVGDrawingParameters& aParams,
22 SVGDocumentWrapper* aSVGDocumentWrapper,
23 bool aContextPaint)
24 : AutoRestoreSVGState(aParams.svgContext, aParams.animationTime,
25 aSVGDocumentWrapper, aContextPaint) {}
27 AutoRestoreSVGState(const Maybe<SVGImageContext>& aSVGContext,
28 float aAnimationTime,
29 SVGDocumentWrapper* aSVGDocumentWrapper,
30 bool aContextPaint)
31 : mIsDrawing(aSVGDocumentWrapper->mIsDrawing)
32 // Apply any 'preserveAspectRatio' override (if specified) to the root
33 // element:
35 mPAR(aSVGContext, aSVGDocumentWrapper->GetRootSVGElem())
36 // Set the animation time:
38 mTime(aSVGDocumentWrapper->GetRootSVGElem(), aAnimationTime) {
39 MOZ_ASSERT(!mIsDrawing.SavedValue());
40 MOZ_ASSERT(aSVGDocumentWrapper->GetDocument());
42 aSVGDocumentWrapper->mIsDrawing = true;
44 // Set context paint (if specified) on the document:
45 if (aContextPaint) {
46 MOZ_ASSERT(aSVGContext->GetContextPaint());
47 mContextPaint.emplace(*aSVGContext->GetContextPaint(),
48 *aSVGDocumentWrapper->GetDocument());
52 private:
53 AutoRestore<bool> mIsDrawing;
54 AutoPreserveAspectRatioOverride mPAR;
55 AutoSVGTimeSetRestore mTime;
56 Maybe<AutoSetRestoreSVGContextPaint> mContextPaint;
59 } // namespace image
60 } // namespace mozilla
62 #endif // mozilla_image_AutoRestoreSVGState_h