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_imagelib_SVGDocumentWrapper_h_
9 #define mozilla_imagelib_SVGDocumentWrapper_h_
11 #include "mozilla/Attributes.h"
14 #include "nsIStreamListener.h"
15 #include "nsIObserver.h"
16 #include "nsIContentViewer.h"
17 #include "nsWeakReference.h"
18 #include "nsMimeTypes.h"
27 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
37 class SVGDocumentWrapper MOZ_FINAL
: public nsIStreamListener
,
39 nsSupportsWeakReference
43 ~SVGDocumentWrapper();
46 NS_DECL_NSISTREAMLISTENER
47 NS_DECL_NSIREQUESTOBSERVER
56 * Looks up the value of the wrapped SVG document's |width| or |height|
57 * attribute in CSS pixels, and returns it by reference. If the document has
58 * a percent value for the queried attribute, then this method fails
61 * @param aDimension Indicates whether the width or height is desired.
62 * @param[out] aResult If this method succeeds, then this outparam will be
63 populated with the width or height in CSS pixels.
64 * @return false to indicate failure, if the queried attribute has a
65 * percent value. Otherwise, true.
68 bool GetWidthOrHeight(Dimension aDimension
, int32_t& aResult
);
71 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
73 nsIDocument
* GetDocument();
76 * Returns the root <svg> element for the wrapped document, or nullptr on
79 mozilla::dom::SVGSVGElement
* GetRootSVGElem();
82 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
84 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
86 nsIFrame
* GetRootLayoutFrame();
89 * Returns (by reference) the nsIPresShell for the wrapped document.
91 * @param[out] aPresShell On success, this will be populated with a pointer
92 * to the wrapped document's nsIPresShell.
94 * @return NS_OK on success, or an error code on failure.
96 inline nsresult
GetPresShell(nsIPresShell
** aPresShell
)
97 { return mViewer
->GetPresShell(aPresShell
); }
100 * Modifier to update the viewport dimensions of the wrapped document. This
101 * method performs a synchronous "Flush_Layout" on the wrapped document,
102 * since a viewport-change affects layout.
104 * @param aViewportSize The new viewport dimensions.
106 void UpdateViewportBounds(const nsIntSize
& aViewportSize
);
109 * If an SVG image's helper document has a pending notification for an
110 * override on the root node's "preserveAspectRatio" attribute, then this
111 * method will flush that notification so that the image can paint correctly.
112 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
113 * notify the image's observers and trigger unwanted repaint-requests.)
115 void FlushImageTransformInvalidation();
118 * Returns a bool indicating whether the document has any SMIL animations.
120 * @return true if the document has any SMIL animations. Else, false.
125 * Indicates whether we should currently ignore rendering invalidations sent
126 * from the wrapped SVG doc.
128 * @return true if we should ignore invalidations sent from this SVG doc.
130 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation
; }
133 * Methods to control animation.
135 void StartAnimation();
136 void StopAnimation();
137 void ResetAnimation();
138 float GetCurrentTime();
139 void SetCurrentTime(float aTime
);
142 * Force a layout flush of the underlying SVG document.
147 nsresult
SetupViewer(nsIRequest
*aRequest
,
148 nsIContentViewer
** aViewer
,
149 nsILoadGroup
** aLoadGroup
);
150 void DestroyViewer();
151 void RegisterForXPCOMShutdown();
152 void UnregisterForXPCOMShutdown();
154 nsCOMPtr
<nsIContentViewer
> mViewer
;
155 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
156 nsCOMPtr
<nsIStreamListener
> mListener
;
157 bool mIgnoreInvalidation
;
158 bool mRegisteredForXPCOMShutdown
;
162 } // namespace mozilla
164 #endif // mozilla_imagelib_SVGDocumentWrapper_h_