InsertIntoTextNodeCommand.cpp [plain text]
#include "config.h"
#include "InsertIntoTextNodeCommand.h"
#include "Document.h"
#include "ExceptionCodePlaceholder.h"
#include "Frame.h"
#include "RenderText.h"
#include "Settings.h"
#include "Text.h"
#if PLATFORM(IOS)
#include "RenderText.h"
#endif
namespace WebCore {
InsertIntoTextNodeCommand::InsertIntoTextNodeCommand(RefPtr<Text>&& node, unsigned offset, const String& text, EditAction editingAction)
: SimpleEditCommand(node->document(), editingAction)
, 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()
{
bool passwordEchoEnabled = frame().settings().passwordEchoEnabled();
if (passwordEchoEnabled)
document().updateLayoutIgnorePendingStylesheets();
if (!m_node->hasEditableStyle())
return;
if (passwordEchoEnabled) {
if (RenderText* renderText = m_node->renderer())
renderText->momentarilyRevealLastTypedCharacter(m_offset + m_text.length());
}
m_node->insertData(m_offset, m_text, IGNORE_EXCEPTION);
}
#if PLATFORM(IOS)
void InsertIntoTextNodeCommand::doReapply()
{
ExceptionCode ec;
m_node->insertData(m_offset, m_text, ec);
}
#endif
void InsertIntoTextNodeCommand::doUnapply()
{
if (!m_node->hasEditableStyle())
return;
m_node->deleteData(m_offset, m_text.length(), IGNORE_EXCEPTION);
}
#ifndef NDEBUG
void InsertIntoTextNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_node.get(), nodes);
}
#endif
}