This source file includes following definitions.
- perform
- undo
- redo
- isUndoableStateMark
- toString
- isUndoableStateMark
- mergeId
- merge
- perform
- markUndoableState
- undo
- redo
- reset
#include "config.h"
#include "core/inspector/InspectorHistory.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/Node.h"
namespace WebCore {
namespace {
class UndoableStateMark FINAL : public InspectorHistory::Action {
public:
UndoableStateMark() : InspectorHistory::Action("[UndoableState]") { }
virtual bool perform(ExceptionState&) OVERRIDE { return true; }
virtual bool undo(ExceptionState&) OVERRIDE { return true; }
virtual bool redo(ExceptionState&) OVERRIDE { return true; }
virtual bool isUndoableStateMark() OVERRIDE { return true; }
};
}
InspectorHistory::Action::Action(const String& name) : m_name(name)
{
}
InspectorHistory::Action::~Action()
{
}
String InspectorHistory::Action::toString()
{
return m_name;
}
bool InspectorHistory::Action::isUndoableStateMark()
{
return false;
}
String InspectorHistory::Action::mergeId()
{
return "";
}
void InspectorHistory::Action::merge(PassRefPtr<Action>)
{
}
InspectorHistory::InspectorHistory() : m_afterLastActionIndex(0) { }
bool InspectorHistory::perform(PassRefPtr<Action> action, ExceptionState& exceptionState)
{
if (!action->perform(exceptionState))
return false;
if (!action->mergeId().isEmpty() && m_afterLastActionIndex > 0 && action->mergeId() == m_history[m_afterLastActionIndex - 1]->mergeId())
m_history[m_afterLastActionIndex - 1]->merge(action);
else {
m_history.resize(m_afterLastActionIndex);
m_history.append(action);
++m_afterLastActionIndex;
}
return true;
}
void InspectorHistory::markUndoableState()
{
perform(adoptRef(new UndoableStateMark()), IGNORE_EXCEPTION);
}
bool InspectorHistory::undo(ExceptionState& exceptionState)
{
while (m_afterLastActionIndex > 0 && m_history[m_afterLastActionIndex - 1]->isUndoableStateMark())
--m_afterLastActionIndex;
while (m_afterLastActionIndex > 0) {
Action* action = m_history[m_afterLastActionIndex - 1].get();
if (!action->undo(exceptionState)) {
reset();
return false;
}
--m_afterLastActionIndex;
if (action->isUndoableStateMark())
break;
}
return true;
}
bool InspectorHistory::redo(ExceptionState& exceptionState)
{
while (m_afterLastActionIndex < m_history.size() && m_history[m_afterLastActionIndex]->isUndoableStateMark())
++m_afterLastActionIndex;
while (m_afterLastActionIndex < m_history.size()) {
Action* action = m_history[m_afterLastActionIndex].get();
if (!action->redo(exceptionState)) {
reset();
return false;
}
++m_afterLastActionIndex;
if (action->isUndoableStateMark())
break;
}
return true;
}
void InspectorHistory::reset()
{
m_afterLastActionIndex = 0;
m_history.clear();
}
}