InsertNodeBeforeCommand.cpp [plain text]
#include "config.h"
#include "InsertNodeBeforeCommand.h"
#include "Document.h"
#include "Editing.h"
#include "RenderElement.h"
#include "Text.h"
namespace WebCore {
InsertNodeBeforeCommand::InsertNodeBeforeCommand(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable, EditAction editingAction)
: SimpleEditCommand(refChild.document(), editingAction)
, m_insertChild(WTFMove(insertChild))
, m_refChild(refChild)
, m_shouldAssumeContentIsAlwaysEditable(shouldAssumeContentIsAlwaysEditable)
{
ASSERT(!m_insertChild->parentNode());
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.ptr());
}
void InsertNodeBeforeCommand::doUnapply()
{
if (!isEditableNode(m_insertChild))
return;
m_insertChild->remove();
}
#ifndef NDEBUG
void InsertNodeBeforeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_insertChild.ptr(), nodes);
addNodeAndDescendants(m_refChild.ptr(), nodes);
}
#endif
}