| OLD | NEW |
| 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 Loading... |
| 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" |
| 31 #include "core/svg/SVGCursorElement.h" | 32 #include "core/svg/SVGCursorElement.h" |
| 32 #include "core/svg/SVGLengthContext.h" | 33 #include "core/svg/SVGLengthContext.h" |
| 33 #include "core/svg/SVGURIReference.h" | 34 #include "core/svg/SVGURIReference.h" |
| 34 #include "wtf/MathExtras.h" | 35 #include "wtf/MathExtras.h" |
| 35 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
| 36 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, TreeScope& treeScope) | 41 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, TreeScope& treeScope) |
| 41 { | 42 { |
| 42 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop
e); | 43 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop
e); |
| 43 return isSVGCursorElement(element) ? toSVGCursorElement(element) : nullptr; | 44 return isSVGCursorElement(element) ? toSVGCursorElement(element) : nullptr; |
| 44 } | 45 } |
| 45 | 46 |
| 46 CSSCursorImageValue::CSSCursorImageValue(PassRefPtrWillBeRawPtr<CSSValue> imageV
alue, bool hotSpotSpecified, const IntPoint& hotSpot) | 47 CSSCursorImageValue::CSSCursorImageValue(PassRefPtrWillBeRawPtr<CSSValue> imageV
alue, bool hotSpotSpecified, const IntPoint& hotSpot) |
| 47 : CSSValue(CursorImageClass) | 48 : CSSValue(CursorImageClass) |
| 48 , m_imageValue(imageValue) | 49 , m_imageValue(imageValue) |
| 49 , m_hotSpotSpecified(hotSpotSpecified) | 50 , m_hotSpotSpecified(hotSpotSpecified) |
| 50 , m_hotSpot(hotSpot) | 51 , m_hotSpot(hotSpot) |
| 51 , m_isCachePending(true) | 52 , m_accessedImage(false) |
| 52 { | 53 { |
| 53 } | 54 } |
| 54 | 55 |
| 55 CSSCursorImageValue::~CSSCursorImageValue() | 56 CSSCursorImageValue::~CSSCursorImageValue() |
| 56 { | 57 { |
| 57 // The below teardown is all handled by weak pointer processing in oilpan. | 58 // The below teardown is all handled by weak pointer processing in oilpan. |
| 58 #if !ENABLE(OILPAN) | 59 #if !ENABLE(OILPAN) |
| 59 if (!isSVGCursor()) | 60 if (!isSVGCursor()) |
| 60 return; | 61 return; |
| 61 | 62 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 m_referencedElements.add(svgElement); | 110 m_referencedElements.add(svgElement); |
| 110 #endif | 111 #endif |
| 111 svgElement->setCursorImageValue(this); | 112 svgElement->setCursorImageValue(this); |
| 112 cursorElement->addClient(svgElement); | 113 cursorElement->addClient(svgElement); |
| 113 return true; | 114 return true; |
| 114 } | 115 } |
| 115 | 116 |
| 116 return false; | 117 return false; |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const | 120 StyleImage* CSSCursorImageValue::cachedImage(Document* document, float deviceSca
leFactor) |
| 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) | |
| 137 { | 121 { |
| 138 if (m_imageValue->isImageSetValue()) | 122 if (m_imageValue->isImageSetValue()) |
| 139 return toCSSImageSetValue(*m_imageValue).cacheImageSet(document, deviceS
caleFactor); | 123 return toCSSImageSetValue(m_imageValue.get())->cachedImageSet(document,
deviceScaleFactor); |
| 140 | 124 |
| 141 if (m_isCachePending) { | 125 if (!m_accessedImage) { |
| 142 m_isCachePending = false; | 126 m_accessedImage = true; |
| 143 | 127 |
| 144 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt | 128 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt |
| 145 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), | 129 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), |
| 146 // we create an alternate CSSImageValue to use. | 130 // we create an alternate CSSImageValue to use. |
| 147 if (isSVGCursor() && document) { | 131 if (isSVGCursor() && document) { |
| 148 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_ima
geValue.get()); | 132 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_ima
geValue.get()); |
| 149 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) | 133 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) |
| 150 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *document)) { | 134 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *document)) { |
| 151 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue:
:create(document->completeURL(cursorElement->href()->currentValue()->value())); | 135 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue:
:create(document->completeURL(cursorElement->href()->currentValue()->value())); |
| 152 svgImageValue->setReferrer(imageValue->referrer()); | 136 svgImageValue->setReferrer(imageValue->referrer()); |
| 153 StyleFetchedImage* cachedImage = svgImageValue->cacheImage(docum
ent); | 137 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(docu
ment); |
| 154 m_cachedImage = cachedImage; | 138 m_image = cachedImage; |
| 155 return cachedImage; | 139 return cachedImage; |
| 156 } | 140 } |
| 157 } | 141 } |
| 158 | 142 |
| 159 if (m_imageValue->isImageValue()) | 143 if (m_imageValue->isImageValue()) |
| 160 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); | 144 m_image = toCSSImageValue(m_imageValue.get())->cachedImage(document)
; |
| 161 } | 145 } |
| 162 | 146 |
| 163 if (m_cachedImage && m_cachedImage->isImageResource()) | 147 if (m_image && m_image->isImageResource()) |
| 164 return toStyleFetchedImage(m_cachedImage); | 148 return toStyleFetchedImage(m_image); |
| 165 return nullptr; | 149 return nullptr; |
| 166 } | 150 } |
| 167 | 151 |
| 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 |
| 168 bool CSSCursorImageValue::isSVGCursor() const | 164 bool CSSCursorImageValue::isSVGCursor() const |
| 169 { | 165 { |
| 170 if (m_imageValue->isImageValue()) { | 166 if (m_imageValue->isImageValue()) { |
| 171 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageVa
lue.get()); | 167 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageVa
lue.get()); |
| 172 KURL kurl(ParsedURLString, imageValue->url()); | 168 KURL kurl(ParsedURLString, imageValue->url()); |
| 173 return kurl.hasFragmentIdentifier(); | 169 return kurl.hasFragmentIdentifier(); |
| 174 } | 170 } |
| 175 return false; | 171 return false; |
| 176 } | 172 } |
| 177 | 173 |
| 178 String CSSCursorImageValue::cachedImageURL() | 174 String CSSCursorImageValue::cachedImageURL() |
| 179 { | 175 { |
| 180 if (!m_cachedImage || !m_cachedImage->isImageResource()) | 176 if (!m_image || !m_image->isImageResource()) |
| 181 return String(); | 177 return String(); |
| 182 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().string(); | 178 return toStyleFetchedImage(m_image)->cachedImage()->url().string(); |
| 183 } | 179 } |
| 184 | 180 |
| 185 void CSSCursorImageValue::clearImageResource() | 181 void CSSCursorImageValue::clearImageResource() |
| 186 { | 182 { |
| 187 m_cachedImage = nullptr; | 183 m_image = nullptr; |
| 188 m_isCachePending = true; | 184 m_accessedImage = false; |
| 189 } | 185 } |
| 190 | 186 |
| 191 #if !ENABLE(OILPAN) | 187 #if !ENABLE(OILPAN) |
| 192 void CSSCursorImageValue::removeReferencedElement(SVGElement* element) | 188 void CSSCursorImageValue::removeReferencedElement(SVGElement* element) |
| 193 { | 189 { |
| 194 m_referencedElements.remove(element); | 190 m_referencedElements.remove(element); |
| 195 } | 191 } |
| 196 #endif | 192 #endif |
| 197 | 193 |
| 198 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const | 194 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const |
| 199 { | 195 { |
| 200 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.
m_hotSpot : !other.m_hotSpotSpecified) | 196 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.
m_hotSpot : !other.m_hotSpotSpecified) |
| 201 && compareCSSValuePtr(m_imageValue, other.m_imageValue); | 197 && compareCSSValuePtr(m_imageValue, other.m_imageValue); |
| 202 } | 198 } |
| 203 | 199 |
| 204 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) | 200 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) |
| 205 { | 201 { |
| 206 visitor->trace(m_imageValue); | 202 visitor->trace(m_imageValue); |
| 207 visitor->trace(m_cachedImage); | 203 visitor->trace(m_image); |
| 208 CSSValue::traceAfterDispatch(visitor); | 204 CSSValue::traceAfterDispatch(visitor); |
| 209 } | 205 } |
| 210 | 206 |
| 211 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |