LayoutTests:
authorlweintraub <lweintraub@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Jul 2006 19:33:28 +0000 (19:33 +0000)
committerlweintraub <lweintraub@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Jul 2006 19:33:28 +0000 (19:33 +0000)
        Reviewed by justin

        Improved table editing

        * editing/deleting/delete-to-select-table-expected.checksum: Added.
        * editing/deleting/delete-to-select-table-expected.png: Added.
        * editing/deleting/delete-to-select-table-expected.txt: Added.
        * editing/deleting/delete-to-select-table.html: Added.
        * editing/input/text-input-controller-expected.txt:

WebCore:

        Reviewed by justin

        Improved table editing: pressing delete directly before or after a table will now select
        the table first, then delete it, instead of just deleting it. Useful for when the table's
        existence is non-obvious.

        * bridge/mac/FrameMac.h: Added shouldDeleteSelection, which allows WebCore to trigger
        deletion editing deligates
        * bridge/mac/FrameMac.mm: ditto
        (WebCore::FrameMac::shouldDeleteSelection):
        * bridge/mac/WebCoreFrameBridge.h: ditto
        * editing/TypingCommand.cpp: Implemented check for a caret position next to a table, and
        subsequent selection (as opposed to removal)
        (WebCore::TypingCommand::deleteKeyPressed):
        (WebCore::TypingCommand::forwardDeleteKeyPressed):
        * page/Frame.cpp: shouldDeleteSelection added
        (WebCore::Frame::shouldDeleteSelection):
        * page/Frame.h: ditto

WebKit:

        Reviewed by justin

        Improved table editing

        * WebCoreSupport/WebFrameBridge.m: Added method to allow WebCore to trigger
        deletion editing delegate
        (-[WebFrameBridge shouldDeleteSelectedDOMRange:]):
        * WebView/WebHTMLView.m: Moved code that expanded a selection when the delete
        key is pressed over to WebCore so we can be more intelligent about how to handle it
        (-[WebHTMLView _deleteRange:killRing:prepend:smartDeleteOK:deletionAction:]):
        (-[NSArray _deleteWithDirection:granularity:killRing:isTypingAction:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15206 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/deleting/delete-to-select-table-expected.checksum [new file with mode: 0644]
LayoutTests/editing/deleting/delete-to-select-table-expected.png [new file with mode: 0644]
LayoutTests/editing/deleting/delete-to-select-table-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-to-select-table.html [new file with mode: 0644]
LayoutTests/editing/input/text-input-controller-expected.txt
WebCore/ChangeLog
WebCore/bridge/mac/FrameMac.h
WebCore/bridge/mac/FrameMac.mm
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/editing/TypingCommand.cpp
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebFrameBridge.m
WebKit/WebView/WebHTMLView.m

index 951daf30b36c64f8dd5cf40fcc7c9badc3c8b95c..f331084772733a1187a43b349543400d099b0b6e 100644 (file)
@@ -1,3 +1,15 @@
+2006-07-07  Levi Weintraub  <lweintraub@apple.com>
+
+        Reviewed by justin
+
+        Improved table editing
+
+        * editing/deleting/delete-to-select-table-expected.checksum: Added.
+        * editing/deleting/delete-to-select-table-expected.png: Added.
+        * editing/deleting/delete-to-select-table-expected.txt: Added.
+        * editing/deleting/delete-to-select-table.html: Added.
+        * editing/input/text-input-controller-expected.txt:
+
 2006-07-07  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/editing/deleting/delete-to-select-table-expected.checksum b/LayoutTests/editing/deleting/delete-to-select-table-expected.checksum
new file mode 100644 (file)
index 0000000..ecdc79b
--- /dev/null
@@ -0,0 +1 @@
+4f3c4bb088358dbb7dd79f971a4a41b8
\ No newline at end of file
diff --git a/LayoutTests/editing/deleting/delete-to-select-table-expected.png b/LayoutTests/editing/deleting/delete-to-select-table-expected.png
new file mode 100644 (file)
index 0000000..acba608
Binary files /dev/null and b/LayoutTests/editing/deleting/delete-to-select-table-expected.png differ
diff --git a/LayoutTests/editing/deleting/delete-to-select-table-expected.txt b/LayoutTests/editing/deleting/delete-to-select-table-expected.txt
new file mode 100644 (file)
index 0000000..a3179c0
--- /dev/null
@@ -0,0 +1,57 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of TABLE > DIV > BODY > HTML > #document to 2 of TABLE > DIV > BODY > HTML > #document toDOMRange:range from 0 of TABLE > DIV > BODY > HTML > #document to 2 of TABLE > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x52
+        RenderTable {TABLE} at (0,0) size 86x52 [border: (3px solid #AAAAAA)]
+          RenderTableSection {TBODY} at (3,3) size 80x46
+            RenderTableRow {TR} at (0,2) size 80x20
+              RenderTableCell {TD} at (2,2) size 27x20 [r=0 c=0 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 25x18
+                  text run at (1,1) width 25: "Foo"
+              RenderTableCell {TD} at (31,2) size 47x20 [r=0 c=1 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 22x18
+                  text run at (1,1) width 22: "baz"
+            RenderTableRow {TR} at (0,24) size 80x20
+              RenderTableCell {TD} at (2,24) size 27x20 [r=1 c=0 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 25x18
+                  text run at (1,1) width 25: "bar      "
+              RenderTableCell {TD} at (31,24) size 47x20 [r=1 c=1 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 45x18
+                  text run at (1,1) width 45: "buffalo"
+selection start: position 0 of child 1 {TABLE} of child 0 {DIV} of child 2 {BODY} of child 0 {HTML} of document
+selection end:   position 2 of child 1 {TABLE} of child 0 {DIV} of child 2 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/deleting/delete-to-select-table.html b/LayoutTests/editing/deleting/delete-to-select-table.html
new file mode 100644 (file)
index 0000000..14e3548
--- /dev/null
@@ -0,0 +1,34 @@
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+<script>
+function editingTest() {
+    for (i = 0; i < 30; i++) {
+        moveSelectionForwardByCharacterCommand();    
+    }
+    for (i = 0; i < 1; i++) {
+        deleteCommand();
+    }
+}
+</script>
+<div contenteditable="true" id="test">
+  <table style="border:3px solid #aaa;">
+    <tr>
+      <td>
+        Foo
+      </td>
+      <td>
+        baz
+      </td>
+    </tr>
+    <tr>
+      <td>
+        bar
+      </td>
+      <td>
+        buffalo
+      </td>
+    </tr>
+  </table>
+</div>
+<script>
+runEditingTest();
+</script>
\ No newline at end of file
index d0c9ae3fb20510e853a8c4b6323d88586aa6af94..b0fba871ac95c0457edf9dc83494386fe51fd8fc 100644 (file)
@@ -9,7 +9,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 13 of #text > DIV > BODY > HTML > #document to 13 of #text > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 13 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldDeleteDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 13 of #text > DIV > BODY > HTML > #document
 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
index a21b9b026826e3c56179ee212d853d0a99a35a07..25206581d13d6c772abbc983813ef9e1634d4a6b 100644 (file)
@@ -1,3 +1,24 @@
+2006-07-06  Levi Weintraub  <lweintraub@apple.com>
+
+        Reviewed by justin
+
+        Improved table editing: pressing delete directly before or after a table will now select
+        the table first, then delete it, instead of just deleting it. Useful for when the table's
+        existence is non-obvious.
+
+        * bridge/mac/FrameMac.h: Added shouldDeleteSelection, which allows WebCore to trigger
+        deletion editing deligates
+        * bridge/mac/FrameMac.mm: ditto
+        (WebCore::FrameMac::shouldDeleteSelection):
+        * bridge/mac/WebCoreFrameBridge.h: ditto
+        * editing/TypingCommand.cpp: Implemented check for a caret position next to a table, and
+        subsequent selection (as opposed to removal)
+        (WebCore::TypingCommand::deleteKeyPressed):
+        (WebCore::TypingCommand::forwardDeleteKeyPressed):
+        * page/Frame.cpp: shouldDeleteSelection added
+        (WebCore::Frame::shouldDeleteSelection):
+        * page/Frame.h: ditto
+
 2006-07-07  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Eric.
index 6cb150791fa7f6f60c574daee459fd606542db3e..a3766eac94b701cf606a6e93115c20677d4e7853 100644 (file)
@@ -265,6 +265,7 @@ public:
     virtual void respondToChangedContents();
     virtual bool isContentEditable() const;
     virtual bool shouldChangeSelection(const SelectionController &oldSelection, const SelectionController &newSelection, EAffinity affinity, bool stillSelecting) const;
+    virtual bool shouldDeleteSelection(const SelectionController&) const;
     virtual bool shouldBeginEditing(const Range*) const;
     virtual bool shouldEndEditing(const Range*) const;
     virtual void didBeginEditing() const;
index 58e89811a0ebe1a978d4947e68ee5623cf9fd973..253398c24d76fe7714f102ff1e74ed7d77b43a69 100644 (file)
@@ -3169,6 +3169,11 @@ bool FrameMac::shouldChangeSelection(const SelectionController &oldSelection, co
                                   stillSelecting:stillSelecting];
 }
 
+bool FrameMac::shouldDeleteSelection(const SelectionController &selection) const
+{
+    return [_bridge shouldDeleteSelectedDOMRange:[DOMRange _rangeWith:selection.toRange().get()]];
+}
+
 void FrameMac::respondToChangedContents()
 {
     if (AccessibilityObjectCache::accessibilityEnabled())
index cc58b142e819c8b4a4e016cec85474d56062324a..86fee76da1f586e1064bee458dc0a3e236edba5d 100644 (file)
@@ -665,6 +665,7 @@ typedef enum {
 - (void)setIsSelected:(BOOL)isSelected forView:(NSView *)view;
 - (BOOL)isEditable;
 - (BOOL)shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag;
+- (BOOL)shouldDeleteSelectedDOMRange:(DOMRange *)currentRange;
 - (BOOL)shouldBeginEditing:(DOMRange *)range;
 - (BOOL)shouldEndEditing:(DOMRange *)range;
 - (void)didBeginEditing;
index bbfde83dc4763275c76fd682a247449c8fa1e0b2..59bcead12fd7c831b4d0cbcfabaaa298051ab4f2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "BeforeTextInsertedEvent.h"
 #include "BreakBlockquoteCommand.h"
+#include "DeleteSelectionCommand.h"
 #include "Document.h"
 #include "Element.h"
 #include "Frame.h"
@@ -332,6 +333,12 @@ void TypingCommand::deleteKeyPressed()
             // root editable element or at the start of a document.
             SelectionController sc = SelectionController(endingSelection().start(), endingSelection().end(), SEL_DEFAULT_AFFINITY);
             sc.modify(SelectionController::EXTEND, SelectionController::BACKWARD, CharacterGranularity);
+            Position upstreamStart = endingSelection().start().upstream();
+            // When deleting tables: Select the table first, then perform the deletion
+            if (upstreamStart.node()->renderer() && upstreamStart.node()->renderer()->isTable() && upstreamStart.offset() == maxDeepOffset(upstreamStart.node())) {
+                setEndingSelection(Selection(Position(upstreamStart.node(), 0), upstreamStart, DOWNSTREAM));
+                return;
+            }
             selectionToDelete = sc.selection();
             break;
         }
@@ -340,7 +347,7 @@ void TypingCommand::deleteKeyPressed()
             break;
     }
     
-    if (selectionToDelete.isCaretOrRange()) {
+    if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(SelectionController(selectionToDelete))) {
         deleteSelection(selectionToDelete, m_smartDelete);
         setSmartDelete(false);
         typingAddedToOpenCommand();
@@ -361,6 +368,12 @@ void TypingCommand::forwardDeleteKeyPressed()
             // root editable element or at the start of a document.
             SelectionController sc = SelectionController(endingSelection().start(), endingSelection().end(), SEL_DEFAULT_AFFINITY);
             sc.modify(SelectionController::EXTEND, SelectionController::FORWARD, CharacterGranularity);
+            Position downstreamEnd = endingSelection().end().downstream();
+            // When deleting tables: Select the table first, then perform the deletion
+            if (downstreamEnd.node()->renderer() && downstreamEnd.node()->renderer()->isTable() && downstreamEnd.offset() == 0) {
+                setEndingSelection(Selection(downstreamEnd, Position(downstreamEnd.node(), maxDeepOffset(downstreamEnd.node())), DOWNSTREAM));
+                return;
+            }
             selectionToDelete = sc.selection();
             break;
         }
@@ -369,7 +382,7 @@ void TypingCommand::forwardDeleteKeyPressed()
             break;
     }
     
-    if (selectionToDelete.isCaretOrRange()) {
+    if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(SelectionController(selectionToDelete))) {
         deleteSelection(selectionToDelete, m_smartDelete);
         setSmartDelete(false);
         typingAddedToOpenCommand();
index 772be9e55fd8272fde7db5ba755e79e8a5d64068..c1b66a7b30473617278a84e51104872f1e768ed5 100644 (file)
@@ -1973,6 +1973,11 @@ bool Frame::shouldChangeSelection(const SelectionController& newselection) const
     return shouldChangeSelection(d->m_selection, newselection, newselection.affinity(), false);
 }
 
+bool Frame::shouldDeleteSelection(const SelectionController& newselection) const
+{
+    return true;
+}
+
 bool Frame::shouldBeginEditing(const Range *range) const
 {
     return true;
index a87cb45fe08a8c8793e50812b10c79b1f706bbd7..9b65ae7dad4f1bb61a290565e8be2d655c1045d5 100644 (file)
@@ -327,6 +327,7 @@ public:
   // FIXME: Replace these with functions on the selection controller.
   void setSelection(const SelectionController&, bool closeTyping = true, bool keepTypingStyle = false);
   bool shouldChangeSelection(const SelectionController&) const;
+  bool shouldDeleteSelection(const SelectionController&) const;
   
   void notifyRendererOfSelectionChange(bool userTriggered);
 
index 15f11047e83fdb614d1339a1fa853b5b428e23b1..d1c03b21bf90dcb4d631525881a9058ffea1f319 100644 (file)
@@ -1,3 +1,17 @@
+2006-07-06  Levi Weintraub  <lweintraub@apple.com>
+
+        Reviewed by justin
+
+        Improved table editing
+
+        * WebCoreSupport/WebFrameBridge.m: Added method to allow WebCore to trigger
+        deletion editing delegate
+        (-[WebFrameBridge shouldDeleteSelectedDOMRange:]):
+        * WebView/WebHTMLView.m: Moved code that expanded a selection when the delete
+        key is pressed over to WebCore so we can be more intelligent about how to handle it
+        (-[WebHTMLView _deleteRange:killRing:prepend:smartDeleteOK:deletionAction:]):
+        (-[NSArray _deleteWithDirection:granularity:killRing:isTypingAction:]):
+
 2006-07-07  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Tim Hatcher
index e1cc15a9b07475e9220673b220ee9cf11d1cd0d6..6794317d8b742a2e1a20176601254158e6b6f28e 100644 (file)
@@ -1471,6 +1471,12 @@ static id <WebFormDelegate> formDelegate(WebFrameBridge *self)
     return [[self webView] _shouldChangeSelectedDOMRange:currentRange toDOMRange:proposedRange affinity:selectionAffinity stillSelecting:flag];
 }
 
+- (BOOL)shouldDeleteSelectedDOMRange:(DOMRange *)range
+{
+    WebView *webView = [self webView];
+    return [[webView _editingDelegateForwarder] webView:webView shouldDeleteDOMRange:range];
+}
+
 - (BOOL)shouldBeginEditing:(DOMRange *)range
 {
     return [[self webView] _shouldBeginEditingInDOMRange:range];
index 22356bda5697fd375b3d0b7751534ef517304ef3..737215d879c324ced4071a94d8beeff084ffac2c 100644 (file)
@@ -574,10 +574,6 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
        smartDeleteOK:(BOOL)smartDeleteOK 
       deletionAction:(WebDeletionAction)deletionAction
 {
-    if (![self _shouldDeleteRange:range]) {
-        return;
-    }
-
     WebFrameBridge *bridge = [self _bridge];
     BOOL smartDelete = smartDeleteOK ? [self _canSmartCopyOrDelete] : NO;
 
@@ -4537,7 +4533,7 @@ NSStrokeColorAttributeName        /* NSColor, default nil: same as foreground co
         if (isTypingAction)
             deletionAction = deleteKeyAction;
     } else {
-        range = [[self _bridge] rangeByAlteringCurrentSelection:WebSelectByExtending direction:direction granularity:granularity];
+        range = [self _selectedRange];
         if (isTypingAction)
             switch (direction) {
                 case WebBridgeSelectForward:
@@ -4551,7 +4547,7 @@ NSStrokeColorAttributeName        /* NSColor, default nil: same as foreground co
             }
     }
 
-    if (range == nil || [range collapsed] || ![self _shouldDeleteRange:range])
+    if (range == nil)
         return NO;
     [self _deleteRange:range killRing:killRing prepend:NO smartDeleteOK:NO deletionAction:deletionAction];
     return YES;