Moved the editing actions implemented in keyPressEvent into webActionTriggered.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:31 +0000 (14:29 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:31 +0000 (14:29 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27535 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/ChangeLog

index ccbbb4f823f6f2a46c34792d71ac720980783bbe..6ce21df5e1f7c86808e5fabe4577355b74fa3ddb 100644 (file)
@@ -317,6 +317,9 @@ QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const Q
 
 void QWebPage::webActionTriggered(WebAction action, bool checked)
 {
+    WebCore::Editor *editor = d->page->focusController()->focusedOrMainFrame()->editor();
+    const char *command = 0;
+
     switch (action) {
         // ### these need a context...
         case OpenLinkInNewWindow:
@@ -340,16 +343,106 @@ void QWebPage::webActionTriggered(WebAction action, bool checked)
             mainFrame()->d->frame->loader()->reload();
             break;
         case Cut:
-            d->page->focusController()->focusedOrMainFrame()->editor()->cut();
+            editor->cut();
             break;
         case Copy:
-            d->page->focusController()->focusedOrMainFrame()->editor()->copy();
+            editor->copy();
             break;
         case Paste:
-            d->page->focusController()->focusedOrMainFrame()->editor()->paste();
+            editor->paste();
+            break;
+
+        case Undo:
+            editor->undo();
+            break;
+        case Redo:
+            editor->redo();
+            break;
+
+        case MoveToNextChar:
+            command = "MoveForward";
+            break;
+        case MoveToPreviousChar:
+            command = "MoveBackward";
+            break;
+        case MoveToNextWord:
+            command = "MoveWordForward";
+            break;
+        case MoveToPreviousWord:
+            command = "MoveWordBackward";
+            break;
+        case MoveToNextLine:
+            command = "MoveDown";
+            break;
+        case MoveToPreviousLine:
+            command = "MoveUp";
+            break;
+        case MoveToStartOfLine:
+            command = "MoveToBeginningOfLine";
+            break;
+        case MoveToEndOfLine:
+            command = "MoveToEndOfLine";
+            break;
+        case MoveToStartOfBlock:
+            command = "MoveToBeginningOfParagraph";
+            break;
+        case MoveToEndOfBlock:
+            command = "MoveToEndOfParagraph";
+            break;
+        case MoveToStartOfDocument:
+            command = "MoveToBeginningOfDocument";
+            break;
+        case MoveToEndOfDocument:
+            command = "MoveToEndOfDocument";
+            break;
+        case SelectNextChar:
+            command = "MoveForwardAndModifySelection";
+            break;
+        case SelectPreviousChar:
+            command = "MoveBackwardAndModifySelection";
+            break;
+        case SelectNextWord:
+            command = "MoveWordForwardAndModifySelection";
+            break;
+        case SelectPreviousWord:
+            command = "MoveWordBackwardAndModifySelection";
+            break;
+        case SelectNextLine:
+            command = "MoveDownAndModifySelection";
+            break;
+        case SelectPreviousLine:
+            command = "MoveUpAndModifySelection";
+            break;
+        case SelectStartOfLine:
+            command = "MoveToBeginningOfLineAndModifySelection";
+            break;
+        case SelectEndOfLine:
+            command = "MoveToEndOfLineAndModifySelection";
+            break;
+        case SelectStartOfBlock:
+            command = "MoveToBeginningOfParagraphAndModifySelection";
+            break;
+        case SelectEndOfBlock:
+            command = "MoveToEndOfParagraphAndModifySelection";
+            break;
+        case SelectStartOfDocument:
+            command = "MoveToBeginningOfDocumentAndModifySelection";
+            break;
+        case SelectEndOfDocument:
+            command = "MoveToEndOfDocumentAndModifySelection";
+            break;
+        case DeleteStartOfWord:
+            command = "DeleteWordBackward";
+            break;
+        case DeleteEndOfWord:
+            command = "DeleteWordForward";
             break;
+
         default: break;
     }
+
+    if (command)
+        editor->execCommand(command);
 }
 
 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
@@ -570,83 +663,104 @@ void QWebPage::keyPressEvent(QKeyEvent *ev)
     QWebFrame *frame = mainFrame();
     WebCore::Editor *editor = frame->d->frame->editor();
     if (editor->canEdit()) {
-        const char *command = 0;
         if (ev == QKeySequence::Cut) {
-            editor->cut();
+            webActionTriggered(Cut);
             handled = true;
         } else if (ev == QKeySequence::Copy) {
-            editor->copy();
+            webActionTriggered(Copy);
             handled = true;
         } else if (ev == QKeySequence::Paste) {
-            editor->paste();
+            webActionTriggered(Paste);
             handled = true;
         } else if (ev == QKeySequence::Undo) {
-            editor->undo();
+            webActionTriggered(Undo);
             handled = true;
         } else if (ev == QKeySequence::Redo) {
-            editor->redo();
+            webActionTriggered(Redo);
             handled = true;
         } else if(ev == QKeySequence::MoveToNextChar) {
-            command = "MoveForward";
+            webActionTriggered(MoveToNextChar);
+            handled = true;
         } else if(ev == QKeySequence::MoveToPreviousChar) {
-            command = "MoveBackward";
+            webActionTriggered(MoveToPreviousChar);
+            handled = true;
         } else if(ev == QKeySequence::MoveToNextWord) {
-            command = "MoveWordForward";
+            webActionTriggered(MoveToNextWord);
+            handled = true;
         } else if(ev == QKeySequence::MoveToPreviousWord) {
-            command = "MoveWordBackward";
+            webActionTriggered(MoveToPreviousWord);
+            handled = true;
         } else if(ev == QKeySequence::MoveToNextLine) {
-            command = "MoveDown";
+            webActionTriggered(MoveToNextLine);
+            handled = true;
         } else if(ev == QKeySequence::MoveToPreviousLine) {
-            command = "MoveUp";
+            webActionTriggered(MoveToPreviousLine);
+            handled = true;
 //             } else if(ev == QKeySequence::MoveToNextPage) {
 //             } else if(ev == QKeySequence::MoveToPreviousPage) {
         } else if(ev == QKeySequence::MoveToStartOfLine) {
-            command = "MoveToBeginningOfLine";
+            webActionTriggered(MoveToStartOfLine);
+            handled = true;
         } else if(ev == QKeySequence::MoveToEndOfLine) {
-            command = "MoveToEndOfLine";
+            webActionTriggered(MoveToEndOfLine);
+            handled = true;
         } else if(ev == QKeySequence::MoveToStartOfBlock) {
-            command = "MoveToBeginningOfParagraph";
+            webActionTriggered(MoveToStartOfBlock);
+            handled = true;
         } else if(ev == QKeySequence::MoveToEndOfBlock) {
-            command = "MoveToEndOfParagraph";
+            webActionTriggered(MoveToEndOfBlock);
+            handled = true;
         } else if(ev == QKeySequence::MoveToStartOfDocument) {
-            command = "MoveToBeginningOfDocument";
+            webActionTriggered(MoveToStartOfDocument);
+            handled = true;
         } else if(ev == QKeySequence::MoveToEndOfDocument) {
-            command = "MoveToEndOfDocument";
+            webActionTriggered(MoveToEndOfDocument);
+            handled = true;
         } else if(ev == QKeySequence::SelectNextChar) {
-            command = "MoveForwardAndModifySelection";
+            webActionTriggered(SelectNextChar);
+            handled = true;
         } else if(ev == QKeySequence::SelectPreviousChar) {
-            command = "MoveBackwardAndModifySelection";
+            webActionTriggered(SelectPreviousChar);
+            handled = true;
         } else if(ev == QKeySequence::SelectNextWord) {
-            command = "MoveWordForwardAndModifySelection";
+            webActionTriggered(SelectNextWord);
+            handled = true;
         } else if(ev == QKeySequence::SelectPreviousWord) {
-            command = "MoveWordBackwardAndModifySelection";
+            webActionTriggered(SelectPreviousWord);
+            handled = true;
         } else if(ev == QKeySequence::SelectNextLine) {
-            command = "MoveDownAndModifySelection";
+            webActionTriggered(SelectNextLine);
+            handled = true;
         } else if(ev == QKeySequence::SelectPreviousLine) {
-            command = "MoveUpAndModifySelection";
+            webActionTriggered(SelectPreviousLine);
+            handled = true;
 //             } else if(ev == QKeySequence::SelectNextPage) {
 //             } else if(ev == QKeySequence::SelectPreviousPage) {
         } else if(ev == QKeySequence::SelectStartOfLine) {
-            command = "MoveToBeginningOfLineAndModifySelection";
+            webActionTriggered(SelectStartOfLine);
+            handled = true;
         } else if(ev == QKeySequence::SelectEndOfLine) {
-            command = "MoveToEndOfLineAndModifySelection";
+            webActionTriggered(SelectEndOfLine);
+            handled = true;
         } else if(ev == QKeySequence::SelectStartOfBlock) {
-            command = "MoveToBeginningOfParagraphAndModifySelection";
+            webActionTriggered(SelectStartOfBlock);
+            handled = true;
         } else if(ev == QKeySequence::SelectEndOfBlock) {
-            command = "MoveToEndOfParagraphAndModifySelection";
+            webActionTriggered(SelectEndOfBlock);
+            handled = true;
         } else if(ev == QKeySequence::SelectStartOfDocument) {
-            command = "MoveToBeginningOfDocumentAndModifySelection";
+            webActionTriggered(SelectStartOfDocument);
+            handled = true;
         } else if(ev == QKeySequence::SelectEndOfDocument) {
-            command = "MoveToEndOfDocumentAndModifySelection";
+            webActionTriggered(SelectEndOfDocument);
+            handled = true;
         } else if(ev == QKeySequence::DeleteStartOfWord) {
-            command = "DeleteWordBackward";
+            webActionTriggered(DeleteStartOfWord);
+            handled = true;
         } else if(ev == QKeySequence::DeleteEndOfWord) {
-            command = "DeleteWordForward";
-//             } else if(ev == QKeySequence::DeleteEndOfLine) {
-        }
-        if (command) {
-            editor->execCommand(command);
+            webActionTriggered(DeleteEndOfWord);
             handled = true;
+//             } else if(ev == QKeySequence::DeleteEndOfLine) {
         }
     }
     if (!handled) 
index 4105f223151d42a617212a91834c68714afdb1e6..bc55b62ca10976e580c43a49fcc6fff5deeda3ad 100644 (file)
@@ -89,7 +89,36 @@ public:
         Copy,
         Paste,
 
-        NumWebActions = Paste
+        Undo,
+        Redo,
+        MoveToNextChar,
+        MoveToPreviousChar,
+        MoveToNextWord,
+        MoveToPreviousWord,
+        MoveToNextLine,
+        MoveToPreviousLine,
+        MoveToStartOfLine,
+        MoveToEndOfLine,
+        MoveToStartOfBlock,
+        MoveToEndOfBlock,
+        MoveToStartOfDocument,
+        MoveToEndOfDocument,
+        SelectNextChar,
+        SelectPreviousChar,
+        SelectNextWord,
+        SelectPreviousWord,
+        SelectNextLine,
+        SelectPreviousLine,
+        SelectStartOfLine,
+        SelectEndOfLine,
+        SelectStartOfBlock,
+        SelectEndOfBlock,
+        SelectStartOfDocument,
+        SelectEndOfDocument,
+        DeleteStartOfWord,
+        DeleteEndOfWord,
+
+        NumWebActions = DeleteEndOfWord
     };
 
 
index 3536c4fa99ff6f42723c7585e69a60c6ab927f60..92ba58cab06475a14da9513da886c94ebcc7eed8 100644 (file)
@@ -1,3 +1,14 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Moved the editing actions implemented in keyPressEvent into webActionTriggered.
+
+        * Api/qwebpage.cpp:
+        (QWebPage::webActionTriggered):
+        (QWebPage::keyPressEvent):
+        * Api/qwebpage.h:
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.