This source file includes following definitions.
- m_offset
- doApply
- doUnapply
- doReapply
- insertText1AndTrimText2
#include "config.h"
#include "core/editing/SplitTextNodeCommand.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/Document.h"
#include "core/dom/DocumentMarkerController.h"
#include "core/dom/Text.h"
#include "wtf/Assertions.h"
namespace WebCore {
SplitTextNodeCommand::SplitTextNodeCommand(PassRefPtr<Text> text, int offset)
: SimpleEditCommand(text->document())
, m_text2(text)
, m_offset(offset)
{
ASSERT(m_text2);
ASSERT(m_text2->length() > 0);
ASSERT(m_offset > 0);
ASSERT(m_offset < m_text2->length());
}
void SplitTextNodeCommand::doApply()
{
ContainerNode* parent = m_text2->parentNode();
if (!parent || !parent->rendererIsEditable())
return;
String prefixText = m_text2->substringData(0, m_offset, IGNORE_EXCEPTION);
if (prefixText.isEmpty())
return;
m_text1 = Text::create(document(), prefixText);
ASSERT(m_text1);
document().markers().copyMarkers(m_text2.get(), 0, m_offset, m_text1.get(), 0);
insertText1AndTrimText2();
}
void SplitTextNodeCommand::doUnapply()
{
if (!m_text1 || !m_text1->rendererIsEditable())
return;
ASSERT(m_text1->document() == document());
String prefixText = m_text1->data();
m_text2->insertData(0, prefixText, ASSERT_NO_EXCEPTION, CharacterData::DeprecatedRecalcStyleImmediatlelyForEditing);
document().markers().copyMarkers(m_text1.get(), 0, prefixText.length(), m_text2.get(), 0);
m_text1->remove(ASSERT_NO_EXCEPTION);
}
void SplitTextNodeCommand::doReapply()
{
if (!m_text1 || !m_text2)
return;
ContainerNode* parent = m_text2->parentNode();
if (!parent || !parent->rendererIsEditable())
return;
insertText1AndTrimText2();
}
void SplitTextNodeCommand::insertText1AndTrimText2()
{
TrackExceptionState exceptionState;
m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(), exceptionState);
if (exceptionState.hadException())
return;
m_text2->deleteData(0, m_offset, exceptionState, CharacterData::DeprecatedRecalcStyleImmediatlelyForEditing);
}
}