12017-12-12 Ryosuke Niwa <rniwa@webkit.org>
2
3 Update the SVG use element's shadow trees explicitly before the style recall
4 https://bugs.webkit.org/show_bug.cgi?id=180729
5 <rdar://problem/36009806>
6
7 Reviewed by NOBODY (OOPS!).
8
9 Update the SVG use element's shadow trees before start resolving styles. Document now has a hash set of all
10 connected SVG use elements with invalidated shadow trees. SVGUseElement adds itself to this set when its
11 shadow tree gets invalidated, or it gets newly connected to a document with the invalidated shadow tree.
12 SVGUseElement removes itself from this set when it updates its shadow tree or it gets disconnected from
13 a document with the invalidated shadow tree.
14
15 No new tests. Covered by existing tests.
16
17 * dom/Document.cpp:
18 (WebCore::Document::~Document): Assert that m_svgUseElements has been cleared.
19 (WebCore::Document::resolveStyle): Update the shadow trees of SVG use elements with invalidated shadow trees.
20 (WebCore::Document::addSVGUseElement): Added.
21 (WebCore::Document::removeSVGUseElement): Added.
22 * dom/Document.h:
23 (WebCore::Document::svgUseElements const): Added.
24 * dom/Element.cpp:
25 (WebCore::Element::cloneElementWithChildren): Removed EventAllowedScope since the SVG use element's shadow
26 tree is no longer updated when there is a NoEventDispatchAssertion in the stack.
27 (WebCore::Element::cloneElementWithoutChildren): Ditto.
28 * svg/SVGUseElement.cpp:
29 (WebCore::SVGUseElement::insertedIntoAncestor): Add the element to the document's hash set if this use element's
30 shadow tree needs to be updated (m_shadowTreeNeedsUpdate is set), and it got newly connected.
31 (WebCore::SVGUseElement::removedFromAncestor): Ditto for removal. We have to check m_shadowTreeNeedsUpdate before
32 calling SVGGraphicsElement::removedFromAncestor or updateExternalDocument since either function can invoke
33 m_shadowTreeNeedsUpdate to true.
34 (WebCore::SVGUseElement::willRecalcStyle): Removed the call to updateShadowTree.
35 (WebCore::SVGUseElement::updateShadowTree): Remove this element from the document's hah set. We can't clear all
36 the entries in the map at once in Document::resolveStyle because updating the shadow trees of a SVG use element
37 can result in a sync IPC in ImageLoader::updateFromElement, which end up executing arbitrary author scripts.
38 (WebCore::SVGUseElement::cloneTarget const): Removed EventAllowedScope since the SVG use element's shadow tree
39 is no longer updated when there is a NoEventDispatchAssertion in the stack.
40 (WebCore::SVGUseElement::expandUseElementsInShadowTree const): Ditto.
41 (WebCore::SVGUseElement::expandSymbolElementsInShadowTree const): Ditto.
42 (WebCore::SVGUseElement::invalidateShadowTree): Add the element to the document's hash set if it's connected.
43 * svg/SVGUseElement.h:
44