Skip to content

Commit 1289135

Browse files
committedJan 27, 2023
Bug 1813148 - Don't return already_AddRefed in nsPresContext::GetRootWidget. r=dholbert
Let the caller addref it if needed. I wrote this because I wanted to make some code dealing with it thread-safe, but I ended up writing a less sketchy solution. However I still think this is worth it. It seems this only returns an already_AddRefed because before it used to be an XPCOM-ish thing where the widget was returned as an out-param. For now it doesn't change behavior but there are some callers that would benefit from having less addref/release calls if they only need to read simple stuff from the widget. Differential Revision: https://phabricator.services.mozilla.com/D168141
1 parent 882dfd8 commit 1289135

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed
 

‎dom/events/TextComposition.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ class TextComposition final {
8181
TextRangeArray* GetRanges() const { return mRanges; }
8282
// Returns the widget which is proper to call NotifyIME().
8383
already_AddRefed<nsIWidget> GetWidget() const {
84-
return mPresContext ? mPresContext->GetRootWidget() : nullptr;
84+
if (!mPresContext) {
85+
return nullptr;
86+
}
87+
return do_AddRef(mPresContext->GetRootWidget());
8588
}
8689
// Returns the tab parent which has this composition in its remote process.
8790
BrowserParent* GetBrowserParent() const { return mBrowserParent; }

‎dom/ipc/BrowserParent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ already_AddRefed<nsPIDOMWindowOuter> BrowserParent::GetParentWindowOuter() {
356356
already_AddRefed<nsIWidget> BrowserParent::GetTopLevelWidget() {
357357
if (RefPtr<Element> element = mFrameElement) {
358358
if (PresShell* presShell = element->OwnerDoc()->GetPresShell()) {
359-
return presShell->GetViewManager()->GetRootWidget();
359+
return do_AddRef(presShell->GetViewManager()->GetRootWidget());
360360
}
361361
}
362362
return nullptr;

‎layout/base/nsPresContext.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1167,13 +1167,12 @@ nsIWidget* nsPresContext::GetNearestWidget(nsPoint* aOffset) {
11671167
return rootView->GetNearestWidget(aOffset);
11681168
}
11691169

1170-
already_AddRefed<nsIWidget> nsPresContext::GetRootWidget() const {
1170+
nsIWidget* nsPresContext::GetRootWidget() const {
11711171
NS_ENSURE_TRUE(mPresShell, nullptr);
11721172
nsViewManager* vm = mPresShell->GetViewManager();
11731173
if (!vm) {
11741174
return nullptr;
11751175
}
1176-
11771176
return vm->GetRootWidget();
11781177
}
11791178

‎layout/base/nsPresContext.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
238238
/**
239239
* Returns the root widget for this.
240240
*/
241-
already_AddRefed<nsIWidget> GetRootWidget() const;
241+
nsIWidget* GetRootWidget() const;
242242

243243
/**
244244
* Returns the widget which may have native focus and handles text input
245245
* like keyboard input, IME, etc.
246246
*/
247-
already_AddRefed<nsIWidget> GetTextInputHandlingWidget() const {
247+
nsIWidget* GetTextInputHandlingWidget() const {
248248
// Currently, root widget for each PresContext handles text input.
249249
return GetRootWidget();
250250
}

‎view/nsViewManager.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -895,16 +895,17 @@ void nsViewManager::DecrementDisableRefreshCount() {
895895
NS_ASSERTION(mRefreshDisableCount >= 0, "Invalid refresh disable count!");
896896
}
897897

898-
already_AddRefed<nsIWidget> nsViewManager::GetRootWidget() {
899-
nsCOMPtr<nsIWidget> rootWidget;
900-
if (mRootView) {
901-
if (mRootView->HasWidget()) {
902-
rootWidget = mRootView->GetWidget();
903-
} else if (mRootView->GetParent()) {
904-
rootWidget = mRootView->GetParent()->GetViewManager()->GetRootWidget();
905-
}
898+
nsIWidget* nsViewManager::GetRootWidget() const {
899+
if (!mRootView) {
900+
return nullptr;
901+
}
902+
if (mRootView->HasWidget()) {
903+
return mRootView->GetWidget();
904+
}
905+
if (mRootView->GetParent()) {
906+
return mRootView->GetParent()->GetViewManager()->GetRootWidget();
906907
}
907-
return rootWidget.forget();
908+
return nullptr;
908909
}
909910

910911
LayoutDeviceIntRect nsViewManager::ViewToWidget(nsView* aView,

‎view/nsViewManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class nsViewManager final {
282282
* Retrieve the widget at the root of the nearest enclosing
283283
* view manager whose root view has a widget.
284284
*/
285-
already_AddRefed<nsIWidget> GetRootWidget();
285+
nsIWidget* GetRootWidget() const;
286286

287287
/**
288288
* Indicate whether the viewmanager is currently painting

0 commit comments

Comments
 (0)
Failed to load comments.