OSDN Git Service

Merge "Removing tests that pass after a v8 merge"
[android-x86/external-webkit.git] / WebCore / loader / CachedImage.h
1 /*
2     Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3     Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4     Copyright (C) 2006 Samuel Weinig (sam.weinig@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 "IntRect.h"
29 #include "Timer.h"
30 #include <wtf/Vector.h>
31
32 namespace WebCore {
33
34 class CachedResourceLoader;
35 class Cache;
36
37 class CachedImage : public CachedResource, public ImageObserver {
38     friend class Cache;
39
40 public:
41     CachedImage(const String& url);
42     CachedImage(Image*);
43     virtual ~CachedImage();
44     
45     virtual void load(CachedResourceLoader* cachedResourceLoader);
46
47     Image* image() const;
48
49     bool canRender(float multiplier) const { return !errorOccurred() && !imageSize(multiplier).isEmpty(); }
50
51     // These are only used for SVGImage right now
52     void setImageContainerSize(const IntSize&);
53     bool usesImageContainerSize() const;
54     bool imageHasRelativeWidth() const;
55     bool imageHasRelativeHeight() const;
56     
57     // Both of these methods take a zoom multiplier that can be used to increase the natural size of the image by the
58     // zoom.
59     IntSize imageSize(float multiplier) const;  // returns the size of the complete image.
60     IntRect imageRect(float multiplier) const;  // The size of the currently decoded portion of the image.
61
62     virtual void didAddClient(CachedResourceClient*);
63     
64     virtual void allClientsRemoved();
65     virtual void destroyDecodedData();
66
67     virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
68     virtual void error();
69     
70     virtual void httpStatusCodeError() { m_httpStatusCodeErrorOccurred = true; }
71     bool httpStatusCodeErrorOccurred() const { return m_httpStatusCodeErrorOccurred; }
72     
73     void checkNotify();
74     
75     virtual bool isImage() const { return true; }
76
77     void clear();
78     
79     bool stillNeedsLoad() const { return !errorOccurred() && status() == Unknown && !isLoading(); }
80     void load();
81
82     // ImageObserver
83     virtual void decodedSizeChanged(const Image* image, int delta);
84     virtual void didDraw(const Image*);
85
86     virtual bool shouldPauseAnimation(const Image*);
87     virtual void animationAdvanced(const Image*);
88     virtual void changedInRect(const Image*, const IntRect&);
89
90 private:
91     void createImage();
92     size_t maximumDecodedImageSize();
93     // If not null, changeRect is the changed part of the image.
94     void notifyObservers(const IntRect* changeRect = 0);
95     void decodedDataDeletionTimerFired(Timer<CachedImage>*);
96
97     RefPtr<Image> m_image;
98     Timer<CachedImage> m_decodedDataDeletionTimer;
99     bool m_httpStatusCodeErrorOccurred;
100 };
101
102 }
103
104 #endif