Bug 1268736: An editable table cell means that both the cell and its contents are children of an editable node. r=mats
authorJet Villegas <jvillegas@mozilla.com>
Sat, 04 Jun 2016 03:23:56 -0700
changeset 341541 d5a74fc98333a8ebae36ae7b47e37742490cb566
parent 341336 f3740cfc4b04fb61a1da306df4b1c2437f6bfb65
child 341542 77345805ea822d045e3559cefae78826a987518a
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1268736
milestone49.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 1268736: An editable table cell means that both the cell and its contents are children of an editable node. r=mats
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug1268736.html
layout/generic/nsSelection.cpp
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -145,16 +145,17 @@ subsuite = clipboard
 [test_bug790475.html]
 [test_bug795785.html]
 [test_bug796839.html]
 [test_bug832025.html]
 [test_bug857487.html]
 [test_bug858918.html]
 [test_bug915962.html]
 [test_bug974309.html]
+[test_bug1268736.html]
 skip-if = toolkit == 'android'
 [test_bug966155.html]
 skip-if = os != "win"
 [test_bug966552.html]
 skip-if = os != "win"
 [test_bug998188.html]
 [test_bug1026397.html]
 [test_bug1067255.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1268736.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1268736
+-->
+<head>
+  <title>Test for Bug 1268736</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1268736">Mozilla Bug 1268736</a>
+<table id="table" border="1" width="100%">
+  <tbody>
+    <tr>
+      <td>a</td>
+      <td>b</td>
+      <td>c</td>
+    </tr>
+    <tr>
+      <td>d</td>
+      <td id="cell_readonly">e</td>
+      <td contenteditable="true" id="cell_writable">f</td>
+    </tr>
+  </tbody>
+</table>
+
+<script type="application/javascript">
+
+/**
+ * Test for Bug 1268736
+ *
+ * Tests for editing a table cell's contents when the table cell is or isn't a child of a contenteditable node.
+ *
+ */
+
+function getEditor() {
+  const Ci = SpecialPowers.Ci;
+  var editingSession = SpecialPowers.wrap(window)
+                                    .QueryInterface(Ci.nsIInterfaceRequestor)
+                                    .getInterface(Ci.nsIWebNavigation)
+                                    .QueryInterface(Ci.nsIInterfaceRequestor)
+                                    .getInterface(Ci.nsIEditingSession);
+  return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsITableEditor);
+}
+
+var table = document.getElementById("table");
+var tableHTML = table.innerHTML;
+var editor = getEditor();
+
+var cell = document.getElementById("cell_readonly");
+cell.focus();
+editor.deleteTableCellContents();
+is(table.innerHTML == tableHTML, true, "editor should not modify non-editable table cell" );
+
+cell = document.getElementById("cell_writable");
+cell.focus();
+editor.deleteTableCellContents();
+is(cell.innerHTML == "<br>", true, "editor can modify editable table cells" );
+
+</script>
+</body>
+</html>
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1698,33 +1698,33 @@ nsFrameSelection::TakeFocus(nsIContent* 
     }
 
     //find out if we are inside a table. if so, find out which one and which cell
     //once we do that, the next time we get a takefocus, check the parent tree. 
     //if we are no longer inside same table ,cell then switch to table selection mode.
     // BUT only do this in an editor
 
     NS_ENSURE_STATE(mShell);
-    bool editable = false;
+    bool editableCell = false;
     RefPtr<nsPresContext> context = mShell->GetPresContext();
     if (context) {
       nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(nsContentUtils::GetHTMLEditor(context));
       if (editor) {
+        nsINode* cellparent = GetCellParent(aNewFocus);
         nsCOMPtr<nsINode> editorHostNode = editor->GetActiveEditingHost();
-        editable = editorHostNode && nsContentUtils::ContentIsDescendantOf(aNewFocus, editorHostNode);
+        editableCell = cellparent && editorHostNode && 
+                   nsContentUtils::ContentIsDescendantOf(cellparent, editorHostNode);
+        if (editableCell) {
+          mCellParent = cellparent;
+#ifdef DEBUG_TABLE_SELECTION
+          printf(" * TakeFocus - Collapsing into new cell\n");
+#endif
+        }
       }
     }
-
-    if (editable) {
-      mCellParent = GetCellParent(aNewFocus);
-#ifdef DEBUG_TABLE_SELECTION
-      if (mCellParent)
-        printf(" * TakeFocus - Collapsing into new cell\n");
-#endif
-    }
   }
   else {
     // Now update the range list:
     if (aContinueSelection && aNewFocus)
     {
       int32_t offset;
       nsINode *cellparent = GetCellParent(aNewFocus);
       if (mCellParent && cellparent && cellparent != mCellParent) //switch to cell selection mode