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"
25 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
27 // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
37 class SVGDocumentWrapper final
: public nsIStreamListener
,
39 nsSupportsWeakReference
45 NS_DECL_NSISTREAMLISTENER
46 NS_DECL_NSIREQUESTOBSERVER
55 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
57 nsIDocument
* GetDocument();
60 * Returns the root <svg> element for the wrapped document, or nullptr on
63 mozilla::dom::SVGSVGElement
* GetRootSVGElem();
66 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
68 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
70 nsIFrame
* GetRootLayoutFrame();
73 * Returns (by reference) the nsIPresShell for the wrapped document.
75 * @param[out] aPresShell On success, this will be populated with a pointer
76 * to the wrapped document's nsIPresShell.
78 * @return NS_OK on success, or an error code on failure.
80 inline nsresult
GetPresShell(nsIPresShell
** aPresShell
)
81 { return mViewer
->GetPresShell(aPresShell
); }
84 * Modifier to update the viewport dimensions of the wrapped document. This
85 * method performs a synchronous "Flush_Layout" on the wrapped document,
86 * since a viewport-change affects layout.
88 * @param aViewportSize The new viewport dimensions.
90 void UpdateViewportBounds(const nsIntSize
& aViewportSize
);
93 * If an SVG image's helper document has a pending notification for an
94 * override on the root node's "preserveAspectRatio" attribute, then this
95 * method will flush that notification so that the image can paint correctly.
96 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
97 * notify the image's observers and trigger unwanted repaint-requests.)
99 void FlushImageTransformInvalidation();
102 * Returns a bool indicating whether the document has any SMIL animations.
104 * @return true if the document has any SMIL animations. Else, false.
109 * Indicates whether we should currently ignore rendering invalidations sent
110 * from the wrapped SVG doc.
112 * @return true if we should ignore invalidations sent from this SVG doc.
114 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation
; }
117 * Methods to control animation.
119 void StartAnimation();
120 void StopAnimation();
121 void ResetAnimation();
122 float GetCurrentTime();
123 void SetCurrentTime(float aTime
);
124 void TickRefreshDriver();
127 * Force a layout flush of the underlying SVG document.
132 ~SVGDocumentWrapper();
134 nsresult
SetupViewer(nsIRequest
* aRequest
,
135 nsIContentViewer
** aViewer
,
136 nsILoadGroup
** aLoadGroup
);
137 void DestroyViewer();
138 void RegisterForXPCOMShutdown();
139 void UnregisterForXPCOMShutdown();
141 nsCOMPtr
<nsIContentViewer
> mViewer
;
142 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
143 nsCOMPtr
<nsIStreamListener
> mListener
;
144 bool mIgnoreInvalidation
;
145 bool mRegisteredForXPCOMShutdown
;
149 } // namespace mozilla
151 #endif // mozilla_image_SVGDocumentWrapper_h