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.
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.
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.
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.
26
#include "CachedResource.h"
27
#include "ImageObserver.h"
29
#include "LayoutSize.h"
30
#include "SVGImageCache.h"
31
#include <wtf/Vector.h>
35
class CachedImageClient;
36
class CachedResourceLoader;
42
class CachedImage : public CachedResource, public ImageObserver {
43
friend class MemoryCache;
46
CachedImage(const ResourceRequest&);
48
virtual ~CachedImage();
50
virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&);
52
Image* image(); // Returns the nullImage() if the image is not available yet.
53
Image* imageForRenderer(const RenderObject*); // Returns the nullImage() if the image is not available yet.
54
bool hasImage() const { return m_image.get(); }
55
bool currentFrameHasAlpha(const RenderObject*); // Side effect: ensures decoded image is in cache, therefore should only be called when about to draw the image.
57
std::pair<Image*, float> brokenImage(float deviceScaleFactor) const; // Returns an image and the image's resolution scale factor.
58
bool willPaintBrokenImage() const;
60
bool canRender(const RenderObject* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); }
62
void setContainerSizeForRenderer(const RenderObject*, const IntSize&, float);
63
bool usesImageContainerSize() const;
64
bool imageHasRelativeWidth() const;
65
bool imageHasRelativeHeight() const;
67
// This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom.
68
LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier); // returns the size of the complete image.
69
void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
71
virtual void didAddClient(CachedResourceClient*);
72
virtual void didRemoveClient(CachedResourceClient*);
74
virtual void allClientsRemoved();
75
virtual void destroyDecodedData();
77
virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
78
virtual void error(CachedResource::Status);
79
virtual void setResponse(const ResourceResponse&);
81
// For compatibility, images keep loading even if there are HTTP errors.
82
virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
84
virtual bool isImage() const { return true; }
85
virtual bool stillNeedsLoad() const OVERRIDE { return !errorOccurred() && status() == Unknown && !isLoading(); }
88
virtual void decodedSizeChanged(const Image* image, int delta);
89
virtual void didDraw(const Image*);
91
virtual bool shouldPauseAnimation(const Image*);
92
virtual void animationAdvanced(const Image*);
93
virtual void changedInRect(const Image*, const IntRect&);
95
virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
98
Image* lookupOrCreateImageForRenderer(const RenderObject*);
104
size_t maximumDecodedImageSize();
105
// If not null, changeRect is the changed part of the image.
106
void notifyObservers(const IntRect* changeRect = 0);
107
virtual PurgePriority purgePriority() const { return PurgeFirst; }
108
void checkShouldPaintBrokenImage();
110
RefPtr<Image> m_image;
112
OwnPtr<SVGImageCache> m_svgImageCache;
114
bool m_shouldPaintBrokenImage;