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

Unified Diff: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp

Issue 2576903002: [EditCommandSource] Pass source from |Editor::Command| to |Editor::apply*()/insert*()/...| (2/3) (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/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 d3281b5d62222298cf0ebfa3e233d4b8f85eedb6..5d253a4c4b77b648a75afec10aa668d5201b2364 100644
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
@@ -250,10 +250,10 @@ static bool applyCommandToFrame(LocalFrame& frame,
// good reason for that?
switch (source) {
case CommandSource::MenuOrKeyBinding:
- frame.editor().applyStyleToSelection(style, inputType);
+ frame.editor().applyStyleToSelection(source, style, inputType);
return true;
case CommandSource::Dom:
- frame.editor().applyStyle(style, inputType);
+ frame.editor().applyStyle(source, style, inputType);
return true;
}
NOTREACHED();
@@ -353,10 +353,10 @@ static bool executeApplyParagraphStyle(LocalFrame& frame,
// good reason for that?
switch (source) {
case CommandSource::MenuOrKeyBinding:
- frame.editor().applyParagraphStyleToSelection(style, inputType);
+ frame.editor().applyParagraphStyleToSelection(source, style, inputType);
return true;
case CommandSource::Dom:
- frame.editor().applyParagraphStyle(style, inputType);
+ frame.editor().applyParagraphStyle(source, style, inputType);
return true;
}
NOTREACHED();
@@ -364,6 +364,7 @@ static bool executeApplyParagraphStyle(LocalFrame& frame,
}
static bool executeInsertFragment(LocalFrame& frame,
+ CommandSource source,
DocumentFragment* fragment) {
DCHECK(frame.document());
return ReplaceSelectionCommand::create(
@@ -373,14 +374,16 @@ static bool executeInsertFragment(LocalFrame& frame,
->apply();
}
-static bool executeInsertElement(LocalFrame& frame, HTMLElement* content) {
+static bool executeInsertElement(LocalFrame& frame,
+ CommandSource source,
+ HTMLElement* content) {
DCHECK(frame.document());
DocumentFragment* fragment = DocumentFragment::create(*frame.document());
DummyExceptionStateForTesting exceptionState;
fragment->appendChild(content, exceptionState);
if (exceptionState.hadException())
return false;
- return executeInsertFragment(frame, fragment);
+ return executeInsertFragment(frame, source, fragment);
}
static bool expandSelectionToGranularity(LocalFrame& frame,
@@ -580,7 +583,7 @@ static bool executeDelete(LocalFrame& frame,
switch (source) {
case CommandSource::MenuOrKeyBinding: {
// Doesn't modify the text if the current selection isn't a range.
- frame.editor().performDelete();
+ frame.editor().performDelete(source);
return true;
}
case CommandSource::Dom:
@@ -601,9 +604,9 @@ static bool executeDelete(LocalFrame& frame,
static bool executeDeleteBackward(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Backward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Backward,
CharacterGranularity, false, true);
return true;
}
@@ -611,68 +614,68 @@ static bool executeDeleteBackward(LocalFrame& frame,
static bool executeDeleteBackwardByDecomposingPreviousCharacter(
LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
DLOG(ERROR) << "DeleteBackwardByDecomposingPreviousCharacter is not "
"implemented, doing DeleteBackward instead";
- frame.editor().deleteWithDirection(DeleteDirection::Backward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Backward,
CharacterGranularity, false, true);
return true;
}
static bool executeDeleteForward(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Forward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Forward,
CharacterGranularity, false, true);
return true;
}
static bool executeDeleteToBeginningOfLine(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Backward, LineBoundary,
- true, false);
+ frame.editor().deleteWithDirection(source, DeleteDirection::Backward,
+ LineBoundary, true, false);
return true;
}
static bool executeDeleteToBeginningOfParagraph(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Backward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Backward,
ParagraphBoundary, true, false);
return true;
}
static bool executeDeleteToEndOfLine(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
// Despite its name, this command should delete the newline at the end of a
// paragraph if you are at the end of a paragraph (like
// DeleteToEndOfParagraph).
- frame.editor().deleteWithDirection(DeleteDirection::Forward, LineBoundary,
- true, false);
+ frame.editor().deleteWithDirection(source, DeleteDirection::Forward,
+ LineBoundary, true, false);
return true;
}
static bool executeDeleteToEndOfParagraph(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
// Despite its name, this command should delete the newline at the end of
// a paragraph if you are at the end of a paragraph.
- frame.editor().deleteWithDirection(DeleteDirection::Forward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Forward,
ParagraphBoundary, true, false);
return true;
}
static bool executeDeleteToMark(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
const EphemeralRange mark =
frame.editor().mark().toNormalizedEphemeralRange();
@@ -685,26 +688,26 @@ static bool executeDeleteToMark(LocalFrame& frame,
if (!selected)
return false;
}
- frame.editor().performDelete();
+ frame.editor().performDelete(source);
frame.editor().setMark(frame.selection().selection());
return true;
}
static bool executeDeleteWordBackward(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Backward, WordGranularity,
- true, false);
+ frame.editor().deleteWithDirection(source, DeleteDirection::Backward,
+ WordGranularity, true, false);
return true;
}
static bool executeDeleteWordForward(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().deleteWithDirection(DeleteDirection::Forward, WordGranularity,
- true, false);
+ frame.editor().deleteWithDirection(source, DeleteDirection::Forward,
+ WordGranularity, true, false);
return true;
}
@@ -778,7 +781,7 @@ static bool executeForwardDelete(LocalFrame& frame,
EditingState editingState;
switch (source) {
case CommandSource::MenuOrKeyBinding:
- frame.editor().deleteWithDirection(DeleteDirection::Forward,
+ frame.editor().deleteWithDirection(source, DeleteDirection::Forward,
CharacterGranularity, false, true);
return true;
case CommandSource::Dom:
@@ -816,8 +819,9 @@ static bool executeIndent(LocalFrame& frame,
static bool executeInsertBacktab(LocalFrame& frame,
Event* event,
- CommandSource,
+ CommandSource source,
const String&) {
+ DCHECK_EQ(source, CommandSource::MenuOrKeyBinding);
Xiaocheng 2016/12/15 03:27:50 Please add some explanation to this DCHECK.
chongz 2016/12/16 00:45:22 Done.
return targetFrame(frame, event)
->eventHandler()
.handleTextInputEvent("\t", event, TextEventInputBackTab);
@@ -825,33 +829,33 @@ static bool executeInsertBacktab(LocalFrame& frame,
static bool executeInsertHorizontalRule(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String& value) {
DCHECK(frame.document());
HTMLHRElement* rule = HTMLHRElement::create(*frame.document());
if (!value.isEmpty())
rule->setIdAttribute(AtomicString(value));
- return executeInsertElement(frame, rule);
+ return executeInsertElement(frame, source, rule);
}
static bool executeInsertHTML(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String& value) {
DCHECK(frame.document());
return executeInsertFragment(
- frame, createFragmentFromMarkup(*frame.document(), value, ""));
+ frame, source, createFragmentFromMarkup(*frame.document(), value, ""));
}
static bool executeInsertImage(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String& value) {
DCHECK(frame.document());
HTMLImageElement* image = HTMLImageElement::create(*frame.document());
if (!value.isEmpty())
image->setSrc(value);
- return executeInsertElement(frame, image);
+ return executeInsertElement(frame, source, image);
}
static bool executeInsertLineBreak(LocalFrame& frame,
@@ -877,8 +881,9 @@ static bool executeInsertLineBreak(LocalFrame& frame,
static bool executeInsertNewline(LocalFrame& frame,
Event* event,
- CommandSource,
+ CommandSource source,
const String&) {
+ DCHECK_EQ(source, CommandSource::MenuOrKeyBinding);
Xiaocheng 2016/12/15 03:27:50 Please add some explanation to this DCHECK.
chongz 2016/12/16 00:45:22 Done.
LocalFrame* targetFrame = blink::targetFrame(frame, event);
return targetFrame->eventHandler().handleTextInputEvent(
"\n", event, targetFrame->editor().canEditRichly()
@@ -915,8 +920,9 @@ static bool executeInsertParagraph(LocalFrame& frame,
static bool executeInsertTab(LocalFrame& frame,
Event* event,
- CommandSource,
+ CommandSource source,
const String&) {
+ DCHECK_EQ(source, CommandSource::MenuOrKeyBinding);
Xiaocheng 2016/12/15 03:27:50 Please add some explanation to this DCHECK.
chongz 2016/12/16 00:45:22 Done.
return targetFrame(frame, event)
->eventHandler()
.handleTextInputEvent("\t", event);
@@ -979,38 +985,38 @@ static bool executeJustifyRight(LocalFrame& frame,
static bool executeMakeTextWritingDirectionLeftToRight(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
MutableStylePropertySet* style =
MutableStylePropertySet::create(HTMLQuirksMode);
style->setProperty(CSSPropertyUnicodeBidi, CSSValueIsolate);
style->setProperty(CSSPropertyDirection, CSSValueLtr);
- frame.editor().applyStyle(style,
+ frame.editor().applyStyle(source, style,
InputEvent::InputType::FormatSetBlockTextDirection);
return true;
}
static bool executeMakeTextWritingDirectionNatural(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
MutableStylePropertySet* style =
MutableStylePropertySet::create(HTMLQuirksMode);
style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
- frame.editor().applyStyle(style,
+ frame.editor().applyStyle(source, style,
InputEvent::InputType::FormatSetBlockTextDirection);
return true;
}
static bool executeMakeTextWritingDirectionRightToLeft(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
MutableStylePropertySet* style =
MutableStylePropertySet::create(HTMLQuirksMode);
style->setProperty(CSSPropertyUnicodeBidi, CSSValueIsolate);
style->setProperty(CSSPropertyDirection, CSSValueRtl);
- frame.editor().applyStyle(style,
+ frame.editor().applyStyle(source, style,
InputEvent::InputType::FormatSetBlockTextDirection);
return true;
}
@@ -1541,17 +1547,17 @@ static bool executePrint(LocalFrame& frame,
static bool executeRedo(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().redo();
+ frame.editor().redo(source);
return true;
}
static bool executeRemoveFormat(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().removeFormattingAndStyle();
+ frame.editor().removeFormattingAndStyle(source);
return true;
}
@@ -1738,9 +1744,9 @@ static bool executeToggleItalic(LocalFrame& frame,
static bool executeTranspose(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().transpose();
+ frame.editor().transpose(source);
return true;
}
@@ -1756,9 +1762,9 @@ static bool executeUnderline(LocalFrame& frame,
static bool executeUndo(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
- frame.editor().undo();
+ frame.editor().undo(source);
return true;
}
@@ -1788,20 +1794,20 @@ static bool executeUnselect(LocalFrame& frame,
static bool executeYank(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
frame.editor().insertTextWithoutSendingTextEvent(
- frame.editor().killRing().yank(), false, 0);
+ source, frame.editor().killRing().yank(), false, 0);
frame.editor().killRing().setToYankedState();
return true;
}
static bool executeYankAndSelect(LocalFrame& frame,
Event*,
- CommandSource,
+ CommandSource source,
const String&) {
frame.editor().insertTextWithoutSendingTextEvent(
- frame.editor().killRing().yank(), true, 0);
+ source, frame.editor().killRing().yank(), true, 0);
frame.editor().killRing().setToYankedState();
return true;
}
@@ -2553,9 +2559,11 @@ bool Editor::executeCommand(const String& commandName) {
// Specially handling commands that Editor::execCommand does not directly
// support.
if (commandName == "DeleteToEndOfParagraph") {
- if (!deleteWithDirection(DeleteDirection::Forward, ParagraphBoundary, true,
+ if (!deleteWithDirection(CommandSource::MenuOrKeyBinding,
+ DeleteDirection::Forward, ParagraphBoundary, true,
false))
- deleteWithDirection(DeleteDirection::Forward, CharacterGranularity, true,
+ deleteWithDirection(CommandSource::MenuOrKeyBinding,
+ DeleteDirection::Forward, CharacterGranularity, true,
false);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698