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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
* Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
* Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
* Copyright (C) 2012 University of Szeged
* Copyright (C) 2012 Renata Hodovan <reni@webkit.org>
* Copyright (C) 2015 Apple Inc. All rights reserved.
*
* 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.
*/
#include "config.h"
#include "SVGUseElement.h"
#include "CachedResourceLoader.h"
#include "CachedSVGDocument.h"
#include "ElementIterator.h"
#include "Event.h"
#include "RenderSVGResource.h"
#include "RenderSVGTransformableContainer.h"
#include "ShadowRoot.h"
#include "SVGGElement.h"
#include "SVGSVGElement.h"
#include "SVGSymbolElement.h"
#include "XLinkNames.h"
namespace WebCore {
DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::xAttr, X, x)
DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::yAttr, Y, y)
DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::widthAttr, Width, width)
DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::heightAttr, Height, height)
DEFINE_ANIMATED_STRING(SVGUseElement, XLinkNames::hrefAttr, Href, href)
DEFINE_ANIMATED_BOOLEAN(SVGUseElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGUseElement)
REGISTER_LOCAL_ANIMATED_PROPERTY(x)
REGISTER_LOCAL_ANIMATED_PROPERTY(y)
REGISTER_LOCAL_ANIMATED_PROPERTY(width)
REGISTER_LOCAL_ANIMATED_PROPERTY(height)
REGISTER_LOCAL_ANIMATED_PROPERTY(href)
REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
END_REGISTER_ANIMATED_PROPERTIES
inline SVGUseElement::SVGUseElement(const QualifiedName& tagName, Document& document)
: SVGGraphicsElement(tagName, document)
, m_x(LengthModeWidth)
, m_y(LengthModeHeight)
, m_width(LengthModeWidth)
, m_height(LengthModeHeight)
, m_svgLoadEventTimer(*this, &SVGElement::svgLoadEventTimerFired)
{
ASSERT(hasCustomStyleResolveCallbacks());
ASSERT(hasTagName(SVGNames::useTag));
registerAnimatedPropertiesForSVGUseElement();
}
Ref<SVGUseElement> SVGUseElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new SVGUseElement(tagName, document));
}
SVGUseElement::~SVGUseElement()
{
if (m_externalDocument)
m_externalDocument->removeClient(this);
}
void SVGUseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
SVGParsingError parseError = NoError;
if (name == SVGNames::xAttr)
setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
else if (name == SVGNames::yAttr)
setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
else if (name == SVGNames::widthAttr)
setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
else if (name == SVGNames::heightAttr)
setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
reportAttributeParsingError(parseError, name, value);
SVGExternalResourcesRequired::parseAttribute(name, value);
SVGGraphicsElement::parseAttribute(name, value);
SVGURIReference::parseAttribute(name, value);
}
Node::InsertionNotificationRequest SVGUseElement::insertedInto(ContainerNode& rootParent)
{
SVGGraphicsElement::insertedInto(rootParent);
if (inDocument()) {
SVGExternalResourcesRequired::insertedIntoDocument(this);
invalidateShadowTree();
updateExternalDocument();
}
return InsertionDone;
}
void SVGUseElement::removedFrom(ContainerNode& rootParent)
{
SVGGraphicsElement::removedFrom(rootParent);
clearShadowTree();
updateExternalDocument();
}
inline Document* SVGUseElement::externalDocument() const
{
return m_externalDocument ? m_externalDocument->document() : nullptr;
}
void SVGUseElement::transferSizeAttributesToTargetClone(SVGElement& shadowElement) const
{
// FIXME: The check for valueInSpecifiedUnits being non-zero below is a workaround for the fact
// that we currently have no good way to tell whether a particular animatable attribute is a value
// indicating it was unspecified, or specified but could not be parsed. Would be nice to fix that some day.
if (is<SVGSymbolElement>(shadowElement)) {
// Spec (<use> on <symbol>): This generated 'svg' will always have explicit values for attributes width and height.
// If attributes width and/or height are provided on the 'use' element, then these attributes
// will be transferred to the generated 'svg'. If attributes width and/or height are not specified,
// the generated 'svg' element will use values of 100% for these attributes.
shadowElement.setAttribute(SVGNames::widthAttr, (widthIsValid() && width().valueInSpecifiedUnits()) ? AtomicString(width().valueAsString()) : "100%");
shadowElement.setAttribute(SVGNames::heightAttr, (heightIsValid() && height().valueInSpecifiedUnits()) ? AtomicString(height().valueAsString()) : "100%");
} else if (is<SVGSVGElement>(shadowElement)) {
// Spec (<use> on <svg>): If attributes width and/or height are provided on the 'use' element, then these
// values will override the corresponding attributes on the 'svg' in the generated tree.
SVGElement* correspondingElement = shadowElement.correspondingElement();
shadowElement.setAttribute(SVGNames::widthAttr, (widthIsValid() && width().valueInSpecifiedUnits()) ? AtomicString(width().valueAsString()) : (correspondingElement ? correspondingElement->getAttribute(SVGNames::widthAttr) : nullAtom));
shadowElement.setAttribute(SVGNames::heightAttr, (heightIsValid() && height().valueInSpecifiedUnits()) ? AtomicString(height().valueAsString()) : (correspondingElement ? correspondingElement->getAttribute(SVGNames::heightAttr) : nullAtom));
}
}
void SVGUseElement::svgAttributeChanged(const QualifiedName& attrName)
{
InstanceInvalidationGuard guard(*this);
if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr || attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr) {
updateRelativeLengthsInformation();
if (attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr) {
// FIXME: It's unnecessarily inefficient to update both width and height each time either is changed.
if (auto* targetClone = this->targetClone())
transferSizeAttributesToTargetClone(*targetClone);
}
if (auto* renderer = this->renderer())
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
return;
}
if (SVGExternalResourcesRequired::handleAttributeChange(this, attrName))
return;
if (SVGURIReference::isKnownAttribute(attrName)) {
updateExternalDocument();
invalidateShadowTree();
return;
}
if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
invalidateShadowTree();
return;
}
SVGGraphicsElement::svgAttributeChanged(attrName);
}
void SVGUseElement::willAttachRenderers()
{
if (m_shadowTreeNeedsUpdate)
updateShadowTree();
SVGGraphicsElement::willAttachRenderers();
}
static HashSet<AtomicString> createAllowedElementSet()
{
// Spec: "Any 'svg', 'symbol', 'g', graphics element or other 'use' is potentially a template object that can be re-used
// (i.e., "instanced") in the SVG document via a 'use' element."
// "Graphics Element" is defined as 'circle', 'ellipse', 'image', 'line', 'path', 'polygon', 'polyline', 'rect', 'text'
// Excluded are anything that is used by reference or that only make sense to appear once in a document.
using namespace SVGNames;
HashSet<AtomicString> set;
for (auto& tag : { aTag, circleTag, descTag, ellipseTag, gTag, imageTag, lineTag, metadataTag, pathTag, polygonTag, polylineTag, rectTag, svgTag, switchTag, symbolTag, textTag, textPathTag, titleTag, trefTag, tspanTag, useTag })
set.add(tag.localName());
return set;
}
static inline bool isDisallowedElement(const SVGElement& element)
{
static NeverDestroyed<HashSet<AtomicString>> set = createAllowedElementSet();
return !set.get().contains(element.localName());
}
static inline bool isDisallowedElement(const Element& element)
{
return !element.isSVGElement() || isDisallowedElement(downcast<SVGElement>(element));
}
void SVGUseElement::clearShadowTree()
{
if (auto* root = userAgentShadowRoot())
root->removeChildren();
}
void SVGUseElement::buildPendingResource()
{
invalidateShadowTree();
}
void SVGUseElement::updateShadowTree()
{
m_shadowTreeNeedsUpdate = false;
// FIXME: It's expensive to re-clone the entire tree every time. We should find a more efficient way to handle this.
clearShadowTree();
if (isInShadowTree() || !inDocument())
return;
String targetID;
auto* target = findTarget(&targetID);
if (!target) {
document().accessSVGExtensions().addPendingResource(targetID, this);
return;
}
cloneTarget(ensureUserAgentShadowRoot(), *target);
expandUseElementsInShadowTree();
expandSymbolElementsInShadowTree();
transferEventListenersToShadowTree();
updateRelativeLengthsInformation();
// When we invalidate the other shadow trees, it's important that we don't
// follow any cycles and invalidate ourselves. To avoid that, we temporarily
// set m_shadowTreeNeedsUpdate to true so invalidateShadowTree will
// quickly return and do nothing.
ASSERT(!m_shadowTreeNeedsUpdate);
m_shadowTreeNeedsUpdate = true;
invalidateDependentShadowTrees();
m_shadowTreeNeedsUpdate = false;
}
SVGElement* SVGUseElement::targetClone() const
{
auto* root = userAgentShadowRoot();
if (!root)
return nullptr;
return downcast<SVGElement>(root->firstChild());
}
RenderPtr<RenderElement> SVGUseElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
{
return createRenderer<RenderSVGTransformableContainer>(*this, WTFMove(style));
}
static bool isDirectReference(const SVGElement& element)
{
using namespace SVGNames;
return element.hasTagName(circleTag)
|| element.hasTagName(ellipseTag)
|| element.hasTagName(pathTag)
|| element.hasTagName(polygonTag)
|| element.hasTagName(polylineTag)
|| element.hasTagName(rectTag)
|| element.hasTagName(textTag);
}
void SVGUseElement::toClipPath(Path& path)
{
ASSERT(path.isEmpty());
auto* targetClone = this->targetClone();
if (!is<SVGGraphicsElement>(targetClone))
return;
if (!isDirectReference(*targetClone)) {
// Spec: Indirect references are an error (14.3.5)
document().accessSVGExtensions().reportError(ASCIILiteral("Not allowed to use indirect reference in <clip-path>"));
return;
}
downcast<SVGGraphicsElement>(*targetClone).toClipPath(path);
SVGLengthContext lengthContext(this);
// FIXME: Find a way to do this without manual resolution of x/y here. It's potentially incorrect.
path.translate(FloatSize(x().value(lengthContext), y().value(lengthContext)));
path.transform(animatedLocalTransform());
}
RenderElement* SVGUseElement::rendererClipChild() const
{
auto* targetClone = this->targetClone();
if (!targetClone)
return nullptr;
if (!isDirectReference(*targetClone))
return nullptr;
return targetClone->renderer();
}
static inline void disassociateAndRemoveClones(const Vector<Element*>& clones)
{
for (auto& clone : clones) {
for (auto& descendant : descendantsOfType<SVGElement>(*clone))
descendant.setCorrespondingElement(nullptr);
clone->parentNode()->removeChild(*clone);
}
}
static void removeDisallowedElementsFromSubtree(SVGElement& subtree)
{
// Remove disallowed elements after the fact rather than not cloning them in the first place.
// This optimizes for the normal case where none of those elements are present.
// This function is used only on elements in subtrees that are not yet in documents, so
// mutation events are not a factor; there are no event listeners to handle those events.
// Assert that it's not in a document to make sure callers are still using it this way.
ASSERT(!subtree.inDocument());
Vector<Element*> disallowedElements;
auto descendants = descendantsOfType<Element>(subtree);
for (auto it = descendants.begin(), end = descendants.end(); it != end; ) {
if (isDisallowedElement(*it)) {
disallowedElements.append(&*it);
it.traverseNextSkippingChildren();
continue;
}
++it;
}
disassociateAndRemoveClones(disallowedElements);
}
static void removeSymbolElementsFromSubtree(SVGElement& subtree)
{
// Symbol elements inside the subtree should not be cloned for two reasons: 1) They are invisible and
// don't need to be cloned to get correct rendering. 2) expandSymbolElementsInShadowTree will turn them
// into <svg> elements, which is correct for symbol elements directly referenced by use elements,
// but incorrect for ones that just happen to be in a subtree.
Vector<Element*> symbolElements;
for (auto& descendant : descendantsOfType<SVGSymbolElement>(subtree))
symbolElements.append(&descendant);
disassociateAndRemoveClones(symbolElements);
}
static void associateClonesWithOriginals(SVGElement& clone, SVGElement& original)
{
// This assertion checks that we don't call this with the arguments backwards.
// The clone is new and so it's not installed in a parent yet.
ASSERT(!clone.parentNode());
// The loop below works because we are associating these clones immediately, before
// doing transformations like removing disallowed elements or expanding elements.
clone.setCorrespondingElement(&original);
for (auto pair : descendantsOfType<SVGElement>(clone, original))
pair.first.setCorrespondingElement(&pair.second);
}
static void associateReplacementCloneWithOriginal(SVGElement& replacementClone, SVGElement& originalClone)
{
auto* correspondingElement = originalClone.correspondingElement();
ASSERT(correspondingElement);
originalClone.setCorrespondingElement(nullptr);
replacementClone.setCorrespondingElement(correspondingElement);
}
static void associateReplacementClonesWithOriginals(SVGElement& replacementClone, SVGElement& originalClone)
{
// This assertion checks that we don't call this with the arguments backwards.
// The replacement clone is new and so it's not installed in a parent yet.
ASSERT(!replacementClone.parentNode());
// The loop below works because we are associating these clones immediately, before
// doing transformations like removing disallowed elements or expanding elements.
associateReplacementCloneWithOriginal(replacementClone, originalClone);
for (auto pair : descendantsOfType<SVGElement>(replacementClone, originalClone))
associateReplacementCloneWithOriginal(pair.first, pair.second);
}
SVGElement* SVGUseElement::findTarget(String* targetID) const
{
auto* correspondingElement = this->correspondingElement();
auto& original = correspondingElement ? downcast<SVGUseElement>(*correspondingElement) : *this;
auto* targetCandidate = targetElementFromIRIString(original.href(), original.document(), targetID, original.externalDocument());
if (targetID && !targetID->isNull()) {
// If the reference is external, don't return the target ID to the caller.
// The caller would use the target ID to wait for a pending resource on the wrong document.
// If we ever want the change that and let the caller to wait on the external document,
// we should change this function so it returns the appropriate document to go with the ID.
if (isExternalURIReference(original.href(), original.document()))
*targetID = String();
}
if (!is<SVGElement>(targetCandidate))
return nullptr;
auto& target = downcast<SVGElement>(*targetCandidate);
if (!target.inDocument() || isDisallowedElement(target))
return nullptr;
// Reject any target that has already been cloned to create one of the ancestors of this element,
// already in the shadow tree. This is sufficient to prevent cycles.
if (correspondingElement) {
for (auto& ancestor : lineageOfType<SVGElement>(*this)) {
if (ancestor.correspondingElement() == &target)
return nullptr;
}
}
return ⌖
}
void SVGUseElement::cloneTarget(ContainerNode& container, SVGElement& target) const
{
Ref<SVGElement> targetClone = static_cast<SVGElement&>(target.cloneElementWithChildren(document()).get());
associateClonesWithOriginals(targetClone.get(), target);
removeDisallowedElementsFromSubtree(targetClone.get());
removeSymbolElementsFromSubtree(targetClone.get());
transferSizeAttributesToTargetClone(targetClone.get());
container.appendChild(WTFMove(targetClone));
}
static void cloneDataAndChildren(SVGElement& replacementClone, SVGElement& originalClone)
{
// This assertion checks that we don't call this with the arguments backwards.
// The replacement clone is new and so it's not installed in a parent yet.
ASSERT(!replacementClone.parentNode());
replacementClone.cloneDataFromElement(originalClone);
originalClone.cloneChildNodes(replacementClone);
associateReplacementClonesWithOriginals(replacementClone, originalClone);
removeDisallowedElementsFromSubtree(replacementClone);
}
void SVGUseElement::expandUseElementsInShadowTree() const
{
auto descendants = descendantsOfType<SVGUseElement>(*userAgentShadowRoot());
for (auto it = descendants.begin(), end = descendants.end(); it != end; ) {
SVGUseElement& originalClone = *it;
it = end; // Efficiently quiets assertions due to the outstanding iterator.
auto* target = originalClone.findTarget();
// Spec: In the generated content, the 'use' will be replaced by 'g', where all attributes from the
// 'use' element except for x, y, width, height and xlink:href are transferred to the generated 'g' element.
auto replacementClone = SVGGElement::create(document());
cloneDataAndChildren(replacementClone.get(), originalClone);
replacementClone->removeAttribute(SVGNames::xAttr);
replacementClone->removeAttribute(SVGNames::yAttr);
replacementClone->removeAttribute(SVGNames::widthAttr);
replacementClone->removeAttribute(SVGNames::heightAttr);
replacementClone->removeAttribute(XLinkNames::hrefAttr);
if (target)
originalClone.cloneTarget(replacementClone.get(), *target);
originalClone.parentNode()->replaceChild(replacementClone.copyRef(), originalClone);
// Resume iterating, starting just inside the replacement clone.
it = descendants.from(replacementClone.get());
}
}
void SVGUseElement::expandSymbolElementsInShadowTree() const
{
auto descendants = descendantsOfType<SVGSymbolElement>(*userAgentShadowRoot());
for (auto it = descendants.begin(), end = descendants.end(); it != end; ) {
SVGSymbolElement& originalClone = *it;
it = end; // Efficiently quiets assertions due to the outstanding iterator.
// Spec: The referenced 'symbol' and its contents are deep-cloned into the generated tree,
// with the exception that the 'symbol' is replaced by an 'svg'. This generated 'svg' will
// always have explicit values for attributes width and height. If attributes width and/or
// height are provided on the 'use' element, then these attributes will be transferred to
// the generated 'svg'. If attributes width and/or height are not specified, the generated
// 'svg' element will use values of 100% for these attributes.
auto replacementClone = SVGSVGElement::create(document());
cloneDataAndChildren(replacementClone.get(), originalClone);
originalClone.parentNode()->replaceChild(replacementClone.copyRef(), originalClone);
// Resume iterating, starting just inside the replacement clone.
it = descendants.from(replacementClone.get());
}
}
void SVGUseElement::transferEventListenersToShadowTree() const
{
for (auto& descendant : descendantsOfType<SVGElement>(*userAgentShadowRoot())) {
if (EventTargetData* data = descendant.correspondingElement()->eventTargetData())
data->eventListenerMap.copyEventListenersNotCreatedFromMarkupToTarget(&descendant);
}
}
void SVGUseElement::invalidateShadowTree()
{
if (m_shadowTreeNeedsUpdate)
return;
m_shadowTreeNeedsUpdate = true;
setNeedsStyleRecalc(ReconstructRenderTree);
invalidateDependentShadowTrees();
}
void SVGUseElement::invalidateDependentShadowTrees()
{
for (auto* instance : instances()) {
if (auto* element = instance->correspondingUseElement())
element->invalidateShadowTree();
}
}
bool SVGUseElement::selfHasRelativeLengths() const
{
if (x().isRelative() || y().isRelative() || width().isRelative() || height().isRelative())
return true;
auto* targetClone = this->targetClone();
return targetClone && targetClone->hasRelativeLengths();
}
void SVGUseElement::notifyFinished(CachedResource* resource)
{
invalidateShadowTree();
if (resource->errorOccurred())
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
else if (!resource->wasCanceled())
SVGExternalResourcesRequired::dispatchLoadEvent(this);
}
void SVGUseElement::finishParsingChildren()
{
SVGGraphicsElement::finishParsingChildren();
SVGExternalResourcesRequired::finishParsingChildren();
}
void SVGUseElement::updateExternalDocument()
{
URL externalDocumentURL;
if (inDocument() && isExternalURIReference(href(), document())) {
externalDocumentURL = document().completeURL(href());
if (!externalDocumentURL.hasFragmentIdentifier())
externalDocumentURL = URL();
}
if (externalDocumentURL == (m_externalDocument ? m_externalDocument->url() : URL()))
return;
if (m_externalDocument)
m_externalDocument->removeClient(this);
if (externalDocumentURL.isNull())
m_externalDocument = nullptr;
else {
ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
options.setContentSecurityPolicyImposition(isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck);
CachedResourceRequest request { ResourceRequest { externalDocumentURL }, options };
request.setInitiator(this);
m_externalDocument = document().cachedResourceLoader().requestSVGDocument(request);
if (m_externalDocument)
m_externalDocument->addClient(this);
}
invalidateShadowTree();
}
bool SVGUseElement::isValid() const
{
return SVGTests::isValid();
}
bool SVGUseElement::haveLoadedRequiredResources()
{
return SVGExternalResourcesRequired::haveLoadedRequiredResources();
}
void SVGUseElement::setHaveFiredLoadEvent(bool haveFiredLoadEvent)
{
m_haveFiredLoadEvent = haveFiredLoadEvent;
}
bool SVGUseElement::haveFiredLoadEvent() const
{
return m_haveFiredLoadEvent;
}
Timer* SVGUseElement::svgLoadEventTimer()
{
return &m_svgLoadEventTimer;
}
}
|