Bug 1450643 part 1 - add additional overloads to Element for GetAttr/HasAttr for kNameSpaceID_None to complement the existing SetAttr method that does not take a namespace. r=mystor

This commit is contained in:
Robert Longson 2018-04-04 04:58:49 +01:00
Родитель c6e5997d48
Коммит 7b723d1d6e
5 изменённых файлов: 31 добавлений и 19 удалений

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

@ -723,7 +723,8 @@ public:
* Get the current value of the attribute. This returns a form that is
* suitable for passing back into SetAttr.
*
* @param aNameSpaceID the namespace of the attr
* @param aNameSpaceID the namespace of the attr (defaults to
kNameSpaceID_None in the overload that omits this arg)
* @param aName the name of the attr
* @param aResult the value (may legitimately be the empty string) [OUT]
* @returns true if the attribute was set (even when set to empty string)
@ -733,14 +734,26 @@ public:
*/
bool GetAttr(int32_t aNameSpaceID, nsAtom* aName, nsAString& aResult) const;
bool GetAttr(nsAtom* aName, nsAString& aResult) const
{
return GetAttr(kNameSpaceID_None, aName, aResult);
}
/**
* Determine if an attribute has been set (empty string or otherwise).
*
* @param aNameSpaceId the namespace id of the attribute
* @param aNameSpaceId the namespace id of the attribute (defaults to
kNameSpaceID_None in the overload that omits this arg)
* @param aAttr the attribute name
* @return whether an attribute exists
*/
inline bool HasAttr(int32_t aNameSpaceID, nsAtom* aName) const;
bool HasAttr(nsAtom* aAttr) const
{
return HasAttr(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.

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

@ -767,7 +767,7 @@ protected:
void GetHTMLAttr(nsAtom* aName, nsAString& aResult) const
{
GetAttr(kNameSpaceID_None, aName, aResult);
GetAttr(aName, aResult);
}
void GetHTMLAttr(nsAtom* aName, mozilla::dom::DOMString& aResult) const
{
@ -788,15 +788,15 @@ protected:
}
void SetHTMLAttr(nsAtom* aName, const nsAString& aValue, mozilla::ErrorResult& aError)
{
mozilla::dom::Element::SetAttr(aName, aValue, aError);
SetAttr(aName, aValue, aError);
}
void SetHTMLAttr(nsAtom* aName, const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, mozilla::ErrorResult& aError)
{
mozilla::dom::Element::SetAttr(aName, aValue, aTriggeringPrincipal, aError);
SetAttr(aName, aValue, aTriggeringPrincipal, aError);
}
void UnsetHTMLAttr(nsAtom* aName, mozilla::ErrorResult& aError)
{
mozilla::dom::Element::UnsetAttr(aName, aError);
UnsetAttr(aName, aError);
}
void SetHTMLBoolAttr(nsAtom* aName, bool aValue, mozilla::ErrorResult& aError)
{

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

@ -108,15 +108,15 @@ SVGAElement::Target()
}
void
SVGAElement::GetDownload(nsAString & aDownload)
SVGAElement::GetDownload(nsAString& aDownload)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::download, aDownload);
GetAttr(nsGkAtoms::download, aDownload);
}
void
SVGAElement::SetDownload(const nsAString & aDownload, ErrorResult& rv)
SVGAElement::SetDownload(const nsAString& aDownload, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::download, aDownload, true);
SetAttr(nsGkAtoms::download, aDownload, rv);
}
//----------------------------------------------------------------------

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

@ -180,37 +180,37 @@ SVGStyleElement::SetXmlspace(const nsAString & aXmlspace, ErrorResult& rv)
void
SVGStyleElement::GetMedia(nsAString & aMedia)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
GetAttr(nsGkAtoms::media, aMedia);
}
void
SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
SetAttr(nsGkAtoms::media, aMedia, rv);
}
void
SVGStyleElement::GetType(nsAString & aType)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
GetAttr(nsGkAtoms::type, aType);
}
void
SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
SetAttr(nsGkAtoms::type, aType, rv);
}
void
SVGStyleElement::GetTitle(nsAString & aTitle)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
GetAttr(nsGkAtoms::title, aTitle);
}
void
SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
SetAttr(nsGkAtoms::title, aTitle, rv);
}
//----------------------------------------------------------------------

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

@ -1119,8 +1119,7 @@ nsSVGElement::IsSVGFocusable(bool* aIsFocusable, int32_t* aTabIndex)
}
// If a tabindex is specified at all, or the default tabindex is 0, we're focusable
*aIsFocusable =
tabIndex >= 0 || HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex);
*aIsFocusable = tabIndex >= 0 || HasAttr(nsGkAtoms::tabindex);
return false;
}
@ -2464,7 +2463,7 @@ nsSVGElement::RecompileScriptEventListeners()
}
nsAutoString value;
GetAttr(kNameSpaceID_None, attr, value);
GetAttr(attr, value);
SetEventHandler(GetEventNameForAttr(attr), value, true);
}
}