OLD | NEW |
| (Empty) |
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 ImageResource_h | |
24 #define ImageResource_h | |
25 | |
26 #include "core/CoreExport.h" | |
27 #include "core/fetch/ResourcePtr.h" | |
28 #include "platform/geometry/IntRect.h" | |
29 #include "platform/geometry/IntSizeHash.h" | |
30 #include "platform/geometry/LayoutSize.h" | |
31 #include "platform/graphics/ImageObserver.h" | |
32 #include "wtf/HashMap.h" | |
33 | |
34 namespace blink { | |
35 | |
36 class ImageResourceClient; | |
37 class FetchRequest; | |
38 class ResourceFetcher; | |
39 class FloatSize; | |
40 class Length; | |
41 class MemoryCache; | |
42 class LayoutObject; | |
43 class SecurityOrigin; | |
44 class SVGImageForContainer; | |
45 | |
46 class CORE_EXPORT ImageResource final : public Resource, public ImageObserver { | |
47 friend class MemoryCache; | |
48 | |
49 public: | |
50 typedef ImageResourceClient ClientType; | |
51 | |
52 static ResourcePtr<ImageResource> fetch(FetchRequest&, ResourceFetcher*); | |
53 | |
54 ImageResource(blink::Image*); | |
55 // Exposed for testing | |
56 ImageResource(const ResourceRequest&, blink::Image*); | |
57 virtual ~ImageResource(); | |
58 | |
59 virtual void load(ResourceFetcher*, const ResourceLoaderOptions&) override; | |
60 | |
61 blink::Image* image(); // Returns the nullImage() if the image is not availa
ble yet. | |
62 blink::Image* imageForLayoutObject(const LayoutObject*); // Returns the null
Image() if the image is not available yet. | |
63 bool hasImage() const { return m_image.get(); } | |
64 // Side effect: ensures decoded image is in cache, therefore should only be
called when about to draw the image. | |
65 // FIXME: Decoding image on the main thread is expensive, so rather than for
cing decode, consider returning false | |
66 // when image is not decoded yet, as we do in case of deferred decoding. | |
67 bool currentFrameKnownToBeOpaque(const LayoutObject*); | |
68 | |
69 static std::pair<blink::Image*, float> brokenImage(float deviceScaleFactor);
// Returns an image and the image's resolution scale factor. | |
70 bool willPaintBrokenImage() const; | |
71 | |
72 bool canRender(const LayoutObject& layoutObject, float multiplier) { return
!errorOccurred() && !imageSizeForLayoutObject(&layoutObject, multiplier).isEmpty
(); } | |
73 | |
74 void setContainerSizeForLayoutObject(const ImageResourceClient*, const IntSi
ze&, float); | |
75 bool usesImageContainerSize() const; | |
76 bool imageHasRelativeWidth() const; | |
77 bool imageHasRelativeHeight() const; | |
78 // The device pixel ratio we got from the server for this image, or 1.0. | |
79 float devicePixelRatioHeaderValue() const { return m_devicePixelRatioHeaderV
alue; } | |
80 bool hasDevicePixelRatioHeaderValue() const { return m_hasDevicePixelRatioHe
aderValue; } | |
81 | |
82 enum SizeType { | |
83 NormalSize, // Report the size of the image associated with a certain la
youtObject | |
84 IntrinsicSize // Report the intrinsic size, i.e. ignore whatever has bee
n set extrinsically. | |
85 }; | |
86 // This method takes a zoom multiplier that can be used to increase the natu
ral size of the image by the zoom. | |
87 LayoutSize imageSizeForLayoutObject(const LayoutObject*, float multiplier, S
izeType = NormalSize); // returns the size of the complete image. | |
88 void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHei
ght, FloatSize& intrinsicRatio); | |
89 | |
90 bool isAccessAllowed(SecurityOrigin*); | |
91 | |
92 void updateImageAnimationPolicy(); | |
93 | |
94 virtual void didAddClient(ResourceClient*) override; | |
95 virtual void didRemoveClient(ResourceClient*) override; | |
96 | |
97 virtual void allClientsRemoved() override; | |
98 | |
99 virtual void appendData(const char*, unsigned) override; | |
100 virtual void error(Resource::Status) override; | |
101 virtual void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataCon
sumerHandle>) override; | |
102 virtual void finishOnePart() override; | |
103 | |
104 // For compatibility, images keep loading even if there are HTTP errors. | |
105 virtual bool shouldIgnoreHTTPStatusCodeErrors() const override { return true
; } | |
106 | |
107 virtual bool isImage() const override { return true; } | |
108 virtual bool stillNeedsLoad() const override { return !errorOccurred() && st
atus() == Unknown && !isLoading(); } | |
109 | |
110 // ImageObserver | |
111 virtual void decodedSizeChanged(const blink::Image*, int delta) override; | |
112 virtual void didDraw(const blink::Image*) override; | |
113 | |
114 virtual bool shouldPauseAnimation(const blink::Image*) override; | |
115 virtual void animationAdvanced(const blink::Image*) override; | |
116 virtual void changedInRect(const blink::Image*, const IntRect&) override; | |
117 | |
118 protected: | |
119 virtual bool isSafeToUnlock() const override; | |
120 virtual void destroyDecodedDataIfPossible() override; | |
121 | |
122 private: | |
123 static void preCacheDataURIImage(const FetchRequest&, ResourceFetcher*); | |
124 | |
125 class ImageResourceFactory : public ResourceFactory { | |
126 public: | |
127 ImageResourceFactory() | |
128 : ResourceFactory(Resource::Image) { } | |
129 | |
130 Resource* create(const ResourceRequest& request, const String&) const ov
erride | |
131 { | |
132 return new ImageResource(request); | |
133 } | |
134 }; | |
135 ImageResource(const ResourceRequest&); | |
136 | |
137 void clear(); | |
138 | |
139 void setCustomAcceptHeader(); | |
140 void createImage(); | |
141 void updateImage(bool allDataReceived); | |
142 void clearImage(); | |
143 // If not null, changeRect is the changed part of the image. | |
144 void notifyObservers(const IntRect* changeRect = nullptr); | |
145 IntSize svgImageSizeForLayoutObject(const LayoutObject*) const; | |
146 blink::Image* svgImageForLayoutObject(const LayoutObject*); | |
147 bool loadingMultipartContent() const; | |
148 | |
149 float m_devicePixelRatioHeaderValue; | |
150 | |
151 typedef HashMap<const ImageResourceClient*, RefPtr<SVGImageForContainer>> Im
ageForContainerMap; | |
152 OwnPtr<ImageForContainerMap> m_imageForContainerMap; | |
153 | |
154 RefPtr<blink::Image> m_image; | |
155 bool m_hasDevicePixelRatioHeaderValue; | |
156 }; | |
157 | |
158 DEFINE_RESOURCE_TYPE_CASTS(Image); | |
159 | |
160 } | |
161 | |
162 #endif | |
OLD | NEW |