InsertNodeBeforeCommand.cpp [plain text]
#include "config.h"
#include "InsertNodeBeforeCommand.h"
#include "AXObjectCache.h"
#include "Document.h"
#include "htmlediting.h"
namespace WebCore {
InsertNodeBeforeCommand::InsertNodeBeforeCommand(PassRefPtr<Node> insertChild, PassRefPtr<Node> refChild)
: SimpleEditCommand(refChild->document())
, m_insertChild(insertChild)
, m_refChild(refChild)
{
ASSERT(m_insertChild);
ASSERT(!m_insertChild->parentNode());
ASSERT(m_refChild);
ASSERT(m_refChild->parentNode());
ASSERT(m_refChild->parentNode()->rendererIsEditable() || !m_refChild->parentNode()->attached());
}
void InsertNodeBeforeCommand::doApply()
{
ContainerNode* parent = m_refChild->parentNode();
if (!parent || !parent->rendererIsEditable())
return;
ExceptionCode ec;
parent->insertBefore(m_insertChild.get(), m_refChild.get(), ec);
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->nodeTextChangeNotification(m_insertChild->renderer(), AXObjectCache::AXTextInserted, 0, m_insertChild->nodeValue());
}
void InsertNodeBeforeCommand::doUnapply()
{
if (!m_insertChild->rendererIsEditable())
return;
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->nodeTextChangeNotification(m_insertChild->renderer(), AXObjectCache::AXTextDeleted, 0, m_insertChild->nodeValue());
ExceptionCode ec;
m_insertChild->remove(ec);
}
#ifndef NDEBUG
void InsertNodeBeforeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_insertChild.get(), nodes);
addNodeAndDescendants(m_refChild.get(), nodes);
}
#endif
}