Bug 1580491 - Introduce Element::HasNonEmptyAttr; r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D51213

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-10-31 16:09:19 +00:00
Родитель ce7c2ef520
Коммит 5301c9ad90
1 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -764,6 +764,20 @@ class Element : public FragmentOrElement {
return HasAttr(kNameSpaceID_None, aAttr);
}
/**
* Determine if an attribute has been set to a non-empty string value. If the
* attribute is not set at all, this will return false.
*
* @param aNameSpaceId the namespace id of the attribute (defaults to
* kNameSpaceID_None in the overload that omits this arg)
* @param aAttr the attribute name
*/
inline bool HasNonEmptyAttr(int32_t aNameSpaceID, const nsAtom* aName) const;
bool HasNonEmptyAttr(const nsAtom* aAttr) const {
return HasNonEmptyAttr(kNameSpaceID_None, aAttr);
}
/**
* Test whether this Element's given attribute has the given value. If the
* attribute is not set at all, this will return false.
@ -1988,6 +2002,15 @@ inline bool Element::HasAttr(int32_t aNameSpaceID, const nsAtom* aName) const {
return mAttrs.IndexOfAttr(aName, aNameSpaceID) >= 0;
}
inline bool Element::HasNonEmptyAttr(int32_t aNameSpaceID,
const nsAtom* aName) const {
MOZ_ASSERT(aNameSpaceID > kNameSpaceID_Unknown, "Must have namespace");
MOZ_ASSERT(aName, "Must have attribute name");
const nsAttrValue* val = mAttrs.GetAttr(aName, aNameSpaceID);
return val && !val->IsEmptyString();
}
inline bool Element::AttrValueIs(int32_t aNameSpaceID, const nsAtom* aName,
const nsAString& aValue,
nsCaseTreatment aCaseSensitive) const {