Bug 1553769 - Make nsIWidget::SetFocus infallible, and make it take an enum class. r=NeilDeakin
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 31 May 2019 22:13:56 +0000
changeset 536117 5c17911ac0596fc7a79d6fb3e053c5ab5d50445c
parent 536116 e3e8eaff2fd1e5ab4981aa64f7836c861abfe730
child 536118 de9c7f8fd95993845ba0789679ac0f9b1f7fd667
push id11522
push userffxbld-merge
push dateMon, 01 Jul 2019 09:00:55 +0000
treeherdermozilla-beta@53ea74d2bd09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1553769
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1553769 - Make nsIWidget::SetFocus infallible, and make it take an enum class. r=NeilDeakin Only gtk returns failure ever, and nobody checks the result anyway. Use an enum class so that it's clear from the caller what it means. Differential Revision: https://phabricator.services.mozilla.com/D32353
dom/base/nsFocusManager.cpp
dom/ipc/BrowserParent.cpp
dom/plugins/ipc/PluginWidgetParent.cpp
gfx/tests/gtest/MockWidget.h
widget/PluginWidgetProxy.cpp
widget/PluginWidgetProxy.h
widget/PuppetWidget.cpp
widget/PuppetWidget.h
widget/android/nsWindow.cpp
widget/android/nsWindow.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/headless/HeadlessWidget.cpp
widget/headless/HeadlessWidget.h
widget/nsIWidget.h
widget/uikit/nsWindow.h
widget/uikit/nsWindow.mm
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -1088,17 +1088,17 @@ void nsFocusManager::EnsureCurrentWidget
   if (!vm) {
     return;
   }
   nsCOMPtr<nsIWidget> widget;
   vm->GetRootWidget(getter_AddRefs(widget));
   if (!widget) {
     return;
   }
-  widget->SetFocus(false);
+  widget->SetFocus(nsIWidget::Raise::No);
 }
 
 bool ActivateOrDeactivateChild(BrowserParent* aParent, void* aArg) {
   bool active = static_cast<bool>(aArg);
   Unused << aParent->SendParentActivated(active);
   return false;
 }
 
@@ -1624,23 +1624,22 @@ bool nsFocusManager::Blur(nsPIDOMWindowO
           nsCOMPtr<nsIBrowserChild> browserChild = docShell->GetBrowserChild();
           if (browserChild) {
             static_cast<BrowserChild*>(browserChild.get())
                 ->SendDispatchFocusToTopLevelWindow();
           }
         } else {
           // note that the presshell's widget is being retrieved here, not the
           // one for the object frame.
-          nsViewManager* vm = presShell->GetViewManager();
-          if (vm) {
+          if (nsViewManager* vm = presShell->GetViewManager()) {
             nsCOMPtr<nsIWidget> widget;
             vm->GetRootWidget(getter_AddRefs(widget));
             if (widget) {
               // set focus to the top level window but don't raise it.
-              widget->SetFocus(false);
+              widget->SetFocus(nsIWidget::Raise::No);
             }
           }
         }
       }
     }
 
     // if the object being blurred is a remote browser, deactivate remote
     // content
@@ -1816,21 +1815,20 @@ void nsFocusManager::Focus(nsPIDOMWindow
   // own widget and is either already focused or is about to be focused.
   nsCOMPtr<nsIWidget> objectFrameWidget;
   if (aElement) {
     nsIFrame* contentFrame = aElement->GetPrimaryFrame();
     nsIObjectFrame* objectFrame = do_QueryFrame(contentFrame);
     if (objectFrame) objectFrameWidget = objectFrame->GetWidget();
   }
   if (aAdjustWidgets && !objectFrameWidget && !sTestMode) {
-    nsViewManager* vm = presShell->GetViewManager();
-    if (vm) {
+    if (nsViewManager* vm = presShell->GetViewManager()) {
       nsCOMPtr<nsIWidget> widget;
       vm->GetRootWidget(getter_AddRefs(widget));
-      if (widget) widget->SetFocus(false);
+      if (widget) widget->SetFocus(nsIWidget::Raise::No);
     }
   }
 
   // if switching to a new document, first fire the focus event on the
   // document and then the window.
   if (aIsNewDocument) {
     Document* doc = aWindow->GetExtantDoc();
     // The focus change should be notified to IMEStateManager from here if
@@ -1873,18 +1871,19 @@ void nsFocusManager::Focus(nsPIDOMWindow
     if (sendFocusEvent) {
       NotifyFocusStateChange(aElement, nullptr, aWindow->ShouldShowFocusRing(),
                              true);
 
       // if this is an object/plug-in/remote browser, focus its widget.  Note
       // that we might no longer be in the same document, due to the events we
       // fired above when aIsNewDocument.
       if (presShell->GetDocument() == aElement->GetComposedDoc()) {
-        if (aAdjustWidgets && objectFrameWidget && !sTestMode)
-          objectFrameWidget->SetFocus(false);
+        if (aAdjustWidgets && objectFrameWidget && !sTestMode) {
+          objectFrameWidget->SetFocus(nsIWidget::Raise::No);
+        }
 
         // if the object being focused is a remote browser, activate remote
         // content
         ActivateRemoteFrameIfNeeded(*aElement);
       }
 
       IMEStateManager::OnChangeFocus(presContext, aElement,
                                      GetFocusMoveActionCause(aFlags));
@@ -1906,21 +1905,22 @@ void nsFocusManager::Focus(nsPIDOMWindow
       }
     }
   } else {
     // If the window focus event (fired above when aIsNewDocument) caused
     // the plugin not to be focusable, update the system focus by focusing
     // the root widget.
     if (aAdjustWidgets && objectFrameWidget && mFocusedWindow == aWindow &&
         mFocusedElement == nullptr && !sTestMode) {
-      nsViewManager* vm = presShell->GetViewManager();
-      if (vm) {
+      if (nsViewManager* vm = presShell->GetViewManager()) {
         nsCOMPtr<nsIWidget> widget;
         vm->GetRootWidget(getter_AddRefs(widget));
-        if (widget) widget->SetFocus(false);
+        if (widget) {
+          widget->SetFocus(nsIWidget::Raise::No);
+        }
       }
     }
 
     if (!mFocusedElement) {
       // When there is no focused element, IMEStateManager needs to adjust IME
       // enabled state with the document.
       nsPresContext* presContext = presShell->GetPresContext();
       IMEStateManager::OnChangeFocus(presContext, nullptr,
@@ -2184,29 +2184,28 @@ void nsFocusManager::RaiseWindow(nsPIDOM
   nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   if (!docShell) return;
 
   PresShell* presShell = docShell->GetPresShell();
   if (!presShell) {
     return;
   }
 
-  nsViewManager* vm = presShell->GetViewManager();
-  if (vm) {
+  if (nsViewManager* vm = presShell->GetViewManager()) {
     nsCOMPtr<nsIWidget> widget;
     vm->GetRootWidget(getter_AddRefs(widget));
-    if (widget) widget->SetFocus(true);
+    if (widget) widget->SetFocus(nsIWidget::Raise::Yes);
   }
 #else
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin =
       do_QueryInterface(aWindow->GetDocShell());
   if (treeOwnerAsWin) {
     nsCOMPtr<nsIWidget> widget;
     treeOwnerAsWin->GetMainWidget(getter_AddRefs(widget));
-    if (widget) widget->SetFocus(true);
+    if (widget) widget->SetFocus(nsIWidget::Raise::Yes);
   }
 #endif
 }
 
 void nsFocusManager::UpdateCaretForCaretBrowsingMode() {
   UpdateCaret(false, true, mFocusedElement);
 }
 
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -2812,19 +2812,18 @@ mozilla::ipc::IPCResult BrowserParent::R
 #else
   MOZ_ASSERT_UNREACHABLE(
       "BrowserParent::RecvSetNativeChildOfShareableWindow not implemented!");
   return IPC_FAIL_NO_REASON(this);
 #endif
 }
 
 mozilla::ipc::IPCResult BrowserParent::RecvDispatchFocusToTopLevelWindow() {
-  nsCOMPtr<nsIWidget> widget = GetTopLevelWidget();
-  if (widget) {
-    widget->SetFocus(false);
+  if (nsCOMPtr<nsIWidget> widget = GetTopLevelWidget()) {
+    widget->SetFocus(nsIWidget::Raise::No);
   }
   return IPC_OK();
 }
 
 bool BrowserParent::ReceiveMessage(const nsString& aMessage, bool aSync,
                                    StructuredCloneData* aData,
                                    CpowHolder* aCpows, nsIPrincipal* aPrincipal,
                                    nsTArray<StructuredCloneData>* aRetVal) {
--- a/dom/plugins/ipc/PluginWidgetParent.cpp
+++ b/dom/plugins/ipc/PluginWidgetParent.cpp
@@ -136,17 +136,17 @@ void PluginWidgetParent::ActorDestroy(Ac
 // to destroy the child widget.) when the tab is closing.
 void PluginWidgetParent::ParentDestroy() {
   PWLOG("PluginWidgetParent::ParentDestroy()\n");
 }
 
 mozilla::ipc::IPCResult PluginWidgetParent::RecvSetFocus(const bool& aRaise) {
   ENSURE_CHANNEL;
   PWLOG("PluginWidgetParent::RecvSetFocus(%d)\n", aRaise);
-  mWidget->SetFocus(aRaise);
+  mWidget->SetFocus(aRaise ? nsIWidget::Raise::Yes : nsIWidget::Raise::No);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult PluginWidgetParent::RecvGetNativePluginPort(
     uintptr_t* value) {
   ENSURE_CHANNEL;
   *value = (uintptr_t)mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT);
   NS_ASSERTION(*value, "no native port??");
--- a/gfx/tests/gtest/MockWidget.h
+++ b/gfx/tests/gtest/MockWidget.h
@@ -56,17 +56,17 @@ class MockWidget : public nsBaseWidget {
   virtual bool IsVisible() const override { return true; }
   virtual void Move(double aX, double aY) override {}
   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override {}
   virtual void Resize(double aX, double aY, double aWidth, double aHeight,
                       bool aRepaint) override {}
 
   virtual void Enable(bool aState) override {}
   virtual bool IsEnabled() const override { return true; }
-  virtual nsresult SetFocus(bool aRaise) override { return NS_OK; }
+  virtual void SetFocus(Raise) override {}
   virtual nsresult ConfigureChildren(
       const nsTArray<Configuration>& aConfigurations) override {
     return NS_OK;
   }
   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override {}
   virtual nsresult SetTitle(const nsAString& title) override { return NS_OK; }
   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override {
     return LayoutDeviceIntPoint(0, 0);
--- a/widget/PluginWidgetProxy.cpp
+++ b/widget/PluginWidgetProxy.cpp
@@ -156,17 +156,17 @@ void PluginWidgetProxy::SetNativeData(ui
     case NS_NATIVE_CHILD_WINDOW:
       mActor->SendSetNativeChildWindow(aVal);
       break;
     default:
       NS_ERROR("SetNativeData called with unsupported data type.");
   }
 }
 
-nsresult PluginWidgetProxy::SetFocus(bool aRaise) {
-  ENSURE_CHANNEL;
-  PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
-  mActor->SendSetFocus(aRaise);
-  return NS_OK;
+void PluginWidgetProxy::SetFocus(Raise aRaise) {
+  if (mActor) {
+    PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise == Raise::Yes);
+    mActor->SendSetFocus(aRaise == Raise::Yes);
+  }
 }
 
 }  // namespace widget
 }  // namespace mozilla
--- a/widget/PluginWidgetProxy.h
+++ b/widget/PluginWidgetProxy.h
@@ -38,17 +38,17 @@ class PluginWidgetProxy final : public P
 
   // nsIWidget
   using PuppetWidget::Create;  // for Create signature not overridden here
   virtual MOZ_MUST_USE nsresult
   Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
          const LayoutDeviceIntRect& aRect,
          nsWidgetInitData* aInitData = nullptr) override;
   virtual void Destroy() override;
-  virtual nsresult SetFocus(bool aRaise = false) override;
+  virtual void SetFocus(Raise) override;
   virtual void SetParent(nsIWidget* aNewParent) override;
 
   virtual nsIWidget* GetParent(void) override;
   virtual void* GetNativeData(uint32_t aDataType) override;
   void SetNativeData(uint32_t aDataType, uintptr_t aVal) override;
   virtual nsTransparencyMode GetTransparencyMode() override {
     return eTransparencyOpaque;
   }
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -255,22 +255,20 @@ nsresult PuppetWidget::ConfigureChildren
     } else if (bounds.TopLeft() != configuration.mBounds.TopLeft()) {
       w->Move(configuration.mBounds.X(), configuration.mBounds.Y());
     }
     w->SetWindowClipRegion(configuration.mClipRegion, false);
   }
   return NS_OK;
 }
 
-nsresult PuppetWidget::SetFocus(bool aRaise) {
-  if (aRaise && mBrowserChild) {
+void PuppetWidget::SetFocus(Raise aRaise) {
+  if (aRaise == Raise::Yes && mBrowserChild) {
     mBrowserChild->SendRequestFocus(true);
   }
-
-  return NS_OK;
 }
 
 void PuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect) {
 #ifdef DEBUG
   debug_DumpInvalidate(stderr, this, &aRect, "PuppetWidget", 0);
 #endif
 
   if (mChild) {
--- a/widget/PuppetWidget.h
+++ b/widget/PuppetWidget.h
@@ -106,17 +106,17 @@ class PuppetWidget : public nsBaseWidget
     return Resize(aWidth, aHeight, aRepaint);
   }
 
   // XXX/cjones: copying gtk behavior here; unclear what disabling a
   // widget is supposed to entail
   virtual void Enable(bool aState) override { mEnabled = aState; }
   virtual bool IsEnabled() const override { return mEnabled; }
 
-  virtual nsresult SetFocus(bool aRaise = false) override;
+  virtual void SetFocus(Raise) override;
 
   virtual nsresult ConfigureChildren(
       const nsTArray<Configuration>& aConfigurations) override;
 
   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
 
   // PuppetWidgets don't have native data, as they're purely nonnative.
   virtual void* GetNativeData(uint32_t aDataType) override;
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1738,21 +1738,19 @@ nsWindow* nsWindow::FindTopLevel() {
 
   ALOG(
       "nsWindow::FindTopLevel(): couldn't find a toplevel or dialog window in "
       "this [%p] widget's hierarchy!",
       (void*)this);
   return this;
 }
 
-nsresult nsWindow::SetFocus(bool aRaise) {
-  nsWindow* top = FindTopLevel();
-  top->BringToFront();
-
-  return NS_OK;
+void nsWindow::SetFocus(Raise) {
+  // FIXME: Shouldn't this account for the argument?
+  FindTopLevel()->BringToFront();
 }
 
 void nsWindow::BringToFront() {
   // If the window to be raised is the same as the currently raised one,
   // do nothing. We need to check the focus manager as well, as the first
   // window that is created will be first in the window list but won't yet
   // be focused.
   nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -244,17 +244,17 @@ class nsWindow final : public nsBaseWidg
   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
   virtual void Resize(double aX, double aY, double aWidth, double aHeight,
                       bool aRepaint) override;
   void SetZIndex(int32_t aZIndex) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
-  virtual nsresult SetFocus(bool aRaise = false) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntRect GetScreenBounds() override;
   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
   virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
                                  nsEventStatus& aStatus) override;
   nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
   virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
   virtual nsresult MakeFullScreen(bool aFullScreen,
                                   nsIScreen* aTargetScreen = nullptr) override;
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -327,17 +327,17 @@ class nsChildView final : public nsBaseW
   virtual float GetDPI() override;
 
   virtual void Move(double aX, double aY) override;
   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
   virtual void Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
 
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
-  virtual nsresult SetFocus(bool aRaise) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntRect GetBounds() override;
   virtual LayoutDeviceIntRect GetClientBounds() override;
   virtual LayoutDeviceIntRect GetScreenBounds() override;
 
   // Refresh mBounds with up-to-date values from [mView frame].
   // Only called if this nsChildView is the popup content view of a popup window.
   // For popup windows, the nsIWidget interface to Gecko is provided by
   // nsCocoaWindow, not by nsChildView. So nsCocoaWindow manages resize requests
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -367,17 +367,17 @@ void nsChildView::ReleaseTitlebarCGConte
   if (mTitlebarCGContext) {
     CGContextRelease(mTitlebarCGContext);
     mTitlebarCGContext = nullptr;
   }
 }
 
 nsresult nsChildView::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
                              const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData) {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   // Because the hidden window is created outside of an event loop,
   // we need to provide an autorelease pool to avoid leaking cocoa objects
   // (see bug 559075).
   nsAutoreleasePool localPool;
 
   mBounds = aRect;
 
@@ -718,24 +718,22 @@ float nsChildView::GetDPI() {
   }
   return dpi;
 }
 
 void nsChildView::Enable(bool aState) {}
 
 bool nsChildView::IsEnabled() const { return true; }
 
-nsresult nsChildView::SetFocus(bool aRaise) {
+void nsChildView::SetFocus(Raise) {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   NSWindow* window = [mView window];
   if (window) [window makeFirstResponder:mView];
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 // Override to set the cursor on the mac
 void nsChildView::SetCursor(nsCursor aDefaultCursor, imgIContainer* aImageCursor,
                             uint32_t aHotspotX, uint32_t aHotspotY) {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if ([mView isDragInProgress]) return;  // Don't change the cursor during dragging.
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -225,17 +225,17 @@ class nsCocoaWindow final : public nsBas
   virtual void Show(bool aState) override;
   virtual nsIWidget* GetSheetWindowParent(void) override;
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
   virtual void SetModal(bool aState) override;
   virtual void SetFakeModal(bool aState) override;
   virtual bool IsRunningAppModal() override;
   virtual bool IsVisible() const override;
-  virtual nsresult SetFocus(bool aState = false) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
   virtual LayoutDeviceIntPoint GetClientOffset() override;
   virtual LayoutDeviceIntSize ClientToWindowSize(const LayoutDeviceIntSize& aClientSize) override;
 
   virtual void* GetNativeData(uint32_t aDataType) override;
 
   virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, int32_t* aY) override;
   virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -1833,31 +1833,31 @@ void nsCocoaWindow::SetMenuBar(nsMenuBar
   // other menu bar has been painted yet so that some reasonable menu bar is
   // displayed when the app starts up.
   id windowDelegate = [mWindow delegate];
   if (mMenuBar && ((!gSomeMenuBarPainted && nsMenuUtilsX::GetHiddenWindowMenuBar() == mMenuBar) ||
                    (windowDelegate && [windowDelegate toplevelActiveState])))
     mMenuBar->Paint();
 }
 
-nsresult nsCocoaWindow::SetFocus(bool aState) {
-  if (!mWindow) return NS_OK;
+void nsCocoaWindow::SetFocus(Raise aRaise) {
+  if (!mWindow) return;
 
   if (mPopupContentView) {
-    mPopupContentView->SetFocus(aState);
-  } else if (aState && ([mWindow isVisible] || [mWindow isMiniaturized])) {
+    return mPopupContentView->SetFocus(aRaise);
+  }
+
+  if (aRaise == Raise::Yes && ([mWindow isVisible] || [mWindow isMiniaturized])) {
     if ([mWindow isMiniaturized]) {
       [mWindow deminiaturize:nil];
     }
 
     [mWindow makeKeyAndOrderFront:nil];
     SendSetZLevelEvent();
   }
-
-  return NS_OK;
 }
 
 LayoutDeviceIntPoint nsCocoaWindow::WidgetToScreenOffset() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   return nsCocoaUtils::CocoaRectToGeckoRectDevPix(GetClientCocoaRect(), BackingScaleFactor())
       .TopLeft();
 
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -1461,45 +1461,45 @@ guint32 nsWindow::GetLastUserInputTime()
   if (sLastUserInputTime != GDK_CURRENT_TIME &&
       TimestampIsNewerThan(sLastUserInputTime, timestamp)) {
     return sLastUserInputTime;
   }
 
   return timestamp;
 }
 
-nsresult nsWindow::SetFocus(bool aRaise) {
+void nsWindow::SetFocus(Raise aRaise) {
   // Make sure that our owning widget has focus.  If it doesn't try to
   // grab it.  Note that we don't set our focus flag in this case.
 
-  LOGFOCUS(("  SetFocus %d [%p]\n", aRaise, (void*)this));
+  LOGFOCUS(("  SetFocus %d [%p]\n", aRaise == Raise::Yes, (void*)this));
 
   GtkWidget* owningWidget = GetMozContainerWidget();
-  if (!owningWidget) return NS_ERROR_FAILURE;
+  if (!owningWidget) return;
 
   // Raise the window if someone passed in true and the prefs are
   // set properly.
   GtkWidget* toplevelWidget = gtk_widget_get_toplevel(owningWidget);
 
-  if (gRaiseWindows && aRaise && toplevelWidget &&
+  if (gRaiseWindows && aRaise == Raise::Yes && toplevelWidget &&
       !gtk_widget_has_focus(owningWidget) &&
       !gtk_widget_has_focus(toplevelWidget)) {
     GtkWidget* top_window = GetToplevelWidget();
     if (top_window && (gtk_widget_get_visible(top_window))) {
       gdk_window_show_unraised(gtk_widget_get_window(top_window));
       // Unset the urgency hint if possible.
       SetUrgencyHint(top_window, false);
     }
   }
 
   RefPtr<nsWindow> owningWindow = get_window_for_gtk_widget(owningWidget);
-  if (!owningWindow) return NS_ERROR_FAILURE;
-
-  if (aRaise) {
-    // aRaise == true means request toplevel activation.
+  if (!owningWindow) return;
+
+  if (aRaise == Raise::Yes) {
+    // means request toplevel activation.
 
     // This is asynchronous.
     // If and when the window manager accepts the request, then the focus
     // widget will get a focus-in-event signal.
     if (gRaiseWindows && owningWindow->mIsShown && owningWindow->mShell &&
         !gtk_window_is_active(GTK_WINDOW(owningWindow->mShell))) {
       uint32_t timestamp = GDK_CURRENT_TIME;
 
@@ -1508,22 +1508,21 @@ nsresult nsWindow::SetFocus(bool aRaise)
 
       LOGFOCUS(("  requesting toplevel activation [%p]\n", (void*)this));
       NS_ASSERTION(owningWindow->mWindowType != eWindowType_popup || mParent,
                    "Presenting an override-redirect window");
       gtk_window_present_with_time(GTK_WINDOW(owningWindow->mShell), timestamp);
 
       if (GTKToolkit) GTKToolkit->SetFocusTimestamp(0);
     }
-
-    return NS_OK;
-  }
-
-  // aRaise == false means that keyboard events should be dispatched
-  // from this widget.
+    return;
+  }
+
+  // aRaise == No means that keyboard events should be dispatched from this
+  // widget.
 
   // Ensure owningWidget is the focused GtkWidget within its toplevel window.
   //
   // For eWindowType_popup, this GtkWidget may not actually be the one that
   // receives the key events as it may be the parent window that is active.
   if (!gtk_widget_is_focus(owningWidget)) {
     // This is synchronous.  It takes focus from a plugin or from a widget
     // in an embedder.  The focus manager already knows that this window
@@ -1532,29 +1531,27 @@ nsresult nsWindow::SetFocus(bool aRaise)
     gBlockActivateEvent = true;
     gtk_widget_grab_focus(owningWidget);
     gBlockActivateEvent = false;
   }
 
   // If this is the widget that already has focus, return.
   if (gFocusWindow == this) {
     LOGFOCUS(("  already have focus [%p]\n", (void*)this));
-    return NS_OK;
+    return;
   }
 
   // Set this window to be the focused child window
   gFocusWindow = this;
 
   if (mIMContext) {
     mIMContext->OnFocusWindow(this);
   }
 
   LOGFOCUS(("  widget now has focus in SetFocus() [%p]\n", (void*)this));
-
-  return NS_OK;
 }
 
 LayoutDeviceIntRect nsWindow::GetScreenBounds() {
   LayoutDeviceIntRect rect;
   if (mIsTopLevel && mContainer) {
     // use the point including window decorations
     gint x, y;
     gdk_window_get_root_origin(gtk_widget_get_window(GTK_WIDGET(mContainer)),
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -134,17 +134,17 @@ class nsWindow final : public nsBaseWidg
   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
   virtual void Resize(double aX, double aY, double aWidth, double aHeight,
                       bool aRepaint) override;
   virtual bool IsEnabled() const override;
 
   void SetZIndex(int32_t aZIndex) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
   virtual void Enable(bool aState) override;
-  virtual nsresult SetFocus(bool aRaise = false) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntRect GetScreenBounds() override;
   virtual LayoutDeviceIntRect GetClientBounds() override;
   virtual LayoutDeviceIntSize GetClientSize() override;
   virtual LayoutDeviceIntPoint GetClientOffset() override;
   virtual void SetCursor(nsCursor aDefaultCursor, imgIContainer* aCursor,
                          uint32_t aHotspotX, uint32_t aHotspotY) override;
   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
   virtual void* GetNativeData(uint32_t aDataType) override;
--- a/widget/headless/HeadlessWidget.cpp
+++ b/widget/headless/HeadlessWidget.cpp
@@ -195,28 +195,27 @@ void HeadlessWidget::Show(bool aState) {
     RaiseWindow();
   }
 
   ApplySizeModeSideEffects();
 }
 
 bool HeadlessWidget::IsVisible() const { return mVisible; }
 
-nsresult HeadlessWidget::SetFocus(bool aRaise) {
-  LOGFOCUS(("  SetFocus %d [%p]\n", aRaise, (void*)this));
+void HeadlessWidget::SetFocus(Raise aRaise) {
+  LOGFOCUS(("  SetFocus %d [%p]\n", aRaise == Raise::Yes, (void*)this));
 
-  // aRaise == true means we request activation of our toplevel window.
-  if (aRaise) {
+  // This means we request activation of our toplevel window.
+  if (aRaise == Raise::Yes) {
     HeadlessWidget* topLevel = (HeadlessWidget*)GetTopLevelWidget();
 
     // The toplevel only becomes active if it's currently visible; otherwise, it
     // will be activated anyway when it's shown.
     if (topLevel->IsVisible()) topLevel->RaiseWindow();
   }
-  return NS_OK;
 }
 
 void HeadlessWidget::Enable(bool aState) { mEnabled = aState; }
 
 bool HeadlessWidget::IsEnabled() const { return mEnabled; }
 
 void HeadlessWidget::Move(double aX, double aY) {
   LOG(("HeadlessWidget::Move [%p] %f %f\n", (void*)this, aX, aY));
--- a/widget/headless/HeadlessWidget.h
+++ b/widget/headless/HeadlessWidget.h
@@ -84,17 +84,17 @@ class HeadlessWidget : public nsBaseWidg
   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
   virtual void Resize(double aX, double aY, double aWidth, double aHeight,
                       bool aRepaint) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
   virtual nsresult MakeFullScreen(bool aFullScreen,
                                   nsIScreen* aTargetScreen = nullptr) override;
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
-  virtual nsresult SetFocus(bool aRaise) override;
+  virtual void SetFocus(Raise) override;
   virtual nsresult ConfigureChildren(
       const nsTArray<Configuration>& aConfigurations) override {
     MOZ_ASSERT_UNREACHABLE(
         "Headless widgets do not support configuring children.");
     return NS_ERROR_FAILURE;
   }
   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override {
     // TODO: see if we need to do anything here.
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -848,26 +848,28 @@ class nsIWidget : public nsISupports {
    */
   virtual void Enable(bool aState) = 0;
 
   /**
    * Ask whether the widget is enabled
    */
   virtual bool IsEnabled() const = 0;
 
+  /*
+   * Whether we should request activation of this widget's toplevel window.
+   */
+  enum class Raise {
+    No,
+    Yes,
+  };
+
   /**
    * Request activation of this window or give focus to this widget.
-   *
-   * @param aRaise If true, this function requests activation of this
-   *               widget's toplevel window.
-   *               If false, the appropriate toplevel window (which in
-   *               the case of popups may not be this widget's toplevel
-   *               window) is already active.
    */
-  virtual nsresult SetFocus(bool aRaise = false) = 0;
+  virtual void SetFocus(Raise) = 0;
 
   /**
    * Get this widget's outside dimensions relative to its parent widget. For
    * popup widgets the returned rect is in screen coordinates and not
    * relative to its parent widget.
    *
    * @return the x, y, width and height of this widget.
    */
--- a/widget/uikit/nsWindow.h
+++ b/widget/uikit/nsWindow.h
@@ -30,17 +30,17 @@ class nsWindow final : public nsBaseWidg
   virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
                                        const LayoutDeviceIntRect& aRect,
                                        nsWidgetInitData* aInitData = nullptr) override;
   virtual void Destroy() override;
   virtual void Show(bool aState) override;
   virtual void Enable(bool aState) override {}
   virtual bool IsEnabled() const override { return true; }
   virtual bool IsVisible() const override { return mVisible; }
-  virtual nsresult SetFocus(bool aState = false) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
 
   virtual void SetBackgroundColor(const nscolor& aColor) override;
   virtual void* GetNativeData(uint32_t aDataType) override;
 
   virtual void Move(double aX, double aY) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
   void EnteredFullScreen(bool aFullScreen);
--- a/widget/uikit/nsWindow.mm
+++ b/widget/uikit/nsWindow.mm
@@ -586,20 +586,19 @@ void nsWindow::Invalidate(const LayoutDe
 
   MOZ_RELEASE_ASSERT(GetLayerManager()->GetBackendType() != LayersBackend::LAYERS_CLIENT,
                      "Shouldn't need to invalidate with accelerated OMTC layers!");
 
   [mNativeView setNeedsLayout];
   [mNativeView setNeedsDisplayInRect:DevPixelsToUIKitPoints(mBounds, BackingScaleFactor())];
 }
 
-nsresult nsWindow::SetFocus(bool aRaise) {
+void nsWindow::SetFocus(Raise) {
   [[mNativeView window] makeKeyWindow];
   [mNativeView becomeFirstResponder];
-  return NS_OK;
 }
 
 void nsWindow::WillPaintWindow() {
   if (mWidgetListener) {
     mWidgetListener->WillPaintWindow(this);
   }
 }
 
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -2160,35 +2160,34 @@ bool nsWindow::IsEnabled() const {
 /**************************************************************
  *
  * SECTION: nsIWidget::SetFocus
  *
  * Give the focus to this widget.
  *
  **************************************************************/
 
-nsresult nsWindow::SetFocus(bool aRaise) {
+void nsWindow::SetFocus(Raise aRaise) {
   if (mWnd) {
 #ifdef WINSTATE_DEBUG_OUTPUT
     if (mWnd == WinUtils::GetTopLevelHWND(mWnd)) {
       MOZ_LOG(gWindowsLog, LogLevel::Info,
-              ("*** SetFocus: [  top] raise=%d\n", aRaise));
+              ("*** SetFocus: [  top] raise=%d\n", aRaise == Raise::Yes));
     } else {
       MOZ_LOG(gWindowsLog, LogLevel::Info,
-              ("*** SetFocus: [child] raise=%d\n", aRaise));
+              ("*** SetFocus: [child] raise=%d\n", aRaise == Raise::Yes));
     }
 #endif
     // Uniconify, if necessary
     HWND toplevelWnd = WinUtils::GetTopLevelHWND(mWnd);
-    if (aRaise && ::IsIconic(toplevelWnd)) {
+    if (aRaise == Raise::Yes && ::IsIconic(toplevelWnd)) {
       ::ShowWindow(toplevelWnd, SW_RESTORE);
     }
     ::SetFocus(mWnd);
   }
-  return NS_OK;
 }
 
 /**************************************************************
  *
  * SECTION: Bounds
  *
  * GetBounds, GetClientBounds, GetScreenBounds,
  * GetRestoredBounds, GetClientOffset
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -139,17 +139,17 @@ class nsWindow final : public nsWindowBa
                                                 int32_t aHorizontal,
                                                 int32_t aVertical) override;
   virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
                            nsIWidget* aWidget, bool aActivate) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
   virtual void SuppressAnimation(bool aSuppress) override;
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
-  virtual nsresult SetFocus(bool aRaise) override;
+  virtual void SetFocus(Raise) override;
   virtual LayoutDeviceIntRect GetBounds() override;
   virtual LayoutDeviceIntRect GetScreenBounds() override;
   virtual MOZ_MUST_USE nsresult
   GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
   virtual LayoutDeviceIntRect GetClientBounds() override;
   virtual LayoutDeviceIntPoint GetClientOffset() override;
   void SetBackgroundColor(const nscolor& aColor) override;
   virtual void SetCursor(nsCursor aDefaultCursor, imgIContainer* aCursorImage,