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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 if (element.hasAttribute(SVGNames::hrefAttr)) | 49 if (element.hasAttribute(SVGNames::hrefAttr)) |
50 return element.getAttribute(SVGNames::hrefAttr); | 50 return element.getAttribute(SVGNames::hrefAttr); |
51 return element.getAttribute(XLinkNames::hrefAttr); | 51 return element.getAttribute(XLinkNames::hrefAttr); |
52 } | 52 } |
53 | 53 |
54 KURL SVGURIReference::legacyHrefURL(const Document& document) const | 54 KURL SVGURIReference::legacyHrefURL(const Document& document) const |
55 { | 55 { |
56 return document.completeURL(stripLeadingAndTrailingHTMLSpaces(hrefString()))
; | 56 return document.completeURL(stripLeadingAndTrailingHTMLSpaces(hrefString()))
; |
57 } | 57 } |
58 | 58 |
| 59 SVGURLReferenceResolver::SVGURLReferenceResolver(const String& urlString, const
Document& document) |
| 60 : m_relativeUrl(urlString) |
| 61 , m_document(&document) |
| 62 , m_isLocal(urlString.startsWith('#')) |
| 63 { |
| 64 } |
| 65 |
| 66 KURL SVGURLReferenceResolver::absoluteUrl() const |
| 67 { |
| 68 if (m_absoluteUrl.isNull()) |
| 69 m_absoluteUrl = m_document->completeURL(m_relativeUrl); |
| 70 return m_absoluteUrl; |
| 71 } |
| 72 |
| 73 bool SVGURLReferenceResolver::isLocal() const |
| 74 { |
| 75 return m_isLocal || equalIgnoringFragmentIdentifier(absoluteUrl(), m_documen
t->url()); |
| 76 } |
| 77 |
| 78 AtomicString SVGURLReferenceResolver::fragmentIdentifier() const |
| 79 { |
| 80 // If this is a "fragment-only" URL, then the reference is always local, so |
| 81 // just return what's after the '#' as the fragment. |
| 82 if (m_isLocal) |
| 83 return AtomicString(m_relativeUrl.substring(1)); |
| 84 return AtomicString(absoluteUrl().fragmentIdentifier()); |
| 85 } |
| 86 |
59 AtomicString SVGURIReference::fragmentIdentifierFromIRIString(const String& urlS
tring, const TreeScope& treeScope) | 87 AtomicString SVGURIReference::fragmentIdentifierFromIRIString(const String& urlS
tring, const TreeScope& treeScope) |
60 { | 88 { |
61 const Document& document = treeScope.document(); | 89 SVGURLReferenceResolver resolver(urlString, treeScope.document()); |
62 | 90 if (!resolver.isLocal()) |
63 KURL url = document.completeURL(urlString); | |
64 if (!url.hasFragmentIdentifier() || !equalIgnoringFragmentIdentifier(url, do
cument.url())) | |
65 return emptyAtom; | 91 return emptyAtom; |
66 return AtomicString(url.fragmentIdentifier()); | 92 return resolver.fragmentIdentifier(); |
67 } | 93 } |
68 | 94 |
69 Element* SVGURIReference::targetElementFromIRIString(const String& urlString, co
nst TreeScope& treeScope, AtomicString* fragmentIdentifier) | 95 Element* SVGURIReference::targetElementFromIRIString(const String& urlString, co
nst TreeScope& treeScope, AtomicString* fragmentIdentifier) |
70 { | 96 { |
71 const Document& document = treeScope.document(); | 97 AtomicString id = fragmentIdentifierFromIRIString(urlString, treeScope); |
72 | 98 if (id.isEmpty()) |
73 KURL url = document.completeURL(urlString); | |
74 if (!url.hasFragmentIdentifier() || !equalIgnoringFragmentIdentifier(url, do
cument.url())) | |
75 return nullptr; | 99 return nullptr; |
76 AtomicString id(url.fragmentIdentifier()); | |
77 if (fragmentIdentifier) | 100 if (fragmentIdentifier) |
78 *fragmentIdentifier = id; | 101 *fragmentIdentifier = id; |
79 return treeScope.getElementById(id); | 102 return treeScope.getElementById(id); |
80 } | 103 } |
81 | 104 |
82 } // namespace blink | 105 } // namespace blink |
OLD | NEW |