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..e6443c6815948dfc829ce9eebe795b5f732d069b 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 |
} |
} |
+HeapVector<Member<Range>> RangesFromCurrentSelectionOrExtendCaret(const VisibleSelection& currentSelection, SelectionDirection direction, TextGranularity granularity) |
+{ |
+ FrameSelection* selection = FrameSelection::create(); |
+ selection->setSelection(currentSelection); |
+ if (selection->isCaret()) |
+ selection->modify(FrameSelection::AlterationExtend, direction, granularity); |
+ HeapVector<Member<Range>> ranges; |
+ // 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,34 @@ int Editor::Command::idForHistogram() const |
return isSupported() ? static_cast<int>(m_command->commandType) : 0; |
} |
+HeapVector<Member<Range>> Editor::Command::getRanges() const |
+{ |
+ DEFINE_STATIC_LOCAL(HeapVector<Member<Range>>, emptyVector, (new HeapVector<Member<Range>>)); |
+ |
+ if (!isSupported() || !m_frame) |
+ return emptyVector; |
+ |
+ 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 emptyVector; |
+ } |
+} |
+ |
} // namespace blink |