Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: third_party/WebKit/Source/core/css/CSSCursorImageValue.cpp

Issue 1368613002: Replace RawPtr with RefPtr on StylePendingImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix image set caching logic Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Rob Buis <buis@kde.org> 2 * Copyright (C) 2006 Rob Buis <buis@kde.org>
3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2008 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 10 matching lines...) Expand all
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "core/css/CSSCursorImageValue.h" 23 #include "core/css/CSSCursorImageValue.h"
24 24
25 #include "core/SVGNames.h" 25 #include "core/SVGNames.h"
26 #include "core/css/CSSImageSetValue.h" 26 #include "core/css/CSSImageSetValue.h"
27 #include "core/fetch/ImageResource.h" 27 #include "core/fetch/ImageResource.h"
28 #include "core/style/StyleFetchedImage.h" 28 #include "core/style/StyleFetchedImage.h"
29 #include "core/style/StyleFetchedImageSet.h" 29 #include "core/style/StyleFetchedImageSet.h"
30 #include "core/style/StyleImage.h" 30 #include "core/style/StyleImage.h"
31 #include "core/style/StylePendingImage.h"
32 #include "core/svg/SVGCursorElement.h" 31 #include "core/svg/SVGCursorElement.h"
33 #include "core/svg/SVGLengthContext.h" 32 #include "core/svg/SVGLengthContext.h"
34 #include "core/svg/SVGURIReference.h" 33 #include "core/svg/SVGURIReference.h"
35 #include "wtf/MathExtras.h" 34 #include "wtf/MathExtras.h"
36 #include "wtf/text/StringBuilder.h" 35 #include "wtf/text/StringBuilder.h"
37 #include "wtf/text/WTFString.h" 36 #include "wtf/text/WTFString.h"
38 37
39 namespace blink { 38 namespace blink {
40 39
41 static inline SVGCursorElement* resourceReferencedByCursorElement(const String& url, TreeScope& treeScope) 40 static inline SVGCursorElement* resourceReferencedByCursorElement(const String& url, TreeScope& treeScope)
42 { 41 {
43 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop e); 42 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop e);
44 return isSVGCursorElement(element) ? toSVGCursorElement(element) : nullptr; 43 return isSVGCursorElement(element) ? toSVGCursorElement(element) : nullptr;
45 } 44 }
46 45
47 CSSCursorImageValue::CSSCursorImageValue(PassRefPtrWillBeRawPtr<CSSValue> imageV alue, bool hotSpotSpecified, const IntPoint& hotSpot) 46 CSSCursorImageValue::CSSCursorImageValue(PassRefPtrWillBeRawPtr<CSSValue> imageV alue, bool hotSpotSpecified, const IntPoint& hotSpot)
48 : CSSValue(CursorImageClass) 47 : CSSValue(CursorImageClass)
49 , m_imageValue(imageValue) 48 , m_imageValue(imageValue)
50 , m_hotSpotSpecified(hotSpotSpecified) 49 , m_hotSpotSpecified(hotSpotSpecified)
51 , m_hotSpot(hotSpot) 50 , m_hotSpot(hotSpot)
52 , m_accessedImage(false) 51 , m_isCachePending(true)
53 { 52 {
54 } 53 }
55 54
56 CSSCursorImageValue::~CSSCursorImageValue() 55 CSSCursorImageValue::~CSSCursorImageValue()
57 { 56 {
58 // The below teardown is all handled by weak pointer processing in oilpan. 57 // The below teardown is all handled by weak pointer processing in oilpan.
59 #if !ENABLE(OILPAN) 58 #if !ENABLE(OILPAN)
60 if (!isSVGCursor()) 59 if (!isSVGCursor())
61 return; 60 return;
62 61
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 m_referencedElements.add(svgElement); 109 m_referencedElements.add(svgElement);
111 #endif 110 #endif
112 svgElement->setCursorImageValue(this); 111 svgElement->setCursorImageValue(this);
113 cursorElement->addClient(svgElement); 112 cursorElement->addClient(svgElement);
114 return true; 113 return true;
115 } 114 }
116 115
117 return false; 116 return false;
118 } 117 }
119 118
120 StyleImage* CSSCursorImageValue::cachedImage(Document* document, float deviceSca leFactor) 119 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const
120 {
121 // Need to delegate completely so that changes in device scale factor can be handled appropriately.
122 if (m_imageValue->isImageSetValue())
123 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto r);
124 return m_isCachePending;
125 }
126
127 StyleImage* CSSCursorImageValue::cachedImage(float deviceScaleFactor)
128 {
129 ASSERT(!isCachePending(deviceScaleFactor));
130
131 if (m_imageValue->isImageSetValue())
132 return toCSSImageSetValue(*m_imageValue).cachedImageSet(deviceScaleFacto r);
133 return m_cachedImage.get();
134 }
135
136 StyleImage* CSSCursorImageValue::cacheImage(Document* document, float deviceScal eFactor)
121 { 137 {
122 if (m_imageValue->isImageSetValue()) 138 if (m_imageValue->isImageSetValue())
123 return toCSSImageSetValue(m_imageValue.get())->cachedImageSet(document, deviceScaleFactor); 139 return toCSSImageSetValue(*m_imageValue).cacheImageSet(document, deviceS caleFactor);
124 140
125 if (!m_accessedImage) { 141 if (m_isCachePending) {
126 m_accessedImage = true; 142 m_isCachePending = false;
127 143
128 // For SVG images we need to lazily substitute in the correct URL. Rathe r than attempt 144 // For SVG images we need to lazily substitute in the correct URL. Rathe r than attempt
129 // to change the URL of the CSSImageValue (which would then change behav ior like cssText), 145 // to change the URL of the CSSImageValue (which would then change behav ior like cssText),
130 // we create an alternate CSSImageValue to use. 146 // we create an alternate CSSImageValue to use.
131 if (isSVGCursor() && document) { 147 if (isSVGCursor() && document) {
132 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_ima geValue.get()); 148 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_ima geValue.get());
133 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827) 149 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827)
134 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) { 150 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) {
135 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue: :create(document->completeURL(cursorElement->href()->currentValue()->value())); 151 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue: :create(document->completeURL(cursorElement->href()->currentValue()->value()));
136 svgImageValue->setReferrer(imageValue->referrer()); 152 svgImageValue->setReferrer(imageValue->referrer());
137 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(docu ment); 153 StyleFetchedImage* cachedImage = svgImageValue->cacheImage(docum ent);
138 m_image = cachedImage; 154 m_cachedImage = cachedImage;
139 return cachedImage; 155 return cachedImage;
140 } 156 }
141 } 157 }
142 158
143 if (m_imageValue->isImageValue()) 159 if (m_imageValue->isImageValue())
144 m_image = toCSSImageValue(m_imageValue.get())->cachedImage(document) ; 160 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document);
145 } 161 }
146 162
147 if (m_image && m_image->isImageResource()) 163 if (m_cachedImage && m_cachedImage->isImageResource())
148 return toStyleFetchedImage(m_image); 164 return toStyleFetchedImage(m_cachedImage);
149 return nullptr; 165 return nullptr;
150 } 166 }
151 167
152 StyleImage* CSSCursorImageValue::cachedOrPendingImage(float deviceScaleFactor)
153 {
154 // Need to delegate completely so that changes in device scale factor can be handled appropriately.
155 if (m_imageValue->isImageSetValue())
156 return toCSSImageSetValue(m_imageValue.get())->cachedOrPendingImageSet(d eviceScaleFactor);
157
158 if (!m_image)
159 m_image = StylePendingImage::create(this);
160
161 return m_image.get();
162 }
163
164 bool CSSCursorImageValue::isSVGCursor() const 168 bool CSSCursorImageValue::isSVGCursor() const
165 { 169 {
166 if (m_imageValue->isImageValue()) { 170 if (m_imageValue->isImageValue()) {
167 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageVa lue.get()); 171 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageVa lue.get());
168 KURL kurl(ParsedURLString, imageValue->url()); 172 KURL kurl(ParsedURLString, imageValue->url());
169 return kurl.hasFragmentIdentifier(); 173 return kurl.hasFragmentIdentifier();
170 } 174 }
171 return false; 175 return false;
172 } 176 }
173 177
174 String CSSCursorImageValue::cachedImageURL() 178 String CSSCursorImageValue::cachedImageURL()
175 { 179 {
176 if (!m_image || !m_image->isImageResource()) 180 if (!m_cachedImage || !m_cachedImage->isImageResource())
177 return String(); 181 return String();
178 return toStyleFetchedImage(m_image)->cachedImage()->url().string(); 182 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().string();
179 } 183 }
180 184
181 void CSSCursorImageValue::clearImageResource() 185 void CSSCursorImageValue::clearImageResource()
182 { 186 {
183 m_image = nullptr; 187 m_cachedImage = nullptr;
184 m_accessedImage = false; 188 m_isCachePending = true;
185 } 189 }
186 190
187 #if !ENABLE(OILPAN) 191 #if !ENABLE(OILPAN)
188 void CSSCursorImageValue::removeReferencedElement(SVGElement* element) 192 void CSSCursorImageValue::removeReferencedElement(SVGElement* element)
189 { 193 {
190 m_referencedElements.remove(element); 194 m_referencedElements.remove(element);
191 } 195 }
192 #endif 196 #endif
193 197
194 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const 198 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const
195 { 199 {
196 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other. m_hotSpot : !other.m_hotSpotSpecified) 200 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other. m_hotSpot : !other.m_hotSpotSpecified)
197 && compareCSSValuePtr(m_imageValue, other.m_imageValue); 201 && compareCSSValuePtr(m_imageValue, other.m_imageValue);
198 } 202 }
199 203
200 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) 204 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue)
201 { 205 {
202 visitor->trace(m_imageValue); 206 visitor->trace(m_imageValue);
203 visitor->trace(m_image); 207 visitor->trace(m_cachedImage);
204 CSSValue::traceAfterDispatch(visitor); 208 CSSValue::traceAfterDispatch(visitor);
205 } 209 }
206 210
207 } // namespace blink 211 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSCursorImageValue.h ('k') | third_party/WebKit/Source/core/css/CSSImageSetValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698