diff --git a/editor/libeditor/EditorCommands.cpp b/editor/libeditor/EditorCommands.cpp index beb4f060adc0..45f9e3198f72 100644 --- a/editor/libeditor/EditorCommands.cpp +++ b/editor/libeditor/EditorCommands.cpp @@ -269,7 +269,8 @@ bool UndoCommand::IsCommandEnabled(Command aCommand, if (!aEditorBase) { return false; } - return aEditorBase->IsSelectionEditable() && aEditorBase->CanUndo(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable() && + aEditorBase->CanUndo(); } nsresult UndoCommand::DoCommand(Command aCommand, EditorBase& aEditorBase, @@ -297,7 +298,8 @@ bool RedoCommand::IsCommandEnabled(Command aCommand, if (!aEditorBase) { return false; } - return aEditorBase->IsSelectionEditable() && aEditorBase->CanRedo(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable() && + aEditorBase->CanRedo(); } nsresult RedoCommand::DoCommand(Command aCommand, EditorBase& aEditorBase, @@ -548,7 +550,7 @@ bool SwitchTextDirectionCommand::IsCommandEnabled( if (!aEditorBase) { return false; } - return aEditorBase->IsSelectionEditable(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable(); } nsresult SwitchTextDirectionCommand::DoCommand(Command aCommand, @@ -581,7 +583,8 @@ bool DeleteCommand::IsCommandEnabled(Command aCommand, // We can generally delete whenever the selection is editable. However, // cmd_delete doesn't make sense if the selection is collapsed because it's // directionless. - bool isEnabled = aEditorBase->IsSelectionEditable(); + bool isEnabled = + aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable(); if (aCommand == Command::Delete && isEnabled) { return aEditorBase->CanDeleteSelection(); @@ -820,7 +823,7 @@ bool InsertPlaintextCommand::IsCommandEnabled(Command aCommand, if (!aEditorBase) { return false; } - return aEditorBase->IsSelectionEditable(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable(); } nsresult InsertPlaintextCommand::DoCommand(Command aCommand, @@ -877,7 +880,7 @@ bool InsertParagraphCommand::IsCommandEnabled(Command aCommand, if (!aEditorBase || aEditorBase->IsSingleLineEditor()) { return false; } - return aEditorBase->IsSelectionEditable(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable(); } nsresult InsertParagraphCommand::DoCommand(Command aCommand, @@ -918,7 +921,7 @@ bool InsertLineBreakCommand::IsCommandEnabled(Command aCommand, if (!aEditorBase || aEditorBase->IsSingleLineEditor()) { return false; } - return aEditorBase->IsSelectionEditable(); + return aEditorBase->IsModifiable() && aEditorBase->IsSelectionEditable(); } nsresult InsertLineBreakCommand::DoCommand(Command aCommand, diff --git a/editor/libeditor/HTMLEditorCommands.cpp b/editor/libeditor/HTMLEditorCommands.cpp index 1864299a3a4c..ecccc7c491cf 100644 --- a/editor/libeditor/HTMLEditorCommands.cpp +++ b/editor/libeditor/HTMLEditorCommands.cpp @@ -52,7 +52,7 @@ bool StateUpdatingCommandBase::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - if (!htmlEditor->IsSelectionEditable()) { + if (!htmlEditor->IsModifiable() || !htmlEditor->IsSelectionEditable()) { return false; } if (aCommand == Command::FormatAbsolutePosition) { @@ -355,8 +355,7 @@ bool RemoveListCommand::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - - if (!htmlEditor->IsSelectionEditable()) { + if (!htmlEditor->IsModifiable() || !htmlEditor->IsSelectionEditable()) { return false; } @@ -401,7 +400,7 @@ bool IndentCommand::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult IndentCommand::DoCommand(Command aCommand, EditorBase& aEditorBase, @@ -434,7 +433,7 @@ bool OutdentCommand::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult OutdentCommand::DoCommand(Command aCommand, EditorBase& aEditorBase, @@ -467,7 +466,7 @@ bool MultiStateCommandBase::IsCommandEnabled(Command aCommand, return false; } // should be disabled sometimes, like if the current selection is an image - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult MultiStateCommandBase::DoCommand(Command aCommand, @@ -1047,7 +1046,7 @@ bool RemoveStylesCommand::IsCommandEnabled(Command aCommand, return false; } // test if we have any styles? - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult RemoveStylesCommand::DoCommand(Command aCommand, @@ -1085,7 +1084,7 @@ bool IncreaseFontSizeCommand::IsCommandEnabled(Command aCommand, return false; } // test if we are at max size? - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult IncreaseFontSizeCommand::DoCommand(Command aCommand, @@ -1121,7 +1120,7 @@ bool DecreaseFontSizeCommand::IsCommandEnabled(Command aCommand, return false; } // test if we are at min size? - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult DecreaseFontSizeCommand::DoCommand(Command aCommand, @@ -1156,7 +1155,7 @@ bool InsertHTMLCommand::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } nsresult InsertHTMLCommand::DoCommand(Command aCommand, EditorBase& aEditorBase, @@ -1213,7 +1212,7 @@ bool InsertTagCommand::IsCommandEnabled(Command aCommand, if (!htmlEditor) { return false; } - return htmlEditor->IsSelectionEditable(); + return htmlEditor->IsModifiable() && htmlEditor->IsSelectionEditable(); } // corresponding STATE_ATTRIBUTE is: src (img) and href (a) diff --git a/editor/libeditor/tests/mochitest.toml b/editor/libeditor/tests/mochitest.toml index 7662d3fb719f..04f3e6a6b04e 100644 --- a/editor/libeditor/tests/mochitest.toml +++ b/editor/libeditor/tests/mochitest.toml @@ -418,6 +418,8 @@ skip-if = ["os == 'android'"] #Bug 1575739 ["test_cmd_paragraphState.html"] +["test_command_state_when_readonly.html"] + ["test_composition_event_created_in_chrome.html"] ["test_composition_with_highlight_in_texteditor.html"] diff --git a/editor/libeditor/tests/test_command_state_when_readonly.html b/editor/libeditor/tests/test_command_state_when_readonly.html new file mode 100644 index 000000000000..7b4daaa1b37b --- /dev/null +++ b/editor/libeditor/tests/test_command_state_when_readonly.html @@ -0,0 +1,149 @@ + +Test for nsIEditor.isCommandEnabled for normal and read-only editors + + + +
+