Back to index

lightning-sunbird  0.9+nobinonly
nsImageLoadingContent.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 // vim: ft=cpp tw=78 sw=2 et ts=2
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License
00007  * Version 1.1 (the "License"); you may not use this file except in
00008  * compliance with the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is 
00019  * Boris Zbarsky <bzbarsky@mit.edu>.
00020  * Portions created by the Initial Developer are Copyright (C) 2003
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the NPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the NPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsImageLoadingContent_h__
00041 #define nsImageLoadingContent_h__
00042 
00043 #include "nsIImageLoadingContent.h"
00044 #include "imgIRequest.h"
00045 #include "prtypes.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsString.h"
00048 
00055 class nsIURI;
00056 class nsIDocument;
00057 class imgILoader;
00058 class nsIIOService;
00059 
00060 class nsImageLoadingContent : public nsIImageLoadingContent,
00061                               public imgIDecoderObserver_MOZILLA_1_8_BRANCH
00062 {
00063   /* METHODS */
00064 public:
00065   nsImageLoadingContent();
00066   virtual ~nsImageLoadingContent();
00067 
00068   NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
00069   NS_IMETHOD_(nsrefcnt) Release(void) = 0;
00070 
00071   NS_DECL_IMGICONTAINEROBSERVER
00072   NS_DECL_IMGIDECODEROBSERVER
00073   NS_DECL_IMGIDECODEROBSERVER_MOZILLA_1_8_BRANCH
00074   NS_DECL_NSIIMAGELOADINGCONTENT
00075 
00076 protected:
00092   nsresult ImageURIChanged(const nsAString& aNewURI,
00093                            PRBool aForce);
00094 
00100   void CancelImageRequests();
00101 
00110   void DestroyImageLoadingContent();
00111 
00112 private:
00116   struct ImageObserver {
00117     MOZ_DECL_CTOR_COUNTER(ImageObserver)
00118     
00119     ImageObserver(imgIDecoderObserver* aObserver) :
00120       mObserver(aObserver),
00121       mNext(nsnull)
00122     {
00123       MOZ_COUNT_CTOR(ImageObserver);
00124     }
00125     ~ImageObserver()
00126     {
00127       MOZ_COUNT_DTOR(ImageObserver);
00128       delete mNext;
00129     }
00130 
00131     nsCOMPtr<imgIDecoderObserver> mObserver;
00132     ImageObserver* mNext;
00133   };
00134 
00147   void CancelImageRequests(nsresult aReason, PRBool aEvenIfSizeAvailable,
00148                            PRInt16 aNewImageStatus);
00149 
00158   nsIDocument* GetOurDocument();
00159 
00169   nsresult StringToURI(const nsAString& aSpec, nsIDocument* aDocument,
00170                        nsIURI** aURI);
00171 
00177   nsresult FireEvent(const nsAString& aEventType);
00178   class Event;
00179   friend class Event;
00180 
00181 protected:
00188   void PreserveLoadHandlers();
00189   void UnpreserveLoadHandlers();
00190 
00191   /* MEMBERS */
00192 protected:
00193   nsCOMPtr<imgIRequest> mCurrentRequest;
00194   nsCOMPtr<imgIRequest> mPendingRequest;
00195   nsCOMPtr<nsIURI>      mCurrentURI;
00196 
00197 private:
00206   ImageObserver mObserverList;
00207 
00208   PRInt16 mImageBlockingStatus;
00209   // This counts the number of operations that we're currently doing
00210   // that require us to root in nsDOMClassInfo to say that there is
00211   // currently network or other activity that could trigger onload or
00212   // onerror handlers.  The number of things a single node can do at
00213   // once is quite limited, so a PRUint8 should be quite sufficient.
00214   PRUint8 mRootRefCount;
00215   PRPackedBool mLoadingEnabled;
00216 };
00217 
00218 #endif // nsImageLoadingContent_h__