Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGFEImageElement.cpp

Issue 2740003003: Use IdTargetObserver in SVGFEImageElement (Closed)
Patch Set: Forward declare ImageResourceContent Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGFEImageElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> 4 * Copyright (C) 2010 Dirk Schulze <krit@webkit.org>
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 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 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, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "core/svg/SVGFEImageElement.h" 22 #include "core/svg/SVGFEImageElement.h"
23 23
24 #include "core/SVGNames.h"
24 #include "core/dom/Document.h" 25 #include "core/dom/Document.h"
26 #include "core/dom/IdTargetObserver.h"
27 #include "core/loader/resource/ImageResourceContent.h"
25 #include "core/svg/SVGPreserveAspectRatio.h" 28 #include "core/svg/SVGPreserveAspectRatio.h"
26 #include "core/svg/SVGTreeScopeResources.h"
27 #include "core/svg/graphics/filters/SVGFEImage.h" 29 #include "core/svg/graphics/filters/SVGFEImage.h"
28 #include "platform/graphics/Image.h" 30 #include "platform/graphics/Image.h"
29 #include "platform/loader/fetch/FetchRequest.h" 31 #include "platform/loader/fetch/FetchRequest.h"
30 #include "platform/loader/fetch/ResourceFetcher.h" 32 #include "platform/loader/fetch/ResourceFetcher.h"
31 33
32 namespace blink { 34 namespace blink {
33 35
34 inline SVGFEImageElement::SVGFEImageElement(Document& document) 36 inline SVGFEImageElement::SVGFEImageElement(Document& document)
35 : SVGFilterPrimitiveStandardAttributes(SVGNames::feImageTag, document), 37 : SVGFilterPrimitiveStandardAttributes(SVGNames::feImageTag, document),
36 SVGURIReference(this), 38 SVGURIReference(this),
37 m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create( 39 m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(
38 this, 40 this,
39 SVGNames::preserveAspectRatioAttr)) { 41 SVGNames::preserveAspectRatioAttr)) {
40 addToPropertyMap(m_preserveAspectRatio); 42 addToPropertyMap(m_preserveAspectRatio);
41 } 43 }
42 44
43 DEFINE_NODE_FACTORY(SVGFEImageElement) 45 DEFINE_NODE_FACTORY(SVGFEImageElement)
44 46
45 SVGFEImageElement::~SVGFEImageElement() { 47 SVGFEImageElement::~SVGFEImageElement() {
46 if (m_cachedImage) { 48 clearImageResource();
47 m_cachedImage->removeObserver(this);
48 m_cachedImage = nullptr;
49 }
50 } 49 }
51 50
52 DEFINE_TRACE(SVGFEImageElement) { 51 DEFINE_TRACE(SVGFEImageElement) {
53 visitor->trace(m_preserveAspectRatio); 52 visitor->trace(m_preserveAspectRatio);
54 visitor->trace(m_cachedImage); 53 visitor->trace(m_cachedImage);
54 visitor->trace(m_targetIdObserver);
55 SVGFilterPrimitiveStandardAttributes::trace(visitor); 55 SVGFilterPrimitiveStandardAttributes::trace(visitor);
56 SVGURIReference::trace(visitor); 56 SVGURIReference::trace(visitor);
57 } 57 }
58 58
59 bool SVGFEImageElement::currentFrameHasSingleSecurityOrigin() const { 59 bool SVGFEImageElement::currentFrameHasSingleSecurityOrigin() const {
60 if (m_cachedImage && m_cachedImage->getImage()) 60 if (m_cachedImage && m_cachedImage->getImage())
61 return m_cachedImage->getImage()->currentFrameHasSingleSecurityOrigin(); 61 return m_cachedImage->getImage()->currentFrameHasSingleSecurityOrigin();
62 62
63 return true; 63 return true;
64 } 64 }
65 65
66 void SVGFEImageElement::clearResourceReferences() { 66 void SVGFEImageElement::clearResourceReferences() {
67 if (m_cachedImage) { 67 clearImageResource();
68 m_cachedImage->removeObserver(this); 68 unobserveTarget(m_targetIdObserver);
69 m_cachedImage = nullptr;
70 }
71
72 removeAllOutgoingReferences(); 69 removeAllOutgoingReferences();
73 } 70 }
74 71
75 void SVGFEImageElement::fetchImageResource() { 72 void SVGFEImageElement::fetchImageResource() {
76 FetchRequest request( 73 FetchRequest request(ResourceRequest(document().completeURL(hrefString())),
77 ResourceRequest(ownerDocument()->completeURL(hrefString())), localName()); 74 localName());
78 m_cachedImage = ImageResourceContent::fetch(request, document().fetcher()); 75 m_cachedImage = ImageResourceContent::fetch(request, document().fetcher());
79 76
80 if (m_cachedImage) 77 if (m_cachedImage)
81 m_cachedImage->addObserver(this); 78 m_cachedImage->addObserver(this);
82 } 79 }
83 80
81 void SVGFEImageElement::clearImageResource() {
82 if (!m_cachedImage)
83 return;
84 m_cachedImage->removeObserver(this);
85 m_cachedImage = nullptr;
86 }
87
84 void SVGFEImageElement::buildPendingResource() { 88 void SVGFEImageElement::buildPendingResource() {
85 clearResourceReferences(); 89 clearResourceReferences();
86 if (!isConnected()) 90 if (!isConnected())
87 return; 91 return;
88 92
89 AtomicString id; 93 Element* target = observeTarget(m_targetIdObserver, *this);
90 Element* target = SVGURIReference::targetElementFromIRIString(
91 hrefString(), treeScope(), &id);
92 if (!target) { 94 if (!target) {
93 if (id.isEmpty()) { 95 if (!SVGURLReferenceResolver(hrefString(), document()).isLocal())
94 fetchImageResource(); 96 fetchImageResource();
95 } else {
96 treeScope().ensureSVGTreeScopedResources().addPendingResource(id, *this);
97 DCHECK(hasPendingResources());
98 }
99 } else if (target->isSVGElement()) { 97 } else if (target->isSVGElement()) {
100 // Register us with the target in the dependencies map. Any change of 98 // Register us with the target in the dependencies map. Any change of
101 // hrefElement that leads to relayout/repainting now informs us, so we can 99 // hrefElement that leads to relayout/repainting now informs us, so we can
102 // react to it. 100 // react to it.
103 addReferenceTo(toSVGElement(target)); 101 addReferenceTo(toSVGElement(target));
104 } 102 }
105 103
106 invalidate(); 104 invalidate();
107 } 105 }
108 106
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 m_cachedImage->errorOccurred() ? nullptr : m_cachedImage->getImage(); 152 m_cachedImage->errorOccurred() ? nullptr : m_cachedImage->getImage();
155 return FEImage::createWithImage(filter, image, 153 return FEImage::createWithImage(filter, image,
156 m_preserveAspectRatio->currentValue()); 154 m_preserveAspectRatio->currentValue());
157 } 155 }
158 156
159 return FEImage::createWithIRIReference(filter, treeScope(), hrefString(), 157 return FEImage::createWithIRIReference(filter, treeScope(), hrefString(),
160 m_preserveAspectRatio->currentValue()); 158 m_preserveAspectRatio->currentValue());
161 } 159 }
162 160
163 } // namespace blink 161 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGFEImageElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698