1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Daniel Holbert <dholbert@mozilla.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef mozilla_imagelib_VectorImage_h_
40 : #define mozilla_imagelib_VectorImage_h_
41 :
42 : #include "Image.h"
43 : #include "nsIStreamListener.h"
44 : #include "nsWeakReference.h"
45 : #include "mozilla/TimeStamp.h"
46 :
47 : class imgIDecoderObserver;
48 :
49 : namespace mozilla {
50 : namespace layers {
51 : class LayerManager;
52 : class ImageContainer;
53 : }
54 : namespace image {
55 :
56 : class SVGDocumentWrapper;
57 : class SVGRootRenderingObserver;
58 :
59 : class VectorImage : public Image,
60 : public nsIStreamListener
61 : {
62 : public:
63 : NS_DECL_ISUPPORTS
64 : NS_DECL_NSIREQUESTOBSERVER
65 : NS_DECL_NSISTREAMLISTENER
66 :
67 : // BEGIN NS_DECL_IMGICONTAINER (minus GetAnimationMode/SetAnimationMode)
68 : // ** Don't edit this chunk except to mirror changes in imgIContainer.idl **
69 : NS_SCRIPTABLE NS_IMETHOD GetWidth(PRInt32 *aWidth);
70 : NS_SCRIPTABLE NS_IMETHOD GetHeight(PRInt32 *aHeight);
71 : NS_SCRIPTABLE NS_IMETHOD GetType(PRUint16 *aType);
72 : NS_IMETHOD_(PRUint16) GetType(void);
73 : NS_SCRIPTABLE NS_IMETHOD GetAnimated(bool *aAnimated);
74 : NS_SCRIPTABLE NS_IMETHOD GetCurrentFrameIsOpaque(bool *aCurrentFrameIsOpaque);
75 : NS_IMETHOD GetFrame(PRUint32 aWhichFrame, PRUint32 aFlags, gfxASurface **_retval NS_OUTPARAM);
76 0 : NS_IMETHOD GetImageContainer(mozilla::layers::ImageContainer **_retval NS_OUTPARAM) { *_retval = NULL; return NS_OK; }
77 : NS_IMETHOD CopyFrame(PRUint32 aWhichFrame, PRUint32 aFlags, gfxImageSurface **_retval NS_OUTPARAM);
78 : NS_IMETHOD ExtractFrame(PRUint32 aWhichFrame, const nsIntRect & aRect, PRUint32 aFlags, imgIContainer **_retval NS_OUTPARAM);
79 : NS_IMETHOD Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter, const gfxMatrix & aUserSpaceToImageSpace, const gfxRect & aFill, const nsIntRect & aSubimage, const nsIntSize & aViewportSize, PRUint32 aFlags);
80 : NS_IMETHOD_(nsIFrame *) GetRootLayoutFrame(void);
81 : NS_SCRIPTABLE NS_IMETHOD RequestDecode(void);
82 : NS_SCRIPTABLE NS_IMETHOD LockImage(void);
83 : NS_SCRIPTABLE NS_IMETHOD UnlockImage(void);
84 : NS_SCRIPTABLE NS_IMETHOD RequestDiscard(void);
85 : NS_SCRIPTABLE NS_IMETHOD ResetAnimation(void);
86 : NS_IMETHOD_(void) RequestRefresh(const mozilla::TimeStamp& aTime);
87 : // END NS_DECL_IMGICONTAINER
88 :
89 : VectorImage(imgStatusTracker* aStatusTracker = nsnull);
90 : virtual ~VectorImage();
91 :
92 : // Methods inherited from Image
93 : nsresult Init(imgIDecoderObserver* aObserver,
94 : const char* aMimeType,
95 : const char* aURIString,
96 : PRUint32 aFlags);
97 : void GetCurrentFrameRect(nsIntRect& aRect);
98 :
99 : virtual size_t HeapSizeOfSourceWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const;
100 : virtual size_t HeapSizeOfDecodedWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const;
101 : virtual size_t NonHeapSizeOfDecoded() const;
102 : virtual size_t OutOfProcessSizeOfDecoded() const;
103 :
104 : // Callback for SVGRootRenderingObserver
105 : void InvalidateObserver();
106 :
107 : protected:
108 : virtual nsresult StartAnimation();
109 : virtual nsresult StopAnimation();
110 : virtual bool ShouldAnimate();
111 :
112 : private:
113 : nsWeakPtr mObserver; //! imgIDecoderObserver
114 : nsRefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
115 : nsRefPtr<SVGRootRenderingObserver> mRenderingObserver;
116 :
117 : nsIntRect mRestrictedRegion; // If we were created by
118 : // ExtractFrame, this is the region
119 : // that we're restricted to using.
120 : // Otherwise, this is ignored.
121 :
122 : nsIntSize mLastRenderedSize; // The viewport-size that we've
123 : // most recently passed to
124 : // mSVGDocumentWrapper as its
125 : // viewport-bounds.
126 :
127 : bool mIsInitialized:1; // Have we been initalized?
128 : bool mIsFullyLoaded:1; // Has OnStopRequest been called?
129 : bool mIsDrawing:1; // Are we currently drawing?
130 : bool mHaveAnimations:1; // Is our SVG content SMIL-animated?
131 : // (Only set after mIsFullyLoaded.)
132 : bool mHaveRestrictedRegion:1; // Are we a restricted-region clone
133 : // created via ExtractFrame?
134 : };
135 :
136 : } // namespace image
137 : } // namespace mozilla
138 :
139 : #endif // mozilla_imagelib_VectorImage_h_
|