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

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

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: xiaocheng's review 3: Rebase and remove updateStyleAndLayoutIgnorePendingStylesheets() Created 4 years 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
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 85fbcce80f3d152ca099a2db1a65105d949a1e3a..9cad8777f9a0e655f0ed413413773dbf343e4683 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;
@@ -285,12 +303,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) {
@@ -570,6 +582,42 @@ 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) {

Powered by Google App Engine
This is Rietveld 408576698