WrapContentsInDummySpanCommand.cpp [plain text]
#include "config.h"
#include "WrapContentsInDummySpanCommand.h"
#include "ApplyStyleCommand.h"
#include "ExceptionCodePlaceholder.h"
namespace WebCore {
WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand(Element& element)
: SimpleEditCommand(element.document())
, m_element(element)
{
}
void WrapContentsInDummySpanCommand::executeApply()
{
Vector<Ref<Node>> children;
for (Node* child = m_element->firstChild(); child; child = child->nextSibling())
children.append(*child);
for (auto& child : children)
m_dummySpan->appendChild(child, IGNORE_EXCEPTION);
m_element->appendChild(*m_dummySpan, IGNORE_EXCEPTION);
}
void WrapContentsInDummySpanCommand::doApply()
{
m_dummySpan = createStyleSpanElement(document());
executeApply();
}
void WrapContentsInDummySpanCommand::doUnapply()
{
if (!m_dummySpan || !m_element->hasEditableStyle())
return;
Vector<Ref<Node>> children;
for (Node* child = m_dummySpan->firstChild(); child; child = child->nextSibling())
children.append(*child);
for (auto& child : children)
m_element->appendChild(child, IGNORE_EXCEPTION);
m_dummySpan->remove(IGNORE_EXCEPTION);
}
void WrapContentsInDummySpanCommand::doReapply()
{
if (!m_dummySpan || !m_element->hasEditableStyle())
return;
executeApply();
}
#ifndef NDEBUG
void WrapContentsInDummySpanCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_element.ptr(), nodes);
addNodeAndDescendants(m_dummySpan.get(), nodes);
}
#endif
}