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 21 matching lines...) Expand all Loading... |
32 #include "core/rendering/style/StyleImage.h" | 32 #include "core/rendering/style/StyleImage.h" |
33 #include "core/rendering/style/StylePendingImage.h" | 33 #include "core/rendering/style/StylePendingImage.h" |
34 #include "core/svg/SVGCursorElement.h" | 34 #include "core/svg/SVGCursorElement.h" |
35 #include "core/svg/SVGLengthContext.h" | 35 #include "core/svg/SVGLengthContext.h" |
36 #include "core/svg/SVGURIReference.h" | 36 #include "core/svg/SVGURIReference.h" |
37 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
38 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, Document* document) | 42 static inline SVGCursorElement* resourceReferencedByCursorElement(const String&
url, Document& document) |
43 { | 43 { |
44 Element* element = SVGURIReference::targetElementFromIRIString(url, document
); | 44 Element* element = SVGURIReference::targetElementFromIRIString(url, document
); |
45 if (element && element->hasTagName(SVGNames::cursorTag)) | 45 if (element && element->hasTagName(SVGNames::cursorTag)) |
46 return static_cast<SVGCursorElement*>(element); | 46 return static_cast<SVGCursorElement*>(element); |
47 | 47 |
48 return 0; | 48 return 0; |
49 } | 49 } |
50 | 50 |
51 CSSCursorImageValue::CSSCursorImageValue(PassRefPtr<CSSValue> imageValue, bool h
asHotSpot, const IntPoint& hotSpot) | 51 CSSCursorImageValue::CSSCursorImageValue(PassRefPtr<CSSValue> imageValue, bool h
asHotSpot, const IntPoint& hotSpot) |
52 : CSSValue(CursorImageClass) | 52 : CSSValue(CursorImageClass) |
53 , m_imageValue(imageValue) | 53 , m_imageValue(imageValue) |
54 , m_hasHotSpot(hasHotSpot) | 54 , m_hasHotSpot(hasHotSpot) |
55 , m_hotSpot(hotSpot) | 55 , m_hotSpot(hotSpot) |
56 , m_accessedImage(false) | 56 , m_accessedImage(false) |
57 { | 57 { |
58 } | 58 } |
59 | 59 |
60 CSSCursorImageValue::~CSSCursorImageValue() | 60 CSSCursorImageValue::~CSSCursorImageValue() |
61 { | 61 { |
62 if (!isSVGCursor()) | 62 if (!isSVGCursor()) |
63 return; | 63 return; |
64 | 64 |
65 HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin(); | 65 HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin(); |
66 HashSet<SVGElement*>::const_iterator end = m_referencedElements.end(); | 66 HashSet<SVGElement*>::const_iterator end = m_referencedElements.end(); |
67 String url = toCSSImageValue(m_imageValue.get())->url(); | 67 String url = toCSSImageValue(m_imageValue.get())->url(); |
68 | 68 |
69 for (; it != end; ++it) { | 69 for (; it != end; ++it) { |
70 SVGElement* referencedElement = *it; | 70 SVGElement* referencedElement = *it; |
71 referencedElement->cursorImageValueRemoved(); | 71 referencedElement->cursorImageValueRemoved(); |
72 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(
url, &referencedElement->document())) | 72 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(
url, referencedElement->document())) |
73 cursorElement->removeClient(referencedElement); | 73 cursorElement->removeClient(referencedElement); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 String CSSCursorImageValue::customCssText() const | 77 String CSSCursorImageValue::customCssText() const |
78 { | 78 { |
79 StringBuilder result; | 79 StringBuilder result; |
80 result.append(m_imageValue->cssText()); | 80 result.append(m_imageValue->cssText()); |
81 if (m_hasHotSpot) { | 81 if (m_hasHotSpot) { |
82 result.append(' '); | 82 result.append(' '); |
83 result.appendNumber(m_hotSpot.x()); | 83 result.appendNumber(m_hotSpot.x()); |
84 result.append(' '); | 84 result.append(' '); |
85 result.appendNumber(m_hotSpot.y()); | 85 result.appendNumber(m_hotSpot.y()); |
86 } | 86 } |
87 return result.toString(); | 87 return result.toString(); |
88 } | 88 } |
89 | 89 |
90 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element) | 90 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element) |
91 { | 91 { |
92 if (!element || !element->isSVGElement()) | 92 if (!element || !element->isSVGElement()) |
93 return false; | 93 return false; |
94 | 94 |
95 if (!isSVGCursor()) | 95 if (!isSVGCursor()) |
96 return false; | 96 return false; |
97 | 97 |
98 String url = toCSSImageValue(m_imageValue.get())->url(); | 98 String url = toCSSImageValue(m_imageValue.get())->url(); |
99 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url,
&element->document())) { | 99 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url,
element->document())) { |
100 // FIXME: This will override hot spot specified in CSS, which is probabl
y incorrect. | 100 // FIXME: This will override hot spot specified in CSS, which is probabl
y incorrect. |
101 SVGLengthContext lengthContext(0); | 101 SVGLengthContext lengthContext(0); |
102 m_hasHotSpot = true; | 102 m_hasHotSpot = true; |
103 float x = roundf(cursorElement->xCurrentValue().value(lengthContext)); | 103 float x = roundf(cursorElement->xCurrentValue().value(lengthContext)); |
104 m_hotSpot.setX(static_cast<int>(x)); | 104 m_hotSpot.setX(static_cast<int>(x)); |
105 | 105 |
106 float y = roundf(cursorElement->yCurrentValue().value(lengthContext)); | 106 float y = roundf(cursorElement->yCurrentValue().value(lengthContext)); |
107 m_hotSpot.setY(static_cast<int>(y)); | 107 m_hotSpot.setY(static_cast<int>(y)); |
108 | 108 |
109 if (cachedImageURL() != element->document().completeURL(cursorElement->h
refCurrentValue())) | 109 if (cachedImageURL() != element->document().completeURL(cursorElement->h
refCurrentValue())) |
(...skipping 16 matching lines...) Expand all Loading... |
126 | 126 |
127 if (!m_accessedImage) { | 127 if (!m_accessedImage) { |
128 m_accessedImage = true; | 128 m_accessedImage = true; |
129 | 129 |
130 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt | 130 // For SVG images we need to lazily substitute in the correct URL. Rathe
r than attempt |
131 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), | 131 // to change the URL of the CSSImageValue (which would then change behav
ior like cssText), |
132 // we create an alternate CSSImageValue to use. | 132 // we create an alternate CSSImageValue to use. |
133 if (isSVGCursor() && loader && loader->document()) { | 133 if (isSVGCursor() && loader && loader->document()) { |
134 RefPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageValue.get(
)); | 134 RefPtr<CSSImageValue> imageValue = toCSSImageValue(m_imageValue.get(
)); |
135 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) | 135 // FIXME: This will fail if the <cursor> element is in a shadow DOM
(bug 59827) |
136 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), loader->document())) { | 136 if (SVGCursorElement* cursorElement = resourceReferencedByCursorElem
ent(imageValue->url(), *loader->document())) { |
137 RefPtr<CSSImageValue> svgImageValue = CSSImageValue::create(curs
orElement->hrefCurrentValue()); | 137 RefPtr<CSSImageValue> svgImageValue = CSSImageValue::create(curs
orElement->hrefCurrentValue()); |
138 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(load
er); | 138 StyleFetchedImage* cachedImage = svgImageValue->cachedImage(load
er); |
139 m_image = cachedImage; | 139 m_image = cachedImage; |
140 return cachedImage; | 140 return cachedImage; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 if (m_imageValue->isImageValue()) | 144 if (m_imageValue->isImageValue()) |
145 m_image = toCSSImageValue(m_imageValue.get())->cachedImage(loader); | 145 m_image = toCSSImageValue(m_imageValue.get())->cachedImage(loader); |
146 } | 146 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 m_referencedElements.remove(element); | 191 m_referencedElements.remove(element); |
192 } | 192 } |
193 | 193 |
194 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const | 194 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const |
195 { | 195 { |
196 return m_hasHotSpot ? other.m_hasHotSpot && m_hotSpot == other.m_hotSpot : !
other.m_hasHotSpot | 196 return m_hasHotSpot ? other.m_hasHotSpot && m_hotSpot == other.m_hotSpot : !
other.m_hasHotSpot |
197 && compareCSSValuePtr(m_imageValue, other.m_imageValue); | 197 && compareCSSValuePtr(m_imageValue, other.m_imageValue); |
198 } | 198 } |
199 | 199 |
200 } // namespace WebCore | 200 } // namespace WebCore |
OLD | NEW |