2006-03-17 Eric Seidel <eseidel@apple.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Mar 2006 10:40:39 +0000 (10:40 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Mar 2006 10:40:39 +0000 (10:40 +0000)
        Reviewed by justing.

        Add support for basic HTML editing.

        * Spinneret/Spinneret/WebView.cpp:
        (WebKit::WebView::WebView):
        (WebKit::WebView::keyPress):

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

WebKitTools/ChangeLog
WebKitTools/Spinneret/Spinneret/WebView.cpp

index b0e4cabb89d9430b4e2b38b7f47626c23813ba7a..3a22ed4b13121a98d09e670ff1629342e4d03022 100644 (file)
@@ -1,3 +1,13 @@
+2006-03-17  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by justing.
+
+        Add support for basic HTML editing.
+
+        * Spinneret/Spinneret/WebView.cpp:
+        (WebKit::WebView::WebView):
+        (WebKit::WebView::keyPress):
+
 2006-03-17  Eric Seidel  <eseidel@apple.com>
 
         Rubber-stamped by ggaren.
index f7764a4495f7b7c3efcc4979b41649b1b0554534..782b522c914d4b70dc3b332f45375d50a8e05ae0 100755 (executable)
 
 #include "WebFrame.h"
 
-#include "WebView.h"
-#include "KeyEvent.h"
-#include "Resource.h"
+#include "DocumentImpl.h"
 #include "FrameView.h"
-#include "MouseEvent.h"
 #include "IntRect.h"
+#include "KeyEvent.h"
+#include "MouseEvent.h"
+#include "Resource.h"
+#include "SelectionController.h"
+#include "TypingCommand.h"
+#include "WebView.h"
 
 using namespace WebCore;
 
@@ -104,7 +107,7 @@ WebView::WebView(HWND hWnd)
     d = new WebViewPrivate();
     d->windowHandle = hWnd;
     d->mainFrame = new WebFrame("dummy", this);
-    d->mainFrame->loadHTMLString("<p style=\"background-color: #00FF00\">Testing</p><img src=\"http://webkit.opendarwin.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>");
+    d->mainFrame->loadHTMLString("<p style=\"background-color: #00FF00\">Testing</p><img src=\"http://webkit.opendarwin.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>");
 }
 
 WebView::~WebView()
@@ -149,7 +152,38 @@ void WebView::mouseDoubleClick(WPARAM wParam, LPARAM lParam)
 bool WebView::keyPress(WPARAM wParam, LPARAM lParam)
 {
     KeyEvent keyEvent(windowHandle(), wParam, lParam);
-    return static_cast<FrameWin*>(d->mainFrame->impl())->keyPress(&keyEvent);
+
+    FrameWin* frame = static_cast<FrameWin*>(d->mainFrame->impl());
+    bool handled = frame->keyPress(&keyEvent);
+    if (!handled && !keyEvent.isKeyUp()) {
+        NodeImpl* start = frame->selection().start().node();
+        if (start && start->isContentEditable()) {
+            switch(keyEvent.WindowsKeyCode()) {
+            case VK_BACK:
+                TypingCommand::deleteKeyPressed(frame->document());
+                break;
+            case VK_DELETE:
+                TypingCommand::forwardDeleteKeyPressed(frame->document());
+                break;
+            case VK_LEFT:
+                frame->selection().modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity);
+                break;
+            case VK_RIGHT:
+                frame->selection().modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity);
+                break;
+            case VK_UP:
+                frame->selection().modify(SelectionController::MOVE, SelectionController::BACKWARD, ParagraphGranularity);
+                break;
+            case VK_DOWN:
+                frame->selection().modify(SelectionController::MOVE, SelectionController::FORWARD, ParagraphGranularity);
+                break;
+            default:
+                TypingCommand::insertText(frame->document(), keyEvent.text(), false);
+            }
+            handled = true;
+        }
+    }
+    return handled;
 }
 
 #define LINE_SCROLL_SIZE 30