~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/loader/cache/CachedImage.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "LayoutSize.h"
 
30
#include "SVGImageCache.h"
 
31
#include <wtf/Vector.h>
 
32
 
 
33
namespace WebCore {
 
34
 
 
35
class CachedImageClient;
 
36
class CachedResourceLoader;
 
37
class FloatSize;
 
38
class MemoryCache;
 
39
class RenderObject;
 
40
struct Length;
 
41
 
 
42
class CachedImage : public CachedResource, public ImageObserver {
 
43
    friend class MemoryCache;
 
44
 
 
45
public:
 
46
    CachedImage(const ResourceRequest&);
 
47
    CachedImage(Image*);
 
48
    virtual ~CachedImage();
 
49
    
 
50
    virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&);
 
51
 
 
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.
 
56
 
 
57
    std::pair<Image*, float> brokenImage(float deviceScaleFactor) const; // Returns an image and the image's resolution scale factor.
 
58
    bool willPaintBrokenImage() const; 
 
59
 
 
60
    bool canRender(const RenderObject* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); }
 
61
 
 
62
    void setContainerSizeForRenderer(const RenderObject*, const IntSize&, float);
 
63
    bool usesImageContainerSize() const;
 
64
    bool imageHasRelativeWidth() const;
 
65
    bool imageHasRelativeHeight() const;
 
66
    
 
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);
 
70
 
 
71
    virtual void didAddClient(CachedResourceClient*);
 
72
    virtual void didRemoveClient(CachedResourceClient*);
 
73
 
 
74
    virtual void allClientsRemoved();
 
75
    virtual void destroyDecodedData();
 
76
 
 
77
    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
 
78
    virtual void error(CachedResource::Status);
 
79
    virtual void setResponse(const ResourceResponse&);
 
80
    
 
81
    // For compatibility, images keep loading even if there are HTTP errors.
 
82
    virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
 
83
 
 
84
    virtual bool isImage() const { return true; }
 
85
    virtual bool stillNeedsLoad() const OVERRIDE { return !errorOccurred() && status() == Unknown && !isLoading(); }
 
86
 
 
87
    // ImageObserver
 
88
    virtual void decodedSizeChanged(const Image* image, int delta);
 
89
    virtual void didDraw(const Image*);
 
90
 
 
91
    virtual bool shouldPauseAnimation(const Image*);
 
92
    virtual void animationAdvanced(const Image*);
 
93
    virtual void changedInRect(const Image*, const IntRect&);
 
94
 
 
95
    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
96
 
 
97
private:
 
98
    Image* lookupOrCreateImageForRenderer(const RenderObject*);
 
99
 
 
100
    void clear();
 
101
 
 
102
    void createImage();
 
103
    void clearImage();
 
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();
 
109
 
 
110
    RefPtr<Image> m_image;
 
111
#if ENABLE(SVG)
 
112
    OwnPtr<SVGImageCache> m_svgImageCache;
 
113
#endif
 
114
    bool m_shouldPaintBrokenImage;
 
115
};
 
116
 
 
117
}
 
118
 
 
119
#endif