Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1393642 - Remove nsIAtom/nsIAtomService usage from script in edit…
Browse files Browse the repository at this point in the history
…or/. 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.
  • Loading branch information
nnethercote committed Aug 25, 2017
1 parent fbb810c commit 87e58e4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 39 deletions.
24 changes: 24 additions & 0 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,30 @@ class HTMLEditor final : public TextEditor
}
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();

Expand Down
59 changes: 58 additions & 1 deletion editor/libeditor/HTMLStyleEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINode* aNode)
}

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)
Expand All @@ -75,6 +83,15 @@ HTMLEditor::AddDefaultProperty(nsIAtom* aProperty,
}

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)
Expand All @@ -101,8 +118,15 @@ HTMLEditor::RemoveAllDefaultProperties()
return NS_OK;
}


NS_IMETHODIMP
HTMLEditor::SetInlineProperty(const nsAString& aProperty,
const nsAString& aAttribute,
const nsAString& aValue)
{
return SetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
}

nsresult
HTMLEditor::SetInlineProperty(nsIAtom* aProperty,
const nsAString& aAttribute,
const nsAString& aValue)
Expand Down Expand Up @@ -1141,6 +1165,18 @@ HTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
}

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,
Expand All @@ -1159,6 +1195,20 @@ HTMLEditor::GetInlineProperty(nsIAtom* aProperty,
}

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,
Expand Down Expand Up @@ -1190,6 +1240,13 @@ HTMLEditor::RemoveAllInlineProperties()
}

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)
{
Expand Down
35 changes: 16 additions & 19 deletions editor/libeditor/TextEditorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,18 @@ nsresult TextEditorTest::TestTextProperties()

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");
Expand All @@ -189,10 +191,9 @@ nsresult TextEditorTest::TestTextProperties()

// 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");
Expand All @@ -203,26 +204,23 @@ nsresult TextEditorTest::TestTextProperties()
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");
Expand All @@ -243,10 +241,9 @@ nsresult TextEditorTest::TestTextProperties()
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");
Expand Down
6 changes: 2 additions & 4 deletions editor/libeditor/tests/test_bug1140105.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@
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");
Expand Down
1 change: 0 additions & 1 deletion editor/nsIEditor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "domstubs.idl"

interface nsIURI;
interface nsIAtom;
interface nsIContent;
interface nsISelection;
interface nsISelectionController;
Expand Down
27 changes: 13 additions & 14 deletions editor/nsIHTMLEditor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "nsISupports.idl"
#include "domstubs.idl"

interface nsIAtom;
interface nsIContent;
interface nsIArray;
interface nsISelection;
Expand Down Expand Up @@ -50,7 +49,7 @@ interface nsIHTMLEditor : nsISupports
* Example: aProperty="font", aAttribute="color",
* aValue="0x00FFFF"
*/
void addDefaultProperty(in nsIAtom aProperty,
void addDefaultProperty(in AString aProperty,
in AString aAttribute,
in AString aValue);

Expand All @@ -65,7 +64,7 @@ interface nsIHTMLEditor : nsISupports
* Example: aProperty="font", aAttribute="color",
* aValue="0x00FFFF"
*/
void removeDefaultProperty(in nsIAtom aProperty,
void removeDefaultProperty(in AString aProperty,
in AString aAttribute,
in AString aValue);

Expand All @@ -87,7 +86,7 @@ interface nsIHTMLEditor : nsISupports
* Example: aProperty="font", aAttribute="color",
* aValue="0x00FFFF"
*/
void setInlineProperty(in nsIAtom aProperty,
void setInlineProperty(in AString aProperty,
in AString aAttribute,
in AString aValue);

Expand All @@ -111,19 +110,19 @@ interface nsIHTMLEditor : nsISupports
* @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
Expand All @@ -149,7 +148,7 @@ interface nsIHTMLEditor : nsISupports
* 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
Expand Down

0 comments on commit 87e58e4

Please sign in to comment.