Commit 32a58c7e authored by fs's avatar fs Committed by Commit bot

Use IdTargetObserver in SVGFEImageElement

Change SVGFEImageElement to use the observeTarget() helper from
SVGURIReference.
A slight change in behavior for when a load is initiated for a potential
image resource is made. Instead of using a "failed element lookup and a
non-existing id" as the condition, use "failed element lookup and non-
local resource reference".
Also add a new method clearImageResource() and put the tear-down for
the image resource, and change a use of ownerDocument() to just
document().

BUG=661598

Review-Url: https://codereview.chromium.org/2740003003
Cr-Commit-Position: refs/heads/master@{#455765}
parent ce79930d
......@@ -21,9 +21,11 @@
#include "core/svg/SVGFEImageElement.h"
#include "core/SVGNames.h"
#include "core/dom/Document.h"
#include "core/dom/IdTargetObserver.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/svg/SVGPreserveAspectRatio.h"
#include "core/svg/SVGTreeScopeResources.h"
#include "core/svg/graphics/filters/SVGFEImage.h"
#include "platform/graphics/Image.h"
#include "platform/loader/fetch/FetchRequest.h"
......@@ -43,15 +45,13 @@ inline SVGFEImageElement::SVGFEImageElement(Document& document)
DEFINE_NODE_FACTORY(SVGFEImageElement)
SVGFEImageElement::~SVGFEImageElement() {
if (m_cachedImage) {
m_cachedImage->removeObserver(this);
m_cachedImage = nullptr;
}
clearImageResource();
}
DEFINE_TRACE(SVGFEImageElement) {
visitor->trace(m_preserveAspectRatio);
visitor->trace(m_cachedImage);
visitor->trace(m_targetIdObserver);
SVGFilterPrimitiveStandardAttributes::trace(visitor);
SVGURIReference::trace(visitor);
}
......@@ -64,38 +64,36 @@ bool SVGFEImageElement::currentFrameHasSingleSecurityOrigin() const {
}
void SVGFEImageElement::clearResourceReferences() {
if (m_cachedImage) {
m_cachedImage->removeObserver(this);
m_cachedImage = nullptr;
}
clearImageResource();
unobserveTarget(m_targetIdObserver);
removeAllOutgoingReferences();
}
void SVGFEImageElement::fetchImageResource() {
FetchRequest request(
ResourceRequest(ownerDocument()->completeURL(hrefString())), localName());
FetchRequest request(ResourceRequest(document().completeURL(hrefString())),
localName());
m_cachedImage = ImageResourceContent::fetch(request, document().fetcher());
if (m_cachedImage)
m_cachedImage->addObserver(this);
}
void SVGFEImageElement::clearImageResource() {
if (!m_cachedImage)
return;
m_cachedImage->removeObserver(this);
m_cachedImage = nullptr;
}
void SVGFEImageElement::buildPendingResource() {
clearResourceReferences();
if (!isConnected())
return;
AtomicString id;
Element* target = SVGURIReference::targetElementFromIRIString(
hrefString(), treeScope(), &id);
Element* target = observeTarget(m_targetIdObserver, *this);
if (!target) {
if (id.isEmpty()) {
if (!SVGURLReferenceResolver(hrefString(), document()).isLocal())
fetchImageResource();
} else {
treeScope().ensureSVGTreeScopedResources().addPendingResource(id, *this);
DCHECK(hasPendingResources());
}
} else if (target->isSVGElement()) {
// Register us with the target in the dependencies map. Any change of
// hrefElement that leads to relayout/repainting now informs us, so we can
......
......@@ -21,8 +21,6 @@
#ifndef SVGFEImageElement_h
#define SVGFEImageElement_h
#include "core/SVGNames.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/loader/resource/ImageResourceObserver.h"
#include "core/svg/SVGAnimatedPreserveAspectRatio.h"
#include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
......@@ -31,6 +29,8 @@
namespace blink {
class ImageResourceContent;
class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
public SVGURIReference,
public ImageResourceObserver {
......@@ -62,6 +62,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
void clearResourceReferences();
void fetchImageResource();
void clearImageResource();
void buildPendingResource() override;
InsertionNotificationRequest insertedInto(ContainerNode*) override;
......@@ -70,6 +71,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
Member<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
Member<ImageResourceContent> m_cachedImage;
Member<IdTargetObserver> m_targetIdObserver;
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment