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

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: Ojan'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 292653e3365030c2e31ab2df40acbc95ba55a0d5..5120de6608779c33db6dfcf51df7f0eaddbc1ace 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,19 @@ InputEvent::InputType InputTypeFromCommandType(WebEditingCommandType commandType
}
}
+RangeVector* RangesFromCurrentSelectionOrExtendCaret(const LocalFrame& frame, SelectionDirection direction, TextGranularity granularity)
+{
+ 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
class EditorInternalCommand {
@@ -1782,7 +1796,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 +1863,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(*m_frame, DirectionBackward, CharacterGranularity);
+ case WebEditingCommandType::DeleteForward:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, CharacterGranularity);
+ case WebEditingCommandType::DeleteToBeginningOfLine:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionBackward, LineGranularity);
+ case WebEditingCommandType::DeleteToBeginningOfParagraph:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionBackward, ParagraphGranularity);
+ case WebEditingCommandType::DeleteToEndOfLine:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, LineGranularity);
+ case WebEditingCommandType::DeleteToEndOfParagraph:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, ParagraphGranularity);
+ case WebEditingCommandType::DeleteWordBackward:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionBackward, WordGranularity);
+ case WebEditingCommandType::DeleteWordForward:
+ return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, WordGranularity);
+ default:
+ return nullptr;
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698