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

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

Issue 1965543002: [InputEvent] Support |sequence<Range> getRanges()| in 'beforeinput' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dtapuska's review Created 4 years, 7 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
Index: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
index b71feb92c5b60592b4d1e5bfc5213c18b86823e2..4ce85d102cfbabede9f4065970fafa7446dd0cae 100644
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
@@ -131,6 +131,19 @@ InputEvent::InputType InputTypeFromCommandType(WebEditingCommandType commandType
}
}
+HeapRanges* RangesFromCurrentSelectionOrExtendCaret(const VisibleSelection& currentSelection, SelectionDirection direction, TextGranularity granularity)
+{
+ FrameSelection* selection = FrameSelection::create();
+ selection->setSelection(currentSelection);
+ if (selection->isCaret())
+ selection->modify(FrameSelection::AlterationExtend, direction, granularity);
yosin_UTC9 2016/05/13 05:26:12 Please use functions in VisbileUnits.h, rather tha
yosin_UTC9 2016/05/13 05:42:33 Correction. Could you move |SelectionEdtior::modif
chongz 2016/05/19 04:41:48 Switched to |SelectionModifier|.
+ HeapRanges* ranges = new HeapRanges;
+ // We only supports single selections.
+ if (!selection->isNone())
+ ranges->append(selection->firstRange());
+ return ranges;
+}
+
} // anonymous namespace
class EditorInternalCommand {
@@ -1782,7 +1795,7 @@ bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) c
if (m_source == CommandFromMenuOrKeyBinding) {
InputEvent::InputType inputType = InputTypeFromCommandType(m_command->commandType);
if (inputType != InputEvent::InputType::None) {
- if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_frame->document()), inputType) != DispatchEventResult::NotCanceled)
+ if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_frame->document()), inputType, emptyString(), getRanges()) != DispatchEventResult::NotCanceled)
return true;
}
}
@@ -1849,4 +1862,32 @@ int Editor::Command::idForHistogram() const
return isSupported() ? static_cast<int>(m_command->commandType) : 0;
}
+HeapRanges* Editor::Command::getRanges() const
+{
+ if (!isSupported() || !m_frame)
+ return nullptr;
chongz 2016/05/12 20:53:49 Have to change them all to pointers to get ride of
+
+ switch (m_command->commandType) {
+ case WebEditingCommandType::Delete:
+ case WebEditingCommandType::DeleteBackward:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionBackward, CharacterGranularity);
+ case WebEditingCommandType::DeleteForward:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionForward, CharacterGranularity);
+ case WebEditingCommandType::DeleteToBeginningOfLine:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionBackward, LineGranularity);
+ case WebEditingCommandType::DeleteToBeginningOfParagraph:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionBackward, ParagraphGranularity);
+ case WebEditingCommandType::DeleteToEndOfLine:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionForward, LineGranularity);
+ case WebEditingCommandType::DeleteToEndOfParagraph:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionForward, ParagraphGranularity);
+ case WebEditingCommandType::DeleteWordBackward:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionBackward, WordGranularity);
+ case WebEditingCommandType::DeleteWordForward:
+ return RangesFromCurrentSelectionOrExtendCaret(frame().selection().selection(), DirectionForward, WordGranularity);
+ default:
+ return nullptr;
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698