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