Bug 1394583 - Remove default properties from nsIHTMLEditor. r=masayuki.

nsIHTMLEditor's addDefaultProperty(), removeDefaultProperty(),
removeAllDefaultProperties() methods are never used -- not from C++ code or
script, in either mozilla-central or comm-central.

So this patch removes them. This means that HMLTEditor::mDefaultStyles is never
used, so the patch removes it and all the code that manipulates it as well.

--HG--
extra : rebase_source : 76634ce2bb2d94534b8d7f299c4ebd6a83b66637
This commit is contained in:
Nicholas Nethercote 2017-08-25 16:59:17 +10:00
parent bdd21f0a1e
commit 0eadf50d37
5 changed files with 4 additions and 181 deletions

View File

@ -4554,38 +4554,6 @@ HTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
nsCOMPtr<nsINode> node = aSelection.GetRangeAt(0)->GetStartContainer();
int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
// next examine our present style and make sure default styles are either
// present or explicitly overridden. If neither, add the default style to
// the TypeInState
int32_t length = mHTMLEditor->mDefaultStyles.Length();
for (int32_t j = 0; j < length; j++) {
PropItem* propItem = mHTMLEditor->mDefaultStyles[j];
MOZ_ASSERT(propItem);
bool bFirst, bAny, bAll;
// GetInlineProperty also examine TypeInState. The only gotcha here is
// that a cleared property looks like an unset property. For now I'm
// assuming that's not a problem: that default styles will always be
// multivalue styles (like font face or size) where clearing the style
// means we want to go back to the default. If we ever wanted a "toggle"
// style like bold for a default, though, I'll have to add code to detect
// the difference between unset and explicitly cleared, else user would
// never be able to unbold, for instance.
nsAutoString curValue;
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
mHTMLEditor->GetInlinePropertyBase(*propItem->tag, &propItem->attr,
nullptr, &bFirst, &bAny, &bAll,
&curValue, false);
NS_ENSURE_SUCCESS(rv, rv);
if (!bAny) {
// no style set for this prop/attr
mHTMLEditor->mTypeInState->SetProp(propItem->tag, propItem->attr,
propItem->value);
}
}
nsCOMPtr<Element> rootElement = aDoc.GetRootElement();
NS_ENSURE_STATE(rootElement);
@ -7341,7 +7309,7 @@ HTMLEditRules::ReapplyCachedStyles()
&(mCachedStyles[i].attr),
&(mCachedStyles[i].value),
&bFirst, &bAny, &bAll,
&curValue, false);
&curValue);
NS_ENSURE_SUCCESS(rv, rv);
}
// This style has disappeared through deletion. Let's add the styles to

View File

@ -162,9 +162,6 @@ HTMLEditor::~HTMLEditor()
mTypeInState = nullptr;
mSelectionListenerP = nullptr;
// free any default style propItems
RemoveAllDefaultProperties();
if (mLinkHandler && IsInitialized()) {
nsCOMPtr<nsIPresShell> ps = GetPresShell();

View File

@ -229,12 +229,6 @@ public:
}
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);
@ -759,7 +753,6 @@ protected:
const nsAString* aAttribute,
nsIContent** aOutLeftNode = nullptr,
nsIContent** aOutRightNode = nullptr);
nsresult ApplyDefaultProperties();
nsresult RemoveStyleInside(nsIContent& aNode,
nsIAtom* aProperty,
const nsAString* aAttribute,
@ -820,8 +813,7 @@ protected:
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString* outValue,
bool aCheckDefaults = true);
nsAString* outValue);
bool HasStyleOrIdOrClass(Element* aElement);
nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement);
@ -902,9 +894,6 @@ protected:
nsTArray<nsString> mStyleSheetURLs;
nsTArray<RefPtr<StyleSheet>> mStyleSheets;
// an array for holding default style settings
nsTArray<PropItem*> mDefaultStyles;
protected:
// ANONYMOUS UTILS
void RemoveListenerAndDeleteRef(const nsAString& aEvent,

View File

@ -54,70 +54,6 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINode* aNode)
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,
mDefaultStyles, index)) {
PropItem *item = mDefaultStyles[index];
item->value = aValue;
} else {
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,
mDefaultStyles, index)) {
delete mDefaultStyles[index];
mDefaultStyles.RemoveElementAt(index);
}
return NS_OK;
}
NS_IMETHODIMP
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,
@ -715,20 +651,6 @@ HTMLEditor::NodeIsProperty(nsINode& aNode)
!aNode.IsHTMLElement(nsGkAtoms::a);
}
nsresult
HTMLEditor::ApplyDefaultProperties()
{
size_t defcon = mDefaultStyles.Length();
for (size_t j = 0; j < defcon; j++) {
PropItem *propItem = mDefaultStyles[j];
NS_ENSURE_TRUE(propItem, NS_ERROR_NULL_POINTER);
nsresult rv =
SetInlineProperty(propItem->tag, propItem->attr, propItem->value);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult
HTMLEditor::RemoveStyleInside(nsIContent& aNode,
nsIAtom* aProperty,
@ -997,8 +919,7 @@ HTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString* outValue,
bool aCheckDefaults)
nsAString* outValue)
{
*aAny = false;
*aAll = true;
@ -1053,21 +974,6 @@ HTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
isSet = IsTextPropertySetByContent(collapsedNode, &aProperty,
aAttribute, aValue, outValue);
*aFirst = *aAny = *aAll = isSet;
if (!isSet && aCheckDefaults) {
// Style not set, but if it is a default then it will appear if content
// is inserted, so we should report it as set (analogous to
// TypeInState).
int32_t index;
if (aAttribute && TypeInState::FindPropInList(&aProperty, *aAttribute,
outValue, mDefaultStyles,
index)) {
*aFirst = *aAny = *aAll = true;
if (outValue) {
outValue->Assign(mDefaultStyles[index]->value);
}
}
}
return NS_OK;
}
@ -1236,7 +1142,7 @@ HTMLEditor::RemoveAllInlineProperties()
nsresult rv = RemoveInlinePropertyImpl(nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
return ApplyDefaultProperties();
return NS_OK;
}
NS_IMETHODIMP

View File

@ -37,43 +37,6 @@ interface nsIHTMLEditor : nsISupports
/* ------------ Inline property methods -------------- */
/**
* AddDefaultProperty() registers a default style property with the editor
*
* @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 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 AString aProperty,
in AString aAttribute,
in AString aValue);
/**
* RemoveAllDefaultProperties() unregisters all default style properties with the editor
*
*/
void removeAllDefaultProperties();
/**
* SetInlineProperty() sets the aggregate properties on the current selection
*