This source file includes following definitions.
- m_elementToReplace
- swapInNodePreservingAttributesAndChildren
- doApply
- doUnapply
#include "config.h"
#include "core/editing/ReplaceNodeWithSpanCommand.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/editing/htmlediting.h"
#include "core/html/HTMLElement.h"
#include "wtf/Assertions.h"
namespace WebCore {
using namespace HTMLNames;
ReplaceNodeWithSpanCommand::ReplaceNodeWithSpanCommand(PassRefPtr<HTMLElement> element)
: SimpleEditCommand(element->document())
, m_elementToReplace(element)
{
ASSERT(m_elementToReplace);
}
static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTMLElement& nodeToReplace)
{
ASSERT(nodeToReplace.inDocument());
RefPtr<ContainerNode> parentNode = nodeToReplace.parentNode();
parentNode->insertBefore(newNode, &nodeToReplace);
NodeVector children;
getChildNodes(nodeToReplace, children);
for (size_t i = 0; i < children.size(); ++i)
newNode->appendChild(children[i]);
newNode->cloneDataFromElement(nodeToReplace);
parentNode->removeChild(&nodeToReplace, ASSERT_NO_EXCEPTION);
}
void ReplaceNodeWithSpanCommand::doApply()
{
if (!m_elementToReplace->inDocument())
return;
if (!m_spanElement)
m_spanElement = createHTMLElement(m_elementToReplace->document(), spanTag);
swapInNodePreservingAttributesAndChildren(m_spanElement.get(), *m_elementToReplace);
}
void ReplaceNodeWithSpanCommand::doUnapply()
{
if (!m_spanElement->inDocument())
return;
swapInNodePreservingAttributesAndChildren(m_elementToReplace.get(), *m_spanElement);
}
}