#ifndef ImageResource_h
#define ImageResource_h
#include "core/fetch/ResourcePtr.h"
#include "core/svg/graphics/SVGImageCache.h"
#include "platform/geometry/IntRect.h"
#include "platform/geometry/IntSizeHash.h"
#include "platform/geometry/LayoutSize.h"
#include "platform/graphics/ImageObserver.h"
#include "wtf/HashMap.h"
namespace WebCore {
class ImageResourceClient;
class ResourceFetcher;
class FloatSize;
class Length;
class MemoryCache;
class RenderObject;
class SecurityOrigin;
class ImageResource FINAL : public Resource, public ImageObserver {
friend class MemoryCache;
public:
typedef ImageResourceClient ClientType;
ImageResource(const ResourceRequest&);
ImageResource(WebCore::Image*);
ImageResource(const ResourceRequest&, WebCore::Image*);
virtual ~ImageResource();
virtual void load(ResourceFetcher*, const ResourceLoaderOptions&) OVERRIDE;
WebCore::Image* image();
WebCore::Image* imageForRenderer(const RenderObject*);
bool hasImage() const { return m_image.get(); }
bool currentFrameKnownToBeOpaque(const RenderObject*);
static std::pair<WebCore::Image*, float> brokenImage(float deviceScaleFactor);
bool willPaintBrokenImage() const;
bool canRender(const RenderObject* renderer, float multiplier) { return !errorOccurred() && !imageSizeForRenderer(renderer, multiplier).isEmpty(); }
void setContainerSizeForRenderer(const ImageResourceClient*, const IntSize&, float);
bool usesImageContainerSize() const;
bool imageHasRelativeWidth() const;
bool imageHasRelativeHeight() const;
float devicePixelRatioHeaderValue() const { return m_devicePixelRatioHeaderValue; }
bool hasDevicePixelRatioHeaderValue() const { return m_hasDevicePixelRatioHeaderValue; }
enum SizeType {
NormalSize,
IntrinsicSize
};
LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier, SizeType = NormalSize);
void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
bool isAccessAllowed(SecurityOrigin*);
virtual void didAddClient(ResourceClient*) OVERRIDE;
virtual void didRemoveClient(ResourceClient*) OVERRIDE;
virtual void allClientsRemoved() OVERRIDE;
virtual void appendData(const char*, int) OVERRIDE;
virtual void error(Resource::Status) OVERRIDE;
virtual void responseReceived(const ResourceResponse&) OVERRIDE;
virtual void finishOnePart() OVERRIDE;
virtual bool shouldIgnoreHTTPStatusCodeErrors() const OVERRIDE { return true; }
virtual bool isImage() const OVERRIDE { return true; }
virtual bool stillNeedsLoad() const OVERRIDE { return !errorOccurred() && status() == Unknown && !isLoading(); }
virtual void decodedSizeChanged(const WebCore::Image*, int delta) OVERRIDE;
virtual void didDraw(const WebCore::Image*) OVERRIDE;
virtual bool shouldPauseAnimation(const WebCore::Image*) OVERRIDE;
virtual void animationAdvanced(const WebCore::Image*) OVERRIDE;
virtual void changedInRect(const WebCore::Image*, const IntRect&) OVERRIDE;
protected:
virtual bool isSafeToUnlock() const OVERRIDE;
virtual void destroyDecodedDataIfPossible() OVERRIDE;
private:
void clear();
void setCustomAcceptHeader();
void createImage();
void updateImage(bool allDataReceived);
void clearImage();
void notifyObservers(const IntRect* changeRect = 0);
virtual void switchClientsToRevalidatedResource() OVERRIDE;
typedef pair<IntSize, float> SizeAndZoom;
typedef HashMap<const ImageResourceClient*, SizeAndZoom> ContainerSizeRequests;
ContainerSizeRequests m_pendingContainerSizeRequests;
float m_devicePixelRatioHeaderValue;
RefPtr<WebCore::Image> m_image;
OwnPtr<SVGImageCache> m_svgImageCache;
bool m_loadingMultipartContent;
bool m_hasDevicePixelRatioHeaderValue;
};
DEFINE_RESOURCE_TYPE_CASTS(Image);
}
#endif