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"
26 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
28 // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
38 class SVGDocumentWrapper MOZ_FINAL
: public nsIStreamListener
,
40 nsSupportsWeakReference
44 ~SVGDocumentWrapper();
47 NS_DECL_NSISTREAMLISTENER
48 NS_DECL_NSIREQUESTOBSERVER
57 * Looks up the value of the wrapped SVG document's |width| or |height|
58 * attribute in CSS pixels, and returns it by reference. If the document has
59 * a percent value for the queried attribute, then this method fails
62 * @param aDimension Indicates whether the width or height is desired.
63 * @param[out] aResult If this method succeeds, then this outparam will be
64 populated with the width or height in CSS pixels.
65 * @return false to indicate failure, if the queried attribute has a
66 * percent value. Otherwise, true.
69 bool GetWidthOrHeight(Dimension aDimension
, int32_t& aResult
);
72 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
74 nsIDocument
* GetDocument();
77 * Returns the root <svg> element for the wrapped document, or nullptr on
80 mozilla::dom::SVGSVGElement
* GetRootSVGElem();
83 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
85 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
87 nsIFrame
* GetRootLayoutFrame();
90 * Returns (by reference) the nsIPresShell for the wrapped document.
92 * @param[out] aPresShell On success, this will be populated with a pointer
93 * to the wrapped document's nsIPresShell.
95 * @return NS_OK on success, or an error code on failure.
97 inline nsresult
GetPresShell(nsIPresShell
** aPresShell
)
98 { return mViewer
->GetPresShell(aPresShell
); }
101 * Modifier to update the viewport dimensions of the wrapped document. This
102 * method performs a synchronous "Flush_Layout" on the wrapped document,
103 * since a viewport-change affects layout.
105 * @param aViewportSize The new viewport dimensions.
107 void UpdateViewportBounds(const nsIntSize
& aViewportSize
);
110 * If an SVG image's helper document has a pending notification for an
111 * override on the root node's "preserveAspectRatio" attribute, then this
112 * method will flush that notification so that the image can paint correctly.
113 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
114 * notify the image's observers and trigger unwanted repaint-requests.)
116 void FlushImageTransformInvalidation();
119 * Returns a bool indicating whether the document has any SMIL animations.
121 * @return true if the document has any SMIL animations. Else, false.
126 * Indicates whether we should currently ignore rendering invalidations sent
127 * from the wrapped SVG doc.
129 * @return true if we should ignore invalidations sent from this SVG doc.
131 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation
; }
134 * Methods to control animation.
136 void StartAnimation();
137 void StopAnimation();
138 void ResetAnimation();
139 float GetCurrentTime();
140 void SetCurrentTime(float aTime
);
143 * Force a layout flush of the underlying SVG document.
148 nsresult
SetupViewer(nsIRequest
*aRequest
,
149 nsIContentViewer
** aViewer
,
150 nsILoadGroup
** aLoadGroup
);
151 void DestroyViewer();
152 void RegisterForXPCOMShutdown();
153 void UnregisterForXPCOMShutdown();
155 nsCOMPtr
<nsIContentViewer
> mViewer
;
156 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
157 nsCOMPtr
<nsIStreamListener
> mListener
;
158 bool mIgnoreInvalidation
;
159 bool mRegisteredForXPCOMShutdown
;
163 } // namespace mozilla
165 #endif // mozilla_imagelib_SVGDocumentWrapper_h_