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 26 matching lines...) Expand all Loading... |
37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, TreeScope& treeScope) | 41 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, TreeScope& treeScope) |
42 { | 42 { |
43 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop
e); | 43 Element* element = SVGURIReference::targetElementFromIRIString(url, treeScop
e); |
44 return isSVGCursorElement(element) ? toSVGCursorElement(element) : 0; | 44 return isSVGCursorElement(element) ? toSVGCursorElement(element) : 0; |
45 } | 45 } |
46 | 46 |
47 CSSCursorImageValue::CSSCursorImageValue(PassRefPtrWillBeRawPtr<CSSValue> imageV
alue, bool hotSpotSpecified, const IntPoint& hotSpot) | 47 CSSCursorImageValue::CSSCursorImageValue(CSSValue imageValue, bool hotSpotSpecif
ied, const IntPoint& hotSpot) |
48 : CSSValue(CursorImageClass) | 48 : CSSValueObject(CursorImageClass) |
49 , m_imageValue(imageValue) | 49 , m_imageValue(imageValue) |
50 , m_hotSpotSpecified(hotSpotSpecified) | 50 , m_hotSpotSpecified(hotSpotSpecified) |
51 , m_hotSpot(hotSpot) | 51 , m_hotSpot(hotSpot) |
52 , m_accessedImage(false) | 52 , m_accessedImage(false) |
53 { | 53 { |
54 } | 54 } |
55 | 55 |
56 CSSCursorImageValue::~CSSCursorImageValue() | 56 CSSCursorImageValue::~CSSCursorImageValue() |
57 { | 57 { |
58 // 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. |
59 #if !ENABLE(OILPAN) | 59 #if !ENABLE(OILPAN) |
60 if (!isSVGCursor()) | 60 if (!isSVGCursor()) |
61 return; | 61 return; |
62 | 62 |
63 HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin(); | 63 HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin(); |
64 HashSet<SVGElement*>::const_iterator end = m_referencedElements.end(); | 64 HashSet<SVGElement*>::const_iterator end = m_referencedElements.end(); |
65 String url = toCSSImageValue(m_imageValue.get())->url(); | 65 String url = toCSSImageValue(m_imageValue).url(); |
66 | 66 |
67 for (; it != end; ++it) { | 67 for (; it != end; ++it) { |
68 SVGElement* referencedElement = *it; | 68 SVGElement* referencedElement = *it; |
69 referencedElement->cursorImageValueRemoved(); | 69 referencedElement->cursorImageValueRemoved(); |
70 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(
url, referencedElement->treeScope())) | 70 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(
url, referencedElement->treeScope())) |
71 cursorElement->removeClient(referencedElement); | 71 cursorElement->removeClient(referencedElement); |
72 } | 72 } |
73 #endif | 73 #endif |
74 } | 74 } |
75 | 75 |
76 String CSSCursorImageValue::customCSSText() const | 76 String CSSCursorImageValue::customCSSText() const |
77 { | 77 { |
78 StringBuilder result; | 78 StringBuilder result; |
79 result.append(m_imageValue->cssText()); | 79 result.append(m_imageValue.cssText()); |
80 if (m_hotSpotSpecified) { | 80 if (m_hotSpotSpecified) { |
81 result.append(' '); | 81 result.append(' '); |
82 result.appendNumber(m_hotSpot.x()); | 82 result.appendNumber(m_hotSpot.x()); |
83 result.append(' '); | 83 result.append(' '); |
84 result.appendNumber(m_hotSpot.y()); | 84 result.appendNumber(m_hotSpot.y()); |
85 } | 85 } |
86 return result.toString(); | 86 return result.toString(); |
87 } | 87 } |
88 | 88 |
89 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element) | 89 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element) |
90 { | 90 { |
91 if (!element || !element->isSVGElement()) | 91 if (!element || !element->isSVGElement()) |
92 return false; | 92 return false; |
93 | 93 |
94 if (!isSVGCursor()) | 94 if (!isSVGCursor()) |
95 return false; | 95 return false; |
96 | 96 |
97 String url = toCSSImageValue(m_imageValue.get())->url(); | 97 String url = toCSSImageValue(m_imageValue).url(); |
98 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url,
element->treeScope())) { | 98 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url,
element->treeScope())) { |
99 // FIXME: This will override hot spot specified in CSS, which is probabl
y incorrect. | 99 // FIXME: This will override hot spot specified in CSS, which is probabl
y incorrect. |
100 SVGLengthContext lengthContext(0); | 100 SVGLengthContext lengthContext(0); |
101 m_hotSpotSpecified = true; | 101 m_hotSpotSpecified = true; |
102 float x = roundf(cursorElement->x()->currentValue()->value(lengthContext
)); | 102 float x = roundf(cursorElement->x()->currentValue()->value(lengthContext
)); |
103 m_hotSpot.setX(static_cast<int>(x)); | 103 m_hotSpot.setX(static_cast<int>(x)); |
104 | 104 |
105 float y = roundf(cursorElement->y()->currentValue()->value(lengthContext
)); | 105 float y = roundf(cursorElement->y()->currentValue()->value(lengthContext
)); |
106 m_hotSpot.setY(static_cast<int>(y)); | 106 m_hotSpot.setY(static_cast<int>(y)); |
107 | 107 |
108 if (cachedImageURL() != element->document().completeURL(cursorElement->h
ref()->currentValue()->value())) | 108 if (cachedImageURL() != element->document().completeURL(cursorElement->h
ref()->currentValue()->value())) |
109 clearImageResource(); | 109 clearImageResource(); |
110 | 110 |
111 SVGElement* svgElement = toSVGElement(element); | 111 SVGElement* svgElement = toSVGElement(element); |
112 #if !ENABLE(OILPAN) | 112 #if !ENABLE(OILPAN) |
113 m_referencedElements.add(svgElement); | 113 m_referencedElements.add(svgElement); |
114 #endif | 114 #endif |
115 svgElement->setCursorImageValue(this); | 115 svgElement->setCursorImageValue(this); |
116 cursorElement->addClient(svgElement); | 116 cursorElement->addClient(svgElement); |
117 return true; | 117 return true; |
118 } | 118 } |
119 | 119 |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 StyleImage* CSSCursorImageValue::cachedImage(Document* document, float deviceSca
leFactor) | 123 StyleImage* CSSCursorImageValue::cachedImage(Document* document, float deviceSca
leFactor) |
124 { | 124 { |
125 if (m_imageValue->isImageSetValue()) | 125 if (m_imageValue.isImageSetValue()) |
126 return toCSSImageSetValue(m_imageValue.get())->cachedImageSet(document,
deviceScaleFactor); | 126 return toCSSImageSetValue(m_imageValue).cachedImageSet(document, deviceS
caleFactor); |
127 | 127 |
128 if (!m_accessedImage) { | 128 if (!m_accessedImage) { |
129 m_accessedImage = true; | 129 m_accessedImage = true; |
130 | 130 |
131 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt | 131 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt |
132 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), | 132 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), |
133 // we create an alternate CSSImageValue to use. | 133 // we create an alternate CSSImageValue to use. |
134 if (isSVGCursor() && document) { | 134 if (isSVGCursor() && document) { |
135 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_ima
geValue.get()); | 135 CSSImageValue& imageValue = toCSSImageValue(m_imageValue); |
136 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) | 136 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) |
137 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *document)) { | 137 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue.url(), *document)) { |
138 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue:
:create(document->completeURL(cursorElement->href()->currentValue()->value())); | 138 RefPtrWillBeRawPtr<CSSImageValue> svgImageValue = CSSImageValue:
:create(document->completeURL(cursorElement->href()->currentValue()->value())); |
139 svgImageValue->setReferrer(imageValue->referrer()); | 139 svgImageValue->setReferrer(imageValue.referrer()); |
140 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(docu
ment); | 140 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(docu
ment); |
141 m_image = cachedImage; | 141 m_image = cachedImage; |
142 return cachedImage; | 142 return cachedImage; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 if (m_imageValue->isImageValue()) | 146 if (m_imageValue.isImageValue()) |
147 m_image = toCSSImageValue(m_imageValue.get())->cachedImage(document)
; | 147 m_image = toCSSImageValue(m_imageValue).cachedImage(document); |
148 } | 148 } |
149 | 149 |
150 if (m_image && m_image->isImageResource()) | 150 if (m_image && m_image->isImageResource()) |
151 return toStyleFetchedImage(m_image); | 151 return toStyleFetchedImage(m_image); |
152 return 0; | 152 return 0; |
153 } | 153 } |
154 | 154 |
155 StyleImage* CSSCursorImageValue::cachedOrPendingImage(float deviceScaleFactor) | 155 StyleImage* CSSCursorImageValue::cachedOrPendingImage(float deviceScaleFactor) |
156 { | 156 { |
157 // Need to delegate completely so that changes in device scale factor can be
handled appropriately. | 157 // Need to delegate completely so that changes in device scale factor can be
handled appropriately. |
158 if (m_imageValue->isImageSetValue()) | 158 if (m_imageValue.isImageSetValue()) |
159 return toCSSImageSetValue(m_imageValue.get())->cachedOrPendingImageSet(d
eviceScaleFactor); | 159 return toCSSImageSetValue(m_imageValue).cachedOrPendingImageSet(deviceSc
aleFactor); |
160 | 160 |
161 if (!m_image) | 161 if (!m_image) |
162 m_image = StylePendingImage::create(this); | 162 m_image = StylePendingImage::create(this); |
163 | 163 |
164 return m_image.get(); | 164 return m_image.get(); |
165 } | 165 } |
166 | 166 |
167 bool CSSCursorImageValue::isSVGCursor() const | 167 bool CSSCursorImageValue::isSVGCursor() const |
168 { | 168 { |
169 if (m_imageValue->isImageValue()) { | 169 if (m_imageValue.isImageValue()) { |
170 RefPtrWillBeRawPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageVa
lue.get()); | 170 CSSImageValue& imageValue = toCSSImageValue(m_imageValue); |
171 KURL kurl(ParsedURLString, imageValue->url()); | 171 KURL kurl(ParsedURLString, imageValue.url()); |
172 return kurl.hasFragmentIdentifier(); | 172 return kurl.hasFragmentIdentifier(); |
173 } | 173 } |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 String CSSCursorImageValue::cachedImageURL() | 177 String CSSCursorImageValue::cachedImageURL() |
178 { | 178 { |
179 if (!m_image || !m_image->isImageResource()) | 179 if (!m_image || !m_image->isImageResource()) |
180 return String(); | 180 return String(); |
181 return toStyleFetchedImage(m_image)->cachedImage()->url().string(); | 181 return toStyleFetchedImage(m_image)->cachedImage()->url().string(); |
182 } | 182 } |
183 | 183 |
184 void CSSCursorImageValue::clearImageResource() | 184 void CSSCursorImageValue::clearImageResource() |
185 { | 185 { |
186 m_image = nullptr; | 186 m_image = nullptr; |
187 m_accessedImage = false; | 187 m_accessedImage = false; |
188 } | 188 } |
189 | 189 |
190 #if !ENABLE(OILPAN) | 190 #if !ENABLE(OILPAN) |
191 void CSSCursorImageValue::removeReferencedElement(SVGElement* element) | 191 void CSSCursorImageValue::removeReferencedElement(SVGElement* element) |
192 { | 192 { |
193 m_referencedElements.remove(element); | 193 m_referencedElements.remove(element); |
194 } | 194 } |
195 #endif | 195 #endif |
196 | 196 |
197 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const | 197 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const |
198 { | 198 { |
199 return m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.m
_hotSpot : !other.m_hotSpotSpecified | 199 return m_hotSpotSpecified ? other.m_hotSpotSpecified && m_hotSpot == other.m
_hotSpot : !other.m_hotSpotSpecified |
200 && compareCSSValuePtr(m_imageValue, other.m_imageValue); | 200 && m_imageValue.equals(other.m_imageValue); |
201 } | 201 } |
202 | 202 |
203 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) | 203 DEFINE_TRACE_AFTER_DISPATCH(CSSCursorImageValue) |
204 { | 204 { |
205 visitor->trace(m_imageValue); | 205 visitor->trace(m_imageValue); |
206 CSSValue::traceAfterDispatch(visitor); | 206 CSSValueObject::traceAfterDispatch(visitor); |
207 } | 207 } |
208 | 208 |
209 } // namespace blink | 209 } // namespace blink |
OLD | NEW |