Changeset 238452 in webkit
- Timestamp:
- Nov 22, 2018, 3:47:33 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 17 edited
-
ChangeLog (modified) (1 diff)
-
accessibility/AccessibilitySVGElement.cpp (modified) (1 diff)
-
css/CSSCursorImageValue.cpp (modified) (1 diff)
-
rendering/svg/RenderSVGTextPath.cpp (modified) (1 diff)
-
svg/SVGAltGlyphElement.cpp (modified) (1 diff)
-
svg/SVGFEImageElement.cpp (modified) (1 diff)
-
svg/SVGGlyphRefElement.cpp (modified) (1 diff)
-
svg/SVGLinearGradientElement.cpp (modified) (2 diffs)
-
svg/SVGMPathElement.cpp (modified) (2 diffs)
-
svg/SVGRadialGradientElement.cpp (modified) (1 diff)
-
svg/SVGTRefElement.cpp (modified) (3 diffs)
-
svg/SVGTextPathElement.cpp (modified) (1 diff)
-
svg/SVGURIReference.cpp (modified) (1 diff)
-
svg/SVGURIReference.h (modified) (1 diff)
-
svg/SVGUseElement.cpp (modified) (1 diff)
-
svg/animation/SVGSMILElement.cpp (modified) (1 diff)
-
svg/graphics/filters/SVGFEImage.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r238451 r238452 1 2018-11-21 Ryosuke Niwa <rniwa@webkit.org> 2 3 Modernize SVGURIReference::targetElementFromIRIString 4 https://bugs.webkit.org/show_bug.cgi?id=191898 5 6 Reviewed by Daniel Bates. 7 8 Made targetElementFromIRIString return an element and the fragment identifier, 9 and merged urlFromIRIStringWithFragmentIdentifier into it. 10 11 Also replaced the code computing the full URL using the base URL after removing 12 the fragment identifier and rejoining it later with a single call to completeURL. 13 14 No new tests since there should be no observable behavior change. 15 16 * accessibility/AccessibilitySVGElement.cpp: 17 (WebCore::AccessibilitySVGElement::targetForUseElement const): 18 * css/CSSCursorImageValue.cpp: 19 (WebCore::CSSCursorImageValue::updateCursorElement): 20 * rendering/svg/RenderSVGTextPath.cpp: 21 (WebCore::RenderSVGTextPath::layoutPath const): 22 * svg/SVGAltGlyphElement.cpp: 23 (WebCore::SVGAltGlyphElement::hasValidGlyphElements const): 24 * svg/SVGFEImageElement.cpp: 25 (WebCore::SVGFEImageElement::buildPendingResource): 26 * svg/SVGGlyphRefElement.cpp: 27 (WebCore::SVGGlyphRefElement::hasValidGlyphElement const): 28 * svg/SVGLinearGradientElement.cpp: 29 (WebCore::SVGLinearGradientElement::collectGradientAttributes): 30 * svg/SVGMPathElement.cpp: 31 (WebCore::SVGMPathElement::buildPendingResource): 32 (WebCore::SVGMPathElement::pathElement): 33 * svg/SVGRadialGradientElement.cpp: 34 (WebCore::SVGRadialGradientElement::collectGradientAttributes): 35 * svg/SVGTRefElement.cpp: 36 (WebCore::SVGTRefElement::detachTarget): 37 (WebCore::SVGTRefElement::buildPendingResource): 38 * svg/SVGTextPathElement.cpp: 39 (WebCore::SVGTextPathElement::buildPendingResource): 40 * svg/SVGURIReference.cpp: 41 (WebCore::SVGURIReference::targetElementFromIRIString): 42 (WebCore::urlFromIRIStringWithFragmentIdentifier): Deleted. 43 * svg/SVGURIReference.h: 44 * svg/SVGUseElement.cpp: 45 (WebCore::SVGUseElement::findTarget const): 46 * svg/animation/SVGSMILElement.cpp: 47 (WebCore::SVGSMILElement::buildPendingResource): 48 * svg/graphics/filters/SVGFEImage.cpp: 49 (WebCore::FEImage::referencedRenderer const): 50 1 51 2018-11-22 Dean Jackson <dino@apple.com> 2 52 -
trunk/Source/WebCore/accessibility/AccessibilitySVGElement.cpp
r224074 r238452 66 66 href = getAttribute(HTMLNames::hrefAttr); 67 67 68 Element* target = SVGURIReference::targetElementFromIRIString(href, use.document()); 69 if (target) 70 return axObjectCache()->getOrCreate(target); 71 72 return nullptr; 68 auto target = SVGURIReference::targetElementFromIRIString(href, use.document()); 69 if (!target.element) 70 return nullptr; 71 return axObjectCache()->getOrCreate(target.element.get()); 73 72 } 74 73 -
trunk/Source/WebCore/css/CSSCursorImageValue.cpp
r218890 r238452 70 70 return nullptr; 71 71 72 auto * element = SVGURIReference::targetElementFromIRIString(m_originalURL, document);72 auto element = SVGURIReference::targetElementFromIRIString(m_originalURL, document).element; 73 73 if (!is<SVGCursorElement>(element)) 74 74 return nullptr; -
trunk/Source/WebCore/rendering/svg/RenderSVGTextPath.cpp
r224537 r238452 47 47 Path RenderSVGTextPath::layoutPath() const 48 48 { 49 Element* targetElement = SVGURIReference::targetElementFromIRIString(textPathElement().href(), document());50 if (! targetElement || !targetElement->hasTagName(SVGNames::pathTag))49 auto target = SVGURIReference::targetElementFromIRIString(textPathElement().href(), document()); 50 if (!is<SVGPathElement>(target.element)) 51 51 return Path(); 52 53 SVGPathElement& pathElement = downcast<SVGPathElement>(*target Element);54 52 53 SVGPathElement& pathElement = downcast<SVGPathElement>(*target.element); 54 55 55 Path path = pathFromGraphicsElement(&pathElement); 56 56 -
trunk/Source/WebCore/svg/SVGAltGlyphElement.cpp
r234683 r238452 82 82 bool SVGAltGlyphElement::hasValidGlyphElements(Vector<String>& glyphNames) const 83 83 { 84 String target; 85 auto element = makeRefPtr(targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document(), &target)); 84 auto target = targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document()); 86 85 87 if (is<SVGGlyphElement>( element)) {88 glyphNames.append(target );86 if (is<SVGGlyphElement>(target.element)) { 87 glyphNames.append(target.identifier); 89 88 return true; 90 89 } 90 91 if (!is<SVGAltGlyphDefElement>(target.element)) 92 return false; 91 93 92 if (is<SVGAltGlyphDefElement>(element) && downcast<SVGAltGlyphDefElement>(*element).hasValidGlyphElements(glyphNames)) 93 return true; 94 95 return false; 94 return downcast<SVGAltGlyphDefElement>(*target.element).hasValidGlyphElements(glyphNames); 96 95 } 97 96 -
trunk/Source/WebCore/svg/SVGFEImageElement.cpp
r234683 r238452 95 95 return; 96 96 97 String id; 98 auto target = makeRefPtr(SVGURIReference::targetElementFromIRIString(href(), document(), &id)); 99 if (!target) { 100 if (id.isEmpty()) 97 auto target = SVGURIReference::targetElementFromIRIString(href(), document()); 98 if (!target.element) { 99 if (target.identifier.isEmpty()) 101 100 requestImageResource(); 102 101 else { 103 document().accessSVGExtensions().addPendingResource( id, this);102 document().accessSVGExtensions().addPendingResource(target.identifier, this); 104 103 ASSERT(hasPendingResources()); 105 104 } 106 } else if (target ->isSVGElement()) {105 } else if (target.element->isSVGElement()) { 107 106 // Register us with the target in the dependencies map. Any change of hrefElement 108 107 // that leads to relayout/repainting now informs us, so we can react to it. 109 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target. get()));108 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target.element.get())); 110 109 } 111 110 -
trunk/Source/WebCore/svg/SVGGlyphRefElement.cpp
r234683 r238452 51 51 // FIXME: We only support xlink:href so far. 52 52 // https://bugs.webkit.org/show_bug.cgi?id=64787 53 return is<SVGGlyphElement>(targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document(), &glyphName)); 53 auto target = targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document()); 54 glyphName = target.identifier; 55 return is<SVGGlyphElement>(target.element); 54 56 } 55 57 -
trunk/Source/WebCore/svg/SVGLinearGradientElement.cpp
r234620 r238452 142 142 return false; 143 143 144 HashSet< SVGGradientElement*> processedGradients;145 SVGGradientElement* current = this;144 HashSet<Ref<SVGGradientElement>> processedGradients; 145 Ref<SVGGradientElement> current { *this }; 146 146 147 setGradientAttributes( *current, attributes);148 processedGradients.add(current );147 setGradientAttributes(current.get(), attributes); 148 processedGradients.add(current.copyRef()); 149 149 150 150 while (true) { 151 151 // Respect xlink:href, take attributes from referenced element 152 auto refNode = makeRefPtr(SVGURIReference::targetElementFromIRIString(current->href(), document()));153 if (is<SVGGradientElement>( refNode)) {154 current = downcast<SVGGradientElement>( refNode.get());152 auto target = SVGURIReference::targetElementFromIRIString(current->href(), document()); 153 if (is<SVGGradientElement>(target.element)) { 154 current = downcast<SVGGradientElement>(*target.element); 155 155 156 156 // Cycle detection … … 161 161 return false; 162 162 163 setGradientAttributes( *current, attributes, current->hasTagName(SVGNames::linearGradientTag));164 processedGradients.add(current );163 setGradientAttributes(current.get(), attributes, current->hasTagName(SVGNames::linearGradientTag)); 164 processedGradients.add(current.copyRef()); 165 165 } else 166 166 return true; -
trunk/Source/WebCore/svg/SVGMPathElement.cpp
r234683 r238452 56 56 return; 57 57 58 String id; 59 auto target = makeRefPtr(SVGURIReference::targetElementFromIRIString(href(), document(), &id)); 60 if (!target) { 58 auto target = SVGURIReference::targetElementFromIRIString(href(), document()); 59 if (!target.element) { 61 60 // Do not register as pending if we are already pending this resource. 62 if (document().accessSVGExtensions().isPendingResource(this, id))61 if (document().accessSVGExtensions().isPendingResource(this, target.identifier)) 63 62 return; 64 63 65 if (! id.isEmpty()) {66 document().accessSVGExtensions().addPendingResource( id, this);64 if (!target.identifier.isEmpty()) { 65 document().accessSVGExtensions().addPendingResource(target.identifier, this); 67 66 ASSERT(hasPendingResources()); 68 67 } 69 } else if (target ->isSVGElement()) {68 } else if (target.element->isSVGElement()) { 70 69 // Register us with the target in the dependencies map. Any change of hrefElement 71 70 // that leads to relayout/repainting now informs us, so we can react to it. 72 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target. get()));71 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target.element.get())); 73 72 } 74 73 … … 123 122 RefPtr<SVGPathElement> SVGMPathElement::pathElement() 124 123 { 125 Element*target = targetElementFromIRIString(href(), document());126 if (is<SVGPathElement>(target ))127 return downcast<SVGPathElement>(target );124 auto target = targetElementFromIRIString(href(), document()); 125 if (is<SVGPathElement>(target.element)) 126 return downcast<SVGPathElement>(target.element.get()); 128 127 return nullptr; 129 128 } -
trunk/Source/WebCore/svg/SVGRadialGradientElement.cpp
r234620 r238452 162 162 while (true) { 163 163 // Respect xlink:href, take attributes from referenced element 164 auto refNode = makeRefPtr(SVGURIReference::targetElementFromIRIString(current->href(), document()));165 if (is<SVGGradientElement>( refNode)) {166 current = downcast<SVGGradientElement>( refNode.get());164 auto target = SVGURIReference::targetElementFromIRIString(current->href(), document()); 165 if (is<SVGGradientElement>(target.element)) { 166 current = downcast<SVGGradientElement>(target.element.get()); 167 167 168 168 // Cycle detection -
trunk/Source/WebCore/svg/SVGTRefElement.cpp
r234683 r238452 168 168 169 169 // Mark the referenced ID as pending. 170 String id; 171 SVGURIReference::targetElementFromIRIString(href(), document(), &id); 172 if (!id.isEmpty()) 173 document().accessSVGExtensions().addPendingResource(id, this); 170 auto target = SVGURIReference::targetElementFromIRIString(href(), document()); 171 if (!target.identifier.isEmpty()) 172 document().accessSVGExtensions().addPendingResource(target.identifier, this); 174 173 } 175 174 … … 232 231 return; 233 232 234 String id; 235 RefPtr<Element> target = SVGURIReference::targetElementFromIRIString(href(), document(), &id); 236 if (!target.get()) { 237 if (id.isEmpty()) 233 auto target = SVGURIReference::targetElementFromIRIString(href(), document()); 234 if (!target.element) { 235 if (target.identifier.isEmpty()) 238 236 return; 239 237 240 document().accessSVGExtensions().addPendingResource( id, this);238 document().accessSVGExtensions().addPendingResource(target.identifier, this); 241 239 ASSERT(hasPendingResources()); 242 240 return; … … 248 246 // case when we land here from SVGUseElement::buildShadowTree(). 249 247 if (!isInShadowTree()) 250 m_targetListener->attach(target. copyRef());251 252 updateReferencedText(target. get());248 m_targetListener->attach(target.element.copyRef()); 249 250 updateReferencedText(target.element.get()); 253 251 } 254 252 -
trunk/Source/WebCore/svg/SVGTextPathElement.cpp
r234683 r238452 142 142 return; 143 143 144 String id; 145 auto target = makeRefPtr(SVGURIReference::targetElementFromIRIString(href(), document(), &id)); 146 if (!target) { 144 auto target = SVGURIReference::targetElementFromIRIString(href(), document()); 145 if (!target.element) { 147 146 // Do not register as pending if we are already pending this resource. 148 if (document().accessSVGExtensions().isPendingResource(this, id))147 if (document().accessSVGExtensions().isPendingResource(this, target.identifier)) 149 148 return; 150 149 151 if (! id.isEmpty()) {152 document().accessSVGExtensions().addPendingResource( id, this);150 if (!target.identifier.isEmpty()) { 151 document().accessSVGExtensions().addPendingResource(target.identifier, this); 153 152 ASSERT(hasPendingResources()); 154 153 } 155 } else if (target ->hasTagName(SVGNames::pathTag)) {154 } else if (target.element->hasTagName(SVGNames::pathTag)) { 156 155 // Register us with the target in the dependencies map. Any change of hrefElement 157 156 // that leads to relayout/repainting now informs us, so we can react to it. 158 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target. get()));157 document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target.element.get())); 159 158 } 160 159 } -
trunk/Source/WebCore/svg/SVGURIReference.cpp
r234683 r238452 88 88 } 89 89 90 static inline URL urlFromIRIStringWithFragmentIdentifier(const String& url, const Document& document, String& fragmentIdentifier) 90 auto SVGURIReference::targetElementFromIRIString(const String& iri, const Document& document, RefPtr<Document> externalDocument) -> TargetElementResult 91 91 { 92 size_t startOfFragmentIdentifier = url.find('#'); 92 // If there's no fragment identifier contained within the IRI string, we can't lookup an element. 93 size_t startOfFragmentIdentifier = iri.find('#'); 93 94 if (startOfFragmentIdentifier == notFound) 94 return URL();95 return { }; 95 96 96 97 // Exclude the '#' character when determining the fragmentIdentifier. 97 fragmentIdentifier = url.substring(startOfFragmentIdentifier + 1); 98 if (startOfFragmentIdentifier) { 99 URL base(document.baseURL(), url.substring(0, startOfFragmentIdentifier)); 100 return URL(base, url.substring(startOfFragmentIdentifier)); 101 } 98 auto id = iri.substring(startOfFragmentIdentifier + 1); 99 if (id.isEmpty()) 100 return { }; 102 101 103 return URL(document.baseURL(), url.substring(startOfFragmentIdentifier)); 104 } 105 106 Element* SVGURIReference::targetElementFromIRIString(const String& iri, const Document& document, String* fragmentIdentifier, const Document* externalDocument) 107 { 108 // If there's no fragment identifier contained within the IRI string, we can't lookup an element. 109 String id; 110 URL url = urlFromIRIStringWithFragmentIdentifier(iri, document, id); 111 if (url == URL()) 112 return 0; 113 114 if (fragmentIdentifier) 115 *fragmentIdentifier = id; 116 117 if (id.isEmpty()) 118 return 0; 119 102 auto url = document.completeURL(iri); 120 103 if (externalDocument) { 121 104 // Enforce that the referenced url matches the url of the document that we've loaded for it! 122 105 ASSERT(equalIgnoringFragmentIdentifier(url, externalDocument->url())); 123 return externalDocument->getElementById(id);106 return { externalDocument->getElementById(id), WTFMove(id) }; 124 107 } 125 108 126 109 // Exit early if the referenced url is external, and we have no externalDocument given. 127 110 if (isExternalURIReference(iri, document)) 128 return 0;111 return { nullptr, WTFMove(id) }; 129 112 130 return document.getElementById(id);113 return { document.getElementById(id), WTFMove(id) }; 131 114 } 132 115 -
trunk/Source/WebCore/svg/SVGURIReference.h
r234620 r238452 42 42 43 43 static String fragmentIdentifierFromIRIString(const String&, const Document&); 44 static Element* targetElementFromIRIString(const String&, const Document&, String* fragmentIdentifier = nullptr, const Document* externalDocument = nullptr); 44 45 struct TargetElementResult { 46 RefPtr<Element> element; 47 String identifier; 48 }; 49 static TargetElementResult targetElementFromIRIString(const String&, const Document&, RefPtr<Document> externalDocument = nullptr); 45 50 46 51 static bool isExternalURIReference(const String& uri, const Document& document) -
trunk/Source/WebCore/svg/SVGUseElement.cpp
r234995 r238452 411 411 auto& original = correspondingElement ? downcast<SVGUseElement>(*correspondingElement) : *this; 412 412 413 auto targetCandidate = makeRefPtr(targetElementFromIRIString(original.href(), original.document(), targetID, original.externalDocument())); 414 if (targetID && !targetID->isNull()) { 413 auto targetResult = targetElementFromIRIString(original.href(), original.document(), original.externalDocument()); 414 if (targetID) { 415 *targetID = WTFMove(targetResult.identifier); 415 416 // If the reference is external, don't return the target ID to the caller. 416 417 // The caller would use the target ID to wait for a pending resource on the wrong document. 417 418 // If we ever want the change that and let the caller to wait on the external document, 418 419 // we should change this function so it returns the appropriate document to go with the ID. 419 if ( isExternalURIReference(original.href(), original.document()))420 *targetID = String ();421 } 422 if (!is<SVGElement>(target Candidate))420 if (!targetID->isNull() && isExternalURIReference(original.href(), original.document())) 421 *targetID = String { }; 422 } 423 if (!is<SVGElement>(targetResult.element)) 423 424 return nullptr; 424 auto& target = downcast<SVGElement>(*target Candidate);425 auto& target = downcast<SVGElement>(*targetResult.element); 425 426 426 427 if (!target.isConnected() || isDisallowedElement(target)) -
trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp
r234995 r238452 184 184 if (href.isEmpty()) 185 185 target = parentElement(); 186 else 187 target = SVGURIReference::targetElementFromIRIString(href.string(), document(), &id); 186 else { 187 auto result = SVGURIReference::targetElementFromIRIString(href.string(), document()); 188 target = WTFMove(result.element); 189 id = WTFMove(result.identifier); 190 } 188 191 SVGElement* svgTarget = is<SVGElement>(target) ? downcast<SVGElement>(target.get()) : nullptr; 189 192 -
trunk/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp
r225366 r238452 82 82 { 83 83 if (!m_document) 84 return 0;85 Element* hrefElement = SVGURIReference::targetElementFromIRIString(m_href, *m_document);86 if (! hrefElement || !hrefElement->isSVGElement())87 return 0;88 return hrefElement->renderer();84 return nullptr; 85 auto target = SVGURIReference::targetElementFromIRIString(m_href, *m_document); 86 if (!is<SVGElement>(target.element)) 87 return nullptr; 88 return target.element->renderer(); 89 89 } 90 90
Note:
See TracChangeset
for help on using the changeset viewer.