--- a/editor/composer/nsComposerCommands.cpp
+++ b/editor/composer/nsComposerCommands.cpp
@@ -201,17 +201,17 @@ nsStyleUpdatingCommand::GetCurrentState(
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
bool firstOfSelectionHasProp = false;
bool anyOfSelectionHasProp = false;
bool allOfSelectionHasProp = false;
- nsresult rv = aHTMLEditor->GetInlineProperty(mTagName, EmptyString(),
+ nsresult rv = aHTMLEditor->GetInlineProperty(mTagName, nullptr,
EmptyString(),
&firstOfSelectionHasProp,
&anyOfSelectionHasProp,
&allOfSelectionHasProp);
aParams->SetBooleanValue(STATE_ENABLED, NS_SUCCEEDED(rv));
aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp);
aParams->SetBooleanValue(STATE_ANY, anyOfSelectionHasProp);
@@ -716,35 +716,33 @@ nsFontFaceStateCommand::SetState(mozilla
nsString& newState)
{
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
if (newState.EqualsLiteral("tt")) {
// The old "teletype" attribute
- nsresult rv = aHTMLEditor->SetInlineProperty(nsGkAtoms::tt, EmptyString(),
+ nsresult rv = aHTMLEditor->SetInlineProperty(nsGkAtoms::tt, nullptr,
EmptyString());
NS_ENSURE_SUCCESS(rv, rv);
// Clear existing font face
- return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("face"));
+ return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font, nsGkAtoms::face);
}
// Remove any existing TT nodes
- nsresult rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::tt, EmptyString());
+ nsresult rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::tt, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
- return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("face"));
+ return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font, nsGkAtoms::face);
}
- return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("face"), newState);
+ return aHTMLEditor->SetInlineProperty(nsGkAtoms::font, nsGkAtoms::face,
+ newState);
}
nsFontSizeStateCommand::nsFontSizeStateCommand()
: nsMultiStateCommand()
{
}
nsresult
@@ -754,17 +752,17 @@ nsFontSizeStateCommand::GetCurrentState(
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
nsAutoString outStateString;
bool firstHas, anyHas, allHas;
nsresult rv = aHTMLEditor->GetInlinePropertyWithAttrValue(
nsGkAtoms::font,
- NS_LITERAL_STRING("size"),
+ nsGkAtoms::size,
EmptyString(),
&firstHas, &anyHas, &allHas,
outStateString);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString tOutStateString;
LossyCopyUTF16toASCII(outStateString, tOutStateString);
aParams->SetBooleanValue(STATE_MIXED, anyHas && !allHas);
@@ -791,28 +789,28 @@ nsFontSizeStateCommand::SetState(mozilla
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
if (!newState.IsEmpty() &&
!newState.EqualsLiteral("normal") &&
!newState.EqualsLiteral("medium")) {
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("size"), newState);
+ nsGkAtoms::size, newState);
}
// remove any existing font size, big or small
nsresult rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("size"));
+ nsGkAtoms::size);
NS_ENSURE_SUCCESS(rv, rv);
- rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::big, EmptyString());
+ rv = aHTMLEditor->RemoveInlineProperty(nsGkAtoms::big, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
- return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::small, EmptyString());
+ return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::small, nullptr);
}
nsFontColorStateCommand::nsFontColorStateCommand()
: nsMultiStateCommand()
{
}
nsresult
@@ -840,21 +838,21 @@ nsFontColorStateCommand::SetState(mozill
nsString& newState)
{
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("color"));
+ nsGkAtoms::color);
}
- return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("color"), newState);
+ return aHTMLEditor->SetInlineProperty(nsGkAtoms::font, nsGkAtoms::color,
+ newState);
}
nsHighlightColorStateCommand::nsHighlightColorStateCommand()
: nsMultiStateCommand()
{
}
nsresult
@@ -882,21 +880,21 @@ nsHighlightColorStateCommand::SetState(m
nsString& newState)
{
if (NS_WARN_IF(!aHTMLEditor)) {
return NS_ERROR_INVALID_ARG;
}
if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
return aHTMLEditor->RemoveInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("bgcolor"));
+ nsGkAtoms::bgcolor);
}
return aHTMLEditor->SetInlineProperty(nsGkAtoms::font,
- NS_LITERAL_STRING("bgcolor"),
+ nsGkAtoms::bgcolor,
newState);
}
NS_IMETHODIMP
nsHighlightColorStateCommand::IsCommandEnabled(const char * aCommandName,
nsISupports *refCon,
bool *outCmdEnabled)
{
@@ -1594,17 +1592,17 @@ RemoveOneProperty(mozilla::HTMLEditor* a
const nsAString& aProp)
{
MOZ_ASSERT(aHTMLEditor);
/// XXX Hack alert! Look in nsIEditProperty.h for this
RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
- return aHTMLEditor->RemoveInlineProperty(styleAtom, EmptyString());
+ return aHTMLEditor->RemoveInlineProperty(styleAtom, nullptr);
}
// the name of the attribute here should be the contents of the appropriate
// tag, e.g. 'b' for bold, 'i' for italics.
nsresult
RemoveTextProperty(mozilla::HTMLEditor* aHTMLEditor,
const nsAString& aProp)
@@ -1625,11 +1623,10 @@ SetTextProperty(mozilla::HTMLEditor* aHT
const nsAString& aProp)
{
MOZ_ASSERT(aHTMLEditor);
/// XXX Hack alert! Look in nsIEditProperty.h for this
RefPtr<nsAtom> styleAtom = NS_Atomize(aProp);
NS_ENSURE_TRUE(styleAtom, NS_ERROR_OUT_OF_MEMORY);
- return aHTMLEditor->SetInlineProperty(styleAtom,
- EmptyString(), EmptyString());
+ return aHTMLEditor->SetInlineProperty(styleAtom, nullptr, EmptyString());
}
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -313,25 +313,16 @@ CSSEditUtils::~CSSEditUtils()
{
}
// Answers true if we have some CSS equivalence for the HTML style defined
// by aProperty and/or aAttribute for the node aNode
bool
CSSEditUtils::IsCSSEditableProperty(nsINode* aNode,
nsAtom* aProperty,
- const nsAString* aAttribute)
-{
- RefPtr<nsAtom> attribute = aAttribute ? NS_Atomize(*aAttribute) : nullptr;
- return IsCSSEditableProperty(aNode, aProperty, attribute);
-}
-
-bool
-CSSEditUtils::IsCSSEditableProperty(nsINode* aNode,
- nsAtom* aProperty,
nsAtom* aAttribute)
{
MOZ_ASSERT(aNode);
nsINode* node = aNode;
// we need an element node here
if (node->NodeType() == nsIDOMNode::TEXT_NODE) {
node = node->GetParentNode();
@@ -592,17 +583,17 @@ CSSEditUtils::RemoveCSSInlineStyle(nsINo
return mHTMLEditor->RemoveContainer(element);
}
// Answers true if the property can be removed by setting a "none" CSS value
// on a node
bool
CSSEditUtils::IsCSSInvertible(nsAtom& aProperty,
- const nsAString* aAttribute)
+ nsAtom* aAttribute)
{
return nsGkAtoms::b == &aProperty;
}
// Get the default browser background color if we need it for GetCSSBackgroundColorState
void
CSSEditUtils::GetDefaultBackgroundColor(nsAString& aColor)
{
@@ -1046,17 +1037,17 @@ CSSEditUtils::GetCSSEquivalentToHTMLInli
// The value of aStyleType controls the styles we retrieve: specified or
// computed. The return value aIsSet is true if the CSS styles are set.
//
// The nsIContent variant returns aIsSet instead of using an out parameter, and
// does not modify aValue.
bool
CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue,
StyleType aStyleType)
{
// Use aValue as only an in param, not in-out
nsAutoString value(aValue);
return IsCSSEquivalentToHTMLInlineStyleSet(aNode, aProperty, aAttribute,
value, aStyleType);
}
--- a/editor/libeditor/CSSEditUtils.h
+++ b/editor/libeditor/CSSEditUtils.h
@@ -78,24 +78,22 @@ public:
};
/**
* Answers true if the given combination element_name/attribute_name
* has a CSS equivalence in this implementation.
*
* @param aNode [IN] A DOM node.
* @param aProperty [IN] An atom containing a HTML tag name.
- * @param aAttribute [IN] A string containing the name of a HTML
+ * @param aAttribute [IN] An atom containing a HTML
* attribute carried by the element above.
* @return A boolean saying if the tag/attribute has a CSS
* equiv.
*/
bool IsCSSEditableProperty(nsINode* aNode, nsAtom* aProperty,
- const nsAString* aAttribute);
- bool IsCSSEditableProperty(nsINode* aNode, nsAtom* aProperty,
nsAtom* aAttribute);
/**
* Adds/remove a CSS declaration to the STYLE atrribute carried by a given
* element.
*
* @param aElement [IN] A DOM element.
* @param aProperty [IN] An atom containing the CSS property to set.
@@ -161,17 +159,17 @@ public:
* on a node.
*
* @param aProperty [IN] An atom containing a CSS property.
* @param aAttribute [IN] Pointer to an attribute name or null if this
* information is irrelevant.
* @return A boolean saying if the property can be remove by
* setting a "none" value.
*/
- bool IsCSSInvertible(nsAtom& aProperty, const nsAString* aAttribute);
+ bool IsCSSInvertible(nsAtom& aProperty, nsAtom* aAttribute);
/**
* Get the default browser background color if we need it for
* GetCSSBackgroundColorState().
*
* @param aColor [OUT] The default color as it is defined in prefs.
*/
void GetDefaultBackgroundColor(nsAString& aColor);
@@ -218,17 +216,17 @@ public:
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
nsAtom* aProperty,
nsAtom* aAttribute,
nsAString& aValue,
StyleType aStyleType);
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue,
StyleType aStyleType);
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
nsAtom* aProperty,
const nsAString* aAttribute,
nsAString& aValue,
StyleType aStyleType);
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -209,35 +209,35 @@ HTMLEditRules::InitFields()
mRangeItem = new RangeItem();
InitStyleCacheArray(mCachedStyles);
}
void
HTMLEditRules::InitStyleCacheArray(StyleCache aStyleCache[SIZE_STYLE_TABLE])
{
- aStyleCache[0] = StyleCache(nsGkAtoms::b, EmptyString());
- aStyleCache[1] = StyleCache(nsGkAtoms::i, EmptyString());
- aStyleCache[2] = StyleCache(nsGkAtoms::u, EmptyString());
- aStyleCache[3] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("face"));
- aStyleCache[4] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("size"));
- aStyleCache[5] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("color"));
- aStyleCache[6] = StyleCache(nsGkAtoms::tt, EmptyString());
- aStyleCache[7] = StyleCache(nsGkAtoms::em, EmptyString());
- aStyleCache[8] = StyleCache(nsGkAtoms::strong, EmptyString());
- aStyleCache[9] = StyleCache(nsGkAtoms::dfn, EmptyString());
- aStyleCache[10] = StyleCache(nsGkAtoms::code, EmptyString());
- aStyleCache[11] = StyleCache(nsGkAtoms::samp, EmptyString());
- aStyleCache[12] = StyleCache(nsGkAtoms::var, EmptyString());
- aStyleCache[13] = StyleCache(nsGkAtoms::cite, EmptyString());
- aStyleCache[14] = StyleCache(nsGkAtoms::abbr, EmptyString());
- aStyleCache[15] = StyleCache(nsGkAtoms::acronym, EmptyString());
- aStyleCache[16] = StyleCache(nsGkAtoms::backgroundColor, EmptyString());
- aStyleCache[17] = StyleCache(nsGkAtoms::sub, EmptyString());
- aStyleCache[18] = StyleCache(nsGkAtoms::sup, EmptyString());
+ aStyleCache[0] = StyleCache(nsGkAtoms::b, nullptr);
+ aStyleCache[1] = StyleCache(nsGkAtoms::i, nullptr);
+ aStyleCache[2] = StyleCache(nsGkAtoms::u, nullptr);
+ aStyleCache[3] = StyleCache(nsGkAtoms::font, nsGkAtoms::face);
+ aStyleCache[4] = StyleCache(nsGkAtoms::font, nsGkAtoms::size);
+ aStyleCache[5] = StyleCache(nsGkAtoms::font, nsGkAtoms::color);
+ aStyleCache[6] = StyleCache(nsGkAtoms::tt, nullptr);
+ aStyleCache[7] = StyleCache(nsGkAtoms::em, nullptr);
+ aStyleCache[8] = StyleCache(nsGkAtoms::strong, nullptr);
+ aStyleCache[9] = StyleCache(nsGkAtoms::dfn, nullptr);
+ aStyleCache[10] = StyleCache(nsGkAtoms::code, nullptr);
+ aStyleCache[11] = StyleCache(nsGkAtoms::samp, nullptr);
+ aStyleCache[12] = StyleCache(nsGkAtoms::var, nullptr);
+ aStyleCache[13] = StyleCache(nsGkAtoms::cite, nullptr);
+ aStyleCache[14] = StyleCache(nsGkAtoms::abbr, nullptr);
+ aStyleCache[15] = StyleCache(nsGkAtoms::acronym, nullptr);
+ aStyleCache[16] = StyleCache(nsGkAtoms::backgroundColor, nullptr);
+ aStyleCache[17] = StyleCache(nsGkAtoms::sub, nullptr);
+ aStyleCache[18] = StyleCache(nsGkAtoms::sup, nullptr);
}
HTMLEditRules::~HTMLEditRules()
{
// remove ourselves as a listener to edit actions
// In some cases, we have already been removed by
// ~HTMLEditor, in which case we will get a null pointer here
// which we ignore. But this allows us to add the ability to
@@ -4909,17 +4909,17 @@ HTMLEditRules::CreateStyleForInsertText(
UniquePtr<PropItem> item =
Move(mHTMLEditor->mTypeInState->TakeClearProperty());
while (item && node != rootElement) {
NS_ENSURE_STATE(mHTMLEditor);
// XXX If we redesign ClearStyle(), we can use EditorDOMPoint in this
// method.
nsresult rv =
mHTMLEditor->ClearStyle(address_of(node), &offset,
- item->tag, &item->attr);
+ item->tag, item->attr);
NS_ENSURE_SUCCESS(rv, rv);
item = Move(mHTMLEditor->mTypeInState->TakeClearProperty());
weDidSomething = true;
}
// then process setting any styles
int32_t relFontSize = mHTMLEditor->mTypeInState->TakeRelativeFontSize();
item = Move(mHTMLEditor->mTypeInState->TakeSetProperty());
@@ -4964,17 +4964,17 @@ HTMLEditRules::CreateStyleForInsertText(
rv = mHTMLEditor->RelativeFontChangeOnTextNode(dir, newNode, 0, -1);
NS_ENSURE_SUCCESS(rv, rv);
}
}
while (item) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
- *item->tag, &item->attr,
+ *item->tag, item->attr,
item->value);
NS_ENSURE_SUCCESS(rv, rv);
item = mHTMLEditor->mTypeInState->TakeSetProperty();
}
}
if (weDidSomething) {
return aSelection.Collapse(node, offset);
}
@@ -7777,26 +7777,26 @@ HTMLEditRules::GetInlineStyles(nsINode*
if (typeInSet) {
continue;
}
bool isSet = false;
nsAutoString outValue;
// Don't use CSS for <font size>, we don't support it usefully (bug 780035)
if (!useCSS || (aStyleCache[j].tag == nsGkAtoms::font &&
- aStyleCache[j].attr.EqualsLiteral("size"))) {
+ aStyleCache[j].attr == nsGkAtoms::size)) {
NS_ENSURE_STATE(mHTMLEditor);
isSet = mHTMLEditor->IsTextPropertySetByContent(aNode, aStyleCache[j].tag,
- &(aStyleCache[j].attr),
+ aStyleCache[j].attr,
nullptr,
&outValue);
} else {
NS_ENSURE_STATE(mHTMLEditor);
isSet = mHTMLEditor->mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
- aNode, aStyleCache[j].tag, &(aStyleCache[j].attr), outValue,
+ aNode, aStyleCache[j].tag, aStyleCache[j].attr, outValue,
CSSEditUtils::eComputed);
}
if (isSet) {
aStyleCache[j].mPresent = true;
aStyleCache[j].value.Assign(outValue);
}
}
return NS_OK;
@@ -7845,25 +7845,25 @@ HTMLEditRules::ReapplyCachedStyles()
bool bFirst, bAny, bAll;
bFirst = bAny = bAll = false;
nsAutoString curValue;
if (useCSS) {
// check computed style first in css case
NS_ENSURE_STATE(mHTMLEditor);
bAny = mHTMLEditor->mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
- selNode, mCachedStyles[i].tag, &(mCachedStyles[i].attr), curValue,
+ selNode, mCachedStyles[i].tag, mCachedStyles[i].attr, curValue,
CSSEditUtils::eComputed);
}
if (!bAny) {
// then check typeinstate and html style
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
mHTMLEditor->GetInlinePropertyBase(*mCachedStyles[i].tag,
- &(mCachedStyles[i].attr),
+ mCachedStyles[i].attr,
&(mCachedStyles[i].value),
&bFirst, &bAny, &bAll,
&curValue);
NS_ENSURE_SUCCESS(rv, rv);
}
// This style has disappeared through deletion. Let's add the styles to
// mTypeInState when same style isn't applied to the node already.
if ((!bAny || IsStyleCachePreservingAction(mTheAction)) &&
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -46,26 +46,26 @@ struct StyleCache final : public PropIte
StyleCache()
: PropItem()
, mPresent(false)
{
MOZ_COUNT_CTOR(StyleCache);
}
StyleCache(nsAtom* aTag,
- const nsAString& aAttr,
+ nsAtom* aAttr,
const nsAString& aValue)
: PropItem(aTag, aAttr, aValue)
, mPresent(false)
{
MOZ_COUNT_CTOR(StyleCache);
}
StyleCache(nsAtom* aTag,
- const nsAString& aAttr)
+ nsAtom* aAttr)
: PropItem(aTag, aAttr, EmptyString())
, mPresent(false)
{
MOZ_COUNT_CTOR(StyleCache);
}
~StyleCache()
{
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -17,19 +17,17 @@
#include "HTMLEditorEventListener.h"
#include "HTMLEditRules.h"
#include "HTMLEditUtils.h"
#include "HTMLURIRefObject.h"
#include "StyleSheetTransactions.h"
#include "TextEditUtils.h"
#include "TypeInState.h"
-#include "nsIDOMMozNamedAttrMap.h"
#include "nsIDOMDocument.h"
-#include "nsIDOMAttr.h"
#include "nsIDocumentInlines.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMMouseEvent.h"
#include "nsISelectionController.h"
#include "nsIDOMHTMLDocument.h"
#include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h"
@@ -2608,37 +2606,31 @@ HTMLEditor::InsertLinkAroundSelection(ns
if (href.IsEmpty()) {
return NS_OK;
}
nsresult rv;
AutoPlaceholderBatch beginBatching(this);
// Set all attributes found on the supplied anchor element
- nsCOMPtr<nsIDOMMozNamedAttrMap> attrMap;
- aAnchorElement->GetAttributes(getter_AddRefs(attrMap));
+ RefPtr<nsDOMAttributeMap> attrMap = anchor->Attributes();
NS_ENSURE_TRUE(attrMap, NS_ERROR_FAILURE);
- uint32_t count;
- attrMap->GetLength(&count);
- nsAutoString name, value;
+ uint32_t count = attrMap->Length();
+ nsAutoString value;
for (uint32_t i = 0; i < count; ++i) {
- nsCOMPtr<nsIDOMAttr> attribute;
- rv = attrMap->Item(i, getter_AddRefs(attribute));
- NS_ENSURE_SUCCESS(rv, rv);
+ RefPtr<Attr> attribute = attrMap->Item(i);
if (attribute) {
// We must clear the string buffers
- // because GetName, GetValue appends to previous string!
- name.Truncate();
+ // because GetValue appends to previous string!
value.Truncate();
- rv = attribute->GetName(name);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsAtom* name = attribute->NodeInfo()->NameAtom();
rv = attribute->GetValue(value);
NS_ENSURE_SUCCESS(rv, rv);
rv = SetInlineProperty(nsGkAtoms::a, name, value);
NS_ENSURE_SUCCESS(rv, rv);
}
}
@@ -3514,31 +3506,31 @@ HTMLEditor::SelectAll()
return errorResult.StealNSResult();
}
// this will NOT find aAttribute unless aAttribute has a non-null value
// so singleton attributes like <Table border> will not be matched!
bool
HTMLEditor::IsTextPropertySetByContent(nsINode* aNode,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue,
nsAString* outValue)
{
MOZ_ASSERT(aNode && aProperty);
while (aNode) {
if (aNode->IsElement()) {
Element* element = aNode->AsElement();
if (aProperty == element->NodeInfo()->NameAtom()) {
- if (!aAttribute || aAttribute->IsEmpty()) {
+ if (!aAttribute) {
return true;
}
nsAutoString value;
- element->GetAttribute(*aAttribute, value);
+ element->GetAttr(kNameSpaceID_None, aAttribute, value);
if (outValue) {
*outValue = value;
}
if (!value.IsEmpty()) {
if (!aValue) {
return true;
}
if (aValue->Equals(value, nsCaseInsensitiveStringComparator())) {
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -233,33 +233,33 @@ public:
nsresult GetAbsolutelyPositionedSelectionContainer(nsINode** aContainer);
Element* GetPositionedElement() const
{
return mAbsolutelyPositionedObject;
}
nsresult GetElementZIndex(Element* aElement, int32_t* aZindex);
nsresult SetInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue);
nsresult GetInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue,
bool* aFirst,
bool* aAny,
bool* aAll);
nsresult GetInlinePropertyWithAttrValue(nsAtom* aProperty,
- const nsAString& aAttr,
+ nsAtom* aAttr,
const nsAString& aValue,
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString& outValue);
nsresult RemoveInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute);
+ nsAtom* 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?
@@ -620,17 +620,17 @@ protected:
* @param outValue [OUT] the value of the attribute, if aIsSet is true
* @return true if <aProperty aAttribute=aValue> effects
* aNode.
*
* The nsIContent variant returns aIsSet instead of using an out parameter.
*/
bool IsTextPropertySetByContent(nsINode* aNode,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue,
nsAString* outValue = nullptr);
// Methods for handling plaintext quotations
NS_IMETHOD PasteAsPlaintextQuotation(int32_t aSelectionType);
/**
* Insert a string as quoted text, replacing the selected text (if any).
@@ -757,44 +757,42 @@ protected:
/**
* Helper routines for inline style.
*/
nsresult SetInlinePropertyOnTextNode(Text& aData,
int32_t aStartOffset,
int32_t aEndOffset,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue);
nsresult SetInlinePropertyOnNode(nsIContent& aNode,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue);
nsresult PromoteInlineRange(nsRange& aRange);
nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
nsresult SplitStyleAboveRange(nsRange* aRange,
nsAtom* aProperty,
- const nsAString* aAttribute);
+ nsAtom* aAttribute);
nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
nsIContent** aOutLeftNode = nullptr,
nsIContent** aOutRightNode = nullptr);
nsresult RemoveStyleInside(nsIContent& aNode,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const bool aChildrenOnly = false);
- nsresult RemoveInlinePropertyImpl(nsAtom* aProperty,
- const nsAString* aAttribute);
bool NodeIsProperty(nsINode& aNode);
bool IsAtFrontOfNode(nsINode& aNode, int32_t aOffset);
bool IsAtEndOfNode(nsINode& aNode, int32_t aOffset);
- bool IsOnlyAttribute(const Element* aElement, const nsAString& aAttribute);
+ bool IsOnlyAttribute(const Element* aElement, nsAtom* aAttribute);
nsresult RemoveBlockContainer(nsIContent& aNode);
nsIContent* GetPriorHTMLSibling(nsINode* aNode);
nsIContent* GetNextHTMLSibling(nsINode* aNode);
/**
@@ -872,17 +870,17 @@ protected:
bool IsLastEditableChild(nsINode* aNode);
nsIContent* GetFirstEditableChild(nsINode& aNode);
nsIContent* GetLastEditableChild(nsINode& aNode);
nsIContent* GetFirstEditableLeaf(nsINode& aNode);
nsIContent* GetLastEditableLeaf(nsINode& aNode);
nsresult GetInlinePropertyBase(nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue,
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString* outValue);
bool HasStyleOrIdOrClass(Element* aElement);
nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement);
@@ -910,17 +908,17 @@ protected:
nsIDOMDocument* aSourceDoc,
nsIDOMNode* aDestNode,
int32_t aDestOffset,
bool aDeleteSelection,
bool aTrustedInput,
bool aClearStyle = true);
nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
- nsAtom* aProperty, const nsAString* aAttribute);
+ nsAtom* aProperty, nsAtom* aAttribute);
void SetElementPosition(Element& aElement, int32_t aX, int32_t aY);
/**
* Reset a selected cell or collapsed selection (the caret) after table
* editing.
*
* @param aTable A table in the document.
@@ -1132,21 +1130,21 @@ public:
friend class HTMLEditorEventListener;
friend class HTMLEditRules;
friend class TextEditRules;
friend class WSRunObject;
private:
bool IsSimpleModifiableNode(nsIContent* aContent,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue);
nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue);
typedef enum { eInserted, eAppended } InsertedOrAppended;
void DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer,
nsIContent* aChild,
InsertedOrAppended aInsertedOrAppended);
already_AddRefed<Element> GetElementOrParentByTagName(
const nsAString& aTagName, nsINode* aNode);
already_AddRefed<Element> CreateElementWithDefaults(
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -55,22 +55,23 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINo
}
NS_IMETHODIMP
HTMLEditor::SetInlineProperty(const nsAString& aProperty,
const nsAString& aAttribute,
const nsAString& aValue)
{
RefPtr<nsAtom> property = NS_Atomize(aProperty);
- return SetInlineProperty(property, aAttribute, aValue);
+ RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
+ return SetInlineProperty(property, attribute, aValue);
}
nsresult
HTMLEditor::SetInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue)
{
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
RefPtr<TextEditRules> rules(mRules);
CommitComposition();
RefPtr<Selection> selection = GetSelection();
@@ -105,17 +106,17 @@ HTMLEditor::SetInlineProperty(nsAtom* aP
// Check for easy case: both range endpoints in same text node
nsCOMPtr<nsINode> startNode = range->GetStartContainer();
nsCOMPtr<nsINode> endNode = range->GetEndContainer();
if (startNode && startNode == endNode && startNode->GetAsText()) {
rv = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
range->StartOffset(),
range->EndOffset(),
- *aProperty, &aAttribute, aValue);
+ *aProperty, aAttribute, aValue);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
// Not the easy case. Range not contained in single text node. There
// are up to three phases here. There are all the nodes reported by the
// subtree iterator to be processed. And there are potentially a
// starting textnode and an ending textnode which are only partially
@@ -146,87 +147,84 @@ HTMLEditor::SetInlineProperty(nsAtom* aP
}
// First check the start parent of the range to see if it needs to be
// separately handled (it does if it's a text node, due to how the
// subtree iterator works - it will not have reported it).
if (startNode && startNode->GetAsText() && IsEditable(startNode)) {
rv = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
range->StartOffset(),
startNode->Length(), *aProperty,
- &aAttribute, aValue);
+ aAttribute, aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
// Then loop through the list, set the property on each node
for (auto& node : arrayOfNodes) {
- rv = SetInlinePropertyOnNode(*node, *aProperty, &aAttribute, aValue);
+ rv = SetInlinePropertyOnNode(*node, *aProperty, aAttribute, aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
// Last check the end parent of the range to see if it needs to be
// separately handled (it does if it's a text node, due to how the
// subtree iterator works - it will not have reported it).
if (endNode && endNode->GetAsText() && IsEditable(endNode)) {
rv = SetInlinePropertyOnTextNode(*endNode->GetAsText(), 0,
range->EndOffset(), *aProperty,
- &aAttribute, aValue);
+ aAttribute, aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
if (!cancel) {
// Post-process
return rules->DidDoAction(selection, &ruleInfo, rv);
}
return NS_OK;
}
// Helper function for SetInlinePropertyOn*: is aNode a simple old <b>, <font>,
// <span style="">, etc. that we can reuse instead of creating a new one?
bool
HTMLEditor::IsSimpleModifiableNode(nsIContent* aContent,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue)
{
// aContent can be null, in which case we'll return false in a few lines
MOZ_ASSERT(aProperty);
MOZ_ASSERT_IF(aAttribute, aValue);
nsCOMPtr<dom::Element> element = do_QueryInterface(aContent);
if (!element) {
return false;
}
// First check for <b>, <i>, etc.
if (element->IsHTMLElement(aProperty) && !element->GetAttrCount() &&
- (!aAttribute || aAttribute->IsEmpty())) {
+ !aAttribute) {
return true;
}
// Special cases for various equivalencies: <strong>, <em>, <s>
if (!element->GetAttrCount() &&
((aProperty == nsGkAtoms::b &&
element->IsHTMLElement(nsGkAtoms::strong)) ||
(aProperty == nsGkAtoms::i &&
element->IsHTMLElement(nsGkAtoms::em)) ||
(aProperty == nsGkAtoms::strike &&
element->IsHTMLElement(nsGkAtoms::s)))) {
return true;
}
// Now look for things like <font>
- if (aAttribute && !aAttribute->IsEmpty()) {
- RefPtr<nsAtom> atom = NS_Atomize(*aAttribute);
- MOZ_ASSERT(atom);
-
+ if (aAttribute) {
nsString attrValue;
if (element->IsHTMLElement(aProperty) &&
- IsOnlyAttribute(element, *aAttribute) &&
- element->GetAttr(kNameSpaceID_None, atom, attrValue) &&
+ IsOnlyAttribute(element, aAttribute) &&
+ element->GetAttr(kNameSpaceID_None, aAttribute, attrValue) &&
attrValue.Equals(*aValue, nsCaseInsensitiveStringComparator())) {
// This is not quite correct, because it excludes cases like
// <font face=000> being the same as <font face=#000000>.
// Property-specific handling is needed (bug 760211).
return true;
}
}
@@ -254,17 +252,17 @@ HTMLEditor::IsSimpleModifiableNode(nsICo
return mCSSEditUtils->ElementsSameStyle(newSpan, element);
}
nsresult
HTMLEditor::SetInlinePropertyOnTextNode(Text& aText,
int32_t aStartOffset,
int32_t aEndOffset,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue)
{
if (!aText.GetParentNode() ||
!CanContainTag(*aText.GetParentNode(), aProperty)) {
return NS_OK;
}
// Don't need to do anything if no characters actually selected
@@ -328,21 +326,19 @@ HTMLEditor::SetInlinePropertyOnTextNode(
// Reparent the node inside inline node with appropriate {attribute,value}
return SetInlinePropertyOnNode(*textNodeForTheRange,
aProperty, aAttribute, aValue);
}
nsresult
HTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue)
{
- RefPtr<nsAtom> attrAtom = aAttribute ? NS_Atomize(*aAttribute) : nullptr;
-
// If this is an element that can't be contained in a span, we have to
// recurse to its children.
if (!TagCanContain(*nsGkAtoms::span, aNode)) {
if (aNode.HasChildren()) {
nsTArray<OwningNonNull<nsIContent>> arrayOfNodes;
// Populate the list.
for (nsCOMPtr<nsIContent> child = aNode.GetFirstChild();
@@ -391,56 +387,55 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(
aAttribute, &aValue)) {
return NS_OK;
}
bool useCSS = (IsCSSEnabled() &&
mCSSEditUtils->IsCSSEditableProperty(&aNode, &aProperty,
aAttribute)) ||
// bgcolor is always done using CSS
- attrAtom == nsGkAtoms::bgcolor;
+ aAttribute == nsGkAtoms::bgcolor;
if (useCSS) {
nsCOMPtr<dom::Element> tmp;
// We only add style="" to <span>s with no attributes (bug 746515). If we
// don't have one, we need to make one.
if (aNode.IsHTMLElement(nsGkAtoms::span) &&
!aNode.AsElement()->GetAttrCount()) {
tmp = aNode.AsElement();
} else {
tmp = InsertContainerAbove(&aNode, nsGkAtoms::span);
NS_ENSURE_STATE(tmp);
}
// Add the CSS styles corresponding to the HTML style request
mCSSEditUtils->SetCSSEquivalentToHTMLStyle(tmp,
- &aProperty, attrAtom,
+ &aProperty, aAttribute,
&aValue, false);
return NS_OK;
}
// is it already the right kind of node, but with wrong attribute?
if (aNode.IsHTMLElement(&aProperty)) {
// Just set the attribute on it.
- nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(&aNode);
- return SetAttribute(elem, *aAttribute, aValue);
+ return SetAttribute(aNode.AsElement(), aAttribute, aValue);
}
// ok, chuck it in its very own container
- nsCOMPtr<Element> tmp = InsertContainerAbove(&aNode, &aProperty, attrAtom,
- &aValue);
+ RefPtr<Element> tmp = InsertContainerAbove(&aNode, &aProperty, aAttribute,
+ &aValue);
NS_ENSURE_STATE(tmp);
return NS_OK;
}
nsresult
HTMLEditor::SetInlinePropertyOnNode(nsIContent& aNode,
nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue)
{
nsCOMPtr<nsIContent> previousSibling = aNode.GetPreviousSibling(),
nextSibling = aNode.GetNextSibling();
NS_ENSURE_STATE(aNode.GetParentNode());
OwningNonNull<nsINode> parent = *aNode.GetParentNode();
nsresult rv = RemoveStyleInside(aNode, &aProperty, aAttribute);
@@ -474,17 +469,17 @@ HTMLEditor::SetInlinePropertyOnNode(nsIC
}
return NS_OK;
}
nsresult
HTMLEditor::SplitStyleAboveRange(nsRange* inRange,
nsAtom* aProperty,
- const nsAString* aAttribute)
+ nsAtom* aAttribute)
{
NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> startNode = inRange->GetStartContainer();
int32_t startOffset = inRange->StartOffset();
nsCOMPtr<nsINode> endNode = inRange->GetEndContainer();
int32_t endOffset = inRange->EndOffset();
@@ -513,17 +508,17 @@ HTMLEditor::SplitStyleAboveRange(nsRange
return NS_OK;
}
nsresult
HTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
int32_t* aOffset,
// null here means we split all properties
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
nsIContent** aOutLeftNode,
nsIContent** aOutRightNode)
{
NS_ENSURE_TRUE(aNode && *aNode && aOffset, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE((*aNode)->IsContent(), NS_OK);
if (aOutLeftNode) {
*aOutLeftNode = nullptr;
@@ -581,17 +576,17 @@ HTMLEditor::SplitStyleAbovePoint(nsCOMPt
return NS_OK;
}
nsresult
HTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode,
int32_t* aOffset,
nsAtom* aProperty,
- const nsAString* aAttribute)
+ nsAtom* aAttribute)
{
nsCOMPtr<nsIContent> leftNode, rightNode;
nsresult rv = SplitStyleAbovePoint(aNode, aOffset, aProperty,
aAttribute, getter_AddRefs(leftNode),
getter_AddRefs(rightNode));
NS_ENSURE_SUCCESS(rv, rv);
if (leftNode) {
@@ -677,17 +672,17 @@ HTMLEditor::NodeIsProperty(nsINode& aNod
{
return IsContainer(&aNode) && IsEditable(&aNode) && !IsBlockNode(&aNode) &&
!aNode.IsHTMLElement(nsGkAtoms::a);
}
nsresult
HTMLEditor::RemoveStyleInside(nsIContent& aNode,
nsAtom* aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const bool aChildrenOnly /* = false */)
{
if (aNode.GetAsText()) {
return NS_OK;
}
// first process the children
RefPtr<nsIContent> child = aNode.GetFirstChild();
@@ -706,17 +701,17 @@ HTMLEditor::RemoveStyleInside(nsIContent
// but check for link (<a href=...)
(aProperty == nsGkAtoms::href && HTMLEditUtils::IsLink(&aNode)) ||
// and for named anchors
(aProperty == nsGkAtoms::name && HTMLEditUtils::IsNamedAnchor(&aNode)) ||
// or node is any prop and we asked for that
(!aProperty && NodeIsProperty(aNode)))) {
// if we weren't passed an attribute, then we want to
// remove any matching inlinestyles entirely
- if (!aAttribute || aAttribute->IsEmpty()) {
+ if (!aAttribute) {
bool hasStyleAttr = aNode.HasAttr(kNameSpaceID_None, nsGkAtoms::style);
bool hasClassAttr = aNode.HasAttr(kNameSpaceID_None, nsGkAtoms::_class);
if (aProperty && (hasStyleAttr || hasClassAttr)) {
// aNode carries inline styles or a class attribute so we can't
// just remove the element... We need to create above the element
// a span that will carry those styles or class, then we can delete
// the node.
RefPtr<Element> spanNode =
@@ -728,96 +723,95 @@ HTMLEditor::RemoveStyleInside(nsIContent
rv =
CloneAttribute(nsGkAtoms::_class, spanNode, aNode.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
}
nsresult rv = RemoveContainer(&aNode);
NS_ENSURE_SUCCESS(rv, rv);
} else if (aNode.IsElement()) {
// otherwise we just want to eliminate the attribute
- RefPtr<nsAtom> attribute = NS_Atomize(*aAttribute);
- if (aNode.AsElement()->HasAttr(kNameSpaceID_None, attribute)) {
+ if (aNode.AsElement()->HasAttr(kNameSpaceID_None, aAttribute)) {
// if this matching attribute is the ONLY one on the node,
// then remove the whole node. Otherwise just nix the attribute.
- if (IsOnlyAttribute(aNode.AsElement(), *aAttribute)) {
+ if (IsOnlyAttribute(aNode.AsElement(), aAttribute)) {
nsresult rv = RemoveContainer(&aNode);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
- nsresult rv = RemoveAttribute(aNode.AsElement(), attribute);
+ nsresult rv = RemoveAttribute(aNode.AsElement(), aAttribute);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}
}
}
if (!aChildrenOnly &&
mCSSEditUtils->IsCSSEditableProperty(&aNode, aProperty, aAttribute)) {
// the HTML style defined by aProperty/aAttribute has a CSS equivalence in
// this implementation for the node aNode; let's check if it carries those
// css styles
if (aNode.IsElement()) {
- RefPtr<nsAtom> attribute =
- aAttribute ? NS_Atomize(*aAttribute) : nullptr;
bool hasAttribute =
mCSSEditUtils->HaveCSSEquivalentStyles(
- aNode, aProperty, attribute, CSSEditUtils::eSpecified);
+ aNode, aProperty, aAttribute,
+ CSSEditUtils::eSpecified);
if (hasAttribute) {
// yes, tmp has the corresponding css declarations in its style
// attribute
// let's remove them
mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(aNode.AsElement(),
aProperty,
- attribute,
+ aAttribute,
nullptr,
false);
// remove the node if it is a span or font, if its style attribute is
// empty or absent, and if it does not have a class nor an id
RemoveElementIfNoStyleOrIdOrClass(*aNode.AsElement());
}
}
}
// Or node is big or small and we are setting font size
if (aChildrenOnly) {
return NS_OK;
}
if (aProperty == nsGkAtoms::font &&
(aNode.IsHTMLElement(nsGkAtoms::big) ||
aNode.IsHTMLElement(nsGkAtoms::small)) &&
- aAttribute && aAttribute->LowerCaseEqualsLiteral("size")) {
+ aAttribute == nsGkAtoms::size) {
// if we are setting font size, remove any nested bigs and smalls
return RemoveContainer(&aNode);
}
return NS_OK;
}
bool
HTMLEditor::IsOnlyAttribute(const Element* aElement,
- const nsAString& aAttribute)
+ nsAtom* aAttribute)
{
MOZ_ASSERT(aElement);
uint32_t attrCount = aElement->GetAttrCount();
for (uint32_t i = 0; i < attrCount; ++i) {
const nsAttrName* name = aElement->GetAttrNameAt(i);
if (!name->NamespaceEquals(kNameSpaceID_None)) {
return false;
}
- nsAutoString attrString;
- name->LocalName()->ToString(attrString);
// if it's the attribute we know about, or a special _moz attribute,
// keep looking
- if (!attrString.Equals(aAttribute, nsCaseInsensitiveStringComparator()) &&
- !StringBeginsWith(attrString, NS_LITERAL_STRING("_moz"))) {
- return false;
+ if (name->LocalName() != aAttribute) {
+ nsAutoString attrString;
+ name->LocalName()->ToString(attrString);
+ if (!StringBeginsWith(attrString, NS_LITERAL_STRING("_moz"))) {
+ return false;
+ }
}
}
// if we made it through all of them without finding a real attribute
// other than aAttribute, then return true
return true;
}
nsresult
@@ -935,17 +929,17 @@ HTMLEditor::IsAtEndOfNode(nsINode& aNode
return true;
}
return false;
}
nsresult
HTMLEditor::GetInlinePropertyBase(nsAtom& aProperty,
- const nsAString* aAttribute,
+ nsAtom* aAttribute,
const nsAString* aValue,
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString* outValue)
{
*aAny = false;
*aAll = true;
@@ -964,18 +958,17 @@ HTMLEditor::GetInlinePropertyBase(nsAtom
bool firstNodeInRange = true;
if (isCollapsed) {
nsCOMPtr<nsINode> collapsedNode = range->GetStartContainer();
NS_ENSURE_TRUE(collapsedNode, NS_ERROR_FAILURE);
bool isSet, theSetting;
nsString tOutString;
if (aAttribute) {
- nsString tString(*aAttribute);
- mTypeInState->GetTypingState(isSet, theSetting, &aProperty, tString,
+ mTypeInState->GetTypingState(isSet, theSetting, &aProperty, aAttribute,
&tOutString);
if (outValue) {
outValue->Assign(tOutString);
}
} else {
mTypeInState->GetTypingState(isSet, theSetting, &aProperty);
}
if (isSet) {
@@ -1100,119 +1093,109 @@ NS_IMETHODIMP
HTMLEditor::GetInlineProperty(const nsAString& aProperty,
const nsAString& aAttribute,
const nsAString& aValue,
bool* aFirst,
bool* aAny,
bool* aAll)
{
RefPtr<nsAtom> property = NS_Atomize(aProperty);
- return GetInlineProperty(property, aAttribute, aValue, aFirst, aAny, aAll);
+ RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
+ return GetInlineProperty(property, attribute, aValue, aFirst, aAny, aAll);
}
nsresult
HTMLEditor::GetInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue,
bool* aFirst,
bool* aAny,
bool* aAll)
{
NS_ENSURE_TRUE(aProperty && aFirst && aAny && aAll, NS_ERROR_NULL_POINTER);
- const nsAString *att = nullptr;
- if (!aAttribute.IsEmpty())
- att = &aAttribute;
const nsAString *val = nullptr;
if (!aValue.IsEmpty())
val = &aValue;
- return GetInlinePropertyBase(*aProperty, att, val, aFirst, aAny, aAll, nullptr);
+ return GetInlinePropertyBase(*aProperty, aAttribute, 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)
{
RefPtr<nsAtom> property = NS_Atomize(aProperty);
- return GetInlinePropertyWithAttrValue(property, aAttribute, aValue, aFirst,
+ RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
+ return GetInlinePropertyWithAttrValue(property, attribute, aValue, aFirst,
aAny, aAll, outValue);
}
nsresult
HTMLEditor::GetInlinePropertyWithAttrValue(nsAtom* aProperty,
- const nsAString& aAttribute,
+ nsAtom* aAttribute,
const nsAString& aValue,
bool* aFirst,
bool* aAny,
bool* aAll,
nsAString& outValue)
{
NS_ENSURE_TRUE(aProperty && aFirst && aAny && aAll, NS_ERROR_NULL_POINTER);
- const nsAString *att = nullptr;
- if (!aAttribute.IsEmpty())
- att = &aAttribute;
const nsAString *val = nullptr;
if (!aValue.IsEmpty())
val = &aValue;
- return GetInlinePropertyBase(*aProperty, att, val, aFirst, aAny, aAll, &outValue);
+ return GetInlinePropertyBase(*aProperty, aAttribute, val, aFirst, aAny, aAll, &outValue);
}
NS_IMETHODIMP
HTMLEditor::RemoveAllInlineProperties()
{
AutoPlaceholderBatch batchIt(this);
AutoRules beginRulesSniffing(this, EditAction::resetTextProperties,
nsIEditor::eNext);
- nsresult rv = RemoveInlinePropertyImpl(nullptr, nullptr);
+ nsresult rv = RemoveInlineProperty(nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
HTMLEditor::RemoveInlineProperty(const nsAString& aProperty,
const nsAString& aAttribute)
{
RefPtr<nsAtom> property = NS_Atomize(aProperty);
- return RemoveInlineProperty(property, aAttribute);
+ RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
+ return RemoveInlineProperty(property, attribute);
}
nsresult
HTMLEditor::RemoveInlineProperty(nsAtom* aProperty,
- const nsAString& aAttribute)
+ nsAtom* aAttribute)
{
- return RemoveInlinePropertyImpl(aProperty, &aAttribute);
-}
-
-nsresult
-HTMLEditor::RemoveInlinePropertyImpl(nsAtom* aProperty,
- const nsAString* aAttribute)
-{
- MOZ_ASSERT_IF(aProperty, aAttribute);
NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
CommitComposition();
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
if (selection->Collapsed()) {
// Manipulating text attributes on a collapsed selection only sets state
// for the next text insertion
// For links, aProperty uses "href", use "a" instead
if (aProperty == nsGkAtoms::href || aProperty == nsGkAtoms::name) {
aProperty = nsGkAtoms::a;
}
if (aProperty) {
- mTypeInState->ClearProp(aProperty, *aAttribute);
+ mTypeInState->ClearProp(aProperty, aAttribute);
} else {
mTypeInState->ClearAllProps();
}
return NS_OK;
}
AutoPlaceholderBatch batchIt(this);
AutoRules beginRulesSniffing(this, EditAction::removeTextProperty,
@@ -1361,17 +1344,17 @@ HTMLEditor::RelativeFontChange(FontSize
selectedNode = *selectedNode->GetParentNode();
}
if (!CanContainTag(selectedNode, atom)) {
return NS_OK;
}
// Manipulating text attributes on a collapsed selection only sets state
// for the next text insertion
- mTypeInState->SetProp(&atom, EmptyString(), EmptyString());
+ mTypeInState->SetProp(&atom, nullptr, EmptyString());
return NS_OK;
}
// Wrap with txn batching, rules sniffing, and selection preservation code
AutoPlaceholderBatch batchIt(this);
AutoRules beginRulesSniffing(this, EditAction::setTextProperty,
nsIEditor::eNext);
AutoSelectionRestorer selectionRestorer(selection, this);
@@ -1648,19 +1631,18 @@ HTMLEditor::GetFontFaceState(bool* aMixe
nsAString& outFace)
{
NS_ENSURE_TRUE(aMixed, NS_ERROR_FAILURE);
*aMixed = true;
outFace.Truncate();
bool first, any, all;
- NS_NAMED_LITERAL_STRING(attr, "face");
nsresult rv =
- GetInlinePropertyBase(*nsGkAtoms::font, &attr.AsString(), nullptr, &first,
+ GetInlinePropertyBase(*nsGkAtoms::font, nsGkAtoms::face, nullptr, &first,
&any, &all, &outFace);
NS_ENSURE_SUCCESS(rv, rv);
if (any && !all) {
return NS_OK; // mixed
}
if (all) {
*aMixed = false;
return NS_OK;
@@ -1689,21 +1671,20 @@ HTMLEditor::GetFontFaceState(bool* aMixe
NS_IMETHODIMP
HTMLEditor::GetFontColorState(bool* aMixed,
nsAString& aOutColor)
{
NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
*aMixed = true;
aOutColor.Truncate();
- NS_NAMED_LITERAL_STRING(colorStr, "color");
bool first, any, all;
nsresult rv =
- GetInlinePropertyBase(*nsGkAtoms::font, &colorStr.AsString(), nullptr,
+ GetInlinePropertyBase(*nsGkAtoms::font, nsGkAtoms::color, nullptr,
&first, &any, &all, &aOutColor);
NS_ENSURE_SUCCESS(rv, rv);
if (any && !all) {
return NS_OK; // mixed
}
if (all) {
*aMixed = false;
return NS_OK;
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -134,17 +134,17 @@ TypeInState::Reset()
delete mSetArray[i];
}
mSetArray.Clear();
}
void
TypeInState::SetProp(nsAtom* aProp,
- const nsAString& aAttr,
+ nsAtom* aAttr,
const nsAString& aValue)
{
// special case for big/small, these nest
if (nsGkAtoms::big == aProp) {
mRelativeFontSize++;
return;
}
if (nsGkAtoms::small == aProp) {
@@ -166,22 +166,22 @@ TypeInState::SetProp(nsAtom* aProp,
RemovePropFromClearedList(aProp, aAttr);
}
void
TypeInState::ClearAllProps()
{
// null prop means "all" props
- ClearProp(nullptr, EmptyString());
+ ClearProp(nullptr, nullptr);
}
void
TypeInState::ClearProp(nsAtom* aProp,
- const nsAString& aAttr)
+ nsAtom* aAttr)
{
// if it's already cleared we are done
if (IsPropCleared(aProp, aAttr)) {
return;
}
// make a new propitem
PropItem* item = new PropItem(aProp, aAttr, EmptyString());
@@ -239,42 +239,34 @@ TypeInState::TakeRelativeFontSize()
int32_t relSize = mRelativeFontSize;
mRelativeFontSize = 0;
return relSize;
}
void
TypeInState::GetTypingState(bool& isSet,
bool& theSetting,
- nsAtom* aProp)
-{
- GetTypingState(isSet, theSetting, aProp, EmptyString(), nullptr);
-}
-
-void
-TypeInState::GetTypingState(bool& isSet,
- bool& theSetting,
nsAtom* aProp,
- const nsString& aAttr,
+ nsAtom* aAttr,
nsString* aValue)
{
if (IsPropSet(aProp, aAttr, aValue)) {
isSet = true;
theSetting = true;
} else if (IsPropCleared(aProp, aAttr)) {
isSet = true;
theSetting = false;
} else {
isSet = false;
}
}
void
TypeInState::RemovePropFromSetList(nsAtom* aProp,
- const nsAString& aAttr)
+ nsAtom* aAttr)
{
int32_t index;
if (!aProp) {
// clear _all_ props
for (size_t i = 0, n = mSetArray.Length(); i < n; i++) {
delete mSetArray[i];
}
mSetArray.Clear();
@@ -282,37 +274,37 @@ TypeInState::RemovePropFromSetList(nsAto
} else if (FindPropInList(aProp, aAttr, nullptr, mSetArray, index)) {
delete mSetArray[index];
mSetArray.RemoveElementAt(index);
}
}
void
TypeInState::RemovePropFromClearedList(nsAtom* aProp,
- const nsAString& aAttr)
+ nsAtom* aAttr)
{
int32_t index;
if (FindPropInList(aProp, aAttr, nullptr, mClearedArray, index)) {
delete mClearedArray[index];
mClearedArray.RemoveElementAt(index);
}
}
bool
TypeInState::IsPropSet(nsAtom* aProp,
- const nsAString& aAttr,
+ nsAtom* aAttr,
nsAString* outValue)
{
int32_t i;
return IsPropSet(aProp, aAttr, outValue, i);
}
bool
TypeInState::IsPropSet(nsAtom* aProp,
- const nsAString& aAttr,
+ nsAtom* aAttr,
nsAString* outValue,
int32_t& outIndex)
{
// linear search. list should be short.
size_t count = mSetArray.Length();
for (size_t i = 0; i < count; i++) {
PropItem *item = mSetArray[i];
if (item->tag == aProp && item->attr == aAttr) {
@@ -324,42 +316,42 @@ TypeInState::IsPropSet(nsAtom* aProp,
}
}
return false;
}
bool
TypeInState::IsPropCleared(nsAtom* aProp,
- const nsAString& aAttr)
+ nsAtom* aAttr)
{
int32_t i;
return IsPropCleared(aProp, aAttr, i);
}
bool
TypeInState::IsPropCleared(nsAtom* aProp,
- const nsAString& aAttr,
+ nsAtom* aAttr,
int32_t& outIndex)
{
if (FindPropInList(aProp, aAttr, nullptr, mClearedArray, outIndex)) {
return true;
}
- if (FindPropInList(0, EmptyString(), nullptr, mClearedArray, outIndex)) {
+ if (FindPropInList(nullptr, nullptr, nullptr, mClearedArray, outIndex)) {
// special case for all props cleared
outIndex = -1;
return true;
}
return false;
}
bool
TypeInState::FindPropInList(nsAtom* aProp,
- const nsAString& aAttr,
+ nsAtom* aAttr,
nsAString* outValue,
nsTArray<PropItem*>& aList,
int32_t& outIndex)
{
// linear search. list should be short.
size_t count = aList.Length();
for (size_t i = 0; i < count; i++) {
PropItem *item = aList[i];
@@ -375,22 +367,23 @@ TypeInState::FindPropInList(nsAtom* aPro
}
/********************************************************************
* mozilla::PropItem: helper struct for mozilla::TypeInState
*******************************************************************/
PropItem::PropItem()
: tag(nullptr)
+ , attr(nullptr)
{
MOZ_COUNT_CTOR(PropItem);
}
PropItem::PropItem(nsAtom* aTag,
- const nsAString& aAttr,
+ nsAtom* aAttr,
const nsAString &aValue)
: tag(aTag)
, attr(aAttr)
, value(aValue)
{
MOZ_COUNT_CTOR(PropItem);
}
--- a/editor/libeditor/TypeInState.h
+++ b/editor/libeditor/TypeInState.h
@@ -28,21 +28,21 @@ namespace mozilla {
class HTMLEditRules;
namespace dom {
class Selection;
} // namespace dom
struct PropItem
{
nsAtom* tag;
- nsString attr;
+ nsAtom* attr;
nsString value;
PropItem();
- PropItem(nsAtom* aTag, const nsAString& aAttr, const nsAString& aValue);
+ PropItem(nsAtom* aTag, nsAtom* aAttr, const nsAString& aValue);
~PropItem();
};
class TypeInState final : public nsISelectionListener
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(TypeInState)
@@ -50,20 +50,20 @@ public:
TypeInState();
void Reset();
nsresult UpdateSelState(dom::Selection* aSelection);
// nsISelectionListener
NS_DECL_NSISELECTIONLISTENER
- void SetProp(nsAtom* aProp, const nsAString& aAttr, const nsAString& aValue);
+ void SetProp(nsAtom* aProp, nsAtom* aAttr, const nsAString& aValue);
void ClearAllProps();
- void ClearProp(nsAtom* aProp, const nsAString& aAttr);
+ void ClearProp(nsAtom* aProp, nsAtom* aAttr);
/**
* TakeClearProperty() hands back next property item on the clear list.
* Caller assumes ownership of PropItem and must delete it.
*/
UniquePtr<PropItem> TakeClearProperty();
/**
@@ -73,34 +73,33 @@ public:
UniquePtr<PropItem> TakeSetProperty();
/**
* TakeRelativeFontSize() hands back relative font value, which is then
* cleared out.
*/
int32_t TakeRelativeFontSize();
- void GetTypingState(bool& isSet, bool& theSetting, nsAtom* aProp);
void GetTypingState(bool& isSet, bool& theSetting, nsAtom* aProp,
- const nsString& aAttr, nsString* outValue);
+ nsAtom* aAttr = nullptr, nsString* outValue = nullptr);
- static bool FindPropInList(nsAtom* aProp, const nsAString& aAttr,
+ static bool FindPropInList(nsAtom* aProp, nsAtom* aAttr,
nsAString* outValue, nsTArray<PropItem*>& aList,
int32_t& outIndex);
protected:
virtual ~TypeInState();
- void RemovePropFromSetList(nsAtom* aProp, const nsAString& aAttr);
- void RemovePropFromClearedList(nsAtom* aProp, const nsAString& aAttr);
- bool IsPropSet(nsAtom* aProp, const nsAString& aAttr, nsAString* outValue);
- bool IsPropSet(nsAtom* aProp, const nsAString& aAttr, nsAString* outValue,
+ void RemovePropFromSetList(nsAtom* aProp, nsAtom* aAttr);
+ void RemovePropFromClearedList(nsAtom* aProp, nsAtom* aAttr);
+ bool IsPropSet(nsAtom* aProp, nsAtom* aAttr, nsAString* outValue);
+ bool IsPropSet(nsAtom* aProp, nsAtom* aAttr, nsAString* outValue,
int32_t& outIndex);
- bool IsPropCleared(nsAtom* aProp, const nsAString& aAttr);
- bool IsPropCleared(nsAtom* aProp, const nsAString& aAttr, int32_t& outIndex);
+ bool IsPropCleared(nsAtom* aProp, nsAtom* aAttr);
+ bool IsPropCleared(nsAtom* aProp, nsAtom* aAttr, int32_t& outIndex);
nsTArray<PropItem*> mSetArray;
nsTArray<PropItem*> mClearedArray;
int32_t mRelativeFontSize;
nsCOMPtr<nsIDOMNode> mLastSelectionContainer;
int32_t mLastSelectionOffset;
friend class HTMLEditRules;