This source file includes following definitions.
- create
- registerUndoStep
- registerRedoStep
- didUnloadFrame
- filterOutUndoSteps
- canUndo
- canRedo
- undo
- redo
#include "config.h"
#include "UndoStack.h"
#include "core/dom/ContainerNode.h"
#include "core/editing/UndoStep.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
static const size_t maximumUndoStackDepth = 1000;
UndoStack::UndoStack()
: m_inRedo(false)
{
}
UndoStack::~UndoStack()
{
}
PassOwnPtr<UndoStack> UndoStack::create()
{
return adoptPtr(new UndoStack());
}
void UndoStack::registerUndoStep(PassRefPtr<UndoStep> step)
{
if (m_undoStack.size() == maximumUndoStackDepth)
m_undoStack.removeFirst();
if (!m_inRedo)
m_redoStack.clear();
m_undoStack.append(step);
}
void UndoStack::registerRedoStep(PassRefPtr<UndoStep> step)
{
m_redoStack.append(step);
}
void UndoStack::didUnloadFrame(const LocalFrame& frame)
{
NoEventDispatchAssertion assertNoEventDispatch;
filterOutUndoSteps(m_undoStack, frame);
filterOutUndoSteps(m_redoStack, frame);
}
void UndoStack::filterOutUndoSteps(UndoStepStack& stack, const LocalFrame& frame)
{
UndoStepStack newStack;
while (!stack.isEmpty()) {
UndoStep* step = stack.first().get();
if (!step->belongsTo(frame))
newStack.append(step);
stack.removeFirst();
}
stack.swap(newStack);
}
bool UndoStack::canUndo() const
{
return !m_undoStack.isEmpty();
}
bool UndoStack::canRedo() const
{
return !m_redoStack.isEmpty();
}
void UndoStack::undo()
{
if (canUndo()) {
UndoStepStack::iterator back = --m_undoStack.end();
RefPtr<UndoStep> step(*back);
m_undoStack.remove(back);
step->unapply();
}
}
void UndoStack::redo()
{
if (canRedo()) {
UndoStepStack::iterator back = --m_redoStack.end();
RefPtr<UndoStep> step(*back);
m_redoStack.remove(back);
ASSERT(!m_inRedo);
TemporaryChange<bool> redoScope(m_inRedo, true);
step->reapply();
}
}
}