Changeset 45080 in webkit


Ignore:
Timestamp:
Jun 24, 2009 7:02:16 AM (15 years ago)
Author:
zecke@webkit.org
Message:

2009-06-24 Jiahua Huang <jhuangjiahua@gmail.com>

Reviewed by Holger Freyther.

[Gtk] Add Undo/Redo support to WebKitGtk
https://bugs.webkit.org/show_bug.cgi?id=26573

Implement EditorClient::undo and other interested funcs.

  • WebCoreSupport/EditorClientGtk.cpp: (WebKit::EditorClient::registerCommandForUndo): (WebKit::EditorClient::registerCommandForRedo): (WebKit::EditorClient::clearUndoRedoOperations): (WebKit::EditorClient::canUndo): (WebKit::EditorClient::canRedo): (WebKit::EditorClient::undo): (WebKit::EditorClient::redo): (WebKit::EditorClient::EditorClient):
  • WebCoreSupport/EditorClientGtk.h:
Location:
trunk/WebKit/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r44904 r45080  
     12009-06-24  Jiahua Huang  <jhuangjiahua@gmail.com>
     2
     3        Reviewed by Holger Freyther.
     4
     5        [Gtk] Add Undo/Redo support to WebKitGtk
     6        https://bugs.webkit.org/show_bug.cgi?id=26573
     7
     8        Implement EditorClient::undo and other interested funcs.
     9
     10        * WebCoreSupport/EditorClientGtk.cpp:
     11        (WebKit::EditorClient::registerCommandForUndo):
     12        (WebKit::EditorClient::registerCommandForRedo):
     13        (WebKit::EditorClient::clearUndoRedoOperations):
     14        (WebKit::EditorClient::canUndo):
     15        (WebKit::EditorClient::canRedo):
     16        (WebKit::EditorClient::undo):
     17        (WebKit::EditorClient::redo):
     18        (WebKit::EditorClient::EditorClient):
     19        * WebCoreSupport/EditorClientGtk.h:
     20
    1212009-06-20  Jan Michael Alonzo  <jmalonzo@webkit.org>
    222
  • trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

    r43982 r45080  
    4040#include "webkitprivate.h"
    4141
     42// Arbitrary depth limit for the undo stack, to keep it from using
     43// unbounded memory.  This is the maximum number of distinct undoable
     44// actions -- unbroken stretches of typed characters are coalesced
     45// into a single action.
     46#define maximumUndoStackDepth 1000
     47
    4248using namespace WebCore;
    4349
     
    254260}
    255261
    256 void EditorClient::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>)
    257 {
    258     notImplemented();
    259 }
    260 
    261 void EditorClient::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
    262 {
    263     notImplemented();
     262void EditorClient::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> command)
     263{
     264    if (undoStack.size() == maximumUndoStackDepth)
     265        undoStack.removeFirst();
     266    if (!m_isInRedo)
     267        redoStack.clear();
     268    undoStack.append(command);
     269}
     270
     271void EditorClient::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand> command)
     272{
     273    redoStack.append(command);
    264274}
    265275
    266276void EditorClient::clearUndoRedoOperations()
    267277{
    268     notImplemented();
     278    undoStack.clear();
     279    redoStack.clear();
    269280}
    270281
    271282bool EditorClient::canUndo() const
    272283{
    273     notImplemented();
    274     return false;
     284    return !undoStack.isEmpty();
    275285}
    276286
    277287bool EditorClient::canRedo() const
    278288{
    279     notImplemented();
    280     return false;
     289    return !redoStack.isEmpty();
    281290}
    282291
    283292void EditorClient::undo()
    284293{
    285     notImplemented();
     294    if (canUndo()) {
     295        RefPtr<WebCore::EditCommand> command(*(--undoStack.end()));
     296        undoStack.remove(--undoStack.end());
     297        // unapply will call us back to push this command onto the redo stack.
     298        command->unapply();
     299    }
    286300}
    287301
    288302void EditorClient::redo()
    289303{
    290     notImplemented();
     304    if (canRedo()) {
     305        RefPtr<WebCore::EditCommand> command(*(--redoStack.end()));
     306        redoStack.remove(--redoStack.end());
     307
     308        ASSERT(!m_isInRedo);
     309        m_isInRedo = true;
     310        // reapply will call us back to push this command onto the undo stack.
     311        command->reapply();
     312        m_isInRedo = false;
     313    }
    291314}
    292315
     
    522545
    523546EditorClient::EditorClient(WebKitWebView* webView)
    524     : m_webView(webView)
     547    : m_isInRedo(false)
     548    , m_webView(webView)
    525549{
    526550    WebKitWebViewPrivate* priv = m_webView->priv;
  • trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.h

    r43982 r45080  
    3333#include "EditorClient.h"
    3434
     35#include <wtf/Deque.h>
    3536#include <wtf/Forward.h>
    3637
     
    4445
    4546    class EditorClient : public WebCore::EditorClient {
     47    protected:
     48        bool m_isInRedo;
     49
     50        WTF::Deque<WTF::RefPtr<WebCore::EditCommand> > undoStack;
     51        WTF::Deque<WTF::RefPtr<WebCore::EditCommand> > redoStack;
     52
    4653    public:
    4754        EditorClient(WebKitWebView*);
Note: See TracChangeset for help on using the changeset viewer.