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-01-30 07:28:00 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
|
|
|
|
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
2000-05-02 01:37:38 +04:00
|
|
|
#include "nsComposerCommands.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#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 "nsICommandParams.h" // for nsICommandParams, etc
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIDOMElement.h" // for nsIDOMElement
|
|
|
|
#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-01-30 07:28:00 +03:00
|
|
|
using mozilla::dom::Element;
|
|
|
|
using mozilla::ErrorResult;
|
2012-05-18 12:29:40 +04:00
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
//prototype
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult GetListState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
bool* aMixed,
|
2012-04-14 17:07:37 +04:00
|
|
|
nsAString& aLocalName);
|
2017-08-04 11:12:01 +03:00
|
|
|
nsresult RemoveOneProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp);
|
|
|
|
nsresult RemoveTextProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp);
|
|
|
|
nsresult SetTextProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp);
|
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
|
|
|
|
|
|
|
|
2000-05-06 03:20:21 +04:00
|
|
|
nsBaseComposerCommand::nsBaseComposerCommand()
|
|
|
|
{
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseComposerCommand, nsIControllerCommand)
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2000-05-06 03:20:21 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsBaseStateUpdatingCommand::nsBaseStateUpdatingCommand(nsAtom* aTagName)
|
2000-05-06 03:20:21 +04:00
|
|
|
: nsBaseComposerCommand()
|
2000-05-02 01:37:38 +04:00
|
|
|
, mTagName(aTagName)
|
|
|
|
{
|
2012-05-18 12:29:40 +04:00
|
|
|
MOZ_ASSERT(mTagName);
|
2000-05-02 01:37:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseStateUpdatingCommand::~nsBaseStateUpdatingCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-08 02:05:34 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsBaseStateUpdatingCommand, nsBaseComposerCommand)
|
2000-05-02 01:37:38 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsBaseStateUpdatingCommand::IsCommandEnabled(const char *aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsBaseStateUpdatingCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsBaseStateUpdatingCommand::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
|
2015-05-28 18:58:42 +03:00
|
|
|
nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
2015-05-28 18:58:42 +03:00
|
|
|
nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsPasteNoFormattingCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsICommandParams *aParams,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsPasteNoFormattingCommand::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
|
|
|
|
2002-10-06 05:23:18 +04:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsStyleUpdatingCommand::nsStyleUpdatingCommand(nsAtom* aTagName)
|
2000-05-02 01:37:38 +04:00
|
|
|
: nsBaseStateUpdatingCommand(aTagName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsStyleUpdatingCommand::GetCurrentState(mozilla::HTMLEditor* aHTMLEditor,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
|
|
|
|
|
|
aParams->SetBooleanValue(STATE_ENABLED, NS_SUCCEEDED(rv));
|
2002-11-13 02:03:27 +03:00
|
|
|
aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp);
|
2002-12-03 01:20:12 +03:00
|
|
|
aParams->SetBooleanValue(STATE_ANY, anyOfSelectionHasProp);
|
2002-11-13 02:03:27 +03:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED, anyOfSelectionHasProp
|
|
|
|
&& !allOfSelectionHasProp);
|
2002-12-03 01:20:12 +03:00
|
|
|
aParams->SetBooleanValue(STATE_BEGIN, firstOfSelectionHasProp);
|
|
|
|
aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 09:57:57 +03:00
|
|
|
nsStyleUpdatingCommand::ToggleState(mozilla::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
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
//create some params now...
|
|
|
|
nsresult rv;
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsICommandParams> params =
|
|
|
|
do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
|
2002-09-12 23:09:01 +04:00
|
|
|
if (NS_FAILED(rv) || !params)
|
2002-02-02 08:13:56 +03:00
|
|
|
return rv;
|
|
|
|
|
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
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = GetCurrentState(aHTMLEditor, params);
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-03-04 18:42:44 +03:00
|
|
|
rv = params->GetBooleanValue(STATE_ALL, &doTagRemoval);
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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) {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("strong"));
|
2012-04-04 15:47:13 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (mTagName == nsGkAtoms::i) {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("em"));
|
2012-04-04 15:47:13 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-05-18 12:29:40 +04:00
|
|
|
} else if (mTagName == nsGkAtoms::strike) {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = RemoveTextProperty(aHTMLEditor, NS_LITERAL_STRING("s"));
|
2012-04-04 15:47:13 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = RemoveTextProperty(aHTMLEditor, nsDependentAtomString(mTagName));
|
2012-04-04 15:47:13 +04:00
|
|
|
} else {
|
2002-02-02 08:13:56 +03:00
|
|
|
// Superscript and Subscript styles are mutually exclusive
|
2017-08-04 09:57:57 +03:00
|
|
|
aHTMLEditor->BeginTransaction();
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2012-05-18 12:29:40 +04:00
|
|
|
nsDependentAtomString tagName(mTagName);
|
|
|
|
if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = RemoveTextProperty(aHTMLEditor, tagName);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = SetTextProperty(aHTMLEditor, tagName);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2017-08-04 09:57:57 +03:00
|
|
|
aHTMLEditor->EndTransaction();
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 01:37:38 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsListCommand::nsListCommand(nsAtom* aTagName)
|
2000-05-02 01:37:38 +04:00
|
|
|
: nsBaseStateUpdatingCommand(aTagName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsListCommand::GetCurrentState(mozilla::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
|
|
|
|
aParams->SetBooleanValue(STATE_MIXED, bMixed);
|
2011-10-17 18:59:28 +04:00
|
|
|
aParams->SetBooleanValue(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
|
2017-08-04 09:57:57 +03:00
|
|
|
nsListCommand::ToggleState(mozilla::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;
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsICommandParams> params =
|
|
|
|
do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
|
|
|
|
if (NS_FAILED(rv) || !params)
|
2002-02-02 08:13:56 +03:00
|
|
|
return rv;
|
2002-12-03 01:20:12 +03:00
|
|
|
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = GetCurrentState(aHTMLEditor, params);
|
2012-05-18 12:29:40 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool inList;
|
2002-02-02 08:13:56 +03:00
|
|
|
rv = params->GetBooleanValue(STATE_ALL,&inList);
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsListItemCommand::nsListItemCommand(nsAtom* aTagName)
|
2000-06-06 00:26:40 +04:00
|
|
|
: nsBaseStateUpdatingCommand(aTagName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsListItemCommand::GetCurrentState(mozilla::HTMLEditor* aHTMLEditor,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
|
|
|
|
aParams->SetBooleanValue(STATE_MIXED, bMixed);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 09:57:57 +03:00
|
|
|
nsListItemCommand::ToggleState(mozilla::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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inList;
|
2002-02-02 08:13:56 +03:00
|
|
|
// Need to use mTagName????
|
|
|
|
nsresult rv;
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsICommandParams> params =
|
|
|
|
do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
|
|
|
|
if (NS_FAILED(rv) || !params)
|
2002-02-02 08:13:56 +03:00
|
|
|
return rv;
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = GetCurrentState(aHTMLEditor, params);
|
2002-02-02 08:13:56 +03:00
|
|
|
rv = params->GetBooleanValue(STATE_ALL,&inList);
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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;
|
2017-08-04 09:57:57 +03:00
|
|
|
rv = GetListState(aHTMLEditor, &bMixed, localName);
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-04-14 17:07:37 +04:00
|
|
|
if (localName.IsEmpty() || bMixed) {
|
|
|
|
return rv;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveListCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-07-16 02:04:13 +04:00
|
|
|
nsRemoveListCommand::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
|
2015-05-28 18:58:42 +03:00
|
|
|
nsRemoveListCommand::DoCommandParams(const char *aCommandName,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveListCommand::GetCommandStateParams(const char *aCommandName,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsICommandParams *aParams,
|
2002-11-13 02:03:27 +03:00
|
|
|
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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
2000-06-16 18:21:46 +04:00
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIndentCommand::IsCommandEnabled(const char * aCommandName,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-07-16 02:04:13 +04:00
|
|
|
nsIndentCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIndentCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIndentCommand::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//OUTDENT
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsOutdentCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-07-16 02:04:13 +04:00
|
|
|
nsOutdentCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsOutdentCommand::DoCommandParams(const char *aCommandName,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsICommandParams *aParams,
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsOutdentCommand::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsMultiStateCommand::nsMultiStateCommand()
|
|
|
|
: nsBaseComposerCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMultiStateCommand::~nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-08 02:05:34 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsMultiStateCommand, nsBaseComposerCommand)
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsMultiStateCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-07-16 02:04:13 +04:00
|
|
|
nsMultiStateCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
|
2000-05-02 01:37:38 +04:00
|
|
|
{
|
2002-09-12 23:09:01 +04:00
|
|
|
#ifdef DEBUG
|
2002-11-13 02:03:27 +03:00
|
|
|
printf("who is calling nsMultiStateCommand::DoCommand \
|
|
|
|
(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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsMultiStateCommand::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
|
|
|
|
2017-08-04 10:20:56 +03:00
|
|
|
nsAutoString tString;
|
|
|
|
if (aParams) {
|
2017-08-16 06:58:35 +03:00
|
|
|
nsCString s;
|
2017-08-04 10:20:56 +03:00
|
|
|
nsresult rv = aParams->GetCStringValue(STATE_ATTRIBUTE, getter_Copies(s));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyASCIItoUTF16(s, tString);
|
|
|
|
else
|
|
|
|
aParams->GetStringValue(STATE_ATTRIBUTE, tString);
|
|
|
|
}
|
|
|
|
return SetState(htmlEditor, tString);
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsMultiStateCommand::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
|
|
|
|
|
|
|
nsParagraphStateCommand::nsParagraphStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsParagraphStateCommand::GetCurrentState(mozilla::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED,outMixed);
|
2002-07-16 02:04:13 +04:00
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 10:20:56 +03:00
|
|
|
nsParagraphStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
|
|
|
|
nsFontFaceStateCommand::nsFontFaceStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsFontFaceStateCommand::GetCurrentState(mozilla::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)) {
|
2002-02-02 08:13:56 +03:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED,outMixed);
|
2004-01-14 19:26:32 +03:00
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
|
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
|
2017-08-04 10:20:56 +03:00
|
|
|
nsFontFaceStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-11-20 04:18:23 +03:00
|
|
|
nsFontSizeStateCommand::nsFontSizeStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsFontSizeStateCommand::GetCurrentState(mozilla::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);
|
2002-12-03 01:20:12 +03:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED, anyHas && !allHas);
|
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
2011-10-17 18:59:28 +04:00
|
|
|
aParams->SetBooleanValue(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
|
2017-08-04 10:20:56 +03:00
|
|
|
nsFontSizeStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
nsFontColorStateCommand::nsFontColorStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsFontColorStateCommand::GetCurrentState(mozilla::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);
|
2012-05-05 13:00:05 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED, outMixed);
|
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 10:20:56 +03:00
|
|
|
nsFontColorStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
nsHighlightColorStateCommand::nsHighlightColorStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsHighlightColorStateCommand::GetCurrentState(mozilla::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);
|
2012-05-05 13:00:05 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED, outMixed);
|
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 10:20:56 +03:00
|
|
|
nsHighlightColorStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsHighlightColorStateCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
nsBackgroundColorStateCommand::nsBackgroundColorStateCommand()
|
|
|
|
: nsMultiStateCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
nsBackgroundColorStateCommand::GetCurrentState(mozilla::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);
|
2012-05-05 13:00:05 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED, outMixed);
|
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
|
|
|
return NS_OK;
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 10:20:56 +03:00
|
|
|
nsBackgroundColorStateCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
|
2000-08-24 05:20:29 +04:00
|
|
|
nsAlignCommand::nsAlignCommand()
|
|
|
|
: nsMultiStateCommand()
|
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
|
2017-08-04 09:41:42 +03:00
|
|
|
nsAlignCommand::GetCurrentState(mozilla::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);
|
2002-07-16 02:04:13 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED,outMixed);
|
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
|
2002-02-02 08:13:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 10:20:56 +03:00
|
|
|
nsAlignCommand::SetState(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
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
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
nsAbsolutePositioningCommand::nsAbsolutePositioningCommand()
|
2012-05-18 12:29:40 +04:00
|
|
|
: nsBaseStateUpdatingCommand(nsGkAtoms::_empty)
|
2003-06-25 12:50:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAbsolutePositioningCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2017-08-04 09:41:42 +03:00
|
|
|
nsAbsolutePositioningCommand::GetCurrentState(mozilla::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
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
bool isEnabled = aHTMLEditor->AbsolutePositioningEnabled();
|
2003-06-25 12:50:48 +04:00
|
|
|
if (!isEnabled) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED,false);
|
2003-06-25 12:50:48 +04:00
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, "");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
nsCOMPtr<nsINode> container;
|
2017-08-04 09:41:42 +03:00
|
|
|
nsresult rv =
|
2017-08-04 12:30:13 +03:00
|
|
|
aHTMLEditor->GetAbsolutelyPositionedSelectionContainer(
|
|
|
|
getter_AddRefs(container));
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
nsAutoString outStateString;
|
2017-08-04 12:30:13 +03:00
|
|
|
if (container) {
|
2004-06-17 04:13:25 +04:00
|
|
|
outStateString.AssignLiteral("absolute");
|
2017-08-04 12:30:13 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aParams->SetBooleanValue(STATE_MIXED,false);
|
2006-02-03 17:18:39 +03:00
|
|
|
aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 09:57:57 +03:00
|
|
|
nsAbsolutePositioningCommand::ToggleState(mozilla::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
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
nsCOMPtr<nsINode> container;
|
2017-08-04 09:57:57 +03:00
|
|
|
nsresult rv =
|
2017-08-04 12:30:13 +03:00
|
|
|
aHTMLEditor->GetAbsolutelyPositionedSelectionContainer(
|
|
|
|
getter_AddRefs(container));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2017-08-04 12:30:13 +03:00
|
|
|
return aHTMLEditor->AbsolutePositionSelection(!container);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDecreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
int32_t z;
|
|
|
|
nsresult rv = htmlEditor->GetElementZIndex(positionedElement, &z);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*outCmdEnabled = (z > 0);
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDecreaseZIndexCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *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;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
return htmlEditor->RelativeChangeZIndex(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDecreaseZIndexCommand::DoCommandParams(const char *aCommandName,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsICommandParams *aParams,
|
2003-06-25 12:50:48 +04:00
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, refCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDecreaseZIndexCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIncreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
|
nsIncreaseZIndexCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *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;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
return htmlEditor->RelativeChangeZIndex(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIncreaseZIndexCommand::DoCommandParams(const char *aCommandName,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsICommandParams *aParams,
|
2003-06-25 12:50:48 +04:00
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, refCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIncreaseZIndexCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveStylesCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveStylesCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveStylesCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsRemoveStylesCommand::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIncreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIncreaseFontSizeCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIncreaseFontSizeCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIncreaseFontSizeCommand::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:37:38 +04:00
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsDecreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsDecreaseFontSizeCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsDecreaseFontSizeCommand::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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsDecreaseFontSizeCommand::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);
|
2002-02-02 08:13:56 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertHTMLCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
|
nsInsertHTMLCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
|
|
|
|
{
|
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
|
|
|
|
nsInsertHTMLCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
nsresult rv = aParams->GetStringValue(STATE_DATA, html);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
return htmlEditor->InsertHTML(html);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertHTMLCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2003-09-08 02:05:34 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsInsertTagCommand, nsBaseComposerCommand)
|
2002-11-20 04:18:23 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsInsertTagCommand::nsInsertTagCommand(nsAtom* aTagName)
|
2002-11-20 04:18:23 +03:00
|
|
|
: nsBaseComposerCommand()
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{
|
2012-06-06 11:42:01 +04:00
|
|
|
MOZ_ASSERT(mTagName);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsInsertTagCommand::~nsInsertTagCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertTagCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
|
nsInsertTagCommand::DoCommand(const char *aCmdName, nsISupports *refCon)
|
|
|
|
{
|
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
|
|
|
|
2012-06-06 11:42:01 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> domElem;
|
2017-08-04 11:12:01 +03:00
|
|
|
nsresult rv = htmlEditor->CreateElementWithDefaults(
|
2012-06-06 11:42:01 +04:00
|
|
|
nsDependentAtomString(mTagName), getter_AddRefs(domElem));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-17 22:41:00 +03:00
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
return htmlEditor->InsertElementAtSelection(domElem, true);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertTagCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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?
|
2017-08-16 06:58:35 +03:00
|
|
|
nsCString s;
|
2002-11-20 04:18:23 +03:00
|
|
|
nsresult rv = aParams->GetCStringValue(STATE_ATTRIBUTE, getter_Copies(s));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-07-24 20:23:52 +03:00
|
|
|
nsAutoString attrib;
|
|
|
|
CopyASCIItoUTF16(s, attrib);
|
2002-11-20 04:18:23 +03:00
|
|
|
|
|
|
|
if (attrib.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElem;
|
2017-08-04 11:12:01 +03:00
|
|
|
rv = htmlEditor->CreateElementWithDefaults(nsDependentAtomString(mTagName),
|
|
|
|
getter_AddRefs(domElem));
|
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
|
|
|
nsCOMPtr<Element> elem = do_QueryInterface(domElem);
|
|
|
|
ErrorResult err;
|
|
|
|
elem->SetAttribute(attributeType, attrib, err);
|
|
|
|
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) {
|
|
|
|
return htmlEditor->InsertLinkAroundSelection(domElem);
|
|
|
|
}
|
|
|
|
return htmlEditor->InsertElementAtSelection(domElem, true);
|
2002-11-20 04:18:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertTagCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
/****************************/
|
|
|
|
//HELPER METHODS
|
|
|
|
/****************************/
|
|
|
|
|
2002-02-02 08:13:56 +03:00
|
|
|
nsresult
|
2017-08-04 09:41:42 +03:00
|
|
|
GetListState(mozilla::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
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-08-04 11:12:01 +03:00
|
|
|
RemoveOneProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
MOZ_ASSERT(aHTMLEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
/// XXX Hack alert! Look in nsIEditProperty.h for this
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
|
2012-04-14 17:07:34 +04:00
|
|
|
NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->RemoveInlineProperty(styleAtom, nullptr);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the name of the attribute here should be the contents of the appropriate
|
|
|
|
// tag, e.g. 'b' for bold, 'i' for italics.
|
|
|
|
nsresult
|
2017-08-04 11:12:01 +03:00
|
|
|
RemoveTextProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
MOZ_ASSERT(aHTMLEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2012-04-14 17:07:34 +04:00
|
|
|
if (aProp.LowerCaseEqualsLiteral("all")) {
|
2017-08-04 11:12:01 +03:00
|
|
|
return aHTMLEditor->RemoveAllInlineProperties();
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2017-08-04 11:12:01 +03:00
|
|
|
return RemoveOneProperty(aHTMLEditor, aProp);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// the name of the attribute here should be the contents of the appropriate
|
|
|
|
// tag, e.g. 'b' for bold, 'i' for italics.
|
|
|
|
nsresult
|
2017-08-04 11:12:01 +03:00
|
|
|
SetTextProperty(mozilla::HTMLEditor* aHTMLEditor,
|
|
|
|
const nsAString& aProp)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2017-08-04 11:12:01 +03:00
|
|
|
MOZ_ASSERT(aHTMLEditor);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
/// XXX Hack alert! Look in nsIEditProperty.h for this
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
|
2012-05-05 13:00:05 +04:00
|
|
|
NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2017-12-26 06:25:45 +03:00
|
|
|
return aHTMLEditor->SetInlineProperty(styleAtom, nullptr, EmptyString());
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|