OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/svg/SVGResourceClient.h" |
| 6 |
| 7 #include "core/fetch/DocumentResourceReference.h" |
| 8 #include "core/layout/svg/LayoutSVGResourceContainer.h" |
| 9 #include "core/layout/svg/ReferenceFilterBuilder.h" |
| 10 #include "core/svg/SVGFilterElement.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 SVGResourceClient::SVGResourceClient() { |
| 15 ThreadState::current()->registerPreFinalizer(this); |
| 16 } |
| 17 |
| 18 SVGResourceClient::~SVGResourceClient() {} |
| 19 |
| 20 void SVGResourceClient::addFilterReferences(const FilterOperations& operations, |
| 21 const Document& document) { |
| 22 for (size_t i = 0; i < operations.size(); ++i) { |
| 23 FilterOperation* filterOperation = operations.operations().at(i); |
| 24 if (filterOperation->type() != FilterOperation::REFERENCE) |
| 25 continue; |
| 26 ReferenceFilterOperation* referenceFilterOperation = |
| 27 toReferenceFilterOperation(filterOperation); |
| 28 DocumentResourceReference* documentReference = |
| 29 ReferenceFilterBuilder::documentResourceReference( |
| 30 referenceFilterOperation); |
| 31 DocumentResource* cachedSVGDocument = |
| 32 documentReference ? documentReference->document() : 0; |
| 33 |
| 34 if (cachedSVGDocument) { |
| 35 cachedSVGDocument->addClient(this); |
| 36 m_externalFilterReferences.append(cachedSVGDocument); |
| 37 } else { |
| 38 Element* element = |
| 39 document.getElementById(referenceFilterOperation->fragment()); |
| 40 if (!isSVGFilterElement(element)) |
| 41 continue; |
| 42 SVGFilterElement* filter = toSVGFilterElement(element); |
| 43 if (filter->layoutObject()) |
| 44 toLayoutSVGResourceContainer(filter->layoutObject()) |
| 45 ->addResourceClient(this); |
| 46 else |
| 47 filter->addClient(this); |
| 48 m_internalFilterReferences.add(filter); |
| 49 } |
| 50 } |
| 51 } |
| 52 |
| 53 void SVGResourceClient::clearFilterReferences() { |
| 54 for (SVGFilterElement* filter : m_internalFilterReferences) { |
| 55 if (filter->layoutObject()) |
| 56 toLayoutSVGResourceContainer(filter->layoutObject()) |
| 57 ->removeResourceClient(this); |
| 58 else |
| 59 filter->removeClient(this); |
| 60 } |
| 61 m_internalFilterReferences.clear(); |
| 62 |
| 63 for (DocumentResource* documentResource : m_externalFilterReferences) |
| 64 documentResource->removeClient(this); |
| 65 m_externalFilterReferences.clear(); |
| 66 } |
| 67 |
| 68 void SVGResourceClient::filterWillBeDestroyed(SVGFilterElement* filter) { |
| 69 m_internalFilterReferences.remove(filter); |
| 70 // TODO(Oilpan): Currently filterNeedsInvalidation() is not called when |
| 71 // the filter is removed from m_internalFilterReferences by weak processing. |
| 72 // It needs to be called. |
| 73 filterNeedsInvalidation(); |
| 74 } |
| 75 |
| 76 void SVGResourceClient::notifyFinished(Resource*) { |
| 77 filterNeedsInvalidation(); |
| 78 } |
| 79 |
| 80 DEFINE_TRACE(SVGResourceClient) { |
| 81 visitor->trace(m_internalFilterReferences); |
| 82 visitor->trace(m_externalFilterReferences); |
| 83 DocumentResourceClient::trace(visitor); |
| 84 } |
| 85 |
| 86 } // namespace blink |
OLD | NEW |