#include "htmlediting.h"
#include "visible_units.h"
+#if ENABLE(TIZEN_ISF_PORT)
+#include "CharacterData.h"
+#endif
+
namespace WebCore {
using namespace HTMLNames;
, m_openedByBackwardDelete(false)
, m_shouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator)
, m_shouldPreventSpellChecking(options & PreventSpellChecking)
+#if ENABLE(TIZEN_ISF_PORT)
+ , m_isInsertText(false)
+#endif
{
updatePreservesTypingStyle(m_commandType);
}
{
ASSERT(document);
if (granularity == CharacterGranularity) {
+#if ENABLE(TIZEN_ISF_PORT)
+ RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame());
+ if (lastTypingCommand && !lastTypingCommand->m_isInsertText) {
+#else
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame())) {
+#endif
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document->frame());
lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
lastTypingCommand->deleteKeyPressed(granularity, options & KillRing);
insertText(document, text, frame->selection()->selection(), options, composition);
}
+#if ENABLE(TIZEN_ISF_PORT)
+unsigned selectionCount(const VisibleSelection& selection)
+{
+ if (!selection.isRange())
+ return 0;
+
+ RefPtr<Range> range = selection.firstRange();
+ Node* startContainer = range->startContainer();
+ Node* endContainer = range->endContainer();
+ Node* pastLast = range->pastLastNode();
+ unsigned count = 0;
+
+ for (Node* node = range->firstNode(); node != pastLast; node = node->traverseNextNode()) {
+ if (node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE) {
+ int length = static_cast<CharacterData*>(node)->length();
+ int start = (node == startContainer) ? std::min(std::max(0, range->startOffset()), length) : 0;
+ int end = (node == endContainer) ? std::min(std::max(start, range->endOffset()), length) : length;
+ count += static_cast<unsigned>(end - start);
+ }
+ }
+
+ return count;
+}
+#endif
+
// FIXME: We shouldn't need to take selectionForInsertion. It should be identical to FrameSelection's current selection.
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
{
// Set the starting and ending selection appropriately if we are using a selection
// that is different from the current selection. In the future, we should change EditCommand
// to deal with custom selections in a general way that can be used by all of the commands.
+#if ENABLE(TIZEN_ISF_PORT)
+ RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame.get());
+ unsigned deleteCount = selectionCount(selectionForInsertion);
+ if (lastTypingCommand && (lastTypingCommand->m_isInsertText ? text.length() >= deleteCount : text.length() <= deleteCount)) {
+#else
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame.get())) {
+#endif
if (lastTypingCommand->endingSelection() != selectionForInsertion) {
lastTypingCommand->setStartingSelection(selectionForInsertion);
lastTypingCommand->setEndingSelection(selectionForInsertion);
RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
+#if ENABLE(TIZEN_ISF_PORT)
+ cmd->m_isInsertText = (text.length() >= deleteCount);
+#endif
}
void TypingCommand::insertLineBreak(Document *document, Options options)