Bug 1393642 - Remove nsIAtom/nsIAtomService usage from script in editor/. r=masayuki.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 25 Aug 2017 15:40:45 +1000
changeset 429095 e774e827d2fb359580c6975d2df01d5730c48d61
parent 429094 241116278286e4c38fd7461da5eae52ba409ae1b
child 429096 d10c97627b51a226e19d0fa801201897fe1932f6
child 429173 bc2cbce028cbdbe33bbbddaa2fd0213479fb3c2a
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1393642, 1392883, 1140105
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1393642 - Remove nsIAtom/nsIAtomService usage from script in editor/. r=masayuki. nsIHTMLEditor has several scriptable methods (addDefaultProperty(), removeDefaultProperty(), etc.) that have nsIAtom parameters. We're in the process of deCOMtaminating nsIAtom (bug 1392883) so these methods need to be changed. This patch does the following. - It changes those methods to take an AString instead of an nsIAtom. - For each existing method, it adds to HTMLEditor a new C++ method of the same name that takes an nsIAtom parameter. - It updates TextEditorTest.cpp to use strings instead of atoms, in order to keep using the XPIDL methods. - It updates test_bug1140105.html to pass strings instead of atoms to getInlineProperty(). This removes the use of nsIAtomService.
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLStyleEditor.cpp
editor/libeditor/TextEditorTest.cpp
editor/libeditor/tests/test_bug1140105.html
editor/nsIEditor.idl
editor/nsIHTMLEditor.idl
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -224,16 +224,40 @@ public:
   }
   nsresult GetAbsolutelyPositionedSelectionContainer(nsINode** aContainer);
   Element* GetPositionedElement() const
   {
     return mAbsolutelyPositionedObject;
   }
   nsresult GetElementZIndex(Element* aElement, int32_t* aZindex);
 
+  nsresult AddDefaultProperty(nsIAtom* aProperty,
+                              const nsAString& aAttribute,
+                              const nsAString& aValue);
+  nsresult RemoveDefaultProperty(nsIAtom* aProperty,
+                                 const nsAString& aAttribute,
+                                 const nsAString& aValue);
+  nsresult SetInlineProperty(nsIAtom* aProperty,
+                             const nsAString& aAttribute,
+                             const nsAString& aValue);
+  nsresult GetInlineProperty(nsIAtom* aProperty,
+                             const nsAString& aAttribute,
+                             const nsAString& aValue,
+                             bool* aFirst,
+                             bool* aAny,
+                             bool* aAll);
+  nsresult GetInlinePropertyWithAttrValue(nsIAtom* aProperty,
+                                          const nsAString& aAttr,
+                                          const nsAString& aValue,
+                                          bool* aFirst,
+                                          bool* aAny,
+                                          bool* aAll,
+                                          nsAString& outValue);
+  nsresult RemoveInlineProperty(nsIAtom* aProperty,
+                                const nsAString& aAttribute);
 protected:
   virtual ~HTMLEditor();
 
   using EditorBase::IsBlockNode;
   virtual bool IsBlockNode(nsINode *aNode) override;
 
 public:
   // XXX Why don't we move following methods above for grouping by the origins?
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -50,16 +50,24 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINo
 {
   bool isEmptyTextNode = false;
   return EditorBase::IsTextNode(aNode) &&
          NS_SUCCEEDED(aThis->IsEmptyNode(aNode, &isEmptyTextNode)) &&
          isEmptyTextNode;
 }
 
 NS_IMETHODIMP
+HTMLEditor::AddDefaultProperty(const nsAString& aProperty,
+                               const nsAString& aAttribute,
+                               const nsAString& aValue)
+{
+  return AddDefaultProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
+}
+
+nsresult
 HTMLEditor::AddDefaultProperty(nsIAtom* aProperty,
                                const nsAString& aAttribute,
                                const nsAString& aValue)
 {
   nsString outValue;
   int32_t index;
   nsString attr(aAttribute);
   if (TypeInState::FindPropInList(aProperty, attr, &outValue,
@@ -70,16 +78,25 @@ HTMLEditor::AddDefaultProperty(nsIAtom* 
     nsString value(aValue);
     PropItem *propItem = new PropItem(aProperty, attr, value);
     mDefaultStyles.AppendElement(propItem);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
+HTMLEditor::RemoveDefaultProperty(const nsAString& aProperty,
+                                  const nsAString& aAttribute,
+                                  const nsAString& aValue)
+{
+  return RemoveDefaultProperty(NS_Atomize(aProperty).take(), aAttribute,
+                               aValue);
+}
+
+nsresult
 HTMLEditor::RemoveDefaultProperty(nsIAtom* aProperty,
                                   const nsAString& aAttribute,
                                   const nsAString& aValue)
 {
   nsString outValue;
   int32_t index;
   nsString attr(aAttribute);
   if (TypeInState::FindPropInList(aProperty, attr, &outValue,
@@ -96,18 +113,25 @@ HTMLEditor::RemoveAllDefaultProperties()
   size_t defcon = mDefaultStyles.Length();
   for (size_t j = 0; j < defcon; j++) {
     delete mDefaultStyles[j];
   }
   mDefaultStyles.Clear();
   return NS_OK;
 }
 
+NS_IMETHODIMP
+HTMLEditor::SetInlineProperty(const nsAString& aProperty,
+                              const nsAString& aAttribute,
+                              const nsAString& aValue)
+{
+  return SetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
+}
 
-NS_IMETHODIMP
+nsresult
 HTMLEditor::SetInlineProperty(nsIAtom* aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue)
 {
   NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIEditRules> rules(mRules);
   CommitComposition();
@@ -1136,16 +1160,28 @@ HTMLEditor::GetInlinePropertyBase(nsIAto
     // make sure that if none of the selection is set, we don't report all is
     // set
     *aAll = false;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
+HTMLEditor::GetInlineProperty(const nsAString& aProperty,
+                              const nsAString& aAttribute,
+                              const nsAString& aValue,
+                              bool* aFirst,
+                              bool* aAny,
+                              bool* aAll)
+{
+  return GetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue,
+                           aFirst, aAny, aAll);
+}
+
+nsresult
 HTMLEditor::GetInlineProperty(nsIAtom* aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue,
                               bool* aFirst,
                               bool* aAny,
                               bool* aAll)
 {
   NS_ENSURE_TRUE(aProperty && aFirst && aAny && aAll, NS_ERROR_NULL_POINTER);
@@ -1154,16 +1190,30 @@ HTMLEditor::GetInlineProperty(nsIAtom* a
     att = &aAttribute;
   const nsAString *val = nullptr;
   if (!aValue.IsEmpty())
     val = &aValue;
   return GetInlinePropertyBase(*aProperty, att, val, aFirst, aAny, aAll, nullptr);
 }
 
 NS_IMETHODIMP
+HTMLEditor::GetInlinePropertyWithAttrValue(const nsAString& aProperty,
+                                           const nsAString& aAttribute,
+                                           const nsAString& aValue,
+                                           bool* aFirst,
+                                           bool* aAny,
+                                           bool* aAll,
+                                           nsAString& outValue)
+{
+  return GetInlinePropertyWithAttrValue(NS_Atomize(aProperty).take(),
+                                        aAttribute, aValue, aFirst, aAny,
+                                        aAll, outValue);
+}
+
+nsresult
 HTMLEditor::GetInlinePropertyWithAttrValue(nsIAtom* aProperty,
                                            const nsAString& aAttribute,
                                            const nsAString& aValue,
                                            bool* aFirst,
                                            bool* aAny,
                                            bool* aAll,
                                            nsAString& outValue)
 {
@@ -1185,16 +1235,23 @@ HTMLEditor::RemoveAllInlineProperties()
                                nsIEditor::eNext);
 
   nsresult rv = RemoveInlinePropertyImpl(nullptr, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
   return ApplyDefaultProperties();
 }
 
 NS_IMETHODIMP
+HTMLEditor::RemoveInlineProperty(const nsAString& aProperty,
+                                 const nsAString& aAttribute)
+{
+  return RemoveInlineProperty(NS_Atomize(aProperty).take(), aAttribute);
+}
+
+nsresult
 HTMLEditor::RemoveInlineProperty(nsIAtom* aProperty,
                                  const nsAString& aAttribute)
 {
   return RemoveInlinePropertyImpl(aProperty, &aAttribute);
 }
 
 nsresult
 HTMLEditor::RemoveInlinePropertyImpl(nsIAtom* aProperty,
--- a/editor/libeditor/TextEditorTest.cpp
+++ b/editor/libeditor/TextEditorTest.cpp
@@ -166,68 +166,66 @@ nsresult TextEditorTest::TestTextPropert
   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   bool any = false;
   bool all = false;
   bool first=false;
 
   const nsString& empty = EmptyString();
 
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                     &any, &all);
+  NS_NAMED_LITERAL_STRING(b, "b");
+  NS_NAMED_LITERAL_STRING(i, "i");
+  NS_NAMED_LITERAL_STRING(u, "u");
+
+  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
-  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  rv = htmlEditor->SetInlineProperty(b, empty, empty);
   TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // remove the bold we just set
   printf("set the whole first text node to not bold\n");
-  rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
+  rv = htmlEditor->RemoveInlineProperty(b, empty);
   TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
   mEditor->DebugDumpContent();
 
   // set all but the first and last character to bold
   printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-1);
-  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  rv = htmlEditor->SetInlineProperty(b, empty, empty);
   TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
   // make all that same text italic
-  rv = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
+  rv = htmlEditor->SetInlineProperty(i, empty, empty);
   TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(i, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // make all the text underlined, except for the first 2 and last 2 characters
   rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
@@ -238,20 +236,19 @@ nsresult TextEditorTest::TestTextPropert
   rv = nodeList->Item(count-2, getter_AddRefs(textNode));
   TEST_RESULT(rv);
   TEST_POINTER(textNode.get());
   textData = do_QueryInterface(textNode);
   textData->GetLength(&length);
   NS_ASSERTION(length==915, "wrong text node");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-2);
-  rv = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
+  rv = htmlEditor->SetInlineProperty(u, empty, empty);
   TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
-                                     &any, &all);
+  rv = htmlEditor->GetInlineProperty(u, empty, empty, &first, &any, &all);
   TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   return rv;
 }
--- a/editor/libeditor/tests/test_bug1140105.html
+++ b/editor/libeditor/tests/test_bug1140105.html
@@ -33,23 +33,21 @@ SimpleTest.waitForFocus(function() {
   is(selRange.endContainer.nodeName, "#text", "selection should be in text node");
   is(selRange.endOffset, 9, "offset should be 9");
 
   var firstHas = {};
   var anyHas = {};
   var allHas = {};
   var editor = getEditor();
 
-  var atomService = SpecialPowers.Cc["@mozilla.org/atom-service;1"].getService(SpecialPowers.Ci.nsIAtomService);
-  var propAtom = atomService.getAtom("font");
-  editor.getInlineProperty(propAtom, "face", "Arial", firstHas, anyHas, allHas);
+  editor.getInlineProperty("font", "face", "Arial", firstHas, anyHas, allHas);
   is(firstHas.value, true, "Test for Arial: firstHas: true expected");
   is(anyHas.value, true, "Test for Arial: anyHas: true expected");
   is(allHas.value, true, "Test for Arial: allHas: true expected");
-  editor.getInlineProperty(propAtom, "face", "Courier", firstHas, anyHas, allHas);
+  editor.getInlineProperty("font", "face", "Courier", firstHas, anyHas, allHas);
   is(firstHas.value, false, "Test for Courier: firstHas: false expected");
   is(anyHas.value, false, "Test for Courier: anyHas: false expected");
   is(allHas.value, false, "Test for Courier: allHas: false expected");
 
   SimpleTest.finish();
 
 });
 
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -3,17 +3,16 @@
  * 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/. */
 
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
 interface nsIURI;
-interface nsIAtom;
 interface nsIContent;
 interface nsISelection;
 interface nsISelectionController;
 interface nsIDocumentStateListener;
 interface nsIOutputStream;
 interface nsITransactionManager;
 interface nsITransaction;
 interface nsIEditorObserver;
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
-interface nsIAtom;
 interface nsIContent;
 interface nsIArray;
 interface nsISelection;
 interface nsIContentFilter;
 
 %{C++
 namespace mozilla {
 namespace dom {
@@ -45,32 +44,32 @@ interface nsIHTMLEditor : nsISupports
    * @param aProperty   the property to set by default
    * @param aAttribute  the attribute of the property, if applicable.
    *                    May be null.
    *                    Example: aProperty="font", aAttribute="color"
    * @param aValue      if aAttribute is not null, the value of the attribute.
    *                    Example: aProperty="font", aAttribute="color",
    *                             aValue="0x00FFFF"
    */
-  void addDefaultProperty(in nsIAtom aProperty,
+  void addDefaultProperty(in AString aProperty,
                           in AString aAttribute,
                           in AString aValue);
 
   /**
    * RemoveDefaultProperty() unregisters a default style property with the editor
    *
    * @param aProperty   the property to remove from defaults
    * @param aAttribute  the attribute of the property, if applicable.
    *                    May be null.
    *                    Example: aProperty="font", aAttribute="color"
    * @param aValue      if aAttribute is not null, the value of the attribute.
    *                    Example: aProperty="font", aAttribute="color",
    *                             aValue="0x00FFFF"
    */
-  void removeDefaultProperty(in nsIAtom aProperty,
+  void removeDefaultProperty(in AString aProperty,
                              in AString aAttribute,
                              in AString aValue);
 
   /**
    * RemoveAllDefaultProperties() unregisters all default style properties with the editor
    *
    */
   void removeAllDefaultProperties();
@@ -82,17 +81,17 @@ interface nsIHTMLEditor : nsISupports
    * @param aAttribute  the attribute of the property, if applicable.
    *                    May be null.
    *                    Example: aProperty="font", aAttribute="color"
    * @param aValue      if aAttribute is not null, the value of the attribute.
    *                    May be null.
    *                    Example: aProperty="font", aAttribute="color",
    *                             aValue="0x00FFFF"
    */
-  void setInlineProperty(in nsIAtom aProperty,
+  void setInlineProperty(in AString aProperty,
                          in AString aAttribute,
                          in AString aValue);
 
   /**
    * getInlineProperty() gets aggregate properties of the current selection.
    * All object in the current selection are scanned and their attributes are
    * represented in a list of Property object.
    *
@@ -106,29 +105,29 @@ interface nsIHTMLEditor : nsISupports
    *                             aValue="0x00FFFF"
    * @param aFirst      [OUT] PR_TRUE if the first text node in the
    *                          selection has the property
    * @param aAny        [OUT] PR_TRUE if any of the text nodes in the
    *                          selection have the property
    * @param aAll        [OUT] PR_TRUE if all of the text nodes in the
    *                          selection have the property
    */
-  void getInlineProperty(in nsIAtom aProperty,
-                         in AString  aAttribute,
-                         in AString  aValue,
+  void getInlineProperty(in AString aProperty,
+                         in AString aAttribute,
+                         in AString aValue,
                          out boolean aFirst,
                          out boolean aAny,
                          out boolean aAll);
 
-  AString getInlinePropertyWithAttrValue(in nsIAtom aProperty,
-                                           in AString  aAttribute,
-                                           in AString  aValue,
-                                           out boolean aFirst,
-                                           out boolean aAny,
-                                           out boolean aAll);
+  AString getInlinePropertyWithAttrValue(in AString aProperty,
+                                         in AString aAttribute,
+                                         in AString aValue,
+                                         out boolean aFirst,
+                                         out boolean aAny,
+                                         out boolean aAll);
 
   /**
    * removeAllInlineProperties() deletes all the inline properties from all
    * text in the current selection.
    */
   void removeAllInlineProperties();
 
 
@@ -144,17 +143,17 @@ interface nsIHTMLEditor : nsISupports
    * @param aAttribute  the attribute of the property, if applicable.
    *                    May be null.
    *                    Example: aProperty=nsIEditorProptery::font,
    *                    aAttribute="color"
    *                    nsIEditProperty::allAttributes is special.
    *                    It indicates that all content-based text properties
    *                    are to be removed from the selection.
    */
-  void removeInlineProperty(in nsIAtom aProperty, in AString  aAttribute);
+  void removeInlineProperty(in AString aProperty, in AString aAttribute);
 
   /**
    *  Increase font size for text in selection by 1 HTML unit
    *  All existing text is scanned for existing <FONT SIZE> attributes
    *  so they will be incremented instead of inserting new <FONT> tag
    */
   void increaseFontSize();