Backed out changeset 177eae915693 (bug 1206581) for bustage
[gecko.git] / image / SVGDocumentWrapper.h
blob7d7586ae37e9ac08c07b5cf41f9791f2e202e7b4
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"
13 #include "nsCOMPtr.h"
14 #include "nsIStreamListener.h"
15 #include "nsIObserver.h"
16 #include "nsIContentViewer.h"
17 #include "nsWeakReference.h"
18 #include "nsSize.h"
20 class nsIPresShell;
21 class nsIRequest;
22 class nsILoadGroup;
23 class nsIFrame;
25 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
27 // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
28 #undef GetCurrentTime
30 namespace mozilla {
31 namespace dom {
32 class SVGSVGElement;
33 } // namespace dom
35 namespace image {
37 class SVGDocumentWrapper final : public nsIStreamListener,
38 public nsIObserver,
39 nsSupportsWeakReference
41 public:
42 SVGDocumentWrapper();
44 NS_DECL_ISUPPORTS
45 NS_DECL_NSISTREAMLISTENER
46 NS_DECL_NSIREQUESTOBSERVER
47 NS_DECL_NSIOBSERVER
49 enum Dimension {
50 eWidth,
51 eHeight
54 /**
55 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
57 nsIDocument* GetDocument();
59 /**
60 * Returns the root <svg> element for the wrapped document, or nullptr on
61 * failure.
63 mozilla::dom::SVGSVGElement* GetRootSVGElem();
65 /**
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();
72 /**
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); }
83 /**
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);
92 /**
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.
106 bool IsAnimated();
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.
129 void FlushLayout();
131 private:
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;
148 } // namespace image
149 } // namespace mozilla
151 #endif // mozilla_image_SVGDocumentWrapper_h