mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1733465 part 2: Modernize nsViewManager::GetRootWidget() to use already_AddRefed return value, instead of requiring getter_AddRefs at callsite. r=tnikkel
This patch shouldn't change behavior at all. This patch replaces a manual NS_ADDREF call with typesafe code that manages the reference count for us. This reduces repeated boilerplate code, in the implementation as well as the callsites. Differential Revision: https://phabricator.services.mozilla.com/D127179
This commit is contained in:
parent
bfb72ec419
commit
ed93bd5007
@ -182,8 +182,7 @@ RefPtr<SessionAccessibility> SessionAccessibility::GetInstanceFor(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> rootWidget;
|
||||
vm->GetRootWidget(getter_AddRefs(rootWidget));
|
||||
nsCOMPtr<nsIWidget> rootWidget = vm->GetRootWidget();
|
||||
// `rootWidget` can be one of several types. Here we make sure it is an
|
||||
// android nsWindow.
|
||||
if (RefPtr<nsWindow> window = nsWindow::From(rootWidget)) {
|
||||
|
@ -932,8 +932,7 @@ void* DocAccessible::GetNativeWindow() const {
|
||||
nsViewManager* vm = mPresShell->GetViewManager();
|
||||
if (!vm) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
if (widget) return widget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
|
||||
return nullptr;
|
||||
|
@ -251,8 +251,7 @@ HWND MsaaAccessible::GetHWNDFor(Accessible* aAccessible) {
|
||||
nsIWidget* widget = frame->GetNearestWidget();
|
||||
if (widget && widget->IsVisible()) {
|
||||
if (nsViewManager* vm = document->PresShellPtr()->GetViewManager()) {
|
||||
nsCOMPtr<nsIWidget> rootWidget;
|
||||
vm->GetRootWidget(getter_AddRefs(rootWidget));
|
||||
nsCOMPtr<nsIWidget> rootWidget = vm->GetRootWidget();
|
||||
// Make sure the accessible belongs to popup. If not then use
|
||||
// document HWND (which might be different from root widget in the
|
||||
// case of window emulation).
|
||||
|
@ -1032,8 +1032,7 @@ nsresult nsContentSink::DidProcessATokenImpl() {
|
||||
(mDeflectedCount % StaticPrefs::content_sink_event_probe_rate()) == 0) {
|
||||
nsViewManager* vm = presShell->GetViewManager();
|
||||
NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
mHasPendingEvent = widget && widget->HasPendingInputEvent();
|
||||
}
|
||||
|
||||
|
@ -1370,8 +1370,7 @@ void nsFocusManager::EnsureCurrentWidgetFocused(CallerType aCallerType) {
|
||||
if (!vm) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
@ -2581,8 +2580,7 @@ void nsFocusManager::Focus(
|
||||
|
||||
if (aAdjustWidget && !sTestMode) {
|
||||
if (nsViewManager* vm = presShell->GetViewManager()) {
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
if (widget)
|
||||
widget->SetFocus(nsIWidget::Raise::No, aFlags & FLAG_NONSYSTEMCALLER
|
||||
? CallerType::NonSystem
|
||||
@ -2966,8 +2964,7 @@ void nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow,
|
||||
}
|
||||
|
||||
if (nsViewManager* vm = presShell->GetViewManager()) {
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
if (widget) {
|
||||
widget->SetFocus(nsIWidget::Raise::Yes, aCallerType);
|
||||
}
|
||||
|
@ -349,10 +349,7 @@ already_AddRefed<nsPIDOMWindowOuter> BrowserParent::GetParentWindowOuter() {
|
||||
already_AddRefed<nsIWidget> BrowserParent::GetTopLevelWidget() {
|
||||
if (RefPtr<Element> element = mFrameElement) {
|
||||
if (PresShell* presShell = element->OwnerDoc()->GetPresShell()) {
|
||||
nsViewManager* vm = presShell->GetViewManager();
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
return widget.forget();
|
||||
return presShell->GetViewManager()->GetRootWidget();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -8837,9 +8837,8 @@ bool PresShell::EventHandler::AdjustContextMenuKeyEvent(
|
||||
nsRootPresContext* rootPC = GetPresContext()->GetRootPresContext();
|
||||
aMouseEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
|
||||
if (rootPC) {
|
||||
rootPC->PresShell()->GetViewManager()->GetRootWidget(
|
||||
getter_AddRefs(aMouseEvent->mWidget));
|
||||
|
||||
aMouseEvent->mWidget =
|
||||
rootPC->PresShell()->GetViewManager()->GetRootWidget();
|
||||
if (aMouseEvent->mWidget) {
|
||||
// default the refpoint to the topleft of our document
|
||||
nsPoint offset(0, 0);
|
||||
|
@ -1081,8 +1081,14 @@ nsIWidget* nsPresContext::GetRootWidget() const {
|
||||
if (!vm) {
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
|
||||
// XXXdholbert REVIEW NOTE: It's kind of sketchy that we're returning a raw
|
||||
// pointer to a refcounted object here, when we've got an owning reference
|
||||
// which we release just as we return the raw pointer. Plus, it's wasteful
|
||||
// to be incurring an AddRef/Release operation before the object actually
|
||||
// even gets used (and potentially AddRef'ed again) by the caller. I'll be
|
||||
// cleaning this up to address these issues in the next patch in this series.
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
return widget.get();
|
||||
}
|
||||
|
||||
|
@ -2337,8 +2337,8 @@ already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
|
||||
template <typename SizeOrMaxSize>
|
||||
static inline bool IsIntrinsicKeyword(const SizeOrMaxSize& aSize) {
|
||||
// All keywords other than auto/none/-moz-available depend on intrinsic sizes.
|
||||
return aSize.IsMaxContent() || aSize.IsMinContent() ||
|
||||
aSize.IsFitContent() || aSize.IsFitContentFunction();
|
||||
return aSize.IsMaxContent() || aSize.IsMinContent() || aSize.IsFitContent() ||
|
||||
aSize.IsFitContentFunction();
|
||||
}
|
||||
|
||||
bool nsIFrame::CanBeDynamicReflowRoot() const {
|
||||
@ -6973,9 +6973,8 @@ nsRect nsIFrame::GetScreenRectInAppUnits() const {
|
||||
rootScreenPos.x = NS_round(parentScale * rootPt.x);
|
||||
rootScreenPos.y = NS_round(parentScale * rootPt.y);
|
||||
} else {
|
||||
nsCOMPtr<nsIWidget> rootWidget;
|
||||
presContext->PresShell()->GetViewManager()->GetRootWidget(
|
||||
getter_AddRefs(rootWidget));
|
||||
nsCOMPtr<nsIWidget> rootWidget =
|
||||
presContext->PresShell()->GetViewManager()->GetRootWidget();
|
||||
if (rootWidget) {
|
||||
LayoutDeviceIntPoint rootDevPx = rootWidget->WidgetToScreenOffset();
|
||||
rootScreenPos.x = presContext->DevPixelsToAppUnits(rootDevPx.x);
|
||||
|
@ -1527,8 +1527,8 @@ nsEventStatus nsXULPopupManager::FirePopupShowingEvent(
|
||||
// coordinates are relative to the root widget
|
||||
nsPresContext* rootPresContext = aPresContext->GetRootPresContext();
|
||||
if (rootPresContext) {
|
||||
rootPresContext->PresShell()->GetViewManager()->GetRootWidget(
|
||||
getter_AddRefs(event.mWidget));
|
||||
event.mWidget =
|
||||
rootPresContext->PresShell()->GetViewManager()->GetRootWidget();
|
||||
} else {
|
||||
event.mWidget = nullptr;
|
||||
}
|
||||
|
@ -903,21 +903,16 @@ void nsViewManager::DecrementDisableRefreshCount() {
|
||||
NS_ASSERTION(mRefreshDisableCount >= 0, "Invalid refresh disable count!");
|
||||
}
|
||||
|
||||
void nsViewManager::GetRootWidget(nsIWidget** aWidget) {
|
||||
if (!mRootView) {
|
||||
*aWidget = nullptr;
|
||||
return;
|
||||
already_AddRefed<nsIWidget> nsViewManager::GetRootWidget() {
|
||||
nsCOMPtr<nsIWidget> rootWidget;
|
||||
if (mRootView) {
|
||||
if (mRootView->HasWidget()) {
|
||||
rootWidget = mRootView->GetWidget();
|
||||
} else if (mRootView->GetParent()) {
|
||||
rootWidget = mRootView->GetParent()->GetViewManager()->GetRootWidget();
|
||||
}
|
||||
}
|
||||
if (mRootView->HasWidget()) {
|
||||
*aWidget = mRootView->GetWidget();
|
||||
NS_ADDREF(*aWidget);
|
||||
return;
|
||||
}
|
||||
if (mRootView->GetParent()) {
|
||||
mRootView->GetParent()->GetViewManager()->GetRootWidget(aWidget);
|
||||
return;
|
||||
}
|
||||
*aWidget = nullptr;
|
||||
return rootWidget.forget();
|
||||
}
|
||||
|
||||
LayoutDeviceIntRect nsViewManager::ViewToWidget(nsView* aView,
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
|
||||
class nsIWidget;
|
||||
@ -281,7 +282,7 @@ class nsViewManager final {
|
||||
* Retrieve the widget at the root of the nearest enclosing
|
||||
* view manager whose root view has a widget.
|
||||
*/
|
||||
void GetRootWidget(nsIWidget** aWidget);
|
||||
already_AddRefed<nsIWidget> GetRootWidget();
|
||||
|
||||
/**
|
||||
* Indicate whether the viewmanager is currently painting
|
||||
|
@ -293,8 +293,7 @@ static GtkWindow* GetGtkWindow(dom::Document* aDocument) {
|
||||
RefPtr<nsViewManager> vm = presShell->GetViewManager();
|
||||
if (!vm) return nullptr;
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
vm->GetRootWidget(getter_AddRefs(widget));
|
||||
nsCOMPtr<nsIWidget> widget = vm->GetRootWidget();
|
||||
if (!widget) return nullptr;
|
||||
|
||||
GtkWidget* gtkWidget =
|
||||
|
Loading…
Reference in New Issue
Block a user