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 15ce3676b997ed63da3b1b93a8cdaab67129f009..df82b8424360c08078528c570e9d55fd9d9c1f61 100644 |
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
@@ -38,6 +38,7 @@ |
#include "core/dom/DocumentFragment.h" |
#include "core/editing/EditingUtilities.h" |
#include "core/editing/FrameSelection.h" |
+#include "core/editing/SelectionModifier.h" |
#include "core/editing/commands/CreateLinkCommand.h" |
#include "core/editing/commands/EditorCommandNames.h" |
#include "core/editing/commands/FormatBlockCommand.h" |
@@ -131,6 +132,18 @@ InputEvent::InputType InputTypeFromCommandType(WebEditingCommandType commandType |
} |
} |
+RangeVector* RangesFromCurrentSelectionOrExtendCaret(const LocalFrame& frame, SelectionDirection direction, TextGranularity granularity) |
yosin_UTC9
2016/05/19 05:01:02
Let's use std::unique_ptr<RangeVector> to specify
chongz
2016/05/25 05:38:57
Done.
|
+{ |
+ 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()) |
yosin_UTC9
2016/05/19 05:01:02
nit: early return is better.
if (selecitonModifie
chongz
2016/05/25 05:38:57
Done.
|
+ ranges->append(firstRangeOf(selectionModifier.selection())); |
+ 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; |
} |
+RangeVector* Editor::Command::getRanges() const |
+{ |
+ if (!isSupported() || !m_frame) |
+ return nullptr; |
+ |
+ switch (m_command->commandType) { |
+ case WebEditingCommandType::Delete: |
+ case WebEditingCommandType::DeleteBackward: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionBackward, CharacterGranularity); |
yosin_UTC9
2016/05/19 05:01:02
nit: %s/frame()/m_frame/
Since L1867 uses |m_frame
chongz
2016/05/25 05:38:57
Done.
|
+ case WebEditingCommandType::DeleteForward: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionForward, CharacterGranularity); |
+ case WebEditingCommandType::DeleteToBeginningOfLine: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionBackward, LineGranularity); |
+ case WebEditingCommandType::DeleteToBeginningOfParagraph: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionBackward, ParagraphGranularity); |
+ case WebEditingCommandType::DeleteToEndOfLine: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionForward, LineGranularity); |
+ case WebEditingCommandType::DeleteToEndOfParagraph: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionForward, ParagraphGranularity); |
+ case WebEditingCommandType::DeleteWordBackward: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionBackward, WordGranularity); |
+ case WebEditingCommandType::DeleteWordForward: |
+ return RangesFromCurrentSelectionOrExtendCaret(frame(), DirectionForward, WordGranularity); |
+ default: |
+ return nullptr; |
+ } |
+} |
+ |
} // namespace blink |