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

Unified Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2574793002: [Editing] Store |CommandSource| in |CompositeEditCommand| (Closed)
Patch Set: Created 4 years 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/Editor.cpp
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp
index c1d7b1601c31f25d33007acffabad03502910b9f..e7282d60b51ad3c3fe1166f8533f1f59bd467a60 100644
--- a/third_party/WebKit/Source/core/editing/Editor.cpp
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp
@@ -214,11 +214,12 @@ 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(),
+ replaceSelectionWithText(CommandSource::MenuOrKeyBinding, event->data(),
+ false, event->shouldSmartReplace(),
InputEvent::InputType::InsertFromPaste);
}
return true;
@@ -231,7 +232,8 @@ bool Editor::handleTextEvent(TextEvent* event) {
return insertParagraphSeparator();
}
- return insertTextWithoutSendingTextEvent(data, false, event);
+ return insertTextWithoutSendingTextEvent(CommandSource::MenuOrKeyBinding,
+ data, false, event);
}
bool Editor::canEdit() const {
@@ -311,7 +313,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) {
@@ -323,13 +326,14 @@ bool Editor::deleteWithDirection(DeleteDirection direction,
if (isTypingAction) {
DCHECK(frame().document());
TypingCommand::deleteKeyPressed(
- *frame().document(),
+ *frame().document(), source,
canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity);
revealSelectionAfterEditingOperation();
} else {
if (killRing)
addToKillRing(selectedRange());
deleteSelectionWithSmartDelete(
+ source,
canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple,
deletionInputTypeFromTextGranularity(direction, granularity));
// Implicitly calls revealSelectionAfterEditingOperation().
@@ -344,13 +348,13 @@ bool Editor::deleteWithDirection(DeleteDirection direction,
case DeleteDirection::Forward:
DCHECK(frame().document());
TypingCommand::forwardDeleteKeyPressed(
- *frame().document(), &editingState, options, granularity);
+ *frame().document(), source, &editingState, options, granularity);
if (editingState.isAborted())
return false;
break;
case DeleteDirection::Backward:
DCHECK(frame().document());
- TypingCommand::deleteKeyPressed(*frame().document(), options,
+ TypingCommand::deleteKeyPressed(*frame().document(), source, options,
granularity);
break;
}
@@ -367,6 +371,7 @@ bool Editor::deleteWithDirection(DeleteDirection direction,
}
void Editor::deleteSelectionWithSmartDelete(
+ CommandSource source,
DeleteMode deleteMode,
InputEvent::InputType inputType,
const Position& referenceMovePosition) {
@@ -378,7 +383,7 @@ void Editor::deleteSelectionWithSmartDelete(
const bool kSanitizeMarkup = true;
DCHECK(frame().document());
DeleteSelectionCommand::create(
- *frame().document(), deleteMode == DeleteMode::Smart,
+ *frame().document(), source, deleteMode == DeleteMode::Smart,
kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup,
inputType, referenceMovePosition)
->apply();
@@ -558,7 +563,8 @@ bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) {
return smartInsertDeleteEnabled() && pasteboard->canSmartReplace();
}
-void Editor::replaceSelectionWithFragment(DocumentFragment* fragment,
+void Editor::replaceSelectionWithFragment(CommandSource source,
+ DocumentFragment* fragment,
bool selectReplacement,
bool smartReplace,
bool matchStyle,
@@ -578,19 +584,20 @@ void Editor::replaceSelectionWithFragment(DocumentFragment* fragment,
if (matchStyle)
options |= ReplaceSelectionCommand::MatchStyle;
DCHECK(frame().document());
- ReplaceSelectionCommand::create(*frame().document(), fragment, options,
- inputType)
+ ReplaceSelectionCommand::create(*frame().document(), source, fragment,
+ options, inputType)
->apply();
revealSelectionAfterEditingOperation();
}
-void Editor::replaceSelectionWithText(const String& text,
+void Editor::replaceSelectionWithText(CommandSource source,
+ const String& text,
bool selectReplacement,
bool smartReplace,
InputEvent::InputType inputType) {
- replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
- selectReplacement, smartReplace, true,
- inputType);
+ replaceSelectionWithFragment(
+ source, createFragmentFromText(selectedRange(), text), selectReplacement,
+ smartReplace, true, inputType);
}
// TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|.
@@ -605,8 +612,9 @@ void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment,
if (dragSourceType == DragSourceType::PlainTextSource)
options |= ReplaceSelectionCommand::MatchStyle;
DCHECK(frame().document());
- ReplaceSelectionCommand::create(*frame().document(), fragment, options,
- InputEvent::InputType::InsertFromDrop)
+ ReplaceSelectionCommand::create(
+ *frame().document(), CommandSource::MenuOrKeyBinding, fragment, options,
+ InputEvent::InputType::InsertFromDrop)
->apply();
}
@@ -628,8 +636,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;
@@ -693,9 +702,9 @@ void Editor::respondToChangedContents(const VisibleSelection& endingSelection) {
client().respondToChangedContents();
}
-void Editor::removeFormattingAndStyle() {
+void Editor::removeFormattingAndStyle(CommandSource source) {
DCHECK(frame().document());
- RemoveFormatCommand::create(*frame().document())->apply();
+ RemoveFormatCommand::create(*frame().document(), source)->apply();
}
void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) {
@@ -719,19 +728,20 @@ 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) {
DCHECK(frame().document());
- ApplyStyleCommand::create(*frame().document(),
+ ApplyStyleCommand::create(*frame().document(), source,
EditingStyle::create(style), inputType)
->apply();
}
@@ -739,30 +749,34 @@ void Editor::applyStyle(StylePropertySet* style,
}
}
-void Editor::applyParagraphStyle(StylePropertySet* style,
+void Editor::applyParagraphStyle(CommandSource source,
+ StylePropertySet* style,
InputEvent::InputType inputType) {
if (frame().selection().isNone() || !style)
return;
DCHECK(frame().document());
- ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style),
- inputType, ApplyStyleCommand::ForceBlockProperties)
+ ApplyStyleCommand::create(*frame().document(), source,
+ EditingStyle::create(style), inputType,
+ ApplyStyleCommand::ForceBlockProperties)
->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,
@@ -948,7 +962,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())
@@ -963,7 +978,7 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text,
// Insert the text
TypingCommand::insertText(
- *selection.start().document(), text, selection,
+ *selection.start().document(), source, text, selection,
selectInsertedText ? TypingCommand::SelectInsertedText : 0,
triggeringEvent && triggeringEvent->isComposition()
? TypingCommand::TextCompositionConfirm
@@ -974,6 +989,8 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text,
if (Page* page = editedFrame->page()) {
LocalFrame* focusedOrMainFrame =
toLocalFrame(page->focusController().focusedOrMainFrame());
+ if (!focusedOrMainFrame->selection().isAvailable())
Xiaocheng 2016/12/14 04:19:50 Seems irrelevant to this patch.
chongz 2016/12/15 00:53:32 Will remove.
+ return true;
focusedOrMainFrame->selection().revealSelection(
ScrollAlignment::alignCenterIfNeeded);
}
@@ -989,7 +1006,8 @@ bool Editor::insertLineBreak() {
VisiblePosition caret = frame().selection().selection().visibleStart();
bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
DCHECK(frame().document());
- if (!TypingCommand::insertLineBreak(*frame().document()))
+ if (!TypingCommand::insertLineBreak(*frame().document(),
+ CommandSource::MenuOrKeyBinding))
return false;
revealSelectionAfterEditingOperation(
alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded
@@ -1009,7 +1027,8 @@ bool Editor::insertParagraphSeparator() {
bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
DCHECK(frame().document());
EditingState editingState;
- if (!TypingCommand::insertParagraphSeparator(*frame().document()))
+ if (!TypingCommand::insertParagraphSeparator(*frame().document(),
+ CommandSource::MenuOrKeyBinding))
return false;
revealSelectionAfterEditingOperation(
alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded
@@ -1018,7 +1037,7 @@ bool Editor::insertParagraphSeparator() {
return true;
}
-void Editor::cut(EditorCommandSource source) {
+void Editor::cut(CommandSource source) {
if (tryDHTMLCut())
return; // DHTML did the whole operation
if (!canCut())
@@ -1042,7 +1061,7 @@ void Editor::cut(EditorCommandSource source) {
writeSelectionToPasteboard();
}
- if (source == CommandFromMenuOrKeyBinding) {
+ if (source == CommandSource::MenuOrKeyBinding) {
if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(),
InputEvent::InputType::DeleteByCut,
nullptr, nullptr) !=
@@ -1053,7 +1072,7 @@ void Editor::cut(EditorCommandSource source) {
return;
}
deleteSelectionWithSmartDelete(
- canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple,
+ source, canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple,
InputEvent::InputType::DeleteByCut);
}
}
@@ -1086,7 +1105,7 @@ void Editor::copy() {
}
}
-void Editor::paste(EditorCommandSource source) {
+void Editor::paste(CommandSource source) {
DCHECK(frame().document());
if (tryDHTMLPaste(AllMimeTypes))
return; // DHTML did the whole operation
@@ -1100,7 +1119,7 @@ void Editor::paste(EditorCommandSource source) {
? AllMimeTypes
: PlainTextOnly;
- if (source == CommandFromMenuOrKeyBinding) {
+ if (source == CommandSource::MenuOrKeyBinding) {
DataTransfer* dataTransfer =
DataTransfer::create(DataTransfer::CopyAndPaste, DataTransferReadable,
DataObject::createFromPasteboard(pasteMode));
@@ -1121,7 +1140,7 @@ void Editor::paste(EditorCommandSource source) {
pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
}
-void Editor::pasteAsPlainText(EditorCommandSource source) {
+void Editor::pasteAsPlainText(CommandSource source) {
if (tryDHTMLPaste(PlainTextOnly))
return;
if (!canPaste())
@@ -1130,7 +1149,7 @@ void Editor::pasteAsPlainText(EditorCommandSource source) {
pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
}
-void Editor::performDelete() {
+void Editor::performDelete(CommandSource source) {
if (!canDelete())
return;
@@ -1143,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
@@ -1230,7 +1249,7 @@ bool Editor::canUndo() {
return m_undoStack->canUndo();
}
-void Editor::undo() {
+void Editor::undo(CommandSource) {
m_undoStack->undo();
}
@@ -1238,7 +1257,7 @@ bool Editor::canRedo() {
return m_undoStack->canRedo();
}
-void Editor::redo() {
+void Editor::redo(CommandSource) {
m_undoStack->redo();
}
@@ -1262,18 +1281,19 @@ void Editor::setBaseWritingDirection(WritingDirection direction) {
: direction == RightToLeftWritingDirection ? "rtl" : "inherit",
false);
applyParagraphStyleToSelection(
- style, InputEvent::InputType::FormatSetBlockTextDirection);
+ CommandSource::MenuOrKeyBinding, style,
+ InputEvent::InputType::FormatSetBlockTextDirection);
}
void Editor::revealSelectionAfterEditingOperation(
const ScrollAlignment& alignment,
RevealExtentOption revealExtentOption) {
- if (m_preventRevealSelection)
+ if (m_preventRevealSelection || !m_frame->selection().isAvailable())
Xiaocheng 2016/12/14 04:19:50 Seems irrelevant to this patch.
chongz 2016/12/15 00:53:32 Will remove.
return;
frame().selection().revealSelection(alignment, revealExtentOption);
}
-void Editor::transpose() {
+void Editor::transpose(CommandSource source) {
if (!canEdit())
return;
@@ -1310,7 +1330,7 @@ void Editor::transpose() {
// Insert the transposed characters.
// TODO(chongz): Once we add |InsertTranspose| in |InputEvent::InputType|, we
// should use it instead of |InsertFromPaste|.
- replaceSelectionWithText(transposed, false, false,
+ replaceSelectionWithText(source, transposed, false, false,
InputEvent::InputType::InsertFromPaste);
}
@@ -1391,7 +1411,8 @@ IntRect Editor::firstRectForRange(const EphemeralRange& range) const {
startCaretRect.height());
}
-void Editor::computeAndSetTypingStyle(StylePropertySet* style,
+void Editor::computeAndSetTypingStyle(CommandSource source,
+ StylePropertySet* style,
InputEvent::InputType inputType) {
if (!style || style->isEmpty()) {
frame().selection().clearTypingStyle();
@@ -1415,12 +1436,14 @@ void Editor::computeAndSetTypingStyle(StylePropertySet* style,
EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties();
if (!blockStyle->isEmpty()) {
DCHECK(frame().document());
- ApplyStyleCommand::create(*frame().document(), blockStyle, inputType)
+ ApplyStyleCommand::create(*frame().document(), source, blockStyle,
+ inputType)
->apply();
}
// Set the remaining style as the typing style.
- frame().selection().setTypingStyle(typingStyle);
+ if (frame().selection().isAvailable())
Xiaocheng 2016/12/14 04:19:50 Seems irrelevant to this patch.
chongz 2016/12/15 00:53:32 Will remove.
+ frame().selection().setTypingStyle(typingStyle);
}
bool Editor::findString(const String& target, FindOptions options) {

Powered by Google App Engine
This is Rietveld 408576698