Back to index

lightning-sunbird  0.9+nobinonly
nsTreeImageListener.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) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Dave Hyatt <hyatt@mozilla.org> (Original Author)
00024  *   Jan Varga <varga@ku.sk>
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 MPL, 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 MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsTreeImageListener.h"
00041 #include "nsITreeBoxObject.h"
00042 #include "imgIContainer.h"
00043 
00044 NS_IMPL_ISUPPORTS3(nsTreeImageListener, imgIDecoderObserver, imgIContainerObserver, nsITreeImageListener)
00045 
00046 nsTreeImageListener::nsTreeImageListener(nsITreeBoxObject* aTree)
00047   : mTree(aTree),
00048     mInvalidationSuppressed(PR_TRUE),
00049     mInvalidationArea(nsnull)
00050 {
00051 }
00052 
00053 nsTreeImageListener::~nsTreeImageListener()
00054 {
00055   delete mInvalidationArea;
00056 }
00057 
00058 NS_IMETHODIMP nsTreeImageListener::OnStartDecode(imgIRequest *aRequest)
00059 {
00060   return NS_OK;
00061 }
00062 
00063 NS_IMETHODIMP nsTreeImageListener::OnStartContainer(imgIRequest *aRequest,
00064                                                     imgIContainer *aImage)
00065 {
00066   // Ensure the animation (if any) is started
00067   aImage->StartAnimation();                                                     
00068   return NS_OK;
00069 }
00070 
00071 NS_IMETHODIMP nsTreeImageListener::OnStartFrame(imgIRequest *aRequest,
00072                                                 gfxIImageFrame *aFrame)
00073 {
00074   return NS_OK;
00075 }
00076 
00077 NS_IMETHODIMP nsTreeImageListener::OnDataAvailable(imgIRequest *aRequest,
00078                                                    gfxIImageFrame *aFrame,
00079                                                    const nsRect *aRect)
00080 {
00081   Invalidate();
00082   return NS_OK;
00083 }
00084 
00085 NS_IMETHODIMP nsTreeImageListener::OnStopFrame(imgIRequest *aRequest,
00086                                                gfxIImageFrame *aFrame)
00087 {
00088   return NS_OK;
00089 }
00090 
00091 NS_IMETHODIMP nsTreeImageListener::OnStopContainer(imgIRequest *aRequest,
00092                                                    imgIContainer *aImage)
00093 {
00094   return NS_OK;
00095 }
00096 
00097 NS_IMETHODIMP nsTreeImageListener::OnStopDecode(imgIRequest *aRequest,
00098                                                 nsresult status,
00099                                                 const PRUnichar *statusArg)
00100 {
00101   return NS_OK;
00102 }
00103 
00104 NS_IMETHODIMP nsTreeImageListener::FrameChanged(imgIContainer *aContainer,
00105                                                 gfxIImageFrame *newframe,
00106                                                 nsRect * dirtyRect)
00107 {
00108   Invalidate();
00109   return NS_OK;
00110 }
00111 
00112 
00113 NS_IMETHODIMP
00114 nsTreeImageListener::AddCell(PRInt32 aIndex, nsITreeColumn* aCol)
00115 {
00116   if (!mInvalidationArea) {
00117     mInvalidationArea = new InvalidationArea(aCol);
00118     mInvalidationArea->AddRow(aIndex);
00119   }
00120   else {
00121     InvalidationArea* currArea;
00122     for (currArea = mInvalidationArea; currArea; currArea = currArea->GetNext()) {
00123       if (currArea->GetCol() == aCol) {
00124         currArea->AddRow(aIndex);
00125         break;
00126       }
00127     }
00128     if (!currArea) {
00129       currArea = new InvalidationArea(aCol);
00130       currArea->SetNext(mInvalidationArea);
00131       mInvalidationArea = currArea;
00132       mInvalidationArea->AddRow(aIndex);
00133     }
00134   }
00135 
00136   return NS_OK;
00137 }
00138 
00139 
00140 void
00141 nsTreeImageListener::Invalidate()
00142 {
00143   if (!mInvalidationSuppressed) {
00144     for (InvalidationArea* currArea = mInvalidationArea; currArea; currArea = currArea->GetNext()) {
00145       // Loop from min to max, invalidating each cell that was listening for this image.
00146       for (PRInt32 i = currArea->GetMin(); i <= currArea->GetMax(); ++i) {
00147         mTree->InvalidateCell(i, currArea->GetCol());
00148       }
00149     }
00150   }
00151 }
00152 
00153 nsTreeImageListener::InvalidationArea::InvalidationArea(nsITreeColumn* aCol)
00154   : mCol(aCol),
00155     mMin(-1), // min should start out "undefined"
00156     mMax(0),
00157     mNext(nsnull)
00158 {
00159 }
00160 
00161 void
00162 nsTreeImageListener::InvalidationArea::AddRow(PRInt32 aIndex)
00163 {
00164   if (mMin == -1)
00165     mMin = mMax = aIndex;
00166   else if (aIndex < mMin)
00167     mMin = aIndex;
00168   else if (aIndex > mMax)
00169     mMax = aIndex;
00170 }