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"
35 class SVGDocumentWrapper final
: public nsIStreamListener
,
37 nsSupportsWeakReference
{
42 NS_DECL_NSISTREAMLISTENER
43 NS_DECL_NSIREQUESTOBSERVER
46 enum Dimension
{ eWidth
, eHeight
};
49 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
51 mozilla::dom::SVGDocument
* GetDocument();
54 * Returns the root <svg> element for the wrapped document, or nullptr on
57 mozilla::dom::SVGSVGElement
* GetRootSVGElem();
60 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
62 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
64 nsIFrame
* GetRootLayoutFrame();
67 * Returns the mozilla::PresShell for the wrapped document.
69 inline mozilla::PresShell
* GetPresShell() { return mViewer
->GetPresShell(); }
72 * Modifier to update the viewport dimensions of the wrapped document. This
73 * method performs a synchronous "FlushType::Layout" on the wrapped document,
74 * since a viewport-change affects layout.
76 * @param aViewportSize The new viewport dimensions.
78 void UpdateViewportBounds(const nsIntSize
& aViewportSize
);
81 * If an SVG image's helper document has a pending notification for an
82 * override on the root node's "preserveAspectRatio" attribute, then this
83 * method will flush that notification so that the image can paint correctly.
84 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
85 * notify the image's observers and trigger unwanted repaint-requests.)
87 void FlushImageTransformInvalidation();
90 * Returns a bool indicating whether the document has any SMIL animations.
92 * @return true if the document has any SMIL animations. Else, false.
97 * Indicates whether we should currently ignore rendering invalidations sent
98 * from the wrapped SVG doc.
100 * @return true if we should ignore invalidations sent from this SVG doc.
102 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation
; }
105 * Methods to control animation.
107 void StartAnimation();
108 void StopAnimation();
109 void ResetAnimation();
110 float GetCurrentTimeAsFloat();
111 void SetCurrentTime(float aTime
);
112 void TickRefreshDriver();
115 * Force a layout flush of the underlying SVG document.
120 ~SVGDocumentWrapper();
122 nsresult
SetupViewer(nsIRequest
* aRequest
, nsIContentViewer
** aViewer
,
123 nsILoadGroup
** aLoadGroup
);
124 void DestroyViewer();
125 void RegisterForXPCOMShutdown();
126 void UnregisterForXPCOMShutdown();
128 nsCOMPtr
<nsIContentViewer
> mViewer
;
129 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
130 nsCOMPtr
<nsIStreamListener
> mListener
;
131 bool mIgnoreInvalidation
;
132 bool mRegisteredForXPCOMShutdown
;
136 } // namespace mozilla
138 #endif // mozilla_image_SVGDocumentWrapper_h