Commit cfb8b328 authored by Daniel Holbert's avatar Daniel Holbert
Browse files

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
parent 88d1a640
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1436,7 +1436,7 @@ void AccessibleCaretManager::DispatchCaretStateChangedEvent(
    commonAncestorNode = sel->GetFrameSelection()->GetAncestorLimiter();
    commonAncestorNode = sel->GetFrameSelection()->GetAncestorLimiter();
  }
  }


  RefPtr<DOMRect> domRect = new DOMRect(ToSupports(doc));
  auto domRect = MakeRefPtr<DOMRect>(ToSupports(doc));
  nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(sel);
  nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(sel);


  nsIFrame* commonAncestorFrame = nullptr;
  nsIFrame* commonAncestorFrame = nullptr;
+4 −7
Original line number Original line Diff line number Diff line
@@ -455,8 +455,7 @@ already_AddRefed<DOMQuad> ConvertQuadFromNode(
  if (aRv.Failed()) {
  if (aRv.Failed()) {
    return nullptr;
    return nullptr;
  }
  }
  RefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject().mObject, points);
  return MakeAndAddRef<DOMQuad>(aTo->GetParentObject().mObject, points);
  return result.forget();
}
}


already_AddRefed<DOMQuad> ConvertRectFromNode(
already_AddRefed<DOMQuad> ConvertRectFromNode(
@@ -473,8 +472,7 @@ already_AddRefed<DOMQuad> ConvertRectFromNode(
  if (aRv.Failed()) {
  if (aRv.Failed()) {
    return nullptr;
    return nullptr;
  }
  }
  RefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject().mObject, points);
  return MakeAndAddRef<DOMQuad>(aTo->GetParentObject().mObject, points);
  return result.forget();
}
}


already_AddRefed<DOMPoint> ConvertPointFromNode(
already_AddRefed<DOMPoint> ConvertPointFromNode(
@@ -490,9 +488,8 @@ already_AddRefed<DOMPoint> ConvertPointFromNode(
  if (aRv.Failed()) {
  if (aRv.Failed()) {
    return nullptr;
    return nullptr;
  }
  }
  RefPtr<DOMPoint> result =
  return MakeAndAddRef<DOMPoint>(aTo->GetParentObject().mObject, point.x,
      new DOMPoint(aTo->GetParentObject().mObject, point.x, point.y);
                                 point.y);
  return result.forget();
}
}


}  // namespace mozilla
}  // namespace mozilla
+3 −6
Original line number Original line Diff line number Diff line
@@ -5700,8 +5700,7 @@ void PresShell::SynthesizeMouseMove(bool aFromScroll) {
  }
  }


  if (!mSynthMouseMoveEvent.IsPending()) {
  if (!mSynthMouseMoveEvent.IsPending()) {
    RefPtr<nsSynthMouseMoveEvent> ev =
    auto ev = MakeRefPtr<nsSynthMouseMoveEvent>(this, aFromScroll);
        new nsSynthMouseMoveEvent(this, aFromScroll);


    GetPresContext()->RefreshDriver()->AddRefreshObserver(
    GetPresContext()->RefreshDriver()->AddRefreshObserver(
        ev, FlushType::Display, "Synthetic mouse move event");
        ev, FlushType::Display, "Synthetic mouse move event");
@@ -10500,11 +10499,10 @@ bool PresShell::VerifyIncrementalReflow() {
  }
  }


  // Create a presentation context to view the new frame tree
  // Create a presentation context to view the new frame tree
  RefPtr<nsPresContext> cx = new nsRootPresContext(
  auto cx = MakeRefPtr<nsRootPresContext>(
      mDocument, mPresContext->IsPaginated()
      mDocument, mPresContext->IsPaginated()
                     ? nsPresContext::eContext_PrintPreview
                     ? nsPresContext::eContext_PrintPreview
                     : nsPresContext::eContext_Galley);
                     : nsPresContext::eContext_Galley);
  NS_ENSURE_TRUE(cx, false);


  nsDeviceContext* dc = mPresContext->DeviceContext();
  nsDeviceContext* dc = mPresContext->DeviceContext();
  nsresult rv = cx->Init(dc);
  nsresult rv = cx->Init(dc);
@@ -10516,8 +10514,7 @@ bool PresShell::VerifyIncrementalReflow() {
  nsIWidget* parentWidget = rootView->GetWidget();
  nsIWidget* parentWidget = rootView->GetWidget();


  // Create a new view manager.
  // Create a new view manager.
  RefPtr<nsViewManager> vm = new nsViewManager();
  auto vm = MakeRefPtr<nsViewManager>();
  NS_ENSURE_TRUE(vm, false);
  rv = vm->Init(dc);
  rv = vm->Init(dc);
  NS_ENSURE_SUCCESS(rv, false);
  NS_ENSURE_SUCCESS(rv, false);


+12 −16
Original line number Original line Diff line number Diff line
@@ -483,8 +483,7 @@ class nsDocumentShownDispatcher : public Runnable {


//------------------------------------------------------------------
//------------------------------------------------------------------
already_AddRefed<nsIDocumentViewer> NS_NewDocumentViewer() {
already_AddRefed<nsIDocumentViewer> NS_NewDocumentViewer() {
  RefPtr<nsDocumentViewer> viewer = new nsDocumentViewer();
  return MakeAndAddRef<nsDocumentViewer>();
  return viewer.forget();
}
}


void nsDocumentViewer::PrepareToStartLoad() {
void nsDocumentViewer::PrepareToStartLoad() {
@@ -1254,8 +1253,7 @@ nsDocumentViewer::DispatchBeforeUnload() {
  // Now, fire an BeforeUnload event to the document and see if it's ok
  // Now, fire an BeforeUnload event to the document and see if it's ok
  // to unload...
  // to unload...
  nsPresContext* presContext = mDocument->GetPresContext();
  nsPresContext* presContext = mDocument->GetPresContext();
  RefPtr<BeforeUnloadEvent> event =
  auto event = MakeRefPtr<BeforeUnloadEvent>(mDocument, presContext, nullptr);
      new BeforeUnloadEvent(mDocument, presContext, nullptr);
  event->InitEvent(u"beforeunload"_ns, false, true);
  event->InitEvent(u"beforeunload"_ns, false, true);


  // Dispatching to |window|, but using |document| as the target.
  // 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
  // Notify observers that a new page has been shown. This will get run
  // from the event loop after we actually draw the page.
  // from the event loop after we actually draw the page.
  RefPtr<nsDocumentShownDispatcher> event =
  auto event = MakeRefPtr<nsDocumentShownDispatcher>(document);
      new nsDocumentShownDispatcher(document);
  document->Dispatch(event.forget());
  document->Dispatch(event.forget());


  return NS_OK;
  return NS_OK;
@@ -2888,8 +2885,8 @@ nsDocumentViewer::Print(nsIPrintSettings* aPrintSettings,
  // earlier in this function.
  // earlier in this function.
  // TODO(dholbert) Do we need to bother with this stack-owned local RefPtr?
  // 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?)
  // (Is there an edge case where it's needed to keep the nsPrintJob alive?)
  RefPtr<nsPrintJob> printJob =
  auto printJob =
      new nsPrintJob(*this, *mContainer, *mDocument,
      MakeRefPtr<nsPrintJob>(*this, *mContainer, *mDocument,
                             float(AppUnitsPerCSSInch()) /
                             float(AppUnitsPerCSSInch()) /
                                 float(mDeviceContext->AppUnitsPerDevPixel()));
                                 float(mDeviceContext->AppUnitsPerDevPixel()));
  mPrintJob = printJob;
  mPrintJob = printJob;
@@ -2931,8 +2928,8 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
  // in this function.
  // in this function.
  // TODO(dholbert) Do we need to bother with this stack-owned local RefPtr?
  // 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?)
  // (Is there an edge case where it's needed to keep the nsPrintJob alive?)
  RefPtr<nsPrintJob> printJob =
  auto printJob =
      new nsPrintJob(*this, *mContainer, *doc,
      MakeRefPtr<nsPrintJob>(*this, *mContainer, *doc,
                             float(AppUnitsPerCSSInch()) /
                             float(AppUnitsPerCSSInch()) /
                                 float(mDeviceContext->AppUnitsPerDevPixel()));
                                 float(mDeviceContext->AppUnitsPerDevPixel()));
  mPrintJob = printJob;
  mPrintJob = printJob;
@@ -3373,8 +3370,7 @@ NS_IMETHODIMP nsDocumentViewer::SetPrintSettingsForSubdocument(
      return NS_ERROR_NOT_AVAILABLE;
      return NS_ERROR_NOT_AVAILABLE;
    }
    }


    RefPtr<nsDeviceContextSpecProxy> devspec =
    auto devspec = MakeRefPtr<nsDeviceContextSpecProxy>(aRemotePrintJob);
        new nsDeviceContextSpecProxy(aRemotePrintJob);
    nsresult rv = devspec->Init(aPrintSettings, /* aIsPrintPreview = */ true);
    nsresult rv = devspec->Init(aPrintSettings, /* aIsPrintPreview = */ true);
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_SUCCESS(rv, rv);


+1 −2
Original line number Original line Diff line number Diff line
@@ -34,8 +34,7 @@ class nsLayoutHistoryState final : public nsILayoutHistoryState,
};
};


already_AddRefed<nsILayoutHistoryState> NS_NewLayoutHistoryState() {
already_AddRefed<nsILayoutHistoryState> NS_NewLayoutHistoryState() {
  RefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
  return MakeAndAddRef<nsLayoutHistoryState>();
  return state.forget();
}
}


NS_IMPL_ISUPPORTS(nsLayoutHistoryState, nsILayoutHistoryState,
NS_IMPL_ISUPPORTS(nsLayoutHistoryState, nsILayoutHistoryState,
Loading