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
|
|
|
|
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include <stdio.h> // for printf
|
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-06-15 19:13:31 +03:00
|
|
|
#include "mozilla/HTMLEditorCommands.h"
|
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 "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
|
|
|
|
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
|
|
|
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
|
|
|
|
#include "nsError.h" // for NS_OK, NS_ERROR_FAILURE, etc
|
|
|
|
#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
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIEditor.h" // for nsIEditor
|
|
|
|
#include "nsIHTMLEditor.h" // for nsIHTMLEditor, etc
|
|
|
|
#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
|
2018-06-15 18:56:25 +03:00
|
|
|
static nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
HTMLEditorCommandBase::HTMLEditorCommandBase()
|
2000-05-06 03:20:21 +04:00
|
|
|
{
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
NS_IMPL_ISUPPORTS(HTMLEditorCommandBase, nsIControllerCommand)
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2000-05-06 03:20:21 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::StateUpdatingCommandBase(nsAtom* aTagName)
|
|
|
|
: HTMLEditorCommandBase()
|
|
|
|
, mTagName(aTagName)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2012-05-18 12:29:40 +04:00
|
|
|
MOZ_ASSERT(mTagName);
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::~StateUpdatingCommandBase()
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 09:57:57 +03:00
|
|
|
if (NS_WARN_IF(!editor)) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-04 09:57:57 +03:00
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
|
|
|
return ToggleState(htmlEditor);
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-12-03 01:20:12 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
StateUpdatingCommandBase::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 09:41:42 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
|
|
|
return GetCurrentState(htmlEditor, aParams);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2002-10-06 05:23:18 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
PasteNoFormattingCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2002-10-06 05:23:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2002-10-06 05:23:18 +04:00
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
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
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return htmlEditor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
PasteNoFormattingCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2002-10-06 05:23:18 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-10-06 05:23:18 +04:00
|
|
|
return htmlEditor->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
PasteNoFormattingCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-10-06 05:23:18 +04:00
|
|
|
{
|
2002-12-03 01:20:12 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
PasteNoFormattingCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-10-06 05:23:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enabled = false;
|
2002-11-20 04:18:23 +03:00
|
|
|
nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
|
2002-10-06 05:23:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, enabled);
|
2002-10-06 05:23:18 +04:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
StyleUpdatingCommand::StyleUpdatingCommand(nsAtom* aTagName)
|
|
|
|
: StateUpdatingCommandBase(aTagName)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
StyleUpdatingCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams *aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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
|
|
|
|
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(mTagName, nullptr,
|
2017-08-04 09:41:42 +03:00
|
|
|
EmptyString(),
|
|
|
|
&firstOfSelectionHasProp,
|
|
|
|
&anyOfSelectionHasProp,
|
|
|
|
&allOfSelectionHasProp);
|
2002-12-03 01:20:12 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_ENABLED, NS_SUCCEEDED(rv));
|
|
|
|
params->SetBool(STATE_ALL, allOfSelectionHasProp);
|
|
|
|
params->SetBool(STATE_ANY, anyOfSelectionHasProp);
|
|
|
|
params->SetBool(STATE_MIXED, anyOfSelectionHasProp && !allOfSelectionHasProp);
|
|
|
|
params->SetBool(STATE_BEGIN, firstOfSelectionHasProp);
|
|
|
|
params->SetBool(STATE_END, allOfSelectionHasProp); //not completely accurate
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
StyleUpdatingCommand::ToggleState(HTMLEditor* aHTMLEditor)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 09:57:57 +03:00
|
|
|
if (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;
|
2012-05-18 12:29:40 +04:00
|
|
|
if (mTagName == nsGkAtoms::href || mTagName == 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
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = GetCurrentState(aHTMLEditor, params);
|
|
|
|
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)
|
2012-05-18 12:29:40 +04:00
|
|
|
if (mTagName == nsGkAtoms::b) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
|
|
|
aHTMLEditor->RemoveInlineProperty(nsGkAtoms::strong, nullptr);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (mTagName == nsGkAtoms::i) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
|
|
|
aHTMLEditor->RemoveInlineProperty(nsGkAtoms::em, nullptr);
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (mTagName == nsGkAtoms::strike) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
|
|
|
aHTMLEditor->RemoveInlineProperty(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
|
|
|
}
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlineProperty(mTagName, 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
|
|
|
}
|
|
|
|
|
|
|
|
// Superscript and Subscript styles are mutually exclusive
|
|
|
|
aHTMLEditor->BeginTransaction();
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = NS_OK;
|
2018-06-15 18:56:25 +03:00
|
|
|
if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
|
|
|
|
rv = aHTMLEditor->RemoveInlineProperty(mTagName, nullptr);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2018-06-15 18:56:25 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = aHTMLEditor->SetInlineProperty(mTagName, nullptr, EmptyString());
|
|
|
|
}
|
|
|
|
|
|
|
|
aHTMLEditor->EndTransaction();
|
2002-02-02 08:13:56 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
ListCommand::ListCommand(nsAtom* aTagName)
|
|
|
|
: StateUpdatingCommandBase(aTagName)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ListCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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 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
|
|
|
|
2012-05-18 12:29:40 +04:00
|
|
|
bool inList = mTagName->Equals(localName);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_ALL, !bMixed && inList);
|
|
|
|
params->SetBool(STATE_MIXED, bMixed);
|
|
|
|
params->SetBool(STATE_ENABLED, true);
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ListCommand::ToggleState(HTMLEditor* aHTMLEditor)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 09:57:57 +03:00
|
|
|
if (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();
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = GetCurrentState(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
|
|
|
|
2012-05-18 12:29:40 +04:00
|
|
|
nsDependentAtomString listType(mTagName);
|
|
|
|
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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
ListItemCommand::ListItemCommand(nsAtom* aTagName)
|
|
|
|
: StateUpdatingCommandBase(aTagName)
|
2000-06-06 00:26:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ListItemCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams *aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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 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) {
|
|
|
|
inList = mTagName == nsGkAtoms::li;
|
|
|
|
} else if (bDT) {
|
|
|
|
inList = mTagName == nsGkAtoms::dt;
|
|
|
|
} else if (bDD) {
|
|
|
|
inList = mTagName == nsGkAtoms::dd;
|
|
|
|
}
|
2002-12-03 01:20:12 +03:00
|
|
|
}
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_ALL, !bMixed && inList);
|
|
|
|
params->SetBool(STATE_MIXED, bMixed);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ListItemCommand::ToggleState(HTMLEditor* aHTMLEditor)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 09:57:57 +03:00
|
|
|
if (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
|
|
|
|
|
|
|
// Need to use mTagName????
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
|
|
|
GetCurrentState(aHTMLEditor, params);
|
|
|
|
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?
|
2017-08-04 09:57:57 +03:00
|
|
|
return aHTMLEditor->SetParagraphFormat(nsDependentAtomString(mTagName));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-06-06 00:26:40 +04:00
|
|
|
|
2000-06-16 18:21:46 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveListCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-06-16 18:21:46 +04:00
|
|
|
{
|
2012-04-14 17:07:37 +04:00
|
|
|
*outCmdEnabled = false;
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2000-09-02 05:44:57 +04:00
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
if (!editorBase->IsSelectionEditable()) {
|
2012-04-14 17:07:37 +04:00
|
|
|
return NS_OK;
|
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
|
2017-08-04 09:41:42 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
2012-04-14 17:07:37 +04:00
|
|
|
|
|
|
|
bool bMixed;
|
|
|
|
nsAutoString localName;
|
2017-08-04 12:30:13 +03:00
|
|
|
nsresult rv = GetListState(htmlEditor, &bMixed, localName);
|
2012-04-14 17:07:37 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*outCmdEnabled = bMixed || !localName.IsEmpty();
|
2000-06-16 18:21:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveListCommand::DoCommand(const char* aCommandName, nsISupports* refCon)
|
2000-06-16 18:21:46 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2002-09-12 23:09:01 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// This removes any list type
|
|
|
|
return htmlEditor->RemoveList(EmptyString());
|
2000-06-16 18:21:46 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveListCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveListCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-06-16 18:21:46 +04:00
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IndentCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon, bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IndentCommand::DoCommand(const char* aCommandName, nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return htmlEditor->Indent(NS_LITERAL_STRING("indent"));
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IndentCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IndentCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//OUTDENT
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
OutdentCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
OutdentCommand::DoCommand(const char* aCommandName, nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return htmlEditor->Indent(NS_LITERAL_STRING("outdent"));
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
OutdentCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2015-05-28 18:58:42 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
OutdentCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::MultiStateCommandBase()
|
|
|
|
: HTMLEditorCommandBase()
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::~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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool *outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2002-12-03 01:20:12 +03:00
|
|
|
// should be disabled sometimes, like if the current selection is an image
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::DoCommand(const char* aCommandName, nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
#ifdef DEBUG
|
2018-06-15 19:13:31 +03:00
|
|
|
printf("who is calling MultiStateCommandBase::DoCommand \
|
2002-11-13 02:03:27 +03:00
|
|
|
(no implementation)? %s\n", aCommandName);
|
2002-09-12 23:09:01 +04:00
|
|
|
#endif
|
2015-05-28 18:58:42 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 10:20:56 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString asciiAttribute;
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = params->GetCString(STATE_ATTRIBUTE, asciiAttribute);
|
2018-07-10 12:04:46 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CopyASCIItoUTF16(asciiAttribute, attribute);
|
|
|
|
} else {
|
2018-07-10 14:04:21 +03:00
|
|
|
params->GetString(STATE_ATTRIBUTE, attribute);
|
2018-07-10 12:04:46 +03:00
|
|
|
}
|
2017-08-04 10:20:56 +03:00
|
|
|
}
|
2018-07-10 12:04:46 +03:00
|
|
|
return SetState(htmlEditor, attribute);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-05-10 03:03:41 +04: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
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
MultiStateCommandBase::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 09:41:42 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2017-08-04 09:41:42 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
|
|
|
return GetCurrentState(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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
ParagraphStateCommand::ParagraphStateCommand()
|
|
|
|
: 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ParagraphStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
ParagraphStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
FontFaceStateCommand::FontFaceStateCommand()
|
|
|
|
: 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontFaceStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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)) {
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
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
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontFaceStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
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
|
|
|
{
|
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
|
2017-12-26 06:25:45 +03:00
|
|
|
nsresult rv = aHTMLEditor->SetInlineProperty(nsGkAtoms::tt, nullptr,
|
2017-08-04 10:20:56 +03:00
|
|
|
EmptyString());
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, 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
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font, nsGkAtoms::face);
|
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
|
2017-12-26 06:25:45 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::tt, nullptr);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font, nsGkAtoms::face);
|
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
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font, nsGkAtoms::face,
|
|
|
|
newState);
|
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
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
FontSizeStateCommand::FontSizeStateCommand()
|
|
|
|
: MultiStateCommandBase()
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontSizeStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
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,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::size,
|
2017-08-04 09:41:42 +03:00
|
|
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, anyHas && !allHas);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
|
|
|
params->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
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontSizeStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
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")) {
|
2017-08-04 10:20:56 +03:00
|
|
|
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::size, newState);
|
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
|
2017-08-04 10:20:56 +03:00
|
|
|
nsresult rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::size);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::big, nullptr);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::small, nullptr);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
FontColorStateCommand::FontColorStateCommand()
|
|
|
|
: MultiStateCommandBase()
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontColorStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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);
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
FontColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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")) {
|
2017-08-04 10:20:56 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::color);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font, nsGkAtoms::color,
|
|
|
|
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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
HighlightColorStateCommand::HighlightColorStateCommand()
|
|
|
|
: MultiStateCommandBase()
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
HighlightColorStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
HighlightColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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")) {
|
2017-08-04 10:20:56 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::bgcolor);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2017-08-04 10:20:56 +03:00
|
|
|
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsGkAtoms::bgcolor,
|
2017-08-04 10:20:56 +03:00
|
|
|
newState);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
HighlightColorStateCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
BackgroundColorStateCommand::BackgroundColorStateCommand()
|
|
|
|
: MultiStateCommandBase()
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
BackgroundColorStateCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2012-05-05 13:00:05 +04:00
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
BackgroundColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
AlignCommand::AlignCommand()
|
|
|
|
: MultiStateCommandBase()
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2000-08-24 05:20:29 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
AlignCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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);
|
2018-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
params->SetBool(STATE_MIXED, outMixed);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, tOutStateString);
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
AlignCommand::SetState(HTMLEditor* aHTMLEditor,
|
|
|
|
const nsString& newState)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
AbsolutePositioningCommand::AbsolutePositioningCommand()
|
|
|
|
: StateUpdatingCommandBase(nsGkAtoms::_empty)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
AbsolutePositioningCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* outCmdEnabled)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
*outCmdEnabled = false;
|
|
|
|
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-08-04 12:30:13 +03:00
|
|
|
if (!htmlEditor->IsSelectionEditable()) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = htmlEditor->AbsolutePositioningEnabled();
|
|
|
|
return NS_OK;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
AbsolutePositioningCommand::GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsICommandParams* aParams)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
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-07-10 14:04:21 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2017-08-04 12:30:13 +03:00
|
|
|
bool isEnabled = aHTMLEditor->AbsolutePositioningEnabled();
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!isEnabled) {
|
2018-07-10 14:04:21 +03:00
|
|
|
params->SetBool(STATE_MIXED, false);
|
|
|
|
params->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();
|
2018-07-10 14:04:21 +03:00
|
|
|
params->SetBool(STATE_MIXED, false);
|
|
|
|
params->SetCString(STATE_ATTRIBUTE,
|
|
|
|
container ? NS_LITERAL_CSTRING("absolute") :
|
|
|
|
EmptyCString());
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
AbsolutePositioningCommand::ToggleState(HTMLEditor* aHTMLEditor)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = htmlEditor->AbsolutePositioningEnabled();
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!(*outCmdEnabled))
|
|
|
|
return NS_OK;
|
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
RefPtr<Element> positionedElement = htmlEditor->GetPositionedElement();
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!positionedElement) {
|
|
|
|
return NS_OK;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2018-02-01 04:55:25 +03:00
|
|
|
int32_t z = htmlEditor->GetZIndex(*positionedElement);
|
2017-08-04 11:12:01 +03:00
|
|
|
*outCmdEnabled = (z > 0);
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseZIndexCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseZIndexCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, refCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enabled = false;
|
2003-06-25 12:50:48 +04:00
|
|
|
nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, enabled);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = htmlEditor->AbsolutePositioningEnabled();
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!(*outCmdEnabled))
|
|
|
|
return NS_OK;
|
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
Element* positionedElement = htmlEditor->GetPositionedElement();
|
2012-07-30 18:20:58 +04:00
|
|
|
*outCmdEnabled = (nullptr != positionedElement);
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseZIndexCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseZIndexCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, refCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enabled = false;
|
2003-06-25 12:50:48 +04:00
|
|
|
nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, enabled);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveStylesCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we have any styles?
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveStylesCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return htmlEditor->RemoveAllInlineProperties();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveStylesCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
RemoveStylesCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2011-08-17 21:28:03 +04:00
|
|
|
// test if we are at max size?
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2002-09-12 23:09:01 +04:00
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseFontSizeCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return htmlEditor->IncreaseFontSize();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseFontSizeCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-12-03 01:20:12 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
IncreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2002-12-03 01:20:12 +03:00
|
|
|
// test if we are at min size?
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseFontSizeCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return htmlEditor->DecreaseFontSize();
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseFontSizeCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-12-03 01:20:12 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DecreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertHTMLCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertHTMLCommand::DoCommand(const char* aCommandName, nsISupports* refCon)
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
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
|
|
|
|
NS_ENSURE_ARG_POINTER(refCon);
|
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsAutoString html;
|
|
|
|
return htmlEditor->InsertHTML(html);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertHTMLCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon)
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
NS_ENSURE_ARG_POINTER(refCon);
|
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
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;
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = aParams->AsCommandParams()->GetString(STATE_DATA, html);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-08-04 11:12:01 +03:00
|
|
|
return htmlEditor->InsertHTML(html);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertHTMLCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
NS_ENSURE_ARG_POINTER(refCon);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-11-13 02:03:27 +03:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::InsertTagCommand(nsAtom* aTagName)
|
|
|
|
: HTMLEditorCommandBase()
|
|
|
|
, mTagName(aTagName)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
2012-06-06 11:42:01 +04:00
|
|
|
MOZ_ASSERT(mTagName);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::~InsertTagCommand()
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-04 11:12:01 +03:00
|
|
|
if (!editor) {
|
|
|
|
*outCmdEnabled = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
|
|
MOZ_ASSERT(editorBase);
|
2017-08-04 12:30:13 +03:00
|
|
|
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
|
|
return NS_OK;
|
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)
|
2002-11-20 04:18:23 +03:00
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::DoCommand(const char* aCmdName, nsISupports* refCon)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
2012-06-06 11:42:01 +04:00
|
|
|
NS_ENSURE_TRUE(mTagName == nsGkAtoms::hr, NS_ERROR_NOT_IMPLEMENTED);
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2018-04-27 06:35:18 +03:00
|
|
|
RefPtr<Element> newElement;
|
2017-08-04 11:12:01 +03:00
|
|
|
nsresult rv = htmlEditor->CreateElementWithDefaults(
|
2018-04-27 06:35:18 +03:00
|
|
|
nsDependentAtomString(mTagName), getter_AddRefs(newElement));
|
2012-06-06 11:42:01 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2018-04-27 06:35:18 +03:00
|
|
|
return htmlEditor->InsertElementAtSelection(newElement, true);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(refCon);
|
|
|
|
|
2002-12-17 22:41:00 +03:00
|
|
|
// inserting an hr shouldn't have an parameters, just call DoCommand for that
|
2012-06-06 11:42:01 +04:00
|
|
|
if (mTagName == nsGkAtoms::hr) {
|
2002-12-17 22:41:00 +03:00
|
|
|
return DoCommand(aCommandName, refCon);
|
2012-06-06 11:42:01 +04:00
|
|
|
}
|
2002-12-17 22:41:00 +03:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-11-20 04:18:23 +03:00
|
|
|
|
|
|
|
// do we have an href to use for creating link?
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString asciiAttribute;
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv =
|
|
|
|
aParams->AsCommandParams()->GetCString(STATE_ATTRIBUTE, asciiAttribute);
|
2018-07-10 12:04:46 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsAutoString attribute;
|
|
|
|
CopyASCIItoUTF16(asciiAttribute, attribute);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2018-07-10 12:04:46 +03:00
|
|
|
if (attribute.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
|
|
|
|
nsAutoString attributeType;
|
2012-06-06 11:42:01 +04:00
|
|
|
if (mTagName == nsGkAtoms::a) {
|
2004-06-17 04:13:25 +04:00
|
|
|
attributeType.AssignLiteral("href");
|
2012-06-06 11:42:01 +04:00
|
|
|
} else if (mTagName == nsGkAtoms::img) {
|
2004-06-17 04:13:25 +04:00
|
|
|
attributeType.AssignLiteral("src");
|
2002-11-20 04:18:23 +03:00
|
|
|
} else {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2018-04-27 06:35:18 +03:00
|
|
|
RefPtr<Element> elem;
|
2017-08-04 11:12:01 +03:00
|
|
|
rv = htmlEditor->CreateElementWithDefaults(nsDependentAtomString(mTagName),
|
2018-04-27 06:35:18 +03:00
|
|
|
getter_AddRefs(elem));
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2018-01-30 07:28:00 +03:00
|
|
|
ErrorResult err;
|
2018-07-10 12:04:46 +03:00
|
|
|
elem->SetAttribute(attributeType, attribute, 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
|
2017-08-04 11:12:01 +03:00
|
|
|
if (mTagName == nsGkAtoms::a) {
|
2018-04-27 06:35:18 +03:00
|
|
|
return htmlEditor->InsertLinkAroundSelection(elem);
|
2017-08-04 11:12:01 +03:00
|
|
|
}
|
2018-04-27 06:35:18 +03:00
|
|
|
return htmlEditor->InsertElementAtSelection(elem, true);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
InsertTagCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
2002-11-20 04:18:23 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
NS_ENSURE_ARG_POINTER(refCon);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2002-11-20 04:18:23 +03:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-10 14:04:21 +03:00
|
|
|
return aParams->AsCommandParams()->SetBool(STATE_ENABLED, outCmdEnabled);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
/****************************/
|
|
|
|
//HELPER METHODS
|
|
|
|
/****************************/
|
|
|
|
|
2018-06-15 18:56:25 +03:00
|
|
|
static nsresult
|
2018-06-15 19:13:31 +03:00
|
|
|
GetListState(HTMLEditor* aHTMLEditor, bool* aMixed, nsAString& aLocalName)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
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
|