Backspace/delete at start of table cell shouldn't step out of cell
https://bugs.webkit.org/show_bug.cgi?id=35372

Patch by Shezan Baig <sbaig1@bloomberg.net> on 2013-03-14
Reviewed by Ryosuke Niwa.

Source/WebCore:

Make Delete and ForwardDelete commands be no-ops if we are at the first
position or last position of a table cell respectively.

Tests: editing/deleting/backspace-at-table-cell-beginning.html
       editing/deleting/forward-delete-at-table-cell-ending.html

* editing/TypingCommand.cpp:
(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):

LayoutTests:

* editing/deleting/backspace-at-table-cell-beginning-expected.txt: Added.
* editing/deleting/backspace-at-table-cell-beginning.html: Added.
* editing/deleting/forward-delete-at-table-cell-ending-expected.txt: Added.
* editing/deleting/forward-delete-at-table-cell-ending.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@145871 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TypingCommand.cpp b/Source/WebCore/editing/TypingCommand.cpp
index 4ec50d4..248b3c9 100644
--- a/Source/WebCore/editing/TypingCommand.cpp
+++ b/Source/WebCore/editing/TypingCommand.cpp
@@ -465,8 +465,9 @@
         }
 
         VisiblePosition visibleStart(endingSelection().visibleStart());
-        // If we have a caret selection on an empty cell, we have nothing to do.
-        if (isEmptyTableCell(visibleStart.deepEquivalent().containerNode()))
+        // If we have a caret selection at the beginning of a cell, we have nothing to do.
+        Node* enclosingTableCell = enclosingNodeOfType(visibleStart.deepEquivalent(), &isTableCell);
+        if (enclosingTableCell && visibleStart == firstPositionInNode(enclosingTableCell))
             return;
 
         // If the caret is at the start of a paragraph after a table, move content into the last table cell.
@@ -554,7 +555,8 @@
 
         Position downstreamEnd = endingSelection().end().downstream();
         VisiblePosition visibleEnd = endingSelection().visibleEnd();
-        if (isEmptyTableCell(visibleEnd.deepEquivalent().containerNode()))
+        Node* enclosingTableCell = enclosingNodeOfType(visibleEnd.deepEquivalent(), &isTableCell);
+        if (enclosingTableCell && visibleEnd == lastPositionInNode(enclosingTableCell))
             return;
         if (visibleEnd == endOfParagraph(visibleEnd))
             downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEquivalent().downstream();