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 #ifndef mozilla_imagelib_VectorImage_h_
7 #define mozilla_imagelib_VectorImage_h_
10 #include "nsIStreamListener.h"
11 #include "mozilla/MemoryReporting.h"
23 struct SVGDrawingParameters
;
24 class SVGDocumentWrapper
;
25 class SVGRootRenderingObserver
;
26 class SVGLoadEventListener
;
27 class SVGParseCompleteListener
;
29 class VectorImage MOZ_FINAL
: public ImageResource
,
30 public nsIStreamListener
34 NS_DECL_NSIREQUESTOBSERVER
35 NS_DECL_NSISTREAMLISTENER
38 // (no public constructor - use ImageFactory)
40 // Methods inherited from Image
41 nsresult
Init(const char* aMimeType
,
43 virtual nsIntRect
FrameRect(uint32_t aWhichFrame
) MOZ_OVERRIDE
;
45 virtual size_t HeapSizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf
) const;
46 virtual size_t HeapSizeOfDecodedWithComputedFallback(MallocSizeOf aMallocSizeOf
) const;
47 virtual size_t NonHeapSizeOfDecoded() const;
48 virtual size_t OutOfProcessSizeOfDecoded() const;
50 virtual size_t HeapSizeOfVectorImageDocument(nsACString
* aDocURL
= nullptr) const MOZ_OVERRIDE
;
52 virtual nsresult
OnImageDataAvailable(nsIRequest
* aRequest
,
53 nsISupports
* aContext
,
54 nsIInputStream
* aInStr
,
55 uint64_t aSourceOffset
,
56 uint32_t aCount
) MOZ_OVERRIDE
;
57 virtual nsresult
OnImageDataComplete(nsIRequest
* aRequest
,
58 nsISupports
* aContext
,
60 bool aLastPart
) MOZ_OVERRIDE
;
61 virtual nsresult
OnNewSourceData() MOZ_OVERRIDE
;
64 * Callback for SVGRootRenderingObserver.
66 * This just sets a dirty flag that we check in VectorImage::RequestRefresh,
67 * which is called under the ticks of the refresh driver of any observing
68 * documents that we may have. Only then (after all animations in this image
69 * have been updated) do we send out "frame changed" notifications,
71 void InvalidateObserversOnNextRefreshDriverTick();
73 // Callback for SVGParseCompleteListener.
74 void OnSVGDocumentParsed();
76 // Callbacks for SVGLoadEventListener.
77 void OnSVGDocumentLoaded();
78 void OnSVGDocumentError();
81 VectorImage(imgStatusTracker
* aStatusTracker
= nullptr,
82 ImageURL
* aURI
= nullptr);
83 virtual ~VectorImage();
85 virtual nsresult
StartAnimation();
86 virtual nsresult
StopAnimation();
87 virtual bool ShouldAnimate();
89 void CreateDrawableAndShow(const SVGDrawingParameters
& aParams
);
90 void Show(gfxDrawable
* aDrawable
, const SVGDrawingParameters
& aParams
);
93 void CancelAllListeners();
94 void SendInvalidationNotifications();
96 nsRefPtr
<SVGDocumentWrapper
> mSVGDocumentWrapper
;
97 nsRefPtr
<SVGRootRenderingObserver
> mRenderingObserver
;
98 nsRefPtr
<SVGLoadEventListener
> mLoadEventListener
;
99 nsRefPtr
<SVGParseCompleteListener
> mParseCompleteListener
;
101 bool mIsInitialized
; // Have we been initalized?
102 bool mIsFullyLoaded
; // Has the SVG document finished loading?
103 bool mIsDrawing
; // Are we currently drawing?
104 bool mHaveAnimations
; // Is our SVG content SMIL-animated?
105 // (Only set after mIsFullyLoaded.)
106 bool mHasPendingInvalidation
; // Invalidate observers next refresh
109 // Initializes imgStatusTracker and resets it on RasterImage destruction.
110 nsAutoPtr
<imgStatusTrackerInit
> mStatusTrackerInit
;
112 friend class ImageFactory
;
115 inline NS_IMETHODIMP
VectorImage::GetAnimationMode(uint16_t *aAnimationMode
) {
116 return GetAnimationModeInternal(aAnimationMode
);
119 inline NS_IMETHODIMP
VectorImage::SetAnimationMode(uint16_t aAnimationMode
) {
120 return SetAnimationModeInternal(aAnimationMode
);
124 } // namespace mozilla
126 #endif // mozilla_imagelib_VectorImage_h_