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"
14 #include "nsIStreamListener.h"
15 #include "nsIObserver.h"
16 #include "nsIContentViewer.h"
17 #include "nsWeakReference.h"
24 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
34 class AutoRestoreSVGState
;
36 class SVGDocumentWrapper final
: public nsIStreamListener
,
38 public nsSupportsWeakReference
{
43 NS_DECL_NSISTREAMLISTENER
44 NS_DECL_NSIREQUESTOBSERVER
47 enum Dimension
{ eWidth
, eHeight
};
50 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
52 mozilla::dom::SVGDocument
* GetDocument();
55 * Returns the root <svg> element for the wrapped document, or nullptr on
58 mozilla::dom::SVGSVGElement
* GetRootSVGElem();
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();
68 * Returns the mozilla::PresShell for the wrapped document.
70 inline mozilla::PresShell
* GetPresShell() { return mViewer
->GetPresShell(); }
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
);
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();
91 * Returns a bool indicating whether the document has any SMIL animations.
93 * @return true if the document has any SMIL animations. Else, false.
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.
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
;
147 } // namespace mozilla
150 * Casting SVGDocumentWrapper to nsISupports is ambiguous. This method handles
153 inline nsISupports
* ToSupports(mozilla::image::SVGDocumentWrapper
* p
) {
154 return NS_ISUPPORTS_CAST(nsSupportsWeakReference
*, p
);
157 #endif // mozilla_image_SVGDocumentWrapper_h