Bug 1542530 - Selection.toString() works correctly when text is selected together with a set of div+svg elements, r=mats
☠☠ backed out by 18f136a88731 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 11 Apr 2019 14:13:24 +0000
changeset 469033 78ed7f9d65666d570e1a87195c1ab5434d588fb8
parent 469032 70ed6fa7f92135943a370c39dffb5c0895350b01
child 469034 5954214372b7ccf56b47d79eb0d6fdb3384455fe
push id82934
push useramarchesini@mozilla.com
push dateThu, 11 Apr 2019 15:43:14 +0000
treeherderautoland@78ed7f9d6566 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1542530
milestone68.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 1542530 - Selection.toString() works correctly when text is selected together with a set of div+svg elements, r=mats Differential Revision: https://phabricator.services.mozilla.com/D27064
dom/base/nsDocumentEncoder.cpp
dom/svg/test/test_text_selection.html
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -618,17 +618,17 @@ nsresult nsDocumentEncoder::SerializeRan
         // intermediate points on the list use the endOffset of the
         // location of the ancestor, rather than just past it.  So we need
         // to add one here in order to include it in the children we serialize.
         if (aNode != aRange->GetEndContainer()) {
           endOffset++;
         }
       }
 
-      if (endOffset) {
+      if (startOffset < endOffset) {
         // serialize the children of this node that are in the range
         nsIContent* childAsNode = content->GetFirstChild();
         int32_t j = 0;
 
         for (; j < startOffset && childAsNode; ++j) {
           childAsNode = childAsNode->GetNextSibling();
         }
 
--- a/dom/svg/test/test_text_selection.html
+++ b/dom/svg/test/test_text_selection.html
@@ -12,17 +12,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=655877">Mozilla Bug 655877</a>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 
 <iframe src="text-helper-selection.svg" width="400" height="300"></iframe>
 
-<pre id="test">
+<br />
+<div id="svg" style="padding-right: 30px;">
+  <div><svg width="36" height="36" viewBox="0 0 36 36"><path d="M6 14l8 8L30 6v8L14 30l-8-8z"></path></svg></div>
+</div>
+This is part of the test
+
 <script class="testbody" type="application/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var svg, doc, win, dragstart, dragend;
 
 function drag(fromX, fromY, toX, toY, show) {
   synthesizeMouse(doc.documentElement, fromX, fromY, { type: "mousemove" }, win);
   synthesizeMouse(doc.documentElement, fromX, fromY, { type: "mousedown" }, win);
@@ -115,25 +120,33 @@ function testSelection() {
   selection_is("בגa", "selecting bidi text");
   deselect();
 
   // Select transformed text.
   drag(101, 250, 99 + text[4].getSubStringLength(0, 6) / 2, 250);
   selection_is("squash");
   deselect();
 
+  let svgImg = document.getElementById("svg");
+  synthesizeMouse(svgImg, 10, 10, { type: "mousemove" }, window);
+  synthesizeMouse(svgImg, 10, 10, { type: "mousedown" }, window);
+
+  let rect = svgImg.getBoundingClientRect();
+  synthesizeMouseAtPoint(rect.left + rect.width + 100, rect.top + rect.height + 10, { type: "mousemove" }, window);
+  synthesizeMouseAtPoint(rect.left + rect.width + 100, rect.top + rect.height + 10, { type: "mouseup" }, window);
+  is(window.getSelection().toString(), "\nThis is part of the test ", "The selection is correct");
+
   SimpleTest.finish();
 }
 
 function runTest() {
   SimpleTest.executeSoon(testSelection);
 }
 
 if (/Android/.test(navigator.userAgent)) {
   ok(true, "No need to test text selection with the mouse on Android.");
   SimpleTest.finish();
 } else {
   window.addEventListener("load", runTest);
 }
 </script>
-</pre>
 </body>
 </html>