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 |