OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 return false; | 38 return false; |
39 } | 39 } |
40 | 40 |
41 bool SVGURIReference::isKnownAttribute(const QualifiedName& attrName) | 41 bool SVGURIReference::isKnownAttribute(const QualifiedName& attrName) |
42 { | 42 { |
43 return attrName.matches(XLinkNames::hrefAttr); | 43 return attrName.matches(XLinkNames::hrefAttr); |
44 } | 44 } |
45 | 45 |
46 String SVGURIReference::fragmentIdentifierFromIRIString(const String& url, Docum
ent* document) | 46 String SVGURIReference::fragmentIdentifierFromIRIString(const String& url, const
Document& document) |
47 { | 47 { |
48 ASSERT(document); | |
49 size_t start = url.find('#'); | 48 size_t start = url.find('#'); |
50 if (start == notFound) | 49 if (start == notFound) |
51 return emptyString(); | 50 return emptyString(); |
52 | 51 |
53 KURL base = start ? KURL(document->baseURI(), url.substring(0, start)) : doc
ument->baseURI(); | 52 KURL base = start ? KURL(document.baseURI(), url.substring(0, start)) : docu
ment.baseURI(); |
54 if (equalIgnoringFragmentIdentifier(base, document->url())) | 53 if (equalIgnoringFragmentIdentifier(base, document.url())) |
55 return url.substring(start + 1); | 54 return url.substring(start + 1); |
56 | 55 |
57 return emptyString(); | 56 return emptyString(); |
58 } | 57 } |
59 | 58 |
60 static inline KURL urlFromIRIStringWithFragmentIdentifier(const String& url, Doc
ument* document, String& fragmentIdentifier) | 59 static inline KURL urlFromIRIStringWithFragmentIdentifier(const String& url, con
st Document& document, String& fragmentIdentifier) |
61 { | 60 { |
62 ASSERT(document); | |
63 size_t startOfFragmentIdentifier = url.find('#'); | 61 size_t startOfFragmentIdentifier = url.find('#'); |
64 if (startOfFragmentIdentifier == notFound) | 62 if (startOfFragmentIdentifier == notFound) |
65 return KURL(); | 63 return KURL(); |
66 | 64 |
67 // Exclude the '#' character when determining the fragmentIdentifier. | 65 // Exclude the '#' character when determining the fragmentIdentifier. |
68 fragmentIdentifier = url.substring(startOfFragmentIdentifier + 1); | 66 fragmentIdentifier = url.substring(startOfFragmentIdentifier + 1); |
69 if (startOfFragmentIdentifier) { | 67 if (startOfFragmentIdentifier) { |
70 KURL base(document->baseURI(), url.substring(0, startOfFragmentIdentifie
r)); | 68 KURL base(document.baseURI(), url.substring(0, startOfFragmentIdentifier
)); |
71 return KURL(base, url.substring(startOfFragmentIdentifier)); | 69 return KURL(base, url.substring(startOfFragmentIdentifier)); |
72 } | 70 } |
73 | 71 |
74 return KURL(document->baseURI(), url.substring(startOfFragmentIdentifier)); | 72 return KURL(document.baseURI(), url.substring(startOfFragmentIdentifier)); |
75 } | 73 } |
76 | 74 |
77 Element* SVGURIReference::targetElementFromIRIString(const String& iri, Document
* document, String* fragmentIdentifier, Document* externalDocument) | 75 Element* SVGURIReference::targetElementFromIRIString(const String& iri, const Do
cument& document, String* fragmentIdentifier, Document* externalDocument) |
78 { | 76 { |
79 // If there's no fragment identifier contained within the IRI string, we can
't lookup an element. | 77 // If there's no fragment identifier contained within the IRI string, we can
't lookup an element. |
80 String id; | 78 String id; |
81 KURL url = urlFromIRIStringWithFragmentIdentifier(iri, document, id); | 79 KURL url = urlFromIRIStringWithFragmentIdentifier(iri, document, id); |
82 if (url == KURL()) | 80 if (url == KURL()) |
83 return 0; | 81 return 0; |
84 | 82 |
85 if (fragmentIdentifier) | 83 if (fragmentIdentifier) |
86 *fragmentIdentifier = id; | 84 *fragmentIdentifier = id; |
87 | 85 |
88 if (id.isEmpty()) | 86 if (id.isEmpty()) |
89 return 0; | 87 return 0; |
90 | 88 |
91 if (externalDocument) { | 89 if (externalDocument) { |
92 // Enforce that the referenced url matches the url of the document that
we've loaded for it! | 90 // Enforce that the referenced url matches the url of the document that
we've loaded for it! |
93 ASSERT(equalIgnoringFragmentIdentifier(url, externalDocument->url())); | 91 ASSERT(equalIgnoringFragmentIdentifier(url, externalDocument->url())); |
94 return externalDocument->getElementById(id); | 92 return externalDocument->getElementById(id); |
95 } | 93 } |
96 | 94 |
97 // Exit early if the referenced url is external, and we have no externalDocu
ment given. | 95 // Exit early if the referenced url is external, and we have no externalDocu
ment given. |
98 if (isExternalURIReference(iri, document)) | 96 if (isExternalURIReference(iri, document)) |
99 return 0; | 97 return 0; |
100 | 98 |
101 return document->getElementById(id); | 99 return document.getElementById(id); |
102 } | 100 } |
103 | 101 |
104 void SVGURIReference::addSupportedAttributes(HashSet<QualifiedName>& supportedAt
tributes) | 102 void SVGURIReference::addSupportedAttributes(HashSet<QualifiedName>& supportedAt
tributes) |
105 { | 103 { |
106 supportedAttributes.add(XLinkNames::hrefAttr); | 104 supportedAttributes.add(XLinkNames::hrefAttr); |
107 } | 105 } |
108 | 106 |
109 } | 107 } |
OLD | NEW |