Commit 748cc858 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

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

--HG--
extra : moz-landing-system : lando
parent 9cf251ce
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -1093,7 +1093,7 @@ void nsFocusManager::EnsureCurrentWidgetFocused() {
  if (!widget) {
    return;
  }
  widget->SetFocus(false);
  widget->SetFocus(nsIWidget::Raise::No);
}

bool ActivateOrDeactivateChild(BrowserParent* aParent, void* aArg) {
@@ -1629,13 +1629,12 @@ bool nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
        } 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);
            }
          }
        }
@@ -1821,11 +1820,10 @@ void nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow, Element* aElement,
    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);
    }
  }

@@ -1878,8 +1876,9 @@ void nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow, Element* aElement,
      // 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
@@ -1911,11 +1910,12 @@ void nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow, Element* aElement,
    // 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);
        }
      }
    }

@@ -2189,11 +2189,10 @@ void nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow) {
    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 =
@@ -2201,7 +2200,7 @@ void nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow) {
  if (treeOwnerAsWin) {
    nsCOMPtr<nsIWidget> widget;
    treeOwnerAsWin->GetMainWidget(getter_AddRefs(widget));
    if (widget) widget->SetFocus(true);
    if (widget) widget->SetFocus(nsIWidget::Raise::Yes);
  }
#endif
}
+2 −3
Original line number Diff line number Diff line
@@ -2812,9 +2812,8 @@ mozilla::ipc::IPCResult BrowserParent::RecvSetNativeChildOfShareableWindow(
}

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();
}
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ void PluginWidgetParent::ParentDestroy() {
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();
}

+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ class MockWidget : public nsBaseWidget {

  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;
+3 −4
Original line number Diff line number Diff line
@@ -161,11 +161,10 @@ void PluginWidgetProxy::SetNativeData(uint32_t aDataType, uintptr_t aVal) {
  }
}

nsresult PluginWidgetProxy::SetFocus(bool aRaise) {
void PluginWidgetProxy::SetFocus(Raise aRaise) {
  ENSURE_CHANNEL;
  PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
  mActor->SendSetFocus(aRaise);
  return NS_OK;
  PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise == Raise::Yes);
  mActor->SendSetFocus(aRaise == Raise::Yes);
}

}  // namespace widget
Loading