Skip to content

Commit

Permalink
fix(windows): Fix the issue where TAB cannot cycle through focus elem…
Browse files Browse the repository at this point in the history
…ents. (#1452)
  • Loading branch information
mzdk100 authored Jan 14, 2025
1 parent 95a9319 commit 0185644
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/element-focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wry': 'patch:enhance'
---

Allow the use of TAB to cycle through focus elements in an HTML document.
23 changes: 19 additions & 4 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ impl InnerWebView {
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
if msg == WM_SETFOCUS {
// Fix https://github.com/DioxusLabs/dioxus/issues/2900
// Get the first child window of the window
let child = GetWindow(hwnd, GW_CHILD).ok();
if child.is_some() {
// Set focus to the child window(WebView document)
let _ = SetFocus(child);
}
}

DefWindowProcW(hwnd, msg, wparam, lparam)
}

Expand Down Expand Up @@ -1671,14 +1681,19 @@ unsafe fn set_background_color(
controller: &ICoreWebView2Controller,
background_color: RGBA,
) -> Result<()> {
let (R, G, B, mut A) = background_color;
if is_windows_7() || A != 0 {
A = 255;
let (r, g, b, mut a) = background_color;
if is_windows_7() || a != 0 {
a = 255;
}

let controller2: ICoreWebView2Controller2 = controller.cast()?;
controller2
.SetDefaultBackgroundColor(COREWEBVIEW2_COLOR { R, G, B, A })
.SetDefaultBackgroundColor(COREWEBVIEW2_COLOR {
R: r,
G: g,
B: b,
A: a,
})
.map_err(Into::into)
}

Expand Down

0 comments on commit 0185644

Please sign in to comment.