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 c7c0ecd59787bc4b6e651bf237664260cad014a9..3a1add57f789151036cbfa15fc1b5a7c750d5525 100644 |
--- a/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
+++ b/third_party/WebKit/Source/core/editing/commands/TypingCommand.cpp |
@@ -155,6 +155,24 @@ InputEvent::InputType inputTypeForTypingCommand( |
} |
} |
+RangeVector* targetRangesFromCurrentSelectionOrExtendCaret( |
+ const LocalFrame& frame, |
+ SelectionDirection direction, |
+ TextGranularity granularity) { |
+ frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
+ SelectionModifier selectionModifier(frame, frame.selection().selection()); |
+ if (selectionModifier.selection().isCaret()) { |
+ selectionModifier.modify(FrameSelection::AlterationExtend, direction, |
+ granularity); |
+ } |
+ RangeVector* ranges = new RangeVector; |
+ // We only supports single selections. |
+ if (selectionModifier.selection().isNone()) |
+ return ranges; |
+ ranges->append(firstRangeOf(selectionModifier.selection())); |
+ return ranges; |
+} |
+ |
} // anonymous namespace |
using namespace HTMLNames; |
@@ -269,12 +287,6 @@ void TypingCommand::forwardDeleteKeyPressed(Document& document, |
->apply(source); |
} |
-String TypingCommand::textDataForInputEvent() const { |
- if (m_inputType == InputEvent::InputType::InsertText) |
- return m_textToInsert; |
- return CompositeEditCommand::textDataForInputEvent(); |
-} |
- |
void TypingCommand::updateSelectionIfDifferentFromCurrentSelection( |
TypingCommand* typingCommand, |
LocalFrame* frame) { |
@@ -534,12 +546,54 @@ InputEvent::InputType TypingCommand::inputType() const { |
return m_inputType; |
} |
+String TypingCommand::textDataForInputEvent() const { |
+ if (m_inputType == InputEvent::InputType::InsertText) |
+ return m_textToInsert; |
+ return CompositeEditCommand::textDataForInputEvent(); |
+} |
+ |
+RangeVector* TypingCommand::targetRangesForInputEvent() const { |
+ LocalFrame* frame = document().frame(); |
+ DCHECK(frame); |
+ |
+ using InputType = InputEvent::InputType; |
+ |
+ switch (m_inputType) { |
+ case InputType::DeleteContentBackward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionBackward, CharacterGranularity); |
+ case InputType::DeleteContentForward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionForward, CharacterGranularity); |
+ case InputType::DeleteWordBackward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionBackward, WordGranularity); |
+ case InputType::DeleteWordForward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionForward, WordGranularity); |
+ case InputType::DeleteLineBackward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionBackward, LineGranularity); |
+ case InputType::DeleteLineForward: |
+ return targetRangesFromCurrentSelectionOrExtendCaret( |
+ *frame, DirectionForward, LineGranularity); |
+ default: |
+ return CompositeEditCommand::targetRangesForInputEvent(); |
+ } |
+} |
+ |
bool TypingCommand::willAddTypingToOpenCommand(EditCommandSource source, |
InputEvent::InputType inputType, |
const String& text) { |
m_inputType = inputType; |
m_textToInsert = text; |
- return willApplyEditing(source); |
+ |
+ bool result = willApplyEditing(source); |
+ |
+ // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
+ // needs to be audited. See http://crbug.com/590369 for more details. |
+ document().updateStyleAndLayoutIgnorePendingStylesheets(); |
+ return result; |
} |
void TypingCommand::typingAddedToOpenCommand( |