Bug 1957689 - Use atoms a bit more in IDTracker. r=smaug
Just drive-by clean-ups. Differential Revision: https://phabricator.services.mozilla.com/D244185
This commit is contained in:
@@ -585,8 +585,8 @@ void DocumentOrShadowRoot::RemoveIDTargetObserver(nsAtom* aID,
|
|||||||
entry->RemoveContentChangeCallback(aObserver, aData, aForImage);
|
entry->RemoveContentChangeCallback(aObserver, aData, aForImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element* DocumentOrShadowRoot::LookupImageElement(const nsAString& aId) {
|
Element* DocumentOrShadowRoot::LookupImageElement(nsAtom* aId) {
|
||||||
if (aId.IsEmpty()) {
|
if (aId->IsEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class DocumentOrShadowRoot {
|
|||||||
* @param aId the ID associated the element we want to lookup
|
* @param aId the ID associated the element we want to lookup
|
||||||
* @return the element associated with |aId|
|
* @return the element associated with |aId|
|
||||||
*/
|
*/
|
||||||
Element* LookupImageElement(const nsAString& aElementId);
|
Element* LookupImageElement(nsAtom* aId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that aId is not empty and log a message to the console
|
* Check that aId is not empty and log a message to the console
|
||||||
|
|||||||
@@ -21,16 +21,15 @@
|
|||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
|
||||||
static Element* LookupElement(DocumentOrShadowRoot& aDocOrShadow,
|
static Element* LookupElement(DocumentOrShadowRoot& aDocOrShadow, nsAtom* aRef,
|
||||||
const nsAString& aRef, bool aReferenceImage) {
|
bool aReferenceImage) {
|
||||||
if (aReferenceImage) {
|
if (aReferenceImage) {
|
||||||
return aDocOrShadow.LookupImageElement(aRef);
|
return aDocOrShadow.LookupImageElement(aRef);
|
||||||
}
|
}
|
||||||
return aDocOrShadow.GetElementById(aRef);
|
return aDocOrShadow.GetElementById(aRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DocumentOrShadowRoot* FindTreeToWatch(nsIContent& aContent,
|
static DocumentOrShadowRoot* FindTreeToWatch(nsIContent& aContent, nsAtom* aID,
|
||||||
const nsAString& aID,
|
|
||||||
bool aReferenceImage) {
|
bool aReferenceImage) {
|
||||||
ShadowRoot* shadow = aContent.GetContainingShadow();
|
ShadowRoot* shadow = aContent.GetContainingShadow();
|
||||||
|
|
||||||
@@ -97,18 +96,17 @@ void IDTracker::ResetToURIWithFragmentID(Element& aFrom, nsIURI* aURI,
|
|||||||
|
|
||||||
bool isEqualExceptRef;
|
bool isEqualExceptRef;
|
||||||
rv = aURI->EqualsExceptRef(doc->GetDocumentURI(), &isEqualExceptRef);
|
rv = aURI->EqualsExceptRef(doc->GetDocumentURI(), &isEqualExceptRef);
|
||||||
|
RefPtr<nsAtom> refAtom = NS_Atomize(ref);
|
||||||
if (NS_FAILED(rv) || !isEqualExceptRef) {
|
if (NS_FAILED(rv) || !isEqualExceptRef) {
|
||||||
return ResetToExternalResource(aURI, aReferrerInfo, ref, aFrom,
|
return ResetToExternalResource(aURI, aReferrerInfo, refAtom, aFrom,
|
||||||
aReferenceImage);
|
aReferenceImage);
|
||||||
}
|
}
|
||||||
|
ResetToID(aFrom, refAtom, aReferenceImage);
|
||||||
RefPtr<nsAtom> id = NS_Atomize(ref);
|
|
||||||
ResetToID(aFrom, id, aReferenceImage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDTracker::ResetToExternalResource(nsIURI* aURI,
|
void IDTracker::ResetToExternalResource(nsIURI* aURI,
|
||||||
nsIReferrerInfo* aReferrerInfo,
|
nsIReferrerInfo* aReferrerInfo,
|
||||||
const nsAString& aRef, Element& aFrom,
|
nsAtom* aRef, Element& aFrom,
|
||||||
bool aReferenceImage) {
|
bool aReferenceImage) {
|
||||||
Unlink();
|
Unlink();
|
||||||
|
|
||||||
@@ -125,9 +123,9 @@ void IDTracker::ResetToExternalResource(nsIURI* aURI,
|
|||||||
load->AddObserver(observer);
|
load->AddObserver(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
mWatchID = NS_Atomize(aRef);
|
mWatchID = aRef;
|
||||||
mReferencingImage = aReferenceImage;
|
mReferencingImage = aReferenceImage;
|
||||||
HaveNewDocumentOrShadowRoot(resourceDoc, /* aWatch = */ true, aRef);
|
HaveNewDocumentOrShadowRoot(resourceDoc, /* aWatch = */ true, mWatchID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static nsIURI* GetExternalResourceURIIfNeeded(nsIURI* aBaseURI,
|
static nsIURI* GetExternalResourceURIIfNeeded(nsIURI* aBaseURI,
|
||||||
@@ -191,14 +189,12 @@ void IDTracker::ResetToLocalFragmentID(Element& aFrom,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<nsAtom> refAtom = NS_Atomize(unescaped);
|
||||||
if (nsIURI* resourceUri = GetExternalResourceURIIfNeeded(aBaseURI, aFrom)) {
|
if (nsIURI* resourceUri = GetExternalResourceURIIfNeeded(aBaseURI, aFrom)) {
|
||||||
NS_ConvertUTF8toUTF16 utf16ref(unescaped);
|
return ResetToExternalResource(resourceUri, aReferrerInfo, refAtom, aFrom,
|
||||||
return ResetToExternalResource(resourceUri, aReferrerInfo, utf16ref, aFrom,
|
|
||||||
aReferenceImage);
|
aReferenceImage);
|
||||||
}
|
}
|
||||||
|
ResetToID(aFrom, refAtom, aReferenceImage);
|
||||||
RefPtr<nsAtom> idAtom = NS_Atomize(unescaped);
|
|
||||||
ResetToID(aFrom, idAtom, aReferenceImage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aReferenceImage) {
|
void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aReferenceImage) {
|
||||||
@@ -213,15 +209,13 @@ void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aReferenceImage) {
|
|||||||
mWatchID = aID;
|
mWatchID = aID;
|
||||||
mReferencingImage = aReferenceImage;
|
mReferencingImage = aReferenceImage;
|
||||||
|
|
||||||
nsDependentAtomString str(aID);
|
|
||||||
DocumentOrShadowRoot* docOrShadow =
|
DocumentOrShadowRoot* docOrShadow =
|
||||||
FindTreeToWatch(aFrom, str, aReferenceImage);
|
FindTreeToWatch(aFrom, aID, aReferenceImage);
|
||||||
HaveNewDocumentOrShadowRoot(docOrShadow, /*aWatch*/ true, str);
|
HaveNewDocumentOrShadowRoot(docOrShadow, /*aWatch*/ true, aID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDTracker::HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot* aDocOrShadow,
|
void IDTracker::HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot* aDocOrShadow,
|
||||||
bool aWatch,
|
bool aWatch, nsAtom* aID) {
|
||||||
const nsAString& aRef) {
|
|
||||||
if (aWatch) {
|
if (aWatch) {
|
||||||
mWatchDocumentOrShadowRoot = nullptr;
|
mWatchDocumentOrShadowRoot = nullptr;
|
||||||
if (aDocOrShadow) {
|
if (aDocOrShadow) {
|
||||||
@@ -236,7 +230,7 @@ void IDTracker::HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot* aDocOrShadow,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Element* e = LookupElement(*aDocOrShadow, aRef, mReferencingImage)) {
|
if (Element* e = LookupElement(*aDocOrShadow, aID, mReferencingImage)) {
|
||||||
mElement = e;
|
mElement = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class IDTracker {
|
|||||||
protected:
|
protected:
|
||||||
/** Requests and maybe watches an external resource doc. */
|
/** Requests and maybe watches an external resource doc. */
|
||||||
void ResetToExternalResource(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
void ResetToExternalResource(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
||||||
const nsAString& aRef, Element& aFrom,
|
nsAtom* aRef, Element& aFrom,
|
||||||
bool aReferenceImage);
|
bool aReferenceImage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +138,7 @@ class IDTracker {
|
|||||||
* null. Either aWatch must be false or aRef must be empty.
|
* null. Either aWatch must be false or aRef must be empty.
|
||||||
*/
|
*/
|
||||||
void HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot*, bool aWatch,
|
void HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot*, bool aWatch,
|
||||||
const nsAString& aRef);
|
nsAtom* aID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool Observe(Element* aOldElement, Element* aNewElement, void* aData);
|
static bool Observe(Element* aOldElement, Element* aNewElement, void* aData);
|
||||||
@@ -183,7 +183,7 @@ class IDTracker {
|
|||||||
|
|
||||||
class DocumentLoadNotification : public Notification, public nsIObserver {
|
class DocumentLoadNotification : public Notification, public nsIObserver {
|
||||||
public:
|
public:
|
||||||
DocumentLoadNotification(IDTracker* aTarget, const nsAString& aRef)
|
DocumentLoadNotification(IDTracker* aTarget, nsAtom* aRef)
|
||||||
: Notification(aTarget) {
|
: Notification(aTarget) {
|
||||||
if (!mTarget->IsPersistent()) {
|
if (!mTarget->IsPersistent()) {
|
||||||
mRef = aRef;
|
mRef = aRef;
|
||||||
@@ -197,7 +197,7 @@ class IDTracker {
|
|||||||
|
|
||||||
virtual void SetTo(Element* aTo) override {}
|
virtual void SetTo(Element* aTo) override {}
|
||||||
|
|
||||||
nsString mRef;
|
RefPtr<nsAtom> mRef;
|
||||||
};
|
};
|
||||||
friend class DocumentLoadNotification;
|
friend class DocumentLoadNotification;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user