1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright (C) 2004, 2005, 2008, 2009 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_URI_REFERENCE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_URI_REFERENCE_H_
#include <memory>
#include "base/callback.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/svg/svg_animated_href.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
namespace blink {
class Document;
class IdTargetObserver;
class SVGElement;
class TreeScope;
class CORE_EXPORT SVGURIReference : public GarbageCollectedMixin {
public:
virtual ~SVGURIReference() = default;
static bool IsKnownAttribute(const QualifiedName&);
// Use this for accesses to 'href' or 'xlink:href' (in that order) for
// elements where both are allowed and don't necessarily inherit from
// SVGURIReference.
static const AtomicString& LegacyHrefString(const SVGElement&);
// Like above, but for elements that inherit from SVGURIReference. Resolves
// against the base URL of the passed Document.
KURL LegacyHrefURL(const Document&) const;
static AtomicString FragmentIdentifierFromIRIString(const String&,
const TreeScope&);
static Element* TargetElementFromIRIString(const String&,
const TreeScope&,
AtomicString* = nullptr);
const String& HrefString() const { return href_->CurrentValue()->Value(); }
// Create an 'id' observer for the href associated with this SVGURIReference
// and its corresponding SVGElement (which should be passed as
// |contextElement|.) Will call buildPendingResource() on |contextElement|
// when changes to the 'id' are noticed.
Element* ObserveTarget(Member<IdTargetObserver>&, SVGElement&);
// Create an 'id' observer for any id denoted by |hrefString|, calling
// buildPendingResource() on |contextElement| on changes.
static Element* ObserveTarget(Member<IdTargetObserver>&,
SVGElement&,
const String& href_string);
// Create an 'id' observer for |id| in the specified TreeScope. On changes,
// the passed Closure will be called.
static Element* ObserveTarget(Member<IdTargetObserver>&,
TreeScope&,
const AtomicString& id,
base::RepeatingClosure);
// Unregister and destroy the observer.
static void UnobserveTarget(Member<IdTargetObserver>&);
// JS API
SVGAnimatedHref* href() const { return href_.Get(); }
void Trace(Visitor*) const override;
protected:
explicit SVGURIReference(SVGElement*);
private:
Member<SVGAnimatedHref> href_;
};
// Helper class used to resolve fragment references. Handles the 'local url
// flag' per https://drafts.csswg.org/css-values/#local-urls .
class SVGURLReferenceResolver {
STACK_ALLOCATED();
public:
SVGURLReferenceResolver(const String& url_string, const Document&);
bool IsLocal() const;
KURL AbsoluteUrl() const;
AtomicString FragmentIdentifier() const;
private:
const String& relative_url_;
const Document* document_;
mutable KURL absolute_url_;
bool is_local_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_URI_REFERENCE_H_
|