Browse Source

fix: call SetCanActivate in setFocusable (#21854)

Co-authored-by: Cheng Zhao <[email protected]>
trop[bot] 5 years ago
parent
commit
a6121f527c
2 changed files with 12 additions and 0 deletions
  1. 1 0
      shell/browser/native_window_views.cc
  2. 11 0
      spec-main/api-browser-window-spec.ts

+ 1 - 0
shell/browser/native_window_views.cc

@@ -976,6 +976,7 @@ void NativeWindowViews::SetContentProtection(bool enable) {
 }
 
 void NativeWindowViews::SetFocusable(bool focusable) {
+  widget()->widget_delegate()->SetCanActivate(focusable);
 #if defined(OS_WIN)
   LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
   if (focusable)

+ 11 - 0
spec-main/api-browser-window-spec.ts

@@ -697,6 +697,17 @@ describe('BrowserWindow module', () => {
         await closeWindow(w2, { assertNotWindows: false })
       })
     })
+
+    describe('BrowserWindow.setFocusable()', () => {
+      it('can set unfocusable window to focusable', async () => {
+        const w2 = new BrowserWindow({ focusable: false })
+        const w2Focused = emittedOnce(w2, 'focus')
+        w2.setFocusable(true)
+        w2.focus()
+        await w2Focused
+        await closeWindow(w2, { assertNotWindows: false })
+      })
+    })
   })
 
   describe('sizing', () => {