/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if (Any(paramType & EditorCommandParamType::Bool)) { if (Any(paramType & EditorCommandParamType::StateAttribute)) {
Maybe<bool> boolParam = Nothing(); if (params) {
ErrorResult error;
boolParam = Some(params->GetBool(STATE_ATTRIBUTE, error)); if (NS_WARN_IF(error.Failed())) { return error.StealNSResult();
}
}
nsresult rv = DoCommandParam(
command, boolParam, MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
}
MOZ_ASSERT_UNREACHABLE("Unexpected state for bool"); return NS_ERROR_NOT_IMPLEMENTED;
}
// Special case for MultiStateCommandBase. It allows both CString and String // in STATE_ATTRIBUTE and CString is preferred. if (Any(paramType & EditorCommandParamType::CString) &&
Any(paramType & EditorCommandParamType::String)) { if (!params) {
nsresult rv =
DoCommandParam(command, VoidString(),
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to do command from " "nsIControllerCommand::DoCommandParams()"); return rv;
} if (Any(paramType & EditorCommandParamType::StateAttribute)) {
nsCString cStringParam;
nsresult rv = params->GetCString(STATE_ATTRIBUTE, cStringParam); if (NS_SUCCEEDED(rv)) {
NS_ConvertUTF8toUTF16 stringParam(cStringParam);
nsresult rv =
DoCommandParam(command, stringParam,
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to do command from " "nsIControllerCommand::DoCommandParams()"); return rv;
}
nsString stringParam;
DebugOnly<nsresult> rvIgnored =
params->GetString(STATE_ATTRIBUTE, stringParam);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "Failed to get string from STATE_ATTRIBUTE");
rv = DoCommandParam(command, stringParam,
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to do command from " "nsIControllerCommand::DoCommandParams()"); return rv;
}
MOZ_ASSERT_UNREACHABLE("Unexpected state for CString/String"); return NS_ERROR_NOT_IMPLEMENTED;
}
if (Any(paramType & EditorCommandParamType::CString)) { if (!params) {
nsresult rv =
DoCommandParam(command, VoidCString(),
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
} if (Any(paramType & EditorCommandParamType::StateAttribute)) {
nsCString cStringParam;
nsresult rv = params->GetCString(STATE_ATTRIBUTE, cStringParam); if (NS_WARN_IF(NS_FAILED(rv))) { return rv;
}
rv = DoCommandParam(command, cStringParam,
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
}
MOZ_ASSERT_UNREACHABLE("Unexpected state for CString"); return NS_ERROR_NOT_IMPLEMENTED;
}
if (Any(paramType & EditorCommandParamType::String)) { if (!params) {
nsresult rv =
DoCommandParam(command, VoidString(),
MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
}
nsString stringParam; if (Any(paramType & EditorCommandParamType::StateAttribute)) {
nsresult rv = params->GetString(STATE_ATTRIBUTE, stringParam); if (NS_WARN_IF(NS_FAILED(rv))) { return rv;
}
} elseif (Any(paramType & EditorCommandParamType::StateData)) {
nsresult rv = params->GetString(STATE_DATA, stringParam); if (NS_WARN_IF(NS_FAILED(rv))) { return rv;
}
} else {
MOZ_ASSERT_UNREACHABLE("Unexpected state for String"); return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult rv = DoCommandParam(
command, stringParam, MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
}
if (Any(paramType & EditorCommandParamType::Transferable)) {
nsCOMPtr<nsITransferable> transferable; if (params) {
nsCOMPtr<nsISupports> supports = params->GetISupports("transferable");
transferable = do_QueryInterface(supports);
}
nsresult rv = DoCommandParam(
command, transferable, MOZ_KnownLive(*editor->AsEditorBase()), nullptr);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Failed to do command from nsIControllerCommand::DoCommandParams()"); return rv;
}
nsresult CopyCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const { // Shouldn't cause "beforeinput" event so that we don't need to specify // the given principal. return aEditorBase.Copy();
}
bool DeleteCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const { if (!aEditorBase) { returnfalse;
} // 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->IsModifiable() && aEditorBase->IsSelectionEditable();
nsresult DeleteCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
nsIEditor::EDirection deleteDir = nsIEditor::eNone; switch (aCommand) { case Command::Delete: // Really this should probably be eNone, but it only makes a difference // if the selection is collapsed, and then this command is disabled. So // let's keep it as it always was to avoid breaking things.
deleteDir = nsIEditor::ePrevious; break; case Command::DeleteCharForward:
deleteDir = nsIEditor::eNext; break; case Command::DeleteCharBackward:
deleteDir = nsIEditor::ePrevious; break; case Command::DeleteWordBackward:
deleteDir = nsIEditor::ePreviousWord; break; case Command::DeleteWordForward:
deleteDir = nsIEditor::eNextWord; break; case Command::DeleteToBeginningOfLine:
deleteDir = nsIEditor::eToBeginningOfLine; break; case Command::DeleteToEndOfLine:
deleteDir = nsIEditor::eToEndOfLine; break; default:
MOZ_CRASH("Unrecognized nsDeleteCommand");
}
nsresult rv = aEditorBase.DeleteSelectionAsAction(
deleteDir, nsIEditor::eStrip, aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DeleteSelectionAsAction() failed"); return rv;
}
bool SelectAllCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const { // You can always select all, unless the selection is editable, // and the editable region is empty! if (!aEditorBase) { returntrue;
}
// You can select all if there is an editor which is non-empty return !aEditorBase->IsEmpty();
}
nsresult SelectAllCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const { // Shouldn't cause "beforeinput" event so that we don't need to specify // aPrincipal.
nsresult rv = aEditorBase.SelectAll();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SelectAll() failed"); return rv;
}
nsresult SelectionMoveCommands::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
RefPtr<dom::Document> document = aEditorBase.GetDocument(); if (document) { // Most of the commands below (possibly all of them) need layout to // be up to date.
document->FlushPendingNotifications(FlushType::Layout);
}
nsCOMPtr<nsISelectionController> selectionController =
aEditorBase.GetSelectionController(); if (NS_WARN_IF(!selectionController)) { return NS_ERROR_FAILURE;
}
// scroll commands for (size_t i = 0; i < std::size(scrollCommands); i++) { const ScrollCommand& cmd = scrollCommands[i]; if (aCommand == cmd.mReverseScroll) { return (selectionController->*(cmd.scroll))(false);
} if (aCommand == cmd.mForwardScroll) { return (selectionController->*(cmd.scroll))(true);
}
}
// caret movement/selection commands for (size_t i = 0; i < std::size(moveCommands); i++) { const MoveCommand& cmd = moveCommands[i]; if (aCommand == cmd.mReverseMove) { return (selectionController->*(cmd.move))(false, false);
} if (aCommand == cmd.mForwardMove) { return (selectionController->*(cmd.move))(true, false);
} if (aCommand == cmd.mReverseSelect) { return (selectionController->*(cmd.move))(false, true);
} if (aCommand == cmd.mForwardSelect) { return (selectionController->*(cmd.move))(true, true);
}
}
// physical-direction movement/selection for (size_t i = 0; i < std::size(physicalCommands); i++) { const PhysicalCommand& cmd = physicalCommands[i]; if (aCommand == cmd.mMove) {
nsresult rv =
selectionController->PhysicalMove(cmd.direction, cmd.amount, false);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "nsISelectionController::PhysicalMove() failed to move caret"); return rv;
} if (aCommand == cmd.mSelect) {
nsresult rv =
selectionController->PhysicalMove(cmd.direction, cmd.amount, true);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "nsISelectionController::PhysicalMove() failed to select"); return rv;
}
}
nsresult InsertPlaintextCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const { // XXX InsertTextAsAction() is not same as OnInputText(). However, other // commands to insert line break or paragraph separator use OnInput*(). // According to the semantics of those methods, using *AsAction() is // better, however, this may not cause two or more placeholder // transactions to the top transaction since its name may not be // nsGkAtoms::TypingTxnName.
DebugOnly<nsresult> rvIgnored =
aEditorBase.InsertTextAsAction(u""_ns, aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::InsertTextAsAction() failed, but ignored"); return NS_OK;
}
// XXX InsertTextAsAction() is not same as OnInputText(). However, other // commands to insert line break or paragraph separator use OnInput*(). // According to the semantics of those methods, using *AsAction() is // better, however, this may not cause two or more placeholder // transactions to the top transaction since its name may not be // nsGkAtoms::TypingTxnName.
DebugOnly<nsresult> rvIgnored =
aEditorBase.InsertTextAsAction(aStringParam, aPrincipal);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::InsertTextAsAction() failed, but ignored"); return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.