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

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

Issue 2018923002: Fixed cursor hotspot SVG override and made CSSCursorImageValue constant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
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
87 float y = roundf(cursorElement->y()->currentValue()->value(lengthContext ));
88 m_hotSpot.setY(static_cast<int>(y));
89
90 if (cachedImageURL() != element->document().completeURL(cursorElement->h ref()->currentValue()->value()))
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 } 81 }
101 82
102 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const 83 bool CSSCursorImageValue::isCachePending(float deviceScaleFactor) const
103 { 84 {
104 // Need to delegate completely so that changes in device scale factor can be handled appropriately. 85 // Need to delegate completely so that changes in device scale factor can be handled appropriately.
105 if (m_imageValue->isImageSetValue()) 86 if (m_imageValue->isImageSetValue())
106 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto r); 87 return toCSSImageSetValue(*m_imageValue).isCachePending(deviceScaleFacto r);
107 return m_isCachePending; 88 return m_isCachePending;
108 } 89 }
109 90
(...skipping 10 matching lines...) Expand all
120 { 101 {
121 if (m_imageValue->isImageSetValue()) 102 if (m_imageValue->isImageSetValue())
122 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal eFactor); 103 return toCSSImageSetValue(*m_imageValue).cacheImage(document, deviceScal eFactor);
123 104
124 if (m_isCachePending) { 105 if (m_isCachePending) {
125 m_isCachePending = false; 106 m_isCachePending = false;
126 107
127 // For SVG images we need to lazily substitute in the correct URL. Rathe r than attempt 108 // 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), 109 // to change the URL of the CSSImageValue (which would then change behav ior like cssText),
129 // we create an alternate CSSImageValue to use. 110 // we create an alternate CSSImageValue to use.
130 if (isSVGCursor() && document) { 111 if (hasFragmentInURL() && document) {
131 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); 112 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get());
132 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827) 113 // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827)
133 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) { 114 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem ent(imageValue->url(), *document)) {
134 CSSImageValue* svgImageValue = CSSImageValue::create(document->c ompleteURL(cursorElement->href()->currentValue()->value())); 115 CSSImageValue* svgImageValue = CSSImageValue::create(document->c ompleteURL(cursorElement->href()->currentValue()->value()));
135 svgImageValue->setReferrer(imageValue->referrer()); 116 svgImageValue->setReferrer(imageValue->referrer());
136 m_cachedImage = svgImageValue->cacheImage(document); 117 m_cachedImage = svgImageValue->cacheImage(document);
137 return m_cachedImage.get(); 118 return m_cachedImage.get();
138 } 119 }
139 } 120 }
140 121
141 if (m_imageValue->isImageValue()) 122 if (m_imageValue->isImageValue())
142 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document); 123 m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document);
143 } 124 }
144 125
145 if (m_cachedImage && m_cachedImage->isImageResource()) 126 if (m_cachedImage && m_cachedImage->isImageResource())
146 return toStyleFetchedImage(m_cachedImage); 127 return toStyleFetchedImage(m_cachedImage);
147 return nullptr; 128 return nullptr;
148 } 129 }
149 130
150 bool CSSCursorImageValue::isSVGCursor() const 131 bool CSSCursorImageValue::hasFragmentInURL() const
151 { 132 {
152 if (m_imageValue->isImageValue()) { 133 if (m_imageValue->isImageValue()) {
153 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get()); 134 CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get());
154 KURL kurl(ParsedURLString, imageValue->url()); 135 KURL kurl(ParsedURLString, imageValue->url());
155 return kurl.hasFragmentIdentifier(); 136 return kurl.hasFragmentIdentifier();
156 } 137 }
157 return false; 138 return false;
158 } 139 }
159 140
160 String CSSCursorImageValue::cachedImageURL() 141 String CSSCursorImageValue::cachedImageURL() const
161 { 142 {
162 if (!m_cachedImage || !m_cachedImage->isImageResource()) 143 if (!m_cachedImage || !m_cachedImage->isImageResource())
163 return String(); 144 return String();
164 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString(); 145 return toStyleFetchedImage(m_cachedImage)->cachedImage()->url().getString();
165 } 146 }
166 147
167 void CSSCursorImageValue::clearImageResource() 148 void CSSCursorImageValue::clearImageResource() const
168 { 149 {
169 m_cachedImage = nullptr; 150 m_cachedImage = nullptr;
170 m_isCachePending = true; 151 m_isCachePending = true;
171 } 152 }
172 153
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698