зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1896711 part 3: Use MakeRefPtr/MakeAndAddRef to reduce boilerplate, in layout/base. r=TYLin
Also remove some unnecessary null-checks for objects that we're allocating infallibly. Differential Revision: https://phabricator.services.mozilla.com/D210389
This commit is contained in:
Родитель
88d1a64077
Коммит
cfb8b32810
|
@ -1436,7 +1436,7 @@ void AccessibleCaretManager::DispatchCaretStateChangedEvent(
|
|||
commonAncestorNode = sel->GetFrameSelection()->GetAncestorLimiter();
|
||||
}
|
||||
|
||||
RefPtr<DOMRect> domRect = new DOMRect(ToSupports(doc));
|
||||
auto domRect = MakeRefPtr<DOMRect>(ToSupports(doc));
|
||||
nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(sel);
|
||||
|
||||
nsIFrame* commonAncestorFrame = nullptr;
|
||||
|
|
|
@ -455,8 +455,7 @@ already_AddRefed<DOMQuad> ConvertQuadFromNode(
|
|||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject().mObject, points);
|
||||
return result.forget();
|
||||
return MakeAndAddRef<DOMQuad>(aTo->GetParentObject().mObject, points);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMQuad> ConvertRectFromNode(
|
||||
|
@ -473,8 +472,7 @@ already_AddRefed<DOMQuad> ConvertRectFromNode(
|
|||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject().mObject, points);
|
||||
return result.forget();
|
||||
return MakeAndAddRef<DOMQuad>(aTo->GetParentObject().mObject, points);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMPoint> ConvertPointFromNode(
|
||||
|
@ -490,9 +488,8 @@ already_AddRefed<DOMPoint> ConvertPointFromNode(
|
|||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<DOMPoint> result =
|
||||
new DOMPoint(aTo->GetParentObject().mObject, point.x, point.y);
|
||||
return result.forget();
|
||||
return MakeAndAddRef<DOMPoint>(aTo->GetParentObject().mObject, point.x,
|
||||
point.y);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -5700,8 +5700,7 @@ void PresShell::SynthesizeMouseMove(bool aFromScroll) {
|
|||
}
|
||||
|
||||
if (!mSynthMouseMoveEvent.IsPending()) {
|
||||
RefPtr<nsSynthMouseMoveEvent> ev =
|
||||
new nsSynthMouseMoveEvent(this, aFromScroll);
|
||||
auto ev = MakeRefPtr<nsSynthMouseMoveEvent>(this, aFromScroll);
|
||||
|
||||
GetPresContext()->RefreshDriver()->AddRefreshObserver(
|
||||
ev, FlushType::Display, "Synthetic mouse move event");
|
||||
|
@ -10500,11 +10499,10 @@ bool PresShell::VerifyIncrementalReflow() {
|
|||
}
|
||||
|
||||
// Create a presentation context to view the new frame tree
|
||||
RefPtr<nsPresContext> cx = new nsRootPresContext(
|
||||
auto cx = MakeRefPtr<nsRootPresContext>(
|
||||
mDocument, mPresContext->IsPaginated()
|
||||
? nsPresContext::eContext_PrintPreview
|
||||
: nsPresContext::eContext_Galley);
|
||||
NS_ENSURE_TRUE(cx, false);
|
||||
|
||||
nsDeviceContext* dc = mPresContext->DeviceContext();
|
||||
nsresult rv = cx->Init(dc);
|
||||
|
@ -10516,8 +10514,7 @@ bool PresShell::VerifyIncrementalReflow() {
|
|||
nsIWidget* parentWidget = rootView->GetWidget();
|
||||
|
||||
// Create a new view manager.
|
||||
RefPtr<nsViewManager> vm = new nsViewManager();
|
||||
NS_ENSURE_TRUE(vm, false);
|
||||
auto vm = MakeRefPtr<nsViewManager>();
|
||||
rv = vm->Init(dc);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
|
|
|
@ -483,8 +483,7 @@ class nsDocumentShownDispatcher : public Runnable {
|
|||
|
||||
//------------------------------------------------------------------
|
||||
already_AddRefed<nsIDocumentViewer> NS_NewDocumentViewer() {
|
||||
RefPtr<nsDocumentViewer> viewer = new nsDocumentViewer();
|
||||
return viewer.forget();
|
||||
return MakeAndAddRef<nsDocumentViewer>();
|
||||
}
|
||||
|
||||
void nsDocumentViewer::PrepareToStartLoad() {
|
||||
|
@ -1254,8 +1253,7 @@ nsDocumentViewer::DispatchBeforeUnload() {
|
|||
// Now, fire an BeforeUnload event to the document and see if it's ok
|
||||
// to unload...
|
||||
nsPresContext* presContext = mDocument->GetPresContext();
|
||||
RefPtr<BeforeUnloadEvent> event =
|
||||
new BeforeUnloadEvent(mDocument, presContext, nullptr);
|
||||
auto event = MakeRefPtr<BeforeUnloadEvent>(mDocument, presContext, nullptr);
|
||||
event->InitEvent(u"beforeunload"_ns, false, true);
|
||||
|
||||
// Dispatching to |window|, but using |document| as the target.
|
||||
|
@ -2094,8 +2092,7 @@ nsDocumentViewer::Show() {
|
|||
|
||||
// Notify observers that a new page has been shown. This will get run
|
||||
// from the event loop after we actually draw the page.
|
||||
RefPtr<nsDocumentShownDispatcher> event =
|
||||
new nsDocumentShownDispatcher(document);
|
||||
auto event = MakeRefPtr<nsDocumentShownDispatcher>(document);
|
||||
document->Dispatch(event.forget());
|
||||
|
||||
return NS_OK;
|
||||
|
@ -2888,10 +2885,10 @@ nsDocumentViewer::Print(nsIPrintSettings* aPrintSettings,
|
|||
// earlier in this function.
|
||||
// TODO(dholbert) Do we need to bother with this stack-owned local RefPtr?
|
||||
// (Is there an edge case where it's needed to keep the nsPrintJob alive?)
|
||||
RefPtr<nsPrintJob> printJob =
|
||||
new nsPrintJob(*this, *mContainer, *mDocument,
|
||||
float(AppUnitsPerCSSInch()) /
|
||||
float(mDeviceContext->AppUnitsPerDevPixel()));
|
||||
auto printJob =
|
||||
MakeRefPtr<nsPrintJob>(*this, *mContainer, *mDocument,
|
||||
float(AppUnitsPerCSSInch()) /
|
||||
float(mDeviceContext->AppUnitsPerDevPixel()));
|
||||
mPrintJob = printJob;
|
||||
|
||||
nsresult rv = printJob->Print(*mDocument, aPrintSettings, aRemotePrintJob,
|
||||
|
@ -2931,10 +2928,10 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|||
// in this function.
|
||||
// TODO(dholbert) Do we need to bother with this stack-owned local RefPtr?
|
||||
// (Is there an edge case where it's needed to keep the nsPrintJob alive?)
|
||||
RefPtr<nsPrintJob> printJob =
|
||||
new nsPrintJob(*this, *mContainer, *doc,
|
||||
float(AppUnitsPerCSSInch()) /
|
||||
float(mDeviceContext->AppUnitsPerDevPixel()));
|
||||
auto printJob =
|
||||
MakeRefPtr<nsPrintJob>(*this, *mContainer, *doc,
|
||||
float(AppUnitsPerCSSInch()) /
|
||||
float(mDeviceContext->AppUnitsPerDevPixel()));
|
||||
mPrintJob = printJob;
|
||||
|
||||
nsresult rv = printJob->PrintPreview(
|
||||
|
@ -3373,8 +3370,7 @@ NS_IMETHODIMP nsDocumentViewer::SetPrintSettingsForSubdocument(
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
RefPtr<nsDeviceContextSpecProxy> devspec =
|
||||
new nsDeviceContextSpecProxy(aRemotePrintJob);
|
||||
auto devspec = MakeRefPtr<nsDeviceContextSpecProxy>(aRemotePrintJob);
|
||||
nsresult rv = devspec->Init(aPrintSettings, /* aIsPrintPreview = */ true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ class nsLayoutHistoryState final : public nsILayoutHistoryState,
|
|||
};
|
||||
|
||||
already_AddRefed<nsILayoutHistoryState> NS_NewLayoutHistoryState() {
|
||||
RefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
|
||||
return state.forget();
|
||||
return MakeAndAddRef<nsLayoutHistoryState>();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsLayoutHistoryState, nsILayoutHistoryState,
|
||||
|
|
|
@ -3652,7 +3652,7 @@ nsLayoutUtils::RectListBuilder::RectListBuilder(DOMRectList* aList)
|
|||
: mRectList(aList) {}
|
||||
|
||||
void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
|
||||
RefPtr<DOMRect> rect = new DOMRect(mRectList);
|
||||
auto rect = MakeRefPtr<DOMRect>(mRectList);
|
||||
|
||||
rect->SetLayoutRect(aRect);
|
||||
mRectList->Append(std::move(rect));
|
||||
|
|
|
@ -2830,7 +2830,7 @@ void nsPresContext::NotifyContentfulPaint() {
|
|||
MOZ_ASSERT(!nowTime.IsNull(),
|
||||
"Most recent refresh timestamp should exist since we are in "
|
||||
"a refresh driver tick");
|
||||
RefPtr<PerformancePaintTiming> paintTiming = new PerformancePaintTiming(
|
||||
auto paintTiming = MakeRefPtr<PerformancePaintTiming>(
|
||||
perf, u"first-contentful-paint"_ns, nowTime);
|
||||
perf->SetFCPTimingEntry(paintTiming);
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ nsresult nsStyleSheetService::LoadAndRegisterSheetInternal(
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
RefPtr<css::Loader> loader = new css::Loader;
|
||||
auto loader = MakeRefPtr<css::Loader>();
|
||||
auto result = loader->LoadSheetSync(aSheetURI, parsingMode,
|
||||
css::Loader::UseSystemPrincipal::Yes);
|
||||
if (result.isErr()) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче