feat: add support for keyboard initialized menu popup (#38954)

* feat: add support for keyboard initialized menu popup

Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>

* Update docs/api/menu.md

Co-authored-by: Erick Zhao <erick@hotmail.ca>

Co-authored-by: Samuel Attard <sam@electronjs.org>

* fix: add patch to chromium for keyboard accessibility menu behavior

Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>

* refactor: s/initiatedByKeyboard/sourceType

Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>

* fix: ignore initial mouse event to retain keyboard initiated focus

Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>

* Update docs/api/menu.md

Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com>

Co-authored-by: Samuel Attard <sam@electronjs.org>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
Co-authored-by: Samuel Attard <sam@electronjs.org>
This commit is contained in:
trop[bot]
2023-07-05 16:30:19 -04:00
committed by GitHub
parent 6452e5c992
commit 2b254b1d6d
13 changed files with 282 additions and 33 deletions

View File

@@ -11,6 +11,7 @@
#include "shell/browser/native_window.h"
#include "shell/common/gin_converters/accelerator_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/image_converter.h"

View File

@@ -78,6 +78,7 @@ class Menu : public gin::Wrappable<Menu>,
int x,
int y,
int positioning_item,
ui::MenuSourceType source_type,
base::OnceClosure callback) = 0;
virtual void ClosePopupAt(int32_t window_id) = 0;
virtual std::u16string GetAcceleratorTextAtForTesting(int index) const;

View File

@@ -24,6 +24,7 @@ class MenuMac : public Menu {
int x,
int y,
int positioning_item,
ui::MenuSourceType source_type,
base::OnceClosure callback) override;
void PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
int32_t window_id,

View File

@@ -52,6 +52,7 @@ void MenuMac::PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,
ui::MenuSourceType source_type,
base::OnceClosure callback) {
NativeWindow* native_window = window->window();
if (!native_window)

View File

@@ -22,6 +22,7 @@ void MenuViews::PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,
ui::MenuSourceType source_type,
base::OnceClosure callback) {
auto* native_window = static_cast<NativeWindowViews*>(window->window());
if (!native_window)
@@ -55,7 +56,7 @@ void MenuViews::PopupAt(BaseWindow* window,
std::make_unique<MenuRunner>(model(), flags, std::move(close_callback));
menu_runners_[window_id]->RunMenuAt(
native_window->widget(), nullptr, gfx::Rect(location, gfx::Size()),
views::MenuAnchorPosition::kTopLeft, ui::MENU_SOURCE_MOUSE);
views::MenuAnchorPosition::kTopLeft, source_type);
}
void MenuViews::ClosePopupAt(int32_t window_id) {

View File

@@ -25,6 +25,7 @@ class MenuViews : public Menu {
int x,
int y,
int positioning_item,
ui::MenuSourceType source_type,
base::OnceClosure callback) override;
void ClosePopupAt(int32_t window_id) override;