Bug 1800553 - part 1: Change most getter methods of HTMLAnchorElement to const methods r=smaug

Most of them are used only by the WebIDL bindings. Therefore, this fixes only
one caller in `HTMLEditUtils`.

`GetText` requires to change `nsContentUtils`, therefore it'll be done by the
following patch.

Differential Revision: https://phabricator.services.mozilla.com/D162065
This commit is contained in:
Masayuki Nakano 2022-11-16 00:21:30 +00:00
parent 1358ce8ff1
commit bb73eac1f4
4 changed files with 35 additions and 25 deletions

View file

@ -158,7 +158,7 @@ void HTMLAnchorElement::GetLinkTarget(nsAString& aTarget) {
}
}
void HTMLAnchorElement::GetTarget(nsAString& aValue) {
void HTMLAnchorElement::GetTarget(nsAString& aValue) const {
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue)) {
GetBaseTarget(aValue);
}
@ -182,10 +182,6 @@ void HTMLAnchorElement::SetText(const nsAString& aText, ErrorResult& aRv) {
aRv = nsContentUtils::SetNodeTextContent(this, aText, false);
}
void HTMLAnchorElement::ToString(nsAString& aSource) {
return GetHref(aSource);
}
already_AddRefed<nsIURI> HTMLAnchorElement::GetHrefURI() const {
if (nsCOMPtr<nsIURI> uri = GetCachedURI()) {
return uri.forget();

View file

@ -73,46 +73,52 @@ class HTMLAnchorElement final : public nsGenericHTMLElement,
// WebIDL API
void GetHref(nsAString& aValue) {
void GetHref(nsAString& aValue) const {
GetURIAttr(nsGkAtoms::href, nullptr, aValue);
}
void SetHref(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::href, aValue, rv);
}
void GetTarget(nsAString& aValue);
void GetTarget(nsAString& aValue) const;
void SetTarget(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::target, aValue, rv);
}
void GetDownload(DOMString& aValue) {
void GetDownload(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::download, aValue);
}
void SetDownload(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::download, aValue, rv);
}
void GetPing(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::ping, aValue); }
void GetPing(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::ping, aValue);
}
void SetPing(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::ping, aValue, rv);
}
void GetRel(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::rel, aValue); }
void GetRel(DOMString& aValue) const { GetHTMLAttr(nsGkAtoms::rel, aValue); }
void SetRel(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::rel, aValue, rv);
}
void SetReferrerPolicy(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::referrerpolicy, aValue, rv);
}
void GetReferrerPolicy(DOMString& aPolicy) {
void GetReferrerPolicy(DOMString& aPolicy) const {
GetEnumAttr(nsGkAtoms::referrerpolicy, "", aPolicy);
}
nsDOMTokenList* RelList();
void GetHreflang(DOMString& aValue) {
void GetHreflang(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::hreflang, aValue);
}
void SetHreflang(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::hreflang, aValue, rv);
}
// Needed for docshell
void GetType(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); }
void GetType(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); }
void GetType(nsAString& aValue) const {
GetHTMLAttr(nsGkAtoms::type, aValue);
}
void GetType(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::type, aValue);
}
void SetType(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::type, aValue, rv);
}
@ -148,31 +154,39 @@ class HTMLAnchorElement final : public nsGenericHTMLElement,
// Link::Link::GetHash is OK for us
// Link::Link::SetHash is OK for us
void GetCoords(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::coords, aValue); }
void GetCoords(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::coords, aValue);
}
void SetCoords(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::coords, aValue, rv);
}
void GetCharset(DOMString& aValue) {
void GetCharset(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::charset, aValue);
}
void SetCharset(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::charset, aValue, rv);
}
void GetName(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); }
void GetName(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); }
void GetName(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::name, aValue);
}
void GetName(nsAString& aValue) const {
GetHTMLAttr(nsGkAtoms::name, aValue);
}
void SetName(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::name, aValue, rv);
}
void GetRev(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::rev, aValue); }
void GetRev(DOMString& aValue) const { GetHTMLAttr(nsGkAtoms::rev, aValue); }
void SetRev(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::rev, aValue, rv);
}
void GetShape(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::shape, aValue); }
void GetShape(DOMString& aValue) const {
GetHTMLAttr(nsGkAtoms::shape, aValue);
}
void SetShape(const nsAString& aValue, mozilla::ErrorResult& rv) {
SetHTMLAttr(nsGkAtoms::shape, aValue, rv);
}
void Stringify(nsAString& aResult) { GetHref(aResult); }
void ToString(nsAString& aSource);
void Stringify(nsAString& aResult) const { GetHref(aResult); }
void ToString(nsAString& aSource) const { GetHref(aSource); }
void NodeInfoChanged(Document* aOldDoc) final {
ClearHasPendingLinkUpdate();

View file

@ -352,14 +352,14 @@ bool HTMLEditUtils::IsImage(nsINode* aNode) {
return aNode && aNode->IsHTMLElement(nsGkAtoms::img);
}
bool HTMLEditUtils::IsLink(nsINode* aNode) {
bool HTMLEditUtils::IsLink(const nsINode* aNode) {
MOZ_ASSERT(aNode);
if (!aNode->IsContent()) {
return false;
}
RefPtr<dom::HTMLAnchorElement> anchor =
RefPtr<const dom::HTMLAnchorElement> anchor =
dom::HTMLAnchorElement::FromNodeOrNull(aNode->AsContent());
if (!anchor) {
return false;

View file

@ -203,7 +203,7 @@ class HTMLEditUtils final {
static bool IsAnyListElement(const nsINode* aNode);
static bool IsPre(const nsINode* aNode);
static bool IsImage(nsINode* aNode);
static bool IsLink(nsINode* aNode);
static bool IsLink(const nsINode* aNode);
static bool IsNamedAnchor(const nsINode* aNode);
static bool IsMozDiv(nsINode* aNode);
static bool IsMailCite(const Element& aElement);