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"
|
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
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h" // for nsAtom, etc
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIClipboard.h" // for nsIClipboard, etc
|
2019-04-27 10:35:56 +03:00
|
|
|
#include "nsIEditingSession.h"
|
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-03-30 14:55:29 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
|
|
|
|
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-15 10:29:17 +03:00
|
|
|
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom>
|
|
|
|
StateUpdatingCommandBase::sTagNameTable;
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
bool StateUpdatingCommandBase::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2019-04-26 14:06:45 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
if (!aTextEditor->IsSelectionEditable()) {
|
|
|
|
return false;
|
2019-04-26 14:06:45 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
if (!strcmp(aCommandName, "cmd_absPos")) {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
|
|
|
return htmlEditor && 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-26 17:00:47 +03:00
|
|
|
nsresult StateUpdatingCommandBase::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
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-15 10:29:17 +03:00
|
|
|
RefPtr<nsAtom> tagName = TagName(aCommandName);
|
|
|
|
if (NS_WARN_IF(!tagName)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
return ToggleState(tagName, MOZ_KnownLive(htmlEditor));
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult StateUpdatingCommandBase::DoCommandParams(
|
|
|
|
const char* aCommandName, nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult StateUpdatingCommandBase::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
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-15 10:29:17 +03:00
|
|
|
RefPtr<nsAtom> tagName = TagName(aCommandName);
|
|
|
|
if (NS_WARN_IF(!tagName)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2019-04-27 10:36:30 +03:00
|
|
|
return GetCurrentState(tagName, 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-26 16:11:24 +03:00
|
|
|
bool PasteNoFormattingCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// This command is only implemented by nsIHTMLEditor, since
|
2015-05-28 18:58:42 +03:00
|
|
|
// pasting in a plaintext editor automatically only supplies
|
2002-11-20 04:18:23 +03:00
|
|
|
// "unformatted" text
|
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-26 17:00:47 +03:00
|
|
|
nsresult PasteNoFormattingCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
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"
|
|
|
|
return MOZ_KnownLive(htmlEditor)
|
|
|
|
->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult PasteNoFormattingCommand::DoCommandParams(
|
|
|
|
const char* aCommandName, nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult PasteNoFormattingCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* aHTMLEditor) 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(
|
|
|
|
*nsGkAtoms::strong, nullptr);
|
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) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
2018-10-30 13:00:17 +03:00
|
|
|
aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::em, nullptr);
|
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) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
2018-10-30 13:00:17 +03:00
|
|
|
aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::s, nullptr);
|
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-04-15 10:29:17 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*aTagName, nullptr);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
return NS_OK;
|
2018-06-15 18:56:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
nsresult rv =
|
|
|
|
aHTMLEditor->SetInlinePropertyAsAction(*aTagName, nullptr, EmptyString());
|
2018-08-09 14:52:46 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-10-24 07:17:42 +03:00
|
|
|
return NS_OK;
|
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-04-26 17:00:47 +03:00
|
|
|
nsresult ListCommand::ToggleState(nsAtom* aTagName,
|
|
|
|
HTMLEditor* aHTMLEditor) 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) {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = aHTMLEditor->RemoveList(listType);
|
2012-05-18 12:29:40 +04:00
|
|
|
} else {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = aHTMLEditor->MakeOrChangeList(listType, false, EmptyString());
|
2002-12-03 01:20:12 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
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-04-15 10:29:17 +03:00
|
|
|
nsresult ListItemCommand::ToggleState(nsAtom* aTagName,
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* aHTMLEditor) 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;
|
|
|
|
}
|
2017-08-04 09:57:57 +03:00
|
|
|
return aHTMLEditor->RemoveList(localName);
|
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-04-15 10:29:17 +03:00
|
|
|
return aHTMLEditor->SetParagraphFormat(nsDependentAtomString(aTagName));
|
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-26 16:11:24 +03:00
|
|
|
bool RemoveListCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
if (!aTextEditor->IsSelectionEditable()) {
|
|
|
|
return false;
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
2002-09-24 17:29:28 +04:00
|
|
|
|
2012-04-14 17:07:37 +04:00
|
|
|
// It is enabled if we are in any list type
|
2019-04-26 16:11:24 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
2017-08-04 09:41:42 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
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
|
|
|
|
|
|
|
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-04-26 17:00:47 +03:00
|
|
|
nsresult RemoveListCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// This removes any list type
|
|
|
|
return htmlEditor->RemoveList(EmptyString());
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult RemoveListCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult RemoveListCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool IndentCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult IndentCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-08-14 11:30:09 +03:00
|
|
|
nsresult rv = htmlEditor->IndentAsAction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult IndentCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IndentCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool OutdentCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult OutdentCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-08-14 11:30:09 +03:00
|
|
|
nsresult rv = htmlEditor->OutdentAsAction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult OutdentCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult OutdentCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool MultiStateCommandBase::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// should be disabled sometimes, like if the current selection is an image
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult MultiStateCommandBase::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) 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-04-26 18:32:06 +03:00
|
|
|
nsresult MultiStateCommandBase::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
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
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoString attribute;
|
2017-08-04 10:20:56 +03:00
|
|
|
if (aParams) {
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString asciiAttribute;
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult rv = aParams->GetCString(STATE_ATTRIBUTE, asciiAttribute);
|
2018-07-10 12:04:46 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CopyASCIItoUTF16(asciiAttribute, attribute);
|
|
|
|
} else {
|
2019-04-26 18:32:06 +03:00
|
|
|
aParams->GetString(STATE_ATTRIBUTE, attribute);
|
2018-07-10 12:04:46 +03:00
|
|
|
}
|
2017-08-04 10:20:56 +03:00
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
return SetState(MOZ_KnownLive(htmlEditor), attribute);
|
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(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
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-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return aHTMLEditor->SetParagraphFormat(newState);
|
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-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) 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
|
|
|
|
2012-05-05 13:00:05 +04:00
|
|
|
if (newState.EqualsLiteral("tt")) {
|
|
|
|
// The old "teletype" attribute
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::tt, nullptr, EmptyString());
|
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,
|
|
|
|
nsGkAtoms::face);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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
|
2018-10-30 13:00:17 +03:00
|
|
|
nsresult rv =
|
|
|
|
aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::tt, nullptr);
|
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
|
|
|
|
|
|
|
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
|
|
|
nsGkAtoms::face);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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,
|
|
|
|
newState);
|
2018-08-13 08:16:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// acceptable values for "newState" are:
|
|
|
|
// -2
|
|
|
|
// -1
|
|
|
|
// 0
|
|
|
|
// +1
|
|
|
|
// +2
|
|
|
|
// +3
|
|
|
|
// medium
|
|
|
|
// normal
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult FontSizeStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) 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
|
|
|
|
2012-05-05 13:00:05 +04:00
|
|
|
if (!newState.IsEmpty() && !newState.EqualsLiteral("normal") &&
|
|
|
|
!newState.EqualsLiteral("medium")) {
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::size, newState);
|
2018-08-13 08:16:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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
|
2018-10-30 13:00:17 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
|
|
|
nsGkAtoms::size);
|
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
|
|
|
|
2018-10-30 13:00:17 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::big, nullptr);
|
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
|
|
|
|
2018-10-30 13:00:17 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::small, nullptr);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) 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
|
|
|
|
2004-05-23 02:15:22 +04:00
|
|
|
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
|
|
|
nsGkAtoms::color);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::color, newState);
|
2018-08-13 08:16:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult HighlightColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) 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
|
|
|
|
2004-05-23 02:15:22 +04:00
|
|
|
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
|
|
|
|
nsGkAtoms::bgcolor);
|
2018-08-13 09:16:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2018-10-24 07:17:42 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
|
|
|
|
*nsGkAtoms::font, nsGkAtoms::bgcolor, newState);
|
2018-08-13 08:16:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
nsresult BackgroundColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
2019-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return aHTMLEditor->SetBackgroundColor(newState);
|
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-04-26 18:32:06 +03:00
|
|
|
const nsString& newState) const {
|
2017-08-04 10:20:56 +03:00
|
|
|
if (NS_WARN_IF(!aHTMLEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return aHTMLEditor->Align(newState);
|
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(
|
|
|
|
nsAtom* aTagName, HTMLEditor* aHTMLEditor) 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();
|
2018-02-01 04:55:25 +03:00
|
|
|
return aHTMLEditor->SetSelectionToAbsoluteOrStatic(!container);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::DecreaseZIndexCommand
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
StaticRefPtr<DecreaseZIndexCommand> DecreaseZIndexCommand::sInstance;
|
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
bool DecreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
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-26 17:00:47 +03:00
|
|
|
nsresult DecreaseZIndexCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2018-02-01 04:55:25 +03:00
|
|
|
return htmlEditor->AddZIndex(-1);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult DecreaseZIndexCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult DecreaseZIndexCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool IncreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
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-26 17:00:47 +03:00
|
|
|
nsresult IncreaseZIndexCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2018-02-01 04:55:25 +03:00
|
|
|
return htmlEditor->AddZIndex(1);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult IncreaseZIndexCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IncreaseZIndexCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool RemoveStylesCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we have any styles?
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult RemoveStylesCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
return MOZ_KnownLive(htmlEditor)->RemoveAllInlineProperties();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult RemoveStylesCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult RemoveStylesCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool IncreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2011-08-17 21:28:03 +04:00
|
|
|
// test if we are at max size?
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2002-09-12 23:09:01 +04:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult IncreaseFontSizeCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
return MOZ_KnownLive(htmlEditor)->IncreaseFontSize();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult IncreaseFontSizeCommand::DoCommandParams(
|
|
|
|
const char* aCommandName, nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult IncreaseFontSizeCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool DecreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we are at min size?
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult DecreaseFontSizeCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
return MOZ_KnownLive(htmlEditor)->DecreaseFontSize();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult DecreaseFontSizeCommand::DoCommandParams(
|
|
|
|
const char* aCommandName, nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult DecreaseFontSizeCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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-26 16:11:24 +03:00
|
|
|
bool InsertHTMLCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult InsertHTMLCommand::DoCommand(const char* aCommandName,
|
|
|
|
TextEditor& aTextEditor) const {
|
2015-05-14 15:02:00 +03:00
|
|
|
// If nsInsertHTMLCommand is called with no parameters, it was probably called
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
nsAutoString html;
|
2019-03-30 14:55:29 +03:00
|
|
|
return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult InsertHTMLCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
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;
|
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// Get HTML source string to insert from command params
|
|
|
|
nsAutoString html;
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult rv = aParams->GetString(STATE_DATA, html);
|
2018-07-10 14:04:21 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-03-30 14:55:29 +03:00
|
|
|
return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertHTMLCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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;
|
|
|
|
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> InsertTagCommand::sTagNameTable;
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
bool InsertTagCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->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-04-26 17:00:47 +03:00
|
|
|
nsresult InsertTagCommand::DoCommand(const char* aCmdName,
|
|
|
|
TextEditor& aTextEditor) const {
|
2019-04-15 10:29:17 +03:00
|
|
|
RefPtr<nsAtom> tagName = TagName(aCmdName);
|
|
|
|
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-15 10:29:17 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)->CreateElementWithDefaults(*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 =
|
|
|
|
MOZ_KnownLive(htmlEditor)->InsertElementAtSelection(newElement, true);
|
2018-08-10 13:36:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult InsertTagCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsCommandParams* aParams,
|
|
|
|
TextEditor& aTextEditor) const {
|
2002-12-17 22:41:00 +03:00
|
|
|
// inserting an hr shouldn't have an parameters, just call DoCommand for that
|
2019-04-15 10:29:17 +03:00
|
|
|
if (!strcmp(aCommandName, "cmd_insertHR")) {
|
2019-04-26 18:32:06 +03:00
|
|
|
return DoCommand(aCommandName, aTextEditor);
|
2012-06-06 11:42:01 +04:00
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2019-04-15 10:29:17 +03:00
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
RefPtr<nsAtom> tagName = TagName(aCommandName);
|
|
|
|
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
|
|
|
|
2019-02-25 06:30:50 +03:00
|
|
|
// Don't use nsAutoString here because nsCommandParams stores string member
|
|
|
|
// with nsString*. Therefore, nsAutoString always needs to copy the storage
|
|
|
|
// but nsString may avoid it.
|
|
|
|
nsString value;
|
2019-04-26 18:32:06 +03:00
|
|
|
nsresult rv = aParams->GetString(STATE_ATTRIBUTE, value);
|
2019-02-27 03:44:18 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-02-22 11:19:37 +03:00
|
|
|
if (NS_WARN_IF(value.IsEmpty())) {
|
2002-11-20 04:18:23 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2018-07-10 12:04:46 +03:00
|
|
|
}
|
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-15 10:29:17 +03:00
|
|
|
MOZ_KnownLive(htmlEditor)->CreateElementWithDefaults(*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-02-22 11:19:37 +03:00
|
|
|
newElement->SetAttr(attribute, value, 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-03-30 14:55:29 +03:00
|
|
|
rv = MOZ_KnownLive(htmlEditor)->InsertLinkAroundSelection(newElement);
|
2018-08-10 13:36:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2018-08-10 13:36:24 +03:00
|
|
|
|
2019-03-30 14:55:29 +03:00
|
|
|
rv = MOZ_KnownLive(htmlEditor)->InsertElementAtSelection(newElement, true);
|
2018-08-10 13:36:24 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertTagCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
IsCommandEnabled(aCommandName, 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
|