Reviewed by Dave
Added execCommand support for cut/copy/paste.
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::execCommand): Added cut/copy/paste atoms and added else if cases
for the commands.
* kwq/KWQKHTMLPart.h:
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::issueCutCommand): Glue for calling from WebCore to do a cut in Cocoa.
(KWQKHTMLPart::issueCopyCommand): Same as above, but for copy.
(KWQKHTMLPart::issuePasteCommand): Same as above, but for paste.
* kwq/WebCoreBridge.h: Declared issueCutCommand, issueCopyCommand, and issuePasteCommand
to be implemented on the WebKit side of the bridge.
* layout-tests/editing/editing.js: Added cut/copy/paste support to js library to support
making layout tests.
* layout-tests/editing/pasteboard/copy-paste-text-001-expected.txt: Added.
* layout-tests/editing/pasteboard/copy-paste-text-001.html: Added.
* layout-tests/editing/pasteboard/cut-paste-text-002-expected.txt: Added.
* layout-tests/editing/pasteboard/cut-paste-text-002.html: Added.
* layout-tests/editing/pasteboard/cut-text-001-expected.txt: Added.
* layout-tests/editing/pasteboard/cut-text-001.html: Added.
WebKit:
Reviewed by Dave
Added execCommand support for cut/copy/paste.
* WebCoreSupport.subproj/WebBridge.m:
(-[WebBridge issueCutCommand]): Glue for calling from WebCore to do a cut in Cocoa.
(-[WebBridge issueCopyCommand]): Same as above, but for copy.
(-[WebBridge issuePasteCommand]): Same as above, but for paste.
* WebView.subproj/WebHTMLView.m:
(-[WebHTMLView copy:]): Move this to private implementation category so the bridge can see it.
(-[WebHTMLView cut:]): Ditto.
(-[WebHTMLView paste:]): Ditto.
* WebView.subproj/WebHTMLViewPrivate.h: Move copy;, cut:, and paste: to private implementation
category so the bridge can see it.
* WebView.subproj/WebView.m:
(-[WebView copy:]): Implemented by calling WebHTMLView to do the work.
(-[WebView cut:]): Ditto.
(-[WebView paste:]): Ditto.
* WebView.subproj/WebViewPrivate.h: Added all the NSReponder methods we plan to implement as
part of the WebKit editing API.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6352
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
//-------------------------------------------------------------------------------------------------------
+function execCutCommand() {
+ document.execCommand("Cut");
+}
+function cutCommand() {
+ if (commandDelay > 0) {
+ window.setTimeout(execCutCommand, commandCount * commandDelay);
+ commandCount++;
+ }
+ else {
+ execCutCommand();
+ }
+}
+
+//-------------------------------------------------------------------------------------------------------
+
+function execCopyCommand() {
+ document.execCommand("Copy");
+}
+function copyCommand() {
+ if (commandDelay > 0) {
+ window.setTimeout(execCopyCommand, commandCount * commandDelay);
+ commandCount++;
+ }
+ else {
+ execCopyCommand();
+ }
+}
+
+//-------------------------------------------------------------------------------------------------------
+
+function execPasteCommand() {
+ document.execCommand("Paste");
+}
+function pasteCommand() {
+ if (commandDelay > 0) {
+ window.setTimeout(execPasteCommand, commandCount * commandDelay);
+ commandCount++;
+ }
+ else {
+ execPasteCommand();
+ }
+}
+
+//-------------------------------------------------------------------------------------------------------
+
function execDeleteCommand() {
document.execCommand("Delete");
}
--- /dev/null
+layer at (0,0) size 800x600
+ RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x72
+ RenderBlock {HTML} at (0,0) size 800x72
+ RenderBody {BODY} at (8,8) size 784x56
+ RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+ RenderInline {SPAN} at (0,0) size 140x28
+ RenderText {TEXT} at (14,14) size 109x28
+ text run at (14,14) width 109: "foo bar baz"
+ RenderInline {SPAN} at (0,0) size 31x28
+ RenderText {TEXT} at (123,14) size 31x28
+ text run at (123,14) width 31: "bar"
+selection is CARET:
+start: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
+upstream: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
+downstream: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
--- /dev/null
+<html>
+<head>
+
+<style>
+.editing {
+ border: 2px solid red;
+ padding: 12px;
+ font-size: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+ for (i = 0; i < 4; i++)
+ moveSelectionForwardByCharacterCommand();
+ for (i = 0; i < 3; i++)
+ extendSelectionForwardByCharacterCommand();
+ copyCommand();
+ for (i = 0; i < 5; i++)
+ moveSelectionForwardByCharacterCommand();
+ pasteCommand();
+}
+
+</script>
+
+<title>Editing Test</title>
+</head>
+<body>
+<div contenteditable id="root" class="editing">
+<span id="test">foo bar baz</span>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
--- /dev/null
+layer at (0,0) size 800x600
+ RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x72
+ RenderBlock {HTML} at (0,0) size 800x72
+ RenderBody {BODY} at (8,8) size 784x56
+ RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+ RenderInline {SPAN} at (0,0) size 109x28
+ RenderText {TEXT} at (14,14) size 78x28
+ text run at (14,14) width 78: "foo baz"
+ RenderInline {SPAN} at (0,0) size 31x28
+ RenderText {TEXT} at (92,14) size 31x28
+ text run at (92,14) width 31: "bar"
+selection is CARET:
+start: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
+upstream: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
+downstream: position 3 of child 1 {TEXT} of child 2 {SPAN} of child 2 {SPAN} of root {DIV}
--- /dev/null
+<html>
+<head>
+
+<style>
+.editing {
+ border: 2px solid red;
+ padding: 12px;
+ font-size: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+ for (i = 0; i < 4; i++)
+ moveSelectionForwardByCharacterCommand();
+ for (i = 0; i < 3; i++)
+ extendSelectionForwardByCharacterCommand();
+ cutCommand();
+ for (i = 0; i < 4; i++)
+ moveSelectionForwardByCharacterCommand();
+ pasteCommand();
+}
+
+</script>
+
+<title>Editing Test</title>
+</head>
+<body>
+<div contenteditable id="root" class="editing">
+<span id="test">foo bar baz</span>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
--- /dev/null
+layer at (0,0) size 800x600
+ RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x72
+ RenderBlock {HTML} at (0,0) size 800x72
+ RenderBody {BODY} at (8,8) size 784x56
+ RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+ RenderInline {SPAN} at (0,0) size 78x28
+ RenderText {TEXT} at (14,14) size 78x28
+ text run at (14,14) width 78: "foo baz"
+ RenderText {TEXT} at (0,0) size 0x0
+selection is CARET:
+start: position 4 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
+upstream: position 4 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
+downstream: position 4 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
--- /dev/null
+<html>
+<head>
+
+<style>
+.editing {
+ border: 2px solid red;
+ padding: 12px;
+ font-size: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+ for (i = 0; i < 4; i++)
+ moveSelectionForwardByCharacterCommand();
+ for (i = 0; i < 3; i++)
+ extendSelectionForwardByCharacterCommand();
+ cutCommand();
+}
+
+</script>
+
+<title>Editing Test</title>
+</head>
+<body>
+<div contenteditable id="root" class="editing">
+<span id="test">foo bar baz</span>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
+2004-04-12 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by Dave
+
+ Added execCommand support for cut/copy/paste.
+
+ * khtml/xml/dom_docimpl.cpp:
+ (DocumentImpl::execCommand): Added cut/copy/paste atoms and added else if cases
+ for the commands.
+ * kwq/KWQKHTMLPart.h:
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::issueCutCommand): Glue for calling from WebCore to do a cut in Cocoa.
+ (KWQKHTMLPart::issueCopyCommand): Same as above, but for copy.
+ (KWQKHTMLPart::issuePasteCommand): Same as above, but for paste.
+ * kwq/WebCoreBridge.h: Declared issueCutCommand, issueCopyCommand, and issuePasteCommand
+ to be implemented on the WebKit side of the bridge.
+ * layout-tests/editing/editing.js: Added cut/copy/paste support to js library to support
+ making layout tests.
+ * layout-tests/editing/pasteboard/copy-paste-text-001-expected.txt: Added.
+ * layout-tests/editing/pasteboard/copy-paste-text-001.html: Added.
+ * layout-tests/editing/pasteboard/cut-paste-text-002-expected.txt: Added.
+ * layout-tests/editing/pasteboard/cut-paste-text-002.html: Added.
+ * layout-tests/editing/pasteboard/cut-text-001-expected.txt: Added.
+ * layout-tests/editing/pasteboard/cut-text-001.html: Added.
+
2004-04-12 Ken Kocienda <kocienda@apple.com>
Reviewed by John
static AtomicString undoCommand("undo");
static AtomicString redoCommand("redo");
static AtomicString deleteCommand("delete");
+ static AtomicString cutCommand("cut");
+ static AtomicString copyCommand("copy");
+ static AtomicString pasteCommand("paste");
updateLayout();
TypingCommand::deleteKeyPressed(this);
return true;
}
+ else if (atom == cutCommand) {
+ if (!part() || part()->selection().state() != KHTMLSelection::RANGE)
+ return false;
+ KWQ(part())->issueCutCommand();
+ return true;
+ }
+ else if (atom == copyCommand) {
+ if (!part() || part()->selection().state() != KHTMLSelection::RANGE)
+ return false;
+ KWQ(part())->issueCopyCommand();
+ return true;
+ }
+ else if (atom == pasteCommand) {
+ if (!part() || part()->selection().isEmpty())
+ return false;
+ KWQ(part())->issuePasteCommand();
+ return true;
+ }
return false;
}
void editingKeyEvent();
void issueUndoCommand();
void issueRedoCommand();
+ void issueCutCommand();
+ void issueCopyCommand();
+ void issuePasteCommand();
private:
virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
{
[_bridge issueRedoCommand];
}
+
+void KWQKHTMLPart::issueCutCommand()
+{
+ [_bridge issueCutCommand];
+}
+
+void KWQKHTMLPart::issueCopyCommand()
+{
+ [_bridge issueCopyCommand];
+}
+
+void KWQKHTMLPart::issuePasteCommand()
+{
+ [_bridge issuePasteCommand];
+}
- (void)clearUndoRedoOperations;
- (void)issueUndoCommand;
- (void)issueRedoCommand;
+- (void)issueCutCommand;
+- (void)issueCopyCommand;
+- (void)issuePasteCommand;
- (void)editingKeyDown:(NSEvent *)event;
+2004-04-12 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by Dave
+
+ Added execCommand support for cut/copy/paste.
+
+ * WebCoreSupport.subproj/WebBridge.m:
+ (-[WebBridge issueCutCommand]): Glue for calling from WebCore to do a cut in Cocoa.
+ (-[WebBridge issueCopyCommand]): Same as above, but for copy.
+ (-[WebBridge issuePasteCommand]): Same as above, but for paste.
+ * WebView.subproj/WebHTMLView.m:
+ (-[WebHTMLView copy:]): Move this to private implementation category so the bridge can see it.
+ (-[WebHTMLView cut:]): Ditto.
+ (-[WebHTMLView paste:]): Ditto.
+ * WebView.subproj/WebHTMLViewPrivate.h: Move copy;, cut:, and paste: to private implementation
+ category so the bridge can see it.
+ * WebView.subproj/WebView.m:
+ (-[WebView copy:]): Implemented by calling WebHTMLView to do the work.
+ (-[WebView cut:]): Ditto.
+ (-[WebView paste:]): Ditto.
+ * WebView.subproj/WebViewPrivate.h: Added all the NSReponder methods we plan to implement as
+ part of the WebKit editing API.
+
2004-04-09 Ken Kocienda <kocienda@apple.com>
Reviewed by Darin
[undoManager redo];
}
+- (void)issueCutCommand
+{
+ [[_frame webView] cut:nil];
+}
+
+- (void)issueCopyCommand
+{
+ [[_frame webView] copy:nil];
+}
+
+- (void)issuePasteCommand
+{
+ [[_frame webView] paste:nil];
+}
+
- (void)setIsSelected:(BOOL)isSelected forView:(NSView *)view
{
if ([view conformsToProtocol:@protocol(WebPluginSelection)]) {
[self mouseDragged:fakeEvent];
}
+- (void)copy:(id)sender
+{
+ [self _writeSelectionToPasteboard:[NSPasteboard generalPasteboard]];
+}
+
+- (void)cut:(id)sender
+{
+ [self copy:sender];
+ [[self _bridge] deleteSelection];
+}
+
+- (void)paste:(id)sender
+{
+ [self _pasteFromPasteboard:[NSPasteboard generalPasteboard]];
+}
+
@end
@implementation NSView (WebHTMLViewPrivate)
- (void)_startAutoscrollTimer:(NSEvent *)event;
- (void)_stopAutoscrollTimer;
+
+- (void)cut:(id)sender;
+- (void)copy:(id)sender;
+- (void)paste:(id)sender;
+
@end
#import <WebKit/WebFrameViewPrivate.h>
#import <WebKit/WebHistoryItemPrivate.h>
#import <WebKit/WebHTMLView.h>
+#import <WebKit/WebHTMLViewPrivate.h>
#import <WebKit/WebIconDatabase.h>
#import <WebKit/WebKitErrors.h>
#import <WebKit/WebKitLogging.h>
- (void)copy:(id)sender
{
if ([self _currentSelectionIsEditable]) {
- ERROR("unimplemented");
+ id <WebDocumentView> view = [[[self mainFrame] frameView] documentView];
+ if ([view isKindOfClass:[WebHTMLView class]]) {
+ [(WebHTMLView *)view copy:nil];
+ }
return;
}
[[self nextResponder] tryToPerform:@selector(copy:) with:sender];
- (void)cut:(id)sender
{
if ([self _currentSelectionIsEditable]) {
- ERROR("unimplemented");
+ id <WebDocumentView> view = [[[self mainFrame] frameView] documentView];
+ if ([view isKindOfClass:[WebHTMLView class]]) {
+ [(WebHTMLView *)view cut:nil];
+ }
return;
}
[[self nextResponder] tryToPerform:@selector(cut:) with:sender];
- (void)paste:(id)sender
{
if ([self _currentSelectionIsEditable]) {
- ERROR("unimplemented");
+ id <WebDocumentView> view = [[[self mainFrame] frameView] documentView];
+ if ([view isKindOfClass:[WebHTMLView class]]) {
+ [(WebHTMLView *)view paste:nil];
+ }
return;
}
[[self nextResponder] tryToPerform:@selector(paste:) with:sender];
- (NSUndoManager *)undoManagerForWebView:(WebView *)webView;
@end
+@interface WebView (WebViewEditingActions)
+
+ /* Selection movement and scrolling */
+
+- (void)centerSelectionInVisibleArea:(id)sender;
+- (void)moveBackward:(id)sender;
+- (void)moveBackwardAndModifySelection:(id)sender;
+- (void)moveDown:(id)sender;
+- (void)moveDownAndModifySelection:(id)sender;
+- (void)moveForward:(id)sender;
+- (void)moveForwardAndModifySelection:(id)sender;
+- (void)moveLeft:(id)sender;
+- (void)moveLeftAndModifySelection:(id)sender;
+- (void)moveRight:(id)sender;
+- (void)moveRightAndModifySelection:(id)sender;
+- (void)moveToBeginningOfDocument:(id)sender;
+- (void)moveToBeginningOfLine:(id)sender;
+- (void)moveToBeginningOfParagraph:(id)sender;
+- (void)moveToEndOfDocument:(id)sender;
+- (void)moveToEndOfLine:(id)sender;
+- (void)moveToEndOfParagraph:(id)sender;
+- (void)moveUp:(id)sender;
+- (void)moveUpAndModifySelection:(id)sender;
+- (void)moveWordBackward:(id)sender;
+- (void)moveWordBackwardAndModifySelection:(id)sender;
+- (void)moveWordForward:(id)sender;
+- (void)moveWordForwardAndModifySelection:(id)sender;
+- (void)moveWordLeft:(id)sender;
+- (void)moveWordLeftAndModifySelection:(id)sender;
+- (void)moveWordRight:(id)sender;
+- (void)moveWordRightAndModifySelection:(id)sender;
+- (void)pageDown:(id)sender;
+- (void)pageUp:(id)sender;
+- (void)scrollLineDown:(id)sender;
+- (void)scrollLineUp:(id)sender;
+- (void)scrollPageDown:(id)sender;
+- (void)scrollPageUp:(id)sender;
+
+ /* Selections */
+
+- (void)selectAll:(id)sender;
+- (void)selectParagraph:(id)sender;
+- (void)selectLine:(id)sender;
+- (void)selectWord:(id)sender;
+
+ /* "Edit menu" actions */
+
+- (void)copy:(id)sender;
+- (void)cut:(id)sender;
+- (void)paste:(id)sender;
+- (void)copyFont:(id)sender;
+- (void)pasteFont:(id)sender;
+- (void)delete:(id)sender;
+- (void)pasteAsPlainText:(id)sender;
+- (void)pasteAsRichText:(id)sender;
+
+ /* Fonts */
+
+- (void)changeFont:(id)sender;
+- (void)changeAttributes:(id)sender;
+- (void)changeDocumentBackgroundColor:(id)sender;
+
+ /* Colors */
+
+- (void)changeColor:(id)sender;
+
+ /* Alignment */
+
+- (void)alignCenter:(id)sender;
+- (void)alignJustified:(id)sender;
+- (void)alignLeft:(id)sender;
+- (void)alignRight:(id)sender;
+
+ /* Insertions and Indentations */
+
+- (void)indent:(id)sender;
+- (void)insertTab:(id)sender;
+- (void)insertBacktab:(id)sender;
+- (void)insertNewline:(id)sender;
+- (void)insertParagraphSeparator:(id)sender;
+
+ /* Case changes */
+
+- (void)changeCaseOfLetter:(id)sender;
+- (void)uppercaseWord:(id)sender;
+- (void)lowercaseWord:(id)sender;
+- (void)capitalizeWord:(id)sender;
+
+ /* Deletions */
+
+- (void)deleteForward:(id)sender;
+- (void)deleteBackward:(id)sender;
+- (void)deleteBackwardByDecomposingPreviousCharacter:(id)sender;
+- (void)deleteWordForward:(id)sender;
+- (void)deleteWordBackward:(id)sender;
+- (void)deleteToBeginningOfLine:(id)sender;
+- (void)deleteToEndOfLine:(id)sender;
+- (void)deleteToBeginningOfParagraph:(id)sender;
+- (void)deleteToEndOfParagraph:(id)sender;
+
+ /* Completion */
+
+- (void)complete:(id)sender;
+
+ /* Spelling */
+
+- (void)checkSpelling:(id)sender;
+- (void)showGuessPanel:(id)sender;
+
+ /* Finding */
+
+- (void)performFindPanelAction:(id)sender;
+
+ /* Speech */
+
+- (void)startSpeaking:(id)sender;
+- (void)stopSpeaking:(id)sender;
+
+@end
+
@interface WebView (WebViewEditingExtras)
- (void)_editingKeyDown:(NSEvent *)event;
@end