1 | /* |
2 | * Copyright (C) 2004, 2005, 2008, 2009 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
4 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "Document.h" |
25 | #include "QualifiedName.h" |
26 | #include "SVGPropertyOwnerRegistry.h" |
27 | |
28 | namespace WebCore { |
29 | |
30 | class SVGElement; |
31 | |
32 | class SVGURIReference { |
33 | WTF_MAKE_NONCOPYABLE(SVGURIReference); |
34 | public: |
35 | virtual ~SVGURIReference() = default; |
36 | |
37 | void parseAttribute(const QualifiedName&, const AtomicString&); |
38 | |
39 | static String fragmentIdentifierFromIRIString(const String&, const Document&); |
40 | |
41 | struct TargetElementResult { |
42 | RefPtr<Element> element; |
43 | String identifier; |
44 | }; |
45 | static TargetElementResult targetElementFromIRIString(const String&, const TreeScope&, RefPtr<Document> externalDocument = nullptr); |
46 | |
47 | static bool isExternalURIReference(const String& uri, const Document& document) |
48 | { |
49 | // Fragment-only URIs are always internal |
50 | if (uri.startsWith('#')) |
51 | return false; |
52 | |
53 | // If the URI matches our documents URL, we're dealing with a local reference. |
54 | URL url = document.completeURL(uri); |
55 | ASSERT(!url.protocolIsData()); |
56 | return !equalIgnoringFragmentIdentifier(url, document.url()); |
57 | } |
58 | |
59 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGURIReference>; |
60 | |
61 | String href() const { return m_href->currentValue(); } |
62 | SVGAnimatedString& hrefAnimated() { return m_href; } |
63 | |
64 | protected: |
65 | SVGURIReference(SVGElement* contextElement); |
66 | |
67 | static bool isKnownAttribute(const QualifiedName& attributeName); |
68 | |
69 | private: |
70 | Ref<SVGAnimatedString> m_href; |
71 | }; |
72 | |
73 | } // namespace WebCore |
74 | |