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
|
/*
* Copyright (C) 2006 Apple Inc. All rights reserved.
* Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2007 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.
*/
#include "config.h"
#include "SVGDocumentExtensions.h"
#include "Document.h"
#include "EventListener.h"
#include "FrameDestructionObserverInlines.h"
#include "FrameLoader.h"
#include "LocalDOMWindow.h"
#include "LocalFrame.h"
#include "Page.h"
#include "SMILTimeContainer.h"
#include "SVGElement.h"
#include "SVGFontFaceElement.h"
#include "SVGResourcesCache.h"
#include "SVGSMILElement.h"
#include "SVGSVGElement.h"
#include "SVGUseElement.h"
#include "ScriptableDocumentParser.h"
#include "ShadowRoot.h"
#include <wtf/TZoneMallocInlines.h>
#include <wtf/text/AtomString.h>
#include <wtf/text/MakeString.h>
namespace WebCore {
WTF_MAKE_TZONE_ALLOCATED_IMPL(SVGDocumentExtensions);
static bool animationsPausedForDocument(Document& document)
{
return !document.page() || !document.page()->isVisible() || !document.page()->imageAnimationEnabled();
}
SVGDocumentExtensions::SVGDocumentExtensions(Document& document)
: m_document(document)
, m_resourcesCache(makeUnique<SVGResourcesCache>())
, m_areAnimationsPaused(animationsPausedForDocument(document))
{
}
SVGDocumentExtensions::~SVGDocumentExtensions() = default;
void SVGDocumentExtensions::addTimeContainer(SVGSVGElement& element)
{
m_timeContainers.add(element);
if (m_areAnimationsPaused)
element.pauseAnimations();
}
void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement& element)
{
m_timeContainers.remove(element);
}
Vector<Ref<SVGSVGElement>> SVGDocumentExtensions::allSVGSVGElements() const
{
return copyToVectorOf<Ref<SVGSVGElement>>(m_timeContainers);
}
void SVGDocumentExtensions::startAnimations()
{
// FIXME: Eventually every "Time Container" will need a way to latch on to some global timer
// starting animations for a document will do this "latching"
// FIXME: We hold a ref pointers to prevent a shadow tree from getting removed out from underneath us.
// In the future we should refactor the use-element to avoid this. See https://webkit.org/b/53704
auto timeContainers = copyToVectorOf<Ref<SVGSVGElement>>(m_timeContainers);
for (auto& element : timeContainers)
element->protectedTimeContainer()->begin();
}
void SVGDocumentExtensions::pauseAnimations()
{
for (Ref container : m_timeContainers)
container->pauseAnimations();
m_areAnimationsPaused = true;
}
Ref<Document> SVGDocumentExtensions::protectedDocument() const
{
return m_document.get();
}
void SVGDocumentExtensions::unpauseAnimations()
{
// If animations are paused at the document level, don't allow `this` to be unpaused.
if (animationsPausedForDocument(protectedDocument()))
return;
for (Ref container : m_timeContainers)
container->unpauseAnimations();
m_areAnimationsPaused = false;
}
void SVGDocumentExtensions::dispatchLoadEventToOutermostSVGElements()
{
auto timeContainers = copyToVectorOf<Ref<SVGSVGElement>>(m_timeContainers);
for (auto& container : timeContainers) {
if (!container->isOutermostSVGSVGElement())
continue;
container->sendLoadEventIfPossible();
}
}
static void reportMessage(Document& document, MessageLevel level, const String& message)
{
if (document.frame())
document.addConsoleMessage(MessageSource::Rendering, level, message);
}
void SVGDocumentExtensions::reportWarning(const String& message)
{
reportMessage(protectedDocument(), MessageLevel::Warning, makeString("Warning: "_s, message));
}
void SVGDocumentExtensions::reportError(const String& message)
{
reportMessage(protectedDocument(), MessageLevel::Error, makeString("Error: "_s, message));
}
void SVGDocumentExtensions::addElementToRebuild(SVGElement& element)
{
m_rebuildElements.append(element);
}
void SVGDocumentExtensions::removeElementToRebuild(SVGElement& element)
{
m_rebuildElements.removeFirstMatching([&](auto& item) { return item.ptr() == &element; });
}
void SVGDocumentExtensions::rebuildElements()
{
auto shadowRebuildElements = std::exchange(m_rebuildElements, { });
for (auto& element : shadowRebuildElements)
element->svgAttributeChanged(SVGNames::hrefAttr);
}
void SVGDocumentExtensions::clearTargetDependencies(SVGElement& referencedElement)
{
for (Ref element : referencedElement.referencingElements()) {
m_rebuildElements.append(element.get());
element->callClearTarget();
}
}
void SVGDocumentExtensions::rebuildAllElementReferencesForTarget(SVGElement& referencedElement)
{
for (Ref element : referencedElement.referencingElements())
element->svgAttributeChanged(SVGNames::hrefAttr);
}
void SVGDocumentExtensions::registerSVGFontFaceElement(SVGFontFaceElement& element)
{
m_svgFontFaceElements.add(element);
}
void SVGDocumentExtensions::unregisterSVGFontFaceElement(SVGFontFaceElement& element)
{
ASSERT(m_svgFontFaceElements.contains(element));
m_svgFontFaceElements.remove(element);
}
}
|