Line data Source code
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 : #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 : } // namespace dom
34 :
35 : namespace image {
36 :
37 : class SVGDocumentWrapper final : public nsIStreamListener,
38 : public nsIObserver,
39 : nsSupportsWeakReference
40 : {
41 : public:
42 : SVGDocumentWrapper();
43 :
44 : NS_DECL_ISUPPORTS
45 : NS_DECL_NSISTREAMLISTENER
46 : NS_DECL_NSIREQUESTOBSERVER
47 : NS_DECL_NSIOBSERVER
48 :
49 : enum Dimension {
50 : eWidth,
51 : eHeight
52 : };
53 :
54 : /**
55 : * Returns the wrapped document, or nullptr on failure. (No AddRef.)
56 : */
57 : nsIDocument* GetDocument();
58 :
59 : /**
60 : * Returns the root <svg> element for the wrapped document, or nullptr on
61 : * failure.
62 : */
63 : mozilla::dom::SVGSVGElement* GetRootSVGElem();
64 :
65 : /**
66 : * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
67 : *
68 : * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
69 : */
70 : nsIFrame* GetRootLayoutFrame();
71 :
72 : /**
73 : * Returns (by reference) the nsIPresShell for the wrapped document.
74 : *
75 : * @param[out] aPresShell On success, this will be populated with a pointer
76 : * to the wrapped document's nsIPresShell.
77 : *
78 : * @return NS_OK on success, or an error code on failure.
79 : */
80 18 : inline nsresult GetPresShell(nsIPresShell** aPresShell)
81 18 : { return mViewer->GetPresShell(aPresShell); }
82 :
83 : /**
84 : * Modifier to update the viewport dimensions of the wrapped document. This
85 : * method performs a synchronous "FlushType::Layout" on the wrapped document,
86 : * since a viewport-change affects layout.
87 : *
88 : * @param aViewportSize The new viewport dimensions.
89 : */
90 : void UpdateViewportBounds(const nsIntSize& aViewportSize);
91 :
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.)
98 : */
99 : void FlushImageTransformInvalidation();
100 :
101 : /**
102 : * Returns a bool indicating whether the document has any SMIL animations.
103 : *
104 : * @return true if the document has any SMIL animations. Else, false.
105 : */
106 : bool IsAnimated();
107 :
108 : /**
109 : * Indicates whether we should currently ignore rendering invalidations sent
110 : * from the wrapped SVG doc.
111 : *
112 : * @return true if we should ignore invalidations sent from this SVG doc.
113 : */
114 72 : bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
115 :
116 : /**
117 : * Methods to control animation.
118 : */
119 : void StartAnimation();
120 : void StopAnimation();
121 : void ResetAnimation();
122 : float GetCurrentTime();
123 : void SetCurrentTime(float aTime);
124 : void TickRefreshDriver();
125 :
126 : /**
127 : * Force a layout flush of the underlying SVG document.
128 : */
129 : void FlushLayout();
130 :
131 : private:
132 : ~SVGDocumentWrapper();
133 :
134 : nsresult SetupViewer(nsIRequest* aRequest,
135 : nsIContentViewer** aViewer,
136 : nsILoadGroup** aLoadGroup);
137 : void DestroyViewer();
138 : void RegisterForXPCOMShutdown();
139 : void UnregisterForXPCOMShutdown();
140 :
141 : nsCOMPtr<nsIContentViewer> mViewer;
142 : nsCOMPtr<nsILoadGroup> mLoadGroup;
143 : nsCOMPtr<nsIStreamListener> mListener;
144 : bool mIgnoreInvalidation;
145 : bool mRegisteredForXPCOMShutdown;
146 : };
147 :
148 : } // namespace image
149 : } // namespace mozilla
150 :
151 : #endif // mozilla_image_SVGDocumentWrapper_h
|