Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1005)

Unified Diff: third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp

Issue 2691433002: Make Blink support multiline text insertion (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/TypingCommand.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp b/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp
index 89d68d2f22af91432529b53d4ce0e8e19ab4bfea..a10d26b007760988e2786384398d95259ce6788f 100644
--- a/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp
@@ -89,10 +89,10 @@ PlainTextRange getSelectionOffsets(LocalFrame* frame) {
return PlainTextRange::create(*editable, range);
}
-VisibleSelection createSelection(const size_t start,
- const size_t end,
- const bool isDirectional,
- Element* element) {
+SelectionInDOMTree createSelection(const size_t start,
+ const size_t end,
+ const bool isDirectional,
+ Element* element) {
const EphemeralRange& startRange =
PlainTextRange(0, static_cast<int>(start)).createRange(*element);
DCHECK(startRange.isNotNull());
@@ -103,11 +103,11 @@ VisibleSelection createSelection(const size_t start,
DCHECK(endRange.isNotNull());
const Position& endPosition = endRange.endPosition();
- const VisibleSelection& selection =
- createVisibleSelection(SelectionInDOMTree::Builder()
- .setBaseAndExtent(startPosition, endPosition)
- .setIsDirectional(isDirectional)
- .build());
+ const SelectionInDOMTree& selection =
+ SelectionInDOMTree::Builder()
+ .setBaseAndExtent(startPosition, endPosition)
+ .setIsDirectional(isDirectional)
+ .build();
return selection;
}
@@ -255,10 +255,11 @@ void TypingCommand::insertText(Document& document,
}
void TypingCommand::adjustSelectionAfterIncrementalInsertion(
- TypingCommand* command,
LocalFrame* frame,
- const size_t start,
- const size_t end) {
+ const size_t textLength) {
+ if (!isIncrementalInsertion())
+ return;
+
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. see http://crbug.com/590369 for more details.
frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
@@ -266,13 +267,17 @@ void TypingCommand::adjustSelectionAfterIncrementalInsertion(
Element* element = frame->selection().selection().rootEditableElement();
DCHECK(element);
- const VisibleSelection& selection = createSelection(
- start, end, command->endingSelection().isDirectional(), element);
+ const size_t end = m_selectionStart + textLength;
+ const size_t start =
+ compositionType() == TextCompositionUpdate ? m_selectionStart : end;
+ const SelectionInDOMTree& selection =
+ createSelection(start, end, endingSelection().isDirectional(), element);
- if (selection != frame->selection().selection()) {
- command->setEndingVisibleSelection(selection);
- frame->selection().setSelection(selection);
- }
+ if (selection == frame->selection().selection().asSelection())
+ return;
+
+ setEndingSelection(selection);
+ frame->selection().setSelection(selection);
}
// FIXME: We shouldn't need to take selectionForInsertion. It should be
@@ -307,6 +312,9 @@ void TypingCommand::insertText(Document& document,
document.updateStyleAndLayoutIgnorePendingStylesheets();
const PlainTextRange selectionOffsets = getSelectionOffsets(frame);
+ if (selectionOffsets.isNull())
+ return;
+ const size_t selectionStart = selectionOffsets.start();
// Set the starting and ending selection appropriately if we are using a
// selection that is different from the current selection. In the future, we
@@ -326,20 +334,9 @@ void TypingCommand::insertText(Document& document,
PreventSpellChecking);
EditingState editingState;
lastTypingCommand->m_isIncrementalInsertion = isIncrementalInsertion;
+ lastTypingCommand->m_selectionStart = selectionStart;
lastTypingCommand->insertText(newText, options & SelectInsertedText,
&editingState);
-
- if (editingState.isAborted())
- return;
-
- if (isIncrementalInsertion) {
- const size_t newEnd = selectionOffsets.start() + newText.length();
- const size_t newStart = (compositionType == TextCompositionUpdate)
- ? selectionOffsets.start()
- : newEnd;
- adjustSelectionAfterIncrementalInsertion(lastTypingCommand, frame,
- newStart, newEnd);
- }
return;
}
@@ -351,23 +348,12 @@ void TypingCommand::insertText(Document& document,
command->setEndingVisibleSelection(selectionForInsertion);
}
command->m_isIncrementalInsertion = isIncrementalInsertion;
- const bool aborted = !(command->apply());
+ command->m_selectionStart = selectionStart;
+ command->apply();
if (changeSelection) {
command->setEndingVisibleSelection(currentSelection);
frame->selection().setSelection(currentSelection);
- return;
- }
-
- if (aborted)
- return;
-
- if (isIncrementalInsertion) {
- const size_t newEnd = selectionOffsets.start() + newText.length();
- const size_t newStart = (compositionType == TextCompositionUpdate)
- ? selectionOffsets.start()
- : newEnd;
- adjustSelectionAfterIncrementalInsertion(command, frame, newStart, newEnd);
}
}
@@ -509,6 +495,8 @@ void TypingCommand::typingAddedToOpenCommand(
void TypingCommand::insertText(const String& text,
bool selectInsertedText,
EditingState* editingState) {
+ m_textToInsert = text;
+
if (text.isEmpty()) {
insertTextRunWithoutNewlines(text, selectInsertedText, editingState);
return;
@@ -524,11 +512,14 @@ void TypingCommand::insertText(const String& text,
size_t newline;
while ((newline = text.find('\n', offset)) != kNotFound) {
if (newline > offset) {
- const bool notSelectInsertedText = false;
- insertTextRunWithoutNewlines(text.substring(offset, newline - offset),
- notSelectInsertedText, editingState);
+ const size_t insertionLength = newline - offset;
+ insertTextRunWithoutNewlines(text.substring(offset, insertionLength),
+ false, editingState);
if (editingState->isAborted())
return;
+
+ adjustSelectionAfterIncrementalInsertion(document().frame(),
+ insertionLength);
}
insertParagraphSeparator(editingState);
@@ -540,12 +531,22 @@ void TypingCommand::insertText(const String& text,
if (!offset) {
insertTextRunWithoutNewlines(text, selectInsertedText, editingState);
+ if (editingState->isAborted())
+ return;
+
+ adjustSelectionAfterIncrementalInsertion(document().frame(), text.length());
return;
}
if (text.length() > offset) {
- insertTextRunWithoutNewlines(text.substring(offset, text.length() - offset),
+ const size_t insertionLength = text.length() - offset;
+ insertTextRunWithoutNewlines(text.substring(offset, insertionLength),
selectInsertedText, editingState);
+ if (editingState->isAborted())
+ return;
+
+ adjustSelectionAfterIncrementalInsertion(document().frame(),
+ insertionLength);
}
}
@@ -572,7 +573,6 @@ void TypingCommand::insertTextRunWithoutNewlines(const String& text,
if (editingState->isAborted())
return;
- m_textToInsert = text;
typingAddedToOpenCommand(InsertText);
}
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/TypingCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698