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

Differential Revision: https://phabricator.services.mozilla.com/D179580
This commit is contained in:
Cathie Chen 2023-06-01 18:16:53 +00:00
parent f06667d996
commit fa7b94707d
3 changed files with 9 additions and 3 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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);
}