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

* feat: add support for keyboard initialized menu popup

* Update docs/api/menu.md

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

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

* refactor: s/initiatedByKeyboard/sourceType

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

* Update docs/api/menu.md

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

---------

Co-authored-by: Erick Zhao <erick@hotmail.ca>
Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com>
This commit is contained in:
Samuel Attard 2023-06-29 15:54:06 -07:00 committed by GitHub
parent 607e71d563
commit 499d893040
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;