Bug 1504911 - part 5: Make HTMLEditor::InsertTableCellsWithTransaction() create AutoPlaceholderBatch and AutoTopLevelEditSubActionNotifier r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 21 Nov 2018 09:30:40 +0000
changeset 503895 824bcd08c85e70d98109b04715b26f139e099ce8
parent 503894 09fd7845a50bad9fa7a579a9e7088828d8155a20
child 503896 f5db5f1b269099e7900bebb64470aaf0e2213b58
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1504911
milestone65.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 1504911 - part 5: Make HTMLEditor::InsertTableCellsWithTransaction() create AutoPlaceholderBatch and AutoTopLevelEditSubActionNotifier r=m_kato Currently, calling nsITableEditor.insertTableCell() does not cause dispatching "input" event since it does not create AutoPlaceholderBatch. Additionally, different from InsertTableRowsWithTransaction() and InsertTableColumnsWithTransaction(), it does not create AutoTopLevelEditSubActionNotifier. Because of those APIs should work similarly, we should make it creates both auto class instances. Differential Revision: https://phabricator.services.mozilla.com/D12248
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/tests/test_nsITableEditor_insertTableCell.html
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -224,16 +224,22 @@ HTMLEditor::InsertTableCellsWithTransact
     case InsertPosition::eAfterSelectedCell:
       MOZ_ASSERT(!cellDataAtSelection.IsSpannedFromOtherRowOrColumn());
       newCellIndex = cellDataAtSelection.NextColumnIndex();
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid InsertPosition");
   }
 
+  AutoPlaceholderBatch treateAsOneTransaction(*this);
+  // Prevent auto insertion of BR in new cell until we're done
+  AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
+                                      *this, EditSubAction::eInsertNode,
+                                      nsIEditor::eNext);
+
   // We control selection resetting after the insert.
   AutoSelectionSetterAfterTableEdit setCaret(*this, table,
                                              cellDataAtSelection.mCurrent.mRow,
                                              newCellIndex, ePreviousColumn,
                                              false);
   // So, suppress Rules System selection munging.
   AutoTransactionsConserveSelection dontChangeSelection(*this);
 
--- a/editor/libeditor/tests/test_nsITableEditor_insertTableCell.html
+++ b/editor/libeditor/tests/test_nsITableEditor_insertTableCell.html
@@ -82,18 +82,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, false);
   is(editor.innerHTML, "<table><tbody>" +
                          "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
                          '<tr><td valign="top"><br></td><td id="select">cell2-1</td><td>cell2-2</td></tr>' +
                          "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in middle row (before)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in middle row (before)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in middle row (before)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
                        '<tr><td id="select">cell2-1</td><td>cell2-2</td></tr>' +
@@ -106,18 +106,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, true);
   is(editor.innerHTML, "<table><tbody>" +
                          "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
                          '<tr><td id="select">cell2-1</td><td valign="top"><br></td><td>cell2-2</td></tr>' +
                          "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in middle row (after)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in middle row (after)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in middle row (after)");
   }
 
   // with rowspan.
 
   // Odd case. This puts the cell containing selection moves right of row-spanning cell.
   selection.removeAllRanges();
@@ -133,18 +133,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, false);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td rowspan="2">cell1-2</td></tr>' +
                          '<tr><td valign="top"><br></td><td id="select">cell2-1</td></tr>' +
                          "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection and moves the cell to right of the row-spanning cell element");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (before)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (before)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in middle row and it has row-spanned cell (before)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        '<tr><td>cell1-1</td><td rowspan="3">cell1-2</td></tr>' +
                        '<tr><td id="select">cell2-1</td></tr>' +
@@ -157,18 +157,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, true);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td rowspan="3">cell1-2</td></tr>' +
                          '<tr><td id="select">cell2-1</td><td valign="top"><br></td></tr>' +
                          "<tr><td>cell3-1</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection and moves the cell to right of the row-spanning cell element");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (after)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (after)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in middle row and it has row-spanned cell (after)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        '<tr><td>cell1-1</td><td id="select" rowspan="2">cell1-2</td></tr>' +
                        "<tr><td>cell2-1</td></tr>" +
@@ -181,18 +181,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 1);
   getTableEditor().insertTableCell(2, false);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td valign="top"><br></td><td valign="top"><br></td><td id="select" rowspan="2">cell1-2</td></tr>' +
                          "<tr><td>cell2-1</td></tr>" +
                          "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(2, false) should insert 2 cells before the row-spanning cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in row-spanning (before)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in row-spanning (before)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in row-spanning (before)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        '<tr><td>cell1-1</td><td id="select" rowspan="2">cell1-2</td></tr>' +
                        "<tr><td>cell2-1</td></tr>" +
@@ -205,18 +205,18 @@ SimpleTest.waitForFocus(function() {
                              document.getElementById("select").firstChild, 1);
   getTableEditor().insertTableCell(2, true);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td id="select" rowspan="2">cell1-2</td><td valign="top"><br></td><td valign="top"><br></td></tr>' +
                          "<tr><td>cell2-1</td></tr>" +
                          "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(2, false) should insert 2 cells after the row-spanning cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell in row-spanning (after)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell in row-spanning (after)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell in row-spanning (after)");
   }
 
   // with colspan
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
@@ -229,18 +229,18 @@ SimpleTest.waitForFocus(function() {
   selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, false);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td valign="top"><br></td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
                          '<tr><td colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection but do not modify col-spanning cell");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (before)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (before)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell whose next row cell is col-spanned (before)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        '<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
                        '<tr><td colspan="3">cell2-1</td></tr>' +
@@ -251,18 +251,18 @@ SimpleTest.waitForFocus(function() {
   selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
                              document.getElementById("select").firstChild, 0);
   getTableEditor().insertTableCell(1, true);
   is(editor.innerHTML, "<table><tbody>" +
                          '<tr><td>cell1-1</td><td id="select">cell1-2</td><td valign="top"><br></td><td>cell1-3</td></tr>' +
                          '<tr><td colspan="3">cell2-1</td></tr>' +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection but do not modify col-spanning cell");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (after)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (after)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell whose next row cell is col-spanned (after)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
                        '<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
@@ -273,18 +273,18 @@ SimpleTest.waitForFocus(function() {
   selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
                              document.getElementById("select").firstChild, 1);
   getTableEditor().insertTableCell(2, false);
   is(editor.innerHTML, "<table><tbody>" +
                          "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
                          '<tr><td valign="top"><br></td><td valign="top"><br></td><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(2, false) should insert 2 cells before the col-spanning cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell which is col-spanning (before)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell which is col-spanning (before)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell which is col-spanning (before)");
   }
 
   selection.removeAllRanges();
   editor.innerHTML = "<table>" +
                        "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
                        '<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
@@ -295,18 +295,18 @@ SimpleTest.waitForFocus(function() {
   selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
                              document.getElementById("select").firstChild, 1);
   getTableEditor().insertTableCell(2, true);
   is(editor.innerHTML, "<table><tbody>" +
                          "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
                          '<tr><td id="select" colspan="2">cell2-1</td><td valign="top"><br></td><td valign="top"><br></td><td>cell2-3</td></tr>' +
                        "</tbody></table>",
      "nsITableEditor.insertTableCell(2, false) should insert 2 cells after the col-spanning cell containing selection");
-  todo_is(inputEvents.length, 1,
-          'Only one "input" event should be fired when selection collapsed in a cell which is col-spanning (after)');
+  is(inputEvents.length, 1,
+     'Only one "input" event should be fired when selection collapsed in a cell which is col-spanning (after)');
   if (inputEvents.length > 0) {
     checkInputEvent(inputEvents[0], "when selection collapsed in a cell which is col-spanning (after)");
   }
 
   editor.removeEventListener("input", onInput);
 
   SimpleTest.finish();
 });