LayoutTests:
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: http://svn.webkit.org/repository/webkit/trunk@15206 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/editing/TypingCommand.cpp b/WebCore/editing/TypingCommand.cpp
index bbfde83..59bcead 100644
--- a/WebCore/editing/TypingCommand.cpp
+++ b/WebCore/editing/TypingCommand.cpp
@@ -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 @@
// 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 @@
break;
}
- if (selectionToDelete.isCaretOrRange()) {
+ if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(SelectionController(selectionToDelete))) {
deleteSelection(selectionToDelete, m_smartDelete);
setSmartDelete(false);
typingAddedToOpenCommand();
@@ -361,6 +368,12 @@
// 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 @@
break;
}
- if (selectionToDelete.isCaretOrRange()) {
+ if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(SelectionController(selectionToDelete))) {
deleteSelection(selectionToDelete, m_smartDelete);
setSmartDelete(false);
typingAddedToOpenCommand();