Bug 1609663 - Reflow non-display SVG text that has just been inserted. r=longsonr
authorCameron McCormack <cam@mcc.id.au>
Wed, 13 May 2020 08:00:23 +0000
changeset 529728 3d8f0e488dbfdc39d0481939dabc80e300d93619
parent 529727 5633cc2aaa9b69e27f8c89d742c03ccc453b2366
child 529729 31a25d4e68f9a9b84372378f29720f70d2eb01dd
push id37414
push usernbeleuzu@mozilla.com
push dateThu, 14 May 2020 02:40:10 +0000
treeherdermozilla-central@045d696faa87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1609663
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1609663 - Reflow non-display SVG text that has just been inserted. r=longsonr Differential Revision: https://phabricator.services.mozilla.com/D75034
layout/svg/SVGTextFrame.cpp
layout/svg/crashtests/1609663.html
layout/svg/crashtests/crashtests.list
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -2778,16 +2778,22 @@ void SVGTextFrame::Init(nsIContent* aCon
   NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::text),
                "Content is not an SVG text");
 
   nsSVGDisplayContainerFrame::Init(aContent, aParent, aPrevInFlow);
   AddStateBits((aParent->GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) |
                NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_SVG_TEXT);
 
   mMutationObserver = new MutationObserver(this);
+
+  if (mState & NS_FRAME_IS_NONDISPLAY) {
+    // We're inserting a new <text> element into a non-display context.
+    // Ensure that we get reflowed.
+    ScheduleReflowSVGNonDisplayText(IntrinsicDirty::StyleChange);
+  }
 }
 
 void SVGTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
                                     const nsDisplayListSet& aLists) {
   if (NS_SUBTREE_DIRTY(this)) {
     // We can sometimes be asked to paint before reflow happens and we
     // have updated mPositions, etc.  In this case, we just avoid
     // painting.
new file mode 100644
--- /dev/null
+++ b/layout/svg/crashtests/1609663.html
@@ -0,0 +1,34 @@
+<html>
+<head>
+</head>
+<body>
+<div id="main">
+	<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="mySvg" width="400" height="800">
+		<defs>
+			<pattern id="pattern1" x="30" y="10" width="30" height="30" patternUnits="userSpaceOnUse" >
+					<text id="idText1" x="15" y="15" font-size="20">1</text>
+			</pattern>
+		</defs>
+		<rect id="idRect1" fill="url(#pattern1)" width="300" height="200"/> 
+	</svg>
+</div>
+<script>
+document.body.offsetHeight;
+
+var pattern = document.getElementById('pattern1');
+var text = document.getElementById('idText1');
+pattern.removeChild(text);
+
+var svgNS = "http://www.w3.org/2000/svg";
+var newText = document.createElementNS(svgNS,"text");
+newText.setAttributeNS(null,"id",'idText1');     
+newText.setAttributeNS(null,"x",15);     
+newText.setAttributeNS(null,"y",15); 
+newText.setAttributeNS(null,"font-size","20");
+
+var textNode = document.createTextNode('x');
+newText.appendChild(textNode);
+pattern.appendChild(newText);
+</script>
+</body>
+</html>
--- a/layout/svg/crashtests/crashtests.list
+++ b/layout/svg/crashtests/crashtests.list
@@ -228,8 +228,9 @@ load 1539318-1.svg
 load 1548985-1.html
 load 1548985-2.svg
 load 1555851.html
 load invalidation-of-opacity-0.html
 load 1563779.html
 load 1600855.html
 load 1601824.html
 load 1605223-1.html
+load 1609663.html