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 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef MOZILLA_IMAGELIB_IMAGE_H_
39 : #define MOZILLA_IMAGELIB_IMAGE_H_
40 :
41 : #include "imgIContainer.h"
42 : #include "imgStatusTracker.h"
43 : #include "prtypes.h"
44 :
45 : namespace mozilla {
46 : namespace image {
47 :
48 : class Image : public imgIContainer
49 24 : {
50 : public:
51 : // From NS_DECL_IMGICONTAINER:
52 : NS_SCRIPTABLE NS_IMETHOD GetAnimationMode(PRUint16 *aAnimationMode);
53 : NS_SCRIPTABLE NS_IMETHOD SetAnimationMode(PRUint16 aAnimationMode);
54 :
55 186 : imgStatusTracker& GetStatusTracker() { return *mStatusTracker; }
56 :
57 : /**
58 : * Flags for Image initialization.
59 : *
60 : * Meanings:
61 : *
62 : * INIT_FLAG_NONE: Lack of flags
63 : *
64 : * INIT_FLAG_DISCARDABLE: The container should be discardable
65 : *
66 : * INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
67 : * decoding on load.
68 : *
69 : * INIT_FLAG_MULTIPART: The container will be used to display a stream of
70 : * images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
71 : * and INIT_FLAG_DECODE_ON_DRAW must not be set.
72 : */
73 : static const PRUint32 INIT_FLAG_NONE = 0x0;
74 : static const PRUint32 INIT_FLAG_DISCARDABLE = 0x1;
75 : static const PRUint32 INIT_FLAG_DECODE_ON_DRAW = 0x2;
76 : static const PRUint32 INIT_FLAG_MULTIPART = 0x4;
77 :
78 : /**
79 : * Creates a new image container.
80 : *
81 : * @param aObserver Observer to send decoder and animation notifications to.
82 : * @param aMimeType The mimetype of the image.
83 : * @param aFlags Initialization flags of the INIT_FLAG_* variety.
84 : */
85 : virtual nsresult Init(imgIDecoderObserver* aObserver,
86 : const char* aMimeType,
87 : const char* aURIString,
88 : PRUint32 aFlags) = 0;
89 :
90 : /**
91 : * The rectangle defining the location and size of the currently displayed
92 : * frame.
93 : */
94 : virtual void GetCurrentFrameRect(nsIntRect& aRect) = 0;
95 :
96 : /**
97 : * The size, in bytes, occupied by the significant data portions of the image.
98 : * This includes both compressed source data and decoded frames.
99 : */
100 : PRUint32 SizeOfData();
101 :
102 : /**
103 : * The components that make up SizeOfData().
104 : */
105 : virtual size_t HeapSizeOfSourceWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const = 0;
106 : virtual size_t HeapSizeOfDecodedWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const = 0;
107 : virtual size_t NonHeapSizeOfDecoded() const = 0;
108 : virtual size_t OutOfProcessSizeOfDecoded() const = 0;
109 :
110 : // Mimetype translation
111 : enum eDecoderType {
112 : eDecoderType_png = 0,
113 : eDecoderType_gif = 1,
114 : eDecoderType_jpeg = 2,
115 : eDecoderType_bmp = 3,
116 : eDecoderType_ico = 4,
117 : eDecoderType_icon = 5,
118 : eDecoderType_unknown = 6
119 : };
120 : static eDecoderType GetDecoderType(const char *aMimeType);
121 :
122 : void IncrementAnimationConsumers();
123 : void DecrementAnimationConsumers();
124 : #ifdef DEBUG
125 : PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
126 : #endif
127 :
128 8 : void SetInnerWindowID(PRUint64 aInnerWindowId) {
129 8 : mInnerWindowId = aInnerWindowId;
130 8 : }
131 1 : PRUint64 InnerWindowID() const { return mInnerWindowId; }
132 :
133 0 : bool HasError() { return mError; }
134 :
135 : protected:
136 : Image(imgStatusTracker* aStatusTracker);
137 :
138 : /**
139 : * Decides whether animation should or should not be happening,
140 : * and makes sure the right thing is being done.
141 : */
142 : virtual void EvaluateAnimation();
143 :
144 : virtual nsresult StartAnimation() = 0;
145 : virtual nsresult StopAnimation() = 0;
146 :
147 : PRUint64 mInnerWindowId;
148 :
149 : // Member data shared by all implementations of this abstract class
150 : nsAutoPtr<imgStatusTracker> mStatusTracker;
151 : PRUint32 mAnimationConsumers;
152 : PRUint16 mAnimationMode; // Enum values in imgIContainer
153 : bool mInitialized:1; // Have we been initalized?
154 : bool mAnimating:1; // Are we currently animating?
155 : bool mError:1; // Error handling
156 :
157 : /**
158 : * Extended by child classes, if they have additional
159 : * conditions for being able to animate
160 : */
161 2 : virtual bool ShouldAnimate() {
162 2 : return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
163 : }
164 : };
165 :
166 : } // namespace image
167 : } // namespace mozilla
168 :
169 : #endif // MOZILLA_IMAGELIB_IMAGE_H_
|