Bug 1605894 reduce the proliferation of DefaultLoopbackTone to only AudioStreamFlowin...
[gecko.git] / image / SVGDocumentWrapper.h
blob75924a4ea58166a2714b6a56cf4386aa3a72b605
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 /* This class wraps an SVG document, for use by VectorImage objects. */
8 #ifndef mozilla_image_SVGDocumentWrapper_h
9 #define mozilla_image_SVGDocumentWrapper_h
11 #include "mozilla/Attributes.h"
13 #include "nsCOMPtr.h"
14 #include "nsIStreamListener.h"
15 #include "nsIObserver.h"
16 #include "nsIContentViewer.h"
17 #include "nsWeakReference.h"
18 #include "nsSize.h"
20 class nsIRequest;
21 class nsILoadGroup;
22 class nsIFrame;
24 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
26 namespace mozilla {
27 class PresShell;
28 namespace dom {
29 class SVGSVGElement;
30 class SVGDocument;
31 } // namespace dom
33 namespace image {
34 class AutoRestoreSVGState;
36 class SVGDocumentWrapper final : public nsIStreamListener,
37 public nsIObserver,
38 public nsSupportsWeakReference {
39 public:
40 SVGDocumentWrapper();
42 NS_DECL_ISUPPORTS
43 NS_DECL_NSISTREAMLISTENER
44 NS_DECL_NSIREQUESTOBSERVER
45 NS_DECL_NSIOBSERVER
47 enum Dimension { eWidth, eHeight };
49 /**
50 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
52 mozilla::dom::SVGDocument* GetDocument();
54 /**
55 * Returns the root <svg> element for the wrapped document, or nullptr on
56 * failure.
58 mozilla::dom::SVGSVGElement* GetRootSVGElem();
60 /**
61 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
63 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
65 nsIFrame* GetRootLayoutFrame();
67 /**
68 * Returns the mozilla::PresShell for the wrapped document.
70 inline mozilla::PresShell* GetPresShell() { return mViewer->GetPresShell(); }
72 /**
73 * Modifier to update the viewport dimensions of the wrapped document. This
74 * method performs a synchronous "FlushType::Layout" on the wrapped document,
75 * since a viewport-change affects layout.
77 * @param aViewportSize The new viewport dimensions.
79 void UpdateViewportBounds(const nsIntSize& aViewportSize);
81 /**
82 * If an SVG image's helper document has a pending notification for an
83 * override on the root node's "preserveAspectRatio" attribute, then this
84 * method will flush that notification so that the image can paint correctly.
85 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
86 * notify the image's observers and trigger unwanted repaint-requests.)
88 void FlushImageTransformInvalidation();
90 /**
91 * Returns a bool indicating whether the document has any SMIL animations.
93 * @return true if the document has any SMIL animations. Else, false.
95 bool IsAnimated();
97 /**
98 * Indicates whether we should currently ignore rendering invalidations sent
99 * from the wrapped SVG doc.
101 * @return true if we should ignore invalidations sent from this SVG doc.
103 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
106 * Returns a bool indicating whether the document is currently drawing.
108 * @return true if the document is drawing. Else, false.
110 bool IsDrawing() const { return mIsDrawing; }
113 * Methods to control animation.
115 void StartAnimation();
116 void StopAnimation();
117 void ResetAnimation();
118 float GetCurrentTimeAsFloat();
119 void SetCurrentTime(float aTime);
120 void TickRefreshDriver();
123 * Force a layout flush of the underlying SVG document.
125 void FlushLayout();
127 private:
128 friend class AutoRestoreSVGState;
130 ~SVGDocumentWrapper();
132 nsresult SetupViewer(nsIRequest* aRequest, nsIContentViewer** aViewer,
133 nsILoadGroup** aLoadGroup);
134 void DestroyViewer();
135 void RegisterForXPCOMShutdown();
136 void UnregisterForXPCOMShutdown();
138 nsCOMPtr<nsIContentViewer> mViewer;
139 nsCOMPtr<nsILoadGroup> mLoadGroup;
140 nsCOMPtr<nsIStreamListener> mListener;
141 bool mIgnoreInvalidation;
142 bool mRegisteredForXPCOMShutdown;
143 bool mIsDrawing;
146 } // namespace image
147 } // namespace mozilla
150 * Casting SVGDocumentWrapper to nsISupports is ambiguous. This method handles
151 * that.
153 inline nsISupports* ToSupports(mozilla::image::SVGDocumentWrapper* p) {
154 return NS_ISUPPORTS_CAST(nsSupportsWeakReference*, p);
157 #endif // mozilla_image_SVGDocumentWrapper_h