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

Unified Diff: Source/core/svg/SVGElement.cpp

Issue 375923002: Don't dispatch '(SVG)load' to ancestors of <svg:image> after doc. 'load' (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Drop assert_true; use toSVGElement. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGElement.h ('k') | Source/core/svg/SVGImageLoader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGElement.cpp
diff --git a/Source/core/svg/SVGElement.cpp b/Source/core/svg/SVGElement.cpp
index a9818bbdced37c909712a016bbab8de3e8e5df05..f9373f5df9189fc56b60436de94c740ca90e6bdd 100644
--- a/Source/core/svg/SVGElement.cpp
+++ b/Source/core/svg/SVGElement.cpp
@@ -836,32 +836,35 @@ static bool hasLoadListener(Element* element)
return false;
}
-void SVGElement::sendSVGLoadEventIfPossible(bool sendParentLoadEvents)
-{
- RefPtrWillBeRawPtr<SVGElement> currentTarget = this;
- while (currentTarget && currentTarget->haveLoadedRequiredResources()) {
- RefPtrWillBeRawPtr<Element> parent = nullptr;
- if (sendParentLoadEvents)
- parent = currentTarget->parentOrShadowHostElement(); // save the next parent to dispatch too incase dispatching the event changes the tree
- if (hasLoadListener(currentTarget.get())
- && (currentTarget->isStructurallyExternal() || isSVGSVGElement(*currentTarget)))
- currentTarget->dispatchEvent(Event::create(EventTypeNames::load));
- currentTarget = (parent && parent->isSVGElement()) ? static_pointer_cast<SVGElement>(parent) : nullptr;
- SVGElement* element = currentTarget.get();
- if (!element || !element->isOutermostSVGSVGElement())
- continue;
-
- // Consider <svg onload="foo()"><image xlink:href="foo.png" externalResourcesRequired="true"/></svg>.
- // If foo.png is not yet loaded, the first SVGLoad event will go to the <svg> element, sent through
- // Document::implicitClose(). Then the SVGLoad event will fire for <image>, once its loaded.
- ASSERT(sendParentLoadEvents);
-
- // If the load event was not sent yet by Document::implicitClose(), but the <image> from the example
- // above, just appeared, don't send the SVGLoad event to the outermost <svg>, but wait for the document
- // to be "ready to render", first.
- if (!document().loadEventFinished())
- break;
- }
+bool SVGElement::sendSVGLoadEventIfPossible()
+{
+ if (!haveLoadedRequiredResources())
+ return false;
+ if ((isStructurallyExternal() || isSVGSVGElement(*this)) && hasLoadListener(this))
+ dispatchEvent(Event::create(EventTypeNames::load));
+ return true;
+}
+
+void SVGElement::sendSVGLoadEventToSelfAndAncestorChainIfPossible()
+{
+ // Let Document::implicitClose() dispatch the 'load' to the outermost SVG root.
+ if (isOutermostSVGSVGElement())
+ return;
+
+ // Save the next parent to dispatch to in case dispatching the event mutates the tree.
+ RefPtrWillBeRawPtr<Element> parent = parentOrShadowHostElement();
+ if (!sendSVGLoadEventIfPossible())
+ return;
+
+ // If document/window 'load' has been sent already, then only deliver to
+ // the element in question.
+ if (document().loadEventFinished())
+ return;
+
+ if (!parent || !parent->isSVGElement())
+ return;
+
+ toSVGElement(parent)->sendSVGLoadEventToSelfAndAncestorChainIfPossible();
}
void SVGElement::sendSVGLoadEventIfPossibleAsynchronously()
« no previous file with comments | « Source/core/svg/SVGElement.h ('k') | Source/core/svg/SVGImageLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698