InsertNodeBeforeCommand.cpp [plain text]
#include "config.h"
#include "InsertNodeBeforeCommand.h"
#include "Document.h"
#include "ExceptionCodePlaceholder.h"
#include "RenderElement.h"
#include "Text.h"
#include "htmlediting.h"
namespace WebCore {
InsertNodeBeforeCommand::InsertNodeBeforeCommand(RefPtr<Node>&& insertChild, RefPtr<Node>&& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable, EditAction editingAction)
: SimpleEditCommand(refChild->document(), editingAction)
, m_insertChild(insertChild)
, m_refChild(refChild)
, m_shouldAssumeContentIsAlwaysEditable(shouldAssumeContentIsAlwaysEditable)
{
ASSERT(m_insertChild);
ASSERT(!m_insertChild->parentNode());
ASSERT(m_refChild);
ASSERT(m_refChild->parentNode());
ASSERT(m_refChild->parentNode()->hasEditableStyle() || !m_refChild->parentNode()->renderer());
}
void InsertNodeBeforeCommand::doApply()
{
ContainerNode* parent = m_refChild->parentNode();
if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !isEditableNode(*parent)))
return;
ASSERT(isEditableNode(*parent));
parent->insertBefore(*m_insertChild, m_refChild.get(), IGNORE_EXCEPTION);
}
void InsertNodeBeforeCommand::doUnapply()
{
if (!isEditableNode(*m_insertChild))
return;
m_insertChild->remove(IGNORE_EXCEPTION);
}
#ifndef NDEBUG
void InsertNodeBeforeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_insertChild.get(), nodes);
addNodeAndDescendants(m_refChild.get(), nodes);
}
#endif
}