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