Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/Editor.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp |
| index d6800be1b677f6a0bf346363ae24713bcca88213..81ffeb5c0492907fb70c7061cb3f638bfed0e97a 100644 |
| --- a/third_party/WebKit/Source/core/editing/Editor.cpp |
| +++ b/third_party/WebKit/Source/core/editing/Editor.cpp |
| @@ -219,8 +219,9 @@ bool Editor::handleTextEvent(TextEvent* event) { |
| if (event->isPaste()) { |
| if (event->pastingFragment()) { |
| replaceSelectionWithFragment( |
| - event->pastingFragment(), false, event->shouldSmartReplace(), |
| - event->shouldMatchStyle(), InputEvent::InputType::InsertFromPaste); |
| + CommandSource::MenuOrKeyBinding, event->pastingFragment(), false, |
| + event->shouldSmartReplace(), event->shouldMatchStyle(), |
| + InputEvent::InputType::InsertFromPaste); |
| } else { |
| replaceSelectionWithText(event->data(), false, |
| event->shouldSmartReplace(), |
| @@ -236,7 +237,8 @@ bool Editor::handleTextEvent(TextEvent* event) { |
| return insertParagraphSeparator(); |
| } |
| - return insertTextWithoutSendingTextEvent(data, false, event); |
| + return insertTextWithoutSendingTextEvent(CommandSource::MenuOrKeyBinding, |
| + data, false, event); |
| } |
| bool Editor::canEdit() const { |
| @@ -316,7 +318,8 @@ bool Editor::isSelectTrailingWhitespaceEnabled() const { |
| return false; |
| } |
| -bool Editor::deleteWithDirection(DeleteDirection direction, |
| +bool Editor::deleteWithDirection(CommandSource source, |
| + DeleteDirection direction, |
| TextGranularity granularity, |
| bool killRing, |
| bool isTypingAction) { |
| @@ -335,6 +338,7 @@ bool Editor::deleteWithDirection(DeleteDirection direction, |
| if (killRing) |
| addToKillRing(selectedRange()); |
| deleteSelectionWithSmartDelete( |
| + source, |
| canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
| deletionInputTypeFromTextGranularity(direction, granularity)); |
| // Implicitly calls revealSelectionAfterEditingOperation(). |
| @@ -372,6 +376,7 @@ bool Editor::deleteWithDirection(DeleteDirection direction, |
| } |
| void Editor::deleteSelectionWithSmartDelete( |
| + CommandSource, |
|
Xiaocheng
2016/12/15 03:27:50
Please add a TODO about future plan so that other
chongz
2016/12/16 00:45:22
Done.
|
| DeleteMode deleteMode, |
| InputEvent::InputType inputType, |
| const Position& referenceMovePosition) { |
| @@ -564,7 +569,8 @@ bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { |
| return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); |
| } |
| -void Editor::replaceSelectionWithFragment(DocumentFragment* fragment, |
| +void Editor::replaceSelectionWithFragment(CommandSource, |
|
Xiaocheng
2016/12/15 03:27:50
Please add a TODO about future plan so that other
chongz
2016/12/16 00:45:22
Done.
|
| + DocumentFragment* fragment, |
| bool selectReplacement, |
| bool smartReplace, |
| bool matchStyle, |
| @@ -593,10 +599,11 @@ void Editor::replaceSelectionWithFragment(DocumentFragment* fragment, |
| void Editor::replaceSelectionWithText(const String& text, |
| bool selectReplacement, |
| bool smartReplace, |
| - InputEvent::InputType inputType) { |
| - replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), |
| - selectReplacement, smartReplace, true, |
| - inputType); |
| + InputEvent::InputType inputType, |
| + CommandSource source) { |
| + replaceSelectionWithFragment( |
| + source, createFragmentFromText(selectedRange(), text), selectReplacement, |
| + smartReplace, true, inputType); |
| } |
| // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
| @@ -634,8 +641,9 @@ bool Editor::deleteSelectionAfterDraggingWithEvents( |
| return false; |
| if (shouldDelete && dragSource->isConnected()) { |
| - deleteSelectionWithSmartDelete( |
| - deleteMode, InputEvent::InputType::DeleteByDrag, referenceMovePosition); |
| + deleteSelectionWithSmartDelete(CommandSource::MenuOrKeyBinding, deleteMode, |
| + InputEvent::InputType::DeleteByDrag, |
| + referenceMovePosition); |
| } |
| return true; |
| @@ -699,7 +707,7 @@ void Editor::respondToChangedContents(const VisibleSelection& endingSelection) { |
| client().respondToChangedContents(); |
| } |
| -void Editor::removeFormattingAndStyle() { |
| +void Editor::removeFormattingAndStyle(CommandSource) { |
|
Xiaocheng
2016/12/15 03:27:50
Please add a TODO about future plan so that other
chongz
2016/12/16 00:45:22
Done.
|
| DCHECK(frame().document()); |
| RemoveFormatCommand::create(*frame().document())->apply(); |
| } |
| @@ -725,14 +733,15 @@ Element* Editor::findEventTargetFromSelection() const { |
| return findEventTargetFrom(frame().selection().selection()); |
| } |
| -void Editor::applyStyle(StylePropertySet* style, |
| +void Editor::applyStyle(CommandSource source, |
| + StylePropertySet* style, |
| InputEvent::InputType inputType) { |
| switch (frame().selection().getSelectionType()) { |
| case NoSelection: |
| // do nothing |
| break; |
| case CaretSelection: |
| - computeAndSetTypingStyle(style, inputType); |
| + computeAndSetTypingStyle(source, style, inputType); |
| break; |
| case RangeSelection: |
| if (style) { |
| @@ -745,7 +754,8 @@ void Editor::applyStyle(StylePropertySet* style, |
| } |
| } |
| -void Editor::applyParagraphStyle(StylePropertySet* style, |
| +void Editor::applyParagraphStyle(CommandSource, |
|
Xiaocheng
2016/12/15 03:27:50
Please add a TODO about future plan so that other
chongz
2016/12/16 00:45:22
Done.
|
| + StylePropertySet* style, |
| InputEvent::InputType inputType) { |
| if (frame().selection().isNone() || !style) |
| return; |
| @@ -755,20 +765,22 @@ void Editor::applyParagraphStyle(StylePropertySet* style, |
| ->apply(); |
| } |
| -void Editor::applyStyleToSelection(StylePropertySet* style, |
| +void Editor::applyStyleToSelection(CommandSource source, |
| + StylePropertySet* style, |
| InputEvent::InputType inputType) { |
| if (!style || style->isEmpty() || !canEditRichly()) |
| return; |
| - applyStyle(style, inputType); |
| + applyStyle(source, style, inputType); |
| } |
| -void Editor::applyParagraphStyleToSelection(StylePropertySet* style, |
| +void Editor::applyParagraphStyleToSelection(CommandSource source, |
| + StylePropertySet* style, |
| InputEvent::InputType inputType) { |
| if (!style || style->isEmpty() || !canEditRichly()) |
| return; |
| - applyParagraphStyle(style, inputType); |
| + applyParagraphStyle(source, style, inputType); |
| } |
| bool Editor::selectionStartHasStyle(CSSPropertyID propertyID, |
| @@ -954,7 +966,8 @@ bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent) { |
| return frame().eventHandler().handleTextInputEvent(text, triggeringEvent); |
| } |
| -bool Editor::insertTextWithoutSendingTextEvent(const String& text, |
| +bool Editor::insertTextWithoutSendingTextEvent(CommandSource source, |
| + const String& text, |
| bool selectInsertedText, |
| TextEvent* triggeringEvent) { |
| if (text.isEmpty()) |
| @@ -1059,7 +1072,7 @@ void Editor::cut(CommandSource source) { |
| return; |
| } |
| deleteSelectionWithSmartDelete( |
| - canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
| + source, canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
| InputEvent::InputType::DeleteByCut); |
| } |
| } |
| @@ -1136,7 +1149,7 @@ void Editor::pasteAsPlainText(CommandSource source) { |
| pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
| } |
| -void Editor::performDelete() { |
| +void Editor::performDelete(CommandSource source) { |
| if (!canDelete()) |
| return; |
| @@ -1149,7 +1162,7 @@ void Editor::performDelete() { |
| // TODO(chongz): |Editor::performDelete()| has no direction. |
| // https://github.com/w3c/editing/issues/130 |
| deleteSelectionWithSmartDelete( |
| - canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
| + source, canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
| InputEvent::InputType::DeleteContentBackward); |
| // clear the "start new kill ring sequence" setting, because it was set to |
| @@ -1236,7 +1249,7 @@ bool Editor::canUndo() { |
| return m_undoStack->canUndo(); |
| } |
| -void Editor::undo() { |
| +void Editor::undo(CommandSource) { |
|
Xiaocheng
2016/12/15 03:27:50
How are we going to use CommandSource here?
chongz
2016/12/16 00:45:22
We are going to fire a 'beforeinput' for user trig
|
| m_undoStack->undo(); |
| } |
| @@ -1244,7 +1257,7 @@ bool Editor::canRedo() { |
| return m_undoStack->canRedo(); |
| } |
| -void Editor::redo() { |
| +void Editor::redo(CommandSource) { |
|
Xiaocheng
2016/12/15 03:27:50
Same question as undo.
chongz
2016/12/16 00:45:22
Same as above.
|
| m_undoStack->redo(); |
| } |
| @@ -1268,7 +1281,8 @@ void Editor::setBaseWritingDirection(WritingDirection direction) { |
| : direction == RightToLeftWritingDirection ? "rtl" : "inherit", |
| false); |
| applyParagraphStyleToSelection( |
| - style, InputEvent::InputType::FormatSetBlockTextDirection); |
| + CommandSource::MenuOrKeyBinding, style, |
| + InputEvent::InputType::FormatSetBlockTextDirection); |
| } |
| void Editor::revealSelectionAfterEditingOperation( |
| @@ -1279,7 +1293,7 @@ void Editor::revealSelectionAfterEditingOperation( |
| frame().selection().revealSelection(alignment, revealExtentOption); |
| } |
| -void Editor::transpose() { |
| +void Editor::transpose(CommandSource source) { |
| if (!canEdit()) |
| return; |
| @@ -1317,7 +1331,7 @@ void Editor::transpose() { |
| // TODO(chongz): Once we add |InsertTranspose| in |InputEvent::InputType|, we |
| // should use it instead of |InsertFromPaste|. |
| replaceSelectionWithText(transposed, false, false, |
| - InputEvent::InputType::InsertFromPaste); |
| + InputEvent::InputType::InsertFromPaste, source); |
| } |
| void Editor::addToKillRing(const EphemeralRange& range) { |
| @@ -1397,7 +1411,8 @@ IntRect Editor::firstRectForRange(const EphemeralRange& range) const { |
| startCaretRect.height()); |
| } |
| -void Editor::computeAndSetTypingStyle(StylePropertySet* style, |
| +void Editor::computeAndSetTypingStyle(CommandSource, |
|
Xiaocheng
2016/12/15 03:27:50
Please add a TODO about future plan so that other
chongz
2016/12/16 00:45:22
Done.
|
| + StylePropertySet* style, |
| InputEvent::InputType inputType) { |
| if (!style || style->isEmpty()) { |
| frame().selection().clearTypingStyle(); |