Bug 1220696 - part 6: Support insertLineBreak and insertParagraphSeparator commands in <textarea> r=smaug

Those command handlers just check whether the given editor is an `HTMLEditor`
or not.  Therefore, we should make them check whether the given editor is
a single line editor or not instead.

Differential Revision: https://phabricator.services.mozilla.com/D108572
This commit is contained in:
Masayuki Nakano 2021-03-24 01:55:09 +00:00
parent fad3ed3447
commit d68f6fc838
2 changed files with 17 additions and 66 deletions

View File

@ -870,7 +870,7 @@ StaticRefPtr<InsertParagraphCommand> InsertParagraphCommand::sInstance;
bool InsertParagraphCommand::IsCommandEnabled(Command aCommand,
TextEditor* aTextEditor) const {
if (!aTextEditor || !aTextEditor->AsHTMLEditor()) {
if (!aTextEditor || aTextEditor->IsSingleLineEditor()) {
return false;
}
return aTextEditor->IsSelectionEditable();
@ -879,15 +879,21 @@ bool InsertParagraphCommand::IsCommandEnabled(Command aCommand,
nsresult InsertParagraphCommand::DoCommand(Command aCommand,
TextEditor& aTextEditor,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
if (!htmlEditor) {
return NS_OK; // Do nothing for now.
if (aTextEditor.IsSingleLineEditor()) {
return NS_ERROR_FAILURE;
}
nsresult rv =
MOZ_KnownLive(htmlEditor)->InsertParagraphSeparatorAsAction(aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
if (aTextEditor.IsHTMLEditor()) {
nsresult rv = MOZ_KnownLive(aTextEditor.AsHTMLEditor())
->InsertParagraphSeparatorAsAction(aPrincipal);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"HTMLEditor::InsertParagraphSeparatorAsAction() failed");
return rv;
}
nsresult rv = aTextEditor.InsertLineBreakAsAction(aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditor::InsertLineBreakAsAction() failed");
return rv;
}
nsresult InsertParagraphCommand::GetCommandStateParams(
@ -905,7 +911,7 @@ StaticRefPtr<InsertLineBreakCommand> InsertLineBreakCommand::sInstance;
bool InsertLineBreakCommand::IsCommandEnabled(Command aCommand,
TextEditor* aTextEditor) const {
if (!aTextEditor || !aTextEditor->AsHTMLEditor()) {
if (!aTextEditor || aTextEditor->IsSingleLineEditor()) {
return false;
}
return aTextEditor->IsSelectionEditable();
@ -914,13 +920,12 @@ bool InsertLineBreakCommand::IsCommandEnabled(Command aCommand,
nsresult InsertLineBreakCommand::DoCommand(Command aCommand,
TextEditor& aTextEditor,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
if (!htmlEditor) {
if (aTextEditor.IsSingleLineEditor()) {
return NS_ERROR_FAILURE;
}
nsresult rv = MOZ_KnownLive(htmlEditor)->InsertLineBreakAsAction(aPrincipal);
nsresult rv = aTextEditor.InsertLineBreakAsAction(aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::InsertLineBreakAsAction() failed");
"TextEditor::InsertLineBreakAsAction() failed");
return rv;
}

View File

@ -110,36 +110,9 @@
[In <textarea>, execCommand("inserthtml", false, <b>inserted</b>), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea>, execCommand("insertparagraph", false, null), a[b\]c): The command should be enabled]
expected: FAIL
[In <textarea>, execCommand("insertparagraph", false, null), a[b\]c): execCommand() should return true]
expected: FAIL
[In <textarea>, execCommand("insertparagraph", false, null), a[b\]c): <textarea>.value should be "a\n[\]c"]
expected: FAIL
[In <textarea>, execCommand("insertparagraph", false, null), a[b\]c): input.inputType should be insertParagraph]
expected: FAIL
[In <textarea>, execCommand("insertparagraph", false, null), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea>, execCommand("insertlinebreak", false, null), a[b\]c): The command should be enabled]
expected: FAIL
[In <textarea>, execCommand("insertlinebreak", false, null), a[b\]c): execCommand() should return true]
expected: FAIL
[In <textarea>, execCommand("insertlinebreak", false, null), a[b\]c): <textarea>.value should be "a\n[\]c"]
expected: FAIL
[In <textarea>, execCommand("insertlinebreak", false, null), a[b\]c): input.inputType should be insertLineBreak]
expected: FAIL
[In <textarea>, execCommand("insertlinebreak", false, null), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea>, execCommand("contentReadOnly", false, true), a[b\]c): contentReadOnly state should be true when <textarea> has focus]
expected: FAIL
@ -245,36 +218,9 @@
[In <textarea> in contenteditable, execCommand("inserthtml", false, <b>inserted</b>), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertparagraph", false, null), a[b\]c): The command should be enabled]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertparagraph", false, null), a[b\]c): execCommand() should return true]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertparagraph", false, null), a[b\]c): <textarea>.value should be "a\n[\]c"]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertparagraph", false, null), a[b\]c): input.inputType should be insertParagraph]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertparagraph", false, null), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertlinebreak", false, null), a[b\]c): The command should be enabled]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertlinebreak", false, null), a[b\]c): execCommand() should return true]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertlinebreak", false, null), a[b\]c): <textarea>.value should be "a\n[\]c"]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertlinebreak", false, null), a[b\]c): input.inputType should be insertLineBreak]
expected: FAIL
[In <textarea> in contenteditable, execCommand("insertlinebreak", false, null), a[b\]c): input.target should be [object HTMLTextAreaElement\]]
expected: FAIL
[In <textarea> in contenteditable, execCommand("contentReadOnly", false, true), a[b\]c): contentReadOnly state should be true when <textarea> has focus]
expected: FAIL