Home | History | Annotate | Download | only in loader
      1 /*
      2     Copyright (C) 1998 Lars Knoll (knoll (at) mpi-hd.mpg.de)
      3     Copyright (C) 2001 Dirk Mueller <mueller (at) kde.org>
      4     Copyright (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com)
      5     Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
      6 
      7     This library is free software; you can redistribute it and/or
      8     modify it under the terms of the GNU Library General Public
      9     License as published by the Free Software Foundation; either
     10     version 2 of the License, or (at your option) any later version.
     11 
     12     This library is distributed in the hope that it will be useful,
     13     but WITHOUT ANY WARRANTY; without even the implied warranty of
     14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15     Library General Public License for more details.
     16 
     17     You should have received a copy of the GNU Library General Public License
     18     along with this library; see the file COPYING.LIB.  If not, write to
     19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20     Boston, MA 02110-1301, USA.
     21 */
     22 
     23 #ifndef CachedImage_h
     24 #define CachedImage_h
     25 
     26 #include "CachedResource.h"
     27 #include "ImageObserver.h"
     28 #include "Image.h"
     29 #include "IntRect.h"
     30 #include "Timer.h"
     31 #include <wtf/Vector.h>
     32 
     33 namespace WebCore {
     34 
     35 class DocLoader;
     36 class Cache;
     37 
     38 class CachedImage : public CachedResource, public ImageObserver {
     39     friend class Cache;
     40 
     41 public:
     42     CachedImage(const String& url);
     43     CachedImage(Image*);
     44     virtual ~CachedImage();
     45 
     46     virtual void load(DocLoader* docLoader);
     47 
     48     Image* image() const;
     49 
     50     bool canRender(float multiplier) const { return !errorOccurred() && !imageSize(multiplier).isEmpty(); }
     51 
     52     // These are only used for SVGImage right now
     53     void setImageContainerSize(const IntSize&);
     54     bool usesImageContainerSize() const;
     55     bool imageHasRelativeWidth() const;
     56     bool imageHasRelativeHeight() const;
     57 
     58     // Both of these methods take a zoom multiplier that can be used to increase the natural size of the image by the
     59     // zoom.
     60     IntSize imageSize(float multiplier) const;  // returns the size of the complete image.
     61     IntRect imageRect(float multiplier) const;  // The size of the currently decoded portion of the image.
     62 
     63     virtual void didAddClient(CachedResourceClient*);
     64 
     65     virtual void allClientsRemoved();
     66     virtual void destroyDecodedData();
     67 
     68     virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
     69     virtual void error();
     70 
     71     virtual void httpStatusCodeError() { m_httpStatusCodeErrorOccurred = true; }
     72     bool httpStatusCodeErrorOccurred() const { return m_httpStatusCodeErrorOccurred; }
     73 
     74     virtual bool schedule() const { return true; }
     75 
     76     void checkNotify();
     77 
     78     virtual bool isImage() const { return true; }
     79 
     80     void clear();
     81 
     82     bool stillNeedsLoad() const { return !m_errorOccurred && m_status == Unknown && m_loading == false; }
     83     void load();
     84 
     85     // ImageObserver
     86     virtual void decodedSizeChanged(const Image* image, int delta);
     87     virtual void didDraw(const Image*);
     88 
     89     virtual bool shouldPauseAnimation(const Image*);
     90     virtual void animationAdvanced(const Image*);
     91     virtual void changedInRect(const Image*, const IntRect&);
     92 
     93 private:
     94     void createImage();
     95     size_t maximumDecodedImageSize();
     96     // If not null, changeRect is the changed part of the image.
     97     void notifyObservers(const IntRect* changeRect = 0);
     98     void decodedDataDeletionTimerFired(Timer<CachedImage>*);
     99 
    100     RefPtr<Image> m_image;
    101     Timer<CachedImage> m_decodedDataDeletionTimer;
    102     bool m_httpStatusCodeErrorOccurred;
    103 };
    104 
    105 }
    106 
    107 #endif
    108