Bug 1931517. Rename confusing IDTracker methods. r=emilio

Some of the Reset* methods are named ResetTo* and some are named ResetWith*.
That seems to imply some sort of difference which simply doesn't exist. This
commit renames them to all use ResetTo* to avoid that.

Furthermore, the inconsistency in naming terminology between
ResetToURIFragmentID and ResetWithLocalRef makes it less than clear that the
latter is exactly the same as the former, but with only the fragment identifier
being specified. This commit better aligns the naming terminology for clarity.

Differential Revision: https://phabricator.services.mozilla.com/D229118
This commit is contained in:
Jonathan Watt 2024-11-15 12:30:03 +00:00
parent 5a9200b9f0
commit ef39f8ec17
7 changed files with 29 additions and 26 deletions

View File

@ -55,11 +55,11 @@ IDTracker::IDTracker() = default;
IDTracker::~IDTracker() { Unlink(); }
void IDTracker::ResetToURIFragmentID(nsIContent* aFromContent, nsIURI* aURI,
nsIReferrerInfo* aReferrerInfo,
bool aWatch, bool aReferenceImage) {
void IDTracker::ResetToURIWithFragmentID(nsIContent* aFromContent, nsIURI* aURI,
nsIReferrerInfo* aReferrerInfo,
bool aWatch, bool aReferenceImage) {
MOZ_ASSERT(aFromContent,
"ResetToURIFragmentID() expects non-null content pointer");
"ResetToURIWithFragmentID() expects non-null content pointer");
Unlink();
@ -128,8 +128,9 @@ void IDTracker::ResetToURIFragmentID(nsIContent* aFromContent, nsIURI* aURI,
HaveNewDocumentOrShadowRoot(docOrShadow, aWatch, ref);
}
void IDTracker::ResetWithLocalRef(Element& aFrom, const nsAString& aLocalRef,
bool aWatch) {
void IDTracker::ResetToLocalFragmentID(Element& aFrom,
const nsAString& aLocalRef,
bool aWatch) {
MOZ_ASSERT(nsContentUtils::IsLocalRefURL(aLocalRef));
auto ref = Substring(aLocalRef, 1);
@ -156,10 +157,10 @@ void IDTracker::ResetWithLocalRef(Element& aFrom, const nsAString& aLocalRef,
}
RefPtr<nsAtom> idAtom = NS_Atomize(unescaped);
ResetWithID(aFrom, idAtom, aWatch);
ResetToID(aFrom, idAtom, aWatch);
}
void IDTracker::ResetWithID(Element& aFrom, nsAtom* aID, bool aWatch) {
void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aWatch) {
MOZ_ASSERT(aID);
Unlink();

View File

@ -75,14 +75,15 @@ class IDTracker {
* property (that is, we're creating a reference an "image element", which
* is subject to the document's mozSetImageElement overriding mechanism).
*/
void ResetToURIFragmentID(nsIContent* aFrom, nsIURI* aURI,
nsIReferrerInfo* aReferrerInfo, bool aWatch = true,
bool aReferenceImage = false);
void ResetToURIWithFragmentID(nsIContent* aFrom, nsIURI* aURI,
nsIReferrerInfo* aReferrerInfo,
bool aWatch = true,
bool aReferenceImage = false);
/**
* A variation on ResetToURIFragmentID() to set up a reference that consists
* only of a fragment identifier, referencing an element in the same document
* as aFrom.
* A variation on ResetToURIWithFragmentID() to set up a reference that
* consists only of a fragment identifier, referencing an element in the same
* document as aFrom.
*
* @param aFrom The source element that is making the reference.
* @param aLocalRef The fragment identifier that identifies the target
@ -91,12 +92,13 @@ class IDTracker {
* changes, so ElementChanged won't fire and get() will always return the
* same value, the current element for the ID.
*/
void ResetWithLocalRef(Element& aFrom, const nsAString& aLocalRef,
bool aWatch = true);
void ResetToLocalFragmentID(Element& aFrom, const nsAString& aLocalRef,
bool aWatch = true);
/**
* A variation on ResetToURIFragmentID() to set up a reference that consists
* of a pre-parsed ID, referencing an element in the same document as aFrom.
* A variation on ResetToURIWithFragmentID() to set up a reference that
* consists of a pre-parsed ID, referencing an element in the same document
* as aFrom.
*
* @param aFrom The source element that is making the reference.
* @param aID The ID of the target element.
@ -104,7 +106,7 @@ class IDTracker {
* changes, so ElementChanged won't fire and get() will always return the
* same value, the current element for the ID.
*/
void ResetWithID(Element& aFrom, nsAtom* aID, bool aWatch = true);
void ResetToID(Element& aFrom, nsAtom* aID, bool aWatch = true);
/**
* Clears the reference. ElementChanged is not triggered. get() will return

View File

@ -93,7 +93,7 @@ void SMILTimeValueSpec::ResolveReferences(Element& aContextElement) {
RefPtr<Element> oldReferencedElement = mReferencedElement.get();
if (mParams.mDependentElemID) {
mReferencedElement.ResetWithID(aContextElement, mParams.mDependentElemID);
mReferencedElement.ResetToID(aContextElement, mParams.mDependentElemID);
} else if (mParams.mType == SMILTimeValueSpecParams::EVENT) {
Element* target = mOwner->GetTargetElement();
mReferencedElement.ResetWithElement(target);

View File

@ -377,7 +377,7 @@ bool SVGAnimationElement::IsEventAttributeNameInternal(nsAtom* aName) {
void SVGAnimationElement::UpdateHrefTarget(const nsAString& aHrefStr) {
if (nsContentUtils::IsLocalRefURL(aHrefStr)) {
mHrefTarget.ResetWithLocalRef(*this, aHrefStr);
mHrefTarget.ResetToLocalFragmentID(*this, aHrefStr);
} else {
mHrefTarget.Unlink();
}

View File

@ -562,7 +562,7 @@ void SVGUseElement::LookupHref() {
Element* treeToWatch = mOriginal ? mOriginal.get() : this;
if (nsContentUtils::IsLocalRefURL(href)) {
mReferencedElementTracker.ResetWithLocalRef(*treeToWatch, href);
mReferencedElementTracker.ResetToLocalFragmentID(*treeToWatch, href);
return;
}
@ -583,8 +583,8 @@ void SVGUseElement::LookupHref() {
nsIReferrerInfo* referrer =
OwnerDoc()->ReferrerInfoForInternalCSSAndSVGResources();
mReferencedElementTracker.ResetToURIFragmentID(treeToWatch, targetURI,
referrer);
mReferencedElementTracker.ResetToURIWithFragmentID(treeToWatch, targetURI,
referrer);
}
void SVGUseElement::TriggerReclone() {

View File

@ -18,7 +18,7 @@ void ListMutationObserver::Attach(bool aRepaint) {
if (InputElement().GetAttr(nsGkAtoms::list_, id)) {
Unlink();
RefPtr<nsAtom> idAtom = NS_AtomizeMainThread(id);
ResetWithID(InputElement(), idAtom);
ResetToID(InputElement(), idAtom);
AddObserverIfNeeded();
}
if (aRepaint) {

View File

@ -457,7 +457,7 @@ SVGIDRenderingObserver::SVGIDRenderingObserver(
referrerInfo = aURI->GetReferrerInfo();
}
mObservedElementTracker.ResetToURIFragmentID(
mObservedElementTracker.ResetToURIWithFragmentID(
aObservingContent, uri, referrerInfo, true, aReferenceImage);
TargetChanged();
StartObserving();