| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include "core/layout/svg/LayoutSVGResourceContainer.h" | 20 #include "core/layout/svg/LayoutSVGResourceContainer.h" |
| 21 | 21 |
| 22 #include "core/SVGElementTypeHelpers.h" | 22 #include "core/SVGElementTypeHelpers.h" |
| 23 #include "core/layout/svg/LayoutSVGResourceClipper.h" | 23 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 24 #include "core/layout/svg/LayoutSVGResourceFilter.h" | 24 #include "core/layout/svg/LayoutSVGResourceFilter.h" |
| 25 #include "core/layout/svg/LayoutSVGResourceMasker.h" | 25 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
| 26 #include "core/layout/svg/SVGResources.h" | 26 #include "core/layout/svg/SVGResources.h" |
| 27 #include "core/layout/svg/SVGResourcesCache.h" | 27 #include "core/layout/svg/SVGResourcesCache.h" |
| 28 #include "core/svg/SVGElementProxy.h" | 28 #include "core/paint/PaintLayer.h" |
| 29 #include "core/svg/SVGFilterElement.h" |
| 30 |
| 29 #include "wtf/AutoReset.h" | 31 #include "wtf/AutoReset.h" |
| 30 | 32 |
| 31 namespace blink { | 33 namespace blink { |
| 32 | 34 |
| 33 static inline SVGDocumentExtensions& svgExtensionsFromElement( | 35 static inline SVGDocumentExtensions& svgExtensionsFromElement( |
| 34 Element* element) { | 36 Element* element) { |
| 35 ASSERT(element); | 37 ASSERT(element); |
| 36 return element->document().accessSVGExtensions(); | 38 return element->document().accessSVGExtensions(); |
| 37 } | 39 } |
| 38 | 40 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 if (m_isInLayout) | 56 if (m_isInLayout) |
| 55 return; | 57 return; |
| 56 | 58 |
| 57 AutoReset<bool> inLayoutChange(&m_isInLayout, true); | 59 AutoReset<bool> inLayoutChange(&m_isInLayout, true); |
| 58 | 60 |
| 59 LayoutSVGHiddenContainer::layout(); | 61 LayoutSVGHiddenContainer::layout(); |
| 60 | 62 |
| 61 clearInvalidationMask(); | 63 clearInvalidationMask(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 void LayoutSVGResourceContainer::notifyContentChanged() { | |
| 65 if (SVGElementProxySet* proxySet = elementProxySet()) | |
| 66 proxySet->notifyContentChanged(element()->treeScope()); | |
| 67 } | |
| 68 | |
| 69 void LayoutSVGResourceContainer::willBeDestroyed() { | 66 void LayoutSVGResourceContainer::willBeDestroyed() { |
| 70 // Detach all clients referring to this resource. If the resource itself is | 67 // Detach all clients referring to this resource. If the resource itself is |
| 71 // a client, it will be detached from any such resources by the call to | 68 // a client, it will be detached from any such resources by the call to |
| 72 // LayoutSVGHiddenContainer::willBeDestroyed() below. | 69 // LayoutSVGHiddenContainer::willBeDestroyed() below. |
| 73 detachAllClients(); | 70 detachAllClients(); |
| 74 | 71 |
| 72 for (SVGResourceClient* client : m_resourceClients) |
| 73 client->filterWillBeDestroyed(toSVGFilterElement(element())); |
| 74 m_resourceClients.clear(); |
| 75 |
| 75 LayoutSVGHiddenContainer::willBeDestroyed(); | 76 LayoutSVGHiddenContainer::willBeDestroyed(); |
| 76 if (m_registered) | 77 if (m_registered) |
| 77 svgExtensionsFromElement(element()).removeResource(m_id); | 78 svgExtensionsFromElement(element()).removeResource(m_id); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff, | 81 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff, |
| 81 const ComputedStyle* oldStyle) { | 82 const ComputedStyle* oldStyle) { |
| 82 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle); | 83 LayoutSVGHiddenContainer::styleDidChange(diff, oldStyle); |
| 83 | 84 |
| 84 if (!m_registered) { | 85 if (!m_registered) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 113 // Remove old id, that is guaranteed to be present in cache. | 114 // Remove old id, that is guaranteed to be present in cache. |
| 114 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); | 115 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); |
| 115 extensions.removeResource(m_id); | 116 extensions.removeResource(m_id); |
| 116 m_id = element()->getIdAttribute(); | 117 m_id = element()->getIdAttribute(); |
| 117 | 118 |
| 118 registerResource(); | 119 registerResource(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void LayoutSVGResourceContainer::markAllClientsForInvalidation( | 122 void LayoutSVGResourceContainer::markAllClientsForInvalidation( |
| 122 InvalidationMode mode) { | 123 InvalidationMode mode) { |
| 123 if (m_isInvalidating) | 124 if ((m_clients.isEmpty() && m_resourceClients.isEmpty()) || m_isInvalidating) |
| 124 return; | 125 return; |
| 125 SVGElementProxySet* proxySet = elementProxySet(); | 126 |
| 126 if (m_clients.isEmpty() && (!proxySet || proxySet->isEmpty())) | |
| 127 return; | |
| 128 if (m_invalidationMask & mode) | 127 if (m_invalidationMask & mode) |
| 129 return; | 128 return; |
| 130 | 129 |
| 131 m_invalidationMask |= mode; | 130 m_invalidationMask |= mode; |
| 132 m_isInvalidating = true; | 131 m_isInvalidating = true; |
| 133 bool needsLayout = mode == LayoutAndBoundariesInvalidation; | 132 bool needsLayout = mode == LayoutAndBoundariesInvalidation; |
| 134 bool markForInvalidation = mode != ParentOnlyInvalidation; | 133 bool markForInvalidation = mode != ParentOnlyInvalidation; |
| 135 | 134 |
| 136 // Invalidate clients registered on the this object (via SVGResources). | |
| 137 for (auto* client : m_clients) { | 135 for (auto* client : m_clients) { |
| 138 DCHECK(client->isSVG()); | |
| 139 if (client->isSVGResourceContainer()) { | 136 if (client->isSVGResourceContainer()) { |
| 140 toLayoutSVGResourceContainer(client)->removeAllClientsFromCache( | 137 toLayoutSVGResourceContainer(client)->removeAllClientsFromCache( |
| 141 markForInvalidation); | 138 markForInvalidation); |
| 142 continue; | 139 continue; |
| 143 } | 140 } |
| 144 | 141 |
| 145 if (markForInvalidation) | 142 if (markForInvalidation) |
| 146 markClientForInvalidation(client, mode); | 143 markClientForInvalidation(client, mode); |
| 147 | 144 |
| 148 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation( | 145 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation( |
| 149 client, needsLayout); | 146 client, needsLayout); |
| 150 } | 147 } |
| 151 | 148 |
| 152 // Invalidate clients registered via an SVGElementProxy. | 149 markAllResourceClientsForInvalidation(); |
| 153 notifyContentChanged(); | |
| 154 | 150 |
| 155 m_isInvalidating = false; | 151 m_isInvalidating = false; |
| 156 } | 152 } |
| 157 | 153 |
| 154 void LayoutSVGResourceContainer::markAllResourceClientsForInvalidation() { |
| 155 for (SVGResourceClient* client : m_resourceClients) |
| 156 client->filterNeedsInvalidation(); |
| 157 } |
| 158 |
| 158 void LayoutSVGResourceContainer::markClientForInvalidation( | 159 void LayoutSVGResourceContainer::markClientForInvalidation( |
| 159 LayoutObject* client, | 160 LayoutObject* client, |
| 160 InvalidationMode mode) { | 161 InvalidationMode mode) { |
| 161 ASSERT(client); | 162 ASSERT(client); |
| 162 ASSERT(!m_clients.isEmpty()); | 163 ASSERT(!m_clients.isEmpty()); |
| 163 | 164 |
| 164 switch (mode) { | 165 switch (mode) { |
| 165 case LayoutAndBoundariesInvalidation: | 166 case LayoutAndBoundariesInvalidation: |
| 166 case BoundariesInvalidation: | 167 case BoundariesInvalidation: |
| 167 client->setNeedsBoundariesUpdate(); | 168 client->setNeedsBoundariesUpdate(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 m_clients.add(client); | 186 m_clients.add(client); |
| 186 clearInvalidationMask(); | 187 clearInvalidationMask(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void LayoutSVGResourceContainer::removeClient(LayoutObject* client) { | 190 void LayoutSVGResourceContainer::removeClient(LayoutObject* client) { |
| 190 ASSERT(client); | 191 ASSERT(client); |
| 191 removeClientFromCache(client, false); | 192 removeClientFromCache(client, false); |
| 192 m_clients.remove(client); | 193 m_clients.remove(client); |
| 193 } | 194 } |
| 194 | 195 |
| 196 void LayoutSVGResourceContainer::addResourceClient(SVGResourceClient* client) { |
| 197 ASSERT(client); |
| 198 m_resourceClients.add(client); |
| 199 clearInvalidationMask(); |
| 200 } |
| 201 |
| 202 void LayoutSVGResourceContainer::removeResourceClient( |
| 203 SVGResourceClient* client) { |
| 204 ASSERT(client); |
| 205 m_resourceClients.remove(client); |
| 206 } |
| 207 |
| 195 void LayoutSVGResourceContainer::invalidateCacheAndMarkForLayout( | 208 void LayoutSVGResourceContainer::invalidateCacheAndMarkForLayout( |
| 196 SubtreeLayoutScope* layoutScope) { | 209 SubtreeLayoutScope* layoutScope) { |
| 197 if (selfNeedsLayout()) | 210 if (selfNeedsLayout()) |
| 198 return; | 211 return; |
| 199 | 212 |
| 200 setNeedsLayoutAndFullPaintInvalidation( | 213 setNeedsLayoutAndFullPaintInvalidation( |
| 201 LayoutInvalidationReason::SvgResourceInvalidated, MarkContainerChain, | 214 LayoutInvalidationReason::SvgResourceInvalidated, MarkContainerChain, |
| 202 layoutScope); | 215 layoutScope); |
| 203 | 216 |
| 204 if (everHadLayout()) | 217 if (everHadLayout()) |
| 205 removeAllClientsFromCache(); | 218 removeAllClientsFromCache(); |
| 206 } | 219 } |
| 207 | 220 |
| 208 void LayoutSVGResourceContainer::registerResource() { | 221 void LayoutSVGResourceContainer::registerResource() { |
| 209 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); | 222 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); |
| 210 if (!extensions.hasPendingResource(m_id)) { | 223 if (!extensions.hasPendingResource(m_id)) { |
| 211 extensions.addResource(m_id, this); | 224 extensions.addResource(m_id, this); |
| 212 return; | 225 return; |
| 213 } | 226 } |
| 214 | 227 |
| 215 SVGDocumentExtensions::SVGPendingElements* clients( | 228 SVGDocumentExtensions::SVGPendingElements* clients( |
| 216 extensions.removePendingResource(m_id)); | 229 extensions.removePendingResource(m_id)); |
| 217 | 230 |
| 218 // Cache us with the new id. | 231 // Cache us with the new id. |
| 219 extensions.addResource(m_id, this); | 232 extensions.addResource(m_id, this); |
| 220 | 233 |
| 221 // Update cached resources of pending clients. | 234 // Update cached resources of pending clients. |
| 222 for (const auto& pendingClient : *clients) { | 235 for (const auto& pendingClient : *clients) { |
| 223 DCHECK(pendingClient->hasPendingResources()); | 236 ASSERT(pendingClient->hasPendingResources()); |
| 224 extensions.clearHasPendingResourcesIfPossible(pendingClient); | 237 extensions.clearHasPendingResourcesIfPossible(pendingClient); |
| 225 LayoutObject* layoutObject = pendingClient->layoutObject(); | 238 LayoutObject* layoutObject = pendingClient->layoutObject(); |
| 226 if (!layoutObject) | 239 if (!layoutObject) |
| 227 continue; | 240 continue; |
| 228 DCHECK(layoutObject->isSVG() && (resourceType() != FilterResourceType || | 241 |
| 229 !layoutObject->isSVGRoot())); | 242 const ComputedStyle& style = layoutObject->styleRef(); |
| 243 |
| 244 // If the client has a layer (is a non-SVGElement) we need to signal |
| 245 // invalidation in the same way as is done in |
| 246 // markAllResourceClientsForInvalidation above. |
| 247 if (layoutObject->hasLayer() && resourceType() == FilterResourceType) { |
| 248 if (!style.hasFilter()) |
| 249 continue; |
| 250 toLayoutBoxModelObject(layoutObject) |
| 251 ->layer() |
| 252 ->filterNeedsPaintInvalidation(); |
| 253 if (!layoutObject->isSVGRoot()) |
| 254 continue; |
| 255 // A root SVG element with a filter, however, still needs to run |
| 256 // the full invalidation step below. |
| 257 } |
| 230 | 258 |
| 231 StyleDifference diff; | 259 StyleDifference diff; |
| 232 diff.setNeedsFullLayout(); | 260 diff.setNeedsFullLayout(); |
| 233 SVGResourcesCache::clientStyleChanged(layoutObject, diff, | 261 SVGResourcesCache::clientStyleChanged(layoutObject, diff, style); |
| 234 layoutObject->styleRef()); | |
| 235 layoutObject->setNeedsLayoutAndFullPaintInvalidation( | 262 layoutObject->setNeedsLayoutAndFullPaintInvalidation( |
| 236 LayoutInvalidationReason::SvgResourceInvalidated); | 263 LayoutInvalidationReason::SvgResourceInvalidated); |
| 237 } | 264 } |
| 238 } | 265 } |
| 239 | 266 |
| 240 static inline void removeFromCacheAndInvalidateDependencies( | 267 static inline void removeFromCacheAndInvalidateDependencies( |
| 241 LayoutObject* object, | 268 LayoutObject* object, |
| 242 bool needsLayout) { | 269 bool needsLayout) { |
| 243 ASSERT(object); | 270 ASSERT(object); |
| 244 if (SVGResources* resources = | 271 if (SVGResources* resources = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // This will process the rest of the ancestors. | 331 // This will process the rest of the ancestors. |
| 305 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache(); | 332 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache(); |
| 306 break; | 333 break; |
| 307 } | 334 } |
| 308 | 335 |
| 309 current = current->parent(); | 336 current = current->parent(); |
| 310 } | 337 } |
| 311 } | 338 } |
| 312 | 339 |
| 313 } // namespace blink | 340 } // namespace blink |
| OLD | NEW |