Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / image / src / VectorImage.h
bloba7d49bd99de1d3820d569aeb4c94a106e4a6937c
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_
9 #include "Image.h"
10 #include "nsIStreamListener.h"
11 #include "mozilla/MemoryReporting.h"
13 class nsIRequest;
14 class gfxDrawable;
16 namespace mozilla {
17 namespace layers {
18 class LayerManager;
19 class ImageContainer;
21 namespace image {
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
32 public:
33 NS_DECL_ISUPPORTS
34 NS_DECL_NSIREQUESTOBSERVER
35 NS_DECL_NSISTREAMLISTENER
36 NS_DECL_IMGICONTAINER
38 // (no public constructor - use ImageFactory)
40 // Methods inherited from Image
41 nsresult Init(const char* aMimeType,
42 uint32_t aFlags);
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,
59 nsresult aResult,
60 bool aLastPart) MOZ_OVERRIDE;
61 virtual nsresult OnNewSourceData() MOZ_OVERRIDE;
63 /**
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();
80 protected:
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);
92 private:
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
107 // driver tick.
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);
123 } // namespace image
124 } // namespace mozilla
126 #endif // mozilla_imagelib_VectorImage_h_