InsertIntoTextNodeCommand.cpp [plain text]
#include "config.h"
#include "InsertIntoTextNodeCommand.h"
#include "AXObjectCache.h"
#include "Document.h"
#include "RenderText.h"
#include "Settings.h"
#include "Text.h"
#include "RenderText.h"
namespace WebCore {
InsertIntoTextNodeCommand::InsertIntoTextNodeCommand(PassRefPtr<Text> node, unsigned offset, const String& text)
: SimpleEditCommand(node->document())
, m_node(node)
, m_offset(offset)
, m_text(text)
{
ASSERT(m_node);
ASSERT(m_offset <= m_node->length());
ASSERT(!m_text.isEmpty());
}
void InsertIntoTextNodeCommand::doApply()
{
if (!m_node->rendererIsEditable())
return;
ExceptionCode ec;
m_node->insertData(m_offset, m_text, ec);
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->nodeTextChangeNotification(m_node->renderer(), AXObjectCache::AXTextInserted, m_offset, m_text);
}
void InsertIntoTextNodeCommand::doReapply()
{
ExceptionCode ec;
m_node->insertData(m_offset, m_text, ec, false);
}
void InsertIntoTextNodeCommand::doUnapply()
{
if (!m_node->rendererIsEditable())
return;
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->nodeTextChangeNotification(m_node->renderer(), AXObjectCache::AXTextDeleted, m_offset, m_text);
ExceptionCode ec;
m_node->deleteData(m_offset, m_text.length(), ec);
}
#ifndef NDEBUG
void InsertIntoTextNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_node.get(), nodes);
}
#endif
}