AppendNodeCommand.cpp [plain text]
#include "config.h"
#include "AppendNodeCommand.h"
#include "AXObjectCache.h"
#include "Document.h"
#include "ExceptionCodePlaceholder.h"
#include "RenderElement.h"
#include "htmlediting.h"
namespace WebCore {
AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node)
: SimpleEditCommand(parent->document())
, m_parent(parent)
, m_node(node)
{
ASSERT(m_parent);
ASSERT(m_node);
ASSERT(!m_node->parentNode());
ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer());
}
static void sendAXTextChangedIgnoringLineBreaks(Node* node, AXObjectCache::AXTextChange textChange)
{
String nodeValue = node->nodeValue();
if (nodeValue == "\n")
return;
if (AXObjectCache* cache = node->document().existingAXObjectCache())
cache->nodeTextChangeNotification(node, textChange, 0, nodeValue);
}
void AppendNodeCommand::doApply()
{
if (!m_parent->hasEditableStyle() && m_parent->renderer())
return;
m_parent->appendChild(m_node.get(), IGNORE_EXCEPTION);
if (AXObjectCache::accessibilityEnabled())
sendAXTextChangedIgnoringLineBreaks(m_node.get(), AXObjectCache::AXTextInserted);
}
void AppendNodeCommand::doUnapply()
{
if (!m_parent->hasEditableStyle())
return;
if (AXObjectCache::accessibilityEnabled())
sendAXTextChangedIgnoringLineBreaks(m_node.get(), AXObjectCache::AXTextDeleted);
m_node->remove(IGNORE_EXCEPTION);
}
#ifndef NDEBUG
void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_parent.get(), nodes);
addNodeAndDescendants(m_node.get(), nodes);
}
#endif
}