| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/svg/SVGTreeScopeResources.h" | 5 #include "core/svg/SVGTreeScopeResources.h" |
| 6 | 6 |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/dom/TreeScope.h" | 8 #include "core/dom/TreeScope.h" |
| 9 #include "core/layout/svg/LayoutSVGResourceContainer.h" | 9 #include "core/layout/svg/LayoutSVGResourceContainer.h" |
| 10 #include "core/layout/svg/SVGResourcesCache.h" |
| 10 #include "wtf/text/AtomicString.h" | 11 #include "wtf/text/AtomicString.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 SVGTreeScopeResources::SVGTreeScopeResources(TreeScope* treeScope) { | 15 SVGTreeScopeResources::SVGTreeScopeResources(TreeScope* treeScope) { |
| 15 // Whenever an object of SVGTreeScopeResources is created, to keep the code | 16 // Whenever an object of SVGTreeScopeResources is created, to keep the code |
| 16 // behave as before, | 17 // behave as before, |
| 17 // the document should also have an instance of SVGDocumentExtensions created. | 18 // the document should also have an instance of SVGDocumentExtensions created. |
| 18 // Thus below line is added. | 19 // Thus below line is added. |
| 19 treeScope->document().accessSVGExtensions(); | 20 treeScope->document().accessSVGExtensions(); |
| 20 } | 21 } |
| 21 | 22 |
| 22 SVGTreeScopeResources::~SVGTreeScopeResources() = default; | 23 SVGTreeScopeResources::~SVGTreeScopeResources() = default; |
| 23 | 24 |
| 24 void SVGTreeScopeResources::addResource(const AtomicString& id, | 25 void SVGTreeScopeResources::updateResource( |
| 25 LayoutSVGResourceContainer* resource) { | 26 const AtomicString& id, |
| 27 LayoutSVGResourceContainer* resource) { |
| 26 DCHECK(resource); | 28 DCHECK(resource); |
| 27 if (id.isEmpty()) | 29 if (id.isEmpty()) |
| 28 return; | 30 return; |
| 29 // Replaces resource if already present, to handle potential id changes | 31 // Replaces resource if already present, to handle potential id changes. |
| 30 m_resources.set(id, resource); | 32 m_resources.set(id, resource); |
| 33 |
| 34 SVGPendingElements* pendingElements = m_pendingResources.take(id); |
| 35 if (!pendingElements) |
| 36 return; |
| 37 // Update cached resources of pending clients. |
| 38 for (Element* clientElement : *pendingElements) { |
| 39 DCHECK(clientElement->hasPendingResources()); |
| 40 clearHasPendingResourcesIfPossible(clientElement); |
| 41 |
| 42 LayoutObject* layoutObject = clientElement->layoutObject(); |
| 43 if (!layoutObject) |
| 44 continue; |
| 45 DCHECK(layoutObject->isSVG()); |
| 46 |
| 47 StyleDifference diff; |
| 48 diff.setNeedsFullLayout(); |
| 49 SVGResourcesCache::clientStyleChanged(layoutObject, diff, |
| 50 layoutObject->styleRef()); |
| 51 layoutObject->setNeedsLayoutAndFullPaintInvalidation( |
| 52 LayoutInvalidationReason::SvgResourceInvalidated); |
| 53 } |
| 31 } | 54 } |
| 32 | 55 |
| 33 void SVGTreeScopeResources::removeResource(const AtomicString& id) { | 56 void SVGTreeScopeResources::removeResource(const AtomicString& id) { |
| 34 if (id.isEmpty()) | 57 if (id.isEmpty()) |
| 35 return; | 58 return; |
| 36 m_resources.erase(id); | 59 m_resources.erase(id); |
| 37 } | 60 } |
| 38 | 61 |
| 39 LayoutSVGResourceContainer* SVGTreeScopeResources::resourceById( | 62 LayoutSVGResourceContainer* SVGTreeScopeResources::resourceById( |
| 40 const AtomicString& id) const { | 63 const AtomicString& id) const { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 SVGTreeScopeResources::SVGPendingElements* | 149 SVGTreeScopeResources::SVGPendingElements* |
| 127 SVGTreeScopeResources::removePendingResource(const AtomicString& id) { | 150 SVGTreeScopeResources::removePendingResource(const AtomicString& id) { |
| 128 DCHECK(m_pendingResources.contains(id)); | 151 DCHECK(m_pendingResources.contains(id)); |
| 129 return m_pendingResources.take(id); | 152 return m_pendingResources.take(id); |
| 130 } | 153 } |
| 131 | 154 |
| 132 DEFINE_TRACE(SVGTreeScopeResources) { | 155 DEFINE_TRACE(SVGTreeScopeResources) { |
| 133 visitor->trace(m_pendingResources); | 156 visitor->trace(m_pendingResources); |
| 134 } | 157 } |
| 135 } | 158 } |
| OLD | NEW |