Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / image / SVGDocumentWrapper.h
blobf5cc74f0aa44042a6b51b27677a2ebe68840c337
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 nsIRequest;
21 class nsILoadGroup;
22 class nsIFrame;
24 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
26 namespace mozilla {
27 class PresShell;
28 namespace dom {
29 class SVGSVGElement;
30 class SVGDocument;
31 } // namespace dom
33 namespace image {
35 class SVGDocumentWrapper final : public nsIStreamListener,
36 public nsIObserver,
37 nsSupportsWeakReference {
38 public:
39 SVGDocumentWrapper();
41 NS_DECL_ISUPPORTS
42 NS_DECL_NSISTREAMLISTENER
43 NS_DECL_NSIREQUESTOBSERVER
44 NS_DECL_NSIOBSERVER
46 enum Dimension { eWidth, eHeight };
48 /**
49 * Returns the wrapped document, or nullptr on failure. (No AddRef.)
51 mozilla::dom::SVGDocument* GetDocument();
53 /**
54 * Returns the root <svg> element for the wrapped document, or nullptr on
55 * failure.
57 mozilla::dom::SVGSVGElement* GetRootSVGElem();
59 /**
60 * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
62 * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
64 nsIFrame* GetRootLayoutFrame();
66 /**
67 * Returns the mozilla::PresShell for the wrapped document.
69 inline mozilla::PresShell* GetPresShell() { return mViewer->GetPresShell(); }
71 /**
72 * Modifier to update the viewport dimensions of the wrapped document. This
73 * method performs a synchronous "FlushType::Layout" on the wrapped document,
74 * since a viewport-change affects layout.
76 * @param aViewportSize The new viewport dimensions.
78 void UpdateViewportBounds(const nsIntSize& aViewportSize);
80 /**
81 * If an SVG image's helper document has a pending notification for an
82 * override on the root node's "preserveAspectRatio" attribute, then this
83 * method will flush that notification so that the image can paint correctly.
84 * (First, though, it sets the mIgnoreInvalidation flag so that we won't
85 * notify the image's observers and trigger unwanted repaint-requests.)
87 void FlushImageTransformInvalidation();
89 /**
90 * Returns a bool indicating whether the document has any SMIL animations.
92 * @return true if the document has any SMIL animations. Else, false.
94 bool IsAnimated();
96 /**
97 * Indicates whether we should currently ignore rendering invalidations sent
98 * from the wrapped SVG doc.
100 * @return true if we should ignore invalidations sent from this SVG doc.
102 bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
105 * Methods to control animation.
107 void StartAnimation();
108 void StopAnimation();
109 void ResetAnimation();
110 float GetCurrentTimeAsFloat();
111 void SetCurrentTime(float aTime);
112 void TickRefreshDriver();
115 * Force a layout flush of the underlying SVG document.
117 void FlushLayout();
119 private:
120 ~SVGDocumentWrapper();
122 nsresult SetupViewer(nsIRequest* aRequest, nsIContentViewer** aViewer,
123 nsILoadGroup** aLoadGroup);
124 void DestroyViewer();
125 void RegisterForXPCOMShutdown();
126 void UnregisterForXPCOMShutdown();
128 nsCOMPtr<nsIContentViewer> mViewer;
129 nsCOMPtr<nsILoadGroup> mLoadGroup;
130 nsCOMPtr<nsIStreamListener> mListener;
131 bool mIgnoreInvalidation;
132 bool mRegisteredForXPCOMShutdown;
135 } // namespace image
136 } // namespace mozilla
138 #endif // mozilla_image_SVGDocumentWrapper_h