Bug 1603313 - Subdocument enum callbacks should take a reference. r=bzbarsky

As they can never take null.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-12-14 05:08:39 +00:00
Родитель b2fe832c7b
Коммит 3ccc6c30ab
12 изменённых файлов: 185 добавлений и 209 удалений

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

@ -753,12 +753,18 @@ Document* ExternalResourceMap::RequestResource(
return nullptr;
}
void ExternalResourceMap::EnumerateResources(Document::SubDocEnumFunc aCallback,
void ExternalResourceMap::EnumerateResources(SubDocEnumFunc aCallback,
void* aData) {
for (auto iter = mMap.Iter(); !iter.Done(); iter.Next()) {
ExternalResourceMap::ExternalResource* resource = iter.UserData();
if (resource->mDocument && !aCallback(resource->mDocument, aData)) {
break;
nsTArray<RefPtr<Document>> docs(mMap.Count());
for (const auto& entry : mMap) {
if (Document* doc = entry.GetData()->mDocument) {
docs.AppendElement(doc);
}
}
for (auto& doc : docs) {
if (!aCallback(*doc, aData)) {
return;
}
}
}
@ -9811,12 +9817,6 @@ void Document::FlushPendingNotifications(mozilla::ChangesToFlush aFlush) {
}
}
static bool Copy(Document* aDocument, void* aData) {
auto* resources = static_cast<nsTArray<nsCOMPtr<Document>>*>(aData);
resources->AppendElement(aDocument);
return true;
}
void Document::FlushExternalResources(FlushType aType) {
NS_ASSERTION(
aType >= FlushType::Style,
@ -9825,12 +9825,12 @@ void Document::FlushExternalResources(FlushType aType) {
return;
}
nsTArray<nsCOMPtr<Document>> resources;
EnumerateExternalResources(Copy, &resources);
for (uint32_t i = 0; i < resources.Length(); i++) {
resources[i]->FlushPendingNotifications(aType);
}
EnumerateExternalResources(
[](Document& aDoc, void* aData) -> bool {
aDoc.FlushPendingNotifications(*static_cast<FlushType*>(aData));
return true;
},
&aType);
}
void Document::SetXMLDeclaration(const char16_t* aVersion,
@ -10062,16 +10062,15 @@ void Document::EnumerateSubDocuments(SubDocEnumFunc aCallback, void* aData) {
// PLDHashTable::Iterator can't handle modifications while iterating so we
// copy all entries to an array first before calling any callbacks.
AutoTArray<nsCOMPtr<Document>, 8> subdocs;
AutoTArray<RefPtr<Document>, 8> subdocs;
for (auto iter = mSubDocuments->Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<SubDocMapEntry*>(iter.Get());
Document* subdoc = entry->mSubDocument;
if (subdoc) {
if (Document* subdoc = entry->mSubDocument) {
subdocs.AppendElement(subdoc);
}
}
for (auto subdoc : subdocs) {
if (!aCallback(subdoc, aData)) {
for (auto& subdoc : subdocs) {
if (!aCallback(*subdoc, aData)) {
break;
}
}
@ -10556,9 +10555,9 @@ void Document::DispatchPageTransition(EventTarget* aDispatchTarget,
nullptr);
}
static bool NotifyPageShow(Document* aDocument, void* aData) {
static bool NotifyPageShow(Document& aDocument, void* aData) {
const bool* aPersistedPtr = static_cast<const bool*>(aData);
aDocument->OnPageShow(*aPersistedPtr, nullptr);
aDocument.OnPageShow(*aPersistedPtr, nullptr);
return true;
}
@ -10622,16 +10621,16 @@ void Document::OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget,
}
}
static bool NotifyPageHide(Document* aDocument, void* aData) {
static bool NotifyPageHide(Document& aDocument, void* aData) {
const bool* aPersistedPtr = static_cast<const bool*>(aData);
aDocument->OnPageHide(*aPersistedPtr, nullptr);
aDocument.OnPageHide(*aPersistedPtr, nullptr);
return true;
}
static void DispatchFullscreenChange(Document* aDocument, nsINode* aTarget) {
if (nsPresContext* presContext = aDocument->GetPresContext()) {
static void DispatchFullscreenChange(Document& aDocument, nsINode* aTarget) {
if (nsPresContext* presContext = aDocument.GetPresContext()) {
auto pendingEvent = MakeUnique<PendingFullscreenEvent>(
FullscreenEventType::Change, aDocument, aTarget);
FullscreenEventType::Change, &aDocument, aTarget);
presContext->RefreshDriver()->ScheduleFullscreenEvent(
std::move(pendingEvent));
}
@ -11055,9 +11054,8 @@ void Document::GetReadyState(nsAString& aReadyState) const {
}
}
static bool SuppressEventHandlingInDocument(Document* aDocument, void* aData) {
aDocument->SuppressEventHandling(*static_cast<uint32_t*>(aData));
static bool SuppressEventHandlingInDocument(Document& aDocument, void* aData) {
aDocument.SuppressEventHandling(*static_cast<uint32_t*>(aData));
return true;
}
@ -11394,22 +11392,22 @@ class nsDelayedEventDispatcher : public Runnable {
nsTArray<nsCOMPtr<Document>> mDocuments;
};
static bool GetAndUnsuppressSubDocuments(Document* aDocument, void* aData) {
if (aDocument->EventHandlingSuppressed() > 0) {
aDocument->DecreaseEventSuppression();
aDocument->ScriptLoader()->RemoveExecuteBlocker();
static bool GetAndUnsuppressSubDocuments(Document& aDocument, void* aData) {
if (aDocument.EventHandlingSuppressed() > 0) {
aDocument.DecreaseEventSuppression();
aDocument.ScriptLoader()->RemoveExecuteBlocker();
}
auto* docs = static_cast<nsTArray<nsCOMPtr<Document>>*>(aData);
docs->AppendElement(aDocument);
aDocument->EnumerateSubDocuments(GetAndUnsuppressSubDocuments, aData);
docs->AppendElement(&aDocument);
aDocument.EnumerateSubDocuments(GetAndUnsuppressSubDocuments, aData);
return true;
}
void Document::UnsuppressEventHandlingAndFireEvents(bool aFireEvents) {
nsTArray<nsCOMPtr<Document>> documents;
GetAndUnsuppressSubDocuments(this, &documents);
GetAndUnsuppressSubDocuments(*this, &documents);
if (aFireEvents) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
@ -11468,15 +11466,15 @@ void Document::FireOrClearPostMessageEvents(bool aFireEvents) {
}
}
static bool SetSuppressedEventListenerInSubDocument(Document* aDocument,
void* aData) {
aDocument->SetSuppressedEventListener(static_cast<EventListener*>(aData));
return true;
}
void Document::SetSuppressedEventListener(EventListener* aListener) {
mSuppressedEventListener = aListener;
EnumerateSubDocuments(SetSuppressedEventListenerInSubDocument, aListener);
EnumerateSubDocuments(
[](Document& aDocument, void* aData) {
aDocument.SetSuppressedEventListener(
static_cast<EventListener*>(aData));
return true;
},
aListener);
}
nsISupports* Document::GetCurrentContentSink() {
@ -11736,10 +11734,17 @@ bool Document::UnregisterActivityObserver(nsISupports* aSupports) {
void Document::EnumerateActivityObservers(
ActivityObserverEnumerator aEnumerator, void* aData) {
if (!mActivityObservers) return;
if (!mActivityObservers) {
return;
}
nsTArray<nsCOMPtr<nsISupports>> observers(mActivityObservers->Count());
for (auto iter = mActivityObservers->ConstIter(); !iter.Done(); iter.Next()) {
aEnumerator(iter.Get()->GetKey(), aData);
observers.AppendElement(iter.Get()->GetKey());
}
for (auto& observer : observers) {
aEnumerator(observer.get(), aData);
}
}
@ -12019,11 +12024,11 @@ mozilla::dom::ImageTracker* Document::ImageTracker() {
return mImageTracker;
}
static bool AllSubDocumentPluginEnum(Document* aDocument, void* userArg) {
static bool AllSubDocumentPluginEnum(Document& aDocument, void* userArg) {
nsTArray<nsIObjectLoadingContent*>* plugins =
reinterpret_cast<nsTArray<nsIObjectLoadingContent*>*>(userArg);
MOZ_ASSERT(plugins);
aDocument->GetPlugins(*plugins);
aDocument.GetPlugins(*plugins);
return true;
}
@ -12822,17 +12827,17 @@ void Document::AsyncExitFullscreen(Document* aDoc) {
}
}
static bool CountFullscreenSubDocuments(Document* aDoc, void* aData) {
if (aDoc->FullscreenStackTop()) {
static bool CountFullscreenSubDocuments(Document& aDoc, void* aData) {
if (aDoc.FullscreenStackTop()) {
uint32_t* count = static_cast<uint32_t*>(aData);
(*count)++;
}
return true;
}
static uint32_t CountFullscreenSubDocuments(Document* aDoc) {
static uint32_t CountFullscreenSubDocuments(Document& aDoc) {
uint32_t count = 0;
aDoc->EnumerateSubDocuments(CountFullscreenSubDocuments, &count);
aDoc.EnumerateSubDocuments(CountFullscreenSubDocuments, &count);
return count;
}
@ -12842,24 +12847,24 @@ bool Document::IsFullscreenLeaf() {
if (!FullscreenStackTop()) {
return false;
}
return CountFullscreenSubDocuments(this) == 0;
return CountFullscreenSubDocuments(*this) == 0;
}
bool GetFullscreenLeaf(Document* aDoc, void* aData) {
if (aDoc->IsFullscreenLeaf()) {
bool GetFullscreenLeaf(Document& aDoc, void* aData) {
if (aDoc.IsFullscreenLeaf()) {
Document** result = static_cast<Document**>(aData);
*result = aDoc;
*result = &aDoc;
return false;
}
if (aDoc->FullscreenStackTop()) {
aDoc->EnumerateSubDocuments(GetFullscreenLeaf, aData);
if (aDoc.FullscreenStackTop()) {
aDoc.EnumerateSubDocuments(GetFullscreenLeaf, aData);
}
return true;
}
static Document* GetFullscreenLeaf(Document* aDoc) {
Document* leaf = nullptr;
GetFullscreenLeaf(aDoc, &leaf);
GetFullscreenLeaf(*aDoc, &leaf);
if (leaf) {
return leaf;
}
@ -12871,18 +12876,18 @@ static Document* GetFullscreenLeaf(Document* aDoc) {
if (!root->FullscreenStackTop()) {
return nullptr;
}
GetFullscreenLeaf(root, &leaf);
GetFullscreenLeaf(*root, &leaf);
return leaf;
}
static bool ResetFullscreen(Document* aDocument, void* aData) {
if (Element* fsElement = aDocument->FullscreenStackTop()) {
static bool ResetFullscreen(Document& aDocument, void* aData) {
if (Element* fsElement = aDocument.FullscreenStackTop()) {
NS_ASSERTION(CountFullscreenSubDocuments(aDocument) <= 1,
"Should have at most 1 fullscreen subdocument.");
aDocument->CleanupFullscreenState();
NS_ASSERTION(!aDocument->FullscreenStackTop(), "Should reset fullscreen");
aDocument.CleanupFullscreenState();
NS_ASSERTION(!aDocument.FullscreenStackTop(), "Should reset fullscreen");
DispatchFullscreenChange(aDocument, fsElement);
aDocument->EnumerateSubDocuments(ResetFullscreen, nullptr);
aDocument.EnumerateSubDocuments(ResetFullscreen, nullptr);
}
return true;
}
@ -12952,7 +12957,7 @@ void Document::ExitFullscreenInDocTree(Document* aMaybeNotARootDoc) {
Document* fullscreenLeaf = GetFullscreenLeaf(root);
// Walk the tree of fullscreen documents, and reset their fullscreen state.
ResetFullscreen(root, nullptr);
ResetFullscreen(*root, nullptr);
NS_ASSERTION(!root->FullscreenStackTop(),
"Fullscreen root should no longer be a fullscreen doc...");
@ -13048,7 +13053,7 @@ void Document::RestorePreviousFullscreenState(UniquePtr<FullscreenExit> aExit) {
// that the loop order is reversed so that events are dispatched in
// the tree order as indicated in the spec.
for (Element* e : Reversed(exitElements)) {
DispatchFullscreenChange(e->OwnerDoc(), e);
DispatchFullscreenChange(*e->OwnerDoc(), e);
}
aExit->MayResolvePromise();
@ -13252,7 +13257,7 @@ void Document::RemoteFrameFullscreenReverted() {
RestorePreviousFullscreenState(std::move(exit));
}
static bool HasFullscreenSubDocument(Document* aDoc) {
static bool HasFullscreenSubDocument(Document& aDoc) {
uint32_t count = CountFullscreenSubDocuments(aDoc);
NS_ASSERTION(count <= 1,
"Fullscreen docs should have at most 1 fullscreen child!");
@ -13313,7 +13318,7 @@ bool Document::FullscreenElementReadyCheck(FullscreenRequest& aRequest) {
aRequest.Reject(msg);
return false;
}
if (HasFullscreenSubDocument(this)) {
if (HasFullscreenSubDocument(*this)) {
aRequest.Reject("FullscreenDeniedSubDocFullScreen");
return false;
}
@ -13564,7 +13569,7 @@ bool Document::ApplyFullscreen(UniquePtr<FullscreenRequest> aRequest) {
// reversed so that events are dispatched in the tree order as
// indicated in the spec.
for (Document* d : Reversed(changed)) {
DispatchFullscreenChange(d, d->FullscreenStackTop());
DispatchFullscreenChange(*d, d->FullscreenStackTop());
}
aRequest->MayResolvePromise();
return true;
@ -14355,8 +14360,8 @@ void Document::ReportUseCounters() {
doc->ReportUseCounters();
}
EnumerateExternalResources(
[](Document* aDoc, void*) -> bool {
aDoc->ReportUseCounters();
[](Document& aDoc, void*) -> bool {
aDoc.ReportUseCounters();
return true;
},
nullptr);
@ -14514,9 +14519,8 @@ void Document::NotifyIntersectionObservers() {
}
}
static bool NotifyLayerManagerRecreatedCallback(Document* aDocument,
void* aData) {
aDocument->NotifyLayerManagerRecreated();
static bool NotifyLayerManagerRecreatedCallback(Document& aDocument, void*) {
aDocument.NotifyLayerManagerRecreated();
return true;
}
@ -14607,16 +14611,14 @@ already_AddRefed<Element> Document::CreateHTMLElement(nsAtom* aTag) {
return element.forget();
}
bool MarkDocumentTreeToBeInSyncOperation(Document* aDoc, void* aData) {
bool MarkDocumentTreeToBeInSyncOperation(Document& aDoc, void* aData) {
auto* documents = static_cast<nsTArray<nsCOMPtr<Document>>*>(aData);
if (aDoc) {
aDoc->SetIsInSyncOperation(true);
if (nsCOMPtr<nsPIDOMWindowInner> window = aDoc->GetInnerWindow()) {
window->TimeoutManager().BeginSyncOperation();
}
documents->AppendElement(aDoc);
aDoc->EnumerateSubDocuments(MarkDocumentTreeToBeInSyncOperation, aData);
aDoc.SetIsInSyncOperation(true);
if (nsCOMPtr<nsPIDOMWindowInner> window = aDoc.GetInnerWindow()) {
window->TimeoutManager().BeginSyncOperation();
}
documents->AppendElement(&aDoc);
aDoc.EnumerateSubDocuments(MarkDocumentTreeToBeInSyncOperation, aData);
return true;
}
@ -14630,8 +14632,9 @@ nsAutoSyncOperation::nsAutoSyncOperation(Document* aDoc) {
if (aDoc) {
if (nsPIDOMWindowOuter* win = aDoc->GetWindow()) {
if (nsCOMPtr<nsPIDOMWindowOuter> top = win->GetInProcessTop()) {
nsCOMPtr<Document> doc = top->GetExtantDoc();
MarkDocumentTreeToBeInSyncOperation(doc, &mDocuments);
if (RefPtr<Document> doc = top->GetExtantDoc()) {
MarkDocumentTreeToBeInSyncOperation(*doc, &mDocuments);
}
}
}
}

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

@ -288,7 +288,7 @@ class DocHeaderData {
};
class ExternalResourceMap {
typedef bool (*SubDocEnumFunc)(Document* aDocument, void* aData);
typedef bool (*SubDocEnumFunc)(Document& aDocument, void* aData);
public:
/**
@ -2573,7 +2573,7 @@ class Document : public nsINode,
* The enumerator callback should return true to continue enumerating, or
* false to stop. This will never get passed a null aDocument.
*/
typedef bool (*SubDocEnumFunc)(Document* aDocument, void* aData);
typedef bool (*SubDocEnumFunc)(Document&, void* aData);
void EnumerateSubDocuments(SubDocEnumFunc aCallback, void* aData);
/**

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

@ -6742,16 +6742,16 @@ void nsGlobalWindowOuter::ActivateOrDeactivate(bool aActivate) {
}
}
static bool NotifyDocumentTree(Document* aDocument, void* aData) {
aDocument->EnumerateSubDocuments(NotifyDocumentTree, nullptr);
aDocument->UpdateDocumentStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE, true);
static bool NotifyDocumentTree(Document& aDocument, void*) {
aDocument.EnumerateSubDocuments(NotifyDocumentTree, nullptr);
aDocument.UpdateDocumentStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE, true);
return true;
}
void nsGlobalWindowOuter::SetActive(bool aActive) {
nsPIDOMWindowOuter::SetActive(aActive);
if (mDoc) {
NotifyDocumentTree(mDoc, nullptr);
NotifyDocumentTree(*mDoc, nullptr);
}
}

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

@ -6318,16 +6318,15 @@ nsIFrame* PresShell::EventHandler::GetNearestFrameContainingPresShell(
return frame;
}
static bool FlushThrottledStyles(Document* aDocument, void* aData) {
PresShell* presShell = aDocument->GetPresShell();
static bool FlushThrottledStyles(Document& aDocument, void* aData) {
PresShell* presShell = aDocument.GetPresShell();
if (presShell && presShell->IsVisible()) {
nsPresContext* presContext = presShell->GetPresContext();
if (presContext) {
if (nsPresContext* presContext = presShell->GetPresContext()) {
presContext->RestyleManager()->UpdateOnlyAnimationStyles();
}
}
aDocument->EnumerateSubDocuments(FlushThrottledStyles, nullptr);
aDocument.EnumerateSubDocuments(FlushThrottledStyles, nullptr);
return true;
}
@ -7198,7 +7197,7 @@ nsIFrame* PresShell::EventHandler::MaybeFlushThrottledStyles(
AutoWeakFrame weakFrameForPresShell(aFrameForPresShell);
{ // scope for scriptBlocker.
nsAutoScriptBlocker scriptBlocker;
FlushThrottledStyles(rootDocument, nullptr);
FlushThrottledStyles(*rootDocument, nullptr);
}
if (weakFrameForPresShell.IsAlive()) {
@ -8830,9 +8829,8 @@ static void FreezeElement(nsISupports* aSupports, void* /* unused */) {
}
}
static bool FreezeSubDocument(Document* aDocument, void* aData) {
PresShell* presShell = aDocument->GetPresShell();
if (presShell) {
static bool FreezeSubDocument(Document& aDocument, void*) {
if (PresShell* presShell = aDocument.GetPresShell()) {
presShell->Freeze();
}
return true;
@ -8901,9 +8899,8 @@ static void ThawElement(nsISupports* aSupports, void* aShell) {
}
}
static bool ThawSubDocument(Document* aDocument, void* aData) {
PresShell* presShell = aDocument->GetPresShell();
if (presShell) {
static bool ThawSubDocument(Document& aDocument, void* aData) {
if (PresShell* presShell = aDocument.GetPresShell()) {
presShell->Thaw();
}
return true;
@ -8918,7 +8915,9 @@ void PresShell::Thaw() {
mDocument->EnumerateActivityObservers(ThawElement, this);
if (mDocument) mDocument->EnumerateSubDocuments(ThawSubDocument, nullptr);
if (mDocument) {
mDocument->EnumerateSubDocuments(ThawSubDocument, nullptr);
}
// Get the activeness of our presshell, as this might have changed
// while we were in the bfcache
@ -10389,9 +10388,8 @@ void PresShell::QueryIsActive() {
}
// Helper for propagating mIsActive changes to external resources
static bool SetExternalResourceIsActive(Document* aDocument, void* aClosure) {
PresShell* presShell = aDocument->GetPresShell();
if (presShell) {
static bool SetExternalResourceIsActive(Document& aDocument, void* aClosure) {
if (PresShell* presShell = aDocument.GetPresShell()) {
presShell->SetIsActive(*static_cast<bool*>(aClosure));
}
return true;
@ -11189,8 +11187,8 @@ PresShell::EventHandler::HandlingTimeAccumulator::~HandlingTimeAccumulator() {
}
}
static bool EndPaintHelper(Document* aDocument, void* aData) {
if (PresShell* presShell = aDocument->GetPresShell()) {
static bool EndPaintHelper(Document& aDocument, void* aData) {
if (PresShell* presShell = aDocument.GetPresShell()) {
presShell->EndPaint();
}
return true;

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

@ -509,7 +509,9 @@ class AutoPrintEventDispatcher {
private:
void DispatchEventToWindowTree(const nsAString& aEvent) {
nsTArray<nsCOMPtr<Document>> targets;
CollectDocuments(mTop, &targets);
if (mTop) {
CollectDocuments(*mTop, &targets);
}
for (nsCOMPtr<Document>& doc : targets) {
nsContentUtils::DispatchTrustedEvent(doc, doc->GetWindow(), aEvent,
CanBubble::eNo, Cancelable::eNo,
@ -517,12 +519,10 @@ class AutoPrintEventDispatcher {
}
}
static bool CollectDocuments(Document* aDocument, void* aData) {
if (aDocument) {
static_cast<nsTArray<nsCOMPtr<Document>>*>(aData)->AppendElement(
aDocument);
aDocument->EnumerateSubDocuments(CollectDocuments, aData);
}
static bool CollectDocuments(Document& aDocument, void* aData) {
static_cast<nsTArray<nsCOMPtr<Document>>*>(aData)->AppendElement(
&aDocument);
aDocument.EnumerateSubDocuments(CollectDocuments, aData);
return true;
}
@ -2661,9 +2661,9 @@ void nsDocumentViewer::PropagateToPresContextsHelper(CallChildFunc aChildFunc,
if (mDocument) {
mDocument->EnumerateExternalResources(
[](Document* aDoc, void* aClosure) -> bool {
[](Document& aDoc, void* aClosure) -> bool {
auto* closure = static_cast<ResourceDocClosure*>(aClosure);
if (nsPresContext* pc = aDoc->GetPresContext()) {
if (nsPresContext* pc = aDoc.GetPresContext()) {
closure->mFunc(pc, closure->mParentClosure);
}
return true;

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

@ -1403,11 +1403,10 @@ void nsPresContext::UIResolutionChangedSync() {
}
}
/*static*/
/* static */
bool nsPresContext::UIResolutionChangedSubdocumentCallback(
dom::Document* aDocument, void* aData) {
nsPresContext* pc = aDocument->GetPresContext();
if (pc) {
dom::Document& aDocument, void* aData) {
if (nsPresContext* pc = aDocument.GetPresContext()) {
// For subdocuments, we want to apply the parent's scale, because there
// are cases where the subdoc's device context is connected to a widget
// that has an out-of-date resolution (it's on a different screen, but
@ -1515,10 +1514,10 @@ void nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
}
static bool MediaFeatureValuesChangedAllDocumentsCallback(Document* aDocument,
static bool MediaFeatureValuesChangedAllDocumentsCallback(Document& aDocument,
void* aChange) {
auto* change = static_cast<const MediaFeatureChange*>(aChange);
if (nsPresContext* pc = aDocument->GetPresContext()) {
if (nsPresContext* pc = aDocument.GetPresContext()) {
pc->MediaFeatureValuesChangedAllDocuments(*change);
}
return true;
@ -1827,11 +1826,10 @@ void nsPresContext::FireDOMPaintEvent(
static_cast<Event*>(event), this, nullptr);
}
static bool MayHavePaintEventListenerSubdocumentCallback(Document* aDocument,
static bool MayHavePaintEventListenerSubdocumentCallback(Document& aDocument,
void* aData) {
bool* result = static_cast<bool*>(aData);
nsPresContext* pc = aDocument->GetPresContext();
if (pc) {
if (nsPresContext* pc = aDocument.GetPresContext()) {
*result = pc->MayHavePaintEventListenerInSubDocument();
// If we found a paint event listener, then we can stop enumerating
@ -1998,23 +1996,19 @@ struct NotifyDidPaintSubdocumentCallbackClosure {
TransactionId mTransactionId;
const mozilla::TimeStamp& mTimeStamp;
};
bool nsPresContext::NotifyDidPaintSubdocumentCallback(dom::Document* aDocument,
bool nsPresContext::NotifyDidPaintSubdocumentCallback(dom::Document& aDocument,
void* aData) {
NotifyDidPaintSubdocumentCallbackClosure* closure =
static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
nsPresContext* pc = aDocument->GetPresContext();
if (pc) {
auto* closure = static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
if (nsPresContext* pc = aDocument.GetPresContext()) {
pc->NotifyDidPaintForSubtree(closure->mTransactionId, closure->mTimeStamp);
}
return true;
}
bool nsPresContext::NotifyRevokingDidPaintSubdocumentCallback(
dom::Document* aDocument, void* aData) {
NotifyDidPaintSubdocumentCallbackClosure* closure =
static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
nsPresContext* pc = aDocument->GetPresContext();
if (pc) {
dom::Document& aDocument, void* aData) {
auto* closure = static_cast<NotifyDidPaintSubdocumentCallbackClosure*>(aData);
if (nsPresContext* pc = aDocument.GetPresContext()) {
pc->NotifyRevokingDidPaint(closure->mTransactionId);
}
return true;

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

@ -1060,8 +1060,8 @@ class nsPresContext : public nsISupports,
// aData here is a pointer to a double that holds the CSS to device-pixel
// scale factor from the parent, which will be applied to the subdocument's
// device context instead of retrieving a scale from the widget.
static bool UIResolutionChangedSubdocumentCallback(
mozilla::dom::Document* aDocument, void* aData);
static bool UIResolutionChangedSubdocumentCallback(mozilla::dom::Document&,
void* aData);
void SetImgAnimations(nsIContent* aParent, uint16_t aMode);
void SetSMILAnimations(mozilla::dom::Document* aDoc, uint16_t aNewMode,
@ -1077,10 +1077,10 @@ class nsPresContext : public nsISupports,
void UpdateCharSet(NotNull<const Encoding*> aCharSet);
static bool NotifyDidPaintSubdocumentCallback(
mozilla::dom::Document* aDocument, void* aData);
static bool NotifyRevokingDidPaintSubdocumentCallback(
mozilla::dom::Document* aDocument, void* aData);
static bool NotifyDidPaintSubdocumentCallback(mozilla::dom::Document&,
void* aData);
static bool NotifyRevokingDidPaintSubdocumentCallback(mozilla::dom::Document&,
void* aData);
public:
// Used by the PresShell to force a reflow when some aspect of font info

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

@ -1808,13 +1808,12 @@ void nsRefreshDriver::CancelIdleRunnable(nsIRunnable* aRunnable) {
}
}
static bool ReduceAnimations(Document* aDocument, void* aData) {
if (aDocument->GetPresContext() &&
aDocument->GetPresContext()->EffectCompositor()->NeedsReducing()) {
aDocument->GetPresContext()->EffectCompositor()->ReduceAnimations();
static bool ReduceAnimations(Document& aDocument, void* aData) {
if (aDocument.GetPresContext() &&
aDocument.GetPresContext()->EffectCompositor()->NeedsReducing()) {
aDocument.GetPresContext()->EffectCompositor()->ReduceAnimations();
}
aDocument->EnumerateSubDocuments(ReduceAnimations, nullptr);
aDocument.EnumerateSubDocuments(ReduceAnimations, nullptr);
return true;
}
@ -1986,7 +1985,7 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) {
// https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events
if (i == 1) {
nsAutoMicroTask mt;
ReduceAnimations(mPresContext->Document(), nullptr);
ReduceAnimations(*mPresContext->Document(), nullptr);
}
// Check if running the microtask checkpoint caused the pres context to

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

@ -1027,22 +1027,18 @@ static void DestroyDisplayItemDataForFrames(nsIFrame* aFrame) {
}
}
static bool BeginSwapDocShellsForDocument(Document* aDocument, void*) {
MOZ_ASSERT(aDocument, "null document");
mozilla::PresShell* presShell = aDocument->GetPresShell();
if (presShell) {
static bool BeginSwapDocShellsForDocument(Document& aDocument, void*) {
if (PresShell* presShell = aDocument.GetPresShell()) {
// Disable painting while the views are detached, see bug 946929.
presShell->SetNeverPainting(true);
nsIFrame* rootFrame = presShell->GetRootFrame();
if (rootFrame) {
if (nsIFrame* rootFrame = presShell->GetRootFrame()) {
::DestroyDisplayItemDataForFrames(rootFrame);
}
}
aDocument->EnumerateActivityObservers(nsPluginFrame::BeginSwapDocShells,
nullptr);
aDocument->EnumerateSubDocuments(BeginSwapDocShellsForDocument, nullptr);
aDocument.EnumerateActivityObservers(nsPluginFrame::BeginSwapDocShells,
nullptr);
aDocument.EnumerateSubDocuments(BeginSwapDocShellsForDocument, nullptr);
return true;
}
@ -1050,9 +1046,8 @@ static nsView* BeginSwapDocShellsForViews(nsView* aSibling) {
// Collect the removed sibling views in reverse order in 'removedViews'.
nsView* removedViews = nullptr;
while (aSibling) {
Document* doc = ::GetDocumentFromView(aSibling);
if (doc) {
::BeginSwapDocShellsForDocument(doc, nullptr);
if (Document* doc = ::GetDocumentFromView(aSibling)) {
::BeginSwapDocShellsForDocument(*doc, nullptr);
}
nsView* next = aSibling->GetNextSibling();
aSibling->GetViewManager()->RemoveChild(aSibling);
@ -1105,14 +1100,11 @@ nsresult nsSubDocumentFrame::BeginSwapDocShells(nsIFrame* aOther) {
return NS_OK;
}
static bool EndSwapDocShellsForDocument(Document* aDocument, void*) {
MOZ_ASSERT(aDocument, "null document");
static bool EndSwapDocShellsForDocument(Document& aDocument, void*) {
// Our docshell and view trees have been updated for the new hierarchy.
// Now also update all nsDeviceContext::mWidget to that of the
// container view in the new hierarchy.
nsCOMPtr<nsIDocShell> ds = aDocument->GetDocShell();
if (ds) {
if (nsCOMPtr<nsIDocShell> ds = aDocument.GetDocShell()) {
nsCOMPtr<nsIContentViewer> cv;
ds->GetContentViewer(getter_AddRefs(cv));
while (cv) {
@ -1129,17 +1121,16 @@ static bool EndSwapDocShellsForDocument(Document* aDocument, void*) {
}
}
aDocument->EnumerateActivityObservers(nsPluginFrame::EndSwapDocShells,
nullptr);
aDocument->EnumerateSubDocuments(EndSwapDocShellsForDocument, nullptr);
aDocument.EnumerateActivityObservers(nsPluginFrame::EndSwapDocShells,
nullptr);
aDocument.EnumerateSubDocuments(EndSwapDocShellsForDocument, nullptr);
return true;
}
static void EndSwapDocShellsForViews(nsView* aSibling) {
for (; aSibling; aSibling = aSibling->GetNextSibling()) {
Document* doc = ::GetDocumentFromView(aSibling);
if (doc) {
::EndSwapDocShellsForDocument(doc, nullptr);
if (Document* doc = ::GetDocumentFromView(aSibling)) {
::EndSwapDocShellsForDocument(*doc, nullptr);
}
nsIFrame* frame = aSibling->GetFrame();
if (frame) {

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

@ -882,12 +882,12 @@ struct CbData {
};
static nsIFrame* GetRootFrameForPainting(nsDisplayListBuilder* aBuilder,
Document* aDocument) {
Document& aDocument) {
// Although this is the actual subdocument, it might not be
// what painting uses. Walk up to the nsSubDocumentFrame owning
// us, and then ask that which subdoc it's going to paint.
PresShell* presShell = aDocument->GetPresShell();
PresShell* presShell = aDocument.GetPresShell();
if (!presShell) {
return nullptr;
}
@ -922,19 +922,16 @@ static nsIFrame* GetRootFrameForPainting(nsDisplayListBuilder* aBuilder,
return presShell ? presShell->GetRootFrame() : nullptr;
}
static bool SubDocEnumCb(Document* aDocument, void* aData) {
MOZ_ASSERT(aDocument);
static bool SubDocEnumCb(Document& aDocument, void* aData) {
MOZ_ASSERT(aData);
CbData* data = static_cast<CbData*>(aData);
auto* data = static_cast<CbData*>(aData);
nsIFrame* rootFrame = GetRootFrameForPainting(data->builder, aDocument);
if (rootFrame) {
if (nsIFrame* rootFrame = GetRootFrameForPainting(data->builder, aDocument)) {
TakeAndAddModifiedAndFramesWithPropsFromRootFrame(
data->builder, data->modifiedFrames, data->framesWithProps, rootFrame);
Document* innerDoc = rootFrame->PresShell()->GetDocument();
if (innerDoc) {
if (Document* innerDoc = rootFrame->PresShell()->GetDocument()) {
innerDoc->EnumerateSubDocuments(SubDocEnumCb, aData);
}
}
@ -951,11 +948,8 @@ static void GetModifiedAndFramesWithProps(
aBuilder, aOutModifiedFrames, aOutFramesWithProps, rootFrame);
Document* rootdoc = rootFrame->PresContext()->Document();
if (rootdoc) {
CbData data = {aBuilder, aOutModifiedFrames, aOutFramesWithProps};
rootdoc->EnumerateSubDocuments(SubDocEnumCb, &data);
}
CbData data = {aBuilder, aOutModifiedFrames, aOutFramesWithProps};
rootdoc->EnumerateSubDocuments(SubDocEnumCb, &data);
}
// ComputeRebuildRegion debugging

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

@ -2924,11 +2924,10 @@ bool nsDisplayList::ComputeVisibilityForSublist(
return anyVisible;
}
static bool TriggerPendingAnimationsOnSubDocuments(Document* aDocument,
static bool TriggerPendingAnimationsOnSubDocuments(Document& aDoc,
void* aReadyTime) {
PendingAnimationTracker* tracker = aDocument->GetPendingAnimationTracker();
if (tracker) {
PresShell* presShell = aDocument->GetPresShell();
if (PendingAnimationTracker* tracker = aDoc.GetPendingAnimationTracker()) {
PresShell* presShell = aDoc.GetPresShell();
// If paint-suppression is in effect then we haven't finished painting
// this document yet so we shouldn't start animations
if (!presShell || !presShell->IsPaintingSuppressed()) {
@ -2936,12 +2935,12 @@ static bool TriggerPendingAnimationsOnSubDocuments(Document* aDocument,
tracker->TriggerPendingAnimationsOnNextTick(readyTime);
}
}
aDocument->EnumerateSubDocuments(TriggerPendingAnimationsOnSubDocuments,
aReadyTime);
aDoc.EnumerateSubDocuments(TriggerPendingAnimationsOnSubDocuments,
aReadyTime);
return true;
}
static void TriggerPendingAnimations(Document* aDocument,
static void TriggerPendingAnimations(Document& aDocument,
const TimeStamp& aReadyTime) {
MOZ_ASSERT(!aReadyTime.IsNull(),
"Animation ready time is not set. Perhaps we're using a layer"
@ -3186,7 +3185,8 @@ already_AddRefed<LayerManager> nsDisplayList::PaintRoot(
aBuilder->SetIsCompositingCheap(prevIsCompositingCheap);
if (document && widgetTransaction) {
TriggerPendingAnimations(document, layerManager->GetAnimationReadyTime());
TriggerPendingAnimations(*document,
layerManager->GetAnimationReadyTime());
}
if (presContext->RefreshDriver()->HasScheduleFlush()) {
@ -3286,7 +3286,7 @@ already_AddRefed<LayerManager> nsDisplayList::PaintRoot(
aBuilder->SetIsCompositingCheap(temp);
if (document && widgetTransaction) {
TriggerPendingAnimations(document, layerManager->GetAnimationReadyTime());
TriggerPendingAnimations(*document, layerManager->GetAnimationReadyTime());
}
nsIntRegion invalid;

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

@ -521,11 +521,8 @@ static nsresult EnsureSettingsHasPrinterNameSet(
#endif
}
static bool DocHasPrintCallbackCanvas(Document* aDoc, void* aData) {
if (!aDoc) {
return true;
}
Element* root = aDoc->GetRootElement();
static bool DocHasPrintCallbackCanvas(Document& aDoc, void* aData) {
Element* root = aDoc.GetRootElement();
if (!root) {
return true;
}
@ -545,10 +542,10 @@ static bool DocHasPrintCallbackCanvas(Document* aDoc, void* aData) {
return true;
}
static bool AnySubdocHasPrintCallbackCanvas(Document* aDoc) {
static bool AnySubdocHasPrintCallbackCanvas(Document& aDoc) {
bool result = false;
aDoc->EnumerateSubDocuments(&DocHasPrintCallbackCanvas,
static_cast<void*>(&result));
aDoc.EnumerateSubDocuments(DocHasPrintCallbackCanvas,
static_cast<void*>(&result));
return result;
}
@ -620,10 +617,10 @@ nsresult nsPrintJob::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
}
bool hasMozPrintCallback = false;
DocHasPrintCallbackCanvas(aOriginalDoc,
DocHasPrintCallbackCanvas(*aOriginalDoc,
static_cast<void*>(&hasMozPrintCallback));
mHasMozPrintCallback =
hasMozPrintCallback || AnySubdocHasPrintCallbackCanvas(aOriginalDoc);
hasMozPrintCallback || AnySubdocHasPrintCallbackCanvas(*aOriginalDoc);
nsCOMPtr<nsIStringBundle> brandBundle;
nsCOMPtr<nsIStringBundleService> svc =