| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 result.append(m_imageValue->cssText()); | 61 result.append(m_imageValue->cssText()); |
| 62 if (m_hotSpotSpecified) { | 62 if (m_hotSpotSpecified) { |
| 63 result.append(' '); | 63 result.append(' '); |
| 64 result.appendNumber(m_hotSpot.x()); | 64 result.appendNumber(m_hotSpot.x()); |
| 65 result.append(' '); | 65 result.append(' '); |
| 66 result.appendNumber(m_hotSpot.y()); | 66 result.appendNumber(m_hotSpot.y()); |
| 67 } | 67 } |
| 68 return result.toString(); | 68 return result.toString(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element) | 71 SVGCursorElement* CSSCursorImageValue::getSVGCursorElement(Element* element) con
st |
| 72 { | 72 { |
| 73 if (!element || !element->isSVGElement()) | 73 if (!element || !element->isSVGElement()) |
| 74 return false; | 74 return nullptr; |
| 75 | 75 |
| 76 if (!isSVGCursor()) | 76 if (!hasFragmentInURL()) |
| 77 return false; | 77 return nullptr; |
| 78 | 78 |
| 79 String url = toCSSImageValue(m_imageValue.get())->url(); | 79 String url = toCSSImageValue(m_imageValue.get())->url(); |
| 80 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url,
element->treeScope())) { | 80 return resourceReferencedByCursorElement(url, element->treeScope()); |
| 81 // FIXME: This will override hot spot specified in CSS, which is probabl
y incorrect. | 81 } |
| 82 SVGLengthContext lengthContext(0); | |
| 83 m_hotSpotSpecified = true; | |
| 84 float x = roundf(cursorElement->x()->currentValue()->value(lengthContext
)); | |
| 85 m_hotSpot.setX(static_cast<int>(x)); | |
| 86 | 82 |
| 87 float y = roundf(cursorElement->y()->currentValue()->value(lengthContext
)); | 83 void CSSCursorImageValue::clearCachedImageIfNotURL(String url) const |
| 88 m_hotSpot.setY(static_cast<int>(y)); | 84 { |
| 89 | 85 if (cachedImageURL() != url) { |
| 90 if (cachedImageURL() != element->document().completeURL(cursorElement->h
ref()->currentValue()->value())) | 86 m_cachedImage = nullptr; |
| 91 clearImageResource(); | 87 m_isCachePending = true; |
| 92 | |
| 93 SVGElement* svgElement = toSVGElement(element); | |
| 94 svgElement->setCursorImageValue(this); | |
| 95 cursorElement->addClient(svgElement); | |
| 96 return true; | |
| 97 } | 88 } |
| 98 | |
| 99 return false; | |
| 100 } | 89 } |
| 101 | 90 |
| 102 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const | 91 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const |
| 103 { | 92 { |
| 104 // Need to delegate completely so that changes in device scale factor can be
handled appropriately. | 93 // Need to delegate completely so that changes in device scale factor can be
handled appropriately. |
| 105 if (m_imageValue->isImageSetValue()) | 94 if (m_imageValue->isImageSetValue()) |
| 106 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto
r); | 95 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto
r); |
| 107 return m_isCachePending; | 96 return m_isCachePending; |
| 108 } | 97 } |
| 109 | 98 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 { | 109 { |
| 121 if (m_imageValue->isImageSetValue()) | 110 if (m_imageValue->isImageSetValue()) |
| 122 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal
eFactor); | 111 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal
eFactor); |
| 123 | 112 |
| 124 if (m_isCachePending) { | 113 if (m_isCachePending) { |
| 125 m_isCachePending = false; | 114 m_isCachePending = false; |
| 126 | 115 |
| 127 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt | 116 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt |
| 128 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), | 117 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), |
| 129 // we create an alternate CSSImageValue to use. | 118 // we create an alternate CSSImageValue to use. |
| 130 if (isSVGCursor() && document) { | 119 if (hasFragmentInURL() && document) { |
| 131 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); | 120 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); |
| 132 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) | 121 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) |
| 133 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *document)) { | 122 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *document)) { |
| 134 CSSImageValue* svgImageValue = CSSImageValue::create(document->c
ompleteURL(cursorElement->href()->currentValue()->value())); | 123 CSSImageValue* svgImageValue = CSSImageValue::create(document->c
ompleteURL(cursorElement->href()->currentValue()->value())); |
| 135 svgImageValue->setReferrer(imageValue->referrer()); | 124 svgImageValue->setReferrer(imageValue->referrer()); |
| 136 m_cachedImage = svgImageValue->cacheImage(document); | 125 m_cachedImage = svgImageValue->cacheImage(document); |
| 137 return m_cachedImage.get(); | 126 return m_cachedImage.get(); |
| 138 } | 127 } |
| 139 } | 128 } |
| 140 | 129 |
| 141 if (m_imageValue->isImageValue()) | 130 if (m_imageValue->isImageValue()) |
| 142 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); | 131 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); |
| 143 } | 132 } |
| 144 | 133 |
| 145 if (m_cachedImage && m_cachedImage->isImageResource()) | 134 if (m_cachedImage && m_cachedImage->isImageResource()) |
| 146 return toStyleFetchedImage(m_cachedImage); | 135 return toStyleFetchedImage(m_cachedImage); |
| 147 return nullptr; | 136 return nullptr; |
| 148 } | 137 } |
| 149 | 138 |
| 150 bool CSSCursorImageValue::isSVGCursor() const | 139 bool CSSCursorImageValue::hasFragmentInURL() const |
| 151 { | 140 { |
| 152 if (m_imageValue->isImageValue()) { | 141 if (m_imageValue->isImageValue()) { |
| 153 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); | 142 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); |
| 154 KURL kurl(ParsedURLString, imageValue->url()); | 143 KURL kurl(ParsedURLString, imageValue->url()); |
| 155 return kurl.hasFragmentIdentifier(); | 144 return kurl.hasFragmentIdentifier(); |
| 156 } | 145 } |
| 157 return false; | 146 return false; |
| 158 } | 147 } |
| 159 | 148 |
| 160 String CSSCursorImageValue::cachedImageURL() | 149 String CSSCursorImageValue::cachedImageURL() const |
| 161 { | 150 { |
| 162 if (!m_cachedImage || !m_cachedImage->isImageResource()) | 151 if (!m_cachedImage || !m_cachedImage->isImageResource()) |
| 163 return String(); | 152 return String(); |
| 164 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString(); | 153 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString(); |
| 165 } | 154 } |
| 166 | 155 |
| 167 void CSSCursorImageValue::clearImageResource() | |
| 168 { | |
| 169 m_cachedImage = nullptr; | |
| 170 m_isCachePending = true; | |
| 171 } | |
| 172 | |
| 173 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const | 156 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const |
| 174 { | 157 { |
| 175 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.
m_hotSpot : !other.m_hotSpotSpecified) | 158 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.
m_hotSpot : !other.m_hotSpotSpecified) |
| 176 && compareCSSValuePtr(m_imageValue, other.m_imageValue); | 159 && compareCSSValuePtr(m_imageValue, other.m_imageValue); |
| 177 } | 160 } |
| 178 | 161 |
| 179 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) | 162 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) |
| 180 { | 163 { |
| 181 visitor->trace(m_imageValue); | 164 visitor->trace(m_imageValue); |
| 182 visitor->trace(m_cachedImage); | 165 visitor->trace(m_cachedImage); |
| 183 CSSValue::traceAfterDispatch(visitor); | 166 CSSValue::traceAfterDispatch(visitor); |
| 184 } | 167 } |
| 185 | 168 |
| 186 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |