Reviewed by Kevin Ollivier.
authorkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Nov 2008 03:24:04 +0000 (03:24 +0000)
committerkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Nov 2008 03:24:04 +0000 (03:24 +0000)
Maintain an EditCommand stack in WebFramePrivate, and expose Undo and
Redo in wxWebView.

https://bugs.webkit.org/show_bug.cgi?id=22403

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

WebKit/wx/ChangeLog
WebKit/wx/WebFrame.cpp
WebKit/wx/WebFrame.h
WebKit/wx/WebFramePrivate.h [new file with mode: 0644]
WebKit/wx/WebKitSupport/ChromeClientWx.cpp
WebKit/wx/WebKitSupport/EditCommandWx.h [new file with mode: 0644]
WebKit/wx/WebKitSupport/EditorClientWx.cpp
WebKit/wx/WebKitSupport/EditorClientWx.h
WebKit/wx/WebView.cpp
WebKit/wx/WebViewPrivate.h

index 340b951818e6cf799a2f192d5113c22ecbec4ca9..84acd29d539e0aec2dc4d0eb1cd5aa8e840b27ed 100644 (file)
@@ -1,3 +1,40 @@
+2008-11-21  Kevin Watters  <kevinwatters@gmail.com>
+
+        Reviewed by Kevin Ollivier.
+
+        Maintain an EditCommand stack in WebFramePrivate, and expose Undo and
+        Redo in wxWebView.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=22403
+
+        * WebFrame.cpp:
+        (wxWebFrame::wxWebFrame):
+        (wxWebFrame::Undo):
+        (wxWebFrame::Redo):
+        (wxWebFrame::CanUndo):
+        (wxWebFrame::CanRedo):
+        * WebFrame.h:
+        * WebFramePrivate.h: Added.
+        (WebFramePrivate::WebFramePrivate):
+        * WebKitSupport/ChromeClientWx.cpp:
+        (WebCore::ChromeClientWx::createWindow):
+        * WebKitSupport/EditCommandWx.h: Added.
+        (EditCommandWx::EditCommandWx):
+        (EditCommandWx::~EditCommandWx):
+        (EditCommandWx::editCommand):
+        * WebKitSupport/EditorClientWx.cpp:
+        (WebCore::EditorClientWx::registerCommandForUndo):
+        (WebCore::EditorClientWx::registerCommandForRedo):
+        (WebCore::EditorClientWx::canUndo):
+        (WebCore::EditorClientWx::canRedo):
+        (WebCore::EditorClientWx::undo):
+        (WebCore::EditorClientWx::redo):
+        * WebKitSupport/EditorClientWx.h:
+        * WebView.cpp:
+        (wxWebView::OnMouseEvents):
+        (wxWebView::OnKeyEvents):
+        * WebViewPrivate.h:
+
 2008-11-19  Darin Fisher  <darin@chromium.org>
 
         Reviewed by Geoff Garen.
index d3337166a130699e9887bcd64aea03e0101da0e9..74c79470cb43b310f147bc336a3fa344b67fe1f2 100644 (file)
@@ -54,6 +54,7 @@
 
 #include "WebFrame.h"
 #include "WebView.h"
+#include "WebFramePrivate.h"
 #include "WebViewPrivate.h"
 
 #include <wx/defs.h>
@@ -72,7 +73,7 @@ wxWebFrame::wxWebFrame(wxWebView* container, wxWebFrame* parent, WebViewFrameDat
     m_title(wxEmptyString)
 {
 
-    m_impl = new WebViewPrivate();
+    m_impl = new WebFramePrivate();
  
     WebCore::HTMLFrameOwnerElement* parentFrame = 0;
     
@@ -233,6 +234,35 @@ bool wxWebFrame::CanGoForward()
 
     return false;
 }
+
+void wxWebFrame::Undo()
+{
+    if (m_impl->frame && m_impl->frame->editor() && CanUndo())
+        return m_impl->frame->editor()->undo();
+}
+
+void wxWebFrame::Redo()
+{
+    if (m_impl->frame && m_impl->frame->editor() && CanRedo())
+        return m_impl->frame->editor()->redo();
+}
+
+bool wxWebFrame::CanUndo()
+{
+    if (m_impl->frame && m_impl->frame->editor())
+        return m_impl->frame->editor()->canUndo();
+
+    return false;
+}
+
+bool wxWebFrame::CanRedo()
+{
+    if (m_impl->frame && m_impl->frame->editor())
+        return m_impl->frame->editor()->canRedo();
+
+    return false;
+}
+
 bool wxWebFrame::CanIncreaseTextSize() const
 {
     if (m_impl->frame) {
index a6961eb177265a9bd52a17d63d8b8c4200c18be5..083043f69469b95dbb23b4e17c02d74daabad3be 100644 (file)
     #include "wx/wx.h"
 #endif
 
-class WebViewPrivate;
+class WebFramePrivate;
 class WebViewFrameData;
 class wxWebView;
 
 namespace WebCore {
     class ChromeClientWx;
     class FrameLoaderClientWx;
+    class EditorClientWx;
     class Frame;
 }
 
@@ -63,6 +64,7 @@ class WXDLLIMPEXP_WEBKIT wxWebFrame
     // for the createWindow function. 
     friend class WebCore::ChromeClientWx;
     friend class WebCore::FrameLoaderClientWx;
+    friend class WebCore::EditorClientWx;
     friend class wxWebView;
 
     wxWebFrame(wxWebView* container, wxWebFrame* parent = NULL, WebViewFrameData* data = NULL);
@@ -86,6 +88,12 @@ class WXDLLIMPEXP_WEBKIT wxWebFrame
     void Copy();
     void Paste();
     
+    bool CanUndo();
+    bool CanRedo();
+    
+    void Undo();
+    void Redo();
+    
     wxString GetPageSource();
     void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
     
@@ -112,7 +120,7 @@ private:
     bool m_isEditable;
     bool m_isInitialized;
     bool m_beingDestroyed;
-    WebViewPrivate* m_impl;
+    WebFramePrivate* m_impl;
     wxString m_title;
     
 };
diff --git a/WebKit/wx/WebFramePrivate.h b/WebKit/wx/WebFramePrivate.h
new file mode 100644 (file)
index 0000000..7af70a8
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 Kevin Ollivier.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef WXWEBFRAMEPRIVATE_H
+#define WXWEBFRAMEPRIVATE_H
+
+#include "config.h"
+#include "EditCommand.h"
+#include "EditCommandWx.h"
+#include "Frame.h"
+#include "wtf/RefPtr.h"
+#include "wtf/Vector.h"
+
+class WebFramePrivate {
+
+public:
+    WebFramePrivate() :
+            frame(0)
+    {}
+
+    WTF::Vector<EditCommandWx> undoStack;
+    WTF::Vector<EditCommandWx> redoStack;
+    
+    WTF::RefPtr<WebCore::Frame> frame;
+};
+
+#endif
index 3d119a583f8a304ccfeaea8c57a3c62688c793a5..5bfc6e9790b39c43d05b9b6529f95206236fb66b 100644 (file)
@@ -122,7 +122,7 @@ Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest& request, cons
 
         WebViewPrivate* impl = newFrame->webview->m_impl;
         if (impl)
-            myPage = impl->frame->page();
+            myPage = impl->page;
     }
     
     return myPage;
diff --git a/WebKit/wx/WebKitSupport/EditCommandWx.h b/WebKit/wx/WebKitSupport/EditCommandWx.h
new file mode 100644 (file)
index 0000000..e5deedd
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Kevin Ollivier.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef WXEDITCOMMAND_H
+#define WXEDITCOMMAND_H
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+    class EditCommand;
+}
+
+class EditCommandWx 
+{
+public:
+    EditCommandWx(WTF::PassRefPtr<WebCore::EditCommand> command) 
+    {
+        m_editCommand = command;
+    }
+    
+    ~EditCommandWx() {}
+    WTF::PassRefPtr<WebCore::EditCommand> editCommand() { return m_editCommand; }
+    
+private:
+    WTF::RefPtr<WebCore::EditCommand> m_editCommand;
+};
+
+#endif
index ade0f414e26fe269da3eb23a101e2642a5cbee4d..c71133eaf329e51ffba33b80652c32321b8940bc 100644 (file)
 #include "PlatformKeyboardEvent.h"
 #include "PlatformString.h"
 #include "SelectionController.h"
+
+#include "WebFrame.h"
+#include "WebFramePrivate.h"
 #include "WebView.h"
+#include "WebViewPrivate.h"
 
 #include <stdio.h>
 
@@ -195,14 +199,28 @@ void EditorClientWx::didSetSelectionTypesForPasteboard()
     notImplemented();
 }
 
-void EditorClientWx::registerCommandForUndo(PassRefPtr<EditCommand>)
+void EditorClientWx::registerCommandForUndo(PassRefPtr<EditCommand> command)
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin) {
+            webKitWin->GetMainFrame()->m_impl->undoStack.append(EditCommandWx(command));
+        }
+    }
 }
 
-void EditorClientWx::registerCommandForRedo(PassRefPtr<EditCommand>)
+void EditorClientWx::registerCommandForRedo(PassRefPtr<EditCommand> command)
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin) {
+            webKitWin->GetMainFrame()->m_impl->redoStack.insert(0, EditCommandWx(command));
+        }
+    }
 }
 
 void EditorClientWx::clearUndoRedoOperations()
@@ -212,24 +230,54 @@ void EditorClientWx::clearUndoRedoOperations()
 
 bool EditorClientWx::canUndo() const
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin && webKitWin->GetMainFrame()) {
+            return webKitWin->GetMainFrame()->m_impl->undoStack.size() != 0;
+        }
+    }
     return false;
 }
 
 bool EditorClientWx::canRedo() const
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin && webKitWin->GetMainFrame()) {
+            return webKitWin->GetMainFrame()->m_impl->redoStack.size() != 0;
+        }
+    }
     return false;
 }
 
 void EditorClientWx::undo()
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin && webKitWin->GetMainFrame()) {
+            webKitWin->GetMainFrame()->m_impl->undoStack.last().editCommand()->unapply();
+            webKitWin->GetMainFrame()->m_impl->undoStack.removeLast();
+        }
+    }
 }
 
 void EditorClientWx::redo()
 {
-    notImplemented();
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+
+    if (frame) {
+        wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
+        if (webKitWin && webKitWin->GetMainFrame()) {
+            webKitWin->GetMainFrame()->m_impl->redoStack.first().editCommand()->reapply();
+            webKitWin->GetMainFrame()->m_impl->redoStack.remove(0);
+        }
+    }
 }
 
 void EditorClientWx::handleInputMethodKeydown(KeyboardEvent* event)
index 51b820c611a94f066a820ee1cafff61089ac66f1..d0207f5f5456cc1cff135b28854ce697c43de832 100644 (file)
 #include "EditorClient.h"
 #include "Page.h"
 
+#include "WebView.h"
+#include "WebFrame.h"
+
 namespace WebCore {
 
 class EditorClientWx : public EditorClient {
+friend class ::wxWebView;
+friend class ::wxWebFrame;
+
 public:
     virtual ~EditorClientWx();
     void setPage(Page*);
index 6704cd6e84d6d7626ffb595fec87f2f8ba27e183..40d28871ad3e47adbf88a74d38ca5218ebe95577 100644 (file)
@@ -498,11 +498,11 @@ void wxWebView::OnMouseEvents(wxMouseEvent& event)
     
     WebCore::PlatformMouseEvent wkEvent(event, globalPoint);
 
-    if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN)
+    if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN || 
+                type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK)
         frame->eventHandler()->handleMousePressEvent(wkEvent);
     
-    else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP || 
-                type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK)
+    else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP)
         frame->eventHandler()->handleMouseReleaseEvent(wkEvent);
 
     else if (type == wxEVT_MOTION)
@@ -562,13 +562,24 @@ void wxWebView::OnKeyEvents(wxKeyEvent& event)
         // WebCore doesn't handle these events itself, so we need to do
         // it and not send the event down or else CTRL+C will erase the text
         // and replace it with c.
-        if (event.CmdDown() && event.GetKeyCode() == static_cast<int>('C'))
-            Copy();
-        else if (event.CmdDown() && event.GetKeyCode() == static_cast<int>('X'))
-            Cut();
-        else if (event.CmdDown() && event.GetKeyCode() == static_cast<int>('V'))
-            Paste();
-        else {    
+        if (event.CmdDown() && event.GetEventType() == wxEVT_KEY_UP) {
+            if (event.GetKeyCode() == static_cast<int>('C'))
+                Copy();
+            else if (event.GetKeyCode() == static_cast<int>('X'))
+                Cut();
+            else if (event.GetKeyCode() == static_cast<int>('V'))
+                Paste();
+            else if (event.GetKeyCode() == static_cast<int>('Z')) {
+                if (event.ShiftDown()) {
+                    if (m_mainFrame->CanRedo())
+                        m_mainFrame->Redo();
+                }
+                else {
+                    if (m_mainFrame->CanUndo())
+                        m_mainFrame->Undo();
+                }
+            }
+        } else {    
             WebCore::PlatformKeyboardEvent wkEvent(event);
             if (wkEvent.type() == WebCore::PlatformKeyboardEvent::Char && wkEvent.altKey())
                 frame->eventHandler()->handleAccessKey(wkEvent);
index 2eef4990d1d6ca3a4891d2ce9d6295775f7a784a..9ad8a3ec90de71fb1a3add27b13b94ca3c279d00 100644 (file)
 #ifndef WXWEBVIEWPRIVATE_H
 #define WXWEBVIEWPRIVATE_H
 
-
 #include "config.h"
-#include "Frame.h"
-#include "FrameView.h"
+#include "HTMLFrameOwnerElement.h"
+#include "Page.h"
 #include "wtf/RefPtr.h"
 #include "KURL.h"
 
@@ -40,11 +39,9 @@ class WebViewPrivate
 {
 public:
     WebViewPrivate() :
-        frame(0),
         page(0)
     {}
     
-    WTF::RefPtr<WebCore::Frame> frame;
     WebCore::Page* page;
 };