2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
#include "mozilla/EditorCommands.h"
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
2017-08-04 11:12:01 +03:00
|
|
|
#include "mozilla/EditorBase.h" // for EditorBase
|
2018-01-30 07:28:00 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2017-08-04 09:41:42 +03:00
|
|
|
#include "mozilla/HTMLEditor.h" // for HTMLEditor
|
2018-01-30 07:28:00 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsAString.h"
|
2019-04-30 07:24:49 +03:00
|
|
|
#include "nsAtom.h" // for nsAtom, nsStaticAtom, etc
|
2018-07-10 14:04:21 +03:00
|
|
|
#include "nsCommandParams.h" // for nsCommandParams, etc
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
|
|
|
#include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::font, etc
|
|
|
|
#include "nsIClipboard.h" // for nsIClipboard, etc
|
2019-04-27 10:35:56 +03:00
|
|
|
#include "nsIEditingSession.h"
|
2019-06-10 13:27:07 +03:00
|
|
|
#include "nsIPrincipal.h" // for nsIPrincipal
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
|
|
|
#include "nsReadableUtils.h" // for EmptyString
|
|
|
|
#include "nsString.h" // for nsAutoString, nsString, etc
|
2017-06-20 12:19:05 +03:00
|
|
|
#include "nsStringFwd.h" // for nsString
|
2012-07-13 10:33:42 +04:00
|
|
|
|
|
|
|
class nsISupports;
|
2018-06-15 19:13:31 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
using dom::Element;
|
2012-05-18 12:29:40 +04:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
// prototype
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed,
|
|
|
|
nsAString& aLocalName);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
|
|
|
// defines
|
2002-07-16 02:04:13 +04:00
|
|
|
#define STATE_ENABLED "state_enabled"
|
|
|
|
#define STATE_ALL "state_all"
|
2002-12-03 01:20:12 +03:00
|
|
|
#define STATE_ANY "state_any"
|
|
|
|
#define STATE_MIXED "state_mixed"
|
2002-07-16 02:04:13 +04:00
|
|
|
#define STATE_BEGIN "state_begin"
|
|
|
|
#define STATE_END "state_end"
|
2002-12-03 01:20:12 +03:00
|
|
|
#define STATE_ATTRIBUTE "state_attribute"
|
2002-11-13 02:03:27 +03:00
|
|
|
#define STATE_DATA "state_data"
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::StateUpdatingCommandBase
|
|
|
|
*****************************************************************************/
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool StateUpdatingCommandBase::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2019-04-26 14:06:45 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!htmlEditor->IsSelectionEditable()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2019-04-26 14:06:45 +03:00
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
if (aCommand == Command::FormatAbsolutePosition) {
|
2019-05-03 05:15:18 +03:00
|
|
|
return htmlEditor->IsAbsolutePositionEditorEnabled();
|
2019-04-26 14:06:45 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return true;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult StateUpdatingCommandBase::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 09:57:57 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-04 09:57:57 +03:00
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
nsAtom* tagName = GetTagName(aCommand);
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!tagName)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
return ToggleState(MOZ_KnownLive(tagName), MOZ_KnownLive(htmlEditor),
|
|
|
|
aPrincipal);
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult StateUpdatingCommandBase::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
if (!aTextEditor) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-04-27 10:35:56 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-04 09:41:42 +03:00
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
nsAtom* tagName = GetTagName(aCommand);
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!tagName)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
return GetCurrentState(MOZ_KnownLive(tagName), MOZ_KnownLive(htmlEditor),
|
|
|
|
aParams);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::PasteNoFormattingCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<PasteNoFormattingCommand> PasteNoFormattingCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool PasteNoFormattingCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return htmlEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult PasteNoFormattingCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-03-12 04:55:03 +03:00
|
|
|
// Known live because we hold a ref above in "editor"
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)
|
|
|
|
->PasteNoFormattingAsAction(nsIClipboard::kGlobalClipboard,
|
|
|
|
aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "PasteNoFormattingAsAction() failed");
|
|
|
|
return rv;
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult PasteNoFormattingCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::StyleUpdatingCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<StyleUpdatingCommand> StyleUpdatingCommand::sInstance;
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-27 10:36:30 +03:00
|
|
|
nsresult StyleUpdatingCommand::GetCurrentState(nsAtom* aTagName,
|
|
|
|
HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool firstOfSelectionHasProp = false;
|
|
|
|
bool anyOfSelectionHasProp = false;
|
|
|
|
bool allOfSelectionHasProp = false;
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetInlineProperty(
|
2019-04-15 10:29:17 +03:00
|
|
|
aTagName, nullptr, EmptyString(), &firstOfSelectionHasProp,
|
2017-08-04 09:41:42 +03:00
|
|
|
&anyOfSelectionHasProp, &allOfSelectionHasProp);
|
2002-12-03 01:20:12 +03:00
|
|
|
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_ENABLED, NS_SUCCEEDED(rv));
|
|
|
|
aParams.SetBool(STATE_ALL, allOfSelectionHasProp);
|
|
|
|
aParams.SetBool(STATE_ANY, anyOfSelectionHasProp);
|
|
|
|
aParams.SetBool(STATE_MIXED, anyOfSelectionHasProp && !allOfSelectionHasProp);
|
|
|
|
aParams.SetBool(STATE_BEGIN, firstOfSelectionHasProp);
|
|
|
|
aParams.SetBool(STATE_END, allOfSelectionHasProp); // not completely accurate
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
nsresult StyleUpdatingCommand::ToggleState(nsAtom* aTagName,
|
2019-06-10 13:27:07 +03:00
|
|
|
HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
// tags "href" and "name" are special cases in the core editor
|
2003-03-04 18:42:44 +03:00
|
|
|
// they are used to remove named anchor/link and shouldn't be used for
|
|
|
|
// insertion
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doTagRemoval;
|
2019-04-15 10:29:17 +03:00
|
|
|
if (aTagName == nsGkAtoms::href || aTagName == nsGkAtoms::name) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doTagRemoval = true;
|
2012-05-18 12:29:40 +04:00
|
|
|
} else {
|
2003-03-04 18:42:44 +03:00
|
|
|
// check current selection; set doTagRemoval if formatting should be removed
|
2019-04-27 10:36:30 +03:00
|
|
|
nsresult rv = GetCurrentState(aTagName, aHTMLEditor, *params);
|
2018-07-10 14:04:21 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
ErrorResult error;
|
|
|
|
doTagRemoval = params->GetBool(STATE_ALL, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
2003-03-04 18:42:44 +03:00
|
|
|
}
|
|
|
|
|
2012-04-04 15:47:13 +04:00
|
|
|
if (doTagRemoval) {
|
|
|
|
// Also remove equivalent properties (bug 317093)
|
2018-08-09 14:52:46 +03:00
|
|
|
// XXX Why don't we make the following two transactions as an atomic
|
|
|
|
// transaction? If the element is <b>, <i> or <strike>, user
|
|
|
|
// needs to undo twice.
|
2019-04-15 10:29:17 +03:00
|
|
|
if (aTagName == nsGkAtoms::b) {
|
2018-10-30 13:00:17 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
*nsGkAtoms::strong, nullptr, aPrincipal);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-04-15 10:29:17 +03:00
|
|
|
} else if (aTagName == nsGkAtoms::i) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::em, nullptr, aPrincipal);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-04-15 10:29:17 +03:00
|
|
|
} else if (aTagName == nsGkAtoms::strike) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::s, nullptr, aPrincipal);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-04-04 15:47:13 +04:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*aTagName, nullptr,
|
|
|
|
aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
2018-08-09 14:52:46 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
|
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
|
|
|
*aTagName, nullptr, EmptyString(), aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ListCommand
|
|
|
|
*****************************************************************************/
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
StaticRefPtr<ListCommand> ListCommand::sInstance;
|
|
|
|
|
|
|
|
nsresult ListCommand::GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
2019-04-27 10:36:30 +03:00
|
|
|
nsCommandParams& aParams) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bMixed;
|
2012-04-14 17:07:37 +04:00
|
|
|
nsAutoString localName;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = GetListState(aHTMLEditor, &bMixed, localName);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
bool inList = aTagName->Equals(localName);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_ALL, !bMixed && inList);
|
|
|
|
aParams.SetBool(STATE_MIXED, bMixed);
|
|
|
|
aParams.SetBool(STATE_ENABLED, true);
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ListCommand::ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2012-05-18 12:29:40 +04:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult rv;
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
2019-04-27 10:36:30 +03:00
|
|
|
rv = GetCurrentState(aTagName, aHTMLEditor, *params);
|
2018-07-10 14:04:21 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-18 12:29:40 +04:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool inList = params->GetBool(STATE_ALL, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
nsDependentAtomString listType(aTagName);
|
2012-05-18 12:29:40 +04:00
|
|
|
if (inList) {
|
2019-06-10 13:27:07 +03:00
|
|
|
rv = aHTMLEditor->RemoveListAsAction(listType, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RemoveListAsAction() failed");
|
|
|
|
return rv;
|
2002-12-03 01:20:12 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
rv = aHTMLEditor->MakeOrChangeListAsAction(listType, false, EmptyString(),
|
|
|
|
aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "MakeOrChangeListAsAction() failed");
|
2002-02-02 08:13:56 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ListItemCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<ListItemCommand> ListItemCommand::sInstance;
|
2000-06-06 00:26:40 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
nsresult ListItemCommand::GetCurrentState(nsAtom* aTagName,
|
|
|
|
HTMLEditor* aHTMLEditor,
|
2019-04-27 10:36:30 +03:00
|
|
|
nsCommandParams& aParams) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bMixed, bLI, bDT, bDD;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetListItemState(&bMixed, &bLI, &bDT, &bDD);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inList = false;
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!bMixed) {
|
2012-05-18 12:29:40 +04:00
|
|
|
if (bLI) {
|
2019-04-15 10:29:17 +03:00
|
|
|
inList = aTagName == nsGkAtoms::li;
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (bDT) {
|
2019-04-15 10:29:17 +03:00
|
|
|
inList = aTagName == nsGkAtoms::dt;
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (bDD) {
|
2019-04-15 10:29:17 +03:00
|
|
|
inList = aTagName == nsGkAtoms::dd;
|
2012-05-18 12:29:40 +04:00
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_ALL, !bMixed && inList);
|
|
|
|
aParams.SetBool(STATE_MIXED, bMixed);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ListItemCommand::ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aTagName) || NS_WARN_IF(!aHTMLEditor)) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
// Need to use aTagName????
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
2019-04-27 10:36:30 +03:00
|
|
|
GetCurrentState(aTagName, aHTMLEditor, *params);
|
2018-07-10 14:04:21 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool inList = params->GetBool(STATE_ALL, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-04-14 17:07:37 +04:00
|
|
|
if (inList) {
|
2002-02-02 08:13:56 +03:00
|
|
|
// To remove a list, first get what kind of list we're in
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bMixed;
|
2012-04-14 17:07:37 +04:00
|
|
|
nsAutoString localName;
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = GetListState(aHTMLEditor, &bMixed, localName);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2012-04-14 17:07:37 +04:00
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
if (localName.IsEmpty() || bMixed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
rv = aHTMLEditor->RemoveListAsAction(localName, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RemoveListAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2012-04-14 17:07:37 +04:00
|
|
|
|
|
|
|
// Set to the requested paragraph type
|
|
|
|
// XXX Note: This actually doesn't work for "LI",
|
|
|
|
// but we currently don't use this for non DL lists anyway.
|
|
|
|
// Problem: won't this replace any current block paragraph style?
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetParagraphFormatAsAction(
|
|
|
|
nsDependentAtomString(aTagName), aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetParagraphFormatAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-06-06 00:26:40 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::RemoveListCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<RemoveListCommand> RemoveListCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool RemoveListCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
|
|
|
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
2002-09-24 17:29:28 +04:00
|
|
|
|
2019-05-03 05:15:18 +03:00
|
|
|
if (!htmlEditor->IsSelectionEditable()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2017-08-04 09:41:42 +03:00
|
|
|
}
|
2012-04-14 17:07:37 +04:00
|
|
|
|
2019-05-03 05:15:18 +03:00
|
|
|
// It is enabled if we are in any list type
|
2012-04-14 17:07:37 +04:00
|
|
|
bool bMixed;
|
|
|
|
nsAutoString localName;
|
2019-03-30 14:55:29 +03:00
|
|
|
nsresult rv = GetListState(MOZ_KnownLive(htmlEditor), &bMixed, localName);
|
2019-04-26 16:11:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return bMixed || !localName.IsEmpty();
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult RemoveListCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// This removes any list type
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = htmlEditor->RemoveListAsAction(EmptyString(), aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RemoveListAsAction() failed");
|
|
|
|
return rv;
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult RemoveListCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-06-16 18:21:46 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::IndentCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<IndentCommand> IndentCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool IndentCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return htmlEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult IndentCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)->IndentAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "IndentAsAction() failed");
|
|
|
|
return rv;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IndentCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::OutdentCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<OutdentCommand> OutdentCommand::sInstance;
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool OutdentCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return htmlEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult OutdentCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)->OutdentAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "OutdentAsAction() failed");
|
|
|
|
return rv;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult OutdentCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::MultiStateCommandBase
|
|
|
|
*****************************************************************************/
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool MultiStateCommandBase::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// should be disabled sometimes, like if the current selection is an image
|
2019-05-03 05:15:18 +03:00
|
|
|
return htmlEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult MultiStateCommandBase::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 05:20:22 +03:00
|
|
|
NS_WARNING(
|
|
|
|
"who is calling MultiStateCommandBase::DoCommand (no implementation)?");
|
2015-05-28 18:58:42 +03:00
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
nsresult MultiStateCommandBase::DoCommandParam(Command aCommand,
|
|
|
|
const nsAString& aStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-06-04 13:01:31 +03:00
|
|
|
NS_WARNING_ASSERTION(aCommand != Command::FormatJustify,
|
|
|
|
"Command::FormatJustify should be used only for "
|
|
|
|
"IsCommandEnabled() and GetCommandStateParams()");
|
2019-04-26 18:32:06 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = SetState(MOZ_KnownLive(htmlEditor), aStringParam, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetState() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-10 03:03:41 +04:00
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult MultiStateCommandBase::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
if (!aTextEditor) {
|
2017-08-04 09:41:42 +03:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2019-04-27 10:35:56 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-04 09:41:42 +03:00
|
|
|
}
|
2019-04-27 10:36:30 +03:00
|
|
|
return GetCurrentState(MOZ_KnownLive(htmlEditor), aParams);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ParagraphStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<ParagraphStateCommand> ParagraphStateCommand::sInstance;
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult ParagraphStateCommand::GetCurrentState(
|
2019-04-27 10:36:30 +03:00
|
|
|
HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2002-07-16 02:04:13 +04:00
|
|
|
nsAutoString outStateString;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetParagraphState(&outMixed, outStateString);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult ParagraphStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-06-10 13:27:07 +03:00
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetParagraphFormatAsAction(aNewState, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetParagraphFormatAsAction() failed");
|
2019-05-21 10:47:47 +03:00
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::FontFaceStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<FontFaceStateCommand> FontFaceStateCommand::sInstance;
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2019-04-27 10:36:30 +03:00
|
|
|
nsresult FontFaceStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
|
2002-07-16 02:04:13 +04:00
|
|
|
nsAutoString outStateString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetFontFaceState(&outMixed, outStateString);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult FontFaceStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-06-10 13:27:07 +03:00
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
if (aNewState.EqualsLiteral("tt")) {
|
2012-05-05 13:00:05 +04:00
|
|
|
// The old "teletype" attribute
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
*nsGkAtoms::tt, nullptr, EmptyString(), aPrincipal);
|
2018-08-13 08:16:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
// Clear existing font face
|
2018-10-30 13:00:17 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
2019-06-10 13:27:07 +03:00
|
|
|
nsGkAtoms::face, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
}
|
2012-05-05 13:00:05 +04:00
|
|
|
|
|
|
|
// Remove any existing TT nodes
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::tt,
|
|
|
|
nullptr, aPrincipal);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-05 13:00:05 +04:00
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
if (aNewState.IsEmpty() || aNewState.EqualsLiteral("normal")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
2019-06-10 13:27:07 +03:00
|
|
|
nsGkAtoms::face, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
}
|
2012-05-05 13:00:05 +04:00
|
|
|
|
2018-10-24 07:17:42 +03:00
|
|
|
rv = aHTMLEditor->SetInlinePropertyAsAction(*nsGkAtoms::font, nsGkAtoms::face,
|
2019-06-10 13:27:07 +03:00
|
|
|
aNewState, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::FontSizeStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<FontSizeStateCommand> FontSizeStateCommand::sInstance;
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-04-27 10:36:30 +03:00
|
|
|
nsresult FontSizeStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2002-12-03 01:20:12 +03:00
|
|
|
nsAutoString outStateString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool firstHas, anyHas, allHas;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetInlinePropertyWithAttrValue(
|
|
|
|
nsGkAtoms::font, nsGkAtoms::size, EmptyString(), &firstHas, &anyHas,
|
|
|
|
&allHas, outStateString);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, anyHas && !allHas);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
|
|
|
aParams.SetBool(STATE_ENABLED, true);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
// acceptable values for "aNewState" are:
|
2002-11-20 04:18:23 +03:00
|
|
|
// -2
|
|
|
|
// -1
|
|
|
|
// 0
|
|
|
|
// +1
|
|
|
|
// +2
|
|
|
|
// +3
|
|
|
|
// medium
|
|
|
|
// normal
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult FontSizeStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-06-10 13:27:07 +03:00
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
if (!aNewState.IsEmpty() && !aNewState.EqualsLiteral("normal") &&
|
|
|
|
!aNewState.EqualsLiteral("medium")) {
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
*nsGkAtoms::font, nsGkAtoms::size, aNewState, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SetInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2012-05-05 13:00:05 +04:00
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2012-05-05 13:00:05 +04:00
|
|
|
// remove any existing font size, big or small
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::size, aPrincipal);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::big, nullptr,
|
|
|
|
aPrincipal);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::small, nullptr,
|
|
|
|
aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::FontColorStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<FontColorStateCommand> FontColorStateCommand::sInstance;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult FontColorStateCommand::GetCurrentState(
|
2019-04-27 10:36:30 +03:00
|
|
|
HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2002-07-16 02:04:13 +04:00
|
|
|
nsAutoString outStateString;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetFontColorState(&outMixed, outStateString);
|
2018-08-27 09:52:35 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-05 13:00:05 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult FontColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-06-10 13:27:07 +03:00
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
if (aNewState.IsEmpty() || aNewState.EqualsLiteral("normal")) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::color, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
*nsGkAtoms::font, nsGkAtoms::color, aNewState, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::HighlightColorStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<HighlightColorStateCommand> HighlightColorStateCommand::sInstance;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult HighlightColorStateCommand::GetCurrentState(
|
2019-04-27 10:36:30 +03:00
|
|
|
HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2002-07-16 02:04:13 +04:00
|
|
|
nsAutoString outStateString;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetHighlightColorState(&outMixed, outStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult HighlightColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
if (aNewState.IsEmpty() || aNewState.EqualsLiteral("normal")) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::bgcolor, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
*nsGkAtoms::font, nsGkAtoms::bgcolor, aNewState, aPrincipal);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetInlinePropertyAsAction() failed");
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::BackgroundColorStateCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<BackgroundColorStateCommand>
|
|
|
|
BackgroundColorStateCommand::sInstance;
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult BackgroundColorStateCommand::GetCurrentState(
|
2019-04-27 10:36:30 +03:00
|
|
|
HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2002-07-16 02:04:13 +04:00
|
|
|
nsAutoString outStateString;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetBackgroundColorState(&outMixed, outStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult BackgroundColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetBackgroundColorAsAction(aNewState, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetBackgroundColorAsAction() failed");
|
2019-05-21 10:47:47 +03:00
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
Fixed lots of nsbeta3+ bugs: 45756, 47654, 41810,47503,48990, 48995,40204, 42740, 46953, 47646, 47696, 48693, 45899. r=sfraser,jfrancis
2000-08-23 04:29:24 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::AlignCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<AlignCommand> AlignCommand::sInstance;
|
2000-08-24 05:20:29 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult AlignCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
2019-04-27 10:36:30 +03:00
|
|
|
nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsIHTMLEditor::EAlignment firstAlign;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outMixed;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetAlignment(&outMixed, &firstAlign);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-12-03 01:20:12 +03:00
|
|
|
nsAutoString outStateString;
|
2016-10-24 05:27:45 +03:00
|
|
|
switch (firstAlign) {
|
2002-02-02 08:13:56 +03:00
|
|
|
default:
|
|
|
|
case nsIHTMLEditor::eLeft:
|
2004-06-17 04:13:25 +04:00
|
|
|
outStateString.AssignLiteral("left");
|
2002-02-02 08:13:56 +03:00
|
|
|
break;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
case nsIHTMLEditor::eCenter:
|
2004-06-17 04:13:25 +04:00
|
|
|
outStateString.AssignLiteral("center");
|
2002-02-02 08:13:56 +03:00
|
|
|
break;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
case nsIHTMLEditor::eRight:
|
2004-06-17 04:13:25 +04:00
|
|
|
outStateString.AssignLiteral("right");
|
2002-02-02 08:13:56 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIHTMLEditor::eJustify:
|
2004-06-17 04:13:25 +04:00
|
|
|
outStateString.AssignLiteral("justify");
|
2002-02-02 08:13:56 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString tOutStateString;
|
2017-07-24 20:23:52 +03:00
|
|
|
LossyCopyUTF16toASCII(outStateString, tOutStateString);
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, outMixed);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult AlignCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-06-10 13:27:07 +03:00
|
|
|
const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->AlignAsAction(aNewState, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "AlignAsAction() failed");
|
2019-05-21 10:47:47 +03:00
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::AbsolutePositioningCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<AbsolutePositioningCommand> AbsolutePositioningCommand::sInstance;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult AbsolutePositioningCommand::GetCurrentState(
|
2019-04-27 10:36:30 +03:00
|
|
|
nsAtom* aTagName, HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const {
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-04-04 16:27:49 +03:00
|
|
|
if (!aHTMLEditor->IsAbsolutePositionEditorEnabled()) {
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, false);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, EmptyCString());
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:42:52 +03:00
|
|
|
RefPtr<Element> container =
|
|
|
|
aHTMLEditor->GetAbsolutelyPositionedSelectionContainer();
|
2019-04-27 10:36:30 +03:00
|
|
|
aParams.SetBool(STATE_MIXED, false);
|
|
|
|
aParams.SetCString(STATE_ATTRIBUTE, container ? NS_LITERAL_CSTRING("absolute")
|
2018-07-10 14:04:21 +03:00
|
|
|
: EmptyCString());
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult AbsolutePositioningCommand::ToggleState(
|
2019-06-10 13:27:07 +03:00
|
|
|
nsAtom* aTagName, HTMLEditor* aHTMLEditor, nsIPrincipal* aPrincipal) const {
|
2017-08-04 09:57:57 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-01-30 07:42:52 +03:00
|
|
|
RefPtr<Element> container =
|
|
|
|
aHTMLEditor->GetAbsolutelyPositionedSelectionContainer();
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetSelectionToAbsoluteOrStaticAsAction(!container,
|
|
|
|
aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"SetSelectionToAbsoluteOrStaticAsAction() failed");
|
|
|
|
return rv;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::DecreaseZIndexCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<DecreaseZIndexCommand> DecreaseZIndexCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool DecreaseZIndexCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2018-04-04 16:27:49 +03:00
|
|
|
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2018-04-04 16:27:49 +03:00
|
|
|
}
|
2017-08-04 12:30:13 +03:00
|
|
|
RefPtr<Element> positionedElement = htmlEditor->GetPositionedElement();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!positionedElement) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return htmlEditor->GetZIndex(*positionedElement) > 0;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult DecreaseZIndexCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = htmlEditor->AddZIndexAsAction(-1, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "AddZIndexAsAction() failed");
|
|
|
|
return rv;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult DecreaseZIndexCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::IncreaseZIndexCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<IncreaseZIndexCommand> IncreaseZIndexCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool IncreaseZIndexCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2018-04-04 16:27:49 +03:00
|
|
|
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2018-04-04 16:27:49 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return !!htmlEditor->GetPositionedElement();
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult IncreaseZIndexCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = htmlEditor->AddZIndexAsAction(1, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "AddZIndexAsAction() failed");
|
|
|
|
return rv;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IncreaseZIndexCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::RemoveStylesCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<RemoveStylesCommand> RemoveStylesCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool RemoveStylesCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we have any styles?
|
2019-05-03 05:15:18 +03:00
|
|
|
return htmlEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult RemoveStylesCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
MOZ_KnownLive(htmlEditor)->RemoveAllInlinePropertiesAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveAllInlinePropertiesAsAction() failed");
|
|
|
|
return rv;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult RemoveStylesCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::IncreaseFontSizeCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<IncreaseFontSizeCommand> IncreaseFontSizeCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool IncreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-17 21:28:03 +04:00
|
|
|
// test if we are at max size?
|
2019-05-03 05:15:18 +03:00
|
|
|
return htmlEditor->IsSelectionEditable();
|
2002-09-12 23:09:01 +04:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult IncreaseFontSizeCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)->IncreaseFontSizeAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "IncreaseFontSizeAsAction() failed");
|
|
|
|
return rv;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IncreaseFontSizeCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::DecreaseFontSizeCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<DecreaseFontSizeCommand> DecreaseFontSizeCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool DecreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we are at min size?
|
2019-05-03 05:15:18 +03:00
|
|
|
return htmlEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult DecreaseFontSizeCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2019-05-03 05:15:18 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)->DecreaseFontSizeAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "DecreaseFontSizeAsAction() failed");
|
|
|
|
return rv;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult DecreaseFontSizeCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::InsertHTMLCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<InsertHTMLCommand> InsertHTMLCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool InsertHTMLCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return htmlEditor->IsSelectionEditable();
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult InsertHTMLCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:45:55 +03:00
|
|
|
// If InsertHTMLCommand is called with no parameters, it was probably called
|
2015-05-14 15:02:00 +03:00
|
|
|
// with an empty string parameter ''. In this case, it should act the same as
|
|
|
|
// the delete command
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
MOZ_KnownLive(htmlEditor)->InsertHTMLAsAction(EmptyString(), aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "InsertHTMLAsAction() failed");
|
2019-05-21 10:45:55 +03:00
|
|
|
return rv;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
nsresult InsertHTMLCommand::DoCommandParam(Command aCommand,
|
|
|
|
const nsAString& aStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:45:55 +03:00
|
|
|
if (NS_WARN_IF(aStringParam.IsVoid())) {
|
2019-04-26 18:32:06 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 18:32:06 +03:00
|
|
|
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
MOZ_KnownLive(htmlEditor)->InsertHTMLAsAction(aStringParam, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "InsertHTMLAsAction() failed");
|
2019-05-21 10:45:55 +03:00
|
|
|
return rv;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertHTMLCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::InsertTagCommand
|
|
|
|
*****************************************************************************/
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
StaticRefPtr<InsertTagCommand> InsertTagCommand::sInstance;
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool InsertTagCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-05-03 05:15:18 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return htmlEditor->IsSelectionEditable();
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
// corresponding STATE_ATTRIBUTE is: src (img) and href (a)
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult InsertTagCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-30 07:24:49 +03:00
|
|
|
nsAtom* tagName = GetTagName(aCommand);
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(tagName != nsGkAtoms::hr)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2019-03-30 14:55:29 +03:00
|
|
|
RefPtr<Element> newElement =
|
2019-04-30 07:24:49 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)
|
|
|
|
->CreateElementWithDefaults(MOZ_KnownLive(*tagName));
|
2018-08-10 13:36:24 +03:00
|
|
|
if (NS_WARN_IF(!newElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
nsresult rv =
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)
|
|
|
|
->InsertElementAtSelectionAsAction(newElement, true, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"InsertElementAtSelectionAsAction() failed");
|
2019-05-21 10:44:11 +03:00
|
|
|
return rv;
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
nsresult InsertTagCommand::DoCommandParam(Command aCommand,
|
|
|
|
const nsAString& aStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:44:11 +03:00
|
|
|
MOZ_ASSERT(aCommand != Command::InsertHorizontalRule);
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
if (NS_WARN_IF(aStringParam.IsEmpty())) {
|
2019-04-15 10:29:17 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
nsAtom* tagName = GetTagName(aCommand);
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!tagName)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
|
|
|
// filter out tags we don't know how to insert
|
2019-02-22 11:19:37 +03:00
|
|
|
nsAtom* attribute = nullptr;
|
2019-04-15 10:29:17 +03:00
|
|
|
if (tagName == nsGkAtoms::a) {
|
2019-02-22 11:19:37 +03:00
|
|
|
attribute = nsGkAtoms::href;
|
2019-04-15 10:29:17 +03:00
|
|
|
} else if (tagName == nsGkAtoms::img) {
|
2019-02-22 11:19:37 +03:00
|
|
|
attribute = nsGkAtoms::src;
|
2002-11-20 04:18:23 +03:00
|
|
|
} else {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-03-30 14:55:29 +03:00
|
|
|
RefPtr<Element> newElement =
|
2019-04-30 07:24:49 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)
|
|
|
|
->CreateElementWithDefaults(MOZ_KnownLive(*tagName));
|
2018-08-10 13:36:24 +03:00
|
|
|
if (NS_WARN_IF(!newElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2018-01-30 07:28:00 +03:00
|
|
|
ErrorResult err;
|
2019-05-21 10:45:55 +03:00
|
|
|
newElement->SetAttr(attribute, aStringParam, err);
|
2018-01-30 07:28:00 +03:00
|
|
|
if (NS_WARN_IF(err.Failed())) {
|
|
|
|
return err.StealNSResult();
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
|
|
|
// do actual insertion
|
2019-04-15 10:29:17 +03:00
|
|
|
if (tagName == nsGkAtoms::a) {
|
2019-05-21 10:45:55 +03:00
|
|
|
nsresult rv =
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)
|
|
|
|
->InsertLinkAroundSelectionAsAction(newElement, aPrincipal);
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2019-06-10 13:27:07 +03:00
|
|
|
"InsertLinkAroundSelectionAsAction() failed");
|
2018-08-10 13:36:24 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2019-05-21 10:45:55 +03:00
|
|
|
|
|
|
|
nsresult rv =
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)
|
|
|
|
->InsertElementAtSelectionAsAction(newElement, true, aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"InsertElementAtSelectionAsAction() failed");
|
2019-05-21 10:45:55 +03:00
|
|
|
return rv;
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertTagCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* Helper methods
|
|
|
|
*****************************************************************************/
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed,
|
2019-03-30 14:55:29 +03:00
|
|
|
nsAString& aLocalName)
|
|
|
|
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
|
2017-08-04 09:41:42 +03:00
|
|
|
MOZ_ASSERT(aHTMLEditor);
|
2012-04-14 17:07:37 +04:00
|
|
|
MOZ_ASSERT(aMixed);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aMixed = false;
|
2012-04-14 17:07:37 +04:00
|
|
|
aLocalName.Truncate();
|
2002-05-20 14:48:31 +04:00
|
|
|
|
2012-04-14 17:07:37 +04:00
|
|
|
bool bOL, bUL, bDL;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->GetListState(aMixed, &bOL, &bUL, &bDL);
|
2012-04-14 17:07:37 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (*aMixed) {
|
|
|
|
return NS_OK;
|
2012-04-14 17:07:37 +04:00
|
|
|
}
|
2012-04-14 17:07:37 +04:00
|
|
|
|
|
|
|
if (bOL) {
|
|
|
|
aLocalName.AssignLiteral("ol");
|
|
|
|
} else if (bUL) {
|
|
|
|
aLocalName.AssignLiteral("ul");
|
|
|
|
} else if (bDL) {
|
|
|
|
aLocalName.AssignLiteral("dl");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2018-06-15 19:13:31 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|