Bug 659610 - Remove nsGenericHTMLElement::SetAttrHelper and related helper macros. r?qdot
The only remaining instance of NS_IMPL_BOOL_ATTR macro was expanded by hand.
MozReview-Commit-ID: DQ8fGGNTl3y
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1572,53 +1572,49 @@ public:
nsINode* GetScopeChainParent() const override;
/**
* Locate a TextEditor rooted at this content node, if there is one.
*/
mozilla::TextEditor* GetTextEditorInternal();
/**
- * Helper method for NS_IMPL_BOOL_ATTR macro.
* Gets value of boolean attribute. Only works for attributes in null
* namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
bool GetBoolAttr(nsAtom* aAttr) const
{
return HasAttr(kNameSpaceID_None, aAttr);
}
/**
- * Helper method for NS_IMPL_BOOL_ATTR macro.
* Sets value of boolean attribute by removing attribute or setting it to
* the empty string. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
nsresult SetBoolAttr(nsAtom* aAttr, bool aValue);
/**
- * Helper method for NS_IMPL_ENUM_ATTR_DEFAULT_VALUE.
* Gets the enum value string of an attribute and using a default value if
* the attribute is missing or the string is an invalid enum value.
*
* @param aType the name of the attribute.
* @param aDefault the default value if the attribute is missing or invalid.
* @param aResult string corresponding to the value [out].
*/
void GetEnumAttr(nsAtom* aAttr,
const char* aDefault,
nsAString& aResult) const;
/**
- * Helper method for NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES.
* Gets the enum value string of an attribute and using the default missing
* value if the attribute is missing or the default invalid value if the
* string is an invalid enum value.
*
* @param aType the name of the attribute.
* @param aDefaultMissing the default value if the attribute is missing. If
null and the attribute is missing, aResult will be
set to the null DOMString; this only matters for
@@ -2153,47 +2149,9 @@ nsresult
return rv; \
}
#define NS_IMPL_ELEMENT_CLONE_WITH_INIT(_elementName) \
NS_IMPL_ELEMENT_CLONE_WITH_INIT_HELPER(_elementName, ())
#define NS_IMPL_ELEMENT_CLONE_WITH_INIT_AND_PARSER(_elementName) \
NS_IMPL_ELEMENT_CLONE_WITH_INIT_HELPER(_elementName, (, NOT_FROM_PARSER))
-/**
- * A macro to implement the getter and setter for a given string
- * valued content property. The method uses the generic GetAttr and
- * SetAttr methods. We use the 5-argument form of SetAttr, because
- * some consumers only implement that one, hiding superclass
- * 4-argument forms.
- */
-#define NS_IMPL_STRING_ATTR(_class, _method, _atom) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, nullptr, aValue, true); \
- }
-
-/**
- * A macro to implement the getter and setter for a given boolean
- * valued content property. The method uses the GetBoolAttr and
- * SetBoolAttr methods.
- */
-#define NS_IMPL_BOOL_ATTR(_class, _method, _atom) \
- NS_IMETHODIMP \
- _class::Get##_method(bool* aValue) \
- { \
- *aValue = GetBoolAttr(nsGkAtoms::_atom); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(bool aValue) \
- { \
- return SetBoolAttr(nsGkAtoms::_atom, aValue); \
- }
-
#endif // mozilla_dom_Element_h__
--- a/dom/html/HTMLFrameElement.h
+++ b/dom/html/HTMLFrameElement.h
@@ -48,17 +48,17 @@ public:
}
void GetLongDesc(nsAString& aLongDesc) const
{
GetURIAttr(nsGkAtoms::longdesc, nullptr, aLongDesc);
}
void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError)
{
- SetAttrHelper(nsGkAtoms::longdesc, aLongDesc);
+ SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc);
}
void GetMarginHeight(DOMString& aMarginHeight) const
{
GetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight);
}
void SetMarginHeight(const nsAString& aMarginHeight, ErrorResult& aError)
{
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -1510,22 +1510,16 @@ nsGenericHTMLElement::MapBackgroundAttri
GenericSpecifiedValues* aData)
{
MapBackgroundInto(aAttributes, aData);
MapBGColorInto(aAttributes, aData);
}
//----------------------------------------------------------------------
-nsresult
-nsGenericHTMLElement::SetAttrHelper(nsAtom* aAttr, const nsAString& aValue)
-{
- return SetAttr(kNameSpaceID_None, aAttr, aValue, true);
-}
-
int32_t
nsGenericHTMLElement::GetIntAttr(nsAtom* aAttr, int32_t aDefault) const
{
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr);
if (attrVal && attrVal->Type() == nsAttrValue::eInteger) {
return attrVal->GetIntegerValue();
}
return aDefault;
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -619,17 +619,16 @@ public:
/**
* See if the document being tested has nav-quirks mode enabled.
* @param doc the document
*/
static bool InNavQuirksMode(nsIDocument* aDoc);
/**
- * Helper method for NS_IMPL_URI_ATTR macro.
* Gets the absolute URI value of an attribute, by resolving any relative
* URIs in the attribute against the baseuri of the element. If the attribute
* isn't a relative URI the value of the attribute is returned as is. Only
* works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aBaseAttr name of base attribute.
* @param aResult result value [out]
@@ -812,60 +811,45 @@ protected:
{
nsAutoString value;
value.AppendInt(aValue);
SetHTMLAttr(aName, value, aError);
}
/**
- * Helper method for NS_IMPL_STRING_ATTR macro.
- * Sets the value of an attribute, returns specified default value if the
- * attribute isn't set. Only works for attributes in null namespace.
- *
- * @param aAttr name of attribute.
- * @param aDefault default-value to return if attribute isn't set.
- * @param aResult result value [out]
- */
- nsresult SetAttrHelper(nsAtom* aAttr, const nsAString& aValue);
-
- /**
- * Helper method for NS_IMPL_INT_ATTR macro.
* Gets the integer-value of an attribute, returns specified default value
* if the attribute isn't set or isn't set to an integer. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
*/
int32_t GetIntAttr(nsAtom* aAttr, int32_t aDefault) const;
/**
- * Helper method for NS_IMPL_INT_ATTR macro.
* Sets value of attribute to specified integer. Only works for attributes
* in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Integer value of attribute.
*/
nsresult SetIntAttr(nsAtom* aAttr, int32_t aValue);
/**
- * Helper method for NS_IMPL_UINT_ATTR macro.
* Gets the unsigned integer-value of an attribute, returns specified default
* value if the attribute isn't set or isn't set to an integer. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
*/
uint32_t GetUnsignedIntAttr(nsAtom* aAttr, uint32_t aDefault) const;
/**
- * Helper method for NS_IMPL_UINT_ATTR macro.
* Sets value of attribute to specified unsigned integer. Only works for
* attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Integer value of attribute.
* @param aDefault Default value (in case value is out of range). If the spec
* doesn't provide one, should be 1 if the value is limited to
* nonzero values, and 0 otherwise.
@@ -1236,225 +1220,16 @@ protected:
computed already. The result is stored in mStateKey on success */
nsresult GenerateStateKey();
/* Used to store the key to that element in the session. Is void until
GenerateStateKey has been used */
nsCString mStateKey;
};
-//----------------------------------------------------------------------
-
-/**
- * This macro is similar to NS_IMPL_STRING_ATTR except that the getter method
- * falls back to an alternative method if the content attribute isn't set.
- */
-#define NS_IMPL_STRING_ATTR_WITH_FALLBACK(_class, _method, _atom, _fallback) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- if (!GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue)) { \
- _fallback(aValue); \
- } \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement the getter and setter for a given integer
- * valued content property. The method uses the generic GetAttr and
- * SetAttr methods.
- */
-#define NS_IMPL_INT_ATTR(_class, _method, _atom) \
- NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, 0)
-
-#define NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
- NS_IMETHODIMP \
- _class::Get##_method(int32_t* aValue) \
- { \
- *aValue = GetIntAttr(nsGkAtoms::_atom, _default); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(int32_t aValue) \
- { \
- return SetIntAttr(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement the getter and setter for a given unsigned integer
- * valued content property. The method uses GetUnsignedIntAttr and
- * SetUnsignedIntAttr methods.
- */
-#define NS_IMPL_UINT_ATTR(_class, _method, _atom) \
- NS_IMPL_UINT_ATTR_DEFAULT_VALUE(_class, _method, _atom, 0)
-
-#define NS_IMPL_UINT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
- NS_IMETHODIMP \
- _class::Get##_method(uint32_t* aValue) \
- { \
- *aValue = GetUnsignedIntAttr(nsGkAtoms::_atom, _default); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(uint32_t aValue) \
- { \
- mozilla::ErrorResult rv; \
- SetUnsignedIntAttr(nsGkAtoms::_atom, aValue, _default, rv); \
- return rv.StealNSResult(); \
- }
-
-/**
- * A macro to implement the getter and setter for a given unsigned integer
- * valued content property. The method uses GetUnsignedIntAttr and
- * SetUnsignedIntAttr methods. This macro is similar to NS_IMPL_UINT_ATTR except
- * that it throws an exception if the set value is null.
- */
-#define NS_IMPL_UINT_ATTR_NON_ZERO(_class, _method, _atom) \
- NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(_class, _method, _atom, 1)
-
-#define NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(_class, _method, _atom, _default) \
- NS_IMETHODIMP \
- _class::Get##_method(uint32_t* aValue) \
- { \
- *aValue = GetUnsignedIntAttr(nsGkAtoms::_atom, _default); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(uint32_t aValue) \
- { \
- if (aValue == 0) { \
- return NS_ERROR_DOM_INDEX_SIZE_ERR; \
- } \
- mozilla::ErrorResult rv; \
- SetUnsignedIntAttr(nsGkAtoms::_atom, aValue, _default, rv); \
- return rv.StealNSResult(); \
- }
-
-/**
- * A macro to implement the getter and setter for a given content
- * property that needs to return a URI in string form. The method
- * uses the generic GetAttr and SetAttr methods. This macro is much
- * like the NS_IMPL_STRING_ATTR macro, except we make sure the URI is
- * absolute.
- */
-#define NS_IMPL_URI_ATTR(_class, _method, _atom) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetURIAttr(nsGkAtoms::_atom, nullptr, aValue); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
-#define NS_IMPL_URI_ATTR_WITH_BASE(_class, _method, _atom, _base_atom) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetURIAttr(nsGkAtoms::_atom, nsGkAtoms::_base_atom, aValue); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement getter and setter for action and form action content
- * attributes. It's very similar to NS_IMPL_URI_ATTR excepted that if the
- * content attribute is the empty string, the empty string is returned.
- */
-#define NS_IMPL_ACTION_ATTR(_class, _method, _atom) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue); \
- if (!aValue.IsEmpty()) { \
- GetURIAttr(nsGkAtoms::_atom, nullptr, aValue); \
- } \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement the getter and setter for a given content
- * property that needs to set a non-negative integer. The method
- * uses the generic GetAttr and SetAttr methods. This macro is much
- * like the NS_IMPL_INT_ATTR macro except we throw an exception if
- * the set value is negative.
- */
-#define NS_IMPL_NON_NEGATIVE_INT_ATTR(_class, _method, _atom) \
- NS_IMPL_NON_NEGATIVE_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, -1)
-
-#define NS_IMPL_NON_NEGATIVE_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
- NS_IMETHODIMP \
- _class::Get##_method(int32_t* aValue) \
- { \
- *aValue = GetIntAttr(nsGkAtoms::_atom, _default); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(int32_t aValue) \
- { \
- if (aValue < 0) { \
- return NS_ERROR_DOM_INDEX_SIZE_ERR; \
- } \
- return SetIntAttr(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement the getter and setter for a given content
- * property that needs to set an enumerated string. The method
- * uses a specific GetEnumAttr and the generic SetAttrHelper methods.
- */
-#define NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetEnumAttr(nsGkAtoms::_atom, _default, aValue); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
-/**
- * A macro to implement the getter and setter for a given content
- * property that needs to set an enumerated string that has different
- * default values for missing and invalid values. The method uses a
- * specific GetEnumAttr and the generic SetAttrHelper methods.
- */
-#define NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(_class, _method, _atom, _defaultMissing, _defaultInvalid) \
- NS_IMETHODIMP \
- _class::Get##_method(nsAString& aValue) \
- { \
- GetEnumAttr(nsGkAtoms::_atom, _defaultMissing, _defaultInvalid, aValue); \
- return NS_OK; \
- } \
- NS_IMETHODIMP \
- _class::Set##_method(const nsAString& aValue) \
- { \
- return SetAttrHelper(nsGkAtoms::_atom, aValue); \
- }
-
#define NS_INTERFACE_MAP_ENTRY_IF_TAG(_interface, _tag) \
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, \
mNodeInfo->Equals(nsGkAtoms::_tag))
namespace mozilla {
namespace dom {
typedef nsGenericHTMLElement* (*HTMLContentCreatorFunction)(
--- a/dom/html/nsGenericHTMLFrameElement.cpp
+++ b/dom/html/nsGenericHTMLFrameElement.cpp
@@ -51,17 +51,27 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsGenericHTMLFrameElement,
nsGenericHTMLElement,
nsIFrameLoaderOwner,
nsIDOMMozBrowserFrame,
nsIMozBrowserFrame,
nsGenericHTMLFrameElement)
-NS_IMPL_BOOL_ATTR(nsGenericHTMLFrameElement, Mozbrowser, mozbrowser)
+NS_IMETHODIMP
+nsGenericHTMLFrameElement::GetMozbrowser(bool* aValue)
+{
+ *aValue = GetBoolAttr(nsGkAtoms::mozbrowser);
+ return NS_OK;
+}
+NS_IMETHODIMP
+nsGenericHTMLFrameElement::SetMozbrowser(bool aValue)
+{
+ return SetBoolAttr(nsGkAtoms::mozbrowser, aValue);
+}
int32_t
nsGenericHTMLFrameElement::TabIndexDefault()
{
return 0;
}
nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement()