|
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/. */ |
|
5 |
|
6 /* This class wraps an SVG document, for use by VectorImage objects. */ |
|
7 |
|
8 #ifndef mozilla_imagelib_SVGDocumentWrapper_h_ |
|
9 #define mozilla_imagelib_SVGDocumentWrapper_h_ |
|
10 |
|
11 #include "mozilla/Attributes.h" |
|
12 |
|
13 #include "nsCOMPtr.h" |
|
14 #include "nsIStreamListener.h" |
|
15 #include "nsIObserver.h" |
|
16 #include "nsIContentViewer.h" |
|
17 #include "nsWeakReference.h" |
|
18 |
|
19 class nsIAtom; |
|
20 class nsIPresShell; |
|
21 class nsIRequest; |
|
22 class nsILoadGroup; |
|
23 class nsIFrame; |
|
24 struct nsIntSize; |
|
25 |
|
26 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1" |
|
27 |
|
28 // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK |
|
29 #undef GetCurrentTime |
|
30 |
|
31 namespace mozilla { |
|
32 namespace dom { |
|
33 class SVGSVGElement; |
|
34 } |
|
35 |
|
36 namespace image { |
|
37 |
|
38 class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener, |
|
39 public nsIObserver, |
|
40 nsSupportsWeakReference |
|
41 { |
|
42 public: |
|
43 SVGDocumentWrapper(); |
|
44 ~SVGDocumentWrapper(); |
|
45 |
|
46 NS_DECL_ISUPPORTS |
|
47 NS_DECL_NSISTREAMLISTENER |
|
48 NS_DECL_NSIREQUESTOBSERVER |
|
49 NS_DECL_NSIOBSERVER |
|
50 |
|
51 enum Dimension { |
|
52 eWidth, |
|
53 eHeight |
|
54 }; |
|
55 |
|
56 /** |
|
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 |
|
60 * (returns false). |
|
61 * |
|
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. |
|
67 * |
|
68 */ |
|
69 bool GetWidthOrHeight(Dimension aDimension, int32_t& aResult); |
|
70 |
|
71 /** |
|
72 * Returns the wrapped document, or nullptr on failure. (No AddRef.) |
|
73 */ |
|
74 nsIDocument* GetDocument(); |
|
75 |
|
76 /** |
|
77 * Returns the root <svg> element for the wrapped document, or nullptr on |
|
78 * failure. |
|
79 */ |
|
80 mozilla::dom::SVGSVGElement* GetRootSVGElem(); |
|
81 |
|
82 /** |
|
83 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure. |
|
84 * |
|
85 * @return the root nsIFrame* for the wrapped document, or nullptr on failure. |
|
86 */ |
|
87 nsIFrame* GetRootLayoutFrame(); |
|
88 |
|
89 /** |
|
90 * Returns (by reference) the nsIPresShell for the wrapped document. |
|
91 * |
|
92 * @param[out] aPresShell On success, this will be populated with a pointer |
|
93 * to the wrapped document's nsIPresShell. |
|
94 * |
|
95 * @return NS_OK on success, or an error code on failure. |
|
96 */ |
|
97 inline nsresult GetPresShell(nsIPresShell** aPresShell) |
|
98 { return mViewer->GetPresShell(aPresShell); } |
|
99 |
|
100 /** |
|
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. |
|
104 * |
|
105 * @param aViewportSize The new viewport dimensions. |
|
106 */ |
|
107 void UpdateViewportBounds(const nsIntSize& aViewportSize); |
|
108 |
|
109 /** |
|
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.) |
|
115 */ |
|
116 void FlushImageTransformInvalidation(); |
|
117 |
|
118 /** |
|
119 * Returns a bool indicating whether the document has any SMIL animations. |
|
120 * |
|
121 * @return true if the document has any SMIL animations. Else, false. |
|
122 */ |
|
123 bool IsAnimated(); |
|
124 |
|
125 /** |
|
126 * Indicates whether we should currently ignore rendering invalidations sent |
|
127 * from the wrapped SVG doc. |
|
128 * |
|
129 * @return true if we should ignore invalidations sent from this SVG doc. |
|
130 */ |
|
131 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; } |
|
132 |
|
133 /** |
|
134 * Methods to control animation. |
|
135 */ |
|
136 void StartAnimation(); |
|
137 void StopAnimation(); |
|
138 void ResetAnimation(); |
|
139 float GetCurrentTime(); |
|
140 void SetCurrentTime(float aTime); |
|
141 |
|
142 /** |
|
143 * Force a layout flush of the underlying SVG document. |
|
144 */ |
|
145 void FlushLayout(); |
|
146 |
|
147 private: |
|
148 nsresult SetupViewer(nsIRequest *aRequest, |
|
149 nsIContentViewer** aViewer, |
|
150 nsILoadGroup** aLoadGroup); |
|
151 void DestroyViewer(); |
|
152 void RegisterForXPCOMShutdown(); |
|
153 void UnregisterForXPCOMShutdown(); |
|
154 |
|
155 nsCOMPtr<nsIContentViewer> mViewer; |
|
156 nsCOMPtr<nsILoadGroup> mLoadGroup; |
|
157 nsCOMPtr<nsIStreamListener> mListener; |
|
158 bool mIgnoreInvalidation; |
|
159 bool mRegisteredForXPCOMShutdown; |
|
160 }; |
|
161 |
|
162 } // namespace image |
|
163 } // namespace mozilla |
|
164 |
|
165 #endif // mozilla_imagelib_SVGDocumentWrapper_h_ |