/src/mozilla-central/image/SVGDocumentWrapper.h
Line | Count | Source (jump to first uncovered line) |
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_image_SVGDocumentWrapper_h |
9 | | #define mozilla_image_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 | | #include "nsSize.h" |
19 | | |
20 | | class nsIPresShell; |
21 | | class nsIRequest; |
22 | | class nsILoadGroup; |
23 | | class nsIFrame; |
24 | | |
25 | 0 | #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1" |
26 | | |
27 | | // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK |
28 | | #undef GetCurrentTime |
29 | | |
30 | | namespace mozilla { |
31 | | namespace dom { |
32 | | class SVGSVGElement; |
33 | | class SVGDocument; |
34 | | } // namespace dom |
35 | | |
36 | | namespace image { |
37 | | |
38 | | class SVGDocumentWrapper final : public nsIStreamListener, |
39 | | public nsIObserver, |
40 | | nsSupportsWeakReference |
41 | | { |
42 | | public: |
43 | | SVGDocumentWrapper(); |
44 | | |
45 | | NS_DECL_ISUPPORTS |
46 | | NS_DECL_NSISTREAMLISTENER |
47 | | NS_DECL_NSIREQUESTOBSERVER |
48 | | NS_DECL_NSIOBSERVER |
49 | | |
50 | | enum Dimension { |
51 | | eWidth, |
52 | | eHeight |
53 | | }; |
54 | | |
55 | | /** |
56 | | * Returns the wrapped document, or nullptr on failure. (No AddRef.) |
57 | | */ |
58 | | mozilla::dom::SVGDocument* GetDocument(); |
59 | | |
60 | | /** |
61 | | * Returns the root <svg> element for the wrapped document, or nullptr on |
62 | | * failure. |
63 | | */ |
64 | | mozilla::dom::SVGSVGElement* GetRootSVGElem(); |
65 | | |
66 | | /** |
67 | | * Returns the root nsIFrame* for the wrapped document, or nullptr on failure. |
68 | | * |
69 | | * @return the root nsIFrame* for the wrapped document, or nullptr on failure. |
70 | | */ |
71 | | nsIFrame* GetRootLayoutFrame(); |
72 | | |
73 | | /** |
74 | | * Returns (by reference) the nsIPresShell for the wrapped document. |
75 | | * |
76 | | * @param[out] aPresShell On success, this will be populated with a pointer |
77 | | * to the wrapped document's nsIPresShell. |
78 | | * |
79 | | * @return NS_OK on success, or an error code on failure. |
80 | | */ |
81 | | inline nsresult GetPresShell(nsIPresShell** aPresShell) |
82 | 0 | { return mViewer->GetPresShell(aPresShell); } |
83 | | |
84 | | /** |
85 | | * Modifier to update the viewport dimensions of the wrapped document. This |
86 | | * method performs a synchronous "FlushType::Layout" on the wrapped document, |
87 | | * since a viewport-change affects layout. |
88 | | * |
89 | | * @param aViewportSize The new viewport dimensions. |
90 | | */ |
91 | | void UpdateViewportBounds(const nsIntSize& aViewportSize); |
92 | | |
93 | | /** |
94 | | * If an SVG image's helper document has a pending notification for an |
95 | | * override on the root node's "preserveAspectRatio" attribute, then this |
96 | | * method will flush that notification so that the image can paint correctly. |
97 | | * (First, though, it sets the mIgnoreInvalidation flag so that we won't |
98 | | * notify the image's observers and trigger unwanted repaint-requests.) |
99 | | */ |
100 | | void FlushImageTransformInvalidation(); |
101 | | |
102 | | /** |
103 | | * Returns a bool indicating whether the document has any SMIL animations. |
104 | | * |
105 | | * @return true if the document has any SMIL animations. Else, false. |
106 | | */ |
107 | | bool IsAnimated(); |
108 | | |
109 | | /** |
110 | | * Indicates whether we should currently ignore rendering invalidations sent |
111 | | * from the wrapped SVG doc. |
112 | | * |
113 | | * @return true if we should ignore invalidations sent from this SVG doc. |
114 | | */ |
115 | 0 | bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; } |
116 | | |
117 | | /** |
118 | | * Methods to control animation. |
119 | | */ |
120 | | void StartAnimation(); |
121 | | void StopAnimation(); |
122 | | void ResetAnimation(); |
123 | | float GetCurrentTime(); |
124 | | void SetCurrentTime(float aTime); |
125 | | void TickRefreshDriver(); |
126 | | |
127 | | /** |
128 | | * Force a layout flush of the underlying SVG document. |
129 | | */ |
130 | | void FlushLayout(); |
131 | | |
132 | | private: |
133 | | ~SVGDocumentWrapper(); |
134 | | |
135 | | nsresult SetupViewer(nsIRequest* aRequest, |
136 | | nsIContentViewer** aViewer, |
137 | | nsILoadGroup** aLoadGroup); |
138 | | void DestroyViewer(); |
139 | | void RegisterForXPCOMShutdown(); |
140 | | void UnregisterForXPCOMShutdown(); |
141 | | |
142 | | nsCOMPtr<nsIContentViewer> mViewer; |
143 | | nsCOMPtr<nsILoadGroup> mLoadGroup; |
144 | | nsCOMPtr<nsIStreamListener> mListener; |
145 | | bool mIgnoreInvalidation; |
146 | | bool mRegisteredForXPCOMShutdown; |
147 | | }; |
148 | | |
149 | | } // namespace image |
150 | | } // namespace mozilla |
151 | | |
152 | | #endif // mozilla_image_SVGDocumentWrapper_h |