WebKitTools:
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Jan 2008 00:51:55 +0000 (00:51 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Jan 2008 00:51:55 +0000 (00:51 +0000)
        Reviewed by Ada Chan.

        Fix for <rdar://5131975> DumpRenderTree doesn't support undo/redo

        - Adds simplified UndoManager to windows DRT to allow testing the
          undo/redo code paths in WebCore and WebKit.  This is a temporary
          solution to an issue that should eventually be solved by having a
          shared UndoManager in WebKit.

        * DumpRenderTree/win/DumpRenderTree.cpp:
        (runTest):
        * DumpRenderTree/win/UIDelegate.cpp:
        (DRTUndoObject::DRTUndoObject):
        (DRTUndoObject::invoke):
        (DRTUndoStack::~DRTUndoStack):
        (DRTUndoStack::isEmpty):
        (DRTUndoStack::clear):
        (DRTUndoStack::push):
        (DRTUndoStack::pop):
        (DRTUndoManager::canRedo):
        (DRTUndoManager::canUndo):
        (DRTUndoManager::DRTUndoManager):
        (DRTUndoManager::removeAllActions):
        (DRTUndoManager::registerUndoWithTarget):
        (DRTUndoManager::redo):
        (DRTUndoManager::undo):
        (UIDelegate::UIDelegate):
        (UIDelegate::resetUndoManager):
        (UIDelegate::registerUndoWithTarget):
        (UIDelegate::removeAllActionsWithTarget):
        (UIDelegate::setActionTitle):
        (UIDelegate::undo):
        (UIDelegate::redo):
        (UIDelegate::canUndo):
        (UIDelegate::canRedo):
        * DumpRenderTree/win/UIDelegate.h:

LayoutTests:

        Reviewed by Ada Chan.

        <rdar://5131975> DumpRenderTree doesn't support undo/redo

        * platform/win/Skipped: With undo/redo support enabled, we can now
        remove the undo tests from the Skipped list.

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

LayoutTests/ChangeLog
LayoutTests/platform/win/Skipped
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/win/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/win/UIDelegate.cpp
WebKitTools/DumpRenderTree/win/UIDelegate.h

index 79ee070c4c62ae004b7a97035138674999679229..7b13a471b5d87d9d61bf85cc1b8d51bcffefb5f0 100644 (file)
@@ -1,3 +1,12 @@
+2008-01-24  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Ada Chan.
+
+        <rdar://5131975> DumpRenderTree doesn't support undo/redo
+
+        * platform/win/Skipped: With undo/redo support enabled, we can now
+        remove the undo tests from the Skipped list.
+
 2008-01-24  Adam Roben  <aroben@apple.com>
 
         Test for Bug 16996: Crash in createFontCustomPlatformData when loading
index 5861ec124213c451ce4bbc28e8c2a6ead184a70f..8d82c6c518eeabf7dafd089bb5e5a7fd68ee6cdd 100644 (file)
@@ -124,20 +124,6 @@ fast/text/international/bidi-fallback-font-weight.html
 fast/text/international/bidi-neutral-directionality-paragraph-start.html
 fast/text/international/thai-line-breaks.html
 
-# DRT doesn't support undo/redo <rdar://problem/5131975>
-editing/deleting/delete-and-undo.html
-editing/deleting/delete-by-word-002.html
-editing/undo/undo-misspellings.html
-editing/undo/undo-typing-001.html
-fast/forms/input-paste-undo.html
-fast/forms/plaintext-mode-1.html
-editing/undo/undo-combined-delete-boundary.html
-editing/undo/undo-combined-delete.html
-editing/undo/undo-delete-boundary.html
-editing/undo/undo-delete.html
-editing/undo/undo-forward-delete-boundary.html
-editing/undo/undo-forward-delete.html
-
 # ASSERT in ClipboardWin::setData <rdar://problem/5015941>
 editing/execCommand/copy-without-selection.html
 
index 77065737fb56e932a6e85497555f6191fc15fdc3..fa9bbc6839e6f1650407ee0775deb00afb4aac43 100644 (file)
@@ -1,3 +1,42 @@
+2008-01-24  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Ada Chan.
+
+        Fix for <rdar://5131975> DumpRenderTree doesn't support undo/redo
+
+        - Adds simplified UndoManager to windows DRT to allow testing the
+          undo/redo code paths in WebCore and WebKit.  This is a temporary
+          solution to an issue that should eventually be solved by having a
+          shared UndoManager in WebKit.
+
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (runTest):
+        * DumpRenderTree/win/UIDelegate.cpp:
+        (DRTUndoObject::DRTUndoObject):
+        (DRTUndoObject::invoke):
+        (DRTUndoStack::~DRTUndoStack):
+        (DRTUndoStack::isEmpty):
+        (DRTUndoStack::clear):
+        (DRTUndoStack::push):
+        (DRTUndoStack::pop):
+        (DRTUndoManager::canRedo):
+        (DRTUndoManager::canUndo):
+        (DRTUndoManager::DRTUndoManager):
+        (DRTUndoManager::removeAllActions):
+        (DRTUndoManager::registerUndoWithTarget):
+        (DRTUndoManager::redo):
+        (DRTUndoManager::undo):
+        (UIDelegate::UIDelegate):
+        (UIDelegate::resetUndoManager):
+        (UIDelegate::registerUndoWithTarget):
+        (UIDelegate::removeAllActionsWithTarget):
+        (UIDelegate::setActionTitle):
+        (UIDelegate::undo):
+        (UIDelegate::redo):
+        (UIDelegate::canUndo):
+        (UIDelegate::canRedo):
+        * DumpRenderTree/win/UIDelegate.h:
+
 2008-01-23  Adam Roben  <aroben@apple.com>
 
         Allow directories containing ChangeLogs to be passed to
index 3b06c5815602073e2b224db03cf8f7bb21c2c2ed..6ac6f8e4c9f61e64f484b61b72bc20219c5e9475 100644 (file)
@@ -687,6 +687,7 @@ static void runTest(const char* pathOrURL)
         history->setOptionalSharedHistory(0);
 
     resetWebViewToConsistentStateBeforeTesting();
+    sharedUIDelegate->resetUndoManager();
 
     prevTestBFItem = 0;
     COMPtr<IWebView> webView;
index 7e3e6f2cb320b96f3b0de5893000f7d67ee4e0c4..8766f23347f541149000948408ab94fe91daa148 100755 (executable)
@@ -35,6 +35,7 @@
 
 #include <WebCore/COMPtr.h>
 #include <wtf/Platform.h>
+#include <wtf/Vector.h>
 #include <JavaScriptCore/Assertions.h>
 #include <JavaScriptCore/JavaScriptCore.h>
 #include <WebKit/IWebFramePrivate.h>
 
 using std::wstring;
 
+class DRTUndoObject {
+public:
+    DRTUndoObject(IWebUndoTarget* target, BSTR actionName, IUnknown* obj)
+        : m_target(target)
+        , m_actionName(SysAllocString(actionName))
+        , m_obj(obj)
+    {
+    }
+
+    ~DRTUndoObject()
+    {
+        SysFreeString(m_actionName);
+    }
+
+    void invoke()
+    {
+        m_target->invoke(m_actionName, m_obj.get());
+    }
+
+private:
+    IWebUndoTarget* m_target;
+    BSTR m_actionName;
+    COMPtr<IUnknown> m_obj;
+};
+
+class DRTUndoStack {
+public:
+    ~DRTUndoStack() { deleteAllValues(m_undoVector); }
+
+    bool isEmpty() const { return m_undoVector.isEmpty(); }
+    void clear() { deleteAllValues(m_undoVector); m_undoVector.clear(); }
+
+    void push(DRTUndoObject* undoObject) { m_undoVector.append(undoObject); }
+    DRTUndoObject* pop() { DRTUndoObject* top = m_undoVector.last(); m_undoVector.removeLast(); return top; }
+
+private:
+    Vector<DRTUndoObject*> m_undoVector;
+};
+
+class DRTUndoManager {
+public:
+    DRTUndoManager();
+
+    void removeAllActions();
+    void registerUndoWithTarget(IWebUndoTarget* target, BSTR actionName, IUnknown* obj);
+    void redo();
+    void undo();
+    bool canRedo() { return !m_redoStack->isEmpty(); }
+    bool canUndo() { return !m_undoStack->isEmpty(); }
+
+private:
+    OwnPtr<DRTUndoStack> m_redoStack;
+    OwnPtr<DRTUndoStack> m_undoStack;
+    bool m_isRedoing;
+    bool m_isUndoing;
+};
+
+DRTUndoManager::DRTUndoManager()
+    : m_redoStack(new DRTUndoStack)
+    , m_undoStack(new DRTUndoStack)
+    , m_isRedoing(false)
+    , m_isUndoing(false)
+{
+}
+
+void DRTUndoManager::removeAllActions()
+{
+    m_redoStack->clear();
+    m_undoStack->clear();
+}
+
+void DRTUndoManager::registerUndoWithTarget(IWebUndoTarget* target, BSTR actionName, IUnknown* obj)
+{
+    if (!m_isUndoing && !m_isRedoing)
+        m_redoStack->clear();
+
+    DRTUndoStack* stack = m_isUndoing ? m_redoStack.get() : m_undoStack.get();
+    stack->push(new DRTUndoObject(target, actionName, obj));
+}
+
+void DRTUndoManager::redo()
+{
+    if (!canRedo())
+        return;
+
+    m_isRedoing = true;
+
+    DRTUndoObject* redoObject = m_redoStack->pop();
+    redoObject->invoke();
+    delete redoObject;
+
+    m_isRedoing = false;
+}
+
+void DRTUndoManager::undo()
+{
+    if (!canUndo())
+        return;
+
+    m_isUndoing = true;
+
+    DRTUndoObject* undoObject = m_undoStack->pop();
+    undoObject->invoke();
+    delete undoObject;
+
+    m_isUndoing = false;
+}
+
 UIDelegate::UIDelegate()
     : m_refCount(1)
+    , m_undoManager(new DRTUndoManager)
 {
     m_frame.bottom = 0;
     m_frame.top = 0;
@@ -52,6 +162,11 @@ UIDelegate::UIDelegate()
     m_frame.right = 0;
 }
 
+void UIDelegate::resetUndoManager()
+{
+    m_undoManager.set(new DRTUndoManager);
+}
+
 HRESULT STDMETHODCALLTYPE UIDelegate::QueryInterface(REFIID riid, void** ppvObject)
 {
     *ppvObject = 0;
@@ -99,6 +214,62 @@ HRESULT STDMETHODCALLTYPE UIDelegate::trackCustomPopupMenu(
     return S_OK;
 }
 
+HRESULT STDMETHODCALLTYPE UIDelegate::registerUndoWithTarget(
+        /* [in] */ IWebUndoTarget* target,
+        /* [in] */ BSTR actionName,
+        /* [in] */ IUnknown* actionArg)
+{
+    m_undoManager->registerUndoWithTarget(target, actionName, actionArg);
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::removeAllActionsWithTarget(
+        /* [in] */ IWebUndoTarget*)
+{
+    m_undoManager->removeAllActions();
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::setActionTitle(
+        /* [in] */ BSTR actionTitle)
+{
+    // It is not neccessary to implement this for DRT because there is
+    // menu to write out the title to.
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::undo()
+{
+    m_undoManager->undo();
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::redo()
+{
+    m_undoManager->redo();
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::canUndo(
+        /* [retval][out] */ BOOL* result)
+{
+    if (!result)
+        return E_POINTER;
+
+    *result = m_undoManager->canUndo();
+    return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE UIDelegate::canRedo(
+        /* [retval][out] */ BOOL* result)
+{
+    if (!result)
+        return E_POINTER;
+
+    *result = m_undoManager->canRedo();
+    return S_OK;
+}
+
 HRESULT STDMETHODCALLTYPE UIDelegate::setFrame( 
         /* [in] */ IWebView* /*sender*/,
         /* [in] */ RECT* frame)
index 240ba52b3f26b929f7d1586d38b25ead3d1dbcf7..e8e255d2a4a4921de7383c8730355d3e50e11a24 100755 (executable)
 
 #include <WebKit/IWebUIDelegate.h>
 #include <WebKit/IWebUIDelegatePrivate.h>
+#include <wtf/OwnPtr.h>
 #include <windef.h>
 
+class DRTUndoManager;
+
 class UIDelegate : public IWebUIDelegate, IWebUIDelegatePrivate {
 public:
     UIDelegate();
 
-    void processWork();
+    void resetUndoManager();
 
     // IUnknown
     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
@@ -227,23 +230,23 @@ public:
     virtual HRESULT STDMETHODCALLTYPE registerUndoWithTarget( 
         /* [in] */ IWebUndoTarget *target,
         /* [in] */ BSTR actionName,
-        /* [in] */ IUnknown *actionArg) { return E_NOTIMPL; }
+        /* [in] */ IUnknown *actionArg);
     
     virtual HRESULT STDMETHODCALLTYPE removeAllActionsWithTarget( 
-        /* [in] */ IWebUndoTarget *target) { return E_NOTIMPL; }
+        /* [in] */ IWebUndoTarget *target);
     
     virtual HRESULT STDMETHODCALLTYPE setActionTitle( 
-        /* [in] */ BSTR actionTitle) { return E_NOTIMPL; }
+        /* [in] */ BSTR actionTitle);
     
-    virtual HRESULT STDMETHODCALLTYPE undo( void) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE undo();
     
-    virtual HRESULT STDMETHODCALLTYPE redo( void) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE redo();
     
     virtual HRESULT STDMETHODCALLTYPE canUndo( 
-        /* [retval][out] */ BOOL *result) { return E_NOTIMPL; }
+        /* [retval][out] */ BOOL *result);
     
     virtual HRESULT STDMETHODCALLTYPE canRedo( 
-        /* [retval][out] */ BOOL *result) { return E_NOTIMPL; }
+        /* [retval][out] */ BOOL *result);
 
 protected:
     // IWebUIDelegatePrivate
@@ -295,6 +298,7 @@ protected:
 
 private:
     RECT m_frame;
+    OwnPtr<DRTUndoManager> m_undoManager;
 };
 
 #endif