Back to index

lightning-sunbird  0.9+nobinonly
imgContainer.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Stuart Parmenter <pavlov@netscape.com>
00024  *   Chris Saari <saari@netscape.com>
00025  *   Asko Tontti <atontti@cc.hut.fi>
00026  *   Arron Mogge <paper@animecity.nu>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsComponentManagerUtils.h"
00043 
00044 #include "imgContainer.h"
00045 
00046 NS_IMPL_ISUPPORTS2(imgContainer, imgIContainer, nsIProperties)
00047 
00048 //******************************************************************************
00049 imgContainer::imgContainer() :
00050   mSize(0,0),
00051   mFrame(nsnull)
00052 {
00053   mProperties = do_CreateInstance("@mozilla.org/properties;1");
00054 }
00055 
00056 //******************************************************************************
00057 imgContainer::~imgContainer()
00058 {
00059   mFrame = nsnull;
00060 }
00061 
00062 //******************************************************************************
00063 /* void init (in PRIn32 aWidth, in PRInt32 aHeight, in imgIContainerObserver aObserver); */
00064 NS_IMETHODIMP imgContainer::Init(PRInt32 aWidth, PRInt32 aHeight, imgIContainerObserver *aObserver)
00065 {
00066   if (aWidth <= 0 || aHeight <= 0) {
00067     NS_WARNING("error - negative image size\n");
00068     return NS_ERROR_FAILURE;
00069   }
00070 
00071   mSize.SizeTo(aWidth, aHeight);
00072 
00073   return NS_OK;
00074 }
00075 
00076 //******************************************************************************
00077 /* readonly attribute gfx_format preferredAlphaChannelFormat; */
00078 NS_IMETHODIMP imgContainer::GetPreferredAlphaChannelFormat(gfx_format *aFormat)
00079 {
00080   NS_ASSERTION(aFormat, "imgContainer::GetPreferredAlphaChannelFormat; Invalid Arg");
00081   if (!aFormat)
00082     return NS_ERROR_INVALID_ARG;
00083 
00084   /* default.. platform's should probably overwrite this */
00085   *aFormat = gfxIFormats::RGB_A8;
00086   return NS_OK;
00087 }
00088 
00089 //******************************************************************************
00090 /* readonly attribute PRInt32 width; */
00091 NS_IMETHODIMP imgContainer::GetWidth(PRInt32 *aWidth)
00092 {
00093   NS_ASSERTION(aWidth, "imgContainer::GetWidth; Invalid Arg");
00094   if (!aWidth)
00095     return NS_ERROR_INVALID_ARG;
00096 
00097   *aWidth = mSize.width;
00098   return NS_OK;
00099 }
00100 
00101 //******************************************************************************
00102 /* readonly attribute PRInt32 height; */
00103 NS_IMETHODIMP imgContainer::GetHeight(PRInt32 *aHeight)
00104 {
00105   NS_ASSERTION(aHeight, "imgContainer::GetHeight; Invalid Arg");
00106   if (!aHeight)
00107     return NS_ERROR_INVALID_ARG;
00108 
00109   *aHeight = mSize.height;
00110   return NS_OK;
00111 }
00112 
00113 //******************************************************************************
00114 /* readonly attribute gfxIImageFrame currentFrame; */
00115 NS_IMETHODIMP imgContainer::GetCurrentFrame(gfxIImageFrame **aCurrentFrame)
00116 {
00117   NS_ASSERTION(aCurrentFrame, "imgContainer::GetCurrentFrame; Invalid Arg");
00118   if (!aCurrentFrame)
00119     return NS_ERROR_INVALID_POINTER;
00120 
00121   if (mFrame) {
00122     *aCurrentFrame = mFrame;
00123     NS_ADDREF(*aCurrentFrame);
00124     return NS_OK;
00125   } else {
00126     *aCurrentFrame = nsnull;
00127     return NS_ERROR_FAILURE;
00128   }
00129 }
00130 
00131 //******************************************************************************
00132 /* readonly attribute unsigned long numFrames; */
00133 NS_IMETHODIMP imgContainer::GetNumFrames(PRUint32 *aNumFrames)
00134 {
00135   NS_ASSERTION(aNumFrames, "imgContainer::GetNumFrames; Invalid Arg");
00136   if (!aNumFrames)
00137     return NS_ERROR_INVALID_ARG;
00138 
00139   *aNumFrames = mFrame ? 1 : 0;
00140   return NS_OK;
00141 }
00142 
00143 //******************************************************************************
00144 /* gfxIImageFrame getFrameAt (in unsigned long index); */
00145 NS_IMETHODIMP imgContainer::GetFrameAt(PRUint32 index, gfxIImageFrame **_retval)
00146 {
00147   NS_ASSERTION(_retval, "imgContainer::GetFrameAt; Invalid Arg");
00148   if (!_retval)
00149     return NS_ERROR_INVALID_POINTER;
00150 
00151   if (!mFrame || index != 0)
00152     return NS_ERROR_FAILURE;
00153   *_retval = mFrame;
00154   NS_ADDREF(*_retval);
00155   return NS_OK;
00156 }
00157 
00158 //******************************************************************************
00159 /* void appendFrame (in gfxIImageFrame item); */
00160 NS_IMETHODIMP imgContainer::AppendFrame(gfxIImageFrame *item)
00161 {
00162   NS_ASSERTION(item, "imgContainer::AppendFrame; Invalid Arg");
00163   if (!item)
00164     return NS_ERROR_INVALID_ARG;
00165   NS_ASSERTION(!mFrame, "imgContainer::AppendFrame; Tried to add another frame when only 1 is allowed");
00166 
00167   if (mFrame)
00168     return NS_ERROR_UNEXPECTED;
00169 
00170   mFrame = item;
00171   return NS_OK;
00172 }
00173 
00174 //******************************************************************************
00175 /* void removeFrame (in gfxIImageFrame item); */
00176 NS_IMETHODIMP imgContainer::RemoveFrame(gfxIImageFrame *item)
00177 {
00178   return NS_ERROR_NOT_IMPLEMENTED;
00179 }
00180 
00181 //******************************************************************************
00182 /* void endFrameDecode (in gfxIImageFrame item, in unsigned long timeout); */
00183 NS_IMETHODIMP imgContainer::EndFrameDecode(PRUint32 aFrameNum, PRUint32 aTimeout)
00184 {
00185   NS_ASSERTION(aFrameNum == 0, "Received an EndFrameDecode call with an invalid frame number");
00186 
00187   if (aFrameNum != 0 || !mFrame)
00188     return NS_ERROR_UNEXPECTED;
00189 
00190   mFrame->SetTimeout(aTimeout);
00191 
00192   return NS_OK;
00193 }
00194 
00195 //******************************************************************************
00196 /* void decodingComplete (); */
00197 NS_IMETHODIMP imgContainer::DecodingComplete(void)
00198 {
00199   return NS_OK;
00200 }
00201 
00202 //******************************************************************************
00203 /* void clear (); */
00204 NS_IMETHODIMP imgContainer::Clear()
00205 {
00206   mFrame = nsnull;
00207   return NS_OK;
00208 }
00209 
00210 //******************************************************************************
00211 NS_IMETHODIMP imgContainer::GetAnimationMode(PRUint16 *aAnimationMode)
00212 {
00213   NS_ASSERTION(aAnimationMode, "imgContainer::GetAnimationMode; Invalid Arg");
00214   if (!aAnimationMode)
00215     return NS_ERROR_INVALID_ARG;
00216 
00217   *aAnimationMode = kDontAnimMode;
00218   return NS_OK;
00219 }
00220 
00221 NS_IMETHODIMP imgContainer::SetAnimationMode(PRUint16 aAnimationMode)
00222 {
00223   // Ignore setting of animation mode
00224   return NS_OK;
00225 }
00226 
00227 //******************************************************************************
00228 /* void startAnimation () */
00229 NS_IMETHODIMP imgContainer::StartAnimation()
00230 {
00231   return NS_OK;
00232 }
00233 
00234 //******************************************************************************
00235 /* void stopAnimation (); */
00236 NS_IMETHODIMP imgContainer::StopAnimation()
00237 {
00238   return NS_OK;
00239 }
00240 
00241 //******************************************************************************
00242 /* attribute long loopCount; */
00243 NS_IMETHODIMP imgContainer::GetLoopCount(PRInt32 *aLoopCount)
00244 {
00245   return NS_ERROR_NOT_IMPLEMENTED;
00246 }
00247 
00248 NS_IMETHODIMP imgContainer::SetLoopCount(PRInt32 aLoopCount)
00249 {
00250   return NS_ERROR_NOT_IMPLEMENTED;
00251 }
00252 
00253 //******************************************************************************
00254 /* void resetAnimation (); */
00255 NS_IMETHODIMP imgContainer::ResetAnimation()
00256 {
00257   return NS_ERROR_NOT_IMPLEMENTED;
00258 }