Chromium Code Reviews| 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::clearCachedImage() const |
| 88 m_hotSpot.setY(static_cast<int>(y)); | 84 { |
| 89 | 85 m_cachedImage = nullptr; |
| 90 if (cachedImageURL() != element->document().completeURL(cursorElement->h ref()->currentValue()->value())) | 86 m_isCachePending = true; |
| 91 clearImageResource(); | |
| 92 | |
| 93 SVGElement* svgElement = toSVGElement(element); | |
| 94 svgElement->setCursorImageValue(this); | |
| 95 cursorElement->addClient(svgElement); | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 return false; | |
| 100 } | 87 } |
| 101 | 88 |
| 102 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const | 89 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const |
| 103 { | 90 { |
| 104 // Need to delegate completely so that changes in device scale factor can be handled appropriately. | 91 // Need to delegate completely so that changes in device scale factor can be handled appropriately. |
| 105 if (m_imageValue->isImageSetValue()) | 92 if (m_imageValue->isImageSetValue()) |
| 106 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto r); | 93 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto r); |
| 107 return m_isCachePending; | 94 return m_isCachePending; |
| 108 } | 95 } |
| 109 | 96 |
| 97 String CSSCursorImageValue::cachedImageURL() const | |
| 98 { | |
| 99 if (!m_cachedImage || !m_cachedImage->isImageResource()) | |
| 100 return String(); | |
| 101 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString(); | |
| 102 } | |
| 103 | |
| 110 StyleImage* CSSCursorImageValue::cachedImage(float deviceScaleFactor) const | 104 StyleImage* CSSCursorImageValue::cachedImage(float deviceScaleFactor) const |
| 111 { | 105 { |
| 112 ASSERT(!isCachePending(deviceScaleFactor)); | 106 ASSERT(!isCachePending(deviceScaleFactor)); |
| 113 | 107 |
| 114 if (m_imageValue->isImageSetValue()) | 108 if (m_imageValue->isImageSetValue()) |
| 115 return toCSSImageSetValue(*m_imageValue).cachedImage(deviceScaleFactor); | 109 return toCSSImageSetValue(*m_imageValue).cachedImage(deviceScaleFactor); |
| 116 return m_cachedImage.get(); | 110 return m_cachedImage.get(); |
| 117 } | 111 } |
| 118 | 112 |
| 119 StyleImage* CSSCursorImageValue::cacheImage(Document* document, float deviceScal eFactor) | 113 StyleImage* CSSCursorImageValue::cacheImage(Document* document, float deviceScal eFactor) |
| 120 { | 114 { |
| 121 if (m_imageValue->isImageSetValue()) | 115 if (m_imageValue->isImageSetValue()) |
| 122 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal eFactor); | 116 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal eFactor); |
| 123 | 117 |
| 124 if (m_isCachePending) { | 118 if (m_isCachePending) { |
| 125 m_isCachePending = false; | 119 m_isCachePending = false; |
| 126 | 120 |
| 127 // For SVG images we need to lazily substitute in the correct URL. Rathe r than attempt | 121 // 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), | 122 // to change the URL of the CSSImageValue (which would then change behav ior like cssText), |
| 129 // we create an alternate CSSImageValue to use. | 123 // we create an alternate CSSImageValue to use. |
| 130 if (isSVGCursor() && document) { | 124 if (hasFragmentInURL() && document) { |
| 131 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); | 125 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); |
| 132 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827) | 126 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827) |
| 133 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) { | 127 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) { |
| 134 CSSImageValue* svgImageValue = CSSImageValue::create(document->c ompleteURL(cursorElement->href()->currentValue()->value())); | 128 CSSImageValue* svgImageValue = CSSImageValue::create(document->c ompleteURL(cursorElement->href()->currentValue()->value())); |
| 135 svgImageValue->setReferrer(imageValue->referrer()); | 129 svgImageValue->setReferrer(imageValue->referrer()); |
| 136 m_cachedImage = svgImageValue->cacheImage(document); | 130 m_cachedImage = svgImageValue->cacheImage(document); |
| 137 return m_cachedImage.get(); | 131 return m_cachedImage.get(); |
| 138 } | 132 } |
| 139 } | 133 } |
| 140 | 134 |
| 141 if (m_imageValue->isImageValue()) | 135 if (m_imageValue->isImageValue()) |
| 142 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); | 136 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); |
| 143 } | 137 } |
| 144 | 138 |
| 145 if (m_cachedImage && m_cachedImage->isImageResource()) | 139 if (m_cachedImage && m_cachedImage->isImageResource()) |
| 146 return toStyleFetchedImage(m_cachedImage); | 140 return toStyleFetchedImage(m_cachedImage); |
| 147 return nullptr; | 141 return nullptr; |
| 148 } | 142 } |
| 149 | 143 |
| 150 bool CSSCursorImageValue::isSVGCursor() const | 144 bool CSSCursorImageValue::hasFragmentInURL() const |
| 151 { | 145 { |
| 152 if (m_imageValue->isImageValue()) { | 146 if (m_imageValue->isImageValue()) { |
| 153 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); | 147 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); |
| 154 KURL kurl(ParsedURLString, imageValue->url()); | 148 KURL kurl(ParsedURLString, imageValue->url()); |
| 155 return kurl.hasFragmentIdentifier(); | 149 return kurl.hasFragmentIdentifier(); |
| 156 } | 150 } |
| 157 return false; | 151 return false; |
| 158 } | 152 } |
| 159 | 153 |
| 160 String CSSCursorImageValue::cachedImageURL() | |
|
Timothy Loh
2016/05/31 05:04:35
would be nicer if you left the functions in the sa
sashab
2016/05/31 05:24:12
Done, also renamed clearCachedImage() back to clea
| |
| 161 { | |
| 162 if (!m_cachedImage || !m_cachedImage->isImageResource()) | |
| 163 return String(); | |
| 164 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString(); | |
| 165 } | |
| 166 | |
| 167 void CSSCursorImageValue::clearImageResource() | |
| 168 { | |
| 169 m_cachedImage = nullptr; | |
| 170 m_isCachePending = true; | |
| 171 } | |
| 172 | |
| 173 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const | 154 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const |
| 174 { | 155 { |
| 175 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other. m_hotSpot : !other.m_hotSpotSpecified) | 156 return (m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other. m_hotSpot : !other.m_hotSpotSpecified) |
| 176 && compareCSSValuePtr(m_imageValue, other.m_imageValue); | 157 && compareCSSValuePtr(m_imageValue, other.m_imageValue); |
| 177 } | 158 } |
| 178 | 159 |
| 179 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) | 160 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) |
| 180 { | 161 { |
| 181 visitor->trace(m_imageValue); | 162 visitor->trace(m_imageValue); |
| 182 visitor->trace(m_cachedImage); | 163 visitor->trace(m_cachedImage); |
| 183 CSSValue::traceAfterDispatch(visitor); | 164 CSSValue::traceAfterDispatch(visitor); |
| 184 } | 165 } |
| 185 | 166 |
| 186 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |