Commit fa7b9470 authored by Cathie Chen's avatar Cathie Chen
Browse files

Bug 1836057 - Popover: Use dialog initial focus for dialog popovers, r=emilio

parent f06667d9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ void HTMLDialogElement::Show(ErrorResult& aError) {

  StorePreviouslyFocusedElement();

  OwnerDoc()->HideAllPopoversWithoutRunningScript();
  FocusDialog();
}

@@ -148,6 +149,7 @@ void HTMLDialogElement::ShowModal(ErrorResult& aError) {

  StorePreviouslyFocusedElement();

  OwnerDoc()->HideAllPopoversWithoutRunningScript();
  FocusDialog();

  aError.SuppressException();
@@ -162,8 +164,6 @@ void HTMLDialogElement::FocusDialog() {
    doc->FlushPendingNotifications(FlushType::Frames);
  }

  doc->HideAllPopoversWithoutRunningScript();

  RefPtr<Element> control = GetFocusDelegate(false /* aWithMouse */);

  // If there isn't one of those either, then let control be subject.
+2 −1
Original line number Diff line number Diff line
@@ -47,11 +47,12 @@ class HTMLDialogElement final : public nsGenericHTMLElement {
  void QueueCancelDialog();
  void RunCancelDialogSteps();

  MOZ_CAN_RUN_SCRIPT_BOUNDARY void FocusDialog();

  nsString mReturnValue;

 protected:
  virtual ~HTMLDialogElement();
  MOZ_CAN_RUN_SCRIPT_BOUNDARY void FocusDialog();
  JSObject* WrapNode(JSContext* aCx,
                     JS::Handle<JSObject*> aGivenProto) override;

+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#include "mozilla/dom/HTMLBodyElement.h"
#include "imgIContainer.h"
#include "nsComputedDOMStyle.h"
#include "mozilla/dom/HTMLDialogElement.h"
#include "mozilla/dom/HTMLLabelElement.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/CustomElementRegistry.h"
@@ -3460,6 +3461,10 @@ void nsGenericHTMLElement::TogglePopover(const Optional<bool>& aForce,

// https://html.spec.whatwg.org/multipage/popover.html#popover-focusing-steps
void nsGenericHTMLElement::FocusPopover() {
  if (auto* dialog = HTMLDialogElement::FromNode(this)) {
    return MOZ_KnownLive(dialog)->FocusDialog();
  }

  if (RefPtr<Document> doc = GetComposedDoc()) {
    doc->FlushPendingNotifications(FlushType::Frames);
  }