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 da67f2e09b2b17bd4384ac0f8785146477f2e336..33fb0eb9ffd9425ef1ca3c82ef99dee35ed800ec 100644 |
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
@@ -69,6 +69,7 @@ |
#include "platform/scroll/Scrollbar.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebEditingCommandType.h" |
+#include "wtf/AutoReset.h" |
#include "wtf/StringExtras.h" |
#include "wtf/text/AtomicString.h" |
@@ -109,105 +110,6 @@ WebEditingCommandType WebEditingCommandTypeFromCommandName( |
return WebEditingCommandType::Invalid; |
} |
-// |frame| is only used for |InsertNewline| due to how |executeInsertNewline()| |
-// works. |
-InputEvent::InputType InputTypeFromCommandType( |
- WebEditingCommandType commandType, |
- LocalFrame& frame) { |
- // We only handle InputType on spec for 'beforeinput'. |
- // http://w3c.github.io/editing/input-events.html |
- using CommandType = WebEditingCommandType; |
- using InputType = InputEvent::InputType; |
- |
- // |executeInsertNewline()| could do two things but we have no other ways to |
- // predict. |
- if (commandType == CommandType::InsertNewline) |
- return frame.editor().canEditRichly() ? InputType::InsertParagraph |
- : InputType::InsertLineBreak; |
- |
- switch (commandType) { |
- // Insertion. |
- case CommandType::InsertBacktab: |
- case CommandType::InsertText: |
- return InputType::InsertText; |
- case CommandType::InsertLineBreak: |
- return InputType::InsertLineBreak; |
- case CommandType::InsertParagraph: |
- case CommandType::InsertNewlineInQuotedContent: |
- return InputType::InsertParagraph; |
- case CommandType::InsertHorizontalRule: |
- return InputType::InsertHorizontalRule; |
- case CommandType::InsertOrderedList: |
- return InputType::InsertOrderedList; |
- case CommandType::InsertUnorderedList: |
- return InputType::InsertUnorderedList; |
- |
- // Deletion. |
- case CommandType::Delete: |
- case CommandType::DeleteBackward: |
- case CommandType::DeleteBackwardByDecomposingPreviousCharacter: |
- return InputType::DeleteContentBackward; |
- case CommandType::DeleteForward: |
- return InputType::DeleteContentForward; |
- case CommandType::DeleteToBeginningOfLine: |
- return InputType::DeleteLineBackward; |
- case CommandType::DeleteToEndOfLine: |
- return InputType::DeleteLineForward; |
- case CommandType::DeleteWordBackward: |
- return InputType::DeleteWordBackward; |
- case CommandType::DeleteWordForward: |
- return InputType::DeleteWordForward; |
- // TODO(chongz): Find appreciate InputType for following commands. |
- case CommandType::DeleteToBeginningOfParagraph: |
- case CommandType::DeleteToEndOfParagraph: |
- case CommandType::DeleteToMark: |
- return InputType::None; |
- |
- // Command. |
- case CommandType::Undo: |
- return InputType::HistoryUndo; |
- case CommandType::Redo: |
- return InputType::HistoryRedo; |
- // Cut and Paste will be handled in |Editor::dispatchCPPEvent()|. |
- |
- // Styling. |
- case CommandType::Bold: |
- case CommandType::ToggleBold: |
- return InputType::FormatBold; |
- case CommandType::Italic: |
- case CommandType::ToggleItalic: |
- return InputType::FormatItalic; |
- case CommandType::Underline: |
- case CommandType::ToggleUnderline: |
- return InputType::FormatUnderline; |
- case CommandType::Strikethrough: |
- return InputType::FormatStrikeThrough; |
- case CommandType::Superscript: |
- return InputType::FormatSuperscript; |
- case CommandType::Subscript: |
- return InputType::FormatSubscript; |
- default: |
- return InputType::None; |
- } |
-} |
- |
-RangeVector* RangesFromCurrentSelectionOrExtendCaret( |
- const LocalFrame& frame, |
- SelectionDirection direction, |
- TextGranularity granularity) { |
- frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
- 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 { |
@@ -2637,20 +2539,8 @@ bool Editor::Command::execute(const String& parameter, |
return false; |
} |
- if (m_source == CommandFromMenuOrKeyBinding) { |
- InputEvent::InputType inputType = |
- InputTypeFromCommandType(m_command->commandType, *m_frame); |
- if (inputType != InputEvent::InputType::None) { |
- if (dispatchBeforeInputEditorCommand( |
- eventTargetNodeForDocument(m_frame->document()), inputType, |
- getTargetRanges()) != DispatchEventResult::NotCanceled) |
- return true; |
- } |
- } |
- |
- // 'beforeinput' event handler may destroy target frame. |
- if (m_frame->document()->frame() != m_frame) |
- return false; |
+ AutoReset<bool> resetCommandSource( |
+ &m_frame->editor().m_executingCommandFromDOM, m_source == CommandFromDOM); |
frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, |
@@ -2706,39 +2596,4 @@ int Editor::Command::idForHistogram() const { |
return isSupported() ? static_cast<int>(m_command->commandType) : 0; |
} |
-RangeVector* Editor::Command::getTargetRanges() 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 |