InsertNodeBeforeCommand.cpp [plain text]
#include "config.h"
#include "InsertNodeBeforeCommand.h"
#include "AXObjectCache.h"
#include "Document.h"
#include "ExceptionCodePlaceholder.h"
#include "htmlediting.h"
namespace WebCore {
InsertNodeBeforeCommand::InsertNodeBeforeCommand(PassRefPtr<Node> insertChild, PassRefPtr<Node> refChild,
ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
: SimpleEditCommand(refChild->document())
, m_insertChild(insertChild)
, m_refChild(refChild)
, m_shouldAssumeContentIsAlwaysEditable(shouldAssumeContentIsAlwaysEditable)
{
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 || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)))
return;
ASSERT(parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable));
parent->insertBefore(m_insertChild.get(), m_refChild.get(), IGNORE_EXCEPTION, AttachLazily);
if (AXObjectCache* cache = document()->existingAXObjectCache())
cache->nodeTextChangeNotification(m_insertChild.get(), AXObjectCache::AXTextInserted, 0, m_insertChild->nodeValue());
}
void InsertNodeBeforeCommand::doUnapply()
{
if (!m_insertChild->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))
return;
if (AXObjectCache* cache = document()->existingAXObjectCache())
cache->nodeTextChangeNotification(m_insertChild.get(), AXObjectCache::AXTextDeleted, 0, m_insertChild->nodeValue());
m_insertChild->remove(IGNORE_EXCEPTION);
}
#ifndef NDEBUG
void InsertNodeBeforeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_insertChild.get(), nodes);
addNodeAndDescendants(m_refChild.get(), nodes);
}
#endif
}