diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index b948822877bd..e101f5157ef1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1551,12 +1551,14 @@ Prevents the window contents from being captured by other apps. On macOS it sets the NSWindow's sharingType to NSWindowSharingNone. On Windows it calls SetWindowDisplayAffinity with `WDA_MONITOR`. -#### `win.setFocusable(focusable)` _Windows_ +#### `win.setFocusable(focusable)` _macOS_ _Windows_ * `focusable` Boolean Changes whether the window can be focused. +On macOS it does not remove the focus from the window. + #### `win.setParentWindow(parent)` * `parent` BrowserWindow diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index e4287a8ca126..8fff95cc2898 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -104,6 +104,7 @@ class NativeWindowMac : public NativeWindow { bool IsDocumentEdited() override; void SetIgnoreMouseEvents(bool ignore, bool forward) override; void SetContentProtection(bool enable) override; + void SetFocusable(bool focusable) override; void AddBrowserView(NativeBrowserView* browser_view) override; void RemoveBrowserView(NativeBrowserView* browser_view) override; void SetParentWindow(NativeWindow* parent) override; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 630ee6451c35..728f217ac683 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1076,6 +1076,13 @@ void NativeWindowMac::SetContentProtection(bool enable) { setSharingType:enable ? NSWindowSharingNone : NSWindowSharingReadOnly]; } +void NativeWindowMac::SetFocusable(bool focusable) { + // No known way to unfocus the window if it had the focus. Here we do not + // want to call Focus(false) because it moves the window to the back, i.e. + // at the bottom in term of z-order. + [window_ setDisableKeyOrMainWindow:!focusable]; +} + void NativeWindowMac::AddBrowserView(NativeBrowserView* view) { [CATransaction begin]; [CATransaction setDisableActions:YES];