AppendNodeCommand.cpp [plain text]
#include "config.h"
#include "AppendNodeCommand.h"
#include "AXObjectCache.h"
#include "Document.h"
#include "ExceptionCodePlaceholder.h"
#include "RenderElement.h"
#include "Text.h"
#include "htmlediting.h"
namespace WebCore {
AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node, EditAction editingAction)
: SimpleEditCommand(parent->document(), editingAction)
, 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, AXTextEditType type)
{
if (!node)
return;
String text = node->nodeValue();
if (text == "\n")
return;
if (AXObjectCache* cache = node->document().existingAXObjectCache()) {
Position position = is<Text>(node) ? Position(downcast<Text>(node), 0) : createLegacyEditingPosition(node, 0);
cache->postTextStateChangeNotification(node, type, text, VisiblePosition(position));
}
}
void AppendNodeCommand::doApply()
{
if (!m_parent->hasEditableStyle() && m_parent->renderer())
return;
m_parent->appendChild(m_node.get(), IGNORE_EXCEPTION);
if (shouldPostAccessibilityNotification())
sendAXTextChangedIgnoringLineBreaks(m_node.get(), applyEditType());
}
void AppendNodeCommand::doUnapply()
{
if (!m_parent->hasEditableStyle())
return;
if (shouldPostAccessibilityNotification())
sendAXTextChangedIgnoringLineBreaks(m_node.get(), unapplyEditType());
m_node->remove(IGNORE_EXCEPTION);
}
#ifndef NDEBUG
void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_parent.get(), nodes);
addNodeAndDescendants(m_node.get(), nodes);
}
#endif
}