Bug 905002: backout bug 879717 until we can fix the mac-only regression rs=roc
[gecko.git] / image / src / SVGDocumentWrapper.h
blobecad9d216be7173b90c84a2f00f8c6007f6170be
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"
13 #include "nsCOMPtr.h"
14 #include "nsIStreamListener.h"
15 #include "nsIObserver.h"
16 #include "nsIContentViewer.h"
17 #include "nsWeakReference.h"
18 #include "nsMimeTypes.h"
20 class nsIAtom;
21 class nsIPresShell;
22 class nsIRequest;
23 class nsILoadGroup;
24 class nsIFrame;
25 struct nsIntSize;
27 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
30 namespace mozilla {
31 namespace dom {
32 class SVGSVGElement;
35 namespace image {
37 class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
38 public nsIObserver,
39 nsSupportsWeakReference
41 public:
42 SVGDocumentWrapper();
43 ~SVGDocumentWrapper();
45 NS_DECL_ISUPPORTS
46 NS_DECL_NSISTREAMLISTENER
47 NS_DECL_NSIREQUESTOBSERVER
48 NS_DECL_NSIOBSERVER
50 enum Dimension {
51 eWidth,
52 eHeight
55 /**
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
59 * (returns false).
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);
70 /**
71 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
73 nsIDocument* GetDocument();
75 /**
76 * Returns the root <svg> element for the wrapped document, or nullptr on
77 * failure.
79 mozilla::dom::SVGSVGElement* GetRootSVGElem();
81 /**
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();
88 /**
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); }
99 /**
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.
122 bool IsAnimated();
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.
144 void FlushLayout();
146 private:
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;
161 } // namespace image
162 } // namespace mozilla
164 #endif // mozilla_imagelib_SVGDocumentWrapper_h_