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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGElement.h ('k') | Source/core/svg/SVGImageLoader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org> 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org>
3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2008 Apple Inc. All rights reserved.
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 const EventListenerVector& entry = element->getEventListeners(EventTypeN ames::load); 829 const EventListenerVector& entry = element->getEventListeners(EventTypeN ames::load);
830 for (size_t i = 0; i < entry.size(); ++i) { 830 for (size_t i = 0; i < entry.size(); ++i) {
831 if (entry[i].useCapture) 831 if (entry[i].useCapture)
832 return true; 832 return true;
833 } 833 }
834 } 834 }
835 835
836 return false; 836 return false;
837 } 837 }
838 838
839 void SVGElement::sendSVGLoadEventIfPossible(bool sendParentLoadEvents) 839 bool SVGElement::sendSVGLoadEventIfPossible()
840 { 840 {
841 RefPtrWillBeRawPtr<SVGElement> currentTarget = this; 841 if (!haveLoadedRequiredResources())
842 while (currentTarget && currentTarget->haveLoadedRequiredResources()) { 842 return false;
843 RefPtrWillBeRawPtr<Element> parent = nullptr; 843 if ((isStructurallyExternal() || isSVGSVGElement(*this)) && hasLoadListener( this))
844 if (sendParentLoadEvents) 844 dispatchEvent(Event::create(EventTypeNames::load));
845 parent = currentTarget->parentOrShadowHostElement(); // save the nex t parent to dispatch too incase dispatching the event changes the tree 845 return true;
846 if (hasLoadListener(currentTarget.get()) 846 }
847 && (currentTarget->isStructurallyExternal() || isSVGSVGElement(*curr entTarget)))
848 currentTarget->dispatchEvent(Event::create(EventTypeNames::load));
849 currentTarget = (parent && parent->isSVGElement()) ? static_pointer_cast <SVGElement>(parent) : nullptr;
850 SVGElement* element = currentTarget.get();
851 if (!element || !element->isOutermostSVGSVGElement())
852 continue;
853 847
854 // Consider <svg onload="foo()"><image xlink:href="foo.png" externalReso urcesRequired="true"/></svg>. 848 void SVGElement::sendSVGLoadEventToSelfAndAncestorChainIfPossible()
855 // If foo.png is not yet loaded, the first SVGLoad event will go to the <svg> element, sent through 849 {
856 // Document::implicitClose(). Then the SVGLoad event will fire for <imag e>, once its loaded. 850 // Let Document::implicitClose() dispatch the 'load' to the outermost SVG ro ot.
857 ASSERT(sendParentLoadEvents); 851 if (isOutermostSVGSVGElement())
852 return;
858 853
859 // If the load event was not sent yet by Document::implicitClose(), but the <image> from the example 854 // Save the next parent to dispatch to in case dispatching the event mutates the tree.
860 // above, just appeared, don't send the SVGLoad event to the outermost < svg>, but wait for the document 855 RefPtrWillBeRawPtr<Element> parent = parentOrShadowHostElement();
861 // to be "ready to render", first. 856 if (!sendSVGLoadEventIfPossible())
862 if (!document().loadEventFinished()) 857 return;
863 break; 858
864 } 859 // If document/window 'load' has been sent already, then only deliver to
860 // the element in question.
861 if (document().loadEventFinished())
862 return;
863
864 if (!parent || !parent->isSVGElement())
865 return;
866
867 toSVGElement(parent)->sendSVGLoadEventToSelfAndAncestorChainIfPossible();
865 } 868 }
866 869
867 void SVGElement::sendSVGLoadEventIfPossibleAsynchronously() 870 void SVGElement::sendSVGLoadEventIfPossibleAsynchronously()
868 { 871 {
869 svgLoadEventTimer()->startOneShot(0, FROM_HERE); 872 svgLoadEventTimer()->startOneShot(0, FROM_HERE);
870 } 873 }
871 874
872 void SVGElement::svgLoadEventTimerFired(Timer<SVGElement>*) 875 void SVGElement::svgLoadEventTimerFired(Timer<SVGElement>*)
873 { 876 {
874 sendSVGLoadEventIfPossible(); 877 sendSVGLoadEventIfPossible();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 Element::trace(visitor); 1214 Element::trace(visitor);
1212 } 1215 }
1213 1216
1214 const AtomicString& SVGElement::eventParameterName() 1217 const AtomicString& SVGElement::eventParameterName()
1215 { 1218 {
1216 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt", AtomicString::Con structFromLiteral)); 1219 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt", AtomicString::Con structFromLiteral));
1217 return evtString; 1220 return evtString;
1218 } 1221 }
1219 1222
1220 } 1223 }
OLDNEW
« 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