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

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: Recursion-based sendSVG...AncestorChain...; Additional tests. 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
Index: Source/core/svg/SVGElement.cpp
diff --git a/Source/core/svg/SVGElement.cpp b/Source/core/svg/SVGElement.cpp
index a9818bbdced37c909712a016bbab8de3e8e5df05..86bd2bedb6a6c3aeb774046027e06bc7b990eaca 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;
+
+ static_pointer_cast<SVGElement>(parent)->sendSVGLoadEventToSelfAndAncestorChainIfPossible();
pdr. 2014/07/10 03:48:15 Should this be toSVGElement(parent)->sendSVGLoadEv
fs 2014/07/10 08:32:50 Yeah, could be. Changed.
}
void SVGElement::sendSVGLoadEventIfPossibleAsynchronously()

Powered by Google App Engine
This is Rietveld 408576698