Add undo/redo support and more editing commands.
authorstaikos <staikos@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2007 16:55:34 +0000 (16:55 +0000)
committerstaikos <staikos@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2007 16:55:34 +0000 (16:55 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19773 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.pro
WebKitQt/Api/qwebpage.cpp
WebKitQt/Api/qwebpage.h
WebKitQt/Api/qwebpage_p.h
WebKitQt/ChangeLog
WebKitQt/WebCoreSupport/EditorClientQt.cpp
WebKitQt/WebCoreSupport/EditorClientQt.h

index 27b25b7bcbcb95422e27d58cea1e02ab50398572..dbd88a9e7d6ec44e9eed5ee566a4e09b37829802 100644 (file)
@@ -1,3 +1,11 @@
+2007-02-21  George Staikos  <staikos@kde.org>
+
+        Reviewed by Zack.
+
+        Add files to the build.
+
+        * WebCore.pro:
+
 2007-02-21  Zack Rusin  <zrusin@trolltech.com>
 
         Reviewed by Lars
index c285980c20cf78f95de2ed4b2112ab0b090a50e1..370e96e0cd3a5e812e8572bb6e576e34f86d0a6e 100644 (file)
@@ -709,6 +709,7 @@ SOURCES += \
     ../WebKitQt/WebCoreSupport/ContextMenuClientQt.cpp \
     ../WebKitQt/WebCoreSupport/DragClientQt.cpp \
     ../WebKitQt/WebCoreSupport/EditorClientQt.cpp \
+    ../WebKitQt/WebCoreSupport/EditCommandQt.cpp \
     ../WebKitQt/WebCoreSupport/FrameLoaderClientQt.cpp \
     ../WebKitQt/Api/qwebframe.cpp \
     ../WebKitQt/Api/qcookiejar.cpp \
index 83bb52708a612f71149e7dd2f609d7baf3211afc..a6a29019365b236a5a54bc929eeb04aa3f222fc4 100644 (file)
@@ -39,6 +39,7 @@
 #include "KURL.h"
 
 #include <QDebug>
+#include <QUndoStack>
 #include <QUrl>
 #include <QVBoxLayout>
 
@@ -67,11 +68,13 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
     settings->setFixedFontFamily("Courier");
     settings->setStandardFontFamily("Arial");
 
+    undoStack = 0;
     mainFrame = 0;
 }
 
 QWebPagePrivate::~QWebPagePrivate()
 {
+    delete undoStack;
     delete page;
 }
 
@@ -199,4 +202,13 @@ bool QWebPage::isModified() const
     return d->modified;
 }
 
+
+QUndoStack *QWebPage::undoStack()
+{
+    if (!d->undoStack)
+        d->undoStack = new QUndoStack(this);
+
+    return d->undoStack;
+}
+
 #include "qwebpage.moc"
index b2bf29dadcb8bb4808c3aed4e606864dfd7b64c6..037efa3ad5965ca5dab57f27c05ee835ed2673f5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <qwidget.h>
 class QWebFrame;
+class QUndoStack;
 class QUrl;
 
 class QWebPagePrivate;
@@ -71,6 +72,8 @@ public:
 
     virtual void runJavaScriptAlert(QWebFrame *frame, const QString& msg);
 
+    QUndoStack *undoStack();
+
 public slots:
     /**
      * Stops loading of the page, if loading.
index 6cb2fdbff0660e6b64006a0ec7c0739ce2478c78..b04aa8ca2996549894c87b1797b443955e690500 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore
 }
 
 class QVBoxLayout;
+class QUndoStack;
 
 class QWebPagePrivate
 {
@@ -53,6 +54,7 @@ public:
     QVBoxLayout *layout;
 
     QWebPage *q;
+    QUndoStack *undoStack;
 
     bool modified;
 };
index f1e7fef52221fee1f2401e87c1e21271edbd1912..99a019c3beb942b058c81976f5fae4e7195eb7c0 100644 (file)
@@ -1,3 +1,34 @@
+2007-02-21  George Staikos  <staikos@kde.org>
+
+        Reviewed by Zack.
+
+        Add more editing support, and undo/redo.  Requires some nasty evil
+        hacks that have to be sorted out in WebCore/editor.
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::QWebPagePrivate):
+        (QWebPagePrivate::~QWebPagePrivate):
+        (QWebPage::undoStack):
+        * Api/qwebpage.h:
+        * Api/qwebpage_p.h:
+        * WebCoreSupport/EditorClientQt.cpp:
+        (WebCore::EditorClientQt::didBeginEditing):
+        (WebCore::EditorClientQt::didEndEditing):
+        (WebCore::EditorClientQt::isEditable):
+        (WebCore::EditorClientQt::registerCommandForUndo):
+        (WebCore::EditorClientQt::registerCommandForRedo):
+        (WebCore::EditorClientQt::clearUndoRedoOperations):
+        (WebCore::EditorClientQt::canUndo):
+        (WebCore::EditorClientQt::canRedo):
+        (WebCore::EditorClientQt::undo):
+        (WebCore::EditorClientQt::redo):
+        (WebCore::EditorClientQt::handleKeyPress):
+        (WebCore::EditorClientQt::EditorClientQt):
+        (WebCore::EditorClientQt::textFieldDidBeginEditing):
+        (WebCore::EditorClientQt::textFieldDidEndEditing):
+        (WebCore::EditorClientQt::isEditing):
+        * WebCoreSupport/EditorClientQt.h:
+
 2007-02-21  Zack Rusin  <zrusin@trolltech.com>
 
         Fix compilation.
index e76c2d31fd5455e895715b6d3292be4f54df6fd9..8af531d8bfeb52b131823fdbd0fa94f86f644eba 100644 (file)
@@ -33,7 +33,7 @@
 #include "qwebpage.h"
 #include "qwebpage_p.h"
 
-#include "EditCommand.h"
+#include "EditCommandQt.h"
 #include "Editor.h"
 #include "FocusController.h"
 #include "Frame.h"
@@ -44,6 +44,7 @@
 
 #include <stdio.h>
 
+#include <QUndoStack>
 
 #define notImplemented() qDebug("FIXME: UNIMPLEMENTED: %s:%d (%s)", __FILE__, __LINE__, __FUNCTION__)
 
@@ -105,7 +106,7 @@ bool EditorClientQt::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
 
 void EditorClientQt::didBeginEditing()
 {
-    notImplemented();
+    m_editing = true;
 }
 
 void EditorClientQt::respondToChangedContents()
@@ -115,7 +116,7 @@ void EditorClientQt::respondToChangedContents()
 
 void EditorClientQt::didEndEditing()
 {
-    notImplemented();
+    m_editing = false;
 }
 
 void EditorClientQt::didWriteSelectionToPasteboard()
@@ -137,44 +138,49 @@ bool EditorClientQt::selectWordBeforeMenuEvent()
 bool EditorClientQt::isEditable()
 {
     // FIXME: should be controllable by a setting in QWebPage
-    return true;
+    return false;
 }
 
-void EditorClientQt::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>)
+void EditorClientQt::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd)
 {
-    notImplemented();
+    Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame();
+    if (m_inUndoRedo || (frame && !frame->editor()->lastEditCommand() /* HACK!! Don't recreate undos */)) {
+        return;
+    }
+    m_page->undoStack()->push(new EditCommandQt(cmd));
 }
 
 void EditorClientQt::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
 {
-    notImplemented();
 }
 
 void EditorClientQt::clearUndoRedoOperations()
 {
-    //notImplemented();
+    return m_page->undoStack()->clear();
 }
 
 bool EditorClientQt::canUndo() const
 {
-    notImplemented();
-    return false;
+    return m_page->undoStack()->canUndo();
 }
 
 bool EditorClientQt::canRedo() const
 {
-    notImplemented();
-    return false;
+    return m_page->undoStack()->canRedo();
 }
 
 void EditorClientQt::undo()
 {
-    notImplemented();
+    m_inUndoRedo = true;
+    m_page->undoStack()->undo();
+    m_inUndoRedo = false;
 }
 
 void EditorClientQt::redo()
 {
-    notImplemented();
+    m_inUndoRedo = true;
+    m_page->undoStack()->redo();
+    m_inUndoRedo = false;
 }
 
 bool EditorClientQt::shouldInsertNode(Node*, Range*, EditorInsertAction)
@@ -223,19 +229,31 @@ void EditorClientQt::handleKeyPress(KeyboardEvent* event)
                                                      CharacterGranularity, false, true);
                 break;
             case VK_LEFT:
-                frame->editor()->execCommand("MoveLeft");
+                if (kevent->shiftKey())
+                    frame->editor()->execCommand("MoveLeftAndModifySelection");
+                else frame->editor()->execCommand("MoveLeft");
                 break;
             case VK_RIGHT:
-                frame->editor()->execCommand("MoveRight");
+                if (kevent->shiftKey())
+                    frame->editor()->execCommand("MoveRightAndModifySelection");
+                else frame->editor()->execCommand("MoveRight");
                 break;
             case VK_UP:
-                frame->editor()->execCommand("MoveUp");
+                if (kevent->shiftKey())
+                    frame->editor()->execCommand("MoveUpAndModifySelection");
+                else frame->editor()->execCommand("MoveUp");
                 break;
             case VK_DOWN:
-                frame->editor()->execCommand("MoveDown");
+                if (kevent->shiftKey())
+                    frame->editor()->execCommand("MoveDownAndModifySelection");
+                else frame->editor()->execCommand("MoveDown");
+                break;
+            case VK_RETURN:
+                frame->editor()->insertLineBreak();
                 break;
             default:
-                frame->editor()->insertText(kevent->text(), false, event);
+                if (!kevent->ctrlKey() && !kevent->altKey())
+                    frame->editor()->insertText(kevent->text(), false, event);
             }
             event->setDefaultHandled();
         }
@@ -243,16 +261,18 @@ void EditorClientQt::handleKeyPress(KeyboardEvent* event)
 }
 
 EditorClientQt::EditorClientQt(QWebPage* page)
-    : m_page(page)
+    : m_page(page), m_editing(false), m_inUndoRedo(false)
 {
 }
 
 void EditorClientQt::textFieldDidBeginEditing(Element*)
 {
+    m_editing = true;
 }
 
 void EditorClientQt::textFieldDidEndEditing(Element*)
 {
+    m_editing = false;
 }
 
 void EditorClientQt::textDidChangeInTextField(Element*)
@@ -272,6 +292,11 @@ void EditorClientQt::textDidChangeInTextArea(Element*)
 {
 }
 
+bool EditorClientQt::isEditing() const
+{
+    return m_editing;
+}
+
 }
 
 // vim: ts=4 sw=4 et
index 75177ad5e29879968a3bfa552aacbfec4d0d06ae..5d847ec996bc084e5bc0884f9527d2c2e557ceb7 100644 (file)
@@ -90,8 +90,12 @@ public:
     virtual void textWillBeDeletedInTextField(Element*);
     virtual void textDidChangeInTextArea(Element*);
 
+    bool isEditing() const;
+
 private:
     QWebPage* m_page;
+    bool m_editing;
+    bool m_inUndoRedo; // our undo stack works differently - don't re-enter!
 };
 
 }