fix: read ignoreMenuShortcuts per WebContents (#14538)
This commit is contained in:
parent
1b920c25af
commit
8950caaa85
4 changed files with 21 additions and 16 deletions
|
@ -1396,7 +1396,9 @@ void WebContents::UnregisterServiceWorker(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::SetIgnoreMenuShortcuts(bool ignore) {
|
void WebContents::SetIgnoreMenuShortcuts(bool ignore) {
|
||||||
set_ignore_menu_shortcuts(ignore);
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
||||||
|
DCHECK(web_preferences);
|
||||||
|
web_preferences->dict()->SetBoolean("ignoreMenuShortcuts", ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::SetAudioMuted(bool muted) {
|
void WebContents::SetAudioMuted(bool muted) {
|
||||||
|
|
|
@ -62,10 +62,6 @@ class CommonWebContentsDelegate
|
||||||
|
|
||||||
NativeWindow* owner_window() const { return owner_window_.get(); }
|
NativeWindow* owner_window() const { return owner_window_.get(); }
|
||||||
|
|
||||||
void set_ignore_menu_shortcuts(bool ignore) {
|
|
||||||
ignore_menu_shortcuts_ = ignore;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_html_fullscreen() const { return html_fullscreen_; }
|
bool is_html_fullscreen() const { return html_fullscreen_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -157,7 +153,6 @@ class CommonWebContentsDelegate
|
||||||
base::WeakPtr<NativeWindow> owner_window_;
|
base::WeakPtr<NativeWindow> owner_window_;
|
||||||
|
|
||||||
bool offscreen_ = false;
|
bool offscreen_ = false;
|
||||||
bool ignore_menu_shortcuts_ = false;
|
|
||||||
|
|
||||||
// Whether window is fullscreened by HTML5 api.
|
// Whether window is fullscreened by HTML5 api.
|
||||||
bool html_fullscreen_ = false;
|
bool html_fullscreen_ = false;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "brightray/browser/mac/event_dispatching_window.h"
|
#include "brightray/browser/mac/event_dispatching_window.h"
|
||||||
#include "content/public/browser/native_web_keyboard_event.h"
|
#include "content/public/browser/native_web_keyboard_event.h"
|
||||||
#include "ui/events/keycodes/keyboard_codes.h"
|
#include "ui/events/keycodes/keyboard_codes.h"
|
||||||
|
@ -27,15 +28,17 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||||
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||||
ExitFullscreenModeForTab(source);
|
ExitFullscreenModeForTab(source);
|
||||||
|
|
||||||
if (!ignore_menu_shortcuts_) {
|
if (auto* web_preferences = WebContentsPreferences::From(source)) {
|
||||||
// Send the event to the menu before sending it to the window
|
if (!web_preferences->IsEnabled("ignoreMenuShortcuts", false)) {
|
||||||
if (event.os_event.type == NSKeyDown &&
|
// Send the event to the menu before sending it to the window
|
||||||
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
if (event.os_event.type == NSKeyDown &&
|
||||||
return;
|
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
||||||
|
return;
|
||||||
|
|
||||||
if (event.os_event.window &&
|
if (event.os_event.window &&
|
||||||
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
||||||
[event.os_event.window redispatchKeyEvent:event.os_event];
|
[event.os_event.window redispatchKeyEvent:event.os_event];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_web_contents_view.h"
|
#include "atom/browser/api/atom_api_web_contents_view.h"
|
||||||
#include "atom/browser/native_window_views.h"
|
#include "atom/browser/native_window_views.h"
|
||||||
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "content/public/browser/native_web_keyboard_event.h"
|
#include "content/public/browser/native_web_keyboard_event.h"
|
||||||
#include "ui/events/keycodes/keyboard_codes.h"
|
#include "ui/events/keycodes/keyboard_codes.h"
|
||||||
|
@ -24,8 +25,12 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||||
ExitFullscreenModeForTab(source);
|
ExitFullscreenModeForTab(source);
|
||||||
|
|
||||||
// Let the NativeWindow handle other parts.
|
// Let the NativeWindow handle other parts.
|
||||||
if (!ignore_menu_shortcuts_ && owner_window())
|
if (auto* web_preferences = WebContentsPreferences::From(source)) {
|
||||||
owner_window()->HandleKeyboardEvent(source, event);
|
if (owner_window() &&
|
||||||
|
!web_preferences->IsEnabled("ignoreMenuShortcuts", false)) {
|
||||||
|
owner_window()->HandleKeyboardEvent(source, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::ShowAutofillPopup(
|
void CommonWebContentsDelegate::ShowAutofillPopup(
|
||||||
|
|
Loading…
Reference in a new issue