LCOV - code coverage report
Current view: top level - editor/composer - nsComposerCommands.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 713 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 113 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : 
       7             : #include <stdio.h>                      // for printf
       8             : 
       9             : #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
      10             : #include "nsAString.h"
      11             : #include "nsCOMPtr.h"                   // for nsCOMPtr, do_QueryInterface, etc
      12             : #include "nsComponentManagerUtils.h"    // for do_CreateInstance
      13             : #include "nsComposerCommands.h"
      14             : #include "nsDebug.h"                    // for NS_ENSURE_TRUE, etc
      15             : #include "nsError.h"                    // for NS_OK, NS_ERROR_FAILURE, etc
      16             : #include "nsGkAtoms.h"                  // for nsGkAtoms, nsGkAtoms::font, etc
      17             : #include "nsIAtom.h"                    // for nsIAtom, etc
      18             : #include "nsIClipboard.h"               // for nsIClipboard, etc
      19             : #include "nsICommandParams.h"           // for nsICommandParams, etc
      20             : #include "nsID.h"
      21             : #include "nsIDOMElement.h"              // for nsIDOMElement
      22             : #include "nsIEditor.h"                  // for nsIEditor
      23             : #include "nsIHTMLAbsPosEditor.h"        // for nsIHTMLAbsPosEditor
      24             : #include "nsIHTMLEditor.h"              // for nsIHTMLEditor, etc
      25             : #include "nsLiteralString.h"            // for NS_LITERAL_STRING
      26             : #include "nsReadableUtils.h"            // for EmptyString
      27             : #include "nsString.h"                   // for nsAutoString, nsString, etc
      28             : #include "nsStringFwd.h"                // for nsString
      29             : 
      30             : class nsISupports;
      31             : 
      32             : //prototype
      33             : nsresult GetListState(nsIHTMLEditor* aEditor, bool* aMixed,
      34             :                       nsAString& aLocalName);
      35             : nsresult RemoveOneProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
      36             : nsresult RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp);
      37             : nsresult SetTextProperty(nsIHTMLEditor *aEditor, const nsAString& aProp);
      38             : 
      39             : 
      40             : //defines
      41             : #define STATE_ENABLED  "state_enabled"
      42             : #define STATE_ALL "state_all"
      43             : #define STATE_ANY "state_any"
      44             : #define STATE_MIXED "state_mixed"
      45             : #define STATE_BEGIN "state_begin"
      46             : #define STATE_END "state_end"
      47             : #define STATE_ATTRIBUTE "state_attribute"
      48             : #define STATE_DATA "state_data"
      49             : 
      50             : 
      51           0 : nsBaseComposerCommand::nsBaseComposerCommand()
      52             : {
      53           0 : }
      54             : 
      55           0 : NS_IMPL_ISUPPORTS(nsBaseComposerCommand, nsIControllerCommand)
      56             : 
      57             : 
      58           0 : nsBaseStateUpdatingCommand::nsBaseStateUpdatingCommand(nsIAtom* aTagName)
      59             : : nsBaseComposerCommand()
      60           0 : , mTagName(aTagName)
      61             : {
      62           0 :   MOZ_ASSERT(mTagName);
      63           0 : }
      64             : 
      65           0 : nsBaseStateUpdatingCommand::~nsBaseStateUpdatingCommand()
      66             : {
      67           0 : }
      68             : 
      69           0 : NS_IMPL_ISUPPORTS_INHERITED0(nsBaseStateUpdatingCommand, nsBaseComposerCommand)
      70             : 
      71             : NS_IMETHODIMP
      72           0 : nsBaseStateUpdatingCommand::IsCommandEnabled(const char *aCommandName,
      73             :                                              nsISupports *refCon,
      74             :                                              bool *outCmdEnabled)
      75             : {
      76           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
      77           0 :   if (editor)
      78           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
      79             : 
      80           0 :   *outCmdEnabled = false;
      81           0 :   return NS_OK;
      82             : }
      83             : 
      84             : 
      85             : NS_IMETHODIMP
      86           0 : nsBaseStateUpdatingCommand::DoCommand(const char *aCommandName,
      87             :                                       nsISupports *refCon)
      88             : {
      89           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
      90           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_INITIALIZED);
      91             : 
      92           0 :   return ToggleState(editor);
      93             : }
      94             : 
      95             : NS_IMETHODIMP
      96           0 : nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName,
      97             :                                             nsICommandParams *aParams,
      98             :                                             nsISupports *refCon)
      99             : {
     100           0 :   return DoCommand(aCommandName, refCon);
     101             : }
     102             : 
     103             : NS_IMETHODIMP
     104           0 : nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName,
     105             :                                                   nsICommandParams *aParams,
     106             :                                                   nsISupports *refCon)
     107             : {
     108           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     109           0 :   if (editor)
     110           0 :     return GetCurrentState(editor, aParams);
     111             : 
     112           0 :   return NS_OK;
     113             : }
     114             : 
     115             : NS_IMETHODIMP
     116           0 : nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName,
     117             :                                              nsISupports *refCon,
     118             :                                              bool *outCmdEnabled)
     119             : {
     120           0 :   NS_ENSURE_ARG_POINTER(outCmdEnabled);
     121           0 :   *outCmdEnabled = false;
     122             : 
     123             :   // This command is only implemented by nsIHTMLEditor, since
     124             :   //  pasting in a plaintext editor automatically only supplies
     125             :   //  "unformatted" text
     126           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
     127           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
     128             : 
     129           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(htmlEditor);
     130           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
     131             : 
     132           0 :   return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
     133             : }
     134             : 
     135             : 
     136             : NS_IMETHODIMP
     137           0 : nsPasteNoFormattingCommand::DoCommand(const char *aCommandName,
     138             :                                       nsISupports *refCon)
     139             : {
     140           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
     141           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
     142             : 
     143           0 :   return htmlEditor->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
     144             : }
     145             : 
     146             : NS_IMETHODIMP
     147           0 : nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName,
     148             :                                             nsICommandParams *aParams,
     149             :                                             nsISupports *refCon)
     150             : {
     151           0 :   return DoCommand(aCommandName, refCon);
     152             : }
     153             : 
     154             : NS_IMETHODIMP
     155           0 : nsPasteNoFormattingCommand::GetCommandStateParams(const char *aCommandName,
     156             :                                                   nsICommandParams *aParams,
     157             :                                                   nsISupports *refCon)
     158             : {
     159           0 :   NS_ENSURE_ARG_POINTER(aParams);
     160             : 
     161           0 :   bool enabled = false;
     162           0 :   nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
     163           0 :   NS_ENSURE_SUCCESS(rv, rv);
     164             : 
     165           0 :   return aParams->SetBooleanValue(STATE_ENABLED, enabled);
     166             : }
     167             : 
     168           0 : nsStyleUpdatingCommand::nsStyleUpdatingCommand(nsIAtom* aTagName)
     169           0 : : nsBaseStateUpdatingCommand(aTagName)
     170             : {
     171           0 : }
     172             : 
     173             : nsresult
     174           0 : nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor,
     175             :                                         nsICommandParams *aParams)
     176             : {
     177           0 :   NS_ASSERTION(aEditor, "Need editor here");
     178           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     179           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED);
     180             : 
     181           0 :   bool firstOfSelectionHasProp = false;
     182           0 :   bool anyOfSelectionHasProp = false;
     183           0 :   bool allOfSelectionHasProp = false;
     184             : 
     185           0 :   nsresult rv = htmlEditor->GetInlineProperty(mTagName, EmptyString(),
     186           0 :                                               EmptyString(),
     187             :                                               &firstOfSelectionHasProp,
     188             :                                               &anyOfSelectionHasProp,
     189           0 :                                               &allOfSelectionHasProp);
     190             : 
     191           0 :   aParams->SetBooleanValue(STATE_ENABLED, NS_SUCCEEDED(rv));
     192           0 :   aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp);
     193           0 :   aParams->SetBooleanValue(STATE_ANY, anyOfSelectionHasProp);
     194           0 :   aParams->SetBooleanValue(STATE_MIXED, anyOfSelectionHasProp
     195           0 :            && !allOfSelectionHasProp);
     196           0 :   aParams->SetBooleanValue(STATE_BEGIN, firstOfSelectionHasProp);
     197           0 :   aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate
     198           0 :   return NS_OK;
     199             : }
     200             : 
     201             : nsresult
     202           0 : nsStyleUpdatingCommand::ToggleState(nsIEditor *aEditor)
     203             : {
     204           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     205           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NO_INTERFACE);
     206             : 
     207             :   //create some params now...
     208             :   nsresult rv;
     209             :   nsCOMPtr<nsICommandParams> params =
     210           0 :       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
     211           0 :   if (NS_FAILED(rv) || !params)
     212           0 :     return rv;
     213             : 
     214             :   // tags "href" and "name" are special cases in the core editor
     215             :   // they are used to remove named anchor/link and shouldn't be used for insertion
     216             :   bool doTagRemoval;
     217           0 :   if (mTagName == nsGkAtoms::href || mTagName == nsGkAtoms::name) {
     218           0 :     doTagRemoval = true;
     219             :   } else {
     220             :     // check current selection; set doTagRemoval if formatting should be removed
     221           0 :     rv = GetCurrentState(aEditor, params);
     222           0 :     NS_ENSURE_SUCCESS(rv, rv);
     223           0 :     rv = params->GetBooleanValue(STATE_ALL, &doTagRemoval);
     224           0 :     NS_ENSURE_SUCCESS(rv, rv);
     225             :   }
     226             : 
     227           0 :   if (doTagRemoval) {
     228             :     // Also remove equivalent properties (bug 317093)
     229           0 :     if (mTagName == nsGkAtoms::b) {
     230           0 :       rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("strong"));
     231           0 :       NS_ENSURE_SUCCESS(rv, rv);
     232           0 :     } else if (mTagName == nsGkAtoms::i) {
     233           0 :       rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("em"));
     234           0 :       NS_ENSURE_SUCCESS(rv, rv);
     235           0 :     } else if (mTagName == nsGkAtoms::strike) {
     236           0 :       rv = RemoveTextProperty(htmlEditor, NS_LITERAL_STRING("s"));
     237           0 :       NS_ENSURE_SUCCESS(rv, rv);
     238             :     }
     239             : 
     240           0 :     rv = RemoveTextProperty(htmlEditor, nsDependentAtomString(mTagName));
     241             :   } else {
     242             :     // Superscript and Subscript styles are mutually exclusive
     243           0 :     aEditor->BeginTransaction();
     244             : 
     245           0 :     nsDependentAtomString tagName(mTagName);
     246           0 :     if (mTagName == nsGkAtoms::sub || mTagName == nsGkAtoms::sup) {
     247           0 :       rv = RemoveTextProperty(htmlEditor, tagName);
     248             :     }
     249           0 :     if (NS_SUCCEEDED(rv))
     250           0 :       rv = SetTextProperty(htmlEditor, tagName);
     251             : 
     252           0 :     aEditor->EndTransaction();
     253             :   }
     254             : 
     255           0 :   return rv;
     256             : }
     257             : 
     258           0 : nsListCommand::nsListCommand(nsIAtom* aTagName)
     259           0 : : nsBaseStateUpdatingCommand(aTagName)
     260             : {
     261           0 : }
     262             : 
     263             : nsresult
     264           0 : nsListCommand::GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams)
     265             : {
     266           0 :   NS_ASSERTION(aEditor, "Need editor here");
     267           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     268           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NO_INTERFACE);
     269             : 
     270             :   bool bMixed;
     271           0 :   nsAutoString localName;
     272           0 :   nsresult rv = GetListState(htmlEditor, &bMixed, localName);
     273           0 :   NS_ENSURE_SUCCESS(rv, rv);
     274             : 
     275           0 :   bool inList = mTagName->Equals(localName);
     276           0 :   aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
     277           0 :   aParams->SetBooleanValue(STATE_MIXED, bMixed);
     278           0 :   aParams->SetBooleanValue(STATE_ENABLED, true);
     279           0 :   return NS_OK;
     280             : }
     281             : 
     282             : nsresult
     283           0 : nsListCommand::ToggleState(nsIEditor *aEditor)
     284             : {
     285           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
     286           0 :   NS_ENSURE_TRUE(editor, NS_NOINTERFACE);
     287             : 
     288             :   nsresult rv;
     289             :   nsCOMPtr<nsICommandParams> params =
     290           0 :       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
     291           0 :   if (NS_FAILED(rv) || !params)
     292           0 :     return rv;
     293             : 
     294           0 :   rv = GetCurrentState(aEditor, params);
     295           0 :   NS_ENSURE_SUCCESS(rv, rv);
     296             : 
     297             :   bool inList;
     298           0 :   rv = params->GetBooleanValue(STATE_ALL,&inList);
     299           0 :   NS_ENSURE_SUCCESS(rv, rv);
     300             : 
     301           0 :   nsDependentAtomString listType(mTagName);
     302           0 :   if (inList) {
     303           0 :     rv = editor->RemoveList(listType);
     304             :   } else {
     305           0 :     rv = editor->MakeOrChangeList(listType, false, EmptyString());
     306             :   }
     307             : 
     308           0 :   return rv;
     309             : }
     310             : 
     311           0 : nsListItemCommand::nsListItemCommand(nsIAtom* aTagName)
     312           0 : : nsBaseStateUpdatingCommand(aTagName)
     313             : {
     314           0 : }
     315             : 
     316             : nsresult
     317           0 : nsListItemCommand::GetCurrentState(nsIEditor* aEditor,
     318             :                                    nsICommandParams *aParams)
     319             : {
     320           0 :   NS_ASSERTION(aEditor, "Need editor here");
     321             :   // 39584
     322           0 :   nsCOMPtr<nsIHTMLEditor>  htmlEditor = do_QueryInterface(aEditor);
     323           0 :   NS_ENSURE_TRUE(htmlEditor, NS_NOINTERFACE);
     324             : 
     325             :   bool bMixed, bLI, bDT, bDD;
     326           0 :   nsresult rv = htmlEditor->GetListItemState(&bMixed, &bLI, &bDT, &bDD);
     327           0 :   NS_ENSURE_SUCCESS(rv, rv);
     328             : 
     329           0 :   bool inList = false;
     330           0 :   if (!bMixed) {
     331           0 :     if (bLI) {
     332           0 :       inList = mTagName == nsGkAtoms::li;
     333           0 :     } else if (bDT) {
     334           0 :       inList = mTagName == nsGkAtoms::dt;
     335           0 :     } else if (bDD) {
     336           0 :       inList = mTagName == nsGkAtoms::dd;
     337             :     }
     338             :   }
     339             : 
     340           0 :   aParams->SetBooleanValue(STATE_ALL, !bMixed && inList);
     341           0 :   aParams->SetBooleanValue(STATE_MIXED, bMixed);
     342             : 
     343           0 :   return NS_OK;
     344             : }
     345             : 
     346             : nsresult
     347           0 : nsListItemCommand::ToggleState(nsIEditor *aEditor)
     348             : {
     349           0 :   NS_ASSERTION(aEditor, "Need editor here");
     350           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     351           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED);
     352             : 
     353             :   bool inList;
     354             :   // Need to use mTagName????
     355             :   nsresult rv;
     356             :   nsCOMPtr<nsICommandParams> params =
     357           0 :       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
     358           0 :   if (NS_FAILED(rv) || !params)
     359           0 :     return rv;
     360           0 :   rv = GetCurrentState(aEditor, params);
     361           0 :   rv = params->GetBooleanValue(STATE_ALL,&inList);
     362           0 :   NS_ENSURE_SUCCESS(rv, rv);
     363           0 :   NS_ENSURE_SUCCESS(rv, rv);
     364             : 
     365           0 :   if (inList) {
     366             :     // To remove a list, first get what kind of list we're in
     367             :     bool bMixed;
     368           0 :     nsAutoString localName;
     369           0 :     rv = GetListState(htmlEditor, &bMixed, localName);
     370           0 :     NS_ENSURE_SUCCESS(rv, rv);
     371           0 :     if (localName.IsEmpty() || bMixed) {
     372           0 :       return rv;
     373             :     }
     374           0 :     return htmlEditor->RemoveList(localName);
     375             :   }
     376             : 
     377             :   // Set to the requested paragraph type
     378             :   //XXX Note: This actually doesn't work for "LI",
     379             :   //    but we currently don't use this for non DL lists anyway.
     380             :   // Problem: won't this replace any current block paragraph style?
     381           0 :   return htmlEditor->SetParagraphFormat(nsDependentAtomString(mTagName));
     382             : }
     383             : 
     384             : NS_IMETHODIMP
     385           0 : nsRemoveListCommand::IsCommandEnabled(const char * aCommandName,
     386             :                                       nsISupports *refCon,
     387             :                                       bool *outCmdEnabled)
     388             : {
     389           0 :   *outCmdEnabled = false;
     390           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     391           0 :   NS_ENSURE_TRUE(editor, NS_OK);
     392             : 
     393           0 :   bool isEditable = false;
     394           0 :   nsresult rv = editor->GetIsSelectionEditable(&isEditable);
     395           0 :   NS_ENSURE_SUCCESS(rv, rv);
     396           0 :   if (!isEditable) {
     397           0 :     return NS_OK;
     398             :   }
     399             : 
     400             :   // It is enabled if we are in any list type
     401           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
     402           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NO_INTERFACE);
     403             : 
     404             :   bool bMixed;
     405           0 :   nsAutoString localName;
     406           0 :   rv = GetListState(htmlEditor, &bMixed, localName);
     407           0 :   NS_ENSURE_SUCCESS(rv, rv);
     408             : 
     409           0 :   *outCmdEnabled = bMixed || !localName.IsEmpty();
     410           0 :   return NS_OK;
     411             : }
     412             : 
     413             : 
     414             : NS_IMETHODIMP
     415           0 : nsRemoveListCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
     416             : {
     417           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
     418             : 
     419           0 :   nsresult rv = NS_OK;
     420           0 :   if (editor) {
     421             :     // This removes any list type
     422           0 :     rv = editor->RemoveList(EmptyString());
     423             :   }
     424             : 
     425           0 :   return rv;
     426             : }
     427             : 
     428             : NS_IMETHODIMP
     429           0 : nsRemoveListCommand::DoCommandParams(const char *aCommandName,
     430             :                                      nsICommandParams *aParams,
     431             :                                      nsISupports *refCon)
     432             : {
     433           0 :   return DoCommand(aCommandName, refCon);
     434             : }
     435             : 
     436             : NS_IMETHODIMP
     437           0 : nsRemoveListCommand::GetCommandStateParams(const char *aCommandName,
     438             :                                            nsICommandParams *aParams,
     439             :                                            nsISupports *refCon)
     440             : {
     441           0 :   bool outCmdEnabled = false;
     442           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
     443           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
     444             : }
     445             : 
     446             : NS_IMETHODIMP
     447           0 : nsIndentCommand::IsCommandEnabled(const char * aCommandName,
     448             :                                   nsISupports *refCon, bool *outCmdEnabled)
     449             : {
     450           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     451           0 :   if (editor)
     452           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
     453             : 
     454           0 :   *outCmdEnabled = false;
     455           0 :   return NS_OK;
     456             : }
     457             : 
     458             : 
     459             : NS_IMETHODIMP
     460           0 : nsIndentCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
     461             : {
     462           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
     463             : 
     464           0 :   nsresult rv = NS_OK;
     465           0 :   if (editor) {
     466           0 :     rv = editor->Indent(NS_LITERAL_STRING("indent"));
     467             :   }
     468             : 
     469           0 :   return rv;
     470             : }
     471             : 
     472             : NS_IMETHODIMP
     473           0 : nsIndentCommand::DoCommandParams(const char *aCommandName,
     474             :                                  nsICommandParams *aParams,
     475             :                                  nsISupports *refCon)
     476             : {
     477           0 :   return DoCommand(aCommandName, refCon);
     478             : }
     479             : 
     480             : NS_IMETHODIMP
     481           0 : nsIndentCommand::GetCommandStateParams(const char *aCommandName,
     482             :                                        nsICommandParams *aParams,
     483             :                                        nsISupports *refCon)
     484             : {
     485           0 :   bool outCmdEnabled = false;
     486           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
     487           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
     488             : }
     489             : 
     490             : 
     491             : //OUTDENT
     492             : 
     493             : NS_IMETHODIMP
     494           0 : nsOutdentCommand::IsCommandEnabled(const char * aCommandName,
     495             :                                    nsISupports *refCon,
     496             :                                    bool *outCmdEnabled)
     497             : {
     498           0 :   *outCmdEnabled = false;
     499             : 
     500           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     501           0 :   if (editor) {
     502           0 :     nsresult rv = editor->GetIsSelectionEditable(outCmdEnabled);
     503           0 :     NS_ENSURE_SUCCESS(rv, rv);
     504             :   }
     505             : 
     506           0 :   return NS_OK;
     507             : }
     508             : 
     509             : 
     510             : NS_IMETHODIMP
     511           0 : nsOutdentCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
     512             : {
     513           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
     514           0 :   if (htmlEditor)
     515           0 :     return htmlEditor->Indent(NS_LITERAL_STRING("outdent"));
     516             : 
     517           0 :   return NS_OK;
     518             : }
     519             : 
     520             : NS_IMETHODIMP
     521           0 : nsOutdentCommand::DoCommandParams(const char *aCommandName,
     522             :                                   nsICommandParams *aParams,
     523             :                                   nsISupports *refCon)
     524             : {
     525           0 :   return DoCommand(aCommandName, refCon);
     526             : }
     527             : 
     528             : NS_IMETHODIMP
     529           0 : nsOutdentCommand::GetCommandStateParams(const char *aCommandName,
     530             :                                         nsICommandParams *aParams,
     531             :                                         nsISupports *refCon)
     532             : {
     533           0 :   bool outCmdEnabled = false;
     534           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
     535           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
     536             : }
     537             : 
     538           0 : nsMultiStateCommand::nsMultiStateCommand()
     539           0 : : nsBaseComposerCommand()
     540             : {
     541           0 : }
     542             : 
     543           0 : nsMultiStateCommand::~nsMultiStateCommand()
     544             : {
     545           0 : }
     546             : 
     547           0 : NS_IMPL_ISUPPORTS_INHERITED0(nsMultiStateCommand, nsBaseComposerCommand)
     548             : 
     549             : NS_IMETHODIMP
     550           0 : nsMultiStateCommand::IsCommandEnabled(const char * aCommandName,
     551             :                                       nsISupports *refCon,
     552             :                                       bool *outCmdEnabled)
     553             : {
     554           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     555             :   // should be disabled sometimes, like if the current selection is an image
     556           0 :   if (editor)
     557           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
     558             : 
     559           0 :   *outCmdEnabled = false;
     560           0 :   return NS_OK;
     561             : }
     562             : 
     563             : 
     564             : NS_IMETHODIMP
     565           0 : nsMultiStateCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
     566             : {
     567             : #ifdef DEBUG
     568             :   printf("who is calling nsMultiStateCommand::DoCommand \
     569           0 :           (no implementation)? %s\n", aCommandName);
     570             : #endif
     571             : 
     572           0 :   return NS_OK;
     573             : }
     574             : 
     575             : NS_IMETHODIMP
     576           0 : nsMultiStateCommand::DoCommandParams(const char *aCommandName,
     577             :                                      nsICommandParams *aParams,
     578             :                                      nsISupports *refCon)
     579             : {
     580           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     581             : 
     582           0 :   nsresult rv = NS_OK;
     583           0 :   if (editor) {
     584           0 :       nsAutoString tString;
     585             : 
     586           0 :       if (aParams) {
     587           0 :         nsXPIDLCString s;
     588           0 :         rv = aParams->GetCStringValue(STATE_ATTRIBUTE, getter_Copies(s));
     589           0 :         if (NS_SUCCEEDED(rv))
     590           0 :           tString.AssignWithConversion(s);
     591             :         else
     592           0 :           rv = aParams->GetStringValue(STATE_ATTRIBUTE, tString);
     593             :       }
     594             : 
     595           0 :       rv = SetState(editor, tString);
     596             :   }
     597             : 
     598           0 :   return rv;
     599             : }
     600             : 
     601             : NS_IMETHODIMP
     602           0 : nsMultiStateCommand::GetCommandStateParams(const char *aCommandName,
     603             :                                            nsICommandParams *aParams,
     604             :                                            nsISupports *refCon)
     605             : {
     606           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     607           0 :   nsresult rv = NS_OK;
     608           0 :   if (editor) {
     609           0 :       rv = GetCurrentState(editor, aParams);
     610             :   }
     611           0 :   return rv;
     612             : }
     613             : 
     614           0 : nsParagraphStateCommand::nsParagraphStateCommand()
     615           0 : : nsMultiStateCommand()
     616             : {
     617           0 : }
     618             : 
     619             : nsresult
     620           0 : nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor,
     621             :                                          nsICommandParams *aParams)
     622             : {
     623           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     624             : 
     625           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     626           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     627             : 
     628             :   bool outMixed;
     629           0 :   nsAutoString outStateString;
     630           0 :   nsresult rv = htmlEditor->GetParagraphState(&outMixed, outStateString);
     631           0 :   if (NS_SUCCEEDED(rv)) {
     632           0 :     nsAutoCString tOutStateString;
     633           0 :     tOutStateString.AssignWithConversion(outStateString);
     634           0 :     aParams->SetBooleanValue(STATE_MIXED,outMixed);
     635           0 :     aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     636             :   }
     637           0 :   return rv;
     638             : }
     639             : 
     640             : 
     641             : nsresult
     642           0 : nsParagraphStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     643             : {
     644           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     645           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     646           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     647             : 
     648           0 :   return htmlEditor->SetParagraphFormat(newState);
     649             : }
     650             : 
     651           0 : nsFontFaceStateCommand::nsFontFaceStateCommand()
     652           0 : : nsMultiStateCommand()
     653             : {
     654           0 : }
     655             : 
     656             : nsresult
     657           0 : nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor,
     658             :                                         nsICommandParams *aParams)
     659             : {
     660           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     661           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     662           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     663             : 
     664           0 :   nsAutoString outStateString;
     665             :   bool outMixed;
     666           0 :   nsresult rv = htmlEditor->GetFontFaceState(&outMixed, outStateString);
     667           0 :   if (NS_SUCCEEDED(rv)) {
     668           0 :     aParams->SetBooleanValue(STATE_MIXED,outMixed);
     669           0 :     aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
     670             :   }
     671           0 :   return rv;
     672             : }
     673             : 
     674             : 
     675             : nsresult
     676           0 : nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     677             : {
     678           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     679           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     680           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     681             : 
     682           0 :   if (newState.EqualsLiteral("tt")) {
     683             :     // The old "teletype" attribute
     684           0 :     nsresult rv = htmlEditor->SetInlineProperty(nsGkAtoms::tt, EmptyString(),
     685           0 :                                                 EmptyString());
     686           0 :     NS_ENSURE_SUCCESS(rv, rv);
     687             :     // Clear existing font face
     688           0 :     return htmlEditor->RemoveInlineProperty(nsGkAtoms::font,
     689           0 :                                             NS_LITERAL_STRING("face"));
     690             :   }
     691             : 
     692             :   // Remove any existing TT nodes
     693           0 :   nsresult rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::tt, EmptyString());
     694           0 :   NS_ENSURE_SUCCESS(rv, rv);
     695             : 
     696           0 :   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     697           0 :     return htmlEditor->RemoveInlineProperty(nsGkAtoms::font,
     698           0 :                                             NS_LITERAL_STRING("face"));
     699             :   }
     700             : 
     701           0 :   return htmlEditor->SetInlineProperty(nsGkAtoms::font,
     702           0 :                                        NS_LITERAL_STRING("face"), newState);
     703             : }
     704             : 
     705           0 : nsFontSizeStateCommand::nsFontSizeStateCommand()
     706           0 :   : nsMultiStateCommand()
     707             : {
     708           0 : }
     709             : 
     710             : //  nsAutoCString tOutStateString;
     711             : //  tOutStateString.AssignWithConversion(outStateString);
     712             : nsresult
     713           0 : nsFontSizeStateCommand::GetCurrentState(nsIEditor *aEditor,
     714             :                                         nsICommandParams *aParams)
     715             : {
     716           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     717           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     718           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_INVALID_ARG);
     719             : 
     720           0 :   nsAutoString outStateString;
     721           0 :   nsCOMPtr<nsIAtom> fontAtom = NS_Atomize("font");
     722             :   bool firstHas, anyHas, allHas;
     723           0 :   nsresult rv = htmlEditor->GetInlinePropertyWithAttrValue(fontAtom,
     724           0 :                                          NS_LITERAL_STRING("size"),
     725           0 :                                          EmptyString(),
     726             :                                          &firstHas, &anyHas, &allHas,
     727           0 :                                          outStateString);
     728           0 :   NS_ENSURE_SUCCESS(rv, rv);
     729             : 
     730           0 :   nsAutoCString tOutStateString;
     731           0 :   tOutStateString.AssignWithConversion(outStateString);
     732           0 :   aParams->SetBooleanValue(STATE_MIXED, anyHas && !allHas);
     733           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     734           0 :   aParams->SetBooleanValue(STATE_ENABLED, true);
     735             : 
     736           0 :   return rv;
     737             : }
     738             : 
     739             : 
     740             : // acceptable values for "newState" are:
     741             : //   -2
     742             : //   -1
     743             : //    0
     744             : //   +1
     745             : //   +2
     746             : //   +3
     747             : //   medium
     748             : //   normal
     749             : nsresult
     750           0 : nsFontSizeStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     751             : {
     752           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     753           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     754           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_INVALID_ARG);
     755             : 
     756           0 :   if (!newState.IsEmpty() &&
     757           0 :       !newState.EqualsLiteral("normal") &&
     758           0 :       !newState.EqualsLiteral("medium")) {
     759           0 :     return htmlEditor->SetInlineProperty(nsGkAtoms::font,
     760           0 :                                          NS_LITERAL_STRING("size"), newState);
     761             :   }
     762             : 
     763             :   // remove any existing font size, big or small
     764           0 :   nsresult rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::font,
     765           0 :                                                  NS_LITERAL_STRING("size"));
     766           0 :   NS_ENSURE_SUCCESS(rv, rv);
     767             : 
     768           0 :   rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::big, EmptyString());
     769           0 :   NS_ENSURE_SUCCESS(rv, rv);
     770             : 
     771           0 :   return htmlEditor->RemoveInlineProperty(nsGkAtoms::small, EmptyString());
     772             : }
     773             : 
     774           0 : nsFontColorStateCommand::nsFontColorStateCommand()
     775           0 : : nsMultiStateCommand()
     776             : {
     777           0 : }
     778             : 
     779             : nsresult
     780           0 : nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor,
     781             :                                          nsICommandParams *aParams)
     782             : {
     783           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     784             : 
     785           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     786           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     787             : 
     788             :   bool outMixed;
     789           0 :   nsAutoString outStateString;
     790           0 :   nsresult rv = htmlEditor->GetFontColorState(&outMixed, outStateString);
     791           0 :   NS_ENSURE_SUCCESS(rv, rv);
     792             : 
     793           0 :   nsAutoCString tOutStateString;
     794           0 :   tOutStateString.AssignWithConversion(outStateString);
     795           0 :   aParams->SetBooleanValue(STATE_MIXED, outMixed);
     796           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     797           0 :   return NS_OK;
     798             : }
     799             : 
     800             : nsresult
     801           0 : nsFontColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     802             : {
     803           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     804           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     805           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     806             : 
     807           0 :   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     808           0 :     return htmlEditor->RemoveInlineProperty(nsGkAtoms::font,
     809           0 :                                             NS_LITERAL_STRING("color"));
     810             :   }
     811             : 
     812           0 :   return htmlEditor->SetInlineProperty(nsGkAtoms::font,
     813           0 :                                        NS_LITERAL_STRING("color"), newState);
     814             : }
     815             : 
     816           0 : nsHighlightColorStateCommand::nsHighlightColorStateCommand()
     817           0 : : nsMultiStateCommand()
     818             : {
     819           0 : }
     820             : 
     821             : nsresult
     822           0 : nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor,
     823             :                                               nsICommandParams *aParams)
     824             : {
     825           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     826           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     827           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     828             : 
     829             :   bool outMixed;
     830           0 :   nsAutoString outStateString;
     831           0 :   nsresult rv = htmlEditor->GetHighlightColorState(&outMixed, outStateString);
     832           0 :   NS_ENSURE_SUCCESS(rv, rv);
     833             : 
     834           0 :   nsAutoCString tOutStateString;
     835           0 :   tOutStateString.AssignWithConversion(outStateString);
     836           0 :   aParams->SetBooleanValue(STATE_MIXED, outMixed);
     837           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     838           0 :   return NS_OK;
     839             : }
     840             : 
     841             : nsresult
     842           0 : nsHighlightColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     843             : {
     844           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     845           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     846           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     847             : 
     848           0 :   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     849           0 :     return htmlEditor->RemoveInlineProperty(nsGkAtoms::font,
     850           0 :                                             NS_LITERAL_STRING("bgcolor"));
     851             :   }
     852             : 
     853           0 :   return htmlEditor->SetInlineProperty(nsGkAtoms::font,
     854           0 :                                        NS_LITERAL_STRING("bgcolor"),
     855           0 :                                        newState);
     856             : }
     857             : 
     858             : NS_IMETHODIMP
     859           0 : nsHighlightColorStateCommand::IsCommandEnabled(const char * aCommandName,
     860             :                                                nsISupports *refCon,
     861             :                                                bool *outCmdEnabled)
     862             : {
     863           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     864           0 :   if (editor)
     865           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
     866             : 
     867           0 :   *outCmdEnabled = false;
     868           0 :   return NS_OK;
     869             : }
     870             : 
     871             : 
     872           0 : nsBackgroundColorStateCommand::nsBackgroundColorStateCommand()
     873           0 : : nsMultiStateCommand()
     874             : {
     875           0 : }
     876             : 
     877             : nsresult
     878           0 : nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor,
     879             :                                                nsICommandParams *aParams)
     880             : {
     881           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     882             : 
     883           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     884           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     885             : 
     886             :   bool outMixed;
     887           0 :   nsAutoString outStateString;
     888           0 :   nsresult rv =  htmlEditor->GetBackgroundColorState(&outMixed, outStateString);
     889           0 :   NS_ENSURE_SUCCESS(rv, rv);
     890             : 
     891           0 :   nsAutoCString tOutStateString;
     892           0 :   tOutStateString.AssignWithConversion(outStateString);
     893           0 :   aParams->SetBooleanValue(STATE_MIXED, outMixed);
     894           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     895           0 :   return NS_OK;
     896             : }
     897             : 
     898             : nsresult
     899           0 : nsBackgroundColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
     900             : {
     901           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     902             : 
     903           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     904           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     905             : 
     906           0 :   return htmlEditor->SetBackgroundColor(newState);
     907             : }
     908             : 
     909           0 : nsAlignCommand::nsAlignCommand()
     910           0 : : nsMultiStateCommand()
     911             : {
     912           0 : }
     913             : 
     914             : nsresult
     915           0 : nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams)
     916             : {
     917           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     918             : 
     919           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     920           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     921             : 
     922             :   nsIHTMLEditor::EAlignment firstAlign;
     923             :   bool outMixed;
     924           0 :   nsresult rv = htmlEditor->GetAlignment(&outMixed, &firstAlign);
     925             : 
     926           0 :   NS_ENSURE_SUCCESS(rv, rv);
     927             : 
     928           0 :   nsAutoString outStateString;
     929           0 :   switch (firstAlign) {
     930             :     default:
     931             :     case nsIHTMLEditor::eLeft:
     932           0 :       outStateString.AssignLiteral("left");
     933           0 :       break;
     934             : 
     935             :     case nsIHTMLEditor::eCenter:
     936           0 :       outStateString.AssignLiteral("center");
     937           0 :       break;
     938             : 
     939             :     case nsIHTMLEditor::eRight:
     940           0 :       outStateString.AssignLiteral("right");
     941           0 :       break;
     942             : 
     943             :     case nsIHTMLEditor::eJustify:
     944           0 :       outStateString.AssignLiteral("justify");
     945           0 :       break;
     946             :   }
     947           0 :   nsAutoCString tOutStateString;
     948           0 :   tOutStateString.AssignWithConversion(outStateString);
     949           0 :   aParams->SetBooleanValue(STATE_MIXED,outMixed);
     950           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get());
     951           0 :   return NS_OK;
     952             : }
     953             : 
     954             : nsresult
     955           0 : nsAlignCommand::SetState(nsIEditor *aEditor, nsString& newState)
     956             : {
     957           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     958             : 
     959           0 :   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
     960           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     961             : 
     962           0 :   return htmlEditor->Align(newState);
     963             : }
     964             : 
     965           0 : nsAbsolutePositioningCommand::nsAbsolutePositioningCommand()
     966           0 : : nsBaseStateUpdatingCommand(nsGkAtoms::_empty)
     967             : {
     968           0 : }
     969             : 
     970             : NS_IMETHODIMP
     971           0 : nsAbsolutePositioningCommand::IsCommandEnabled(const char * aCommandName,
     972             :                                                nsISupports *aCommandRefCon,
     973             :                                                bool *outCmdEnabled)
     974             : {
     975           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
     976           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aCommandRefCon);
     977           0 :   if (htmlEditor) {
     978           0 :     bool isEditable = false;
     979           0 :     nsresult rv = editor->GetIsSelectionEditable(&isEditable);
     980           0 :     NS_ENSURE_SUCCESS(rv, rv);
     981           0 :     if (isEditable)
     982           0 :       return htmlEditor->GetAbsolutePositioningEnabled(outCmdEnabled);
     983             :   }
     984             : 
     985           0 :   *outCmdEnabled = false;
     986           0 :   return NS_OK;
     987             : }
     988             : 
     989             : nsresult
     990           0 : nsAbsolutePositioningCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams)
     991             : {
     992           0 :   NS_ASSERTION(aEditor, "Need an editor here");
     993             : 
     994           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor);
     995           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
     996             : 
     997             :   bool isEnabled;
     998           0 :   htmlEditor->GetAbsolutePositioningEnabled(&isEnabled);
     999           0 :   if (!isEnabled) {
    1000           0 :     aParams->SetBooleanValue(STATE_MIXED,false);
    1001           0 :     aParams->SetCStringValue(STATE_ATTRIBUTE, "");
    1002           0 :     return NS_OK;
    1003             :   }
    1004             : 
    1005           0 :   nsCOMPtr<nsIDOMElement>  elt;
    1006           0 :   nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
    1007           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1008             : 
    1009           0 :   nsAutoString outStateString;
    1010           0 :   if (elt)
    1011           0 :     outStateString.AssignLiteral("absolute");
    1012             : 
    1013           0 :   aParams->SetBooleanValue(STATE_MIXED,false);
    1014           0 :   aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
    1015           0 :   return NS_OK;
    1016             : }
    1017             : 
    1018             : nsresult
    1019           0 : nsAbsolutePositioningCommand::ToggleState(nsIEditor *aEditor)
    1020             : {
    1021           0 :   NS_ASSERTION(aEditor, "Need an editor here");
    1022             : 
    1023           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor);
    1024           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
    1025             : 
    1026           0 :   nsCOMPtr<nsIDOMElement> elt;
    1027           0 :   nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
    1028           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1029             : 
    1030           0 :   return htmlEditor->AbsolutePositionSelection(!elt);
    1031             : }
    1032             : 
    1033             : 
    1034             : NS_IMETHODIMP
    1035           0 : nsDecreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
    1036             :                                           nsISupports *refCon,
    1037             :                                           bool *outCmdEnabled)
    1038             : {
    1039           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
    1040           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
    1041             : 
    1042           0 :   htmlEditor->GetAbsolutePositioningEnabled(outCmdEnabled);
    1043           0 :   if (!(*outCmdEnabled))
    1044           0 :     return NS_OK;
    1045             : 
    1046           0 :   nsCOMPtr<nsIDOMElement> positionedElement;
    1047           0 :   htmlEditor->GetPositionedElement(getter_AddRefs(positionedElement));
    1048           0 :   *outCmdEnabled = false;
    1049           0 :   if (positionedElement) {
    1050             :     int32_t z;
    1051           0 :     nsresult rv = htmlEditor->GetElementZIndex(positionedElement, &z);
    1052           0 :     NS_ENSURE_SUCCESS(rv, rv);
    1053           0 :     *outCmdEnabled = (z > 0);
    1054             :   }
    1055             : 
    1056           0 :   return NS_OK;
    1057             : }
    1058             : 
    1059             : NS_IMETHODIMP
    1060           0 : nsDecreaseZIndexCommand::DoCommand(const char *aCommandName,
    1061             :                                    nsISupports *refCon)
    1062             : {
    1063           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
    1064           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
    1065             : 
    1066           0 :   return htmlEditor->RelativeChangeZIndex(-1);
    1067             : }
    1068             : 
    1069             : NS_IMETHODIMP
    1070           0 : nsDecreaseZIndexCommand::DoCommandParams(const char *aCommandName,
    1071             :                                          nsICommandParams *aParams,
    1072             :                                          nsISupports *refCon)
    1073             : {
    1074           0 :   return DoCommand(aCommandName, refCon);
    1075             : }
    1076             : 
    1077             : NS_IMETHODIMP
    1078           0 : nsDecreaseZIndexCommand::GetCommandStateParams(const char *aCommandName,
    1079             :                                                nsICommandParams *aParams,
    1080             :                                                nsISupports *refCon)
    1081             : {
    1082           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1083             : 
    1084           0 :   bool enabled = false;
    1085           0 :   nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
    1086           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1087             : 
    1088           0 :   return aParams->SetBooleanValue(STATE_ENABLED, enabled);
    1089             : }
    1090             : 
    1091             : NS_IMETHODIMP
    1092           0 : nsIncreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
    1093             :                                           nsISupports *refCon,
    1094             :                                           bool *outCmdEnabled)
    1095             : {
    1096           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
    1097           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
    1098             : 
    1099           0 :   htmlEditor->GetAbsolutePositioningEnabled(outCmdEnabled);
    1100           0 :   if (!(*outCmdEnabled))
    1101           0 :     return NS_OK;
    1102             : 
    1103           0 :   nsCOMPtr<nsIDOMElement> positionedElement;
    1104           0 :   htmlEditor->GetPositionedElement(getter_AddRefs(positionedElement));
    1105           0 :   *outCmdEnabled = (nullptr != positionedElement);
    1106           0 :   return NS_OK;
    1107             : }
    1108             : 
    1109             : NS_IMETHODIMP
    1110           0 : nsIncreaseZIndexCommand::DoCommand(const char *aCommandName,
    1111             :                                    nsISupports *refCon)
    1112             : {
    1113           0 :   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
    1114           0 :   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
    1115             : 
    1116           0 :   return htmlEditor->RelativeChangeZIndex(1);
    1117             : }
    1118             : 
    1119             : NS_IMETHODIMP
    1120           0 : nsIncreaseZIndexCommand::DoCommandParams(const char *aCommandName,
    1121             :                                          nsICommandParams *aParams,
    1122             :                                          nsISupports *refCon)
    1123             : {
    1124           0 :   return DoCommand(aCommandName, refCon);
    1125             : }
    1126             : 
    1127             : NS_IMETHODIMP
    1128           0 : nsIncreaseZIndexCommand::GetCommandStateParams(const char *aCommandName,
    1129             :                                                nsICommandParams *aParams,
    1130             :                                                nsISupports *refCon)
    1131             : {
    1132           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1133             : 
    1134           0 :   bool enabled = false;
    1135           0 :   nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
    1136           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1137             : 
    1138           0 :   return aParams->SetBooleanValue(STATE_ENABLED, enabled);
    1139             : }
    1140             : 
    1141             : 
    1142             : NS_IMETHODIMP
    1143           0 : nsRemoveStylesCommand::IsCommandEnabled(const char * aCommandName,
    1144             :                                         nsISupports *refCon,
    1145             :                                         bool *outCmdEnabled)
    1146             : {
    1147           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
    1148             :   // test if we have any styles?
    1149           0 :   if (editor)
    1150           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
    1151             : 
    1152           0 :   *outCmdEnabled = false;
    1153           0 :   return NS_OK;
    1154             : }
    1155             : 
    1156             : 
    1157             : 
    1158             : NS_IMETHODIMP
    1159           0 : nsRemoveStylesCommand::DoCommand(const char *aCommandName,
    1160             :                                  nsISupports *refCon)
    1161             : {
    1162           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1163             : 
    1164           0 :   nsresult rv = NS_OK;
    1165           0 :   if (editor) {
    1166           0 :     rv = editor->RemoveAllInlineProperties();
    1167             :   }
    1168             : 
    1169           0 :   return rv;
    1170             : }
    1171             : 
    1172             : NS_IMETHODIMP
    1173           0 : nsRemoveStylesCommand::DoCommandParams(const char *aCommandName,
    1174             :                                        nsICommandParams *aParams,
    1175             :                                        nsISupports *refCon)
    1176             : {
    1177           0 :   return DoCommand(aCommandName, refCon);
    1178             : }
    1179             : 
    1180             : NS_IMETHODIMP
    1181           0 : nsRemoveStylesCommand::GetCommandStateParams(const char *aCommandName,
    1182             :                                              nsICommandParams *aParams,
    1183             :                                              nsISupports *refCon)
    1184             : {
    1185           0 :   bool outCmdEnabled = false;
    1186           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
    1187           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
    1188             : }
    1189             : 
    1190             : NS_IMETHODIMP
    1191           0 : nsIncreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName,
    1192             :                                             nsISupports *refCon,
    1193             :                                             bool *outCmdEnabled)
    1194             : {
    1195           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
    1196             :   // test if we are at max size?
    1197           0 :   if (editor)
    1198           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
    1199             : 
    1200           0 :   *outCmdEnabled = false;
    1201           0 :   return NS_OK;
    1202             : }
    1203             : 
    1204             : 
    1205             : NS_IMETHODIMP
    1206           0 : nsIncreaseFontSizeCommand::DoCommand(const char *aCommandName,
    1207             :                                      nsISupports *refCon)
    1208             : {
    1209           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1210             : 
    1211           0 :   nsresult rv = NS_OK;
    1212           0 :   if (editor) {
    1213           0 :     rv = editor->IncreaseFontSize();
    1214             :   }
    1215             : 
    1216           0 :   return rv;
    1217             : }
    1218             : 
    1219             : NS_IMETHODIMP
    1220           0 : nsIncreaseFontSizeCommand::DoCommandParams(const char *aCommandName,
    1221             :                                            nsICommandParams *aParams,
    1222             :                                            nsISupports *refCon)
    1223             : {
    1224           0 :   return DoCommand(aCommandName, refCon);
    1225             : }
    1226             : 
    1227             : NS_IMETHODIMP
    1228           0 : nsIncreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName,
    1229             :                                                  nsICommandParams *aParams,
    1230             :                                                  nsISupports *refCon)
    1231             : {
    1232           0 :   bool outCmdEnabled = false;
    1233           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
    1234           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
    1235             : }
    1236             : 
    1237             : NS_IMETHODIMP
    1238           0 : nsDecreaseFontSizeCommand::IsCommandEnabled(const char * aCommandName,
    1239             :                                             nsISupports *refCon,
    1240             :                                             bool *outCmdEnabled)
    1241             : {
    1242           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
    1243             :   // test if we are at min size?
    1244           0 :   if (editor)
    1245           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
    1246             : 
    1247           0 :   *outCmdEnabled = false;
    1248           0 :   return NS_OK;
    1249             : }
    1250             : 
    1251             : 
    1252             : NS_IMETHODIMP
    1253           0 : nsDecreaseFontSizeCommand::DoCommand(const char *aCommandName,
    1254             :                                      nsISupports *refCon)
    1255             : {
    1256           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1257             : 
    1258           0 :   nsresult rv = NS_OK;
    1259           0 :   if (editor) {
    1260           0 :     rv = editor->DecreaseFontSize();
    1261             :   }
    1262             : 
    1263           0 :   return rv;
    1264             : }
    1265             : 
    1266             : NS_IMETHODIMP
    1267           0 : nsDecreaseFontSizeCommand::DoCommandParams(const char *aCommandName,
    1268             :                                            nsICommandParams *aParams,
    1269             :                                            nsISupports *refCon)
    1270             : {
    1271           0 :   return DoCommand(aCommandName, refCon);
    1272             : }
    1273             : 
    1274             : NS_IMETHODIMP
    1275           0 : nsDecreaseFontSizeCommand::GetCommandStateParams(const char *aCommandName,
    1276             :                                                  nsICommandParams *aParams,
    1277             :                                                  nsISupports *refCon)
    1278             : {
    1279           0 :   bool outCmdEnabled = false;
    1280           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
    1281           0 :   return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled);
    1282             : }
    1283             : 
    1284             : NS_IMETHODIMP
    1285           0 : nsInsertHTMLCommand::IsCommandEnabled(const char * aCommandName,
    1286             :                                       nsISupports *refCon,
    1287             :                                       bool *outCmdEnabled)
    1288             : {
    1289           0 :   NS_ENSURE_ARG_POINTER(outCmdEnabled);
    1290           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
    1291           0 :   if (editor)
    1292           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
    1293             : 
    1294           0 :   *outCmdEnabled = false;
    1295           0 :   return NS_OK;
    1296             : }
    1297             : 
    1298             : 
    1299             : NS_IMETHODIMP
    1300           0 : nsInsertHTMLCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
    1301             : {
    1302             :   // If nsInsertHTMLCommand is called with no parameters, it was probably called with
    1303             :   // an empty string parameter ''. In this case, it should act the same as the delete command
    1304           0 :   NS_ENSURE_ARG_POINTER(refCon);
    1305             : 
    1306           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1307           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
    1308             : 
    1309           0 :   nsString html = EmptyString();
    1310           0 :   return editor->InsertHTML(html);
    1311             : }
    1312             : 
    1313             : NS_IMETHODIMP
    1314           0 : nsInsertHTMLCommand::DoCommandParams(const char *aCommandName,
    1315             :                                      nsICommandParams *aParams,
    1316             :                                      nsISupports *refCon)
    1317             : {
    1318           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1319           0 :   NS_ENSURE_ARG_POINTER(refCon);
    1320             : 
    1321           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1322           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
    1323             : 
    1324             :   // Get HTML source string to insert from command params
    1325           0 :   nsAutoString html;
    1326           0 :   nsresult rv = aParams->GetStringValue(STATE_DATA, html);
    1327           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1328             : 
    1329           0 :   return editor->InsertHTML(html);
    1330             : }
    1331             : 
    1332             : NS_IMETHODIMP
    1333           0 : nsInsertHTMLCommand::GetCommandStateParams(const char *aCommandName,
    1334             :                                            nsICommandParams *aParams,
    1335             :                                            nsISupports *refCon)
    1336             : {
    1337           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1338           0 :   NS_ENSURE_ARG_POINTER(refCon);
    1339             : 
    1340           0 :   bool outCmdEnabled = false;
    1341           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
    1342           0 :   return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
    1343             : }
    1344             : 
    1345           0 : NS_IMPL_ISUPPORTS_INHERITED0(nsInsertTagCommand, nsBaseComposerCommand)
    1346             : 
    1347           0 : nsInsertTagCommand::nsInsertTagCommand(nsIAtom* aTagName)
    1348             : : nsBaseComposerCommand()
    1349           0 : , mTagName(aTagName)
    1350             : {
    1351           0 :   MOZ_ASSERT(mTagName);
    1352           0 : }
    1353             : 
    1354           0 : nsInsertTagCommand::~nsInsertTagCommand()
    1355             : {
    1356           0 : }
    1357             : 
    1358             : NS_IMETHODIMP
    1359           0 : nsInsertTagCommand::IsCommandEnabled(const char * aCommandName,
    1360             :                                      nsISupports *refCon,
    1361             :                                      bool *outCmdEnabled)
    1362             : {
    1363           0 :   NS_ENSURE_ARG_POINTER(outCmdEnabled);
    1364           0 :   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
    1365           0 :   if (editor)
    1366           0 :     return editor->GetIsSelectionEditable(outCmdEnabled);
    1367             : 
    1368           0 :   *outCmdEnabled = false;
    1369           0 :   return NS_OK;
    1370             : }
    1371             : 
    1372             : 
    1373             : // corresponding STATE_ATTRIBUTE is: src (img) and href (a)
    1374             : NS_IMETHODIMP
    1375           0 : nsInsertTagCommand::DoCommand(const char *aCmdName, nsISupports *refCon)
    1376             : {
    1377           0 :   NS_ENSURE_TRUE(mTagName == nsGkAtoms::hr, NS_ERROR_NOT_IMPLEMENTED);
    1378             : 
    1379           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1380           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
    1381             : 
    1382           0 :   nsCOMPtr<nsIDOMElement> domElem;
    1383           0 :   nsresult rv = editor->CreateElementWithDefaults(
    1384           0 :     nsDependentAtomString(mTagName), getter_AddRefs(domElem));
    1385           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1386             : 
    1387           0 :   return editor->InsertElementAtSelection(domElem, true);
    1388             : }
    1389             : 
    1390             : NS_IMETHODIMP
    1391           0 : nsInsertTagCommand::DoCommandParams(const char *aCommandName,
    1392             :                                     nsICommandParams *aParams,
    1393             :                                     nsISupports *refCon)
    1394             : {
    1395           0 :   NS_ENSURE_ARG_POINTER(refCon);
    1396             : 
    1397             :   // inserting an hr shouldn't have an parameters, just call DoCommand for that
    1398           0 :   if (mTagName == nsGkAtoms::hr) {
    1399           0 :     return DoCommand(aCommandName, refCon);
    1400             :   }
    1401             : 
    1402           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1403             : 
    1404           0 :   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
    1405           0 :   NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
    1406             : 
    1407             :   // do we have an href to use for creating link?
    1408           0 :   nsXPIDLCString s;
    1409           0 :   nsresult rv = aParams->GetCStringValue(STATE_ATTRIBUTE, getter_Copies(s));
    1410           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1411           0 :   nsAutoString attrib; attrib.AssignWithConversion(s);
    1412             : 
    1413           0 :   if (attrib.IsEmpty())
    1414           0 :     return NS_ERROR_INVALID_ARG;
    1415             : 
    1416             :   // filter out tags we don't know how to insert
    1417           0 :   nsAutoString attributeType;
    1418           0 :   if (mTagName == nsGkAtoms::a) {
    1419           0 :     attributeType.AssignLiteral("href");
    1420           0 :   } else if (mTagName == nsGkAtoms::img) {
    1421           0 :     attributeType.AssignLiteral("src");
    1422             :   } else {
    1423           0 :     return NS_ERROR_NOT_IMPLEMENTED;
    1424             :   }
    1425             : 
    1426           0 :   nsCOMPtr<nsIDOMElement> domElem;
    1427           0 :   rv = editor->CreateElementWithDefaults(nsDependentAtomString(mTagName),
    1428           0 :                                          getter_AddRefs(domElem));
    1429           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1430             : 
    1431           0 :   rv = domElem->SetAttribute(attributeType, attrib);
    1432           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1433             : 
    1434             :   // do actual insertion
    1435           0 :   if (mTagName == nsGkAtoms::a)
    1436           0 :     return editor->InsertLinkAroundSelection(domElem);
    1437             : 
    1438           0 :   return editor->InsertElementAtSelection(domElem, true);
    1439             : }
    1440             : 
    1441             : NS_IMETHODIMP
    1442           0 : nsInsertTagCommand::GetCommandStateParams(const char *aCommandName,
    1443             :                                           nsICommandParams *aParams,
    1444             :                                           nsISupports *refCon)
    1445             : {
    1446           0 :   NS_ENSURE_ARG_POINTER(aParams);
    1447           0 :   NS_ENSURE_ARG_POINTER(refCon);
    1448             : 
    1449           0 :   bool outCmdEnabled = false;
    1450           0 :   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
    1451           0 :   return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
    1452             : }
    1453             : 
    1454             : 
    1455             : /****************************/
    1456             : //HELPER METHODS
    1457             : /****************************/
    1458             : 
    1459             : nsresult
    1460           0 : GetListState(nsIHTMLEditor* aEditor, bool* aMixed, nsAString& aLocalName)
    1461             : {
    1462           0 :   MOZ_ASSERT(aEditor);
    1463           0 :   MOZ_ASSERT(aMixed);
    1464             : 
    1465           0 :   *aMixed = false;
    1466           0 :   aLocalName.Truncate();
    1467             : 
    1468             :   bool bOL, bUL, bDL;
    1469           0 :   nsresult rv = aEditor->GetListState(aMixed, &bOL, &bUL, &bDL);
    1470           0 :   NS_ENSURE_SUCCESS(rv, rv);
    1471             : 
    1472           0 :   if (*aMixed) {
    1473           0 :     return NS_OK;
    1474             :   }
    1475             : 
    1476           0 :   if (bOL) {
    1477           0 :     aLocalName.AssignLiteral("ol");
    1478           0 :   } else if (bUL) {
    1479           0 :     aLocalName.AssignLiteral("ul");
    1480           0 :   } else if (bDL) {
    1481           0 :     aLocalName.AssignLiteral("dl");
    1482             :   }
    1483           0 :   return NS_OK;
    1484             : }
    1485             : 
    1486             : nsresult
    1487           0 : RemoveOneProperty(nsIHTMLEditor* aEditor, const nsAString& aProp)
    1488             : {
    1489           0 :   MOZ_ASSERT(aEditor);
    1490             : 
    1491             :   /// XXX Hack alert! Look in nsIEditProperty.h for this
    1492           0 :   nsCOMPtr<nsIAtom> styleAtom = NS_Atomize(aProp);
    1493           0 :   NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
    1494             : 
    1495           0 :   return aEditor->RemoveInlineProperty(styleAtom, EmptyString());
    1496             : }
    1497             : 
    1498             : 
    1499             : // the name of the attribute here should be the contents of the appropriate
    1500             : // tag, e.g. 'b' for bold, 'i' for italics.
    1501             : nsresult
    1502           0 : RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp)
    1503             : {
    1504           0 :   MOZ_ASSERT(aEditor);
    1505             : 
    1506           0 :   if (aProp.LowerCaseEqualsLiteral("all")) {
    1507           0 :     return aEditor->RemoveAllInlineProperties();
    1508             :   }
    1509             : 
    1510           0 :   return RemoveOneProperty(aEditor, aProp);
    1511             : }
    1512             : 
    1513             : // the name of the attribute here should be the contents of the appropriate
    1514             : // tag, e.g. 'b' for bold, 'i' for italics.
    1515             : nsresult
    1516           0 : SetTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp)
    1517             : {
    1518           0 :   MOZ_ASSERT(aEditor);
    1519             : 
    1520             :   /// XXX Hack alert! Look in nsIEditProperty.h for this
    1521           0 :   nsCOMPtr<nsIAtom> styleAtom = NS_Atomize(aProp);
    1522           0 :   NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
    1523             : 
    1524           0 :   return aEditor->SetInlineProperty(styleAtom, EmptyString(), EmptyString());
    1525             : }

Generated by: LCOV version 1.13